use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class SetOfArgumentTuplesForFunctionOccurringInExpressionTest method testCase6.
@Test
public // ⋃<sub>x</sub>(oc<sub>ƒ</sub>[C] ∪ oc<sub>ƒ</sub>[E′])
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));
}
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);
}
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;
}
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;
}
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;
}
Aggregations