use of com.sri.ai.expresso.api.Symbol in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableConstraintWithBinaryAtoms method getEquivalentSignAndNormalFunctor.
/**
* Determine which normal functor to use, possibly negating functor if non-normal
* @param sign
* @param atom
* @return
*/
private Pair<Boolean, Expression> getEquivalentSignAndNormalFunctor(boolean sign, Expression atom) {
Expression normalFunctor;
Expression functor = atom.getFunctor();
String functorString = functor.toString();
if (getNormalFunctors().contains(functorString)) {
normalFunctor = functor;
} else {
Symbol negatedFunctor = makeSymbol(getNegationFunctor(functorString));
myAssert(() -> getNormalFunctors().contains(negatedFunctor), () -> getClass().getSimpleName() + ": requires negation of non-normal functors to be normal functors, but got non-normal '" + functor + "' which has non-normal negation '" + negatedFunctor + "'");
normalFunctor = negatedFunctor;
// flip sign since we negated the functor
sign = !sign;
}
Pair<Boolean, Expression> signAndNormalFunctor = Pair.make(sign, normalFunctor);
return signAndNormalFunctor;
}
use of com.sri.ai.expresso.api.Symbol in project aic-expresso by aic-sri-international.
the class SwitchTest method testSimpleSwitchRewriter.
@Test
public void testSimpleSwitchRewriter() {
RewriterFromStepMaker baseRewriterSum = (Expression e, Context c) -> {
int argument1 = e.get(0).intValue();
int argument2 = e.get(1).intValue();
Symbol resultValue = DefaultSymbol.createSymbol(argument1 + argument2);
return new Solution(resultValue);
};
RewriterFromStepMaker baseRewriterSubtraction = (Expression e, Context c) -> {
int argument1 = e.get(0).intValue();
int argument2 = e.get(1).intValue();
Symbol resultValue = DefaultSymbol.createSymbol(argument1 - argument2);
return new Solution(resultValue);
};
Switch rewriter = new Switch<String>(e -> e.getFunctor() != null ? e.getFunctor().toString() : "", map("+", baseRewriterSum, "-", baseRewriterSubtraction));
Expression initial;
Expression expected;
initial = parse("7");
expected = parse("7");
runTest(rewriter, initial, expected, map());
initial = parse("10 - 7");
expected = parse("3");
runTest(rewriter, initial, expected, map());
initial = parse("10 + 3");
expected = parse("13");
runTest(rewriter, initial, expected, map());
}
use of com.sri.ai.expresso.api.Symbol in project aic-praise by aic-sri-international.
the class FromTableToExpressionFactorConverter method makeComparisonToAssignedValue.
private Expression makeComparisonToAssignedValue(TableVariable tableVariable, int assignment) {
Symbol assignedValueExpression = createSymbol(assignment);
Symbol variableExpression = makeVariableExpression(tableVariable);
Expression result = Equality.make(variableExpression, assignedValueExpression);
return result;
}
use of com.sri.ai.expresso.api.Symbol in project aic-expresso by aic-sri-international.
the class RealInterval method sampleUniquelyNamedConstant.
@Override
public Expression sampleUniquelyNamedConstant(Random random) {
myAssert(() -> boundsAreConstants(), () -> "Cannot sample uniquely named constant from real interval that is infinite and/or defined by variables: " + getName());
// We split the interval into NUMBER_OF_SAMPLING_POINTS contiguous sub-intervals, delimited by (NUMBER_OF_SAMPLING_POINTS + 1) points.
// We then pick one of these points, but exclude the extreme ones depending on whether bounds are open or closed.
int sampledPoint = (lowerBoundIsOpen ? 1 : 0) + random.nextInt(getNumberOfAllowedSamplingPoints());
// We compute the sampled element of the interval
Rational intervalFraction = new Rational(sampledPoint, SAMPLING_RESOLUTION);
Rational sampledElement = lowerBound.rationalValue().add(intervalFraction.multiply(getLength()));
Symbol result = makeSymbol(sampledElement);
return result;
}
use of com.sri.ai.expresso.api.Symbol in project aic-expresso by aic-sri-international.
the class SamplingProceduralAttachmentSingleQuantifierEliminator method solve.
@Override
public Expression solve(MultiQuantifierEliminationProblem problem, Context context) {
sampler = new SamplingAdderLazyIterator(problem, getTopRewriterUsingContextAssignments(), random, context);
List<Expression> proceduralAttachmentParameters = getParameters(problem, context);
int arity = proceduralAttachmentParameters.size();
Symbol samplerFunctor = makeAndRegisterProceduralAttachment(arity, context);
Expression samplerExpression = apply(samplerFunctor, proceduralAttachmentParameters);
return samplerExpression;
}
Aggregations