BOOL cont_TermEqual(CONTEXT Context1, TERM Term1, CONTEXT Context2, TERM Term2) /********************************************************* INPUT: Two terms and two contexts. RETURNS: TRUE iff the two terms are equal, where variables are interpreted with respect to the bindings in the contexts. ********************************************************/ { #ifdef CHECK if (!(term_IsTerm(Term1) && term_IsTerm(Term2))) { misc_StartErrorReport(); misc_ErrorReport("\n In cont_TermEqual: Input terms are corrupted.\n"); misc_FinishErrorReport(); } #endif Term1 = cont_Deref(&Context1,Term1); Term2 = cont_Deref(&Context2,Term2); if (!term_EqualTopSymbols(Term1, Term2)) return FALSE; else if (term_ArgumentList(Term1)) { LIST Scan1, Scan2; for (Scan1=term_ArgumentList(Term1), Scan2=term_ArgumentList(Term2); list_Exist(Scan1) && list_Exist(Scan2); Scan1=list_Cdr(Scan1), Scan2=list_Cdr(Scan2)) if (!cont_TermEqual(Context1,list_Car(Scan1), Context2,list_Car(Scan2))) return FALSE; return (list_Empty(Scan1) ? list_Empty(Scan2) : FALSE); } else return TRUE; }
BOOL cont_TermEqual(CONTEXT GlobalContext1, CONTEXT TermContext1, TERM Term1, CONTEXT GlobalContext2, CONTEXT TermContext2, TERM Term2) /********************************************************* INPUT: Two terms and two local contexts for the terms and two global contexts RETURNS: TRUE iff the two terms are equal, where variables are interpreted with respect to the bindings in the contexts. CAUTION: Variables of <Term1> and <Term2> are bound in <TermContext1> and <TermContext2> respectively and the index variables are bound in <GlobalContext1> and <GlobalContext2> respectively. ********************************************************/ { #ifdef CHECK if (!(term_IsTerm(Term1) && term_IsTerm(Term2))) { misc_StartErrorReport(); misc_ErrorReport("\n In cont_TermEqual: Input terms are corrupted.\n"); misc_FinishErrorReport(); } #endif Term1 = cont_Deref(GlobalContext1,&TermContext1,Term1); Term2 = cont_Deref(GlobalContext2,&TermContext2,Term2); if (!term_EqualTopSymbols(Term1, Term2)) return FALSE; else if (term_ArgumentList(Term1)) { LIST Scan1, Scan2; for (Scan1=term_ArgumentList(Term1), Scan2=term_ArgumentList(Term2); list_Exist(Scan1) && list_Exist(Scan2); Scan1=list_Cdr(Scan1), Scan2=list_Cdr(Scan2)) if (!cont_TermEqual(GlobalContext1, TermContext1,list_Car(Scan1), GlobalContext2, TermContext2,list_Car(Scan2))) return FALSE; return (list_Empty(Scan1) ? list_Empty(Scan2) : FALSE); } else return TRUE; }
static BOOL kbo_ContGreaterCompareStruc(CONTEXT Context1, TERM Term1, CONTEXT Context2, TERM Term2) /************************************************************** INPUT: Two contexts and two terms where the kbo-variable condition for <Term1> and <Term2> is satisfied as well as the weight difference between the terms is zero. RETURNS: TRUE if Term1 is greater than Term2. The Terms are interpreted with respect to the contexts. CAUTION: The precedence from the order module is used to determine the precedence of symbols! ***************************************************************/ { LIST Scan1,Scan2; SYMBOL Top1,Top2; Term1 = cont_Deref(&Context1,Term1); Term2 = cont_Deref(&Context2,Term2); Top1 = term_TopSymbol(Term1); Top2 = term_TopSymbol(Term2); if (symbol_IsStandardVariable(Top1)) { if (symbol_IsStandardVariable(Top2)) return FALSE; else return FALSE; } else if (symbol_IsStandardVariable(Top2) || symbol_PrecedenceGreater(ord_PRECEDENCE, Top1, Top2)) return TRUE; else if (Top1 == Top2) { int RecWeightDiff; BOOL T1VarCond, T2VarCond; TERM RecTerm1,RecTerm2; Scan1 = term_ArgumentList(Term1); Scan2 = term_ArgumentList(Term2); if (symbol_HasProperty(Top1,ORDRIGHT)) { int i; for (i = symbol_Arity(Top1); i > 0 && cont_TermEqual(Context1,list_NthElement(Scan1,i), Context2,list_NthElement(Scan2,i)); i--); if (i > 0) { RecTerm1 = cont_Deref(&Context1,list_NthElement(Scan1,i)); RecTerm2 = cont_Deref(&Context2,list_NthElement(Scan2,i)); } else return FALSE; } else { while (!list_Empty(Scan1) && cont_TermEqual(Context1,list_Car(Scan1),Context2,list_Car(Scan2))) { Scan1 = list_Cdr(Scan1); Scan2 = list_Cdr(Scan2); } if (list_Empty(Scan1)) /* Implies that list_Empty(Scan2) */ return FALSE; else { RecTerm1 = cont_Deref(&Context1,list_Car(Scan1)); RecTerm2 = cont_Deref(&Context2,list_Car(Scan2)); } } RecWeightDiff = kbo_ContCompVarCondAndWeight(Context1,RecTerm1,&T1VarCond, Context2,RecTerm2,&T2VarCond); if (T1VarCond) { if (RecWeightDiff > 0) return TRUE; else if (RecWeightDiff == 0) return kbo_ContGreaterCompareStruc(Context1, RecTerm1, Context2, RecTerm2); } } return FALSE; }