Search in sources :

Example 16 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method isect.

private Functor<O, A, Set, Fn> isect(Functor<O, A, Set, Fn> a, Functor<O, A, Set, Fn> b) {
    Map<O, Set> nm = new HashMap<>();
    Map<A, Fn> em = new HashMap<>();
    for (O n : cat.objects()) {
        Set set = new HashSet<>();
        for (Object p : a.applyO(n)) {
            if (b.applyO(n).contains(p)) {
                set.add(p);
            }
        }
        nm.put(n, set);
    }
    for (A n : cat.arrows()) {
        FUNCTION g = x -> {
            Object p = a.applyA(n).apply(x);
            Object q = b.applyA(n).apply(x);
            if (!p.equals(q)) {
                throw new RuntimeException("Report to Ryan: problem in intersection computation.");
            }
            return p;
        };
        Fn f = new Fn<>(nm.get(cat.source(n)), nm.get(cat.target(n)), g);
        em.put(n, f);
    }
    return new Functor<>(cat, FinSet.FinSet, nm::get, em::get);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) Chc(catdata.Chc) Util(catdata.Util) Set(java.util.Set) HashMap(java.util.HashMap) Unit(catdata.Unit) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) HashSet(java.util.HashSet)

Example 17 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method initial.

public Functor<O, A, Set, Fn> initial() {
    Set ret = new HashSet<>();
    Fn fn = new Fn<>(ret, ret, x -> {
        throw new RuntimeException();
    });
    return new Functor<>(cat, FinSet.FinSet, x -> ret, x -> fn);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Fn(catdata.fqlpp.cat.FinSet.Fn) HashSet(java.util.HashSet)

Example 18 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method terminal.

public Functor<O, A, Set, Fn> terminal() {
    Set<Unit> ret = new HashSet<>();
    ret.add(new Unit());
    Fn<Unit, Unit> fn = new Fn<>(ret, ret, x -> new Unit());
    return new Functor<>(cat, FinSet.FinSet, x -> ret, x -> fn);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) HashSet(java.util.HashSet)

Example 19 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Transform method toFPTransX.

@SuppressWarnings({ "unchecked", "rawtypes" })
private FPTransform<O1, A1> toFPTransX() {
    if (source.source.isInfinite() || !source.target.equals(FinSet.FinSet)) {
        throw new RuntimeException("Cannot create FP transform from " + this);
    }
    Map<Signature<O1, A1>.Node, Map<Object, Object>> data = new HashMap<>();
    for (Signature<O1, A1>.Node n : source.source.toSig().nodes) {
        Fn f = (Fn) t.apply(n.name);
        data.put(n, Util.reify(f::apply, f.source));
    }
    return new FPTransform<>(source.toInstance(), target.toInstance(), data);
}
Also used : HashMap(java.util.HashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with Fn

use of catdata.fqlpp.cat.FinSet.Fn 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)

Aggregations

Fn (catdata.fqlpp.cat.FinSet.Fn)38 Pair (catdata.Pair)23 Set (java.util.Set)22 HashMap (java.util.HashMap)20 Map (java.util.Map)18 HashSet (java.util.HashSet)16 Chc (catdata.Chc)15 List (java.util.List)14 Triple (catdata.Triple)13 Util (catdata.Util)13 LinkedList (java.util.LinkedList)13 Functor (catdata.fqlpp.cat.Functor)12 Transform (catdata.fqlpp.cat.Transform)12 LinkedHashMap (java.util.LinkedHashMap)12 Entry (java.util.Map.Entry)12 Category (catdata.fqlpp.cat.Category)11 FinSet (catdata.fqlpp.cat.FinSet)11 Edge (catdata.fqlpp.cat.Signature.Edge)11 Node (catdata.fqlpp.cat.Signature.Node)11 Unit (catdata.Unit)10