Search in sources :

Example 16 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class EvalAlgebra method eval.

// TODO must convert back to original unfolded vars
private Pair<List<Var>, Collection<Row<En2, X>>> eval(En2 en2, Frozen<Ty, En1, Sym, Fk1, Att1> q, Connection conn, boolean useSql) {
    Collection<Row<En2, X>> ret = null;
    Integer k = maxTempSize();
    if (useSql) {
        Pair<List<Var>, Collection<Row<En2, X>>> ret2 = evalSql(en2, q, I.algebra().intifyX((int) options.getOrDefault(AqlOption.start_ids_at)), conn);
        // TODO aql should also stop on max temp size?
        return ret2;
    } else {
        ret = new LinkedList<>();
        List<Var> plan = q.order(options, I);
        boolean useIndices = useIndices() && q.gens.size() > 1 && I.algebra().hasFreeTypeAlgebra();
        ret.add(new Row<>(en2));
        for (Var v : plan) {
            ret = Row.extend(en2, ret, v, q, I, k, useIndices);
        }
        return new Pair<>(plan, ret);
    }
}
Also used : Var(catdata.aql.Var) Collection(java.util.Collection) LinkedList(java.util.LinkedList) List(java.util.List) Row(catdata.aql.fdm.EvalAlgebra.Row) Pair(catdata.Pair)

Example 17 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, Iso e) {
    Category l = e.l.accept(env, this);
    Category r = e.r.accept(env, this);
    Optional<Pair<Functor, Functor>> k = FinCat.iso(l, r);
    if (!k.isPresent()) {
        throw new RuntimeException("Not isomorphic: " + e.l + " and " + e.r);
    }
    return e.lToR ? k.get().first : k.get().second;
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) Pair(catdata.Pair)

Example 18 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, TransExp.Iso e) {
    Functor l = e.l.accept(env, this);
    Functor r = e.r.accept(env, this);
    if (!l.source.equals(r.source)) {
        throw new RuntimeException("Source categories do not match: " + l.source + "\nand\n" + r.source);
    }
    if (l.source.isInfinite()) {
        throw new RuntimeException("Source category must be finite.");
    }
    if (!l.target.equals(FinSet.FinSet)) {
        throw new RuntimeException("Target category must be Set.");
    }
    Optional<Pair<Transform, Transform>> k = Inst.get(l.source).iso(l, r);
    if (!k.isPresent()) {
        throw new RuntimeException("Not isomorphic: " + e.l + " and " + e.r);
    }
    return e.lToR ? k.get().first : k.get().second;
}
Also used : Functor(catdata.fqlpp.cat.Functor) Pair(catdata.Pair)

Example 19 with Pair

use of catdata.Pair 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 20 with Pair

use of catdata.Pair 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)

Aggregations

Pair (catdata.Pair)305 LinkedList (java.util.LinkedList)169 HashMap (java.util.HashMap)144 List (java.util.List)127 HashSet (java.util.HashSet)101 Triple (catdata.Triple)98 Map (java.util.Map)94 LinkedHashMap (java.util.LinkedHashMap)82 Set (java.util.Set)70 Tuple3 (org.jparsec.functors.Tuple3)46 Node (catdata.fql.decl.Node)38 JPanel (javax.swing.JPanel)37 GridLayout (java.awt.GridLayout)32 FQLException (catdata.fql.FQLException)31 Paint (java.awt.Paint)29 Chc (catdata.Chc)28 Util (catdata.Util)27 En (catdata.aql.exp.SchExpRaw.En)26 Tuple5 (org.jparsec.functors.Tuple5)26 Ty (catdata.aql.exp.TyExpRaw.Ty)25