Search in sources :

Example 6 with Fn

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;
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) HashSet(java.util.HashSet)

Example 7 with Fn

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);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn)

Example 8 with Fn

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);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn)

Example 9 with Fn

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);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) List(java.util.List) Quad(catdata.Quad) FUNCTION(catdata.fqlpp.FUNCTION) Map(java.util.Map) Triple(catdata.Triple) Set(java.util.Set) HashMap(java.util.HashMap) Pair(catdata.Pair) Set(java.util.Set) Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) Triple(catdata.Triple) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with Fn

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;
}
Also used : Color(java.awt.Color) Edge(catdata.fqlpp.cat.Signature.Edge) Vector(java.util.Vector) Map(java.util.Map) FinCat(catdata.fqlpp.cat.FinCat) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) FunCat(catdata.fqlpp.cat.FunCat) JFrame(javax.swing.JFrame) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Pair(catdata.Pair) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) Fn(catdata.fqlpp.cat.FinSet.Fn) Quad(catdata.Quad) Function(com.google.common.base.Function) Disp(catdata.ide.Disp) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) Inst(catdata.fqlpp.cat.Inst) BorderFactory(javax.swing.BorderFactory) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Entry(java.util.Map.Entry) Triple(catdata.Triple) BasicStroke(java.awt.BasicStroke) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) Const(catdata.fqlpp.CatExp.Const) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Node(catdata.fqlpp.cat.Signature.Node) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Functor(catdata.fqlpp.cat.Functor) HashMap(java.util.HashMap) GridLayout(java.awt.GridLayout) Signature(catdata.fqlpp.cat.Signature) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) GUI(catdata.ide.GUI) LinkedList(java.util.LinkedList) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Transform(catdata.fqlpp.cat.Transform) Layout(edu.uci.ics.jung.algorithms.layout.Layout) CodeTextPanel(catdata.ide.CodeTextPanel) JList(javax.swing.JList) Util(catdata.Util) ActionEvent(java.awt.event.ActionEvent) FinSet(catdata.fqlpp.cat.FinSet) JScrollPane(javax.swing.JScrollPane) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Fn(catdata.fqlpp.cat.FinSet.Fn) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Functor(catdata.fqlpp.cat.Functor) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Transform(catdata.fqlpp.cat.Transform)

Aggregations

Fn (catdata.fqlpp.cat.FinSet.Fn)38 Pair (catdata.Pair)23 Set (java.util.Set)22 HashMap (java.util.HashMap)20 Map (java.util.Map)18 HashSet (java.util.HashSet)16 Chc (catdata.Chc)15 List (java.util.List)14 Triple (catdata.Triple)13 Util (catdata.Util)13 LinkedList (java.util.LinkedList)13 Functor (catdata.fqlpp.cat.Functor)12 Transform (catdata.fqlpp.cat.Transform)12 LinkedHashMap (java.util.LinkedHashMap)12 Entry (java.util.Map.Entry)12 Category (catdata.fqlpp.cat.Category)11 FinSet (catdata.fqlpp.cat.FinSet)11 Edge (catdata.fqlpp.cat.Signature.Edge)11 Node (catdata.fqlpp.cat.Signature.Node)11 Unit (catdata.Unit)10