use of catdata.fqlpp.FunctorExp.CatConst in project fql by CategoricalData.
the class Ben method colim.
public static Const colim(FQLPPProgram env, CatConst f) {
if (!(f.sig instanceof CatExp.Var)) {
throw new RuntimeException(f.sig + " is not variable, is " + f.sig.getClass());
}
CatExp c = env.cats.get(((CatExp.Var) f.sig).v);
if (!(c instanceof Const)) {
throw new RuntimeException(c + " is not finitely presented, is " + c.getClass());
}
Const src = (Const) c;
Map<String, Const> obMapping = new HashMap<>();
Map<String, MapConst> arrMapping = new HashMap<>();
for (String src_ob : f.nm.keySet()) {
CatExp C = f.nm.get(src_ob);
if (!(C instanceof CatExp.Var)) {
throw new RuntimeException(C + " is not a variable");
}
CatExp D = env.cats.get(((CatExp.Var) C).v);
if (!(D instanceof Const)) {
throw new RuntimeException(D + " is not finitely presented");
}
obMapping.put(src_ob, (Const) D);
}
for (String src_arr : f.em.keySet()) {
FunctorExp C = f.em.get(src_arr);
if (!(C instanceof Var)) {
throw new RuntimeException(C + " is not a variable");
}
FunctorExp D = env.ftrs.get(((Var) C).v);
if (!(D instanceof MapConst)) {
throw new RuntimeException(D + " is not finitely presented");
}
arrMapping.put(src_arr, (MapConst) D);
}
return sandbox(src, obMapping, arrMapping);
}
use of catdata.fqlpp.FunctorExp.CatConst in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Category visit(FQLPPProgram env, Colim e) {
FunctorExp f = ENV.prog.ftrs.get(e.F);
if (f == null) {
throw new RuntimeException("Undefined functor: " + e.F);
}
if (!(f instanceof CatConst)) {
throw new RuntimeException("Not a literal: " + e.F + ", is " + f.getClass());
}
CatConst F = (CatConst) f;
Const C = Ben.colim(env, F);
return C.accept(env, this);
}
use of catdata.fqlpp.FunctorExp.CatConst in project fql by CategoricalData.
the class PPParser method toCatFtrConst.
private static FunctorExp toCatFtrConst(Object decl) {
Tuple5 y = (Tuple5) decl;
org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
Tuple3 nodes = (Tuple3) x.a;
Tuple3 arrows = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
List arrows0 = (List) arrows.b;
Map<String, CatExp> nodesX = new HashMap<>();
for (Object o : nodes0) {
if (nodesX.containsKey(o)) {
throw new RuntimeException("Duplicate object: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
CatExp l = toCat(u.c);
nodesX.put(n, l);
}
Map<String, FunctorExp> arrowsX = new HashMap<>();
for (Object o : arrows0) {
if (arrowsX.containsKey(o)) {
throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
FunctorExp l = toFtr(u.c);
arrowsX.put(n, l);
}
CatConst ret = new CatConst(toCat(y.c), nodesX, arrowsX);
return ret;
}
use of catdata.fqlpp.FunctorExp.CatConst 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