use of com.sri.ai.expresso.api.QuantifiedExpression in project aic-expresso by aic-sri-international.
the class Theory method isVariable.
/**
* Indicates whether an expression is considered a variable in this theory,
* meaning that it is not a constants of any of the registered types in context
* (per {@link Context#getTypes()} and {@link Context#isUniquelyNamedConstant(Expression)}),
* it is not interpreted in propositional logic
* (per {@link FormulaUtil#isInterpretedInPropositionalLogicIncludingConditionals(Expression)}),
* and is not interpreted in this theory besides boolean connectives
* (per {@link #isInterpretedInThisTheoryBesidesBooleanConnectives(Expression, Context)}.
* @param expression
* @param context
* @return
*/
default default boolean isVariable(Expression expression, Context context) {
Expression typeExpression;
Type type;
boolean result = !context.isUniquelyNamedConstant(expression) && !(expression instanceof QuantifiedExpression) && !isInterpretedInPropositionalLogicIncludingConditionals(expression) && !isInterpretedInThisTheoryBesidesBooleanConnectives(expression) && (typeExpression = GrinderUtil.getTypeExpression(expression, context)) != null && (type = context.getType(typeExpression)) != null && isSuitableFor(expression, type) && !thereExists(context.getTypes(), t -> t.contains(expression));
return result;
}
use of com.sri.ai.expresso.api.QuantifiedExpression in project aic-expresso by aic-sri-international.
the class TupleQuantifierSimplifier method rewriteThereExists.
private static Expression rewriteThereExists(Expression quantifiedExpression, Map<Expression, Expression> indexToTypeMap, Map<Expression, Expression> indexToTupleOfVars, Context context) {
if (indexToTypeMap.size() > 1) {
throw new IllegalStateException("We have an Existential Quantifier with > 1 index : " + quantifiedExpression);
}
Pair<IndexExpressionsSet, Expression> updatePair = update(ThereExists.getBody(quantifiedExpression), indexToTypeMap, indexToTupleOfVars, context);
Expression result = ThereExists.make(updatePair.first, updatePair.second);
return result;
}
use of com.sri.ai.expresso.api.QuantifiedExpression in project aic-expresso by aic-sri-international.
the class TupleQuantifierSimplifier method rewriteForAll.
private static Expression rewriteForAll(Expression quantifiedExpression, Map<Expression, Expression> indexToTypeMap, Map<Expression, Expression> indexToTupleOfVars, Context context) {
if (indexToTypeMap.size() > 1) {
throw new IllegalStateException("We have a Universal Quantifier with > 1 index : " + quantifiedExpression);
}
Pair<IndexExpressionsSet, Expression> updatePair = update(ForAll.getBody(quantifiedExpression), indexToTypeMap, indexToTupleOfVars, context);
Expression result = ForAll.make(updatePair.first, updatePair.second);
return result;
}
use of com.sri.ai.expresso.api.QuantifiedExpression in project aic-expresso by aic-sri-international.
the class TupleQuantifierSimplifier method createTuplesOfVarsForTupleTypes.
private static Map<Expression, Expression> createTuplesOfVarsForTupleTypes(QuantifiedExpression quantifiedExpression, List<Map.Entry<Expression, Expression>> indexesOfTupleType) {
Map<Expression, Expression> result = new HashMap<>();
Set<Expression> allSubExpressions = Util.addAllToSet(new SubExpressionsDepthFirstIterator(quantifiedExpression));
for (Map.Entry<Expression, Expression> entry : indexesOfTupleType) {
List<Expression> tupleVars = new ArrayList<>();
for (int i = 1; i <= entry.getValue().numberOfArguments(); i++) {
Expression proposedVar = Expressions.makeSymbol(entry.getKey().toString() + "_" + i);
Expression actualVar = Expressions.primedUntilUnique(proposedVar, expr -> !allSubExpressions.contains(expr));
tupleVars.add(actualVar);
}
result.put(entry.getKey(), Expressions.makeTuple(tupleVars));
}
return result;
}
use of com.sri.ai.expresso.api.QuantifiedExpression in project aic-expresso by aic-sri-international.
the class TupleQuantifierSimplifier method simplify.
public static Expression simplify(Expression expression, Context context) {
Expression result = expression;
if (expression instanceof QuantifiedExpression) {
QuantifiedExpression quantifiedExpression = (QuantifiedExpression) expression;
Map<Expression, Expression> indexToTypeMap = IndexExpressions.getIndexToTypeMapWithDefaultNull(quantifiedExpression);
List<Map.Entry<Expression, Expression>> indexesOfTupleType = indexToTypeMap.entrySet().stream().filter(entry -> entry.getValue() != null && TupleType.isTupleType(entry.getValue())).collect(Collectors.toList());
if (indexesOfTupleType.size() > 0) {
Map<Expression, Expression> indexToTupleOfVars = createTuplesOfVarsForTupleTypes(quantifiedExpression, indexesOfTupleType);
result = rewriteQuantifiedExpression(quantifiedExpression, indexToTypeMap, indexToTupleOfVars, context);
}
}
return result;
}
Aggregations