Search in sources :

Example 1 with Case

use of catdata.fqlpp.FunctorExp.Case 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 2 with Case

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

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, Pushout e) {
    Transform l = ENV.trans.get(e.l);
    if (l == null) {
        throw new RuntimeException("Missing transform: " + e.l);
    }
    Transform r = ENV.trans.get(e.r);
    if (r == null) {
        throw new RuntimeException("Missing transform: " + e.r);
    }
    if (!l.source.equals(r.source)) {
        throw new RuntimeException("Source functors do not match.");
    }
    Category<Object, Object> D = l.source.source;
    Set<String> objects = new HashSet<>();
    objects.add("A");
    objects.add("B");
    objects.add("C");
    Set<String> arrows = new HashSet<>();
    arrows.add("f");
    arrows.add("g");
    arrows.add("a");
    arrows.add("b");
    arrows.add("c");
    Map<String, String> sources = new HashMap<>();
    sources.put("f", "A");
    sources.put("g", "A");
    sources.put("a", "A");
    sources.put("b", "B");
    sources.put("c", "C");
    Map<String, String> targets = new HashMap<>();
    targets.put("f", "B");
    targets.put("g", "C");
    targets.put("a", "A");
    targets.put("b", "B");
    targets.put("c", "C");
    Map<Pair<String, String>, String> composition = new HashMap<>();
    composition.put(new Pair<>("a", "a"), "a");
    composition.put(new Pair<>("b", "b"), "b");
    composition.put(new Pair<>("c", "c"), "c");
    composition.put(new Pair<>("a", "f"), "f");
    composition.put(new Pair<>("a", "g"), "g");
    composition.put(new Pair<>("f", "b"), "f");
    composition.put(new Pair<>("g", "c"), "g");
    Map<String, String> identities = new HashMap<>();
    identities.put("A", "a");
    identities.put("B", "b");
    identities.put("C", "c");
    Category<String, String> span = new FiniteCategory<>(objects, arrows, sources, targets, composition, identities);
    Category<Pair<Object, String>, Pair<Object, String>> Dspan = FinCat.product(D, span);
    Functor<Pair<Object, String>, Pair<Object, String>, Object, Object> fst = FinCat.first(D, span);
    FUNCTION<Pair<Object, String>, Set> o = p -> {
        switch(p.second) {
            case "A":
                return (Set) l.source.applyO(p.first);
            case "B":
                return (Set) l.target.applyO(p.first);
            case "C":
                return (Set) r.target.applyO(p.first);
            default:
                throw new RuntimeException();
        }
    };
    FUNCTION<Pair<Object, String>, Fn> x = fp -> {
        Object f = fp.first;
        String p = fp.second;
        Object a = D.source(f);
        // Object b = D.target(f);
        // String i = span.source(p);
        String j = span.target(p);
        // Functor I = i == "A" ? l.source : i == "B" ? l.target : r.target;
        Functor J = Objects.equals(j, "A") ? l.source : Objects.equals(j, "B") ? l.target : r.target;
        // Fn If = (Fn) I.applyA(f);
        Fn Jf = (Fn) J.applyA(f);
        Transform P = Objects.equals(p, "f") ? l : Objects.equals(p, "g") ? r : Objects.equals(p, "a") ? Transform.id(l.source) : Objects.equals(p, "b") ? Transform.id(l.target) : Transform.id(r.target);
        // Fn Pb = (Fn) P.apply(b);
        Fn Pa = (Fn) P.apply(a);
        return Fn.compose(Pa, Jf);
    };
    Functor I = new Functor(Dspan, FinSet.FinSet0(), o, x);
    return FDM.sigmaF(fst).applyO(I);
}
Also used : PeterApply(catdata.fqlpp.TransExp.PeterApply) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Named(catdata.fqlpp.CatExp.Named) Edge(catdata.fqlpp.cat.Signature.Edge) Snd(catdata.fqlpp.FunctorExp.Snd) Comp(catdata.fqlpp.FunctorExp.Comp) ToInst(catdata.fqlpp.TransExp.ToInst) Id(catdata.fqlpp.FunctorExp.Id) Inr(catdata.fqlpp.FunctorExp.Inr) FF(catdata.fqlpp.FunctorExp.FF) Migrate(catdata.fqlpp.FunctorExp.Migrate) Colim(catdata.fqlpp.CatExp.Colim) Exp(catdata.fqlpp.CatExp.Exp) Pushout(catdata.fqlpp.FunctorExp.Pushout) FinCat(catdata.fqlpp.cat.FinCat) FunCat(catdata.fqlpp.cat.FunCat) Pair(catdata.Pair) CoMonad(catdata.fqlpp.cat.CoMonad) Iso(catdata.fqlpp.FunctorExp.Iso) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Inj(catdata.fqlpp.TransExp.Inj) Fn(catdata.fqlpp.cat.FinSet.Fn) Bool(catdata.fqlpp.TransExp.Bool) Case(catdata.fqlpp.FunctorExp.Case) ToMap(catdata.fqlpp.TransExp.ToMap) Zero(catdata.fqlpp.CatExp.Zero) Monad(catdata.fqlpp.cat.Monad) Plus(catdata.fqlpp.CatExp.Plus) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) Inst(catdata.fqlpp.cat.Inst) ToSet(catdata.fqlpp.TransExp.ToSet) Groth(catdata.fqlpp.cat.Groth) Mapping(catdata.fqlpp.cat.Mapping) Serializable(java.io.Serializable) Kleisli(catdata.fqlpp.CatExp.Kleisli) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Dom(catdata.fqlpp.CatExp.Dom) Triple(catdata.Triple) Eval(catdata.fqlpp.FunctorExp.Eval) Var(catdata.fqlpp.FunctorExp.Var) Times(catdata.fqlpp.CatExp.Times) Const(catdata.fqlpp.CatExp.Const) java.util(java.util) Prod(catdata.fqlpp.FunctorExp.Prod) InstConst(catdata.fqlpp.FunctorExp.InstConst) Node(catdata.fqlpp.cat.Signature.Node) Chc(catdata.Chc) TT(catdata.fqlpp.FunctorExp.TT) Functor(catdata.fqlpp.cat.Functor) Proj(catdata.fqlpp.TransExp.Proj) Prop(catdata.fqlpp.FunctorExp.Prop) CatExpVisitor(catdata.fqlpp.CatExp.CatExpVisitor) Signature(catdata.fqlpp.cat.Signature) TransExpVisitor(catdata.fqlpp.TransExp.TransExpVisitor) Union(catdata.fqlpp.CatExp.Union) ToCat(catdata.fqlpp.TransExp.ToCat) One(catdata.fqlpp.CatExp.One) FDM(catdata.fqlpp.cat.FDM) Ker(catdata.fqlpp.TransExp.Ker) Fst(catdata.fqlpp.FunctorExp.Fst) Whisker(catdata.fqlpp.TransExp.Whisker) Curry(catdata.fqlpp.FunctorExp.Curry) Transform(catdata.fqlpp.cat.Transform) Apply(catdata.fqlpp.FunctorExp.Apply) Instance(catdata.fqlpp.cat.Instance) MapConst(catdata.fqlpp.FunctorExp.MapConst) Path(catdata.fqlpp.cat.Signature.Path) Pivot(catdata.fqlpp.FunctorExp.Pivot) Chr(catdata.fqlpp.TransExp.Chr) Cod(catdata.fqlpp.CatExp.Cod) FinSet(catdata.fqlpp.cat.FinSet) Uncurry(catdata.fqlpp.FunctorExp.Uncurry) FunctorExpVisitor(catdata.fqlpp.FunctorExp.FunctorExpVisitor) Adj(catdata.fqlpp.TransExp.Adj) SetSet(catdata.fqlpp.TransExp.SetSet) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Inl(catdata.fqlpp.FunctorExp.Inl) CoProd(catdata.fqlpp.TransExp.CoProd) ToSet(catdata.fqlpp.TransExp.ToSet) FinSet(catdata.fqlpp.cat.FinSet) SetSet(catdata.fqlpp.TransExp.SetSet) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform) Pair(catdata.Pair)

Aggregations

Pair (catdata.Pair)2 Apply (catdata.fqlpp.FunctorExp.Apply)2 Case (catdata.fqlpp.FunctorExp.Case)2 Comp (catdata.fqlpp.FunctorExp.Comp)2 Curry (catdata.fqlpp.FunctorExp.Curry)2 Eval (catdata.fqlpp.FunctorExp.Eval)2 FF (catdata.fqlpp.FunctorExp.FF)2 Fst (catdata.fqlpp.FunctorExp.Fst)2 Id (catdata.fqlpp.FunctorExp.Id)2 Inl (catdata.fqlpp.FunctorExp.Inl)2 Inr (catdata.fqlpp.FunctorExp.Inr)2 Iso (catdata.fqlpp.FunctorExp.Iso)2 Migrate (catdata.fqlpp.FunctorExp.Migrate)2 Pivot (catdata.fqlpp.FunctorExp.Pivot)2 Prod (catdata.fqlpp.FunctorExp.Prod)2 Prop (catdata.fqlpp.FunctorExp.Prop)2 Pushout (catdata.fqlpp.FunctorExp.Pushout)2 Snd (catdata.fqlpp.FunctorExp.Snd)2 TT (catdata.fqlpp.FunctorExp.TT)2 Uncurry (catdata.fqlpp.FunctorExp.Uncurry)2