Search in sources :

Example 31 with Fn

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

the class Inst method tru.

public Transform<O, A, Set, Fn> tru() {
    Set e = new HashSet<>();
    e.add(new Unit());
    Functor<O, A, Set, Fn> prp = (Functor<O, A, Set, Fn>) ((Object) prop());
    Pair<Map<O, Functor<O, A, Set<A>, Fn<A, A>>>, Map<A, Transform<O, A, Set<A>, Fn<A, A>>>> k = cat.repX();
    return new Transform<>(terminal(), prp, x -> new Fn<>(e, prp.applyO(x), z -> k.first.get(x)));
}
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) Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 32 with Fn

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

the class Inst method terminal.

public Transform<O, A, Set, Fn> terminal(Functor<O, A, Set, Fn> o) {
    Set<Unit> ret = new HashSet<>();
    ret.add(new Unit());
    FUNCTION<O, Fn> fn = x -> new Fn(o.applyO(x), ret, y -> new Unit());
    return new Transform<>(o, terminal(), fn);
}
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) Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) HashSet(java.util.HashSet)

Example 33 with Fn

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

the class LeftKanSigma method fullSigma.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Quad<Functor<O2, A2, Set, Fn>, Transform<O1, A1, Set, Fn>, Transform<O2, A2, Set, Fn>, Map<Object, List<Pair<A2, Object>>>> fullSigma(Functor<O1, A1, O2, A2> F, Functor<O1, A1, Set, Fn> I, Transform<O1, A1, Set, Fn> t, Functor<O2, A2, Set, Fn> JJJ) {
    Mapping<O1, A1, O2, A2> G = F.toMapping();
    FPTransform<O1, A1> m = null;
    if (t != null) {
        m = t.toFPTransform();
    }
    Instance<O2, A2> J = null;
    if (JJJ != null) {
        J = JJJ.toInstance();
    }
    Quad<Instance<O2, A2>, Map<Signature<O1, A1>.Node, Map<Object, Object>>, Map<Signature<O2, A2>.Node, Map<Object, Object>>, Map<Object, List<Pair<Signature<O2, A2>.Edge, Object>>>> q = fullSigmaOnPresentation(G, I.toInstance(), m, J, 100);
    Functor<Signature<O2, A2>.Node, Signature<O2, A2>.Path, Set, Fn> f2 = q.first.toFunctor();
    Functor<O2, A2, Set, Fn> f3 = new Functor<>(F.target, FinSet.FinSet, x -> f2.applyO(G.target.new Node(x)), a -> {
        if (F.target.isId(a)) {
            return Fn.id(f2.applyO(G.target.new Node(F.target.source(a))));
        }
        return f2.applyA(G.target.path(G.target.getEdge(a)));
    });
    // use third
    Transform<O2, A2, Set, Fn> thr = null;
    if (t != null) {
        if (JJJ == null) {
            throw new RuntimeException("Left kan sigma anomaly, please report");
        }
        thr = new Transform<>(f3, JJJ, x -> new Fn(f3.applyO(x), JJJ.applyO(x), q.third.get(G.target.new Node(x))::get));
    }
    Transform<O1, A1, Set, Fn> et = new Transform<>(I, Functor.compose(F, f3), x -> new Fn(I.applyO(x), Functor.compose(F, f3).applyO(x), q.second.get(G.source.new Node(x))::get));
    Map<Object, List<Pair<A2, Object>>> nq = new HashMap<>();
    for (Entry<Object, List<Pair<Signature<O2, A2>.Edge, Object>>> o : q.fourth.entrySet()) {
        List<Pair<A2, Object>> rt = new LinkedList<>();
        for (int j = 0; j < o.getValue().size(); j++) {
            Pair<Signature<O2, A2>.Edge, Object> fst = o.getValue().get(j);
            if (fst.first == null) {
                // because no guids, have pairs as first
                rt.add(new Pair<>(null, ((Pair) fst.second).second));
            } else {
                // 
                rt.add(new Pair<>(fst.first.name, fst.second));
            }
        }
        nq.put(o.getKey(), rt);
    }
    return new Quad<>(f3, et, thr, nq);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) List(java.util.List) Quad(catdata.Quad) Map(java.util.Map) Entry(java.util.Map.Entry) Util(catdata.Util) Set(java.util.Set) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Collectors(java.util.stream.Collectors) Pair(catdata.Pair) Quad(catdata.Quad) Set(java.util.Set) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Fn(catdata.fqlpp.cat.FinSet.Fn) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with Fn

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

the class Inst method union.

private Functor<O, A, Set, Fn> union(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<>();
        set.addAll(a.applyO(n));
        set.addAll(a.applyO(n));
        nm.put(n, set);
    }
    for (A n : cat.arrows()) {
        FUNCTION g = x -> {
            Object a_out = null;
            Object b_out = null;
            if (a.applyA(n).source.contains(x)) {
                a_out = a.applyA(n).apply(x);
            }
            if (b.applyA(n).source.contains(x)) {
                b_out = a.applyA(n).apply(x);
            }
            if (a_out != null && b_out != null && !a_out.equals(b_out)) {
                throw new RuntimeException("Report to Ryan: problem in union computation.");
            }
            if (a_out != null) {
                return a_out;
            }
            if (b_out != null) {
                return b_out;
            }
            throw new RuntimeException("Report to Ryan: problem in union computation.");
        };
        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 35 with Fn

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

the class Inst method chr.

public Transform<O, A, Set, Fn> chr(Transform<O, A, Set, Fn> t) {
    Functor<O, A, Set, Fn> I = t.source;
    Functor<O, A, Set, Fn> J = t.target;
    Pair<Map<O, Functor<O, A, Set<A>, Fn<A, A>>>, Map<A, Transform<O, A, Set<A>, Fn<A, A>>>> HH = I.source.repX();
    Map<O, Functor<O, A, Set, Fn>> H = ((Map<O, Functor<O, A, Set, Fn>>) ((Object) HH.first));
    Map<O, Fn> map = new HashMap<>();
    Functor<O, A, Set, Fn> prop = (Functor<O, A, Set, Fn>) ((Object) prop());
    for (O c : I.source.objects()) {
        Map<Object, Functor<O, A, Set, Fn>> m = new HashMap<>();
        for (Object x : J.applyO(c)) {
            Transform<O, A, Set, Fn> xx = new Transform<>(H.get(c), J, d -> new Fn<>(H.get(c).applyO(d), J.applyO(d), f -> J.applyA((A) f).apply(x)));
            Map<O, Set> pb1 = new HashMap<>();
            Map<A, Fn> pb2 = new HashMap<>();
            for (O d : I.source.objects()) {
                Set pb1x = new HashSet<>();
                for (Object y : H.get(c).applyO(d)) {
                    Set im = Util.image(t.apply(d).source, t.apply(d)::apply);
                    if (im.contains(xx.apply(d).apply(y))) {
                        pb1x.add(y);
                    }
                }
                pb1.put(d, pb1x);
            }
            for (A f : I.source.arrows()) {
                Fn pb2x = new Fn(pb1.get(I.source.source(f)), pb1.get(I.source.target(f)), q -> H.get(c).applyA(f).apply(q));
                pb2.put(f, pb2x);
            }
            m.put(x, new Functor<>(cat, FinSet.FinSet, pb1::get, pb2::get));
        }
        map.put(c, new Fn(J.applyO(c), prop().applyO(c), m::get));
    }
    return new Transform<>(J, prop, map::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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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