Search in sources :

Example 41 with Context

use of com.sri.ai.grinder.sgdpllt.api.Context 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 = AbstractIterativeMultiIndexQuantifierElimination.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 : CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) BruteForceCommonInterpreter(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

Example 42 with Context

use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.

the class SGDPLLTTester method runGroupProblemSolvingTesterOnEmptyConstraint.

/**
	 * Same as {@link #runGroupProblemSolvingTesterForSuccessiveConstraints(String, TestRunner, boolean, AssociativeCommutativeGroup, TheoryTestingSupport, long, int, boolean)},
	 * but running the tester on a single, empty constraint.
	 * @param problemName
	 * @param tester
	 * @param testAgainstBruteForce
	 * @param group
	 * @param theoryTestingSupport
	 * @param numberOfTests
	 * @param outputCount
	 * @throws Error
	 */
private static void runGroupProblemSolvingTesterOnEmptyConstraint(String problemName, TestRunner tester, boolean testAgainstBruteForce, AssociativeCommutativeGroup group, TheoryTestingSupport theoryTestingSupport, long numberOfTests, boolean outputCount) throws Error {
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    SingleVariableConstraint emptyConstraint = theoryTestingSupport.getTheory().makeSingleVariableConstraint(parse(theoryTestingSupport.pickTestingVariableAtRandom()), theoryTestingSupport.getTheory(), context);
    for (int i = 1; i != numberOfTests + 1; i++) {
        tester.runOneTest(list(), emptyConstraint, testAgainstBruteForce, theoryTestingSupport, context);
        indicateCompletionOfTest(outputCount, problemName, i, testAgainstBruteForce, theoryTestingSupport);
    }
}
Also used : CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)

Example 43 with Context

use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.

the class MultiVariableContextWithCheckedProperty method setIsUniquelyNamedConstantPredicate.

@Override
public MultiVariableContextWithCheckedProperty setIsUniquelyNamedConstantPredicate(Predicate<Expression> isUniquelyNamedConstantPredicate) {
    MultiVariableContextWithCheckedProperty result = clone();
    Context newTail = tail.setIsUniquelyNamedConstantPredicate(isUniquelyNamedConstantPredicate);
    result.tail = newTail;
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context)

Example 44 with Context

use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.

the class MultiVariableContextWithCheckedProperty method putAllGlobalObjects.

@Override
public MultiVariableContextWithCheckedProperty putAllGlobalObjects(Map<Object, Object> objects) {
    MultiVariableContextWithCheckedProperty result = clone();
    Context newTail = tail.putAllGlobalObjects(objects);
    result.tail = newTail;
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context)

Example 45 with Context

use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.

the class AbstractIterativeMultiIndexQuantifierElimination method solve.

public Expression solve(AssociativeCommutativeGroup group, List<Expression> indices, Expression indicesCondition, Expression body, Context context) {
    Expression result = group.additiveIdentityElement();
    Expression summand = makeSummand(group, indices, indicesCondition, body, context);
    Rewriter rewriter = new Recursive(new Exhaustive(getTopRewriterUsingContextAssignments()));
    Iterator<Map<Expression, Expression>> assignmentsIterator = makeAssignmentsIterator(indices, indicesCondition, context);
    for (Map<Expression, Expression> indicesValues : in(assignmentsIterator)) {
        Context extendedContext = extendAssignments(indicesValues, context);
        Expression bodyEvaluation = rewriter.apply(summand, extendedContext);
        if (group.isAdditiveAbsorbingElement(bodyEvaluation)) {
            return bodyEvaluation;
        }
        result = group.add(result, bodyEvaluation, extendedContext);
    }
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive) StackedHashMap(com.sri.ai.util.collect.StackedHashMap) Map(java.util.Map)

Aggregations

Context (com.sri.ai.grinder.sgdpllt.api.Context)105 Expression (com.sri.ai.expresso.api.Expression)80 Test (org.junit.Test)48 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)36 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)30 Type (com.sri.ai.expresso.api.Type)28 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)28 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)22 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)20 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)18 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)17 Map (java.util.Map)17 Beta (com.google.common.annotations.Beta)16 CompleteMultiVariableContext (com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext)16 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)14 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)14 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)14 FunctionType (com.sri.ai.expresso.type.FunctionType)13 Util (com.sri.ai.util.Util)13 SingleVariableConstraint (com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)12