use of catdata.fqlpp.CatExp.Const 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.CatExp.Const 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.CatExp.Const 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.CatExp.Const in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ApplyPath e) {
Functor F = e.F.accept(env, this);
CatExp c = resolve(env, e.cat);
if (!(c instanceof Const)) {
throw new RuntimeException("Can only take paths in constant categories.");
}
Const C = (Const) c;
Signature s = new Signature(C.nodes, C.arrows, C.eqs);
Path n = s.path(e.node, e.edges);
return (Transform) F.applyA(n);
}
use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.
the class FqlppDisplay method showTrans.
@SuppressWarnings("unchecked")
private JPanel showTrans(Transform view, Color c) {
JTabbedPane px = new JTabbedPane();
if (view.source.source.isInfinite()) {
CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, "Cannot display transforms from " + view.source.source);
px.add("Text", p);
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
Signature<Object, Object> src_sig = null;
// Signature<Object, Object> dst_sig = null;
String src_key = unr(env.cats, view.source.source, null);
if (src_key == null) {
src_key = unr(env.cats, view.target.source, null);
}
if (src_key != null) {
CatExp r = CatOps.resolve(prog, prog.cats.get(src_key));
if (r instanceof Const) {
Const sig0 = (Const) r;
src_sig = new Signature(sig0.nodes, sig0.arrows, sig0.eqs);
}
}
if (src_sig != null && FinSet.FinSet.equals(view.target.target)) {
// JPanel vwr = new JPanel(new GridLayout(1, 1));
if (DefunctGlobalOptions.debug.fqlpp.trans_elements) {
Graph g = build2Elements(src_sig, view);
if (g.getVertexCount() == 0) {
px.add("Elements", new JPanel());
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
px.add("Elements", xxx);
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
px.add("Elements", xxx);
} else {
JComponent zzz = doElements2View(c, g);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(zzz);
px.add("Elements", xxx);
}
}
}
if (DefunctGlobalOptions.debug.fqlpp.trans_graph) {
JPanel vwr = new JPanel(new GridLayout(1, 1));
if (view.source.source.objects().isEmpty()) {
px.add("Graph", vwr);
} else {
JComponent zzz = doNTView(view, vwr, c, buildFromCat(view.source.source));
JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
newthing.setResizeWeight(.5d);
newthing.add(zzz);
newthing.add(vwr);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(newthing);
px.add("Graph", xxx);
}
}
if (DefunctGlobalOptions.debug.fqlpp.trans_tabular) {
JPanel gp = new JPanel(new GridLayout(1, 1));
Object[][] rowData = new Object[view.source.source.objects().size()][2];
int i = 0;
for (Object o : view.source.source.objects()) {
rowData[i][0] = Util.nice(o.toString());
rowData[i][1] = Util.nice(view.apply(o).toString());
i++;
}
Object[] colNames = new Object[] { "Input", "Output" };
JPanel gp1 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Objects (" + view.source.source.objects().size() + ")", rowData, colNames);
gp.add(gp1);
px.add("Table", gp);
}
if (DefunctGlobalOptions.debug.fqlpp.trans_textual) {
CodeTextPanel gp = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", Util.nice(view.toString()));
px.add("Text", gp);
}
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
Aggregations