Search in sources :

Example 1 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, 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, 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) Transform(catdata.fqlpp.cat.Transform) Edge(catdata.fqlpp.cat.Signature.Edge)

Example 2 with Fn

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

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, ToSet e) {
    Functor s = e.src.accept(env, this);
    Functor t = e.dst.accept(env, this);
    FUNCTION o = x -> {
        Node n = (Node) x;
        Chc<FnExp, SetExp> chc = e.fun.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing object mapping for: " + n.name);
        }
        if (chc.left) {
            return chc.l.accept(env, new SetOps(ENV));
        } else {
            Set src = (Set) s.applyO(n);
            Set dst = (Set) t.applyO(n);
            Set<Pair> p = (Set<Pair>) chc.r.accept(env, new SetOps(ENV));
            Map<Object, Object> map = new HashMap<>();
            for (Pair h : p) {
                if (map.containsKey(h.first)) {
                    throw new RuntimeException("Duplicate arg: " + e);
                }
                map.put(h.first, h.second);
            }
            return new Fn(src, dst, map::get);
        }
    };
    return new Transform(s, t, o);
}
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) Node(catdata.fqlpp.cat.Signature.Node) Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform) ToMap(catdata.fqlpp.TransExp.ToMap) Chc(catdata.Chc) Pair(catdata.Pair)

Example 3 with Fn

use of catdata.fqlpp.cat.FinSet.Fn 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 4 with Fn

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

the class SetOps method visit.

@SuppressWarnings("unchecked")
@Override
public Fn visit(FQLPPProgram env, Apply e) {
    FunctorExp k = env.ftrs.get(e.f);
    if (k == null) {
        throw new RuntimeException("Missing functor: " + e.f);
    }
    Fn s = e.set.accept(env, this);
    Functor f = k.accept(env, new CatOps(ENV));
    if (!FinSet.FinSet.equals(f.source)) {
        throw new RuntimeException("Domain is not Set in " + e);
    }
    if (!FinSet.FinSet.equals(f.target)) {
        throw new RuntimeException("Codomain is not Set in " + e);
    }
    return (Fn) f.applyA(s);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) Functor(catdata.fqlpp.cat.Functor)

Example 5 with Fn

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

the class SetOps method visit.

@SuppressWarnings("unchecked")
@Override
public Fn visit(FQLPPProgram env, ApplyTrans e) {
    TransExp k = env.trans.get(e.f);
    if (k == null) {
        throw new RuntimeException("Missing transform: " + e.f);
    }
    Transform f = k.accept(env, new CatOps(ENV));
    if (!FinSet.FinSet.equals(f.source.source)) {
        throw new RuntimeException("Domain is not Set in " + e);
    }
    if (!FinSet.FinSet.equals(f.target.target)) {
        throw new RuntimeException("Codomain is not Set in " + e);
    }
    Set<?> s = e.set.accept(env, this);
    return (Fn) f.apply(s);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) Transform(catdata.fqlpp.cat.Transform)

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