Search in sources :

Example 1 with Instance

use of catdata.fqlpp.cat.Instance in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, InstConst ic) {
    // new Instance(nm, em, sig);
    Pair<Category, Instance<String, String>> xxx = toInstance(env, ic);
    Functor ret = toFunctor(xxx.first, xxx.second);
    ret.instance0 = xxx.second;
    return ret;
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) Instance(catdata.fqlpp.cat.Instance) Functor(catdata.fqlpp.cat.Functor)

Example 2 with Instance

use of catdata.fqlpp.cat.Instance in project fql by CategoricalData.

the class CatOps method toInstance.

private Pair<Category, Instance<String, String>> toInstance(FQLPPProgram env, InstConst ic) {
    CatExp e = resolve(env, ic.sig);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create instances for finitely-presented categories.");
    }
    Const c = (Const) e;
    Category src = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
    Map<Node, Set> nm = new HashMap<>();
    for (String n0 : ic.nm.keySet()) {
        Node n = sig.getNode(n0);
        SetExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        nm.put(n, kkk.accept(env, new SetOps(ENV)));
    }
    Map<Edge, Map> em = new HashMap<>();
    for (String n0 : ic.em.keySet()) {
        Edge n = sig.getEdge(n0);
        Chc<FnExp, SetExp> chc = ic.em.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing edge mapping from " + n);
        }
        if (chc.left) {
            FnExp kkk = chc.l;
            em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
        } else {
            SetExp sss = chc.r;
            Set vvv = sss.accept(env, new SetOps(ENV));
            Map<Object, Object> uuu = new HashMap<>();
            for (Object o : vvv) {
                if (!(o instanceof Pair)) {
                    throw new RuntimeException("Not a pair: " + o);
                }
                Pair oo = (Pair) o;
                if (uuu.containsKey(oo.first)) {
                    throw new RuntimeException("Duplicate domain entry: " + o + " in " + ic);
                }
                uuu.put(oo.first, oo.second);
            }
            FnExp kkk = new FnExp.Const(uuu::get, ic.nm.get(n.source.name), ic.nm.get(n.target.name));
            em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
        }
    }
    return new Pair<>(src, new Instance(nm, em, sig));
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) ToSet(catdata.fqlpp.TransExp.ToSet) FinSet(catdata.fqlpp.cat.FinSet) SetSet(catdata.fqlpp.TransExp.SetSet) Instance(catdata.fqlpp.cat.Instance) 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) Signature(catdata.fqlpp.cat.Signature) Edge(catdata.fqlpp.cat.Signature.Edge) ToMap(catdata.fqlpp.TransExp.ToMap) Pair(catdata.Pair)

Aggregations

Category (catdata.fqlpp.cat.Category)2 FiniteCategory (catdata.fqlpp.cat.FiniteCategory)2 Instance (catdata.fqlpp.cat.Instance)2 Pair (catdata.Pair)1 Const (catdata.fqlpp.CatExp.Const)1 CatConst (catdata.fqlpp.FunctorExp.CatConst)1 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)1 InstConst (catdata.fqlpp.FunctorExp.InstConst)1 MapConst (catdata.fqlpp.FunctorExp.MapConst)1 SetSetConst (catdata.fqlpp.FunctorExp.SetSetConst)1 SetSet (catdata.fqlpp.TransExp.SetSet)1 ToMap (catdata.fqlpp.TransExp.ToMap)1 ToSet (catdata.fqlpp.TransExp.ToSet)1 FinSet (catdata.fqlpp.cat.FinSet)1 Functor (catdata.fqlpp.cat.Functor)1 Signature (catdata.fqlpp.cat.Signature)1 Edge (catdata.fqlpp.cat.Signature.Edge)1 Node (catdata.fqlpp.cat.Signature.Node)1