Search in sources :

Example 6 with Node

use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, ToMap e) {
    Functor s = e.src.accept(env, this);
    Functor t = e.dst.accept(env, this);
    CatExp scat = resolve(env, e.s);
    if (!(scat instanceof Const)) {
        throw new RuntimeException("Source category of " + e + " is not a constant.");
    }
    // CatExp.Const scon = (CatExp.Const) scat;
    CatExp tcat = resolve(env, e.t);
    if (!(tcat instanceof Const)) {
        throw new RuntimeException("Target category of " + e + " is not a constant.");
    }
    Const tcon = (Const) tcat;
    // Signature ssig = new Signature(scon.nodes, scon.arrows, scon.eqs);
    Signature<String, String> tsig = new Signature<>(tcon.nodes, tcon.arrows, tcon.eqs);
    FUNCTION o = x -> {
        Node n = (Node) x;
        // Set src = (Set) s.applyO(n);
        // Set dst = (Set) t.applyO(n);
        Pair<String, List<String>> k = e.fun.get(n.name);
        Signature<String, String>.Path fun = tsig.path(k.first, k.second);
        // new Fn(src, dst, fun);
        return fun;
    };
    return new Transform(s, t, o);
}
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) 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) Pair(catdata.Pair)

Example 7 with Node

use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.

the class CatOps method toInstance.

private Pair<Category, Instance<String, String>> toInstance(FQLPPProgram env, InstConst ic) {
    CatExp e = resolve(env, ic.sig);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create instances for finitely-presented categories.");
    }
    Const c = (Const) e;
    Category src = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
    Map<Node, Set> nm = new HashMap<>();
    for (String n0 : ic.nm.keySet()) {
        Node n = sig.getNode(n0);
        SetExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        nm.put(n, kkk.accept(env, new SetOps(ENV)));
    }
    Map<Edge, Map> em = new HashMap<>();
    for (String n0 : ic.em.keySet()) {
        Edge n = sig.getEdge(n0);
        Chc<FnExp, SetExp> chc = ic.em.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing edge mapping from " + n);
        }
        if (chc.left) {
            FnExp kkk = chc.l;
            em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
        } else {
            SetExp sss = chc.r;
            Set vvv = sss.accept(env, new SetOps(ENV));
            Map<Object, Object> uuu = new HashMap<>();
            for (Object o : vvv) {
                if (!(o instanceof Pair)) {
                    throw new RuntimeException("Not a pair: " + o);
                }
                Pair oo = (Pair) o;
                if (uuu.containsKey(oo.first)) {
                    throw new RuntimeException("Duplicate domain entry: " + o + " in " + ic);
                }
                uuu.put(oo.first, oo.second);
            }
            FnExp kkk = new FnExp.Const(uuu::get, ic.nm.get(n.source.name), ic.nm.get(n.target.name));
            em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
        }
    }
    return new Pair<>(src, new Instance(nm, em, sig));
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) ToSet(catdata.fqlpp.TransExp.ToSet) FinSet(catdata.fqlpp.cat.FinSet) SetSet(catdata.fqlpp.TransExp.SetSet) Instance(catdata.fqlpp.cat.Instance) 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) Signature(catdata.fqlpp.cat.Signature) Edge(catdata.fqlpp.cat.Signature.Edge) ToMap(catdata.fqlpp.TransExp.ToMap) Pair(catdata.Pair)

Example 8 with Node

use of catdata.fqlpp.cat.Signature.Node 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)

Example 9 with Node

use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, PeterApply e) {
    Transform t = e.t.accept(env, this);
    Node n = t.source.source.toSig().new Node(e.node);
    return (Transform) t.apply(n);
}
Also used : Node(catdata.fqlpp.cat.Signature.Node) Transform(catdata.fqlpp.cat.Transform)

Example 10 with Node

use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, ToInst e) {
    Functor s = e.src.accept(env, this);
    Functor t = e.dst.accept(env, this);
    FUNCTION o = x -> {
        Node n = (Node) x;
        // Set src = (Set) s.applyO(n);
        // Set dst = (Set) t.applyO(n);
        Transform fun = e.fun.get(n.name).accept(env, this);
        // new Fn(src, dst, fun);
        return fun;
    };
    return new Transform(s, t, o);
}
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) Node(catdata.fqlpp.cat.Signature.Node) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform)

Aggregations

Node (catdata.fqlpp.cat.Signature.Node)11 Pair (catdata.Pair)9 Edge (catdata.fqlpp.cat.Signature.Edge)9 Triple (catdata.Triple)8 Const (catdata.fqlpp.CatExp.Const)8 CatConst (catdata.fqlpp.FunctorExp.CatConst)8 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)8 InstConst (catdata.fqlpp.FunctorExp.InstConst)8 MapConst (catdata.fqlpp.FunctorExp.MapConst)8 SetSetConst (catdata.fqlpp.FunctorExp.SetSetConst)8 FinSet (catdata.fqlpp.cat.FinSet)7 Signature (catdata.fqlpp.cat.Signature)7 Chc (catdata.Chc)6 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)6 Cod (catdata.fqlpp.CatExp.Cod)6 Colim (catdata.fqlpp.CatExp.Colim)6 Dom (catdata.fqlpp.CatExp.Dom)6 Exp (catdata.fqlpp.CatExp.Exp)6 Kleisli (catdata.fqlpp.CatExp.Kleisli)6 Named (catdata.fqlpp.CatExp.Named)6