use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class SingleVariableDifferenceArithmeticConstraint method getType.
/**
* Returns the {@link IntegerInterval} type of the constraint's variable.
* @param context
* @return
*/
public IntegerInterval getType(Context context) {
if (cachedType == null) {
Expression variableTypeExpression = getVariableTypeExpression(context);
Type type = context.getTypeFromTypeExpression(variableTypeExpression);
if (type instanceof IntegerExpressoType) {
cachedType = new IntegerInterval("-infinity..infinity");
// represents Integer as integer interval for uniformity
} else {
cachedType = (IntegerInterval) type;
}
}
return cachedType;
}
use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class EqualityTheory method argumentIsValid.
private boolean argumentIsValid(Expression argumentOfAtomFunctor, Context context) {
boolean result;
if (argumentOfAtomFunctor.getSyntacticFormType().equals("Symbol")) {
Type eType = GrinderUtil.getTypeOfExpression(argumentOfAtomFunctor, context);
result = isNonBooleanCategoricalType(eType);
} else {
result = false;
}
return result;
}
use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class SatisfiabilityOfSingleVariableEqualityConstraintStepSolver method getPropagatedCNFBesidesPropagatedLiterals.
@Override
protected Iterable<Iterable<Expression>> getPropagatedCNFBesidesPropagatedLiterals(Context context) {
if (!variableIsBoundToUniquelyNamedConstant(context)) {
// the following logic only holds if the variable is not bound to a uniquely named constants,
// since that eliminates all disequalities to other uniquely named constants as redundant
long variableDomainSize = getConstraint().getVariableTypeSize(context);
if (variableDomainSize >= 0 && getConstraint().numberOfDisequals() >= variableDomainSize) {
// the following procedure can be very expensive but the condition above will rarely be satisfied
ArrayList<Expression> variableDisequals = getVariableDisequals(context);
Set<Expression> uniquelyNamedConstantDisequals = getUniquelyNamedConstantDisequals(context);
Expression typeExpression = GrinderUtil.getTypeExpressionOfExpression(getConstraint().getVariable(), context);
Type type = context.getTypeFromTypeExpression(typeExpression);
ArrayList<Expression> remainingUniquelyNamedConstants = arrayListFrom(new PredicateIterator<>(type.iterator(), c -> !uniquelyNamedConstantDisequals.contains(c)));
CartesianProductIterator<ArrayList<Expression>> subsetOfVariableDisequalsAndRemainingConstantsPermutationIterator = new CartesianProductIterator<ArrayList<Expression>>(() -> new SubsetsOfKIterator<Expression>(variableDisequals, remainingUniquelyNamedConstants.size()), () -> new PermutationIterator<Expression>(remainingUniquelyNamedConstants));
FunctionIterator<ArrayList<ArrayList<Expression>>, Iterable<Expression>> clausesIterator = FunctionIterator.make(subsetOfVariableDisequalsAndRemainingConstantsPermutationIterator, (ArrayList<ArrayList<Expression>> subsetAndPermutation) -> clauseNegatingAssignmentOfSubsetOfVariablesToParticularPermutationOfRemainingConstants(subsetAndPermutation));
Iterable<Iterable<Expression>> clauses = in(clausesIterator);
return clauses;
}
}
// otherwise, nothing is implied.
return list();
}
use of com.sri.ai.expresso.api.Type 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;
}
use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class LinearRealArithmeticTheory method symbolIsRealTyped.
private static boolean symbolIsRealTyped(Expression variable, Context context) {
Type variableType = context.getTypeOfRegisteredSymbol(variable);
boolean variableIsInteger = variableType instanceof RealExpressoType || variableType instanceof RealInterval;
return variableIsInteger;
}
Aggregations