Search in sources :

Example 16 with ExpressionLiteralSplitterStepSolver

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;
}
Also used : SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Expression(com.sri.ai.expresso.api.Expression) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)

Example 17 with ExpressionLiteralSplitterStepSolver

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;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)

Example 18 with ExpressionLiteralSplitterStepSolver

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;
}
Also used : ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver) QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(com.sri.ai.grinder.sgdpllt.core.solver.QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver) Sum(com.sri.ai.grinder.sgdpllt.group.Sum) ExpressionStepSolverToLiteralSplitterStepSolverAdapter(com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)

Example 19 with ExpressionLiteralSplitterStepSolver

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;
}
Also used : Theory(com.sri.ai.grinder.sgdpllt.api.Theory) AbstractTheory(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheory) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)

Example 20 with ExpressionLiteralSplitterStepSolver

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;
}
Also used : Theory(com.sri.ai.grinder.sgdpllt.api.Theory) AbstractTheory(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheory) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)

Aggregations

ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)26 Expression (com.sri.ai.expresso.api.Expression)14 Context (com.sri.ai.grinder.sgdpllt.api.Context)5 ContextSplitting (com.sri.ai.grinder.sgdpllt.core.constraint.ContextSplitting)5 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)5 ExpressionStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver)4 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)4 ExpressionStepSolverToLiteralSplitterStepSolverAdapter (com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)4 QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver (com.sri.ai.grinder.sgdpllt.core.solver.QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver)4 Test (org.junit.Test)4 Step (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver.Step)3 StepSolver (com.sri.ai.grinder.sgdpllt.api.StepSolver)3 AbstractTheory (com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheory)3 TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)3 ConstantExpressionStepSolver (com.sri.ai.grinder.sgdpllt.theory.base.ConstantExpressionStepSolver)3 Expressions (com.sri.ai.expresso.helper.Expressions)2 Solution (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver.Solution)2 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)2 Sum (com.sri.ai.grinder.sgdpllt.group.Sum)2 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)2