use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class SetOps method visit.
@SuppressWarnings("unchecked")
@Override
public Set<?> visit(FQLPPProgram env, Range e) {
Fn f = e.f.accept(env, this);
Set<Object> ret = new HashSet<>();
for (Object o : f.source) {
ret.add(f.apply(o));
}
return ret;
}
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, Prod e) {
Fn s = e.l.accept(env, this);
Fn t = e.r.accept(env, this);
return FinSet.pair(s, t);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class SetOps method visit.
@Override
public Fn visit(FQLPPProgram env, Comp e) {
Fn l = e.l.accept(env, this);
Fn r = e.r.accept(env, this);
return FinSet.FinSet.compose(l, r);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class FDM method deltaPi.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Adjunction<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> deltaPi(Functor<O2, A2, O1, A1> F) {
Category<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> D = Inst.get(F.source);
Category<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> C = Inst.get(F.target);
FUNCTION<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> f = I -> {
Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, Functor.compose(F, I));
FUNCTION<O1, Fn> j = n -> new Fn<>(I.applyO(n), xxx.first.applyO(n), i -> {
outer: for (Map m : xxx.second.get(n)) {
for (int p = 1; p < m.size(); p++) {
if (xxx.third.get(n)[p - 1].third.equals(F.target.identity(n))) {
if (!m.get(p).equals(i)) {
continue outer;
}
}
}
return m.get(0);
}
throw new RuntimeException("Cannot find diagonal of " + i + " in " + xxx.second.get(n));
});
return new Transform<>(I, xxx.first, j);
};
Transform<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> unit = new Transform<>(Functor.identity(C), Functor.compose(deltaF(F), piF(F)), f);
FUNCTION<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> g = I -> {
Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, I);
Functor<O2, A2, Set, Fn> deltad = Functor.compose(F, xxx.first);
FUNCTION<O2, Fn> j = m -> {
O1 n = F.applyO(m);
Triple<O1, O2, A1>[] col = xxx.third.get(n);
Triple<O1, O2, A1> tofind = new Triple<>(n, m, F.target.identity(n));
Set<Map> lim = xxx.second.get(n);
int[] i = new int[] { 0 };
for (Triple<O1, O2, A1> cand : col) {
if (!cand.equals(tofind)) {
i[0]++;
continue;
}
FUNCTION h = id -> {
for (Map row : lim) {
if (row.get(0).equals(id)) {
return row.get(i[0] + 1);
}
}
throw new RuntimeException("Report this error to Ryan.");
};
return new Fn<>(deltad.applyO(m), I.applyO(m), h);
}
throw new RuntimeException("Report this error to Ryan.");
};
return new Transform<>(deltad, I, j);
};
Transform<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> counit = new Transform<>(Functor.compose(piF(F), deltaF(F)), Functor.identity(D), g);
return new Adjunction<>(deltaF(F), sigmaF(F), counit, unit);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class FqlppDisplay method doNTView.
@SuppressWarnings("unchecked")
private <X, Y> JComponent doNTView(Transform fn, JPanel p, Color clr, Graph<X, Y> sgv) {
// Layout<X, Y> layout = new FRLayout<>(sgv);
Layout<X, Y> layout = new FRLayout(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
Function<X, Paint> vertexPaint = z -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function www = arg0 -> Util.nice(arg0.toString());
vv.getRenderContext().setVertexLabelTransformer(www);
vv.getRenderContext().setEdgeLabelTransformer(www);
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
X str = ((X) e.getItem());
Object y = fn.apply(str);
p.removeAll();
if (y instanceof Functor) {
Functor ttt = (Functor) y;
JPanel sss = showFtr(ttt, getColor(ttt.source), null);
p.add(sss);
} else if (y instanceof Fn) {
Fn ttt = (Fn) y;
JPanel sss = showFn(ttt, getColor(ttt.source), getColor(ttt.target));
p.add(sss);
} else if (y instanceof Transform) {
Transform ttt = (Transform) y;
JPanel sss = showTrans(ttt, getColor(ttt.source));
p.add(sss);
} else {
String sss = Util.nice(y.toString());
p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
}
p.revalidate();
});
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
Aggregations