use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class SymbolicShell method main.
public static void main(String[] args) {
Theory theory = makeTheory();
Context context = makeContext(theory);
ConsoleIterator consoleIterator = getConsole(args);
help(consoleIterator);
for (String example : EXAMPLES) {
interpretExample(example, consoleIterator, theory, context);
}
while (consoleIterator.hasNext()) {
context = interpretConsoleInput(consoleIterator, theory, context);
}
consoleIterator.getOutputWriter().println("\nGoodbye.");
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class TheorySolvedSingleQuantifierEliminationProblem method makeStepSolver.
private ExpressionLiteralSplitterStepSolver makeStepSolver(Context context) {
Theory theory = context.getTheory();
ExpressionLiteralSplitterStepSolver result = theory.getSingleQuantifierEliminatorStepSolver(this, context);
return result;
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class BPTest method main.
public static void main(String[] args) {
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);
Model m = IsingModel(3, 4, theory, context, parse("Boolean"));
// printModel(model);
runTest(m);
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class FactorComponent method calculate.
public Expression calculate() {
Theory theory = this.model.theory;
Context context = this.model.context;
Expression childrenMessage = parse("{ 1 }");
for (VariableComponent children : this.children) {
childrenMessage = apply(TIMES, childrenMessage, children.calculate());
}
childrenMessage = apply(TIMES, childrenMessage, this.phi);
for (Expression cutset : this.cutsetInsideSubModel) {
// String str = "sum({{ (on " + cutset + " in Boolean ) " + childrenMessage + " }})";
// childrenMessage = parse(str);
// childrenMessage = theory.evaluate(childrenMessage, context);
Expression valuesTakenByVariableToSum = this.model.getValues(cutset);
IndexExpressionsSet indices = new ExtensionalIndexExpressionsSet(apply(IN, cutset, valuesTakenByVariableToSum));
Expression intensionalMultiSet = IntensionalSet.makeMultiSet(indices, childrenMessage, parse("true"));
Expression summation = apply(SUM, intensionalMultiSet);
childrenMessage = summation;
// String str = "sum({{ (on " + variableToSum + " in " + this.model.getValues(variableToSum) +" ) " + childrenMessage + " }})";
// childrenMessage = parse(str);
}
Set<Expression> toSum = model.getNeighbors(phi);
for (Expression e : this.parent) {
toSum.remove(e);
}
toSum.removeAll(this.cutsetOutsideSubModel);
toSum.removeAll(this.cutsetInsideSubModel);
for (Expression variableToSum : toSum) {
Expression expressionToSum = theory.evaluate(childrenMessage, context);
Expression valuesTakenByVariableToSum = this.model.getValues(variableToSum);
IndexExpressionsSet indices = new ExtensionalIndexExpressionsSet(apply(IN, variableToSum, valuesTakenByVariableToSum));
Expression intensionalMultiSet = IntensionalSet.makeMultiSet(indices, expressionToSum, parse("true"));
Expression summation = apply(SUM, intensionalMultiSet);
// String str = "sum({{ (on " + variableToSum + " in " + this.model.getValues(variableToSum) +" ) " + childrenMessage + " }})";
// childrenMessage = parse(str);
childrenMessage = summation;
}
return theory.evaluate(childrenMessage, context);
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class VariableComponent method calculateBound.
public void calculateBound() {
Theory theory = this.model.theory;
Context context = this.model.context;
// Expression childrenBound = parse("{ 1 }");
// for (FactorComponent children : this.children) {
// childrenBound = Bounds.boundProduct(theory, context, childrenBound, children.bound);
// }
Bound[] childrenArray = new Bound[children.size()];
int i = 0;
for (FactorComponent children : this.children) {
childrenArray[i] = children.bound;
i++;
}
Bound childrenBound;
if (childrenArray.length != 0) {
childrenBound = Bounds.boundProduct(this.model.theory, this.model.context, isExtensionalBound, childrenArray);
} else {
childrenBound = Bounds.makeSingleElementBound(makeSymbol(1), isExtensionalBound);
}
Iterator<Expression> iteratorToVariables = this.cutsetInsideSubModel.iterator();
ArrayList<Expression> variablesToBeSummedOut = new ArrayList<>(this.cutsetInsideSubModel.size());
for (Expression var : Util.in(iteratorToVariables)) {
variablesToBeSummedOut.add(var);
}
// We want sum other toSum of Phi*childrenBound
DefaultExtensionalUniSet varToSum = new DefaultExtensionalUniSet(variablesToBeSummedOut);
bound = childrenBound.summingBound(varToSum, context, theory);
}
Aggregations