Search in sources :

Example 1 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, 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 Node

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

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, ToSet e) {
    Functor s = e.src.accept(env, this);
    Functor t = e.dst.accept(env, this);
    FUNCTION o = x -> {
        Node n = (Node) x;
        Chc<FnExp, SetExp> chc = e.fun.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing object mapping for: " + n.name);
        }
        if (chc.left) {
            return chc.l.accept(env, new SetOps(ENV));
        } else {
            Set src = (Set) s.applyO(n);
            Set dst = (Set) t.applyO(n);
            Set<Pair> p = (Set<Pair>) chc.r.accept(env, new SetOps(ENV));
            Map<Object, Object> map = new HashMap<>();
            for (Pair h : p) {
                if (map.containsKey(h.first)) {
                    throw new RuntimeException("Duplicate arg: " + e);
                }
                map.put(h.first, h.second);
            }
            return new Fn(src, dst, map::get);
        }
    };
    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) ToSet(catdata.fqlpp.TransExp.ToSet) FinSet(catdata.fqlpp.cat.FinSet) SetSet(catdata.fqlpp.TransExp.SetSet) Node(catdata.fqlpp.cat.Signature.Node) Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform) ToMap(catdata.fqlpp.TransExp.ToMap) Chc(catdata.Chc) Pair(catdata.Pair)

Example 3 with Node

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

the class FqlppDisplay method makeJoined.

@SuppressWarnings("unchecked")
private static Pair<JPanel, Map<Object, JPanel>> makeJoined(Signature<String, String> sig, Functor<Object, Object, Set, Fn<Object, Object>> F) {
    Map<Node, List<Signature<String, String>.Edge>> map = new HashMap<>();
    Map<Object, JPanel> mapX = new HashMap<>();
    for (Node n : sig.nodes) {
        map.put(n, new LinkedList<>());
    }
    for (Edge t : sig.edges) {
        map.get(t.source).add(t);
    }
    // int x = (int) Math.ceil(Math.sqrt(sig.nodes.size()));
    List<JComponent> ret = new LinkedList<>();
    for (Node n : sig.nodes) {
        List<Signature<String, String>.Edge> cols = map.get(n);
        Object[] colNames = new Object[cols.size() + 1];
        colNames[0] = "ID";
        Set set = F.applyO(n);
        Object[][] rowData = new Object[set.size()][cols.size() + 1];
        int j = 0;
        for (Object o : set) {
            rowData[j][0] = o;
            j++;
        }
        int i = 1;
        for (Signature<String, String>.Edge t : cols) {
            colNames[i] = t.name;
            Fn<Object, Object> fn = F.applyA(sig.path(t));
            j = 0;
            for (Object o : set) {
                rowData[j][i] = fn.apply(o);
                j++;
            }
            i++;
        }
        JPanel p = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), n + " (" + set.size() + " rows)", rowData, colNames);
        ret.add(p);
        mapX.put(n, p);
    }
    for (Signature<String, String>.Edge t : sig.edges) {
        Object[] colNames = new Object[2];
        colNames[0] = t.source;
        colNames[1] = t.target;
        Set set = F.applyO(t.source);
        Object[][] rowData = new Object[set.size()][2];
        Fn<Object, Object> fn = F.applyA(sig.path(t));
        int j = 0;
        for (Object o : set) {
            rowData[j][0] = o;
            rowData[j][1] = fn.apply(o);
            j++;
        }
        JPanel p = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), t.name + " (" + set.size() + " rows)", rowData, colNames);
        mapX.put(t.name, p);
    }
    return new Pair<>(GuiUtil.makeGrid(ret), mapX);
}
Also used : JPanel(javax.swing.JPanel) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) HashMap(java.util.HashMap) Node(catdata.fqlpp.cat.Signature.Node) JComponent(javax.swing.JComponent) LinkedList(java.util.LinkedList) Paint(java.awt.Paint) Signature(catdata.fqlpp.cat.Signature) List(java.util.List) LinkedList(java.util.LinkedList) JList(javax.swing.JList) Edge(catdata.fqlpp.cat.Signature.Edge) Pair(catdata.Pair)

Example 4 with Node

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

the class FqlppDisplay method build2Elements.

@SuppressWarnings("unchecked")
private static Graph build2Elements(Signature<Object, Object> sig, Transform<Object, Object, Set, Fn> trans) {
    Functor<Object, Object, Set, Fn> I = trans.source;
    Functor<Object, Object, Set, Fn> J = trans.target;
    Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
    for (Node n : sig.nodes) {
        for (Object o : I.applyO(n)) {
            ret.addVertex(new Triple<>(o, n.name, "src"));
        }
    }
    for (Edge e : sig.edges) {
        for (Object o : I.applyO(e.source)) {
            Object fo = I.applyA(sig.path(e)).apply(o);
            Triple s = new Triple<>(o, e.source.name, "src");
            Triple t = new Triple<>(fo, e.target.name, "dst");
            ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
        }
    }
    for (Node n : sig.nodes) {
        for (Object o : J.applyO(n)) {
            ret.addVertex(new Triple<>(o, n.name, "dst"));
        }
    }
    for (Edge e : sig.edges) {
        for (Object o : J.applyO(e.source)) {
            Object fo = J.applyA(sig.path(e)).apply(o);
            Triple s = new Triple<>(o, e.source.name, "dst");
            Triple t = new Triple<>(fo, e.target.name, "dst");
            ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
        }
    }
    int i = 0;
    for (Node n : sig.nodes) {
        for (Object o : I.applyO(n)) {
            Object fo = trans.apply(n).apply(o);
            Triple s = new Triple<>(o, n.name, "src");
            Triple t = new Triple<>(fo, n.name, "dst");
            ret.addEdge(new Quad<>("", s, t, i++), s, t);
        }
    }
    return ret;
}
Also used : Triple(catdata.Triple) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Node(catdata.fqlpp.cat.Signature.Node) Fn(catdata.fqlpp.cat.FinSet.Fn) Edge(catdata.fqlpp.cat.Signature.Edge) Paint(java.awt.Paint)

Example 5 with Node

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

the class FqlppDisplay method buildMapping.

@SuppressWarnings("unchecked")
private static Graph buildMapping(Signature<String, String> src, Signature<String, String> dst, Functor F) {
    Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
    for (Node n : src.nodes) {
        ret.addVertex(new Pair<>(n.name, "src"));
    }
    for (Edge e : src.edges) {
        Pair s = new Pair<>(e.source.name, "src");
        Pair t = new Pair<>(e.target.name, "src");
        ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
    }
    for (Node n : dst.nodes) {
        ret.addVertex(new Pair<>(n.name, "dst"));
    }
    for (Edge e : dst.edges) {
        Pair s = new Pair<>(e.source.name, "dst");
        Pair t = new Pair<>(e.target.name, "dst");
        ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
    }
    int i = 0;
    for (Node n : src.nodes) {
        Node fo = (Node) F.applyO(n);
        Pair s = new Pair<>(n.name, "src");
        Pair t = new Pair<>(fo.name, "dst");
        ret.addEdge(new Quad<>("", s, t, i++), s, t);
    }
    return ret;
}
Also used : DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Node(catdata.fqlpp.cat.Signature.Node) Edge(catdata.fqlpp.cat.Signature.Edge) Paint(java.awt.Paint) Pair(catdata.Pair)

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