use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class AbstractSingleQuantifierEliminationStepSolver method stepOnSubProblemIfSplitterIs.
private Step stepOnSubProblemIfSplitterIs(boolean splitterValue, ExpressionLiteralSplitterStepSolver.Step bodyStep, Constraint indexConstraintAndLiteral, Context context) {
ExpressionStepSolver subProblemStepSolverForThisSplitterValue = makeSubProblemStepSolver(splitterValue, bodyStep, indexConstraintAndLiteral);
Step step = subProblemStepSolverForThisSplitterValue.step(context);
return step;
}
use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method runTest.
private void runTest(Expression variable, String constraintString, Expression body, Expression expected, Context context) {
Theory theory = context.getTheory();
SingleVariableDifferenceArithmeticConstraint constraint = new SingleVariableDifferenceArithmeticConstraint(variable, true, theory);
constraint = (SingleVariableDifferenceArithmeticConstraint) constraint.conjoin(parse(constraintString), context);
Expression typeExpression = context.getTypeExpressionOfRegisteredSymbol(variable);
SingleQuantifierEliminationProblem problem = new DefaultSingleQuantifierEliminationProblem(new Sum(), variable, typeExpression, constraint, body);
ExpressionStepSolver stepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver(problem);
Expression actual = stepSolver.solve(context);
expected = simplify(expected, context);
System.out.println("sum({{ (on " + variable + " in " + GrinderUtil.getTypeExpressionOfExpression(variable, context) + ") " + body + " : " + constraintString + " }} = " + actual + "\n");
if (!expected.equals(actual)) {
Expression difference = apply(MINUS, expected, actual);
Expression differenceResult = simplify(difference, context);
if (!differenceResult.equals(ZERO)) {
System.err.println("Expressions are not equal and even difference is not zero");
System.err.println("Expected: " + expected);
System.err.println("Actual: " + actual);
System.err.println("Difference: " + differenceResult);
fail("Expressions are not equal and even difference is not zero. Expected: " + expected + ", actual: " + actual);
}
}
// TODO: correctness test against grounding
}
use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class PropositionalTheory method getSingleQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleQuantifierEliminatorStepSolver(SingleQuantifierEliminationProblem problem, Context context) {
ExpressionStepSolver formulaSplitterStepSolver = new QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(problem);
ExpressionLiteralSplitterStepSolver result = toExpressionLiteralSplitterStepSolver(formulaSplitterStepSolver);
return result;
}
use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class AbstractModelCountingWithPropagatedLiteralsImportedFromSatisfiabilityStepSolver method getPropagatedCNF.
/**
* This is overridden to re-use satisfiability's propagated CNF.
* It overrides caching done by overridden method, but that's fine since satisfiability should be doing that already.
*/
@Override
protected ArrayList<ArrayList<Expression>> getPropagatedCNF(Context context) {
Theory theory = getConstraint().getTheory();
ExpressionStepSolver satisfiability = theory.getSingleVariableConstraintSatisfiabilityStepSolver(getConstraint(), context);
if (satisfiability == null) {
throw new Error("No solver present for solving satisfiability of " + getConstraint().getVariable());
}
AbstractExpressionWithPropagatedLiteralsStepSolver satisfiabilityWithPropagatedLiterals;
try {
satisfiabilityWithPropagatedLiterals = (AbstractExpressionWithPropagatedLiteralsStepSolver) satisfiability;
} catch (ClassCastException e) {
throw new Error(this.getClass() + " can only be used with theories providing satisfiability context-dependent step solvers" + " that are extensions of " + AbstractExpressionWithPropagatedLiteralsStepSolver.class + ", but theory " + theory.getClass() + " provided instead an instance of" + satisfiability.getClass());
}
return satisfiabilityWithPropagatedLiterals.getPropagatedCNF(context);
}
use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class LinearRealArithmeticTheory method getSingleQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleQuantifierEliminatorStepSolver(SingleQuantifierEliminationProblem problem, Context context) {
ExpressionStepSolver formulaSplitterStepSolver;
if (problem.getGroup() instanceof Sum) {
formulaSplitterStepSolver = new SummationOnLinearRealArithmeticAndPolynomialStepSolver(problem);
} else {
formulaSplitterStepSolver = new QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(problem);
}
ExpressionLiteralSplitterStepSolver result = toExpressionLiteralSplitterStepSolver(formulaSplitterStepSolver);
return result;
}
Aggregations