use of com.sri.ai.expresso.type.IntegerInterval in project aic-praise by aic-sri-international.
the class FromTableToExpressionFactorConverter method makeTypeExpression.
Expression makeTypeExpression(TableVariable tableVariable) {
int cardinality = tableVariable.getCardinality();
Expression typeExpression = new IntegerInterval(0, cardinality - 1).toExpression();
return typeExpression;
}
use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.
the class AssignmentsSamplingIteratorTest method newSamplingIterator.
private Iterator<Assignment> newSamplingIterator(String indexString, int sampleSize, String conditionString) {
Expression index = parse(indexString);
Expression condition = parse(conditionString);
// Ensure condition of correct type is created
Type indexType = GrinderUtil.getTypeOfExpression(index, context);
if (indexType instanceof RealExpressoType || indexType instanceof RealInterval) {
SingleVariableLinearRealArithmeticConstraint svlraConstraint = new SingleVariableLinearRealArithmeticConstraint(index, true, context.getTheory());
svlraConstraint = (SingleVariableLinearRealArithmeticConstraint) svlraConstraint.conjoin(condition, context);
condition = svlraConstraint;
} else if (indexType instanceof IntegerExpressoType || indexType instanceof IntegerInterval) {
SingleVariableDifferenceArithmeticConstraint svdaConstraint = new SingleVariableDifferenceArithmeticConstraint(index, true, context.getTheory());
svdaConstraint = (SingleVariableDifferenceArithmeticConstraint) svdaConstraint.conjoin(condition, context);
condition = svdaConstraint;
}
AssignmentsSamplingIterator samplingIterator = new AssignmentsSamplingIterator(Arrays.asList(index), condition, conditionRewriter, random, context);
Iterator<Assignment> result = nIterator(sampleSize, samplingIterator);
return result;
}
use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method run.
private Expression run(int sampleSizeN, boolean alwaysSample, String expressionString) {
SamplingCommonInterpreter interpreter = new SamplingCommonInterpreter(sampleSizeN, alwaysSample, random);
Expression expression = parse(expressionString);
if (expression.numberOfArguments() == 1 && Sets.isIntensionalSet(expression.get(0))) {
IntensionalSet intensionalSet = (IntensionalSet) expression.get(0);
IndexExpressionsSet indexExpressions = intensionalSet.getIndexExpressions();
List<Expression> indices = IndexExpressions.getIndices(indexExpressions);
if (indices.size() == 1) {
Expression index = indices.get(0);
Context intensionalSetContext = context.extendWith(indexExpressions);
// Ensure condition of correct type is created
Type indexType = GrinderUtil.getTypeOfExpression(index, intensionalSetContext);
SingleVariableConstraint singleVariableConstraint = null;
if (indexType instanceof RealExpressoType || indexType instanceof RealInterval) {
singleVariableConstraint = new SingleVariableLinearRealArithmeticConstraint(index, true, intensionalSetContext.getTheory());
} else if (indexType instanceof IntegerExpressoType || indexType instanceof IntegerInterval) {
singleVariableConstraint = new SingleVariableDifferenceArithmeticConstraint(index, true, intensionalSetContext.getTheory());
}
if (singleVariableConstraint != null) {
singleVariableConstraint = singleVariableConstraint.conjoin(intensionalSet.getCondition(), intensionalSetContext);
intensionalSet = intensionalSet.setCondition(singleVariableConstraint);
expression = expression.set(0, intensionalSet);
}
}
}
Expression result = interpreter.apply(expression, context);
System.out.println("Evaluation with " + sampleSizeN + " samples of " + expressionString + " = " + result.doubleValue() + " (as rational=" + toString(result) + ")");
return result;
}
use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.
the class IntensionalSetConditionSimplifierTest method setUp.
@Before
public void setUp() {
context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
IntegerInterval nType = new IntegerInterval(1, 10);
context = (Context) GrinderUtil.extendRegistryWith(map("N", nType.toString()), Arrays.asList(nType), context);
simplifier = new IntensionalSetConditionSimplifier();
}
use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.
the class IntegerIntervalTest method testContains.
@Test
public void testContains() {
IntegerInterval intInterval = new IntegerInterval("Integer");
Assert.assertTrue(intInterval.contains(parse("0")));
intInterval = new IntegerInterval("0..4");
Assert.assertFalse(intInterval.contains(parse("-1")));
Assert.assertTrue(intInterval.contains(parse("0")));
Assert.assertTrue(intInterval.contains(parse("1")));
Assert.assertTrue(intInterval.contains(parse("2")));
Assert.assertTrue(intInterval.contains(parse("3")));
Assert.assertTrue(intInterval.contains(parse("4")));
Assert.assertFalse(intInterval.contains(parse("5")));
Assert.assertFalse(intInterval.contains(parse("2.5")));
intInterval = new IntegerInterval("-infinity..4");
Assert.assertFalse(intInterval.contains(parse("-infinity")));
Assert.assertTrue(intInterval.contains(parse("-100")));
Assert.assertTrue(intInterval.contains(parse("4")));
Assert.assertFalse(intInterval.contains(parse("5")));
intInterval = new IntegerInterval("0..infinity");
Assert.assertFalse(intInterval.contains(parse("infinity")));
Assert.assertFalse(intInterval.contains(parse("-1")));
Assert.assertTrue(intInterval.contains(parse("0")));
Assert.assertTrue(intInterval.contains(parse("4")));
Assert.assertTrue(intInterval.contains(parse("5")));
Assert.assertTrue(intInterval.contains(parse("500")));
}
Aggregations