use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class SymbolicShell method main.
public static void main(String[] args) {
CompoundTheory 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.add(BOOLEAN_TYPE);
context = context.add(new Categorical("People", 1000000, makeSymbol("ann"), makeSymbol("bob"), makeSymbol("ciaran")));
context = context.add(new IntegerInterval("Integer"));
context = context.add(new RealInterval("Real"));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("P"), makeSymbol("Boolean")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("Q"), makeSymbol("Boolean")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("R"), makeSymbol("Boolean")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("S"), makeSymbol("Boolean")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("C"), makeSymbol("People")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("D"), makeSymbol("People")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("E"), makeSymbol("People")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("I"), makeSymbol("Integer")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("J"), makeSymbol("Integer")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("K"), makeSymbol("Integer")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("X"), makeSymbol("Real")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("Y"), makeSymbol("Real")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("Z"), makeSymbol("Real")));
context = context.registerAdditionalSymbolsAndTypes(map(makeSymbol("T"), parse("(1..5 x 1..5)")));
ConsoleIterator consoleIterator = getConsole(args);
help(consoleIterator);
Collection<String> examples = list("sum({{ (on C in People) 3 }})", "sum({{ (on C in People) 3 : C != D }})", "product({{ (on C in People) 3 : C != D }})", "| {{ (on C in People) 3 : C != D }} |", "| { (on C in People) tuple(C) : C != D } |", "max({{ (on C in People) 3 : C != D }})", "sum({{ (on C in People, D in People) 3 : C != D }})", "sum({{ (on C in People) 3 : C != D and C != ann }})", "sum({{ (on C in People, P in Boolean) 3 : C != ann }})", "sum({{ (on C in People, P in Boolean) 3 : C != ann and not P }})", "sum({{ (on C in People, D in People) if C = ann and D != bob then 2 else 0 : for all E in People : E = ann => C = E }})", "sum({{ (on I in 1..100) I }})", "sum({{ (on I in 1..100) I : I != 3 and I != 5 and I != 500 }})", "sum({{ (on I in 1..100) I : I != J and I != 5 and I != 500 }})", "sum({{ (on I in 1..100) (I - J)^2 }})", "sum({{ (on I in 1..100) if I != K then (I - J)^2 else 0 }})", "sum({{ (on I in 1..100) I : I >= 3 and I < 21 }})", "sum({{ (on I in 1..100) I : I > J and I < 5 and I < 500 }})", "sum({{ (on I in 1..100) (I - J)^2 : I < 50 }})", "sum({{ (on X in [0;100]) 1 }})", "sum({{ (on X in [0;100[) 1 }})", "sum({{ (on X in ]0;100]) 1 }})", "sum({{ (on X in [0;100]) Y }})", "sum({{ (on X in [0;100]) X }})", "sum({{ (on X in [0;100]) X^2 }})", "sum({{ (on X in [0;100]) X + Y }})", "sum({{ (on X in [0;100]) 1 : Y < X and X < Z}})", "sum({{ (on X in Real) 1 : 0 <= X and X <= 100 and Y < X and X < Z}})", "for all X in Real : X > 0 or X <= 0", "for all X in ]0;10] : X > 0", "for all X in [0;10] : X > 0", "| X in 1..10 : X < 4 or X > 8 |", "| X in 1..10, Y in 3..5 : (X < 4 or X > 8) and Y != 5 |", "sum( {{ (on T in (1..4 x 1..4)) 10 }})", "sum( {{ (on T in (1..4 x 1..4)) 10 : T != (2, 3) }})", "sum( {{ (on T in (1..4 x 1..4)) 10 : T != (I, J) }})", "sum( {{ (on T in (1..4 x 1..4)) 10 : get(T, 1) != 2 }})");
for (String example : examples) {
consoleIterator.getOutputWriter().println(consoleIterator.getPrompt() + example);
interpretedInputParsedAsExpression(consoleIterator, theory, example, context);
consoleIterator.getOutputWriter().println("\n");
}
while (consoleIterator.hasNext()) {
String input = consoleIterator.next();
if (input.equals("")) {
consoleIterator.getOutputWriter().println();
} else if (input.startsWith("show")) {
consoleIterator.getOutputWriter().println("\n" + join(mapIntoList(context.getSymbolsAndTypes().entrySet(), e -> e.getKey() + ": " + e.getValue()), ", ") + "\n");
} else if (input.equals("debug")) {
debug = !debug;
consoleIterator.getOutputWriter().println("\nDebug toggled to " + debug + "\n");
} else if (input.equals("help")) {
help(consoleIterator);
} else {
context = interpretedInputParsedAsExpression(consoleIterator, theory, input, context);
}
}
consoleIterator.getOutputWriter().println("\nGoodbye.");
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class MeasureTest method testThrowsUnsupportedGreaterThan1Index.
@Test(expected = UnsupportedOperationException.class)
public void testThrowsUnsupportedGreaterThan1Index() {
updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
measure("{{(on I in People, J in People) (I, J) : true}}");
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class MeasureTest method testCategoricalTypeDomain.
@Test
public void testCategoricalTypeDomain() {
updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
Assert.assertEquals(new Rational(5), measure("{{(on I in People) I : true}}"));
Assert.assertEquals(new Rational(4), measure("{{(on I in People) I : I != p1}}"));
Assert.assertEquals(new Rational(3), measure("{{(on I in People) I : I != p1 and I != p5}}"));
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method testCategoricalEg2.
@Test
public void testCategoricalEg2() {
updateContextWithIndexAndType("N", new Categorical("Person", 1000000));
String intensionalSet = "{{(on I in Person) if I != person1 then 20 else 30 : I != person2 }}";
String[][] functionNamesAndExactValues = new String[][] { // 42sec brute, 1186ms sample
{ "sum", "19999990" }, // 26sec brute, 762ms sample
{ "max", "30" }, // 25sec brute, 703ms sample
{ "product", "7.425492171971923688023442712229336E+1301028" } };
runSampleCompareToExact(10000, true, intensionalSet, functionNamesAndExactValues);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class LambdaBetaReductionSimplifierTest method testNoReduction.
@Test
public void testNoReduction() {
Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob"), makeSymbol("tom")));
Context context = new TrueContext();
context = context.add(peopleType);
Assert.assertEquals(parse("(lambda X in People : if X = ann then 0 else if X = 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)()"), context));
Assert.assertEquals(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann)"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann)"), context));
Assert.assertEquals(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob, tom)"), 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, tom)"), context));
}
Aggregations