use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableConstraintWithBinaryAtomsIncludingEquality method rewriteSignAndNormalizedAtomForValueVariableIsBoundTo.
private Expression rewriteSignAndNormalizedAtomForValueVariableIsBoundTo(boolean sign, Expression normalizedAtom, Expression valueVariableIsBoundTo, Context context) {
Expression normalizedAtomInTermsOfValueVariableIsBoundTo = apply(normalizedAtom.getFunctor(), valueVariableIsBoundTo, normalizedAtom.get(1));
Expression literal = sign ? normalizedAtomInTermsOfValueVariableIsBoundTo : not(normalizedAtomInTermsOfValueVariableIsBoundTo);
Expression simplifiedLiteral = getTheory().simplify(literal, context);
return simplifiedLiteral;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractTheoryWithBinaryAtomsTestingSupport method makeRandomAtomOn.
/**
* Makes a random atom by uniformly picking among the theory functors and testing variables.
*/
@Override
public Expression makeRandomAtomOn(String mainVariable, Context context) {
String mainVariableName = getVariableName(mainVariable);
Type mainType = getTestingVariableType(mainVariable);
Expression otherTerm = parse(pickTestingVariableAtRandom(mainType, otherName -> !otherName.equals(mainVariableName)));
String functor = pickUniformly(getTheoryFunctors(), getRandom());
Expression mainVariableExpression = parse(mainVariable);
Expression possiblyTrivialAtom = getRandom().nextBoolean() ? apply(functor, mainVariableExpression, otherTerm) : apply(functor, otherTerm, mainVariableExpression);
Expression result = getTheory().simplify(possiblyTrivialAtom, context);
return result;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class BruteForceFunctionTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraint, Expression body, Context context) {
Expression variable = constraint.getVariable();
Expression type = GrinderUtil.getTypeExpression(variable, context);
Expression indexExpression = IndexExpressions.makeIndexExpression(variable, type);
ExtensionalIndexExpressionsSet indexExpressionsSet = new ExtensionalIndexExpressionsSet(indexExpression);
MultiIndexQuantifierEliminator quantifierEliminator = new BruteForceMultiIndexQuantifierEliminator(context.getTheory().getTopRewriter());
Expression solution = quantifierEliminator.solve(group, indexExpressionsSet, constraint, body, context);
return new ConstantExpressionStepSolver(solution);
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class BruteForceFunctionTheoryTestingSupport method getSmallCategoricalTestingType.
public static Categorical getSmallCategoricalTestingType() {
if (_someType == null) {
ArrayList<Expression> knownConstants = mapIntoArrayList(list("a", "b", "c"), s -> makeSymbol(s));
_someType = new Categorical("SmallSomeType", 3, knownConstants);
}
return _someType;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class BruteForceFunctionTheoryTestingSupport method makeFunctionApplication.
protected Expression makeFunctionApplication(String functorName, FunctionType functionType) {
// Generate arguments for the application
List<Expression> args = new ArrayList<>();
for (Type argType : functionType.getArgumentTypes()) {
// If constants supported, use at random
if (argType.isSampleUniquelyNamedConstantSupported() && getRandom().nextBoolean()) {
args.add(argType.sampleUniquelyNamedConstant(getRandom()));
} else {
// Otherwise retrieve a term variable matching that type and use it
String termVariable = pickTestingVariableAtRandom(getTermVariableNamesAndTypesForTesting(), argType, variableName -> true);
Type termType = getTermVariableNamesAndTypesForTesting().get(termVariable);
if (termType instanceof FunctionType) {
// Allow for nested function applications
args.add(makeFunctionApplication(termVariable, (FunctionType) termType));
} else {
// Otherwise just assign the variable for the term.
args.add(parse(termVariable));
}
}
}
Expression result = Expressions.apply(functorName, args.toArray(new Object[args.size()]));
return result;
}
Aggregations