use of catdata.fqlpp.cat.FinSet.Fn 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.FinSet.Fn 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.FinSet.Fn in project fql by CategoricalData.
the class PPParser method toValue.
private static Object toValue(Object o) {
if (o.toString().equals("true")) {
return true;
}
if (o.toString().equals("false")) {
return false;
}
if (o instanceof Tuple5) {
Tuple5 t = (Tuple5) o;
if (t.a.toString().equals("(")) {
return new Pair(toValue(t.b), toValue(t.d));
}
List l = (List) t.b;
Map s = new HashMap();
for (Object y : l) {
Pair yy = (Pair) toValue(y);
if (s.containsKey(yy.first)) {
throw new RuntimeException("Duplicate domain entry in " + o);
}
s.put(yy.first, yy.second);
}
Tuple3 tt = (Tuple3) t.e;
Set ui = (Set) toValue(tt.a);
Set uj = (Set) toValue(tt.c);
return new Fn(ui, uj, s::get);
}
if (o instanceof Tuple3) {
Tuple3 p = (Tuple3) o;
List l = (List) p.b;
Set s = new HashSet();
for (Object y : l) {
s.add(toValue(y));
}
return s;
}
if (o instanceof org.jparsec.functors.Pair) {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
if (p.a.toString().equals("inl")) {
return Chc.inLeft(toValue(p.b));
} else if (p.a.toString().equals("inr")) {
return Chc.inRight(toValue(p.b));
} else {
return new Unit();
}
}
return o.toString();
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class SetOps method visit.
@SuppressWarnings("unchecked")
@Override
public Fn visit(FQLPPProgram env, Apply e) {
FunctorExp k = env.ftrs.get(e.f);
if (k == null) {
throw new RuntimeException("Missing functor: " + e.f);
}
Fn s = e.set.accept(env, this);
Functor f = k.accept(env, new CatOps(ENV));
if (!FinSet.FinSet.equals(f.source)) {
throw new RuntimeException("Domain is not Set in " + e);
}
if (!FinSet.FinSet.equals(f.target)) {
throw new RuntimeException("Codomain is not Set in " + e);
}
return (Fn) f.applyA(s);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class SetOps method visit.
@SuppressWarnings("unchecked")
@Override
public Fn visit(FQLPPProgram env, ApplyTrans e) {
TransExp k = env.trans.get(e.f);
if (k == null) {
throw new RuntimeException("Missing transform: " + e.f);
}
Transform f = k.accept(env, new CatOps(ENV));
if (!FinSet.FinSet.equals(f.source.source)) {
throw new RuntimeException("Domain is not Set in " + e);
}
if (!FinSet.FinSet.equals(f.target.target)) {
throw new RuntimeException("Codomain is not Set in " + e);
}
Set<?> s = e.set.accept(env, this);
return (Fn) f.apply(s);
}
Aggregations