예제 #1
0
파일: CatOps.java 프로젝트: epost/fql2
 @Override
 public Functor visit(FQLProgram env, fql_lib.decl.FunctorExp.Zero e) {
   Category<?, ?> cat = e.cat.accept(env, this);
   Category<?, ?> amb = e.ambient.accept(env, this);
   if (amb.equals(FinSet.FinSet)) {
     return Inst.get(cat).initial();
   } else if (amb.equals(FinCat.FinCat)) {
     return FunCat.get(cat).initial();
   } else {
     throw new RuntimeException("Report this error to Ryan. Error: ambient category is " + amb);
   }
 }
예제 #2
0
파일: CatOps.java 프로젝트: epost/fql2
  @Override
  public Functor visit(FQLProgram env, FinalConst ic) {
    CatExp e = resolve(env, ic.src);
    if (!(e instanceof Const)) {
      throw new RuntimeException("Can only create functors from finitely-presented categories.");
    }
    Const c = (Const) e;

    Category cat = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);

    Category target = ic.C.accept(env, this);

    Map<Node, Functor> nm = new HashMap<>();
    for (Node n : sig.nodes) {
      FunctorExp kkk = ic.nm.get(n.name);
      if (kkk == null) {
        throw new RuntimeException("Missing node mapping from " + n);
      }
      Functor F = kkk.accept(env, this);
      nm.put(n, F);
    }
    Map<Edge, Transform> em = new HashMap<>();
    for (Edge n : sig.edges) {
      TransExp chc = ic.em.get(n.name);
      if (chc == null) {
        throw new RuntimeException("Missing edge mapping from " + n);
      }
      em.put(n, chc.accept(env, this));
    }

    FUNCTION fff =
        p0 -> {
          Path p = (Path) p0;
          Object fn = target.identity(nm.get(p.source));
          for (Object nnn : p.path) {
            Edge n = (Edge) nnn;
            fn = target.compose(fn, em.get(n));
          }
          return fn;
        };

    return new Functor<>(cat, target, x -> nm.get(x), fff);
  }
예제 #3
0
파일: CatOps.java 프로젝트: epost/fql2
 @Override
 public Category visit(FQLProgram env, Exp e) {
   Category<?, ?> a = e.a.accept(env, this);
   Category<?, ?> b = e.b.accept(env, this);
   if (!a.isInfinite() && !b.isInfinite()) {
     return FinCat.FinCat.exp(a, b);
   } else if (!b.isInfinite() && a.equals(FinSet.FinSet)) {
     return Inst.get(b);
   } else if (!b.isInfinite() && a.equals(FinCat.FinCat)) {
     return FunCat.get(b);
   } else {
     throw new RuntimeException("Cannot compute category " + a + "^" + b);
   }
 }
예제 #4
0
파일: CatOps.java 프로젝트: epost/fql2
  @Override
  public Functor visit(FQLProgram env, Pushout e) {
    Transform l = ENV.trans.get(e.l);
    if (l == null) {
      throw new RuntimeException("Missing transform: " + e.l);
    }
    Transform r = ENV.trans.get(e.r);
    if (r == null) {
      throw new RuntimeException("Missing transform: " + e.r);
    }

    if (!l.source.equals(r.source)) {
      throw new RuntimeException("Source functors do not match.");
    }
    Category<Object, Object> D = l.source.source;

    Set<String> objects = new HashSet<>();
    objects.add("A");
    objects.add("B");
    objects.add("C");
    Set<String> arrows = new HashSet<>();
    arrows.add("f");
    arrows.add("g");
    arrows.add("a");
    arrows.add("b");
    arrows.add("c");
    Map<String, String> sources = new HashMap<>();
    sources.put("f", "A");
    sources.put("g", "A");
    sources.put("a", "A");
    sources.put("b", "B");
    sources.put("c", "C");
    Map<String, String> targets = new HashMap<>();
    targets.put("f", "B");
    targets.put("g", "C");
    targets.put("a", "A");
    targets.put("b", "B");
    targets.put("c", "C");
    Map<Pair<String, String>, String> composition = new HashMap<>();
    composition.put(new Pair<>("a", "a"), "a");
    composition.put(new Pair<>("b", "b"), "b");
    composition.put(new Pair<>("c", "c"), "c");
    composition.put(new Pair<>("a", "f"), "f");
    composition.put(new Pair<>("a", "g"), "g");
    composition.put(new Pair<>("f", "b"), "f");
    composition.put(new Pair<>("g", "c"), "g");
    Map<String, String> identities = new HashMap<>();
    identities.put("A", "a");
    identities.put("B", "b");
    identities.put("C", "c");
    Category<String, String> span =
        new FiniteCategory<>(objects, arrows, sources, targets, composition, identities);

    Category<Pair<Object, String>, Pair<Object, String>> Dspan = FinCat.FinCat.product(D, span);
    Functor<Pair<Object, String>, Pair<Object, String>, Object, Object> fst =
        FinCat.FinCat.first(D, span);

    FUNCTION<Pair<Object, String>, Set> o =
        p -> {
          if (p.second.equals("A")) {
            return (Set) l.source.applyO(p.first);
          } else if (p.second.equals("B")) {
            return (Set) l.target.applyO(p.first);
          } else if (p.second.equals("C")) {
            return (Set) r.target.applyO(p.first);
          } else {
            throw new RuntimeException();
          }
        };
    FUNCTION<Pair<Object, String>, Fn> x =
        fp -> {
          Object f = fp.first;
          String p = fp.second;
          Object a = D.source(f);
          Object b = D.target(f);
          String i = span.source(p);
          String j = span.target(p);
          Functor I = i == "A" ? l.source : i == "B" ? l.target : r.target;
          Functor J = j == "A" ? l.source : j == "B" ? l.target : r.target;
          Fn If = (Fn) I.applyA(f);
          Fn Jf = (Fn) J.applyA(f);
          Transform P =
              p == "f"
                  ? l
                  : p == "g"
                      ? r
                      : p == "a"
                          ? Transform.id(l.source)
                          : p == "b" ? Transform.id(l.target) : Transform.id(r.target);
          Fn Pb = (Fn) P.apply(b);
          Fn Pa = (Fn) P.apply(a);
          return Fn.compose(Pa, Jf);
          /*			if (p.second.equals("f")) {
          	return (Fn) l.apply(p.first);
          } else if (p.second.equals("g")) {
          	return (Fn) r.apply(p.first);
          } else if (p.second.equals("a")) {
          	return (Fn) l.source.applyA(p.first); //Fn.id(o.apply(new Pair<>(p.first, "A")));
          } else if (p.second.equals("b")) {
          	return (Fn) l.target.applyA(p.first); //Fn.id(o.apply(new Pair<>(p.first, "B")));
          } else if (p.second.equals("c")) {
          	return (Fn) r.target.applyA(p.first); //Fn.id(o.apply(new Pair<>(p.first, "C")));
          } else {
          	throw new RuntimeException();
          } */
        };
    Functor I = new Functor(Dspan, FinSet.FinSet(), o, x);

    return FDM.sigmaF(fst).applyO(I);
  }