Search in sources :

Example 1 with Var

use of catdata.fqlpp.FunctorExp.Var in project fql by CategoricalData.

the class Ben method colim.

public static Const colim(FQLPPProgram env, CatConst f) {
    if (!(f.sig instanceof CatExp.Var)) {
        throw new RuntimeException(f.sig + " is not variable, is " + f.sig.getClass());
    }
    CatExp c = env.cats.get(((CatExp.Var) f.sig).v);
    if (!(c instanceof Const)) {
        throw new RuntimeException(c + " is not finitely presented, is " + c.getClass());
    }
    Const src = (Const) c;
    Map<String, Const> obMapping = new HashMap<>();
    Map<String, MapConst> arrMapping = new HashMap<>();
    for (String src_ob : f.nm.keySet()) {
        CatExp C = f.nm.get(src_ob);
        if (!(C instanceof CatExp.Var)) {
            throw new RuntimeException(C + " is not a variable");
        }
        CatExp D = env.cats.get(((CatExp.Var) C).v);
        if (!(D instanceof Const)) {
            throw new RuntimeException(D + " is not finitely presented");
        }
        obMapping.put(src_ob, (Const) D);
    }
    for (String src_arr : f.em.keySet()) {
        FunctorExp C = f.em.get(src_arr);
        if (!(C instanceof Var)) {
            throw new RuntimeException(C + " is not a variable");
        }
        FunctorExp D = env.ftrs.get(((Var) C).v);
        if (!(D instanceof MapConst)) {
            throw new RuntimeException(D + " is not finitely presented");
        }
        arrMapping.put(src_arr, (MapConst) D);
    }
    return sandbox(src, obMapping, arrMapping);
}
Also used : HashMap(java.util.HashMap) Var(catdata.fqlpp.FunctorExp.Var) Const(catdata.fqlpp.CatExp.Const) MapConst(catdata.fqlpp.FunctorExp.MapConst) CatConst(catdata.fqlpp.FunctorExp.CatConst) MapConst(catdata.fqlpp.FunctorExp.MapConst)

Example 2 with Var

use of catdata.fqlpp.FunctorExp.Var in project fql by CategoricalData.

the class PPParser method toFtr.

private static FunctorExp toFtr(Object o) {
    try {
        Tuple5 p = (Tuple5) o;
        if (p.a.toString().equals("apply")) {
            FunctorExp f = toFtr(p.b);
            FunctorExp e = toFtr(p.e);
            return new Apply(f, e);
        }
        if (p.e.toString().equals("Set")) {
            return p.c.toString().equals("Set") ? toSetSet(o) : toInstConst(o);
        } else if (p.e.toString().equals("Cat")) {
            return toCatFtrConst(o);
        } else {
            if (p.e instanceof Tuple3) {
                Tuple3 t = (Tuple3) p.e;
                if ((t.a.toString().equals("Cat") || t.a.toString().equals("Set")) && t.b.toString().equals("^")) {
                    return toFinalConst(o);
                } else {
                    throw new RuntimeException();
                }
            }
            return toMapConst(o);
        }
    } catch (Exception e) {
    }
    try {
        Tuple3 p = (Tuple3) o;
        Object p2 = p.b;
        Object p3 = p.c;
        Object o1 = p.a;
        String p1 = p.a.toString();
        if (p1.equals("fst")) {
            return new Fst(toCat(p2), toCat(p3));
        } else if (p1.equals("snd")) {
            return new Snd(toCat(p2), toCat(p3));
        } else if (p1.equals("inl")) {
            return new Inl(toCat(p2), toCat(p3));
        } else if (p1.equals("inr")) {
            return new Inr(toCat(p2), toCat(p3));
        } else if (p1.equals("iso1")) {
            return new Iso(true, toCat(p2), toCat(p3));
        } else if (p1.equals("iso2")) {
            return new Iso(false, toCat(p2), toCat(p3));
        } else if (p1.equals("eval")) {
            return new Eval(toCat(p2), toCat(p3));
        } else if (p2.toString().equals(";")) {
            return new Comp(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("*")) {
            return new Prod(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("+")) {
            return new Case(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("^")) {
            return new Exp(toFtr(o1), toFtr(p3));
        } else if (p1.equals("unit")) {
            return new One(toCat(p.b), toCat(p.c));
        } else if (p1.equals("void")) {
            return new Zero(toCat(p.b), toCat(p.c));
        } else if (p1.equals("pushout")) {
            return new Pushout(p.b.toString(), p.c.toString());
        }
    } catch (RuntimeException re) {
    }
    try {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        String p1 = p.a.toString();
        Object p2 = p.b;
        switch(p1) {
            case "id":
                return new Id(toCat(p2));
            case "prop":
                return new Prop(toCat(p2));
            case "curry":
                return new Curry(toFtr(p2));
            case "uncurry":
                return new Uncurry(toFtr(p2));
            case "delta":
            case "sigma":
            case "pi":
                return new Migrate(toFtr(p2), p1);
            case "ff":
                return new FF(toCat(p2));
            case "tt":
                return new TT(toCat(p2));
            case "dom":
                return new Dom(p2.toString(), true);
            case "cod":
                return new Dom(p2.toString(), false);
            case "pivot":
                return new Pivot(toFtr(p2), true);
            case "unpivot":
                return new Pivot(toFtr(p2), false);
            default:
                break;
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new Var(o.toString());
    }
    throw new RuntimeException("Bad: " + o);
}
Also used : Curry(catdata.fqlpp.FunctorExp.Curry) FF(catdata.fqlpp.FunctorExp.FF) TT(catdata.fqlpp.FunctorExp.TT) PeterApply(catdata.fqlpp.TransExp.PeterApply) Apply(catdata.fqlpp.FunctorExp.Apply) Inl(catdata.fqlpp.FunctorExp.Inl) Migrate(catdata.fqlpp.FunctorExp.Migrate) Var(catdata.fqlpp.FunctorExp.Var) One(catdata.fqlpp.FunctorExp.One) Snd(catdata.fqlpp.FunctorExp.Snd) Pushout(catdata.fqlpp.FunctorExp.Pushout) Inr(catdata.fqlpp.FunctorExp.Inr) Comp(catdata.fqlpp.FunctorExp.Comp) Case(catdata.fqlpp.FunctorExp.Case) Prod(catdata.fqlpp.FunctorExp.Prod) CoProd(catdata.fqlpp.TransExp.CoProd) Eval(catdata.fqlpp.FunctorExp.Eval) Pair(catdata.Pair) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Iso(catdata.fqlpp.FunctorExp.Iso) Prop(catdata.fqlpp.FunctorExp.Prop) Fst(catdata.fqlpp.FunctorExp.Fst) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Pivot(catdata.fqlpp.FunctorExp.Pivot) Id(catdata.fqlpp.FunctorExp.Id) Exp(catdata.fqlpp.FunctorExp.Exp) Uncurry(catdata.fqlpp.FunctorExp.Uncurry)

Example 3 with Var

use of catdata.fqlpp.FunctorExp.Var in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, Apply e) {
    Functor ret1 = null;
    Exception ret1_e = null;
    Functor ret2 = null;
    Exception ret2_e = null;
    Functor F = e.F.accept(env, this);
    try {
        Functor I = e.I.accept(env, this);
        ret1 = (Functor) F.applyO(I);
    } catch (Exception ex) {
        ret1_e = ex;
    }
    try {
        Var I = (Var) e.I;
        Node n = F.source.toSig().new Node(I.v);
        ret2 = (Functor) F.applyO(n);
    } catch (Exception ex) {
        ret2_e = ex;
    }
    if (ret1 != null && ret2 != null) {
        throw new RuntimeException("Ambiguous: " + e.I + " is an object in two different categories.");
    }
    if (ret1 != null) {
        return ret1;
    }
    if (ret2 != null) {
        return ret2;
    }
    if (ret1_e != null) {
        // TODO !!!
        ret1_e.printStackTrace();
    }
    if (ret2_e != null) {
        ret2_e.printStackTrace();
    }
    throw new RuntimeException("Cannot apply:\n\nmost probable cause: " + ret1_e + "\n\nless probable cause: " + ret2_e);
}
Also used : Var(catdata.fqlpp.FunctorExp.Var) Node(catdata.fqlpp.cat.Signature.Node) Functor(catdata.fqlpp.cat.Functor)

Aggregations

Var (catdata.fqlpp.FunctorExp.Var)3 Pair (catdata.Pair)1 Const (catdata.fqlpp.CatExp.Const)1 Apply (catdata.fqlpp.FunctorExp.Apply)1 Case (catdata.fqlpp.FunctorExp.Case)1 CatConst (catdata.fqlpp.FunctorExp.CatConst)1 Comp (catdata.fqlpp.FunctorExp.Comp)1 Curry (catdata.fqlpp.FunctorExp.Curry)1 Dom (catdata.fqlpp.FunctorExp.Dom)1 Eval (catdata.fqlpp.FunctorExp.Eval)1 Exp (catdata.fqlpp.FunctorExp.Exp)1 FF (catdata.fqlpp.FunctorExp.FF)1 Fst (catdata.fqlpp.FunctorExp.Fst)1 Id (catdata.fqlpp.FunctorExp.Id)1 Inl (catdata.fqlpp.FunctorExp.Inl)1 Inr (catdata.fqlpp.FunctorExp.Inr)1 Iso (catdata.fqlpp.FunctorExp.Iso)1 MapConst (catdata.fqlpp.FunctorExp.MapConst)1 Migrate (catdata.fqlpp.FunctorExp.Migrate)1 One (catdata.fqlpp.FunctorExp.One)1