use of com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class SGDPLLT method solve.
/**
* @param group
* @param indices
* @param indicesCondition
* @param body
* @param context
* @return
*/
@Override
public Expression solve(AssociativeCommutativeGroup group, List<Expression> indices, Expression indicesCondition, Expression body, Context context) {
Theory theory = context.getTheory();
Expression currentBody = body;
int numberOfIndices = indices.size();
if (numberOfIndices != 0) {
// Re-use {@link SingleVariableConstraint} if condition is one.
// TODO: eventually we want the algorithm to work so that it splitters may be entire constraints,
// if they are found. Then this encoding would become superfluous,
// and the condition could always be safely encoded in the body, since it would then be picked and re-used.
// This would also re-use body if it happens to be a constraint.
Pair<Expression, SingleVariableConstraint> bodyAndLastIndexConstraint = SGDPLLT.encodeConditionAsLastIndexConstraintIfPossibleOrInBodyOtherwise(group, indices, indicesCondition, body, theory, context);
currentBody = bodyAndLastIndexConstraint.first;
SingleVariableConstraint lastIndexConstraint = bodyAndLastIndexConstraint.second;
if (lastIndexConstraint.isContradiction()) {
return group.additiveIdentityElement();
}
for (int i = numberOfIndices - 1; i >= 0; i--) {
// evaluate from inside out; this may change in the future
Expression index = indices.get(i);
SingleVariableConstraint constraintForThisIndex = i == numberOfIndices - 1 ? lastIndexConstraint : theory.makeSingleVariableConstraint(index, theory, context);
ExpressionLiteralSplitterStepSolver quantifierEliminatorStepSolver = theory.getSingleVariableConstraintQuantifierEliminatorStepSolver(group, constraintForThisIndex, currentBody, context);
if (quantifierEliminatorStepSolver != null) {
currentBody = quantifierEliminatorStepSolver.solve(context);
} else {
// cannot eliminate this level, so reconstruct original expression up to this index
throw new Error("Reconstruction of quantifier not yet eliminable not yet implemented.");
// once implemented, must return
}
}
} else {
currentBody = IfThenElse.make(indicesCondition, currentBody, group.additiveIdentityElement());
}
// Normalize final result.
ExpressionLiteralSplitterStepSolver evaluator = theory.makeEvaluatorStepSolver(currentBody);
currentBody = evaluator.solve(context);
return currentBody;
}
use of com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class MultiVariableContextWithCheckedProperty method check.
private MultiVariableContextWithCheckedProperty check(Context context) {
MultiVariableContextWithCheckedProperty result;
if (checked) {
result = this;
} else {
ExpressionLiteralSplitterStepSolver problem = contextDependentProblemStepSolverMaker.apply(head, context);
Expression solution = problem.solve(tail);
if (solution == null) {
// tail is found to be inconsistent with given context
result = makeContradiction();
} else if (solution.equals(FALSE)) {
// the head constraint does not exhibit the property in all contexts, so the total constraint does not either.
result = makeContradiction();
} else {
this.checked = true;
result = this;
}
}
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class DifferenceArithmeticTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraint, Expression body, Context context) {
ExpressionStepSolver formulaSplitterStepSolver;
if (group instanceof Sum) {
formulaSplitterStepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver(constraint, body);
} else {
formulaSplitterStepSolver = new QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(group, constraint, body);
}
ExpressionLiteralSplitterStepSolver result = new ExpressionStepSolverToLiteralSplitterStepSolverAdapter(formulaSplitterStepSolver);
;
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class CompoundTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraint, Expression body, Context context) {
Theory theory = getTheory(constraint.getVariable(), context);
ExpressionLiteralSplitterStepSolver result;
if (theory != null) {
result = theory.getSingleVariableConstraintQuantifierEliminatorStepSolver(group, constraint, body, context);
} else {
result = null;
}
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class CompoundTheory method getSingleVariableConstraintModelCountingStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintModelCountingStepSolver(SingleVariableConstraint constraint, Context context) {
Theory theory = getTheory(constraint.getVariable(), context);
ExpressionLiteralSplitterStepSolver result;
if (theory != null) {
result = theory.getSingleVariableConstraintModelCountingStepSolver(constraint, context);
} else {
result = null;
}
return result;
}
Aggregations