Search in sources :

Example 6 with BruteForceCommonInterpreter

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");
    }
}
Also used : Context(com.sri.ai.grinder.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) BruteForceCommonInterpreter(com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

Example 7 with BruteForceCommonInterpreter

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;
}
Also used : BruteForceCommonInterpreter(com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter) Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

Example 8 with BruteForceCommonInterpreter

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()));
}
Also used : BruteForceCommonInterpreter(com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Random(java.util.Random) Exhaustive(com.sri.ai.grinder.rewriter.core.Exhaustive) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) Recursive(com.sri.ai.grinder.rewriter.core.Recursive) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Before(org.junit.Before)

Example 9 with BruteForceCommonInterpreter

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);
}
Also used : BruteForceCommonInterpreter(com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter) Expression(com.sri.ai.expresso.api.Expression)

Aggregations

BruteForceCommonInterpreter (com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter)9 Expression (com.sri.ai.expresso.api.Expression)8 Context (com.sri.ai.grinder.api.Context)5 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)4 Type (com.sri.ai.expresso.api.Type)3 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)3 Theory (com.sri.ai.grinder.api.Theory)3 CompleteMultiVariableContext (com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext)3 AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)3 Beta (com.google.common.annotations.Beta)2 TRUE (com.sri.ai.expresso.helper.Expressions.TRUE)2 ZERO (com.sri.ai.expresso.helper.Expressions.ZERO)2 Expressions.getVariablesBeingReferenced (com.sri.ai.expresso.helper.Expressions.getVariablesBeingReferenced)2 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)2 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)2 SubExpressionsDepthFirstIterator (com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator)2 Constraint (com.sri.ai.grinder.api.Constraint)2 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)2 DefaultMultiVariableConstraint (com.sri.ai.grinder.core.constraint.DefaultMultiVariableConstraint)2 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)2