Search in sources :

Example 6 with Times

use of catdata.fql.decl.SigExp.Times in project fql by CategoricalData.

the class MapExpChecker method visit.

@Override
public Pair<SigExp, SigExp> visit(FQLProgram env, Dist2 e) {
    SigExp aa = e.a.typeOf(env);
    SigExp bb = e.b.typeOf(env);
    SigExp cc = e.c.typeOf(env);
    return new Pair<>(new Plus(new Times(aa, bb), new Times(aa, cc)), new Times(aa, new Plus(bb, cc)));
}
Also used : Times(catdata.fql.decl.SigExp.Times) Plus(catdata.fql.decl.SigExp.Plus) Pair(catdata.Pair)

Example 7 with Times

use of catdata.fql.decl.SigExp.Times in project fql by CategoricalData.

the class MapExpChecker method visit.

@Override
public Pair<SigExp, SigExp> visit(FQLProgram env, Snd e) {
    SigExp a = e.s.typeOf(env);
    SigExp b = e.t.typeOf(env);
    return new Pair<>(new Times(a, b), b);
}
Also used : Times(catdata.fql.decl.SigExp.Times) Pair(catdata.Pair)

Example 8 with Times

use of catdata.fql.decl.SigExp.Times in project fql by CategoricalData.

the class SigOps method visit.

@Override
public Const visit(FQLProgram env, Curry e) {
    try {
        Const F = e.f.accept(env, this);
        Pair<SigExp, SigExp> type = e.f.type(env);
        SigExp.Const C = type.second.toConst(env);
        Signature Csig = C.toSig(env);
        if (!(type.first instanceof Times)) {
            throw new RuntimeException();
        }
        Times src = (Times) type.first;
        SigExp.Const A = src.a.toConst(env);
        SigExp.Const B = src.b.toConst(env);
        // Signature Asig = A.toSig(env);
        Signature Bsig = B.toSig(env);
        if (!A.attrs.isEmpty()) {
            throw new RuntimeException("Cannot curry when context has attributes.");
        }
        Pair<Quad<SigExp.Const, Const, Const, Fn<Triple<SigExp.Const, Const, Const>, Const>>, Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>>> AB_stuff = prod(A, B);
        // SigExp.Const AB = AB_stuff.first.first;
        Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>> maps = AB_stuff.second;
        FinCat<Mapping, Map<Node, Path>> cat = exp(env, C.toSig(env), B.toSig(env));
        Quad<Signature, Pair<Map<Mapping, String>, Map<String, Mapping>>, Pair<Map<Arr<Mapping, Map<Node, Path>>, String>, Map<String, Arr<Mapping, Map<Node, Path>>>>, Pair<Map<Attribute<Mapping>, String>, Map<String, Attribute<Mapping>>>> CB_stuff = cat.toSig(env.enums);
        Signature CB = CB_stuff.first;
        List<Pair<String, String>> nmret = new LinkedList<>();
        for (String a : A.nodes) {
            Mapping m = curry_helper(F, Csig, B, Bsig, maps, a);
            String target = CB_stuff.second.first.get(m);
            nmret.add(new Pair<>(a, target));
        }
        List<Pair<String, List<String>>> amret = new LinkedList<>();
        for (Triple<String, String, String> a : A.arrows) {
            Mapping s = curry_helper(F, Csig, B, Bsig, maps, a.second);
            Mapping t = curry_helper(F, Csig, B, Bsig, maps, a.third);
            Map<Node, Path> nt = new HashMap<>();
            for (String b : B.nodes) {
                // edge A*B
                String p = maps.third.get(new Pair<>(a.first, b));
                // path C
                List<String> p0 = lookup(p, F.arrows);
                Path p1 = new Path(Csig, p0);
                nt.put(new Node(b), p1);
            }
            List<String> l = new LinkedList<>();
            l.add(CB_stuff.second.first.get(s));
            Arr<Mapping, Map<Node, Path>> arr = new Arr<>(nt, s, t);
            if (null != CB_stuff.third.first.get(arr)) {
                l.add(CB_stuff.third.first.get(arr));
            }
            amret.add(new Pair<>(a.first, l));
        }
        List<Pair<String, String>> attrs = new LinkedList<>();
        // A*B -> C
        // A -> C^B
        Const ret = new Const(nmret, attrs, amret, A, CB.toConst());
        ret.toMap(env);
        return ret;
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Quad(catdata.Quad) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Const(catdata.fql.decl.MapExp.Const) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Times(catdata.fql.decl.SigExp.Times) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Pair (catdata.Pair)8 Times (catdata.fql.decl.SigExp.Times)8 Exp (catdata.fql.decl.SigExp.Exp)2 Plus (catdata.fql.decl.SigExp.Plus)2 LinkedList (java.util.LinkedList)2 Quad (catdata.Quad)1 Triple (catdata.Triple)1 FQLException (catdata.fql.FQLException)1 Arr (catdata.fql.cat.Arr)1 Const (catdata.fql.decl.MapExp.Const)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1