use of com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method testSymbolicVsBruteForceComputationForAssignment.
private static void testSymbolicVsBruteForceComputationForAssignment(Map<Expression, Expression> assignment, Theory theory, String problemDescription, Expression symbolicSolution, BinaryFunction<BruteForceCommonInterpreter, Context, Expression> fromInterpreterAndContextWithAssignmentToBruteForceSolution, Context context) throws Error {
BruteForceCommonInterpreter interpreter = new BruteForceCommonInterpreter();
Context extendedContext = Assignment.extendAssignments(assignment, context);
Expression bruteForceResultUnderAssignment = fromInterpreterAndContextWithAssignmentToBruteForceSolution.apply(interpreter, extendedContext);
Expression symbolicResultUnderAssignment = interpreter.apply(symbolicSolution, extendedContext);
output("Under free variables assignment " + assignment);
output("Symbolic result becomes " + symbolicResultUnderAssignment);
output("Brute force result becomes " + bruteForceResultUnderAssignment + "\n");
if (!symbolicResultUnderAssignment.equals(bruteForceResultUnderAssignment)) {
throw new Error("Failure in testing of " + problemDescription + "\n" + "Symbolic solution: " + symbolicSolution + "\n" + "Under assignment to free variables: " + assignment + "\n" + "Value of symbolic solution : " + symbolicResultUnderAssignment + "\n" + "Value of brute force computation: " + bruteForceResultUnderAssignment + "\n" + "Context : " + extendedContext + "\n");
}
}
use of com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method isSatisfiableByBruteForce.
/**
* Determines whether a formula is satisfiable by adding existential quantifiers for each of its variables
* (according to the theory provided) and evaluating it.
* @param formula
* @param theoryTestingSupport
* @param context
* @return whether the formula is satisfiable.
*/
public static boolean isSatisfiableByBruteForce(Expression formula, TheoryTestingSupport theoryTestingSupport, Context context) {
Map<String, Type> variableNamesAndTypesForTesting = theoryTestingSupport.getVariableNamesAndTypesForTesting();
Expression quantifiedFormula = formula;
Collection<Expression> variables = theoryTestingSupport.getTheory().getVariablesIn(formula, context);
for (Expression variable : variables) {
Expression typeNameExpression = parse(variableNamesAndTypesForTesting.get(variable).toString());
quantifiedFormula = ThereExists.make(IndexExpressions.makeIndexExpression(variable, typeNameExpression), quantifiedFormula);
}
Expression evaluation = new BruteForceCommonInterpreter().apply(quantifiedFormula, context);
boolean result = evaluation.equals(TRUE);
return result;
}
use of com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter in project aic-expresso by aic-sri-international.
the class AssignmentsSamplingIteratorTest method setUp.
@Before
public void setUp() {
// Make tests repeatable
random = new Random(1);
conditionRewriter = new Recursive(new Exhaustive(new BruteForceCommonInterpreter()));
context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new EqualityTheory(false, false), new PropositionalTheory()));
}
use of com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter in project aic-expresso by aic-sri-international.
the class BruteForceCommonInterpreterTest method runTest.
public void runTest(String expression, String expected, Context context) {
BruteForceCommonInterpreter interpreter = new BruteForceCommonInterpreter();
Expression result = interpreter.apply(parse(expression), context);
Assert.assertEquals(parse(expected), result);
}
Aggregations