Sindbad~EG File Manager

Current Path : /usr/home/beeson/Otter-Lambda/yyy/polyval/
Upload File :
Current File : /usr/home/beeson/Otter-Lambda/yyy/polyval/fsubst.c

/* M. Beeson, for Mathpert.
Extracted from relrates.c 6.2.97
Last modified 1.29.98
*/

#define POLYVAL_DLL
#include "globals.h"
#include "fsubst.h"

/*___________________________________________________________*/
MEXPORT_POLYVAL void free_subst(term new, term old, term t, term *ans)
/* substitute new for occurrences of old in t, but stopping
   the substitution inside each binding operator.  Thus
   on substituting x=3 in  x dx/dt  we get 3 dx/dt, not 3 d3/dt.
*/
{ unsigned short f;
  unsigned short n;
  int i;
  if(equals(t,old))
     { *ans = new;
       return;
     }

  /*  y' counts as equal to dy/dt where t is the eigenvariable */
  if(FUNCTOR(t) == DIFF && FUNCTOR(old) == PR &&
     equals(ARG(1,t),get_eigenvariable()) &&
     equals(ARG(0,t),ARG(0,old)) &&
     ONE(ARG(1,old))
    )
     { *ans = new;
       return;
     }
  if(FUNCTOR(old) == DIFF && FUNCTOR(t) == PR &&
     equals(ARG(1,old),get_eigenvariable()) &&
     equals(ARG(0,t),ARG(0,old)) &&
     ONE(ARG(1,t))
    )
    { *ans = new;
      return;
    }
  if(ATOMIC(t))
     { *ans = t;
       return;
     }
  f = FUNCTOR(t);
  if(f==DIFF || f == PR || f == INTEGRAL || f == LAM || f == ALL || f == EXISTS)
     { *ans = t;
       return;
     }
  n = ARITY(t);
  *ans = make_term(f,n);
  for(i=0;i<n;i++)
     { free_subst(new,old,ARG(i,t),ARGPTR(*ans) + i);
     }
}

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