Search in sources :

Example 26 with Expression

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

the class SetOfArgumentTuplesForFunctionOccurringInExpressionTest method testCase6.

@Test
public // &bigcup;<sub>x</sub>(oc<sub>&fnof;</sub>[C] &cup; oc<sub>&fnof;</sub>[E&prime;])
void testCase6() {
    Expression e = parse("{ (on X in 1..10) f(X,2) : f(X,3) != 4 }");
    Assert.assertEquals(parse("Union({{(on X in 1..10) {(X,3)} union {(X,2)} }})"), getSetOfArgumentTuples(e));
    e = parse("{{ (on X in 1..10) f(X,2) : f(X,3) != 4 }}");
    Assert.assertEquals(parse("Union({{(on X in 1..10) {(X,3)} union {(X,2)} }})"), getSetOfArgumentTuples(e));
    e = parse("| X in 1..10 : f(X,3) != 4 |");
    Assert.assertEquals(parse("Union({{(on X in 1..10) {(X,3)} }})"), getSetOfArgumentTuples(e));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) SetOfArgumentTuplesForFunctionOccurringInExpression(com.sri.ai.grinder.sgdpllt.library.set.invsupport.SetOfArgumentTuplesForFunctionOccurringInExpression) Test(org.junit.Test)

Example 27 with Expression

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

the class EvaluationTest method runTest.

private void runTest(String expressionString, Expression expected, Context context) {
    Expression expression = parse(expressionString);
    ExpressionLiteralSplitterStepSolver stepSolver = context.getTheory().makeEvaluatorStepSolver(expression);
    System.out.println("Evaluating " + expression);
    Expression solution = ContextDependentExpressionProblemSolver.staticSolve(stepSolver, context);
    System.out.println(expression + " -----> " + solution + "\n");
    assertEquals(expected, solution);
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)

Example 28 with Expression

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

the class AbstractSingleVariableConstraintWithDependentNormalizedAtoms method impliesLiteralWithDifferentNormalizedAtom.

/**
	 * Indicates whether, according to the current theory, sign1 atom1 implies sign2 atom2,
	 * where atom1 and atom2 can be assumed distinct (the result is not defined otherwise).
	 * Remember that the notion of "atom" is specific to this constraint and variable.
	 * @param sign1
	 * @param atom1
	 * @param sign2
	 * @param atom2
	 * @param context
	 * @return
	 */
private boolean impliesLiteralWithDifferentNormalizedAtom(boolean sign1, Expression atom1, boolean sign2, Expression atom2, Context context) {
    Expression sign1Atom1ImpliesSign2Atom2 = getVariableFreeLiteralEquivalentToSign1Atom1ImpliesSign2Atom2(sign1, atom1, sign2, atom2, context);
    boolean result = sign1Atom1ImpliesSign2Atom2.equals(TRUE);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 29 with Expression

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

the class AbstractTheoryTestingSupport method getDefaultTestingType.

/**
	 * Returns the type used for the default testing variables.
	 * @return
	 */
public static Categorical getDefaultTestingType() {
    if (_someType == null) {
        ArrayList<Expression> knownConstants = mapIntoArrayList(list("a", "b", "c", "d"), s -> makeSymbol(s));
        _someType = new Categorical("SomeType", 5, knownConstants);
    }
    return _someType;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Categorical(com.sri.ai.expresso.type.Categorical)

Example 30 with Expression

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

the class MultiVariableContextWithCheckedProperty method conjoinSpecializedForConstraintsIfApplicable.

/**
	 * Returns a pair indicating whether specialized conjoin for constraints applies to this case and,
	 * if so, provides the result of this conjoining.
	 * @param formula
	 * @param context
	 * @return
	 */
private Pair<Boolean, Context> conjoinSpecializedForConstraintsIfApplicable(Expression formula, Context context) {
    Pair<Boolean, Context> result;
    if (formula instanceof SingleVariableConstraint) {
        SingleVariableConstraint formulaAsSingleVariableConstraint = (SingleVariableConstraint) formula;
        Expression variable = formulaAsSingleVariableConstraint.getVariable();
        // TODO: this forces expression representation to be generated, which can be expensive. Better write a method that checks it on the constraint representation itself
        boolean variableAlreadyConstrainedInThis = contains(this, variable);
        if (!variableAlreadyConstrainedInThis) {
            // if the variable is new to this constraint, we can simply tack on its constraint on it. 
            Context newContext = makeAndCheck(getTheory(), formulaAsSingleVariableConstraint, this, contextDependentProblemStepSolverMaker, context);
            result = pair(true, newContext);
        } else {
            // otherwise we won't be able to use the single variable constraint structure in any special way
            result = pair(false, null);
        }
    } else if (formula instanceof MultiVariableContextWithCheckedProperty) {
        MultiVariableContextWithCheckedProperty formulaAsMultiVariableConstraint = (MultiVariableContextWithCheckedProperty) formula;
        // if formula is itself a MultiVariableContextWithCheckedProperty,
        // we conjoin its two known parts individually.
        // Their own inner structure will also be efficiently exploited by these conjunctions.
        Context conjunction = this;
        if (formulaAsMultiVariableConstraint.tail != null) {
            conjunction = conjunction.conjoin(formulaAsMultiVariableConstraint.tail, context);
        }
        if (formulaAsMultiVariableConstraint.head != null) {
            conjunction = conjunction.conjoin(formulaAsMultiVariableConstraint.head, context);
        }
        result = pair(true, conjunction);
    } else {
        // the formula does not have a recognizable structure we can exploit
        result = pair(false, null);
    }
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) 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