Search in sources :

Example 1 with Unit

use of catdata.Unit 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();
}
Also used : Set(java.util.Set) ToSet(catdata.fqlpp.TransExp.ToSet) HashSet(java.util.HashSet) SetSet(catdata.fqlpp.TransExp.SetSet) HashMap(java.util.HashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) Tuple5(org.jparsec.functors.Tuple5) Scanners(org.jparsec.Scanners) Plus(catdata.fqlpp.CatExp.Plus) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) Parsers(org.jparsec.Parsers) Times(catdata.fqlpp.CatExp.Times) Terminals(org.jparsec.Terminals) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) ToMap(catdata.fqlpp.TransExp.ToMap) HashMap(java.util.HashMap) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 2 with Unit

use of catdata.Unit in project fql by CategoricalData.

the class Inst method kernel.

public Transform<O, A, Set, Fn> kernel(Transform<O, A, Set, Fn> L) {
    Functor<O, A, Set, Fn> J = L.source;
    Map<O, Set> nm = new HashMap<>();
    Map<A, Fn> em = new HashMap<>();
    Map<O, Fn> t = new HashMap<>();
    for (O d : J.source.objects()) {
        Set s = new HashSet<>();
        for (Object x : J.applyO(d)) {
            if (L.apply(d).apply(x).equals(tru().apply(d).apply(new Unit()))) {
                s.add(x);
            }
        }
        nm.put(d, s);
        t.put(d, new Fn<>(s, J.applyO(d), x -> x));
    }
    for (A f : J.source.arrows()) {
        em.put(f, new Fn<>(nm.get(J.source.source(f)), nm.get(J.source.target(f)), x -> J.applyA(f).apply(x)));
    }
    Functor<O, A, Set, Fn> I = new Functor<>(cat, FinSet.FinSet, nm::get, em::get);
    return new Transform<>(I, J, t::get);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) Chc(catdata.Chc) Util(catdata.Util) Set(java.util.Set) HashMap(java.util.HashMap) Unit(catdata.Unit) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) Set(java.util.Set) Unit(catdata.Unit) HashSet(java.util.HashSet) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 3 with Unit

use of catdata.Unit in project fql by CategoricalData.

the class Inst method terminal.

public Functor<O, A, Set, Fn> terminal() {
    Set<Unit> ret = new HashSet<>();
    ret.add(new Unit());
    Fn<Unit, Unit> fn = new Fn<>(ret, ret, x -> new Unit());
    return new Functor<>(cat, FinSet.FinSet, x -> ret, x -> fn);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) HashSet(java.util.HashSet)

Example 4 with Unit

use of catdata.Unit in project fql by CategoricalData.

the class OplOptions method display.

@Override
public Pair<JComponent, Function<Unit, Unit>> display() {
    JPanel opl1 = new JPanel(new GridLayout(Options.biggestSize, 1));
    JPanel opl2 = new JPanel(new GridLayout(Options.biggestSize, 1));
    JSplitPane oplsplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    oplsplit.add(opl1);
    oplsplit.add(opl2);
    JCheckBox opl_validate_box = new JCheckBox("", opl_validate);
    JLabel opl_validate_label = new JLabel("Validate mappings:");
    opl1.add(opl_validate_label);
    opl2.add(opl_validate_box);
    JCheckBox opl_unfailing_box = new JCheckBox("", opl_prover_unfailing);
    JLabel opl_unfailing_label = new JLabel("Allow unorientable equations:");
    opl1.add(opl_unfailing_label);
    opl2.add(opl_unfailing_box);
    JCheckBox opl_const_box = new JCheckBox("", opl_prover_require_const);
    JLabel opl_const_label = new JLabel("Require a constant at each sort (false=dangerous):");
    opl2.add(opl_const_box);
    opl1.add(opl_const_label);
    JCheckBox opl_reorder_box = new JCheckBox("", opl_reorder_joins);
    JLabel opl_reorder_label = new JLabel("Reorder joins:");
    opl2.add(opl_reorder_box);
    opl1.add(opl_reorder_label);
    JCheckBox opl_semantic_ac_box = new JCheckBox("", opl_prover_ac);
    JLabel opl_semantic_ac_label = new JLabel("Enable Semantic AC optimization in Knuth-Bendix:");
    opl2.add(opl_semantic_ac_box);
    opl1.add(opl_semantic_ac_label);
    JTextField opl_iterations_box = new JTextField(Integer.toString(opl_prover_timeout), 12);
    JLabel opl_iterations_label = new JLabel("Knuth-Bendix timeout (ms)");
    opl2.add(wrap(opl_iterations_box));
    opl1.add(opl_iterations_label);
    JTextField opl_homit_box = new JTextField(Integer.toString(opl_saturate_timeout), 12);
    JLabel opl_homit_label = new JLabel("Saturation timeout (ms)");
    opl2.add(wrap(opl_homit_box));
    opl1.add(opl_homit_label);
    JTextField opl_red_box = new JTextField(Integer.toString(opl_prover_reduction_limit), 12);
    JLabel opl_red_label = new JLabel("Reduction iterations maximum");
    opl2.add(wrap(opl_red_box));
    opl1.add(opl_red_label);
    JCheckBox opl_pretty_box = new JCheckBox("", opl_pretty_print);
    JLabel opl_pretty_label = new JLabel("Pretty Print terms:");
    opl2.add(opl_pretty_box);
    opl1.add(opl_pretty_label);
    JCheckBox opl_suppress_box = new JCheckBox("", opl_suppress_dom);
    JLabel opl_suppress_label = new JLabel("Supress instance domains:");
    opl2.add(opl_suppress_box);
    opl1.add(opl_suppress_label);
    JCheckBox opl_horn_box = new JCheckBox("", opl_allow_horn);
    JLabel opl_horn_label = new JLabel("Allow implications in theories (dangerous, also can't check mappings):");
    opl2.add(opl_horn_box);
    opl1.add(opl_horn_label);
    JCheckBox opl_eqs_box = new JCheckBox("", opl_query_check_eqs);
    JLabel opl_eqs_label = new JLabel("Check that queries preserve equalities:");
    opl2.add(opl_eqs_box);
    opl1.add(opl_eqs_label);
    JCheckBox opl_simpl_box = new JCheckBox("", opl_pushout_simpl);
    JLabel opl_simpl_label = new JLabel("Simplify pushout schemas:");
    opl2.add(opl_simpl_box);
    opl1.add(opl_simpl_label);
    JCheckBox opl_lazy_box = new JCheckBox("", opl_lazy_gui);
    JLabel opl_lazy_label = new JLabel("Lazily compute gui:");
    opl2.add(opl_lazy_box);
    opl1.add(opl_lazy_label);
    JCheckBox opl_sort_box = new JCheckBox("", opl_prover_sort);
    JLabel opl_sort_label = new JLabel("In prover, sort critical pairs by length:");
    opl2.add(opl_sort_box);
    opl1.add(opl_sort_label);
    JCheckBox opl_selfsub_box = new JCheckBox("", opl_prover_filter_subsumed);
    JLabel opl_selfsub_label = new JLabel("In prover, filter self-subsumed equations:");
    opl2.add(opl_selfsub_box);
    opl1.add(opl_selfsub_label);
    JCheckBox opl_compose_box = new JCheckBox("", opl_prover_compose);
    JLabel opl_compose_label = new JLabel("In prover, compose equations:");
    opl2.add(opl_compose_box);
    opl1.add(opl_compose_label);
    JCheckBox opl_prec_box = new JCheckBox("", opl_prover_force_prec);
    JLabel opl_prec_label = new JLabel("In prover, force gens < consts < atts < fkeys precedence:");
    opl2.add(opl_prec_box);
    opl1.add(opl_prec_label);
    JCheckBox opl_cache_box = new JCheckBox("", opl_cache_gui);
    JLabel opl_cache_label = new JLabel("Cache artifacts between runs (true=not tested thoroughly):");
    opl2.add(opl_cache_box);
    opl1.add(opl_cache_label);
    JCheckBox opl_consistency_box = new JCheckBox("", opl_require_consistency);
    JLabel opl_consistency_label = new JLabel("Ensure consistency by requiring free type algebras:");
    opl2.add(opl_consistency_box);
    opl1.add(opl_consistency_label);
    JCheckBox opl_nat_sugar_box = new JCheckBox("", opl_desugar_nat);
    JLabel opl_nat_sugar_label = new JLabel("When possible desugar numerals into zero:Nat and succ:Nat->Nat:");
    opl2.add(opl_nat_sugar_box);
    opl1.add(opl_nat_sugar_label);
    JCheckBox opl_print_simpl_pres_box = new JCheckBox("", opl_print_simplified_presentations);
    JLabel opl_print_simpl_pres_label = new JLabel("Print simplified presentations (true=not canonical):");
    opl2.add(opl_print_simpl_pres_box);
    opl1.add(opl_print_simpl_pres_label);
    JCheckBox opl_fresh_ids_box = new JCheckBox("", opl_display_fresh_ids);
    JLabel opl_fresh_ids_label = new JLabel("Display fresh IDs:");
    opl2.add(opl_fresh_ids_box);
    opl1.add(opl_fresh_ids_label);
    JCheckBox opl_simplify_box = new JCheckBox("", opl_prover_simplify_instances);
    JLabel opl_simplify_label = new JLabel("Simplify instances before doing theorem proving:");
    opl2.add(opl_simplify_box);
    opl1.add(opl_simplify_label);
    JCheckBox opl_safejava_box = new JCheckBox("", opl_safe_java);
    JLabel opl_safejava_label = new JLabel("Require use of java typesides to be complete (false=dangerous):");
    opl2.add(opl_safejava_box);
    opl1.add(opl_safejava_label);
    JCheckBox opl_agg_box = new JCheckBox("", opl_secret_agg);
    JLabel opl_agg_label = new JLabel("Allow ad-hoc aggregation (true=dangerous):");
    opl2.add(opl_agg_box);
    opl1.add(opl_agg_label);
    for (int i = 0; i < Options.biggestSize - size(); i++) {
        opl1.add(new JLabel());
        opl2.add(new JLabel());
    }
    Function<Unit, Unit> fn = (Unit t) -> {
        try {
            int opl = opl_prover_timeout;
            int opl_h = opl_saturate_timeout;
            int opl_r = opl_prover_reduction_limit;
            try {
                opl = Integer.parseInt(opl_iterations_box.getText());
                opl_h = Integer.parseInt(opl_homit_box.getText());
                opl_r = Integer.parseInt(opl_red_box.getText());
            } catch (NumberFormatException nfe) {
            }
            opl_prover_timeout = opl;
            opl_saturate_timeout = opl_h;
            opl_prover_reduction_limit = opl_r;
        } catch (NumberFormatException nfe) {
        }
        opl_prover_require_const = opl_const_box.isSelected();
        opl_prover_sort = opl_sort_box.isSelected();
        opl_prover_unfailing = opl_unfailing_box.isSelected();
        opl_validate = opl_validate_box.isSelected();
        opl_pretty_print = opl_pretty_box.isSelected();
        opl_reorder_joins = opl_reorder_box.isSelected();
        opl_suppress_dom = opl_suppress_box.isSelected();
        opl_allow_horn = opl_horn_box.isSelected();
        opl_prover_ac = opl_semantic_ac_box.isSelected();
        opl_query_check_eqs = opl_eqs_box.isSelected();
        opl_pushout_simpl = opl_simpl_box.isSelected();
        opl_lazy_gui = opl_lazy_box.isSelected();
        opl_prover_filter_subsumed = opl_selfsub_box.isSelected();
        // simplify = opl_simplify_box.isSelected();
        opl_prover_compose = opl_compose_box.isSelected();
        opl_cache_gui = opl_cache_box.isSelected();
        opl_prover_force_prec = opl_prec_box.isSelected();
        opl_require_consistency = opl_consistency_box.isSelected();
        opl_desugar_nat = opl_nat_sugar_box.isSelected();
        opl_print_simplified_presentations = opl_print_simpl_pres_box.isSelected();
        opl_display_fresh_ids = opl_fresh_ids_box.isSelected();
        opl_prover_simplify_instances = opl_simplify_box.isSelected();
        opl_safe_java = opl_safejava_box.isSelected();
        opl_secret_agg = opl_agg_box.isSelected();
        return new Unit();
    };
    return new Pair<>(oplsplit, fn);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JLabel(javax.swing.JLabel) JSplitPane(javax.swing.JSplitPane) JTextField(javax.swing.JTextField) Unit(catdata.Unit) Pair(catdata.Pair)

Example 5 with Unit

use of catdata.Unit in project fql by CategoricalData.

the class DefunctGlobalOptions method showOptions.

public static void showOptions() {
    JTabbedPane jtb = new JTabbedPane();
    List<Function<Unit, Unit>> callbacks = new LinkedList<>();
    for (Options option : debug.options()) {
        Pair<JComponent, Function<Unit, Unit>> x = option.display();
        jtb.add(option.getName(), x.first);
        callbacks.add(x.second);
    }
    jtb.setSelectedIndex(selected_tab);
    JOptionPane pane = new JOptionPane(new JScrollPane(jtb), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new String[] { "OK", "Cancel", "Reset", "Save", "Load", "Delete" }, "OK");
    JDialog dialog = pane.createDialog(null, "Options");
    dialog.setModal(false);
    dialog.setResizable(true);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowDeactivated(WindowEvent e) {
            Object ret = pane.getValue();
            selected_tab = jtb.getSelectedIndex();
            if (ret == "OK") {
                for (Function<Unit, Unit> callback : callbacks) {
                    callback.apply(new Unit());
                }
            } else if (ret == "Reset") {
                debug = new DefunctGlobalOptions();
                showOptions();
            } else if (ret == "Save") {
                // save
                for (Function<Unit, Unit> callback : callbacks) {
                    callback.apply(new Unit());
                }
                save();
                showOptions();
            } else if (ret == "Load") {
                // load
                load();
                showOptions();
            } else if (ret == "Delete") {
                delete();
                showOptions();
            }
        }
    });
    dialog.pack();
    dialog.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) OplOptions(catdata.opl.OplOptions) XOptions(catdata.fpql.XOptions) FqlppOptions(catdata.fqlpp.FqlppOptions) FqlOptions(catdata.fql.FqlOptions) JTabbedPane(javax.swing.JTabbedPane) JComponent(javax.swing.JComponent) WindowAdapter(java.awt.event.WindowAdapter) Unit(catdata.Unit) JOptionPane(javax.swing.JOptionPane) LinkedList(java.util.LinkedList) Function(java.util.function.Function) WindowEvent(java.awt.event.WindowEvent) JDialog(javax.swing.JDialog)

Aggregations

Unit (catdata.Unit)29 Pair (catdata.Pair)16 LinkedList (java.util.LinkedList)11 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 List (java.util.List)9 Map (java.util.Map)8 Set (java.util.Set)8 Chc (catdata.Chc)6 Util (catdata.Util)6 Fn (catdata.fqlpp.cat.FinSet.Fn)6 JPanel (javax.swing.JPanel)6 GridLayout (java.awt.GridLayout)5 LinkedHashMap (java.util.LinkedHashMap)5 Collectors (java.util.stream.Collectors)5 FUNCTION (catdata.fqlpp.FUNCTION)4 CodeTextPanel (catdata.ide.CodeTextPanel)4 Entry (java.util.Map.Entry)4 Triple (catdata.Triple)3 Optional (java.util.Optional)3