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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations