use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class EqualityTheory 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 DifferenceArithmeticTheory method getSingleQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleQuantifierEliminatorStepSolver(SingleQuantifierEliminationProblem problem, Context context) {
ExpressionStepSolver formulaSplitterStepSolver;
if (problem.getGroup() instanceof Sum) {
formulaSplitterStepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver(problem);
} else {
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 LinearRealArithmeticTheoryTest method runTest.
/**
* @param variable
* @param constraintString
* @param expected
* @param computedFunction
* @param stepSolverMaker
* @param context
*/
private void runTest(Expression variable, String constraintString, Expression expected, String computedFunction, Function<SingleVariableConstraint, ExpressionStepSolver> stepSolverMaker, Context context) {
System.out.println("Solving " + computedFunction + " for " + variable + " in " + constraintString);
SingleVariableConstraint constraint = new SingleVariableLinearRealArithmeticConstraint(variable, true, context.getTheory());
constraint = constraint.conjoin(parse(constraintString), context);
ExpressionStepSolver stepSolver = stepSolverMaker.apply(constraint);
Expression actual = stepSolver.solve(context);
System.out.println("Variable " + variable + "\nhas " + computedFunction + ":\n" + actual + "\nfor constraint:\n" + constraintString + "\n");
assertEquals(expected, actual);
}
use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class LinearRealArithmeticTheoryTest method runQuantifierTest.
private void runQuantifierTest(Expression variable, String constraintString, String bodyString, Expression expected, String computedFunction, BinaryFunction<SingleVariableConstraint, Expression, ExpressionStepSolver> stepSolverMaker, Context context) {
Expression body = parse(bodyString);
Function<SingleVariableConstraint, ExpressionStepSolver> stepSolverMakerFromConstraint = c -> stepSolverMaker.apply(c, body);
runTest(variable, constraintString, expected, computedFunction, stepSolverMakerFromConstraint, context);
}
use of com.sri.ai.grinder.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.
the class INCOMPLETE_BooleanFormulaExpressionStepSolver method step.
@Override
public Step step(Context context) {
Step result;
Expression splitter;
Expression problemIfSplitterIsTrue;
Expression problemIfSplitterIsFalse;
Expression functor = booleanFormula.getFunctor();
String functorString = functor == null ? "" : functor.toString();
switch(functorString) {
case FunctorConstants.AND:
List<Expression> arguments = booleanFormula.getArguments();
int numberOfArguments = booleanFormula.numberOfArguments();
splitter = arguments.get(0);
List<Expression> rest = arguments.subList(1, numberOfArguments);
problemIfSplitterIsTrue = And.make(rest);
problemIfSplitterIsFalse = Expressions.FALSE;
break;
default:
splitter = booleanFormula;
problemIfSplitterIsTrue = Expressions.TRUE;
problemIfSplitterIsFalse = Expressions.FALSE;
}
// IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
// Need to extend context to non-conjunctive formulas so I can split on formulas below
ContextSplitting contextSplitting = new ContextSplitting(null, context);
ExpressionStepSolver ifFirstConjunctIsTrue;
ExpressionStepSolver ifFirstConjunctIsFalse;
switch(contextSplitting.getResult()) {
case LITERAL_IS_TRUE:
ifFirstConjunctIsTrue = new INCOMPLETE_BooleanFormulaExpressionStepSolver(problemIfSplitterIsTrue);
result = ifFirstConjunctIsTrue.step(contextSplitting.getContextAndLiteral());
break;
case LITERAL_IS_FALSE:
ifFirstConjunctIsFalse = new INCOMPLETE_BooleanFormulaExpressionStepSolver(problemIfSplitterIsFalse);
result = ifFirstConjunctIsFalse.step(contextSplitting.getContextAndLiteralNegation());
break;
case LITERAL_IS_UNDEFINED:
ifFirstConjunctIsTrue = new INCOMPLETE_BooleanFormulaExpressionStepSolver(problemIfSplitterIsTrue);
ifFirstConjunctIsFalse = new INCOMPLETE_BooleanFormulaExpressionStepSolver(problemIfSplitterIsFalse);
result = new ItDependsOn(splitter, contextSplitting, ifFirstConjunctIsTrue, ifFirstConjunctIsFalse);
break;
case CONSTRAINT_IS_CONTRADICTORY:
throw new Error("Should not be operating under contradictory context, but got " + context);
default:
throw new Error("Unexpected context splitting result: " + contextSplitting.getResult());
}
return result;
}
Aggregations