Search in sources :

Example 6 with ExpressionStepSolver

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;
}
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 7 with ExpressionStepSolver

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;
}
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)

Example 8 with ExpressionStepSolver

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);
}
Also used : SingleVariableConstraint(com.sri.ai.grinder.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint)

Example 9 with ExpressionStepSolver

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);
}
Also used : BinaryFunction(com.sri.ai.util.base.BinaryFunction) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) Random(java.util.Random) Expression(com.sri.ai.expresso.api.Expression) SummationOnLinearRealArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.SummationOnLinearRealArithmeticAndPolynomialStepSolver) TrueContext(com.sri.ai.grinder.core.TrueContext) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver) Context(com.sri.ai.grinder.api.Context) MeasureOfSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.MeasureOfSingleVariableLinearRealArithmeticConstraintStepSolver) Function(com.google.common.base.Function) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) SatisfiabilityOfSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.SatisfiabilityOfSingleVariableLinearRealArithmeticConstraintStepSolver) Test(org.junit.Test) Beta(com.google.common.annotations.Beta) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Sum(com.sri.ai.grinder.group.Sum) SingleVariableConstraint(com.sri.ai.grinder.api.SingleVariableConstraint) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver) Assert.assertEquals(org.junit.Assert.assertEquals) SingleVariableConstraint(com.sri.ai.grinder.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver)

Example 10 with ExpressionStepSolver

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

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