Sindbad~EG File Manager

Current Path : /usr/home/beeson/MathXpert/var/
Upload File :
Current File : /usr/home/beeson/MathXpert/var/alphaeq.c

// 7.2.06  last modified
// 11.24.23 initialized savex, savey,  to silence a warning

#include <string.h>
#include <assert.h>

#include "terms.h"
#include "speed.h"
#include "prover.h"  // BINDING 

static int table[2560];
// we assume all bound variables will have functor < 2560

static int alpha_aux(term a, term b)
/* return 0 if term a and term b differ by
a renaming of bound variables, or by a renaming 
of free variables given by 'table', i.e. 
two variables are equivalent if one's functor
is the entry in table under the other one's functor
as index. */

{ unsigned short f = FUNCTOR(a);
  unsigned short g = FUNCTOR(b);
  term x,y;
  int savex=0,savey=0,err; //initialization just to silence a warning
  unsigned short i,n;
  if(ISATOM(a) && ISATOM(b))
      {  if(f == g)
            return 0;
         if(table[f] == g || table[g] == f)
            return 0;
         return 1;
      }
  if(ISATOM(a) || ISATOM(b) || f != g || ARITY(a) != ARITY(b))
     return 1;
  if(OBJECT(a) && OBJECT(b))
     return equals(a,b);
  if(OBJECT(a) || OBJECT(b))
     return 1;
  if(BINDING(a))
     { // make an entry in table for the bound variable
       x = BOUNDVAR(a);  // the bound variable
       y = BOUNDVAR(b); 
       savex = table[FUNCTOR(x)];
       savey = table[FUNCTOR(y)];
       table[FUNCTOR(x)] = FUNCTOR(y);
       table[FUNCTOR(y)] = FUNCTOR(x);
     }
  n = ARITY(a);
  for(i=0;i<n;i++)
     { err = alpha_aux(ARG(i,a),ARG(i,b));
       if(err)
          return 1;  // no need to restore table.
     }
  if(BINDING(a))
     { table[FUNCTOR(x)] = savex;
       table[FUNCTOR(y)] = savey;
     }
  return 0;
}  
       
     
int alpha_equivalent(term a, term b)
/* return 0 if a and b differ only by 
renaming bound variables */
{ memset(table,0,sizeof(table));
  return alpha_aux(a,b);
}  


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists