Search in sources :

Example 71 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class Examples method TreeModel.

public static VariableComponent TreeModel() {
    Expression a = DefaultSymbol.createSymbol("A");
    Expression b = DefaultSymbol.createSymbol("B");
    Expression c = DefaultSymbol.createSymbol("C");
    Expression q = DefaultSymbol.createSymbol("Q");
    Expression trueValue = DefaultSymbol.createSymbol(true);
    Expression f1 = apply(IF_THEN_ELSE, apply(EQUAL, a, trueValue), apply(IF_THEN_ELSE, apply(EQUAL, q, trueValue), 95, 5), apply(IF_THEN_ELSE, apply(EQUAL, q, trueValue), 5, 95));
    Expression f2 = apply(IF_THEN_ELSE, apply(EQUAL, b, trueValue), apply(IF_THEN_ELSE, apply(EQUAL, q, trueValue), 5, 95), apply(IF_THEN_ELSE, apply(EQUAL, q, trueValue), 95, 5));
    Expression f3 = apply(IF_THEN_ELSE, apply(EQUAL, c, trueValue), apply(IF_THEN_ELSE, apply(EQUAL, b, trueValue), 60, 40), apply(IF_THEN_ELSE, apply(EQUAL, b, trueValue), 40, 60));
    Set<Expression> Factor = new HashSet<Expression>();
    Factor.add(f1);
    Factor.add(f2);
    Factor.add(f3);
    Model m = new Model(Factor);
    m.setType(a, "Boolean");
    m.setType(b, "Boolean");
    m.setType(c, "Boolean");
    m.setType(q, "Boolean");
    m.setValues(a, "Boolean");
    m.setValues(b, "Boolean");
    m.setValues(c, "Boolean");
    m.setValues(q, "Boolean");
    Expression f4 = apply(IF_THEN_ELSE, apply(EQUAL, c, trueValue), apply(IF_THEN_ELSE, apply(EQUAL, a, trueValue), 50, 50), apply(IF_THEN_ELSE, apply(EQUAL, a, trueValue), 50, 50));
    Expression f5 = apply(IF_THEN_ELSE, apply(EQUAL, a, trueValue), 1, 0);
    VariableComponent ComponentResultat = new VariableComponent(q, null, m, new HashSet<Expression>());
    return ComponentResultat;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) HashSet(java.util.HashSet)

Example 72 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class Examples method DoubleDiamondModel.

public static VariableComponent DoubleDiamondModel() {
    Expression func = DefaultSymbol.createSymbol("f");
    Expression a = DefaultSymbol.createSymbol("A");
    Expression b = DefaultSymbol.createSymbol("B");
    Expression c = DefaultSymbol.createSymbol("C");
    Expression d = DefaultSymbol.createSymbol("D");
    Expression e = DefaultSymbol.createSymbol("E");
    Expression f = DefaultSymbol.createSymbol("F");
    Expression g = DefaultSymbol.createSymbol("G");
    Expression q = DefaultSymbol.createSymbol("Q");
    Expression f1 = IfThenElse.make(a, IfThenElse.make(q, parse("3"), parse("9")), IfThenElse.make(q, parse("5"), parse("7")));
    Expression f2 = IfThenElse.make(e, IfThenElse.make(q, parse("2"), parse("8")), IfThenElse.make(q, parse("1"), parse("0")));
    Expression f3 = IfThenElse.make(g, IfThenElse.make(q, parse("34"), parse("9")), IfThenElse.make(q, parse("5"), parse("7")));
    Expression f4 = IfThenElse.make(e, IfThenElse.make(f, parse("5"), parse("2")), IfThenElse.make(f, parse("1"), parse("1")));
    Expression f5 = IfThenElse.make(g, IfThenElse.make(f, parse("6"), parse("0")), IfThenElse.make(f, parse("0"), parse("3")));
    Expression f6 = IfThenElse.make(b, IfThenElse.make(d, parse("9"), parse("3")), IfThenElse.make(d, parse("2"), parse("0")));
    Expression f7 = IfThenElse.make(c, IfThenElse.make(d, parse("1"), parse("7")), IfThenElse.make(d, parse("6"), parse("6")));
    Expression f8 = IfThenElse.make(b, IfThenElse.make(a, parse("2"), parse("1")), IfThenElse.make(a, parse("4"), parse("10")));
    Expression f9 = IfThenElse.make(c, IfThenElse.make(a, parse("6"), parse("4")), IfThenElse.make(a, parse("8"), parse("4")));
    Expression f10 = IfThenElse.make(c, parse("1"), parse("0"));
    Expression res = apply(func, q);
    Set<Expression> Factor = new HashSet<Expression>();
    Factor.add(f1);
    Factor.add(f2);
    Factor.add(f3);
    Factor.add(f4);
    Factor.add(f5);
    Factor.add(f6);
    Factor.add(f7);
    Factor.add(f8);
    Factor.add(f9);
    Factor.add(f10);
    Factor.add(res);
    Model m = new Model(Factor);
    VariableComponent ComponentResultat = new VariableComponent(q, res, m, new HashSet<Expression>());
    return ComponentResultat;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) HashSet(java.util.HashSet)

Example 73 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class Model method naiveCalculation.

public Expression naiveCalculation(Expression query) {
    Expression factorProduct = parse("1");
    for (Expression factor : this.getFactor()) {
        factorProduct = apply(TIMES, factor, factorProduct);
    }
    Expression summedProduct = factorProduct;
    for (Expression variable : this.getVariable()) {
        if (variable != query) {
            String values = this.getValues(variable);
            String string = "sum({{ (on " + variable + " in " + values + " ) " + summedProduct + " }})";
            summedProduct = theory.evaluate(parse(string), context);
        }
    }
    return summedProduct;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 74 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class MultiIndexQuantifierEliminator method solve.

/**
	 * Convenience substitute for {@link #solve(AssociativeCommutativeGroup, Expression, Expression, Collection, Context)}
	 * assuming a true constraint.
	 */
default default Expression solve(AssociativeCommutativeGroup group, List<Expression> indices, Expression body, Context context) {
    Constraint trueConstraint = context.getTheory().makeTrueConstraint();
    Expression result = solve(group, indices, trueConstraint, body, context);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 75 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class MultiIndexQuantifierEliminator method solve.

// Convenience:
/**
	 * Convenience substitute for {@link #solve(AssociativeCommutativeGroup, Collection, Expression, Context)} that takes care of constructing the Context
	 * given the data required to build it.
	 */
default default Expression solve(AssociativeCommutativeGroup group, Expression expression, List<Expression> indices, Map<String, String> mapFromSymbolNameToTypeName, Map<String, String> mapFromCategoricalTypeNameToSizeString, Collection<Type> additionalTypes, Predicate<Expression> isUniquelyNamedConstantPredicate, Theory theory) {
    Context context = SGDPLLTUtil.makeContext(mapFromSymbolNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes, isUniquelyNamedConstantPredicate, theory);
    Expression result = solve(group, indices, expression, context);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1392 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)196 Context (com.sri.ai.grinder.api.Context)187 Type (com.sri.ai.expresso.api.Type)124 TrueContext (com.sri.ai.grinder.core.TrueContext)113 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)100 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)91 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)90 Context (com.sri.ai.grinder.sgdpllt.api.Context)87 Theory (com.sri.ai.grinder.api.Theory)78 Map (java.util.Map)78 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)71 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)68 List (java.util.List)68 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)63 CommonTheory (com.sri.ai.grinder.application.CommonTheory)55 LinkedHashMap (java.util.LinkedHashMap)55 LinkedHashSet (java.util.LinkedHashSet)54 Pair (com.sri.ai.util.base.Pair)52