use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class ConjoinedContext method conjoinSpecializedForConstraintsIfApplicable.
/**
* Returns the result of conjoining a formula and this context under a given context if a specialized routine is available,
* or null otherwise.
*/
private Context conjoinSpecializedForConstraintsIfApplicable(Expression formula, Context context) {
Context result;
if (formula instanceof SingleVariableConstraint) {
SingleVariableConstraint formulaAsSingleVariableConstraint = (SingleVariableConstraint) formula;
boolean formulaIsSingleVariableConstraintOnNewVariable = checkIfFormulaISingleVariableConstraintOnNewVariable(formulaAsSingleVariableConstraint);
if (formulaIsSingleVariableConstraintOnNewVariable) {
result = conjoinWithSingleVariableConstraintOnANewVariable(formulaAsSingleVariableConstraint, context);
} else {
// otherwise we won't be able to use the single variable constraint structure in any special way
result = null;
}
} else if (formula instanceof ConjoinedContext) {
ConjoinedContext formulaAsMultiVariableConstraint = (ConjoinedContext) formula;
result = conjoinWithMultiVariableContextWithCheckedProperty(formulaAsMultiVariableConstraint, context);
} else {
result = null;
}
return result;
}
use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class LinearRealArithmeticTheoryTest method runSummationTest.
private void runSummationTest(Expression variable, String constraintString, String bodyString, Expression expected, Simplifier simplifier, Context context) {
Expression typeExpression = context.getTypeExpressionOfRegisteredSymbol(variable);
runQuantifierTest(variable, constraintString, bodyString, expected, "summation for " + bodyString, (SingleVariableConstraint c, Expression b) -> new SummationOnLinearRealArithmeticAndPolynomialStepSolver(new DefaultSingleQuantifierEliminationProblem(new Sum(), variable, typeExpression, c, b)), context);
}
use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class SingleQuantifierEliminationForIndexFreeBody method bodyTimesNumberOfIndexValues.
private Expression bodyTimesNumberOfIndexValues() {
SingleVariableConstraint singleVariableConstraint = (SingleVariableConstraint) getConstraint();
Expression modelCount = singleVariableConstraint.modelCount(context);
Expression result = bodyTimes(modelCount);
return result;
}
use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class CompoundTheory method makeSingleVariableConstraintAfterBookkeeping.
@Override
public SingleVariableConstraint makeSingleVariableConstraintAfterBookkeeping(Expression variable, Context context) {
Theory theoryForVariable = getTheory(variable, context);
SingleVariableConstraint result;
if (theoryForVariable != null) {
result = theoryForVariable.makeSingleVariableConstraintAfterBookkeeping(variable, context);
} else {
result = null;
}
return result;
}
use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method runModelCountingTestForSingleVariableConstraint.
private static void runModelCountingTestForSingleVariableConstraint(Expression variable, Collection<Expression> literals, Constraint constraint, boolean testAgainstBruteForce, Theory theory, Context context) {
Expression literalsConjunction = And.make(literals);
String problemDescription = "model counting of " + literalsConjunction + " for variable " + variable;
output("Problem: " + problemDescription);
Simplifier symbolicSolver = (e, p) -> computeModelCountBySolver((SingleVariableConstraint) e, p);
SingleVariableConstraint singleVariableConstraint = (SingleVariableConstraint) constraint;
Expression symbolicSolution = symbolicSolver.apply(singleVariableConstraint, context);
if (Util.thereExists(new SubExpressionsDepthFirstIterator(symbolicSolution), e -> e instanceof QuantifiedExpression || Sets.isIntensionalSet(e))) {
throw new Error("Symbolic solution is not quantifier-free: " + symbolicSolution);
}
output("Symbolic result: " + symbolicSolution);
if (testAgainstBruteForce) {
if (singleVariableConstraint.isContradiction()) {
if (!symbolicSolution.equals(ZERO)) {
throw new Error("Constraint is contradiction, but symbolic solver does not produce 0, but instead " + symbolicSolution);
}
} else {
Expression testingVariable = singleVariableConstraint.getVariable();
Set<Expression> allVariables = getVariablesBeingReferenced(singleVariableConstraint, context);
Collection<? extends Expression> otherVariables = removeFromSetNonDestructively(allVariables, v -> v.equals(testingVariable));
BinaryFunction<BruteForceCommonInterpreter, Context, Expression> fromInterpreterAndContextWithAssignmentToOtherVariablesToBruteForceSolution = (interpreter, contextWithAssignmentToOtherVariables) -> bruteForceModelCounterForVariableGivenInterpreterAndAssignmentToOtherVariables(variable, literalsConjunction, interpreter, theory, contextWithAssignmentToOtherVariables);
testSymbolicVsBruteForceComputationForEachAssignment(theory, problemDescription, otherVariables, symbolicSolution, fromInterpreterAndContextWithAssignmentToOtherVariablesToBruteForceSolution, context);
}
} else {
output("Skipping test againt brute-force.");
}
}
Aggregations