Search in sources :

Example 1 with FUNCTION

use of catdata.fqlpp.FUNCTION in project fql by CategoricalData.

the class FDM method deltaPi.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Adjunction<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> deltaPi(Functor<O2, A2, O1, A1> F) {
    Category<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> D = Inst.get(F.source);
    Category<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> C = Inst.get(F.target);
    FUNCTION<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> f = I -> {
        Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, Functor.compose(F, I));
        FUNCTION<O1, Fn> j = n -> new Fn<>(I.applyO(n), xxx.first.applyO(n), i -> {
            outer: for (Map m : xxx.second.get(n)) {
                for (int p = 1; p < m.size(); p++) {
                    if (xxx.third.get(n)[p - 1].third.equals(F.target.identity(n))) {
                        if (!m.get(p).equals(i)) {
                            continue outer;
                        }
                    }
                }
                return m.get(0);
            }
            throw new RuntimeException("Cannot find diagonal of " + i + " in " + xxx.second.get(n));
        });
        return new Transform<>(I, xxx.first, j);
    };
    Transform<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> unit = new Transform<>(Functor.identity(C), Functor.compose(deltaF(F), piF(F)), f);
    FUNCTION<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> g = I -> {
        Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, I);
        Functor<O2, A2, Set, Fn> deltad = Functor.compose(F, xxx.first);
        FUNCTION<O2, Fn> j = m -> {
            O1 n = F.applyO(m);
            Triple<O1, O2, A1>[] col = xxx.third.get(n);
            Triple<O1, O2, A1> tofind = new Triple<>(n, m, F.target.identity(n));
            Set<Map> lim = xxx.second.get(n);
            int[] i = new int[] { 0 };
            for (Triple<O1, O2, A1> cand : col) {
                if (!cand.equals(tofind)) {
                    i[0]++;
                    continue;
                }
                FUNCTION h = id -> {
                    for (Map row : lim) {
                        if (row.get(0).equals(id)) {
                            return row.get(i[0] + 1);
                        }
                    }
                    throw new RuntimeException("Report this error to Ryan.");
                };
                return new Fn<>(deltad.applyO(m), I.applyO(m), h);
            }
            throw new RuntimeException("Report this error to Ryan.");
        };
        return new Transform<>(deltad, I, j);
    };
    Transform<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> counit = new Transform<>(Functor.compose(piF(F), deltaF(F)), Functor.identity(D), g);
    return new Adjunction<>(deltaF(F), sigmaF(F), counit, unit);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) List(java.util.List) Quad(catdata.Quad) FUNCTION(catdata.fqlpp.FUNCTION) Map(java.util.Map) Triple(catdata.Triple) Set(java.util.Set) HashMap(java.util.HashMap) Pair(catdata.Pair) Set(java.util.Set) Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) Triple(catdata.Triple) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with FUNCTION

use of catdata.fqlpp.FUNCTION 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 3 with FUNCTION

use of catdata.fqlpp.FUNCTION in project fql by CategoricalData.

the class Inst method initial.

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

Example 4 with FUNCTION

use of catdata.fqlpp.FUNCTION 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 5 with FUNCTION

use of catdata.fqlpp.FUNCTION 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)

Aggregations

Pair (catdata.Pair)5 FUNCTION (catdata.fqlpp.FUNCTION)5 Fn (catdata.fqlpp.cat.FinSet.Fn)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 Chc (catdata.Chc)4 Unit (catdata.Unit)4 Util (catdata.Util)4 HashSet (java.util.HashSet)4 LinkedHashMap (java.util.LinkedHashMap)4 LinkedList (java.util.LinkedList)4 Entry (java.util.Map.Entry)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Quad (catdata.Quad)1 Triple (catdata.Triple)1