Search in sources :

Example 1 with MultiQuantifierEliminationProblem

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

the class MultiQuantifierEliminationProblemTest method cornerCasesTest.

@Test
public void cornerCasesTest() {
    MultiQuantifierEliminationProblem problem;
    Expression problemExpression;
    problem = new DefaultMultiQuantifierEliminationProblem(new Sum(), list(), list(), parse("false"), parse("0"));
    problemExpression = parse("sum({{ (on ) 0 : false }})");
    assertEquals(problemExpression, problem.toExpression());
    try {
        problem = new DefaultMultiQuantifierEliminationProblem(new Conjunction(), list(parse("I")), list(parse("Integer"), parse("Boolean")), parse("I > 3 and I < 10 and not J"), parse("true"));
    } catch (AssertionError e) {
        if (!e.getMessage().contains("DefaultMultiQuantifierEliminationProblem")) {
            fail("Should have thrown an error containing 'DefaultMultiQuantifierEliminationProblem'");
        }
    }
}
Also used : Expression(com.sri.ai.expresso.api.Expression) DefaultMultiQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem) MultiQuantifierEliminationProblem(com.sri.ai.grinder.api.MultiQuantifierEliminationProblem) DefaultMultiQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem) Conjunction(com.sri.ai.grinder.group.Conjunction) Sum(com.sri.ai.grinder.group.Sum) Test(org.junit.Test)

Example 2 with MultiQuantifierEliminationProblem

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

the class SamplingProceduralAttachmentSingleQuantifierEliminatorTest method test.

@Test
public void test() {
    String intervalString = "0..10";
    Context context = new TrueContext(new DifferenceArithmeticTheory(true, true));
    MultiQuantifierEliminationProblem problem = new DefaultMultiQuantifierEliminationProblem(new Sum(), list(parse("I")), list(parse(intervalString)), parse("I != 3"), parse("I^2"));
    SamplingProceduralAttachmentSingleQuantifierEliminator eliminator = new SamplingProceduralAttachmentSingleQuantifierEliminator(new CommonSimplifier(), new Random());
    // SHOULD NOT HAVE TO
    context = problem.extend(context);
    Expression sampler = eliminator.solve(problem, context);
    println(sampler);
    Rewriter rewriter = new CombiningTopRewriter(new CommonSimplifier(), ProceduralAttachments.getProceduralAttachmentsTopRewriter(context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
    println(rewriter.apply(sampler, context));
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonSimplifier(com.sri.ai.grinder.library.commonrewriters.CommonSimplifier) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Sum(com.sri.ai.grinder.group.Sum) TrueContext(com.sri.ai.grinder.core.TrueContext) SamplingProceduralAttachmentSingleQuantifierEliminator(com.sri.ai.grinder.interpreter.SamplingProceduralAttachmentSingleQuantifierEliminator) Random(java.util.Random) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) Expression(com.sri.ai.expresso.api.Expression) DefaultMultiQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem) MultiQuantifierEliminationProblem(com.sri.ai.grinder.api.MultiQuantifierEliminationProblem) DefaultMultiQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) Test(org.junit.Test)

Example 3 with MultiQuantifierEliminationProblem

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

the class MultiQuantifierEliminationProblemTest method regularCasesTest.

@Test
public void regularCasesTest() {
    MultiQuantifierEliminationProblem problem;
    Expression problemExpression;
    problem = new DefaultSingleQuantifierEliminationProblem(new Sum(), parse("I"), parse("Integer"), parse("I > 3 and I < 10"), parse("I"));
    problemExpression = parse("sum({{ (on I in Integer) I : I > 3 and I < 10 }})");
    assertEquals(problemExpression, problem.toExpression());
    problem = new DefaultSingleQuantifierEliminationProblem(new Disjunction(), parse("I"), parse("Integer"), parse("I > 3 and I < 10"), parse("true"));
    problemExpression = parse("there exists I in Integer : I > 3 and I < 10");
    assertEquals(problemExpression, problem.toExpression());
    problem = new DefaultSingleQuantifierEliminationProblem(new Conjunction(), parse("I"), parse("Integer"), parse("I > 3 and I < 10"), parse("true"));
    problemExpression = parse("for all I in Integer : if I > 3 and I < 10 then true else true");
    assertEquals(problemExpression, problem.toExpression());
    problem = new DefaultMultiQuantifierEliminationProblem(new Sum(), list(parse("I"), parse("J")), list(parse("Integer"), parse("Boolean")), parse("I > 3 and I < 10 and not J"), parse("I"));
    problemExpression = parse("sum({{ (on I in Integer, J in Boolean) I : I > 3 and I < 10 and not J }})");
    assertEquals(problemExpression, problem.toExpression());
    problem = new DefaultMultiQuantifierEliminationProblem(new Disjunction(), list(parse("I"), parse("J")), list(parse("Integer"), parse("Boolean")), parse("I > 3 and I < 10 and not J"), parse("true"));
    problemExpression = parse("there exists I in Integer : there exists J in Boolean : I > 3 and I < 10 and not J");
    assertEquals(problemExpression, problem.toExpression());
    problem = new DefaultMultiQuantifierEliminationProblem(new Conjunction(), list(parse("I"), parse("J")), list(parse("Integer"), parse("Boolean")), parse("I > 3 and I < 10 and not J"), parse("true"));
    problemExpression = parse("for all I in Integer : for all J in Boolean : if I > 3 and I < 10 and not J then true else true");
    assertEquals(problemExpression, problem.toExpression());
}
Also used : Disjunction(com.sri.ai.grinder.group.Disjunction) Expression(com.sri.ai.expresso.api.Expression) DefaultMultiQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem) MultiQuantifierEliminationProblem(com.sri.ai.grinder.api.MultiQuantifierEliminationProblem) Conjunction(com.sri.ai.grinder.group.Conjunction) DefaultMultiQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) Sum(com.sri.ai.grinder.group.Sum) Test(org.junit.Test)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)3 MultiQuantifierEliminationProblem (com.sri.ai.grinder.api.MultiQuantifierEliminationProblem)3 DefaultMultiQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem)3 Sum (com.sri.ai.grinder.group.Sum)3 Test (org.junit.Test)3 Conjunction (com.sri.ai.grinder.group.Conjunction)2 Context (com.sri.ai.grinder.api.Context)1 TrueContext (com.sri.ai.grinder.core.TrueContext)1 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)1 Disjunction (com.sri.ai.grinder.group.Disjunction)1 SamplingProceduralAttachmentSingleQuantifierEliminator (com.sri.ai.grinder.interpreter.SamplingProceduralAttachmentSingleQuantifierEliminator)1 CommonSimplifier (com.sri.ai.grinder.library.commonrewriters.CommonSimplifier)1 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)1 CombiningTopRewriter (com.sri.ai.grinder.rewriter.core.CombiningTopRewriter)1 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)1 Random (java.util.Random)1