[BACK]Return to strobj.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Diff for /OpenXM_contrib2/asir2000/builtin/strobj.c between version 1.88 and 1.91

version 1.88, 2005/11/01 07:24:11 version 1.91, 2005/11/02 06:32:44
Line 45 
Line 45 
  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,   * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.   * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
  *   *
  * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.87 2005/10/31 10:03:48 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.90 2005/11/02 05:39:23 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 58  extern jmp_buf environnement;
Line 58  extern jmp_buf environnement;
 #endif  #endif
 #include <string.h>  #include <string.h>
   
   #if defined(__GNUC__)
   #define INLINE inline
   #elif defined(VISUAL)
   #define INLINE __inline
   #else
   #define INLINE
   #endif
   
 struct TeXSymbol {  struct TeXSymbol {
         char *text;          char *text;
         char *symbol;          char *symbol;
Line 88  void Pquote_is_integer(),Pquote_is_rational(),Pquote_i
Line 96  void Pquote_is_integer(),Pquote_is_rational(),Pquote_i
 void Pquote_is_dependent(),Pquote_is_function();  void Pquote_is_dependent(),Pquote_is_function();
 void Pquote_normalize();  void Pquote_normalize();
 void Pquote_normalize_comp();  void Pquote_normalize_comp();
 void Pquote_normalize_unify();  void Pquote_normalize_match();
   
 void Pquote_to_funargs(),Pfunargs_to_quote(),Pget_function_name();  void Pquote_to_funargs(),Pfunargs_to_quote(),Pget_function_name();
 void Pquote_unify(),Pget_quote_id(),Pquote_match_rewrite();  void Pquote_match(),Pget_quote_id(),Pquote_match_rewrite();
 void Pquote_to_nary(),Pquote_to_bin();  void Pquote_to_nary(),Pquote_to_bin();
 void fnode_do_assign(NODE arg);  void fnode_do_assign(NODE arg);
 void do_assign(NODE arg);  void do_assign(NODE arg);
Line 104  void tb_to_string(TB tb,STRING *rp);
Line 112  void tb_to_string(TB tb,STRING *rp);
 void fnodenodetotex_tb(NODE n,TB tb);  void fnodenodetotex_tb(NODE n,TB tb);
 void fargstotex_tb(char *opname,FNODE f,TB tb);  void fargstotex_tb(char *opname,FNODE f,TB tb);
 int top_is_minus(FNODE f);  int top_is_minus(FNODE f);
 int quote_unify(Obj f,Obj pat,NODE *rp);  int quote_match(Obj f,Obj pat,NODE *rp);
   
 struct ftab str_tab[] = {  struct ftab str_tab[] = {
         {"sprintf",Psprintf,-99999999},          {"sprintf",Psprintf,-99999999},
Line 138  struct ftab str_tab[] = {
Line 146  struct ftab str_tab[] = {
         {"quotetotex_env",Pquotetotex_env,-99999999},          {"quotetotex_env",Pquotetotex_env,-99999999},
         {"flatten_quote",Pflatten_quote,-2},          {"flatten_quote",Pflatten_quote,-2},
         {"quote_to_funargs",Pquote_to_funargs,1},          {"quote_to_funargs",Pquote_to_funargs,1},
         {"quote_unify",Pquote_unify,2},          {"quote_match",Pquote_match,2},
         {"quote_normalize_unify",Pquote_normalize_unify,2},          {"quote_normalize_match",Pquote_normalize_match,2},
         {"quote_match_rewrite",Pquote_match_rewrite,-4},          {"quote_match_rewrite",Pquote_match_rewrite,-4},
         {"funargs_to_quote",Pfunargs_to_quote,1},          {"funargs_to_quote",Pfunargs_to_quote,1},
         {"get_function_name",Pget_function_name,1},          {"get_function_name",Pget_function_name,1},
Line 626  void Pquote_is_dependent(NODE arg,Q *rp)
Line 634  void Pquote_is_dependent(NODE arg,Q *rp)
 }  }
   
   
 void Pquote_unify(NODE arg,Q *rp)  void Pquote_match(NODE arg,Q *rp)
 {  {
         FNODE f,g;          FNODE f,g;
         Obj obj;          Obj obj;
Line 637  void Pquote_unify(NODE arg,Q *rp)
Line 645  void Pquote_unify(NODE arg,Q *rp)
 #if 0  #if 0
         g = partial_eval(BDY(((QUOTE)ARG0(arg))));          g = partial_eval(BDY(((QUOTE)ARG0(arg))));
         MKQUOTE(q,g);          MKQUOTE(q,g);
         ret = quote_unify((Obj)q,(Obj)ARG1(arg),&r);          ret = quote_match((Obj)q,(Obj)ARG1(arg),&r);
 #else  #else
         obj = (Obj)ARG0(arg);          obj = (Obj)ARG0(arg);
         ret = quote_unify(obj,(Obj)ARG1(arg),&r);          ret = quote_match(obj,(Obj)ARG1(arg),&r);
 #endif  #endif
         if ( ret ) {          if ( ret ) {
                 do_assign(r);                  do_assign(r);
Line 649  void Pquote_unify(NODE arg,Q *rp)
Line 657  void Pquote_unify(NODE arg,Q *rp)
                 *rp = 0;                  *rp = 0;
 }  }
   
 void Pquote_normalize_unify(NODE arg,Q *rp)  void Pquote_normalize_match(NODE arg,Q *rp)
 {  {
         QUOTE fq,pq;          QUOTE fq,pq;
         FNODE f,p;          FNODE f,p;
Line 658  void Pquote_normalize_unify(NODE arg,Q *rp)
Line 666  void Pquote_normalize_unify(NODE arg,Q *rp)
   
         fq = (QUOTE)ARG0(arg); Pquote_normalize(mknode(2,fq,0),&fq); f = (FNODE)BDY(fq);          fq = (QUOTE)ARG0(arg); Pquote_normalize(mknode(2,fq,0),&fq); f = (FNODE)BDY(fq);
         pq = (QUOTE)ARG1(arg); Pquote_normalize(mknode(2,pq,0),&pq); p = (FNODE)BDY(pq);          pq = (QUOTE)ARG1(arg); Pquote_normalize(mknode(2,pq,0),&pq); p = (FNODE)BDY(pq);
         ret = fnode_normalize_unify(f,p,&r);          ret = fnode_normalize_match(f,p,&r);
         if ( ret ) {          if ( ret ) {
                 fnode_do_assign(r);                  fnode_do_assign(r);
                 *rp = ONE;                  *rp = ONE;
Line 679  void Pquote_match_rewrite(NODE arg,Obj *rp)
Line 687  void Pquote_match_rewrite(NODE arg,Obj *rp)
         int ret,ind,ac;          int ret,ind,ac;
   
         obj = (Obj)ARG0(arg);          obj = (Obj)ARG0(arg);
         ret = quote_unify(obj,(Obj)ARG1(arg),&r);          ret = quote_match(obj,(Obj)ARG1(arg),&r);
         if ( ret ) {          if ( ret ) {
                 for ( t = r, s0 = 0; t; t = NEXT(t) ) {                  for ( t = r, s0 = 0; t; t = NEXT(t) ) {
                         NEXTNODE(s0,s);                          NEXTNODE(s0,s);
Line 777  int merge_matching_node(NODE n,NODE a,NODE *rp)
Line 785  int merge_matching_node(NODE n,NODE a,NODE *rp)
         return 1;          return 1;
 }  }
   
 int quote_unify_node(NODE f,NODE pat,NODE *rp) {  int quote_match_node(NODE f,NODE pat,NODE *rp) {
         NODE r,a,tf,tp,r1;          NODE r,a,tf,tp,r1;
         int ret;          int ret;
   
         if ( length(f) != length(pat) ) return 0;          if ( length(f) != length(pat) ) return 0;
         r = 0;          r = 0;
         for ( tf = f, tp = pat; tf; tf = NEXT(tf), tp = NEXT(tp) ) {          for ( tf = f, tp = pat; tf; tf = NEXT(tf), tp = NEXT(tp) ) {
                 ret = quote_unify((Obj)BDY(tf),(Obj)BDY(tp),&a);                  ret = quote_match((Obj)BDY(tf),(Obj)BDY(tp),&a);
                 if ( !ret ) return 0;                  if ( !ret ) return 0;
                 ret = merge_matching_node(r,a,&r1);                  ret = merge_matching_node(r,a,&r1);
                 if ( !ret ) return 0;                  if ( !ret ) return 0;
Line 796  int quote_unify_node(NODE f,NODE pat,NODE *rp) {
Line 804  int quote_unify_node(NODE f,NODE pat,NODE *rp) {
   
 /* f = [a,b,c,...] pat = [X,Y,...] rpat matches the rest of f */  /* f = [a,b,c,...] pat = [X,Y,...] rpat matches the rest of f */
   
 int quote_unify_cons(NODE f,NODE pat,Obj rpat,NODE *rp) {  int quote_match_cons(NODE f,NODE pat,Obj rpat,NODE *rp) {
         QUOTE q;          QUOTE q;
         Q id;          Q id;
         FNODE fn;          FNODE fn;
Line 808  int quote_unify_cons(NODE f,NODE pat,Obj rpat,NODE *rp
Line 816  int quote_unify_cons(NODE f,NODE pat,Obj rpat,NODE *rp
         if ( length(f) < length(pat) ) return 0;          if ( length(f) < length(pat) ) return 0;
         r = 0;          r = 0;
         for ( tf = f, tp = pat; tp; tf = NEXT(tf), tp = NEXT(tp) ) {          for ( tf = f, tp = pat; tp; tf = NEXT(tf), tp = NEXT(tp) ) {
                 ret = quote_unify((Obj)BDY(tf),(Obj)BDY(tp),&a);                  ret = quote_match((Obj)BDY(tf),(Obj)BDY(tp),&a);
                 if ( !ret ) return 0;                  if ( !ret ) return 0;
                 ret = merge_matching_node(r,a,&r1);                  ret = merge_matching_node(r,a,&r1);
                 if ( !ret ) return 0;                  if ( !ret ) return 0;
Line 820  int quote_unify_cons(NODE f,NODE pat,Obj rpat,NODE *rp
Line 828  int quote_unify_cons(NODE f,NODE pat,Obj rpat,NODE *rp
         MKLIST(alist,a);          MKLIST(alist,a);
         arg = mknode(1,alist);          arg = mknode(1,alist);
         Pfunargs_to_quote(arg,&q);          Pfunargs_to_quote(arg,&q);
         ret = quote_unify((Obj)q,rpat,&a);          ret = quote_match((Obj)q,rpat,&a);
         if ( !ret ) return 0;          if ( !ret ) return 0;
         ret = merge_matching_node(r,a,&r1);          ret = merge_matching_node(r,a,&r1);
         if ( !ret ) return 0;          if ( !ret ) return 0;
Line 839  void get_quote_id_arg(QUOTE f,int *id,NODE *r)
Line 847  void get_quote_id_arg(QUOTE f,int *id,NODE *r)
   
 /* *rp : [[quote(A),quote(1)],...] */  /* *rp : [[quote(A),quote(1)],...] */
   
 int quote_unify(Obj f, Obj pat, NODE *rp)  int quote_match(Obj f, Obj pat, NODE *rp)
 {  {
         NODE tf,tp,head,body;          NODE tf,tp,head,body;
         NODE parg,farg,r;          NODE parg,farg,r;
Line 858  int quote_unify(Obj f, Obj pat, NODE *rp)
Line 866  int quote_unify(Obj f, Obj pat, NODE *rp)
                         return 0;                          return 0;
         else if ( OID(pat) == O_LIST ) {          else if ( OID(pat) == O_LIST ) {
                 if ( OID(f) == O_LIST )                  if ( OID(f) == O_LIST )
                         return quote_unify_node(BDY((LIST)f),BDY((LIST)pat),rp);                          return quote_match_node(BDY((LIST)f),BDY((LIST)pat),rp);
                 else                  else
                         return 0;                          return 0;
         } else if ( OID(pat) == O_QUOTE ) {          } else if ( OID(pat) == O_QUOTE ) {
Line 885  int quote_unify(Obj f, Obj pat, NODE *rp)
Line 893  int quote_unify(Obj f, Obj pat, NODE *rp)
   
                                 tp = BDY((LIST)BDY(parg));                                  tp = BDY((LIST)BDY(parg));
                                 if ( pid == I_LIST )                                  if ( pid == I_LIST )
                                         return quote_unify_node(tf,tp,rp);                                          return quote_match_node(tf,tp,rp);
                                 else {                                  else {
                                         rpat = (Obj)BDY(NEXT(parg));                                          rpat = (Obj)BDY(NEXT(parg));
                                         return quote_unify_cons(tf,tp,rpat,rp);                                          return quote_match_cons(tf,tp,rpat,rp);
                                 }                                  }
   
                         case I_PVAR:                          case I_PVAR:
Line 904  int quote_unify(Obj f, Obj pat, NODE *rp)
Line 912  int quote_unify(Obj f, Obj pat, NODE *rp)
                                 if ( id == I_FUNC ) {                                  if ( id == I_FUNC ) {
                                         r = mknode(2,BDY(parg),BDY(farg)); MKLIST(l,r);                                          r = mknode(2,BDY(parg),BDY(farg)); MKLIST(l,r);
                                         head = mknode(1,l);                                          head = mknode(1,l);
                                         ret = quote_unify(BDY(NEXT(farg)),                                          ret = quote_match(BDY(NEXT(farg)),
                                                                 BDY(NEXT(parg)),&body);                                                                  BDY(NEXT(parg)),&body);
                                         if ( !ret ) return 0;                                          if ( !ret ) return 0;
                                         else return merge_matching_node(head,body,rp);                                          else return merge_matching_node(head,body,rp);
Line 932  int quote_unify(Obj f, Obj pat, NODE *rp)
Line 940  int quote_unify(Obj f, Obj pat, NODE *rp)
                                 get_quote_id_arg((QUOTE)pat,&pid,&parg);                                  get_quote_id_arg((QUOTE)pat,&pid,&parg);
                                 get_quote_id_arg((QUOTE)f,&id,&farg);                                  get_quote_id_arg((QUOTE)f,&id,&farg);
                                 if ( compqa(CO,BDY(farg),BDY(parg)) ) return 0;                                  if ( compqa(CO,BDY(farg),BDY(parg)) ) return 0;
                                 return quote_unify_node(NEXT(farg),NEXT(parg),rp);                                  return quote_match_node(NEXT(farg),NEXT(parg),rp);
   
                         default:                          default:
                                 if ( OID(f) != O_QUOTE ) return 0;                                  if ( OID(f) != O_QUOTE ) return 0;
Line 940  int quote_unify(Obj f, Obj pat, NODE *rp)
Line 948  int quote_unify(Obj f, Obj pat, NODE *rp)
                                 if ( id != pid ) return 0;                                  if ( id != pid ) return 0;
                                 get_quote_id_arg((QUOTE)pat,&pid,&parg);                                  get_quote_id_arg((QUOTE)pat,&pid,&parg);
                                 get_quote_id_arg((QUOTE)f,&id,&farg);                                  get_quote_id_arg((QUOTE)f,&id,&farg);
                                 return quote_unify_node(farg,parg,rp);                                  return quote_match_node(farg,parg,rp);
                 }                  }
         }          }
 }  }
Line 1306  FNODE strip_paren(FNODE);
Line 1314  FNODE strip_paren(FNODE);
   
 void fnodetotex_tb(FNODE f,TB tb)  void fnodetotex_tb(FNODE f,TB tb)
 {  {
         NODE n,t,t0;          NODE n,t,t0,args;
         char vname[BUFSIZ],prefix[BUFSIZ];          char vname[BUFSIZ],prefix[BUFSIZ];
         char *opname,*vname_conv,*prefix_conv;          char *opname,*vname_conv,*prefix_conv;
         Obj obj;          Obj obj;
         int i,len,allzero,elen,elen2,si;          int i,len,allzero,elen,elen2,si;
         C cplx;          C cplx;
         char *r;          char *r;
         FNODE fi,f2;          FNODE fi,f2,f1;
   
         write_tb(" ",tb);          write_tb(" ",tb);
         if ( !f ) {          if ( !f ) {
Line 1394  void fnodetotex_tb(FNODE f,TB tb)
Line 1402  void fnodetotex_tb(FNODE f,TB tb)
                                         break;                                          break;
                         }                          }
                         break;                          break;
                   case I_NARYOP:
                           args = (NODE)FA1(f);
                           write_tb("(",tb);
                           switch ( OPNAME(f) ) {
                                   case '+':
                                           fnodetotex_tb((FNODE)BDY(args),tb);
                                           for ( args = NEXT(args); args; args = NEXT(args) ) {
                                                   write_tb("+",tb);
                                                   fnodetotex_tb((FNODE)BDY(args),tb);
                                           }
                                           break;
                                   case '*':
                                           f1 = (FNODE)BDY(args);
                                           if ( f1->id == I_FORMULA && MUNIQ(FA0(f1)) )
                                                   write_tb("-",tb);
                                           else
                                                   fnodetotex_tb(f1,tb);
                                           write_tb(" ",tb);
                                           for ( args = NEXT(args); args; args = NEXT(args) ) {
                                                   /* XXX special care for DP */
                                                   f2 = (FNODE)BDY(args);
                                                   if ( f2->id == I_EV ) {
                                                           n = (NODE)FA0(f2);
                                                           for ( i = 0; n; n = NEXT(n), i++ ) {
                                                                   fi = (FNODE)BDY(n);
                                                                   if ( fi->id != I_FORMULA || FA0(fi) )
                                                                           break;
                                                           }
                                                           if ( n )
                                                                   fnodetotex_tb(f2,tb);
                                                   } else
                                                           fnodetotex_tb(f2,tb);
                                           }
                                           break;
                                   default:
                                           error("invalid nary op");
                                           break;
                           }
                           write_tb(")",tb);
                           break;
   
                 case I_COP:                  case I_COP:
                         switch( (cid)FA0(f) ) {                          switch( (cid)FA0(f) ) {
Line 1786  int top_is_minus(FNODE f)
Line 1834  int top_is_minus(FNODE f)
                                                 return opname[0]=='-';                                                  return opname[0]=='-';
                                 }                                  }
                         }                          }
                   case I_NARYOP:
                           return top_is_minus((FNODE)BDY((NODE)FA1(f)));
   
                 default:                  default:
                         return 0;                          return 0;
         }          }
Line 2005  void Pquote_normalize_comp(NODE arg,Q *rp)
Line 2056  void Pquote_normalize_comp(NODE arg,Q *rp)
         STOQ(r,*rp);          STOQ(r,*rp);
 }  }
   
 int fnode_is_number(FNODE f)  INLINE int fnode_is_number(FNODE f)
 {  {
         Obj obj;          Obj obj;
   
Line 2168  FNODE fnode_normalize(FNODE f,int expand)
Line 2219  FNODE fnode_normalize(FNODE f,int expand)
         NODE n;          NODE n;
         Q q;          Q q;
   
           if ( f->normalized && (f->expanded || !expand) ) return f;
         STOQ(-1,q);          STOQ(-1,q);
         mone = mkfnode(1,I_FORMULA,q);          mone = mkfnode(1,I_FORMULA,q);
         switch ( f->id ) {          switch ( f->id ) {
                 case I_PAREN:                  case I_PAREN:
                         return fnode_normalize(FA0(f),expand);                          r = fnode_normalize(FA0(f),expand);
                           break;
   
                 case I_MINUS:                  case I_MINUS:
                         return fnode_normalize_mul_coef((Num)q,                          r = fnode_normalize_mul_coef((Num)q,
                                 fnode_normalize(FA0(f),expand),expand);                                  fnode_normalize(FA0(f),expand),expand);
                           break;
   
                 case I_BOP:                  case I_BOP:
                         /* arf fnode fnode */                          /* arf fnode fnode */
Line 2184  FNODE fnode_normalize(FNODE f,int expand)
Line 2238  FNODE fnode_normalize(FNODE f,int expand)
                         a2 = fnode_normalize(FA2(f),expand);                          a2 = fnode_normalize(FA2(f),expand);
                         switch ( OPNAME(f) ) {                          switch ( OPNAME(f) ) {
                                 case '+':                                  case '+':
                                         return fnode_normalize_add(a1,a2,expand);                                          r = fnode_normalize_add(a1,a2,expand);
                                           break;
                                 case '-':                                  case '-':
                                         a2 = fnode_normalize_mul_coef((Num)q,a2,expand);                                          a2 = fnode_normalize_mul_coef((Num)q,a2,expand);
                                         return fnode_normalize_add(a1,a2,expand);                                          r = fnode_normalize_add(a1,a2,expand);
                                           break;
                                 case '*':                                  case '*':
                                         return fnode_normalize_mul(a1,a2,expand);                                          r = fnode_normalize_mul(a1,a2,expand);
                                           break;
                                 case '/':                                  case '/':
                                         a2 = fnode_normalize_pwr(a2,mone,expand);                                          a2 = fnode_normalize_pwr(a2,mone,expand);
                                         return fnode_normalize_mul(a1,a2,expand);                                          r = fnode_normalize_mul(a1,a2,expand);
                                           break;
                                 case '^':                                  case '^':
                                         return fnode_normalize_pwr(a1,a2,expand);                                          r = fnode_normalize_pwr(a1,a2,expand);
                                           break;
                                 default:                                  default:
                                         return mkfnode(3,I_BOP,FA0(f),a1,a2);                                          r = mkfnode(3,I_BOP,FA0(f),a1,a2);
                                           break;
                         }                          }
                         break;                          break;
   
Line 2209  FNODE fnode_normalize(FNODE f,int expand)
Line 2269  FNODE fnode_normalize(FNODE f,int expand)
                                                 a1 = fnode_normalize(BDY(n),expand);                                                  a1 = fnode_normalize(BDY(n),expand);
                                                 r = fnode_normalize_add(r,a1,expand);                                                  r = fnode_normalize_add(r,a1,expand);
                                         }                                          }
                                         return r;                                          break;
                                 case '*':                                  case '*':
                                         n = (NODE)FA1(f);                                          n = (NODE)FA1(f);
                                         r = fnode_normalize(BDY(n),expand); n = NEXT(n);                                          r = fnode_normalize(BDY(n),expand); n = NEXT(n);
Line 2217  FNODE fnode_normalize(FNODE f,int expand)
Line 2277  FNODE fnode_normalize(FNODE f,int expand)
                                                 a1 = fnode_normalize(BDY(n),expand);                                                  a1 = fnode_normalize(BDY(n),expand);
                                                 r = fnode_normalize_mul(r,a1,expand);                                                  r = fnode_normalize_mul(r,a1,expand);
                                         }                                          }
                                         return r;                                          break;
                                 default:                                  default:
                                         error("fnode_normallize : cannot happen");                                          error("fnode_normallize : cannot happen");
                         }                          }
                           break;
   
                 default:                  default:
                         return fnode_apply(f,fnode_normalize,expand);                          return fnode_apply(f,fnode_normalize,expand);
         }          }
           r->normalized = 1;
           r->expanded = expand;
           return r;
 }  }
   
 FNODE fnode_apply(FNODE f,FNODE (*func)(),int expand)  FNODE fnode_apply(FNODE f,FNODE (*func)(),int expand)
Line 2377  FNODE fnode_normalize_mul(FNODE f1,FNODE f2,int expand
Line 2441  FNODE fnode_normalize_mul(FNODE f1,FNODE f2,int expand
   
 FNODE fnode_normalize_pwr(FNODE f1,FNODE f2,int expand)  FNODE fnode_normalize_pwr(FNODE f1,FNODE f2,int expand)
 {  {
         FNODE b,b1,e1,e,cc,r;          FNODE b,b1,e1,e,cc,r,mf2,mone,inv;
         Num c,c1;          Num c,c1,nf2;
         NODE arg,n;          int ee;
           NODE arg,n,t0,t1;
         Q q;          Q q;
   
         if ( IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,ONE);          if ( IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,ONE);
Line 2398  FNODE fnode_normalize_pwr(FNODE f1,FNODE f2,int expand
Line 2463  FNODE fnode_normalize_pwr(FNODE f1,FNODE f2,int expand
                         return b1;                          return b1;
                 else                  else
                         return mkfnode(3,I_BOP,FA0(f1),b1,e);                          return mkfnode(3,I_BOP,FA0(f1),b1,e);
         } else if ( IS_NARYMUL(f1) && fnode_is_integer(f2) ) {          } else if ( expand && IS_NARYMUL(f1) && fnode_is_integer(f2) ) {
                 fnode_coef_body(f1,&c1,&b1);                  fnode_coef_body(f1,&c1,&b1);
                 pwrnum(0,(Num)c1,(Num)eval(f2),&c);                  nf2 = (Num)eval(f2);
                   pwrnum(0,(Num)c1,nf2,&c);
                   ee = QTOS((Q)nf2);
                 cc = mkfnode(1,I_FORMULA,c);                  cc = mkfnode(1,I_FORMULA,c);
                 b = fnode_normalize_pwr(b1,f2,expand);                  if ( fnode_is_nonnegative_integer(f2) )
                           b = fnode_expand_pwr(b1,ee);
                   else {
                           STOQ(-1,q);
                           mone = mkfnode(1,I_FORMULA,q);
                           for ( t0 = 0, n = (NODE)FA1(b1); n; n = NEXT(n) ) {
                                   inv = mkfnode(3,I_BOP,pwrfs,BDY(n),mone);
                                   MKNODE(t1,inv,t0); t0 = t1;
                           }
                           b1 = mkfnode(2,I_NARYOP,FA0(f1),t0);
                           b = fnode_expand_pwr(b1,-ee);
                   }
                 if ( fnode_is_one(cc) )                  if ( fnode_is_one(cc) )
                         return b;                          return b;
                 else                  else
Line 2672  NODE append_node(NODE a1,NODE a2)
Line 2750  NODE append_node(NODE a1,NODE a2)
         }          }
 }  }
   
 int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)  int fnode_normalize_match(FNODE f,FNODE pat,NODE *rp)
 {  {
         NODE m,m1,m2,base,exp,fa,pa,n;          NODE m,m1,m2,base,exp,fa,pa,n;
         LIST l;          LIST l;
Line 2696  int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)
Line 2774  int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)
                 case I_BOP:                  case I_BOP:
                         /* OPNAME should be "^" */                          /* OPNAME should be "^" */
                         if ( !IS_BINARYPWR(pat) )                          if ( !IS_BINARYPWR(pat) )
                                 error("fnode_normalize_unify : invalid BOP");                                  error("fnode_normalize_match : invalid BOP");
                         if ( IS_BINARYPWR(f) ) {                          if ( IS_BINARYPWR(f) ) {
                                 fbase = FA1(f); fexp = FA2(f);                                  fbase = FA1(f); fexp = FA2(f);
                         } else {                          } else {
                                 fbase = f; fexp = mkfnode(1,I_FORMULA,ONE);                                  fbase = f; fexp = mkfnode(1,I_FORMULA,ONE);
                         }                          }
                         if ( !fnode_normalize_unify(fbase,FA1(pat),&base) ) return 0;                          if ( !fnode_normalize_match(fbase,FA1(pat),&base) ) return 0;
                         a = rewrite_fnode(FA2(pat),base);                          a = rewrite_fnode(FA2(pat),base);
                         if ( !fnode_normalize_unify(fexp,a,&exp) ) return 0;                          if ( !fnode_normalize_match(fexp,a,&exp) ) return 0;
                         else {                          else {
                                 *rp = append_node(base,exp);                                  *rp = append_node(base,exp);
                                 return 1;                                  return 1;
Line 2721  int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)
Line 2799  int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)
                         m = 0;                          m = 0;
                         while ( fa && pa ) {                          while ( fa && pa ) {
                                 a = rewrite_fnode(BDY(pa),m);                                  a = rewrite_fnode(BDY(pa),m);
                                 if ( !fnode_normalize_unify(BDY(fa),a,&m1) ) return 0;                                  if ( !fnode_normalize_match(BDY(fa),a,&m1) ) return 0;
                                 m = append_node(m1,m);                                  m = append_node(m1,m);
                                 fa = NEXT(fa); pa = NEXT(pa);                                  fa = NEXT(fa); pa = NEXT(pa);
                         }                          }
Line 2733  int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)
Line 2811  int fnode_normalize_unify(FNODE f,FNODE pat,NODE *rp)
   
                 case I_NARYOP:                  case I_NARYOP:
                         if ( IS_NARYADD(pat) )                          if ( IS_NARYADD(pat) )
                                 return fnode_normalize_unify_naryadd(f,pat,rp);                                  return fnode_normalize_match_naryadd(f,pat,rp);
                         else if ( IS_NARYMUL(pat) )                          else if ( IS_NARYMUL(pat) )
                                 return fnode_normalize_unify_narymul(f,pat,rp);                                  return fnode_normalize_match_narymul(f,pat,rp);
                         else                          else
                                 error("fnode_normalize_unify : invalid NARYOP");                                  error("fnode_normalize_match : invalid NARYOP");
                         break;                          break;
   
                 default:                  default:
                         error("fnode_normalize_unify : invalid pattern");                          error("fnode_normalize_match : invalid pattern");
         }          }
 }  }
   
Line 2806  FNODE fnode_right_narymul(FNODE p,int i)
Line 2884  FNODE fnode_right_narymul(FNODE p,int i)
         }          }
 }  }
   
 int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE *rp)  int fnode_normalize_match_naryadd(FNODE f,FNODE p,NODE *rp)
 {  {
         int fl,pl,fi,pi;          int fl,pl,fi,pi;
         NODE fa,pa,t,s,m,m1;          NODE fa,pa,t,s,m,m1;
Line 2818  int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE
Line 2896  int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE
         if ( fl < pl ) return 0;          if ( fl < pl ) return 0;
         else if ( pl == 1 ) {          else if ( pl == 1 ) {
                 if ( fl == 1 )                  if ( fl == 1 )
                         return fnode_normalize_unify(BDY(fa),BDY(pa),rp);                          return fnode_normalize_match(BDY(fa),BDY(pa),rp);
                 else                  else
                         return 0;                          return 0;
         } else {          } else {
Line 2828  int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE
Line 2906  int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE
                         /* all are I_PVAR */                          /* all are I_PVAR */
                         m = 0;                          m = 0;
                         for ( t = pa, s = fa; NEXT(t); t = NEXT(t), s = NEXT(s) ) {                          for ( t = pa, s = fa; NEXT(t); t = NEXT(t), s = NEXT(s) ) {
                                 fnode_normalize_unify(BDY(s),BDY(t),&m1);                                  fnode_normalize_match(BDY(s),BDY(t),&m1);
                                 m = append_node(m1,m);                                  m = append_node(m1,m);
                         }                          }
                         if ( !NEXT(s) )                          if ( !NEXT(s) )
                                 fr = (FNODE)BDY(s);                                  fr = (FNODE)BDY(s);
                         else                          else
                                 fr = mkfnode(2,I_NARYOP,FA0(f),s);                                  fr = mkfnode(2,I_NARYOP,FA0(f),s);
                         fnode_normalize_unify(fr,BDY(t),&m1);                          fnode_normalize_match(fr,BDY(t),&m1);
                         *rp = append_node(m1,m);                          *rp = append_node(m1,m);
                         return 1;                          return 1;
                 } else {                  } else {
                         pivot = (FNODE)BDY(t);                          pivot = (FNODE)BDY(t);
                         pr = fnode_removeith_naryadd(p,pi);                          pr = fnode_removeith_naryadd(p,pi);
                         for ( s = fa, fi = 0; s; s = NEXT(s), fi++ ) {                          for ( s = fa, fi = 0; s; s = NEXT(s), fi++ ) {
                                 if ( fnode_normalize_unify(BDY(s),pivot,&m) ) {                                  if ( fnode_normalize_match(BDY(s),pivot,&m) ) {
                                         fr = fnode_removeith_naryadd(f,fi);                                          fr = fnode_removeith_naryadd(f,fi);
                                         prr = rewrite_fnode(pr,m);                                          prr = rewrite_fnode(pr,m);
                                         if ( fnode_normalize_unify(fr,prr,&m1) ) {                                          if ( fnode_normalize_match(fr,prr,&m1) ) {
                                                 *rp = append_node(m,m1);                                                  *rp = append_node(m,m1);
                                                 return 1;                                                  return 1;
                                         }                                          }
Line 2856  int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE
Line 2934  int fnode_normalize_unify_naryadd(FNODE f,FNODE p,NODE
         }          }
 }  }
   
 int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE *rp)  int fnode_normalize_match_narymul(FNODE f,FNODE p,NODE *rp)
 {  {
         int fl,pl,fi,pi;          int fl,pl,fi,pi;
         NODE fa,pa,t,s,m,m1;          NODE fa,pa,t,s,m,m1;
Line 2868  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
Line 2946  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
         if ( fl < pl ) return 0;          if ( fl < pl ) return 0;
         else if ( pl == 1 ) {          else if ( pl == 1 ) {
                 if ( fl == 1 )                  if ( fl == 1 )
                         return fnode_normalize_unify(BDY(fa),BDY(pa),rp);                          return fnode_normalize_match(BDY(fa),BDY(pa),rp);
                 else                  else
                         return 0;                          return 0;
         } else {          } else {
Line 2879  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
Line 2957  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
                         m = 0;                          m = 0;
                         for ( t = pa, s = fa; NEXT(t); t = NEXT(t), s = NEXT(s) ) {                          for ( t = pa, s = fa; NEXT(t); t = NEXT(t), s = NEXT(s) ) {
                                 pr = rewrite_fnode(BDY(t),m);                                  pr = rewrite_fnode(BDY(t),m);
                                 if ( !fnode_normalize_unify(BDY(s),pr,&m1) ) return 0;                                  if ( !fnode_normalize_match(BDY(s),pr,&m1) ) return 0;
                                 m = append_node(m1,m);                                  m = append_node(m1,m);
                         }                          }
                         if ( !NEXT(s) )                          if ( !NEXT(s) )
Line 2887  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
Line 2965  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
                         else                          else
                                 fr = mkfnode(2,I_NARYOP,FA0(f),s);                                  fr = mkfnode(2,I_NARYOP,FA0(f),s);
                         pr = rewrite_fnode(BDY(t),m);                          pr = rewrite_fnode(BDY(t),m);
                         if ( !fnode_normalize_unify(fr,pr,&m1) ) return 0;                          if ( !fnode_normalize_match(fr,pr,&m1) ) return 0;
                         *rp = append_node(m1,m);                          *rp = append_node(m1,m);
                         return 1;                          return 1;
                 } else {                  } else {
Line 2896  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
Line 2974  int fnode_normalize_unify_narymul(FNODE f,FNODE p,NODE
                         pright = fnode_right_narymul(p,pi);                          pright = fnode_right_narymul(p,pi);
                         /* XXX : incomplete */                          /* XXX : incomplete */
                         for ( s = fa, fi = 0; s; s = NEXT(s), fi++ ) {                          for ( s = fa, fi = 0; s; s = NEXT(s), fi++ ) {
                                 if ( fnode_normalize_unify(BDY(s),pivot,&m) ) {                                  if ( fnode_normalize_match(BDY(s),pivot,&m) ) {
                                         fleft = fnode_left_narymul(f,fi);                                          fleft = fnode_left_narymul(f,fi);
                                         pleft1 = rewrite_fnode(pleft,m);                                          pleft1 = rewrite_fnode(pleft,m);
                                         if ( fnode_normalize_unify(fleft,pleft1,&m1) ) {                                          if ( fnode_normalize_match(fleft,pleft1,&m1) ) {
                                                 m = append_node(m1,m);                                                  m = append_node(m1,m);
                                                 fright = fnode_right_narymul(f,fi);                                                  fright = fnode_right_narymul(f,fi);
                                                 pright1 = rewrite_fnode(pright,m);                                                  pright1 = rewrite_fnode(pright,m);
                                                 if ( fnode_normalize_unify(fright,pright1,&m1) ) {                                                  if ( fnode_normalize_match(fright,pright1,&m1) ) {
                                                         *rp = append_node(m1,m);                                                          *rp = append_node(m1,m);
                                                         return 1;                                                          return 1;
                                                 }                                                  }

Legend:
Removed from v.1.88  
changed lines
  Added in v.1.91

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>