Search in sources :

Example 16 with Theory

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

the class CompoundTheory method getTheory.

// NOTE: package protected so TestingSupport can utilize.
Theory getTheory(Expression variable, Context context) {
    Type type = GrinderUtil.getType(variable, context);
    Theory result = getTheory(variable, type);
    return result;
}
Also used : Type(com.sri.ai.expresso.api.Type) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) AbstractTheory(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheory)

Example 17 with Theory

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

Example 18 with Theory

use of com.sri.ai.grinder.sgdpllt.api.Theory in project aic-praise by aic-sri-international.

the class RandomConditionalPotentialExpressionGenerator method newTheoryTestingSupport.

private TheoryTestingSupport newTheoryTestingSupport(Random random, RandomHOGMv1Generator.TheoryTypePropositionalArgs[] propositionTheoryArgs, RandomHOGMv1Generator.TheoryTypeEqualityArgs[] equalityTheoryArgs, RandomHOGMv1Generator.TheoryTypeInequalityArgs[] inequalityTheoryArgs) {
    List<Theory> theories = new ArrayList<>();
    if (propositionTheoryArgs.length > 0) {
        theories.add(new PropositionalTheory());
    }
    if (equalityTheoryArgs.length > 0) {
        EqualityTheory equalityTheory;
        if (inequalityTheoryArgs.length == 0) {
            // first flag is 'true' because all equalities are atoms in the final theory; there is no need to check arguments type
            equalityTheory = new EqualityTheory(true, true);
        } else {
            // 'false' because not all equalities are atoms in this final theory; need to check arguments type
            equalityTheory = new EqualityTheory(false, true);
        }
        theories.add(equalityTheory);
    }
    if (inequalityTheoryArgs.length > 0) {
        DifferenceArithmeticTheory differenceArithmeticTheory;
        if (equalityTheoryArgs.length == 0) {
            // first flag is 'true' because all equalities are atoms in the final theory; there is no need to check arguments type
            differenceArithmeticTheory = new DifferenceArithmeticTheory(true, true);
        } else {
            // 'false' because not all equalities are atoms in this final theory; need to check arguments type
            differenceArithmeticTheory = new DifferenceArithmeticTheory(false, true);
        }
        theories.add(differenceArithmeticTheory);
    }
    Theory finalTheory;
    if (theories.size() > 1) {
        finalTheory = new CompoundTheory(theories.toArray(new Theory[theories.size()]));
    } else {
        finalTheory = theories.get(0);
    }
    TheoryTestingSupport result = TheoryTestingSupport.make(random, finalTheory);
    return result;
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) ArrayList(java.util.ArrayList) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)

Example 19 with Theory

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

Example 20 with Theory

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

the class SGDPLLTTester method testCompleteMultiVariableConstraints.

/**
	 * Given a theory and a number <code>n</code> of multi-variable constraint tests,
	 * generates <code>n</code> formulas in the theory
	 * and see if those detected as unsatisfiable by the corresponding solver
	 * are indeed unsatisfiable (checked by brute force).
	 * Throws an {@link Error} with the failure description if a test fails.
	 * @param theoryTestingSupport
	 * @param numberOfTests
	 * @param maxNumberOfLiterals
	 * @param outputCount
	 */
public static void testCompleteMultiVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    NullaryFunction<Constraint> makeInitialConstraint = () -> new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
    Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteral(context);
    // CompleteMultiVariableContext is complete
    TestRunner tester = SGDPLLTTester::testCompleteSatisfiability;
    runTesterGivenOnSuccessiveConjunctionsOfLiterals("complete satisfiability", tester, numberOfTests, maxNumberOfLiterals, testAgainstBruteForce, theoryTestingSupport, makeInitialConstraint, makeRandomLiteral, outputCount, context);
}
Also used : CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) BinaryFunction(com.sri.ai.util.base.BinaryFunction) Util.removeFromSetNonDestructively(com.sri.ai.util.Util.removeFromSetNonDestructively) SubExpressionsDepthFirstIterator(com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) Function(java.util.function.Function) GrinderUtil(com.sri.ai.grinder.helper.GrinderUtil) Util.in(com.sri.ai.util.Util.in) ThereExists(com.sri.ai.grinder.sgdpllt.library.boole.ThereExists) AbstractIterativeMultiIndexQuantifierElimination(com.sri.ai.grinder.sgdpllt.interpreter.AbstractIterativeMultiIndexQuantifierElimination) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Map(java.util.Map) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) And(com.sri.ai.grinder.sgdpllt.library.boole.And) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint) ZERO(com.sri.ai.expresso.helper.Expressions.ZERO) LinkedHashSet(java.util.LinkedHashSet) Sets(com.sri.ai.grinder.sgdpllt.library.set.Sets) Type(com.sri.ai.expresso.api.Type) NullaryFunction(com.sri.ai.util.base.NullaryFunction) Util.join(com.sri.ai.util.Util.join) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Simplifier(com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier) Collection(java.util.Collection) Util.list(com.sri.ai.util.Util.list) Set(java.util.Set) Expressions.getVariableReferences(com.sri.ai.expresso.helper.Expressions.getVariableReferences) Context(com.sri.ai.grinder.sgdpllt.api.Context) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Beta(com.google.common.annotations.Beta) IndexExpressions(com.sri.ai.grinder.sgdpllt.library.indexexpression.IndexExpressions) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Util(com.sri.ai.util.Util) AssociativeCommutativeGroup(com.sri.ai.grinder.sgdpllt.group.AssociativeCommutativeGroup) Util.pickKElementsWithoutReplacement(com.sri.ai.util.Util.pickKElementsWithoutReplacement) TRUE(com.sri.ai.expresso.helper.Expressions.TRUE) BruteForceCommonInterpreter(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter) AssignmentsIterator(com.sri.ai.grinder.helper.AssignmentsIterator) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

Aggregations

Theory (com.sri.ai.grinder.sgdpllt.api.Theory)29 Expression (com.sri.ai.expresso.api.Expression)21 Context (com.sri.ai.grinder.sgdpllt.api.Context)13 Type (com.sri.ai.expresso.api.Type)10 Map (java.util.Map)9 Beta (com.google.common.annotations.Beta)8 SingleVariableConstraint (com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)8 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)8 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)8 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)8 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)8 Collection (java.util.Collection)8 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)7 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)7 AssociativeCommutativeGroup (com.sri.ai.grinder.sgdpllt.group.AssociativeCommutativeGroup)7 And (com.sri.ai.grinder.sgdpllt.library.boole.And)7 Util (com.sri.ai.util.Util)7 Util.join (com.sri.ai.util.Util.join)7 Util.list (com.sri.ai.util.Util.list)7 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)6