Search in sources :

Example 26 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, CatConst ic) {
    CatExp e = resolve(env, ic.sig);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create functors to cat 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);
    Map<Node, Category> nm = new HashMap<>();
    for (Node n : sig.nodes) {
        CatExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        nm.put(n, kkk.accept(env, this));
    }
    Map<Edge, Functor> em = new HashMap<>();
    for (Edge n : sig.edges) {
        FunctorExp 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;
        Functor fn = FinCat.FinCat.identity(nm.get(p.source));
        for (Object nnn : p.path) {
            Edge n = (Edge) nnn;
            fn = FinCat.FinCat.compose(fn, em.get(n));
        }
        return fn;
    };
    return new Functor(cat, FinCat.FinCat, nm::get, fff);
}
Also used : PeterApply(catdata.fqlpp.TransExp.PeterApply) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Named(catdata.fqlpp.CatExp.Named) Edge(catdata.fqlpp.cat.Signature.Edge) Snd(catdata.fqlpp.FunctorExp.Snd) Comp(catdata.fqlpp.FunctorExp.Comp) ToInst(catdata.fqlpp.TransExp.ToInst) Id(catdata.fqlpp.FunctorExp.Id) Inr(catdata.fqlpp.FunctorExp.Inr) FF(catdata.fqlpp.FunctorExp.FF) Migrate(catdata.fqlpp.FunctorExp.Migrate) Colim(catdata.fqlpp.CatExp.Colim) Exp(catdata.fqlpp.CatExp.Exp) Pushout(catdata.fqlpp.FunctorExp.Pushout) FinCat(catdata.fqlpp.cat.FinCat) FunCat(catdata.fqlpp.cat.FunCat) Pair(catdata.Pair) CoMonad(catdata.fqlpp.cat.CoMonad) Iso(catdata.fqlpp.FunctorExp.Iso) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Inj(catdata.fqlpp.TransExp.Inj) Fn(catdata.fqlpp.cat.FinSet.Fn) Bool(catdata.fqlpp.TransExp.Bool) Case(catdata.fqlpp.FunctorExp.Case) ToMap(catdata.fqlpp.TransExp.ToMap) Zero(catdata.fqlpp.CatExp.Zero) Monad(catdata.fqlpp.cat.Monad) Plus(catdata.fqlpp.CatExp.Plus) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) Inst(catdata.fqlpp.cat.Inst) ToSet(catdata.fqlpp.TransExp.ToSet) Groth(catdata.fqlpp.cat.Groth) Mapping(catdata.fqlpp.cat.Mapping) Serializable(java.io.Serializable) Kleisli(catdata.fqlpp.CatExp.Kleisli) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Dom(catdata.fqlpp.CatExp.Dom) Triple(catdata.Triple) Eval(catdata.fqlpp.FunctorExp.Eval) Var(catdata.fqlpp.FunctorExp.Var) Times(catdata.fqlpp.CatExp.Times) Const(catdata.fqlpp.CatExp.Const) java.util(java.util) Prod(catdata.fqlpp.FunctorExp.Prod) InstConst(catdata.fqlpp.FunctorExp.InstConst) Node(catdata.fqlpp.cat.Signature.Node) Chc(catdata.Chc) TT(catdata.fqlpp.FunctorExp.TT) Functor(catdata.fqlpp.cat.Functor) Proj(catdata.fqlpp.TransExp.Proj) Prop(catdata.fqlpp.FunctorExp.Prop) CatExpVisitor(catdata.fqlpp.CatExp.CatExpVisitor) Signature(catdata.fqlpp.cat.Signature) TransExpVisitor(catdata.fqlpp.TransExp.TransExpVisitor) Union(catdata.fqlpp.CatExp.Union) ToCat(catdata.fqlpp.TransExp.ToCat) One(catdata.fqlpp.CatExp.One) FDM(catdata.fqlpp.cat.FDM) Ker(catdata.fqlpp.TransExp.Ker) Fst(catdata.fqlpp.FunctorExp.Fst) Whisker(catdata.fqlpp.TransExp.Whisker) Curry(catdata.fqlpp.FunctorExp.Curry) Transform(catdata.fqlpp.cat.Transform) Apply(catdata.fqlpp.FunctorExp.Apply) Instance(catdata.fqlpp.cat.Instance) MapConst(catdata.fqlpp.FunctorExp.MapConst) Path(catdata.fqlpp.cat.Signature.Path) Pivot(catdata.fqlpp.FunctorExp.Pivot) Chr(catdata.fqlpp.TransExp.Chr) Cod(catdata.fqlpp.CatExp.Cod) FinSet(catdata.fqlpp.cat.FinSet) Uncurry(catdata.fqlpp.FunctorExp.Uncurry) FunctorExpVisitor(catdata.fqlpp.FunctorExp.FunctorExpVisitor) Adj(catdata.fqlpp.TransExp.Adj) SetSet(catdata.fqlpp.TransExp.SetSet) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Inl(catdata.fqlpp.FunctorExp.Inl) CoProd(catdata.fqlpp.TransExp.CoProd) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Path(catdata.fqlpp.cat.Signature.Path) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Const(catdata.fqlpp.CatExp.Const) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Node(catdata.fqlpp.cat.Signature.Node) Functor(catdata.fqlpp.cat.Functor) Signature(catdata.fqlpp.cat.Signature) Edge(catdata.fqlpp.cat.Signature.Edge)

Example 27 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram 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.product(D, span);
    Functor<Pair<Object, String>, Pair<Object, String>, Object, Object> fst = FinCat.first(D, span);
    FUNCTION<Pair<Object, String>, Set> o = p -> {
        switch(p.second) {
            case "A":
                return (Set) l.source.applyO(p.first);
            case "B":
                return (Set) l.target.applyO(p.first);
            case "C":
                return (Set) r.target.applyO(p.first);
            default:
                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 = Objects.equals(j, "A") ? l.source : Objects.equals(j, "B") ? l.target : r.target;
        // Fn If = (Fn) I.applyA(f);
        Fn Jf = (Fn) J.applyA(f);
        Transform P = Objects.equals(p, "f") ? l : Objects.equals(p, "g") ? r : Objects.equals(p, "a") ? Transform.id(l.source) : Objects.equals(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);
    };
    Functor I = new Functor(Dspan, FinSet.FinSet0(), o, x);
    return FDM.sigmaF(fst).applyO(I);
}
Also used : PeterApply(catdata.fqlpp.TransExp.PeterApply) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Named(catdata.fqlpp.CatExp.Named) Edge(catdata.fqlpp.cat.Signature.Edge) Snd(catdata.fqlpp.FunctorExp.Snd) Comp(catdata.fqlpp.FunctorExp.Comp) ToInst(catdata.fqlpp.TransExp.ToInst) Id(catdata.fqlpp.FunctorExp.Id) Inr(catdata.fqlpp.FunctorExp.Inr) FF(catdata.fqlpp.FunctorExp.FF) Migrate(catdata.fqlpp.FunctorExp.Migrate) Colim(catdata.fqlpp.CatExp.Colim) Exp(catdata.fqlpp.CatExp.Exp) Pushout(catdata.fqlpp.FunctorExp.Pushout) FinCat(catdata.fqlpp.cat.FinCat) FunCat(catdata.fqlpp.cat.FunCat) Pair(catdata.Pair) CoMonad(catdata.fqlpp.cat.CoMonad) Iso(catdata.fqlpp.FunctorExp.Iso) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Inj(catdata.fqlpp.TransExp.Inj) Fn(catdata.fqlpp.cat.FinSet.Fn) Bool(catdata.fqlpp.TransExp.Bool) Case(catdata.fqlpp.FunctorExp.Case) ToMap(catdata.fqlpp.TransExp.ToMap) Zero(catdata.fqlpp.CatExp.Zero) Monad(catdata.fqlpp.cat.Monad) Plus(catdata.fqlpp.CatExp.Plus) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) Inst(catdata.fqlpp.cat.Inst) ToSet(catdata.fqlpp.TransExp.ToSet) Groth(catdata.fqlpp.cat.Groth) Mapping(catdata.fqlpp.cat.Mapping) Serializable(java.io.Serializable) Kleisli(catdata.fqlpp.CatExp.Kleisli) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Dom(catdata.fqlpp.CatExp.Dom) Triple(catdata.Triple) Eval(catdata.fqlpp.FunctorExp.Eval) Var(catdata.fqlpp.FunctorExp.Var) Times(catdata.fqlpp.CatExp.Times) Const(catdata.fqlpp.CatExp.Const) java.util(java.util) Prod(catdata.fqlpp.FunctorExp.Prod) InstConst(catdata.fqlpp.FunctorExp.InstConst) Node(catdata.fqlpp.cat.Signature.Node) Chc(catdata.Chc) TT(catdata.fqlpp.FunctorExp.TT) Functor(catdata.fqlpp.cat.Functor) Proj(catdata.fqlpp.TransExp.Proj) Prop(catdata.fqlpp.FunctorExp.Prop) CatExpVisitor(catdata.fqlpp.CatExp.CatExpVisitor) Signature(catdata.fqlpp.cat.Signature) TransExpVisitor(catdata.fqlpp.TransExp.TransExpVisitor) Union(catdata.fqlpp.CatExp.Union) ToCat(catdata.fqlpp.TransExp.ToCat) One(catdata.fqlpp.CatExp.One) FDM(catdata.fqlpp.cat.FDM) Ker(catdata.fqlpp.TransExp.Ker) Fst(catdata.fqlpp.FunctorExp.Fst) Whisker(catdata.fqlpp.TransExp.Whisker) Curry(catdata.fqlpp.FunctorExp.Curry) Transform(catdata.fqlpp.cat.Transform) Apply(catdata.fqlpp.FunctorExp.Apply) Instance(catdata.fqlpp.cat.Instance) MapConst(catdata.fqlpp.FunctorExp.MapConst) Path(catdata.fqlpp.cat.Signature.Path) Pivot(catdata.fqlpp.FunctorExp.Pivot) Chr(catdata.fqlpp.TransExp.Chr) Cod(catdata.fqlpp.CatExp.Cod) FinSet(catdata.fqlpp.cat.FinSet) Uncurry(catdata.fqlpp.FunctorExp.Uncurry) FunctorExpVisitor(catdata.fqlpp.FunctorExp.FunctorExpVisitor) Adj(catdata.fqlpp.TransExp.Adj) SetSet(catdata.fqlpp.TransExp.SetSet) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Inl(catdata.fqlpp.FunctorExp.Inl) CoProd(catdata.fqlpp.TransExp.CoProd) ToSet(catdata.fqlpp.TransExp.ToSet) FinSet(catdata.fqlpp.cat.FinSet) SetSet(catdata.fqlpp.TransExp.SetSet) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform) Pair(catdata.Pair)

Example 28 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class FQLPPDriver method makeEnv.

public static FQLPPEnvironment makeEnv(String str, FQLPPProgram init, String... toUpdate) {
    Map<String, Fn<?, ?>> fns = new HashMap<>();
    Map<String, Set<?>> sets = new HashMap<>();
    Map<String, Category<?, ?>> cats = new HashMap<>();
    Map<String, Functor<?, ?, ?, ?>> ftrs = new HashMap<>();
    Map<String, Transform<?, ?, ?, ?>> trans = new HashMap<>();
    FQLPPEnvironment ret = new FQLPPEnvironment(init, str, sets, fns, cats, ftrs, trans);
    for (Entry<String, CatExp> k : init.cats.entrySet()) {
        init.cats.put(k.getKey(), k.getValue().accept(init, new PreProcessor()));
    }
    for (String k : init.order) {
        SetExp se = init.sets.get(k);
        if (se != null) {
            try {
                Set<?> xxx = se.accept(init, new SetOps(ret));
                sets.put(k, xxx);
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "set");
            }
            toUpdate[0] = "Last Processed: " + k;
        }
        FnExp fe = init.fns.get(k);
        if (fe != null) {
            try {
                Fn<?, ?> xxx = fe.accept(init, new SetOps(ret));
                fns.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "function");
            }
        }
        CatExp ce = init.cats.get(k);
        // CatExp ce = ce0.accept(init, new PreProcessor());
        if (ce != null) {
            try {
                Category<?, ?> xxx = ce.accept(init, new CatOps(ret));
                cats.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "category");
            }
        }
        FunctorExp FE = init.ftrs.get(k);
        if (FE != null) {
            try {
                Functor<?, ?, ?, ?> xxx = FE.accept(init, new CatOps(ret));
                ftrs.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "functor");
            }
        }
        TransExp te = init.trans.get(k);
        if (te != null) {
            try {
                Transform<?, ?, ?, ?> xxx = te.accept(init, new CatOps(ret));
                trans.put(k, xxx);
                toUpdate[0] = "Last Processed: " + k;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new LineException(t.getLocalizedMessage(), k, "transform");
            }
        }
    }
    return ret;
}
Also used : Set(java.util.Set) Category(catdata.fqlpp.cat.Category) HashMap(java.util.HashMap) LineException(catdata.LineException) Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform)

Example 29 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method initial.

public Transform<O, A, Set, Fn> initial(Functor<O, A, Set, Fn> o) {
    Set ret = new HashSet<>();
    FUNCTION<O, Fn> fn = x -> new Fn<>(ret, o.applyO(x), y -> {
        throw new RuntimeException();
    });
    return new Transform<>(initial(), o, fn);
}
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) Fn(catdata.fqlpp.cat.FinSet.Fn) HashSet(java.util.HashSet)

Example 30 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method fals.

public Transform<O, A, Set, Fn> fals() {
    Set e = new HashSet<>();
    e.add(new Unit());
    Functor<O, A, Set, Fn> prp = (Functor<O, A, Set, Fn>) ((Object) prop());
    return new Transform<>(terminal(), prp, x -> new Fn<>(e, prp.applyO(x), z -> initial()));
}
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) Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) HashSet(java.util.HashSet)

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