static ord_RESULT rpos_MulGreaterEqual(TERM T1, TERM T2) /************************************************************** INPUT: Two terms with equal top symbols and multiset status. RETURNS: ord_GREATER_THAN if <T1> is greater than <T2>, ord_EQUAL if both terms are equal and ord_UNCOMPARABLE otherwise. ***************************************************************/ { LIST l1, l2; l1 = rpos_MultisetDifference(T1, T2); if (list_Empty(l1)) /* If |M| = |N| and M-N = {} then N-M = {} */ return ord_Equal(); /* Terms are equal */ else { LIST scan; BOOL greater; l2 = rpos_MultisetDifference(T2, T1); for (greater = TRUE; !list_Empty(l2) && greater; l2 = list_Pop(l2)) { for (scan = l1, greater = FALSE; !list_Empty(scan) && !greater; scan = list_Cdr(scan)) greater = rpos_Greater(list_Car(scan), list_Car(l2)); } list_Delete(l1); /* l2 was freed in the outer for loop */ if (greater) return ord_GreaterThan(); else return ord_Uncomparable(); } }
static ord_RESULT rpos_MulGreaterEqual(TERM T1, TERM T2, BOOL VarIsConst) /************************************************************** INPUT: Two terms with equal top symbols and multiset status. RETURNS: ord_GREATER_THAN if <T1> is greater than <T2>, ord_EQUAL if both terms are equal and ord_UNCOMPARABLE otherwise. CAUTION: If <VarIsConst> is set then variables are interpreted as constants with lowest precedence. They are ranked to each other using their variable index. ***************************************************************/ { LIST l1, l2; l1 = rpos_MultisetDifference(T1, T2); if (list_Empty(l1)) /* If |M| = |N| and M-N = {} then N-M = {} */ return ord_Equal(); /* Terms are equal */ else { LIST scan; BOOL greater; l2 = rpos_MultisetDifference(T2, T1); for (greater = TRUE; !list_Empty(l2) && greater; l2 = list_Pop(l2)) { for (scan = l1, greater = FALSE; !list_Empty(scan) && !greater; scan = list_Cdr(scan)) greater = rpos_Greater(list_Car(scan), list_Car(l2), VarIsConst); } list_Delete(l1); /* l2 was freed in the outer for loop */ if (greater) return ord_GreaterThan(); else return ord_Uncomparable(); } }
BOOL rpos_Equal(TERM T1, TERM T2) /************************************************************** INPUT: Two terms. RETURNS: TRUE, if <T1> is equal to <T2> and FALSE otherwise. ***************************************************************/ { LIST l1, l2; if (!term_EqualTopSymbols(T1, T2)) return FALSE; else if (!term_IsComplex(T1)) /* Equal variable or constant */ return TRUE; else { if (symbol_HasProperty(term_TopSymbol(T1), ORDMUL)) { /* MUL case */ l1 = rpos_MultisetDifference(T1, T2); if (list_Empty(l1)) return TRUE; else { list_Delete(l1); return FALSE; } } else { /* LEX case */ for (l1 = term_ArgumentList(T1), l2 = term_ArgumentList(T2); !list_Empty(l1) && rpos_Equal(list_Car(l1), list_Car(l2)); l1 = list_Cdr(l1), l2 = list_Cdr(l2)) /* empty */; return list_Empty(l1); /* All arguments were equal */ } } }