[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.108 and 1.109

version 1.108, 2005/12/11 07:21:43 version 1.109, 2005/12/14 06:07:30
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.107 2005/12/11 05:27:30 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.108 2005/12/11 07:21:43 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 94  void Pflatten_quote();
Line 94  void Pflatten_quote();
   
 void Pqt_is_integer(),Pqt_is_rational(),Pqt_is_number(),Pqt_is_coef();  void Pqt_is_integer(),Pqt_is_rational(),Pqt_is_number(),Pqt_is_coef();
 void Pqt_is_dependent(),Pqt_is_function(),Pqt_is_var();  void Pqt_is_dependent(),Pqt_is_function(),Pqt_is_var();
 void Pqt_set_ord(),Pqt_set_coef();  void Pqt_set_ord(),Pqt_set_coef(),Pqt_set_weight();
 void Pqt_normalize();  void Pqt_normalize();
 void Pnqt_comp();  void Pnqt_comp();
 void Pnqt_match();  void Pnqt_match();
Line 165  struct ftab str_tab[] = {
Line 165  struct ftab str_tab[] = {
   
         {"qt_set_coef",Pqt_set_coef,-1},          {"qt_set_coef",Pqt_set_coef,-1},
         {"qt_set_ord",Pqt_set_ord,-1},          {"qt_set_ord",Pqt_set_ord,-1},
           {"qt_set_weight",Pqt_set_weight,-1},
         {"qt_normalize",Pqt_normalize,-2},          {"qt_normalize",Pqt_normalize,-2},
         {"qt_match",Pqt_match,2},          {"qt_match",Pqt_match,2},
         {"nqt_match_rewrite",Pnqt_match_rewrite,3},          {"nqt_match_rewrite",Pnqt_match_rewrite,3},
Line 2166  VL reordvars(VL vl0,NODE head)
Line 2167  VL reordvars(VL vl0,NODE head)
         return vl;          return vl;
 }  }
   
   struct wtab {
           V v;
           int w;
   };
   
   struct wtab *qt_weight_tab;
 VL qt_current_ord, qt_current_coef;  VL qt_current_ord, qt_current_coef;
 LIST qt_current_ord_obj,qt_current_coef_obj;  LIST qt_current_ord_obj,qt_current_coef_obj,qt_current_weight_obj;
   LIST qt_current_weight_obj;
   
 void Pqt_set_ord(NODE arg,LIST *rp)  void Pqt_set_ord(NODE arg,LIST *rp)
 {  {
Line 2177  void Pqt_set_ord(NODE arg,LIST *rp)
Line 2185  void Pqt_set_ord(NODE arg,LIST *rp)
   
         if ( !argc(arg) )          if ( !argc(arg) )
                 *rp = qt_current_ord_obj;                  *rp = qt_current_ord_obj;
         else {          else if ( !ARG0(arg) ) {
                   qt_current_ord_obj = 0;
                   qt_current_ord = 0;
           } else {
                 qt_current_ord = reordvars(CO,BDY((LIST)ARG0(arg)));                  qt_current_ord = reordvars(CO,BDY((LIST)ARG0(arg)));
                 for ( r0 = 0, vl = qt_current_ord; vl; vl = NEXT(vl) ) {                  for ( r0 = 0, vl = qt_current_ord; vl; vl = NEXT(vl) ) {
                         NEXTNODE(r0,r); MKV(vl->v,v); BDY(r) = v;                          NEXTNODE(r0,r); MKV(vl->v,v); BDY(r) = v;
Line 2188  void Pqt_set_ord(NODE arg,LIST *rp)
Line 2199  void Pqt_set_ord(NODE arg,LIST *rp)
         }          }
 }  }
   
   void Pqt_set_weight(NODE arg,LIST *rp)
   {
           NODE n,pair;
           int l,i;
           struct wtab *tab;
   
           if ( !argc(arg) )
                   *rp = qt_current_weight_obj;
           else if ( !ARG0(arg) ) {
                   qt_current_weight_obj = 0;
                   qt_weight_tab = 0;
           } else {
                   n = BDY((LIST)ARG0(arg));
                   l = length(n);
                   tab = qt_weight_tab = (struct wtab *)MALLOC((l+1)*sizeof(struct wtab));
                   for ( i = 0; i < l; i++, n = NEXT(n) ) {
                           pair = BDY((LIST)BDY(n));
                           tab[i].v = VR((P)ARG0(pair));
                           tab[i].w = QTOS((Q)ARG1(pair));
                   }
                   tab[i].v = 0;
                   qt_current_weight_obj = (LIST)ARG0(arg);
                   *rp = qt_current_weight_obj;
           }
   }
   
 void Pqt_set_coef(NODE arg,LIST *rp)  void Pqt_set_coef(NODE arg,LIST *rp)
 {  {
         NODE r0,r,n;          NODE r0,r,n;
Line 2196  void Pqt_set_coef(NODE arg,LIST *rp)
Line 2233  void Pqt_set_coef(NODE arg,LIST *rp)
   
         if ( !argc(arg) )          if ( !argc(arg) )
                 *rp = qt_current_coef_obj;                  *rp = qt_current_coef_obj;
         else {          else if ( !ARG0(arg) ) {
                   qt_current_coef_obj = 0;
                   qt_current_coef = 0;
           } else {
                 n = BDY((LIST)ARG0(arg));                  n = BDY((LIST)ARG0(arg));
                 for ( vl0 = 0, r0 = 0; n; n = NEXT(n) ) {                  for ( vl0 = 0, r0 = 0; n; n = NEXT(n) ) {
                         NEXTNODE(r0,r);                          NEXTNODE(r0,r);
Line 2845  FNODE nfnode_mul(FNODE f1,FNODE f2,int expand)
Line 2885  FNODE nfnode_mul(FNODE f1,FNODE f2,int expand)
         FNODE b1,b2,e1,e2,cc,t,t1;          FNODE b1,b2,e1,e2,cc,t,t1;
         FNODE *m;          FNODE *m;
         int s;          int s;
         Obj c1,c2,c;          Obj c1,c2,c,e;
         Num e;  
         int l1,l,i,j;          int l1,l,i,j;
   
         if ( IS_ZERO(f1) || IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,0);          if ( IS_ZERO(f1) || IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,0);
Line 2887  FNODE nfnode_mul(FNODE f1,FNODE f2,int expand)
Line 2926  FNODE nfnode_mul(FNODE f1,FNODE f2,int expand)
                 else {                  else {
                         fnode_base_exp(m[i-1],&b1,&e1); fnode_base_exp(BDY(r),&b2,&e2);                          fnode_base_exp(m[i-1],&b1,&e1); fnode_base_exp(BDY(r),&b2,&e2);
                         if ( compfnode(b1,b2) ) break;                          if ( compfnode(b1,b2) ) break;
                         addnum(0,eval(e1),eval(e2),&e);                          arf_add(CO,eval(e1),eval(e2),&e);
                         if ( !e ) i--;                          if ( !e ) i--;
                         else if ( UNIQ(e) )                          else if ( UNIQ(e) )
                                 m[i-1] = b1;                                  m[i-1] = b1;
Line 3085  void fnode_coef_body(FNODE f,Obj *cp,FNODE *bp)
Line 3124  void fnode_coef_body(FNODE f,Obj *cp,FNODE *bp)
   
 int nfnode_comp_pwr(FNODE f1,FNODE f2);  int nfnode_comp_pwr(FNODE f1,FNODE f2);
   
   int nfnode_weight(struct wtab *tab,FNODE f)
   {
           NODE n;
           int w,w1;
           int i;
           Q a2;
           V v;
   
           switch ( f->id ) {
                   case I_FORMULA:
                           if ( fnode_is_coef(f) ) return 0;
                           else if ( fnode_is_var(f) ) {
                                   v = VR((P)FA0(f));
                                   for ( i = 0; tab[i].v; i++ )
                                           if ( v == tab[i].v ) return tab[i].w;
                                   return w;
                           } else return 0;
   
                   /* XXX */
                   case I_PVAR: return 1;
                   /* XXX */
                   case I_FUNC: I_FUNC: I_FUNC_QARG:
                           /* w(f) = 1 */
                           /* w(f(a1,...,an)=w(a1)+...+w(an) */
                           n = FA0((FNODE)FA1(f));
                           for ( w = 0; n; n = NEXT(n) )
                                   w += nfnode_weight(tab,BDY(n));
                           return w;
                   case I_NARYOP:
                           n = (NODE)FA1(f);
                           if ( IS_NARYADD(f) )
                                   for ( w = nfnode_weight(tab,BDY(n)),
                                           n = NEXT(n); n; n = NEXT(n) ) {
                                           w1 = nfnode_weight(tab,BDY(n));
                                           w = MAX(w,w1);
                                   }
                           else
                                   for ( w = 0; n; n = NEXT(n) )
                                           w += nfnode_weight(tab,BDY(n));
                           return w;
                   case I_BOP:
                           /* must be binary power */
                           /* XXX w(2^x)=0 ? */
                           if ( fnode_is_rational(FA2(f)) ) {
                                   a2 = (Q)eval(FA2(f));
                                   w = QTOS(a2);
                           } else
                                   w = nfnode_weight(tab,FA2(f));
                           return nfnode_weight(tab,FA1(f))*w;
                   default:
                           error("nfnode_weight : not_implemented");
           }
   }
   
 int nfnode_comp(FNODE f1,FNODE f2)  int nfnode_comp(FNODE f1,FNODE f2)
 {  {
         NODE n1,n2;          NODE n1,n2;
Line 3093  int nfnode_comp(FNODE f1,FNODE f2)
Line 3186  int nfnode_comp(FNODE f1,FNODE f2)
         FNODE b1,b2,e1,e2,g,a1,a2,fn1,fn2;          FNODE b1,b2,e1,e2,g,a1,a2,fn1,fn2;
         Num ee,ee1;          Num ee,ee1;
         Obj c1,c2;          Obj c1,c2;
           int w1,w2;
   
           if ( qt_weight_tab ) {
                   w1 = nfnode_weight(qt_weight_tab,f1);
                   w2 = nfnode_weight(qt_weight_tab,f2);
                   if ( w1 > w2 ) return 1;
                   if ( w1 < w2 ) return -1;
           }
   
         if ( IS_NARYADD(f1) || IS_NARYADD(f2) ) {          if ( IS_NARYADD(f1) || IS_NARYADD(f2) ) {
                 f1 = to_naryadd(f1); f2 = to_naryadd(f2);                  f1 = to_naryadd(f1); f2 = to_naryadd(f2);

Legend:
Removed from v.1.108  
changed lines
  Added in v.1.109

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