Exemple #1
0
SYMBOL cont_TermMaxVar(CONTEXT Context, TERM Term)
/*********************************************************
  INPUT:   A context and a term.
  RETURNS: The maximal variable in <Term> with respect to
           the bindings in <Context>
********************************************************/
{
  LIST   scan;
  SYMBOL result;

#ifdef CHECK
  if (!term_IsTerm(Term)) {
    misc_StartErrorReport();
    misc_ErrorReport("\n In cont_TermMaxVar: Input term is corrupted.\n");
    misc_FinishErrorReport();
  }
#endif

  Term   = cont_Deref(&Context,Term);
  result = symbol_Null();

  if (term_IsStandardVariable(Term)) {
    if (term_TopSymbol(Term) > result)
      result = term_TopSymbol(Term);
  } else {
    for (scan = term_ArgumentList(Term); !list_Empty(scan); scan = list_Cdr(scan)) {
      SYMBOL max = cont_TermMaxVar(Context, list_Car(scan));

      if (max > result)
	result = max;
    }
  }

  return result;
}
Exemple #2
0
static int kbo_ContCompVarCondAndWeightIntern(CONTEXT Context, TERM Term, int Index)
/**************************************************************
  INPUT:
  EFFECT:
***************************************************************/
{
    int Weight;

    Weight = 0;
    Term   = cont_Deref(&Context,Term);

    if (term_IsStandardVariable(Term)) {
        ord_VARCOUNT[term_TopSymbol(Term)][Index]++;
        Weight += kbo_MINWEIGHT;
    }
    else {
        LIST Scan;
        Weight += symbol_Weight(term_TopSymbol(Term));
        for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
            Weight += kbo_ContCompVarCondAndWeightIntern(Context, list_Car(Scan), Index);
    }

    return Weight;
}
Exemple #3
0
static int kbo_CompVarCondAndWeight(TERM Term1, BOOL *VarCond1, TERM Term2, BOOL *VarCond2)
/**************************************************************
  INPUT:   Two terms and two pointers to booleans.
  EFFECT:  Sets the booleans with respect to the kbo variable condition.
           Computes the kbo weight difference.
***************************************************************/
{
    SYMBOL MaxVar1,MaxVar2;
    TERM   Term;
    LIST   Scan;
    int    i,Stack,Weight;

    *VarCond1 = *VarCond2 = TRUE;
    MaxVar1   = term_MaxVar(Term1);
    MaxVar2   = term_MaxVar(Term2);
    Stack     = stack_Bottom();
    Weight    = 0;

    if (MaxVar1 < MaxVar2)
        MaxVar1 = MaxVar2;

    for (i = 0; i <= MaxVar1; i++) {
        ord_VARCOUNT[i][0] = 0;
        ord_VARCOUNT[i][1] = 0;
    }

    Term = Term1;
    if (term_IsStandardVariable(Term)) {
        ord_VARCOUNT[term_TopSymbol(Term)][0]++;
        Weight += kbo_MINWEIGHT;
    }
    else {
        Weight += symbol_Weight(term_TopSymbol(Term));
        if (term_IsComplex(Term))
            stack_Push(term_ArgumentList(Term));
    }
    while (!stack_Empty(Stack)) {
        Scan = stack_Top();
        Term = (TERM)list_Car(Scan);
        stack_RplacTop(list_Cdr(Scan));
        if (term_IsStandardVariable(Term)) {
            Weight += kbo_MINWEIGHT;
            ord_VARCOUNT[term_TopSymbol(Term)][0]++;
        }
        else {
            Weight += symbol_Weight(term_TopSymbol(Term));
            if (term_IsComplex(Term))
                stack_Push(term_ArgumentList(Term));
        }
        while (!stack_Empty(Stack) && list_Empty(stack_Top()))
            stack_Pop();
    }

    Term = Term2;
    if (term_IsStandardVariable(Term)) {
        Weight -= kbo_MINWEIGHT;
        ord_VARCOUNT[term_TopSymbol(Term)][1]++;
    }
    else {
        Weight -= symbol_Weight(term_TopSymbol(Term));
        if (term_IsComplex(Term))
            stack_Push(term_ArgumentList(Term));
    }
    while (!stack_Empty(Stack)) {
        Scan = stack_Top();
        Term = (TERM)list_Car(Scan);
        stack_RplacTop(list_Cdr(Scan));
        if (term_IsStandardVariable(Term)) {
            Weight -= kbo_MINWEIGHT;
            ord_VARCOUNT[term_TopSymbol(Term)][1]++;
        }
        else {
            Weight -= symbol_Weight(term_TopSymbol(Term));
            if (term_IsComplex(Term))
                stack_Push(term_ArgumentList(Term));
        }
        while (!stack_Empty(Stack) && list_Empty(stack_Top()))
            stack_Pop();
    }

    for (i = 0; i <= MaxVar1; i++) {
        if (ord_VARCOUNT[i][0] < ord_VARCOUNT[i][1]) {
            *VarCond1 = FALSE;
            if (!*VarCond2)
                return Weight;
        }
        if (ord_VARCOUNT[i][0] > ord_VARCOUNT[i][1]) {
            *VarCond2 = FALSE;
            if (!*VarCond1)
                return Weight;
        }
    }
    return Weight;
}