use of catdata.fqlpp.cat.FiniteCategory in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, Pushout e) {
Transform l = ENV.trans.get(e.l);
if (l == null) {
throw new RuntimeException("Missing transform: " + e.l);
}
Transform r = ENV.trans.get(e.r);
if (r == null) {
throw new RuntimeException("Missing transform: " + e.r);
}
if (!l.source.equals(r.source)) {
throw new RuntimeException("Source functors do not match.");
}
Category<Object, Object> D = l.source.source;
Set<String> objects = new HashSet<>();
objects.add("A");
objects.add("B");
objects.add("C");
Set<String> arrows = new HashSet<>();
arrows.add("f");
arrows.add("g");
arrows.add("a");
arrows.add("b");
arrows.add("c");
Map<String, String> sources = new HashMap<>();
sources.put("f", "A");
sources.put("g", "A");
sources.put("a", "A");
sources.put("b", "B");
sources.put("c", "C");
Map<String, String> targets = new HashMap<>();
targets.put("f", "B");
targets.put("g", "C");
targets.put("a", "A");
targets.put("b", "B");
targets.put("c", "C");
Map<Pair<String, String>, String> composition = new HashMap<>();
composition.put(new Pair<>("a", "a"), "a");
composition.put(new Pair<>("b", "b"), "b");
composition.put(new Pair<>("c", "c"), "c");
composition.put(new Pair<>("a", "f"), "f");
composition.put(new Pair<>("a", "g"), "g");
composition.put(new Pair<>("f", "b"), "f");
composition.put(new Pair<>("g", "c"), "g");
Map<String, String> identities = new HashMap<>();
identities.put("A", "a");
identities.put("B", "b");
identities.put("C", "c");
Category<String, String> span = new FiniteCategory<>(objects, arrows, sources, targets, composition, identities);
Category<Pair<Object, String>, Pair<Object, String>> Dspan = FinCat.product(D, span);
Functor<Pair<Object, String>, Pair<Object, String>, Object, Object> fst = FinCat.first(D, span);
FUNCTION<Pair<Object, String>, Set> o = p -> {
switch(p.second) {
case "A":
return (Set) l.source.applyO(p.first);
case "B":
return (Set) l.target.applyO(p.first);
case "C":
return (Set) r.target.applyO(p.first);
default:
throw new RuntimeException();
}
};
FUNCTION<Pair<Object, String>, Fn> x = fp -> {
Object f = fp.first;
String p = fp.second;
Object a = D.source(f);
// Object b = D.target(f);
// String i = span.source(p);
String j = span.target(p);
// Functor I = i == "A" ? l.source : i == "B" ? l.target : r.target;
Functor J = Objects.equals(j, "A") ? l.source : Objects.equals(j, "B") ? l.target : r.target;
// Fn If = (Fn) I.applyA(f);
Fn Jf = (Fn) J.applyA(f);
Transform P = Objects.equals(p, "f") ? l : Objects.equals(p, "g") ? r : Objects.equals(p, "a") ? Transform.id(l.source) : Objects.equals(p, "b") ? Transform.id(l.target) : Transform.id(r.target);
// Fn Pb = (Fn) P.apply(b);
Fn Pa = (Fn) P.apply(a);
return Fn.compose(Pa, Jf);
};
Functor I = new Functor(Dspan, FinSet.FinSet0(), o, x);
return FDM.sigmaF(fst).applyO(I);
}
Aggregations