use of catdata.fqlpp.cat.Mapping in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, MapConst ic) {
Triple<Category, Category, Mapping<String, String, String, String>> xxx = toMapping(env, ic);
Mapping<String, String, String, String> I = xxx.third;
FUNCTION f = p0 -> {
Path p = (Path) p0;
return I.apply(p);
};
Functor et = new Functor(xxx.first, xxx.second, x -> I.nm.get(x), f);
et.mapping0 = xxx.third;
return et;
}
use of catdata.fqlpp.cat.Mapping in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, FinalConst ic) {
CatExp e = resolve(env, ic.src);
if (!(e instanceof Const)) {
throw new RuntimeException("Can only create functors from finitely-presented categories.");
}
Const c = (Const) e;
Category cat = c.accept(env, this);
Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
Category target = ic.C.accept(env, this);
Map<Node, Functor> nm = new HashMap<>();
for (Node n : sig.nodes) {
FunctorExp kkk = ic.nm.get(n.name);
if (kkk == null) {
throw new RuntimeException("Missing node mapping from " + n);
}
Functor F = kkk.accept(env, this);
nm.put(n, F);
}
Map<Edge, Transform> em = new HashMap<>();
for (Edge n : sig.edges) {
TransExp chc = ic.em.get(n.name);
if (chc == null) {
throw new RuntimeException("Missing edge mapping from " + n);
}
em.put(n, chc.accept(env, this));
}
FUNCTION fff = p0 -> {
Path p = (Path) p0;
Object fn = target.identity(nm.get(p.source));
for (Object nnn : p.path) {
Edge n = (Edge) nnn;
fn = target.compose(fn, em.get(n));
}
return fn;
};
return new Functor(cat, target, nm::get, fff);
}
use of catdata.fqlpp.cat.Mapping in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToSet e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
Chc<FnExp, SetExp> chc = e.fun.get(n.name);
if (chc == null) {
throw new RuntimeException("Missing object mapping for: " + n.name);
}
if (chc.left) {
return chc.l.accept(env, new SetOps(ENV));
} else {
Set src = (Set) s.applyO(n);
Set dst = (Set) t.applyO(n);
Set<Pair> p = (Set<Pair>) chc.r.accept(env, new SetOps(ENV));
Map<Object, Object> map = new HashMap<>();
for (Pair h : p) {
if (map.containsKey(h.first)) {
throw new RuntimeException("Duplicate arg: " + e);
}
map.put(h.first, h.second);
}
return new Fn(src, dst, map::get);
}
};
return new Transform(s, t, o);
}
use of catdata.fqlpp.cat.Mapping in project fql by CategoricalData.
the class CatOps method toMapping.
private Triple<Category, Category, Mapping<String, String, String, String>> toMapping(FQLPPProgram env, MapConst ic) {
CatExp src0 = resolve(env, ic.src);
if (src0 == null) {
throw new RuntimeException("Missing category: " + ic.src);
}
if (!(src0 instanceof Const)) {
throw new RuntimeException("Can only create mappings for finitely-presented categories.");
}
Const src = (Const) src0;
CatExp dst0 = resolve(env, ic.dst);
if (!(dst0 instanceof Const)) {
throw new RuntimeException("Can only create mappings for finitely-presented categories.");
}
Const dst = (Const) dst0;
Category srcX = src.accept(env, this);
Category dstX = dst.accept(env, this);
Signature<String, String> srcY = new Signature<>(src.nodes, src.arrows, src.eqs);
Signature<String, String> dstY = new Signature<>(dst.nodes, dst.arrows, dst.eqs);
Map<Node, Node> nm = new HashMap<>();
for (String n0 : ic.nm.keySet()) {
Signature<String, String>.Node n = srcY.getNode(n0);
String v = ic.nm.get(n.name);
if (v == null) {
throw new RuntimeException("Missing object mapping for " + n.name);
}
nm.put(n, dstY.getNode(v));
}
Map<Edge, Path> em = new HashMap<>();
for (String n0 : ic.em.keySet()) {
Signature<String, String>.Edge n = srcY.getEdge(n0);
Pair<String, List<String>> k = ic.em.get(n.name);
if (k == null) {
throw new RuntimeException("Missing arrow mapping for " + n.name);
}
em.put(n, dstY.path(k.first, k.second));
}
Mapping<String, String, String, String> I = new Mapping(nm, em, srcY, dstY);
return new Triple<>(srcX, dstX, I);
}
use of catdata.fqlpp.cat.Mapping in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, CatConst ic) {
CatExp e = resolve(env, ic.sig);
if (!(e instanceof Const)) {
throw new RuntimeException("Can only create functors to cat from finitely-presented categories.");
}
Const c = (Const) e;
Category cat = c.accept(env, this);
Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
Map<Node, Category> nm = new HashMap<>();
for (Node n : sig.nodes) {
CatExp kkk = ic.nm.get(n.name);
if (kkk == null) {
throw new RuntimeException("Missing node mapping from " + n);
}
nm.put(n, kkk.accept(env, this));
}
Map<Edge, Functor> em = new HashMap<>();
for (Edge n : sig.edges) {
FunctorExp chc = ic.em.get(n.name);
if (chc == null) {
throw new RuntimeException("Missing edge mapping from " + n);
}
em.put(n, chc.accept(env, this));
}
FUNCTION fff = p0 -> {
Path p = (Path) p0;
Functor fn = FinCat.FinCat.identity(nm.get(p.source));
for (Object nnn : p.path) {
Edge n = (Edge) nnn;
fn = FinCat.FinCat.compose(fn, em.get(n));
}
return fn;
};
return new Functor(cat, FinCat.FinCat, nm::get, fff);
}
Aggregations