use of catdata.Triple in project fql by CategoricalData.
the class XMapping method pi_counit.
@SuppressWarnings({ "rawtypes", "unchecked" })
public XMapping pi_counit(XCtx<C> I) {
XCtx<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> piI = pi(I);
XCtx deltapiI = delta((XCtx) piI);
Map m = new HashMap();
for (Object x : deltapiI.terms()) {
Pair<Triple<?, ?, List>, C> x0 = (Pair<Triple<?, ?, List>, C>) x;
if (src.cat().arrows().contains(x0.first)) {
List l = new LinkedList();
l.add(x0.first.first);
l.addAll(x0.first.third);
m.put(x, l);
continue;
}
Map theta;
if (deltapiI.saturated && DefunctGlobalOptions.debug.fpql.fast_amalgams) {
if (x0.first.third.size() != 2) {
throw new RuntimeException();
}
if (!x0.first.third.get(0).equals("!__1")) {
throw new RuntimeException();
}
theta = (Map) x0.first.third.get(1);
} else {
if (x0.first.third.size() != 1) {
throw new RuntimeException();
}
theta = (Map) x0.first.third.get(0);
}
Object o = theta.get(new Pair<>(x0.second, new Triple<>(em.get(x0.second).get(0), em.get(x0.second).get(0), new LinkedList<>())));
if (o == null) {
throw new RuntimeException();
}
List l = new LinkedList();
l.add(((Triple) o).first);
l.addAll((Collection) ((Triple) o).third);
m.put(x, l);
}
for (Object o : src.allTerms()) {
if (m.containsKey(o)) {
continue;
}
List l = new LinkedList();
l.add(o);
m.put(o, l);
}
return new XMapping(deltapiI, I, m, "homomorphism");
}
use of catdata.Triple in project fql by CategoricalData.
the class XMapping method deltaT.
@SuppressWarnings({ "rawtypes", "unchecked" })
public XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>> deltaT(XMapping<D, D> t) {
XCtx<Pair<Triple<D, D, List<D>>, C>> dsrc = delta(t.src);
XCtx<Pair<Triple<D, D, List<D>>, C>> ddst = delta(t.dst);
Map m = new HashMap();
for (Pair<Triple<D, D, List<D>>, C> k0 : dsrc.terms()) {
// boolean found = false;
Pair<Triple<D, D, List<D>>, C> k = new Pair<>(new Triple<>(k0.first.first, k0.first.second, t.applyAlsoId(k0.first.third)), k0.second);
Triple<D, D, List<D>> v = t.dst.find_fast(k.first);
if (v == null) {
throw new RuntimeException();
}
if (dst.global.ids.contains(v.second) && dst.global.cat().hom((D) "_1", v.second).contains(v)) {
List l = new LinkedList<>();
l.add(v.first);
l.addAll(v.third);
m.put(k0, l);
} else {
List<Pair<Triple<D, D, List<D>>, C>> l = new LinkedList<>();
l.add(new Pair<>(v, k.second));
m.put(k0, l);
}
}
for (Object o : dsrc.allTerms()) {
if (m.containsKey(o)) {
continue;
}
List l = new LinkedList();
l.add(o);
m.put(o, l);
}
return new XMapping<>(dsrc, ddst, m, "homomorphism");
}
use of catdata.Triple in project fql by CategoricalData.
the class XMapping method uber.
/*
* public XMapping<C, D> rel() { Map m = new HashMap<>();
*
* for (C c : src.terms()) { Pair<C, C> t = src.type(c); if
* (src.schema.allTerms().contains(c)) {
*
* continue; }
*
* List<C> l = new LinkedList<>(); l.add(c); List<Map<Triple<C, C, List<C>>,
* Triple<C, C, List<C>>>> lx = src.obs(l);
*
* List<Map<Triple<D, D, List<D>>, Triple<D, D, List<D>>>> rx =
* dst.obs(em.get(c)); dst.rel().type((List<D>)rx); //sanity check
*
* m.put(lx.get(0), rx); }
*
* for (Object o : src.schema.allTerms()) { if (m.containsKey(o)) {
* continue; } List l = new LinkedList(); l.add(o); m.put(o, l); }
*
* return new XMapping<>(src.rel(), dst.rel(), m, "homomorphism"); }
*/
@SuppressWarnings("unchecked")
public XPoly<C, D> uber() {
Map<Object, Pair<D, Block<C, D>>> map = new HashMap<>();
Map<D, XCtx<Pair<Triple<D, D, List<D>>, C>>> dfys = new HashMap<>();
Map<D, XCtx<D>> ys = new HashMap<>();
for (D d : dst.allIds()) {
XCtx<D> y = dst.y((D) "u_u", d);
XCtx<Pair<Triple<D, D, List<D>>, C>> dfy = delta(y);
dfys.put(d, dfy);
ys.put(d, y);
}
Map<D, XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>>> dfys_t = new HashMap<>();
for (D e : dst.allTerms()) {
if (dst.allIds().contains(e)) {
continue;
}
Pair<D, D> t = dst.type(e);
D d = t.first;
D d0 = t.second;
XMapping<D, D> h = uber_sub((D) "u_u", (D) "u_u", e, ys.get(d), ys.get(d0));
dfys_t.put(e, deltaT(h));
}
for (D d : dst.ids) {
XCtx<Pair<Triple<D, D, List<D>>, C>> dfy = dfys.get(d);
Map<Object, C> from = new HashMap<>();
for (Pair<Triple<D, D, List<D>>, C> cf : dfy.terms()) {
from.put(cf, cf.second);
}
@SuppressWarnings("rawtypes") Set where = new HashSet<>(dfy.eqs);
Map<D, Pair<Object, Map<Object, List<Object>>>> edges = new HashMap<>();
Map<D, List<Object>> attrs = new HashMap<>();
for (D e : dst.terms()) {
if (dst.allIds().contains(e)) {
continue;
}
Pair<D, D> t = dst.type(e);
if (!t.first.equals(d) || t.second.equals("_1")) {
continue;
}
D d0 = t.second;
XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>> dfh = dfys_t.get(e);
if (dfh == null) {
throw new RuntimeException("missing: edge " + e + " in " + dfys_t.keySet());
}
XCtx<Pair<Triple<D, D, List<D>>, C>> dfy0 = dfys.get(d0);
if (dfy0 == null) {
throw new RuntimeException();
}
if (dst.ids.contains(d0)) {
@SuppressWarnings("rawtypes") Map edge_m = new HashMap<>();
dfy0.terms();
for (Pair<Triple<D, D, List<D>>, C> cf : dfy0.terms()) {
edge_m.put(cf, dfh.em.get(cf));
}
edges.put(e, new Pair<>("q" + d0, edge_m));
} else {
@SuppressWarnings("rawtypes") List lll = dfh.em.get(new Pair<>(new Triple<>((D) "_1", d0, Util.singList((D) "u_u")), (C) d0));
if (lll == null) {
throw new RuntimeException();
}
attrs.put(e, lll);
}
}
Block<C, D> block = new Block<>(from, where, attrs, edges);
map.put("q" + d, new Pair<>(d, block));
}
XPoly<C, D> ret = new XPoly<>(src, dst, map);
return ret;
}
use of catdata.Triple in project fql by CategoricalData.
the class XMapping method piT.
@SuppressWarnings({ "rawtypes", "unchecked" })
public XMapping<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>, Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> piT(XMapping<C, C> t) {
XCtx<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> src = pi(t.src);
XCtx<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> dst = pi(t.dst);
Map em = new HashMap<>();
for (Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> theta : src.terms()) {
Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>> theta2 = new HashMap<>();
for (Pair<C, Triple<D, D, List<D>>> cf : theta.keySet()) {
Triple<C, C, List<C>> i = theta.get(cf);
List<C> i2 = new LinkedList<>(i.third);
i2.add(0, i.first);
List<C> i2ap = t.apply(i2);
Triple<C, C, List<C>> i2ap0 = new Triple<>(i.first, i.second, i2ap);
Triple<C, C, List<C>> found = t.dst.find_fast(i2ap0);
if (found == null) {
throw new RuntimeException("not found " + i2ap0 + " in " + t.src.cat().hom(i.first, i.second));
}
theta2.put(cf, found);
}
List<Map<Pair<C, Triple<D, D, List<D>>>, Triple<C, C, List<C>>>> l = new LinkedList<>();
if (dst.terms().contains(theta2)) {
l.add(theta2);
em.put(theta, l);
}
}
for (Object o : src.allTerms()) {
if (em.containsKey(o)) {
continue;
}
List l = new LinkedList();
l.add(o);
em.put(o, l);
}
return new XMapping<>(src, dst, em, "homomorphism");
}
use of catdata.Triple in project fql by CategoricalData.
the class XParser method toCatConst.
private static XSchema toCatConst(Object y) {
List<String> nodes = new LinkedList<>();
List<Triple<String, String, String>> arrows = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
Tuple3 s = (Tuple3) y;
Tuple3 nodes0 = (Tuple3) s.a;
Tuple3 arrows0 = (Tuple3) s.b;
Tuple3 eqs0 = (Tuple3) s.c;
List nodes1 = (List) nodes0.b;
List arrows1 = (List) arrows0.b;
List eqs1 = (List) eqs0.b;
for (Object o : nodes1) {
nodes.add((String) o);
}
for (Object o : arrows1) {
Tuple5 x = (Tuple5) o;
arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
}
for (Object o : eqs1) {
Tuple3 x = (Tuple3) o;
List<String> l1 = (List<String>) x.a;
List<String> l2 = (List<String>) x.c;
eqs.add(new Pair<>(l1, l2));
}
XSchema c = new XSchema(nodes, arrows, eqs);
return c;
}
Aggregations