Search in sources :

Example 1 with FinalConst

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

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, FinalConst ic) {
    CatExp e = resolve(env, ic.src);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create functors from finitely-presented categories.");
    }
    Const c = (Const) e;
    Category cat = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
    Category target = ic.C.accept(env, this);
    Map<Node, Functor> nm = new HashMap<>();
    for (Node n : sig.nodes) {
        FunctorExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        Functor F = kkk.accept(env, this);
        nm.put(n, F);
    }
    Map<Edge, Transform> em = new HashMap<>();
    for (Edge n : sig.edges) {
        TransExp chc = ic.em.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing edge mapping from " + n);
        }
        em.put(n, chc.accept(env, this));
    }
    FUNCTION fff = p0 -> {
        Path p = (Path) p0;
        Object fn = target.identity(nm.get(p.source));
        for (Object nnn : p.path) {
            Edge n = (Edge) nnn;
            fn = target.compose(fn, em.get(n));
        }
        return fn;
    };
    return new Functor(cat, target, nm::get, fff);
}
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) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Path(catdata.fqlpp.cat.Signature.Path) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Const(catdata.fqlpp.CatExp.Const) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Node(catdata.fqlpp.cat.Signature.Node) Functor(catdata.fqlpp.cat.Functor) Signature(catdata.fqlpp.cat.Signature) Transform(catdata.fqlpp.cat.Transform) Edge(catdata.fqlpp.cat.Signature.Edge)

Example 2 with FinalConst

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

the class PPParser method toFinalConst.

private static FunctorExp toFinalConst(Object decl) {
    Tuple5 y = (Tuple5) decl;
    org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
    Tuple3 nodes = (Tuple3) x.a;
    Tuple3 arrows = (Tuple3) x.b;
    List nodes0 = (List) nodes.b;
    List arrows0 = (List) arrows.b;
    Map<String, FunctorExp> nodesX = new HashMap<>();
    for (Object o : nodes0) {
        if (nodesX.containsKey(o)) {
            throw new RuntimeException("Duplicate object: " + o + " in " + decl);
        }
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        FunctorExp l = toFtr(u.c);
        nodesX.put(n, l);
    }
    Map<String, TransExp> arrowsX = new HashMap<>();
    for (Object o : arrows0) {
        if (arrowsX.containsKey(o)) {
            throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
        }
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        TransExp l = toTrans(u.c);
        arrowsX.put(n, l);
    }
    FinalConst ret = new FinalConst(toCat(y.c), toCat(y.e), nodesX, arrowsX);
    return ret;
}
Also used : HashMap(java.util.HashMap) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Pair(catdata.Pair)

Aggregations

Pair (catdata.Pair)2 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)2 Chc (catdata.Chc)1 Triple (catdata.Triple)1 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)1 Cod (catdata.fqlpp.CatExp.Cod)1 Colim (catdata.fqlpp.CatExp.Colim)1 Const (catdata.fqlpp.CatExp.Const)1 Dom (catdata.fqlpp.CatExp.Dom)1 Exp (catdata.fqlpp.CatExp.Exp)1 Kleisli (catdata.fqlpp.CatExp.Kleisli)1 Named (catdata.fqlpp.CatExp.Named)1 One (catdata.fqlpp.CatExp.One)1 Plus (catdata.fqlpp.CatExp.Plus)1 Times (catdata.fqlpp.CatExp.Times)1 Union (catdata.fqlpp.CatExp.Union)1 Zero (catdata.fqlpp.CatExp.Zero)1 Apply (catdata.fqlpp.FunctorExp.Apply)1 Case (catdata.fqlpp.FunctorExp.Case)1 CatConst (catdata.fqlpp.FunctorExp.CatConst)1