Search in sources :

Example 66 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class AqlInACan method toHtml.

public static <X, Y> String toHtml(AqlEnv env, Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I) {
    String ret = "<div>";
    // TODO aql hardcoded
    Map<En, Pair<List<String>, Object[][]>> tables = new AqlViewer(256, env).makeEnTables(I.algebra());
    for (En t : Util.alphabetical(tables.keySet())) {
        ret += "<table id=\"table" + i + "\" style=\"float: left; border: 1px solid black; padding: 5px; border-collapse: collapse; margin-right:10px\" border=\"1\"  cellpadding=\"3\">";
        ret += "<caption><b>" + t.toString() + "</b></caption>";
        List<String> cols = tables.get(t).first;
        cols.remove(0);
        cols.add(0, "ID");
        Object[][] rows = tables.get(t).second;
        ret += "<tr>";
        int j = 0;
        for (String col : cols) {
            ret += "<th onclick=\"sortTable('table" + i + "', " + j + ")\">" + col + "</th>";
            j++;
        }
        ret += "</tr>";
        for (Object[] row : rows) {
            ret += "<tr>";
            for (Object col : row) {
                // System.ou
                ret += "<td>" + strip(col.toString()) + "</td>";
            }
            ret += "</tr>";
        }
        ret += "</table>";
        i++;
    }
    return ret + "</div><br style=\"clear:both;\"/>";
}
Also used : AqlViewer(catdata.aql.gui.AqlViewer) En(catdata.aql.exp.SchExpRaw.En) Pair(catdata.Pair)

Example 67 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XMapping method delta.

@SuppressWarnings({ "rawtypes", "unchecked" })
public XCtx<Pair<Triple<D, D, List<D>>, C>> delta(XCtx<D> I) {
    Set<Pair<Triple<D, D, List<D>>, C>> ids = new HashSet<>();
    Map<Pair<Triple<D, D, List<D>>, C>, Pair<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>>> types = new HashMap<>();
    Set<Pair<List<Pair<Triple<D, D, List<D>>, C>>, List<Pair<Triple<D, D, List<D>>, C>>>> eqs = new HashSet<>();
    for (C c : src.allIds()) {
        for (Triple<D, D, List<D>> arr : I.cat().hom((D) "_1", em.get(c).get(0))) {
            if (I.global.cat().objects().contains(c)) {
                if (I.global.cat().hom((D) "_1", (D) c).contains(arr)) {
                    continue;
                }
            }
            Pair tr = new Pair(arr, c);
            types.put(tr, new Pair("_1", c));
        }
    }
    for (Pair<Triple<D, D, List<D>>, C> t1 : types.keySet()) {
        for (C c : src.allTerms()) {
            // f
            if (src.ids.contains(c)) {
                continue;
            }
            Pair<C, C> t = src.type(c);
            D dsrc = t1.first.first;
            D ddst = em.get(t.second).get(0);
            if (t1.second.equals(t.first)) {
                List lhs = new LinkedList<>();
                lhs.add(t1);
                lhs.add(c);
                List j = new LinkedList<>(t1.first.third);
                j.addAll(em.get(c));
                Triple rhs = new Triple(dsrc, ddst, j);
                // Util.sep(I.cat().hom(dsrc, ddst), "\n\n"));
                Triple rhsX = I.find_fast(rhs);
                List g = new LinkedList<>();
                g.add(new Pair<>(rhsX, t.second));
                if (I.global.allIds().contains(t.second)) {
                    // a' in G
                    Triple ooo = I.global.find_fast(rhsX);
                    if (ooo != null) {
                        List lll = new LinkedList();
                        if (((Collection) ooo.third).isEmpty()) {
                            lll.add(ooo.first);
                        }
                        lll.addAll((Collection) ooo.third);
                        eqs.add(new Pair(lhs, lll));
                    } else {
                        eqs.add(new Pair<>(lhs, g));
                    }
                } else {
                    eqs.add(new Pair<>(lhs, g));
                }
            }
        }
    }
    XCtx ret = new XCtx<>(ids, types, eqs, (XCtx<Pair<Triple<D, D, List<D>>, C>>) src.global, (XCtx<Pair<Triple<D, D, List<D>>, C>>) src, "instance");
    // I.saturated;
    ret.saturated = true;
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Collection(java.util.Collection) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 68 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XMapping method makeThetas2.

// /////////////////////////////////////
@SuppressWarnings({ "rawtypes", "unchecked" })
private Pair<Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>>, Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>>> makeThetas2(XCtx<C> I) {
    Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>> ret = new HashMap<>();
    Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>> ret2 = new HashMap<>();
    for (D d : dst.allIds()) {
        // was allIds
        List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> bad_thetas = new LinkedList<>();
        if (dst.global.allIds().contains(d)) {
            for (Triple<D, D, List<D>> constant : dst.global.cat().hom((D) "_1", d)) {
                Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> bad_theta = new LinkedHashMap<>();
                for (C c : src.allIds()) {
                    for (Triple<D, D, List<D>> f : dst.cat().hom(d, em.get(c).get(0))) {
                        Triple composed = dst.global.cat().compose(constant, f);
                        bad_theta.put(new Pair<>(c, f), composed);
                    }
                }
                bad_thetas.add(bad_theta);
            }
        }
        ret2.put(d, bad_thetas);
        List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> thetas = new LinkedList<>();
        Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> theta = new LinkedHashMap<>();
        Map<Pair<C, Triple<D, D, List<D>>>, Pair<C, Triple<D, D, List<D>>>> theta2 = new LinkedHashMap<>();
        for (C c : src.allIds()) {
            for (Triple<D, D, List<D>> f : dst.cat().hom(d, em.get(c).get(0))) {
                theta.put(new Pair<>(c, f), null);
                theta2.put(new Pair<>(c, f), null);
            }
        }
        if (theta.keySet().isEmpty()) {
            thetas.add(new HashMap<>());
        } else {
            for (Pair<C, Triple<D, D, List<D>>> cf : theta.keySet()) {
                for (Triple<C, C, List<C>> x : I.cat().hom((C) "_1", cf.first)) {
                    try_branch(I, thetas, theta, theta2, cf, x, bad_thetas);
                }
                // this is fine - just do first key
                break;
            }
        }
        ret.put(d, thetas);
    }
    return new Pair<>(ret, ret2);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) Triple(catdata.Triple) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 69 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XMapping method pi_unit.

@SuppressWarnings({ "rawtypes", "unchecked" })
public XMapping pi_unit(XCtx<D> J) {
    XCtx<Pair<Triple<D, D, List<D>>, C>> deltaI = delta(J);
    XCtx pideltaI = pi((XCtx) deltaI);
    Map m = new HashMap();
    for (D x : J.terms()) {
        D d = J.type(x).second;
        if (!J.type(x).first.equals("_1")) {
            throw new RuntimeException();
        }
        Map theta = new HashMap();
        for (C c : src.allIds()) {
            for (Triple<D, D, List<D>> f : dst.cat().hom(d, em.get(c).get(0))) {
                List<D> tofind = new LinkedList<>();
                tofind.add(x);
                tofind.addAll(f.third);
                Triple<D, D, List<D>> found = J.find_fast(new Triple<>((D) "_1", f.second, tofind));
                if (found == null) {
                    throw new RuntimeException();
                }
                List<Pair<Triple<D, D, List<D>>, C>> g = new LinkedList<>();
                Pair<Triple<D, D, List<D>>, C> pr = new Pair<>(found, c);
                g.add(pr);
                if (src.global.allIds().contains(pr.second) && src.global.cat().arrows().contains(pr.first)) {
                    theta.put(new Pair<>(c, f), pr.first);
                } else {
                    Triple tr = new Triple<>("_1", c, g);
                    Object xxx = deltaI.find_fast(tr);
                    if (xxx == null) {
                        throw new RuntimeException("cannot find " + tr);
                    }
                    theta.put(new Pair<>(c, f), xxx);
                }
            }
        }
        List l = new LinkedList();
        l.add(theta);
        m.put(x, l);
    }
    for (Object o : dst.allTerms()) {
        if (m.containsKey(o)) {
            continue;
        }
        List l = new LinkedList();
        l.add(o);
        m.put(o, l);
    }
    return new XMapping(J, pideltaI, m, "homomorphism");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) Triple(catdata.Triple) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 70 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XMapping method pi.

@SuppressWarnings({ "rawtypes", "unchecked" })
public XCtx<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> pi(XCtx<C> I) {
    Pair<Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>>, Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>>> zzz = makeThetas2(I);
    Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>> thetas_d = zzz.first;
    Map<D, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>> bad_thetas = zzz.second;
    Map types = new HashMap<>();
    for (D d : dst.allIds()) {
        for (Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> theta : thetas_d.get(d)) {
            types.put(theta, new Pair<>("_1", d));
        }
    }
    Set<Pair<List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>, List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>>>> eqs = new HashSet<>();
    for (D h : dst.allTerms()) {
        Pair<D, D> t = dst.type(h);
        // what if t.second is a type? have a theta but won't build a theta
        for (Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> theta : thetas_d.get(t.first)) {
            Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> theta0 = new HashMap<>();
            for (C c : src.allIds()) {
                for (Triple<D, D, List<D>> f : dst.cat().hom(t.second, em.get(c).get(0))) {
                    List<D> f0 = new LinkedList<>();
                    f0.add(h);
                    f0.addAll(f.third);
                    Triple<D, D, List<D>> key = dst.find_fast(new Triple<>(t.first, f.second, f0));
                    if (key == null) {
                        throw new RuntimeException("Cannot find null key in " + dst.cat().arrows());
                    }
                    Triple<C, C, List<C>> toStore = getWrapper(I, theta, new Pair<>(c, key));
                    if (toStore == null) {
                        throw new RuntimeException("Cannot find " + new Pair<>(c, key) + " in " + theta);
                    }
                    theta0.put(new Pair<>(c, f), toStore);
                }
            }
            List lhs = new LinkedList<>();
            lhs.add(theta);
            lhs.add(h);
            if (I.global.allIds().contains(t.second)) {
                List rhs = new LinkedList<>();
                rhs.add(theta0);
                if (bad_thetas.get(t.second).contains(theta0)) {
                    Object o1 = t.second;
                    Object o2 = new Triple<>(t.second, t.second, new LinkedList<>());
                    Pair key = new Pair(o1, o2);
                    // theta0.get(key);
                    Triple<C, C, List<C>> val = getWrapper(I, theta0, key);
                    if (val == null) {
                        throw new RuntimeException();
                    }
                    List lll = new LinkedList();
                    if (val.third.isEmpty()) {
                        lll.add(val.first);
                    } else {
                        lll.addAll((val.third));
                    }
                    eqs.add(new Pair(lhs, lll));
                } else {
                    eqs.add(new Pair<>(lhs, rhs));
                }
            } else {
                boolean found = false;
                for (Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> thetaX : thetas_d.get(t.second)) {
                    if (theta0.equals(thetaX)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new RuntimeException("At h=" + h + ": " + t + ", Constructed theta^prime " + theta0 + " not found in\n\n" + Util.sep(thetas_d.get(t.second), "\n"));
                }
                List rhs = new LinkedList<>();
                rhs.add(theta0);
                eqs.add(new Pair<>(lhs, rhs));
            }
        }
    }
    XCtx ret = new XCtx(new HashSet<>(), types, eqs, src.global, dst, "instance");
    ret.saturated = true;
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) Triple(catdata.Triple) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Pair (catdata.Pair)305 LinkedList (java.util.LinkedList)169 HashMap (java.util.HashMap)144 List (java.util.List)127 HashSet (java.util.HashSet)101 Triple (catdata.Triple)98 Map (java.util.Map)94 LinkedHashMap (java.util.LinkedHashMap)82 Set (java.util.Set)70 Tuple3 (org.jparsec.functors.Tuple3)46 Node (catdata.fql.decl.Node)38 JPanel (javax.swing.JPanel)37 GridLayout (java.awt.GridLayout)32 FQLException (catdata.fql.FQLException)31 Paint (java.awt.Paint)29 Chc (catdata.Chc)28 Util (catdata.Util)27 En (catdata.aql.exp.SchExpRaw.En)26 Tuple5 (org.jparsec.functors.Tuple5)26 Ty (catdata.aql.exp.TyExpRaw.Ty)25