Search in sources :

Example 1 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.

the class PropositionalTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraintForThisIndex, Expression body, Context context) {
    ExpressionStepSolver formulaSplitterStepSolver = new QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(group, constraintForThisIndex, 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) ExpressionStepSolverToLiteralSplitterStepSolverAdapter(com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)

Example 2 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.

the class EqualityTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraint, Expression body, Context context) {
    ExpressionStepSolver 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) ExpressionStepSolverToLiteralSplitterStepSolverAdapter(com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)

Example 3 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.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.sgdpllt.api.Theory) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver)

Example 4 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver 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 5 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.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();
    Constraint constraint = new SingleVariableDifferenceArithmeticConstraint(variable, true, theory);
    constraint = constraint.conjoin(parse(constraintString), context);
    ExpressionStepSolver stepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver((SingleVariableDifferenceArithmeticConstraint) constraint, body);
    Expression actual = stepSolver.solve(context);
    expected = simplify(expected, context);
    System.out.println("sum({{ (on " + variable + " in " + GrinderUtil.getTypeExpression(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");
        }
    }
// TODO: correctness test against grounding
}
Also used : SummationOnDifferenceArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)

Aggregations

ExpressionStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver)8 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)4 ExpressionStepSolverToLiteralSplitterStepSolverAdapter (com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)4 QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver (com.sri.ai.grinder.sgdpllt.core.solver.QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver)4 Expression (com.sri.ai.expresso.api.Expression)3 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)3 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)2 Sum (com.sri.ai.grinder.sgdpllt.group.Sum)2 SingleVariableLinearRealArithmeticConstraint (com.sri.ai.grinder.sgdpllt.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.sgdpllt.api.Context)1 Simplifier (com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier)1 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)1 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)1 SingleVariableDifferenceArithmeticConstraint (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)1 SummationOnDifferenceArithmeticAndPolynomialStepSolver (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver)1 IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver)1 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)1