Search in sources :

Example 6 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class BruteForceCommonInterpreterTest method makeContext.

/**
 * Makes context with initializations necessary for these tests.
 * @return
 */
public Context makeContext() {
    LinkedHashMap<Expression, Expression> assignment = map(parse("Two"), Expressions.TWO);
    Context context = new TrueContext();
    context = Assignment.extendAssignments(assignment, context);
    return context;
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 7 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method setUp.

@Before
public void setUp() {
    // Make tests repeatable
    random = new Random(1);
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new EqualityTheory(false, false), new PropositionalTheory()));
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Random(java.util.Random) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Before(org.junit.Before)

Example 8 with TrueContext

use of com.sri.ai.grinder.core.TrueContext 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 9 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class BoundsTest method declareTheoryContextAndSetOfFactors.

private void declareTheoryContextAndSetOfFactors() {
    /* That's how we create a empty bound
		 * It is useful for abstracting the kind of bound we are talking about:
		 * 		if you say to a program that one of his attributes is a bound, you can let the user choose
		 * 		between a extensional or intensional representation just by passing the right object as 
		 * 		argument.
		 * 
		 * 		Example:
		 * 		
		 * 		class foo{
		 * 			Bound b
		 * 			...
		 * 			public foo(Bound b, ...) {
		 *				this.b = b;
		 *				...
		 *			} 	 
		 * 		}
		 * 		
		 * 		Use:
		 * 		foo object = new foo(new DefaultExtensionalBound(),...);
		 * 		
		 * */
    ExpressoConfiguration.setDisplayNumericsExactlyForSymbols(true);
    extensionalBound = new DefaultExtensionalBound();
    intensionalBound = new DefaultIntensionalBound();
    theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory());
    context = new TrueContext(theory);
    context = context.extendWithSymbolsAndTypes("X", "Boolean");
    context = context.extendWithSymbolsAndTypes("Y", "Boolean");
    context = context.extendWithSymbolsAndTypes("A", "Boolean");
    context = context.extendWithSymbolsAndTypes("B", "Boolean");
    context = context.extendWithSymbolsAndTypes("C", "1..5");
    // context = context.extendWithSymbolsAndTypes("D","{1,3,4,8}");
    // Set of functions
    Expression phi1 = parse("if X = true then 1 else if Y = true then 2 else 3");
    Expression phi2 = parse("if A = true then if Y = true then 4 else 5 else 6");
    Expression phi3 = parse("if X = true then 7 else if B = true then 8 else 9");
    Expression phi4 = parse("if B = true then 10 else if A = true then 11 else 12");
    Expression phi5 = parse("if C < 4 then 10 else if C = 4 then 11 else 12");
    /*
		 * This is how we create a non empty extensional bound
		 */
    setOfFactors = new DefaultExtensionalBound(arrayList(phi1, phi2, phi3, phi4, phi5));
    // Set of numbers
    setOFNumbers = new DefaultExtensionalBound(arrayList(ONE, TWO));
    Set<Expression> Factor = new HashSet<Expression>();
    model = new Model(Factor);
    model.context = model.context.extendWithSymbolsAndTypes("A", "Boolean");
    model.context = model.context.extendWithSymbolsAndTypes("B", "Boolean");
    model.context = model.context.extendWithSymbolsAndTypes("Q", "Boolean");
    model.context = model.context.extendWithSymbolsAndTypes("C", "1..4");
    model.context = model.context.extendWithSymbolsAndTypes("D", "6..9");
    intensionalSetOfFactors1 = new DefaultIntensionalBound(arrayList(parse("A' in Boolean"), parse("C' in 1..5")), parse("if C = C' then if A = A' then 1 else 4 else 0"), TRUE);
    intensionalSetOfFactors2 = DefaultIntensionalBound.simplex(arrayList(parse("A")), model);
    intensionalSetOfFactors3 = DefaultIntensionalBound.simplex(arrayList(parse("C"), parse("B")), model);
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) DefaultIntensionalBound(com.sri.ai.grinder.library.bounds.DefaultIntensionalBound) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Expression(com.sri.ai.expresso.api.Expression) DefaultExtensionalBound(com.sri.ai.grinder.library.bounds.DefaultExtensionalBound) Model(com.sri.ai.grinder.anytime.Model) HashSet(java.util.HashSet)

Example 10 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class LambdaBetaReductionSimplifierTest method testSimpleReduction.

@Test
public void testSimpleReduction() {
    Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob")));
    Context context = new TrueContext();
    context = context.makeNewContextWithAddedType(peopleType);
    Assert.assertEquals(parse("if X = ann then 0 else if X = bob then 0 else 0"), simplifier.apply(parse("(lambda : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
    Assert.assertEquals(parse("if ann = ann then 0 else if ann = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)(ann)"), context));
    Assert.assertEquals(parse("if ann = ann then 0 else if bob = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob)"), context));
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Type(com.sri.ai.expresso.api.Type) Categorical(com.sri.ai.expresso.type.Categorical) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Aggregations

TrueContext (com.sri.ai.grinder.core.TrueContext)39 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)28 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)25 Context (com.sri.ai.grinder.api.Context)24 Expression (com.sri.ai.expresso.api.Expression)20 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)18 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)15 Before (org.junit.Before)12 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)11 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 Test (org.junit.Test)10 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 Theory (com.sri.ai.grinder.api.Theory)6 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)6 Type (com.sri.ai.expresso.api.Type)3 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)3 CombiningTopRewriter (com.sri.ai.grinder.rewriter.core.CombiningTopRewriter)3 Exhaustive (com.sri.ai.grinder.rewriter.core.Exhaustive)3 Recursive (com.sri.ai.grinder.rewriter.core.Recursive)3 Random (java.util.Random)3