Search in sources :

Example 1 with ExpressionStepSolver

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

Example 2 with ExpressionStepSolver

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
}
Also used : SummationOnDifferenceArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) SingleQuantifierEliminationProblem(com.sri.ai.grinder.api.SingleQuantifierEliminationProblem) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) Sum(com.sri.ai.grinder.group.Sum) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)

Example 3 with ExpressionStepSolver

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

Example 4 with ExpressionStepSolver

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);
}
Also used : Theory(com.sri.ai.grinder.api.Theory) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver)

Example 5 with ExpressionStepSolver

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

Aggregations

ExpressionStepSolver (com.sri.ai.grinder.api.ExpressionStepSolver)10 Expression (com.sri.ai.expresso.api.Expression)4 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver)4 ExpressionStepSolverToLiteralSplitterStepSolverAdapter.toExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter.toExpressionLiteralSplitterStepSolver)4 QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver (com.sri.ai.grinder.core.solver.QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver)4 Sum (com.sri.ai.grinder.group.Sum)4 Theory (com.sri.ai.grinder.api.Theory)3 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)2 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)2 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)2 SingleVariableLinearRealArithmeticConstraint (com.sri.ai.grinder.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint)2 Beta (com.google.common.annotations.Beta)1 Function (com.google.common.base.Function)1 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)1 Context (com.sri.ai.grinder.api.Context)1 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)1 TrueContext (com.sri.ai.grinder.core.TrueContext)1 ContextSplitting (com.sri.ai.grinder.core.constraint.ContextSplitting)1 Simplifier (com.sri.ai.grinder.rewriter.api.Simplifier)1 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)1