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