use of com.sri.ai.expresso.api.CountingFormula in project aic-expresso by aic-sri-international.
the class CountingFormulaEquivalentExpressions method isCountingFormulaEquivalentExpression.
/**
* Tests if a given expression is equivalent to a counting formula. Three
* cases exist for this currently:
* <ol>
* <li>Instances of the CountingFormula interface.</li>
* <li>Applications of the cardinality functor to intensional
* multisets.</li>
* <li>Applications of the cardinality functor to intensional unisets whose
* head is a tuple over the indices of the set.</li>
* </ol>
*
* @param expression
* the expression to be tested.
* @return true if the given expression is equivalent semantically to a
* counting formula, false otherwise.
*/
public static boolean isCountingFormulaEquivalentExpression(Expression expression) {
boolean result = false;
if (expression instanceof CountingFormula) {
result = true;
} else if (expression.hasFunctor(FunctorConstants.CARDINALITY)) {
Expression cardinalityArg = expression.get(0);
if (Sets.isIntensionalMultiSet(cardinalityArg)) {
result = true;
} else if (Sets.isIntensionalUniSet(cardinalityArg)) {
IntensionalSet intensionalUniSet = (IntensionalSet) cardinalityArg;
Expression head = intensionalUniSet.getHead();
if (Tuple.isTuple(head)) {
// TODO - we should really test if the args of the tuple
// match the indices but for now we will trust they are the
// same.
result = true;
}
}
}
return result;
}
Aggregations