use of catdata.fqlpp.cat.FinSet.Fn 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.cat.FinSet.Fn in project fql by CategoricalData.
the class Inst method initial.
public Functor<O, A, Set, Fn> initial() {
Set ret = new HashSet<>();
Fn fn = new Fn<>(ret, ret, x -> {
throw new RuntimeException();
});
return new Functor<>(cat, FinSet.FinSet, x -> ret, x -> fn);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class Inst method terminal.
public Functor<O, A, Set, Fn> terminal() {
Set<Unit> ret = new HashSet<>();
ret.add(new Unit());
Fn<Unit, Unit> fn = new Fn<>(ret, ret, x -> new Unit());
return new Functor<>(cat, FinSet.FinSet, x -> ret, x -> fn);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class Transform method toFPTransX.
@SuppressWarnings({ "unchecked", "rawtypes" })
private FPTransform<O1, A1> toFPTransX() {
if (source.source.isInfinite() || !source.target.equals(FinSet.FinSet)) {
throw new RuntimeException("Cannot create FP transform from " + this);
}
Map<Signature<O1, A1>.Node, Map<Object, Object>> data = new HashMap<>();
for (Signature<O1, A1>.Node n : source.source.toSig().nodes) {
Fn f = (Fn) t.apply(n.name);
data.put(n, Util.reify(f::apply, f.source));
}
return new FPTransform<>(source.toInstance(), target.toInstance(), data);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class FqlppDisplay method build2Elements.
@SuppressWarnings("unchecked")
private static Graph build2Elements(Signature<Object, Object> sig, Transform<Object, Object, Set, Fn> trans) {
Functor<Object, Object, Set, Fn> I = trans.source;
Functor<Object, Object, Set, Fn> J = trans.target;
Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
for (Node n : sig.nodes) {
for (Object o : I.applyO(n)) {
ret.addVertex(new Triple<>(o, n.name, "src"));
}
}
for (Edge e : sig.edges) {
for (Object o : I.applyO(e.source)) {
Object fo = I.applyA(sig.path(e)).apply(o);
Triple s = new Triple<>(o, e.source.name, "src");
Triple t = new Triple<>(fo, e.target.name, "dst");
ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
}
}
for (Node n : sig.nodes) {
for (Object o : J.applyO(n)) {
ret.addVertex(new Triple<>(o, n.name, "dst"));
}
}
for (Edge e : sig.edges) {
for (Object o : J.applyO(e.source)) {
Object fo = J.applyA(sig.path(e)).apply(o);
Triple s = new Triple<>(o, e.source.name, "dst");
Triple t = new Triple<>(fo, e.target.name, "dst");
ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
}
}
int i = 0;
for (Node n : sig.nodes) {
for (Object o : I.applyO(n)) {
Object fo = trans.apply(n).apply(o);
Triple s = new Triple<>(o, n.name, "src");
Triple t = new Triple<>(fo, n.name, "dst");
ret.addEdge(new Quad<>("", s, t, i++), s, t);
}
}
return ret;
}
Aggregations