Search in sources :

Example 21 with Theory

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

the class SGDPLLTTester method testMultiVariableConstraints.

/**
	 * 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 testMultiVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
    NullaryFunction<Constraint> makeInitialConstraint = () -> new DefaultMultiVariableConstraint(theoryTestingSupport.getTheory());
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteral(context);
    // DefaultMultiVariableConstraint is incomplete
    TestRunner tester = SGDPLLTTester::testIncompleteSatisfiability;
    runTesterGivenOnSuccessiveConjunctionsOfLiterals("incomplete 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) 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) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint)

Example 22 with Theory

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

the class SGDPLLTTester method runModelCountingTestForSingleVariableConstraint.

private static void runModelCountingTestForSingleVariableConstraint(Expression variable, Collection<Expression> literals, Constraint constraint, boolean testAgainstBruteForce, Theory theory, Context context) {
    Expression literalsConjunction = And.make(literals);
    String problemDescription = "model counting of " + literalsConjunction + " for variable " + variable;
    output("Problem: " + problemDescription);
    Simplifier symbolicSolver = (e, p) -> computeModelCountBySolver((SingleVariableConstraint) e, p);
    SingleVariableConstraint singleVariableConstraint = (SingleVariableConstraint) constraint;
    Expression symbolicSolution = symbolicSolver.apply(singleVariableConstraint, context);
    if (Util.thereExists(new SubExpressionsDepthFirstIterator(symbolicSolution), e -> e instanceof QuantifiedExpression || Sets.isIntensionalSet(e))) {
        throw new Error("Symbolic solution is not quantifier-free: " + symbolicSolution);
    }
    output("Symbolic result: " + symbolicSolution);
    if (testAgainstBruteForce) {
        if (singleVariableConstraint.isContradiction()) {
            if (!symbolicSolution.equals(ZERO)) {
                throw new Error("Constraint is contradiction, but symbolic solver does not produce 0, but instead " + symbolicSolution);
            }
        } else {
            Expression testingVariable = singleVariableConstraint.getVariable();
            Set<Expression> allVariables = getVariableReferences(singleVariableConstraint, context);
            Collection<Expression> otherVariables = removeFromSetNonDestructively(allVariables, v -> v.equals(testingVariable));
            BinaryFunction<BruteForceCommonInterpreter, Context, Expression> fromInterpreterAndContextWithAssignmentToOtherVariablesToBruteForceSolution = (interpreter, contextWithAssignmentToOtherVariables) -> bruteForceModelCounterForVariableGivenInterpreterAndAssignmentToOtherVariables(variable, literalsConjunction, interpreter, theory, contextWithAssignmentToOtherVariables);
            testSymbolicVsBruteForceComputationForEachAssignment(theory, problemDescription, otherVariables, symbolicSolution, fromInterpreterAndContextWithAssignmentToOtherVariablesToBruteForceSolution, context);
        }
    } else {
        output("Skipping test againt brute-force.");
    }
}
Also used : 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) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) BruteForceCommonInterpreter(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) Simplifier(com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier) SubExpressionsDepthFirstIterator(com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator)

Example 23 with Theory

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

the class SGDPLLTTester method testSingleVariableConstraints.

/**
	 * Given a theory and a number <code>n</code> of single-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 testSingleVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    NullaryFunction<Constraint> makeInitialConstraint = () -> theoryTestingSupport.getTheory().makeSingleVariableConstraint(parse(theoryTestingSupport.pickTestingVariableAtRandom()), theoryTestingSupport.getTheory(), context);
    Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteralOn(((SingleVariableConstraint) c).getVariable().toString(), context);
    boolean isComplete = theoryTestingSupport.getTheory().singleVariableConstraintIsCompleteWithRespectToItsVariable();
    TestRunner tester = isComplete ? SGDPLLTTester::testCompleteSatisfiability : SGDPLLTTester::testIncompleteSatisfiability;
    String problemName = (isComplete ? "complete" : "incomplete") + " satisfiability for single-variable constraints";
    runTesterGivenOnSuccessiveConjunctionsOfLiterals(problemName, 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) 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) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) 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)

Example 24 with Theory

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

the class CompilationTest method test.

@Test
public void test() {
    Expression input;
    Expression expected;
    Theory theory = new CompoundTheory(new EqualityTheory(true, true), new PropositionalTheory());
    Map<String, String> mapFromCategoricalTypeNameToSizeString;
    Map<String, String> mapFromVariableNameToTypeName;
    Map<String, String> mapFromUniquelyNamedConstantToTypeName;
    input = Expressions.parse("if X = a then if X = b then 1 else 2 else 3");
    expected = parse("if X = a then 2 else 3");
    mapFromCategoricalTypeNameToSizeString = Util.map("Everything", "2");
    mapFromVariableNameToTypeName = Util.map("X", "Everything");
    mapFromUniquelyNamedConstantToTypeName = Util.map("a", "Everything", "b", "Everything");
    runTest(input, expected, theory, mapFromCategoricalTypeNameToSizeString, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName);
    input = Expressions.parse("" + "if X = a and Y = a then 0.1 else " + "if X = a and Y = b then 0.1 else " + "if X = b and Y = a then 0.2 else " + // + "if X = b and Y = b then 0.2" // no need to test because it is the last case
    "0.2");
    expected = parse("if X = a then 0.1 else 0.2");
    mapFromCategoricalTypeNameToSizeString = Util.map("Everything", "2");
    mapFromVariableNameToTypeName = Util.map("X", "Everything", "Y", "Everything");
    mapFromUniquelyNamedConstantToTypeName = Util.map("a", "Everything", "b", "Everything");
    runTest(input, expected, theory, mapFromCategoricalTypeNameToSizeString, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName);
    input = Expressions.parse("" + "if X = a and Y = a and Z = a then 0.1 else " + "if X = a and Y = a and Z = b then 0.1 else " + "if X = a and Y = a and Z = c then 0.1 else " + "if X = a and Y = b and Z = a then 0.1 else " + "if X = a and Y = b and Z = b then 0.1 else " + "if X = a and Y = b and Z = c then 0.1 else " + "if X = a and Y = c and Z = a then 0.1 else " + "if X = a and Y = c and Z = b then 0.1 else " + "if X = a and Y = c and Z = c then 0.1 else " + "if X = b and Y = a and Z = a then 0.2 else " + "if X = b and Y = a and Z = b then 0.2 else " + "if X = b and Y = a and Z = c then 0.2 else " + "if X = b and Y = b and Z = a then 0.2 else " + "if X = b and Y = b and Z = b then 0.2 else " + "if X = b and Y = b and Z = c then 0.2 else " + "if X = b and Y = c and Z = a then 0.2 else " + "if X = b and Y = c and Z = b then 0.2 else " + "if X = b and Y = c and Z = c then 0.2 else " + "if X = c and Y = a and Z = a then 0.3 else " + "if X = c and Y = a and Z = b then 0.3 else " + "if X = c and Y = a and Z = c then 0.3 else " + "if X = c and Y = b and Z = a then 0.3 else " + "if X = c and Y = b and Z = b then 0.3 else " + "if X = c and Y = b and Z = c then 0.3 else " + "if X = c and Y = c and Z = a then 0.3 else " + "if X = c and Y = c and Z = b then 0.3 else " + /* X = c and Y = c and Z = c ; no need as it is implied by domain definition */
    "0.3");
    expected = parse("if X = a then 0.1 else if X = b then 0.2 else 0.3");
    mapFromCategoricalTypeNameToSizeString = Util.map("Everything", "3");
    mapFromVariableNameToTypeName = Util.map("X", "Everything", "Y", "Everything", "Z", "Everything");
    mapFromUniquelyNamedConstantToTypeName = Util.map("a", "Everything", "b", "Everything", "c", "Everything");
    runTest(input, expected, theory, mapFromCategoricalTypeNameToSizeString, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName);
    // Same thing, but with non-capitalized variables that should still be recognized as variables
    input = Expressions.parse("" + "if x = a and y = a and z = a then 0.1 else " + "if x = a and y = a and z = b then 0.1 else " + "if x = a and y = a and z = c then 0.1 else " + "if x = a and y = b and z = a then 0.1 else " + "if x = a and y = b and z = b then 0.1 else " + "if x = a and y = b and z = c then 0.1 else " + "if x = a and y = c and z = a then 0.1 else " + "if x = a and y = c and z = b then 0.1 else " + "if x = a and y = c and z = c then 0.1 else " + "if x = b and y = a and z = a then 0.2 else " + "if x = b and y = a and z = b then 0.2 else " + "if x = b and y = a and z = c then 0.2 else " + "if x = b and y = b and z = a then 0.2 else " + "if x = b and y = b and z = b then 0.2 else " + "if x = b and y = b and z = c then 0.2 else " + "if x = b and y = c and z = a then 0.2 else " + "if x = b and y = c and z = b then 0.2 else " + "if x = b and y = c and z = c then 0.2 else " + "if x = c and y = a and z = a then 0.3 else " + "if x = c and y = a and z = b then 0.3 else " + "if x = c and y = a and z = c then 0.3 else " + "if x = c and y = b and z = a then 0.3 else " + "if x = c and y = b and z = b then 0.3 else " + "if x = c and y = b and z = c then 0.3 else " + "if x = c and y = c and z = a then 0.3 else " + "if x = c and y = c and z = b then 0.3 else " + /* x = c and y = c and z = c ; no need as it is implied by domain definition */
    "0.3");
    expected = parse("if x = a then 0.1 else if x = b then 0.2 else 0.3");
    mapFromCategoricalTypeNameToSizeString = Util.map("Everything", "3");
    mapFromVariableNameToTypeName = Util.map("x", "Everything", "y", "Everything", "z", "Everything");
    mapFromUniquelyNamedConstantToTypeName = Util.map("a", "Everything", "b", "Everything", "c", "Everything");
    runTest(input, expected, theory, mapFromCategoricalTypeNameToSizeString, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName);
    input = Expressions.parse("" + "if not g0 and (g1 = consg1_0)\r\n" + "then 0.0001\r\n" + "else if not g0 and (g1 = consg1_1)\r\n" + "     then 1\r\n" + "     else if not g0 and (g1 = consg1_2)\r\n" + "          then 0.0001\r\n" + "          else if not g0 and (g1 = consg1_3)\r\n" + "               then 1\r\n" + "               else if g0 and (g1 = consg1_0)\r\n" + "                    then 1\r\n" + "                    else if g0 and (g1 = consg1_1)\r\n" + "                         then 1\r\n" + "                         else if g0 and (g1 = consg1_2)\r\n" + "                              then 1\r\n" + "                              else 1\r\n" + "");
    expected = parse("if not g0 then if g1 = consg1_0 then 0.0001 else if g1 = consg1_1 then 1 else if g1 = consg1_2 then 0.0001 else 1 else 1");
    mapFromCategoricalTypeNameToSizeString = Util.map("G1Type", "4", "Boolean", "2");
    mapFromVariableNameToTypeName = Util.map("g0", "Boolean", "g1", "G1Type");
    mapFromUniquelyNamedConstantToTypeName = Util.map("consg1_0", "G1Type", "consg1_1", "G1Type", "consg1_2", "G1Type", "consg1_3", "G1Type");
    runTest(input, expected, theory, mapFromCategoricalTypeNameToSizeString, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName);
    input = Expressions.parse("if not g0 then 1 else 1");
    expected = parse("1");
    mapFromCategoricalTypeNameToSizeString = Util.map("G1Type", "4", "Boolean", "2");
    mapFromVariableNameToTypeName = Util.map("g0", "Boolean", "g1", "G1Type");
    mapFromUniquelyNamedConstantToTypeName = Util.map();
    runTest(input, expected, theory, mapFromCategoricalTypeNameToSizeString, mapFromVariableNameToTypeName, mapFromUniquelyNamedConstantToTypeName);
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Expression(com.sri.ai.expresso.api.Expression) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) 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) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 25 with Theory

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

the class BoundTest method testNormalize.

@Test
public void testNormalize() {
    Theory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory());
    Context context = new TrueContext(theory);
    context = context.extendWithSymbolsAndTypes("X", "Boolean");
    context = context.extendWithSymbolsAndTypes("Y", "Boolean");
    //Set of numbers
    Expression one = DefaultSymbol.createSymbol(1);
    Expression two = DefaultSymbol.createSymbol(2);
    Expression three = DefaultSymbol.createSymbol(3);
    Expression setOFNumbers = ExtensionalSets.makeUniSet(one, two, three);
    //Set of functions
    Expression phi1 = parse("if X = true then 1 else if Y = true then 2 else 3");
    Expression phi2 = parse("if X = true then if Y = true then 4 else 5 else 6");
    Expression phi3 = parse("if X = true then 7 else if Y = true then 8 else 9");
    Expression phi4 = parse("if X = true then 10 else if Y = true then 11 else 12");
    Expression setOfFactors = ExtensionalSets.makeUniSet(phi1, phi2, phi3, phi4);
    assertEquals(parse("{if X then 1/7 else if Y then 2/7 else 3/7," + " if X then if Y then 4/21 else 5/21 else 2/7, " + "if X then 7/31 else if Y then 8/31 else 9/31, " + "if X then 10/43 else if Y then 11/43 else 12/43 }"), Bounds.normalize(setOfFactors, theory, context));
    assertEquals(parse("{ 1, 1, 1 }"), Bounds.normalize(setOFNumbers, theory, context));
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) 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) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Test(org.junit.Test)

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