Search in sources :

Example 1 with CountingFormula

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;
}
Also used : CountingFormula(com.sri.ai.expresso.api.CountingFormula) IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression)

Aggregations

CountingFormula (com.sri.ai.expresso.api.CountingFormula)1 Expression (com.sri.ai.expresso.api.Expression)1 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)1