[BACK]Return to test1-tr.rr CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-contrib / testing

Annotation of OpenXM/src/asir-contrib/testing/test1-tr.rr, Revision 1.3

1.3     ! takayama    1: /* $OpenXM: OpenXM/src/asir-contrib/testing/test1-tr.rr,v 1.2 2005/04/02 05:56:57 takayama Exp $ */
        !             2: /* $Id: test1-tr.rr,v 1.6 2005/04/03 11:03:01 taka Exp $ */
1.2       takayama    3:
                      4: load("tr.rr")$
                      5:
                      6:
                      7:
                      8:
                      9: def test0() {
                     10:   A = quotetolist(quote(1+sin(x)+sin(3*@pi)*sin(0)));
                     11:   P = quotetolist(quote(sin(pn("x")*@pi)));
                     12:   Q = ["qt_sin_int","x"];
                     13:   print(A);
                     14:   print(P);
                     15:   print(Q);
                     16:   print("----------------");
                     17:   print(tr_match0(A,P));
                     18:   A2 = quotetolist(quote(sin(2*@pi)));
                     19:   print(tr_match0(A2,P));
                     20:   print("----------------");
                     21:   print("---- tr_make_binding --------");
                     22:   print(tr_make_binding(A2,P));
                     23:   print("-----tr_rp -------------");
                     24:   R=tr_rp(A,P,Q);
                     25:   print("--------------------");
                     26:   print(R);
                     27:   print("--------------------");
                     28:   return quote_input_form_quote_list(R);
                     29: }
                     30:
                     31: def test1()  {
                     32:   Rule1=[quote(sin(pn("x")*@pi)),["qt_sin_int","x"]]; /* sin($B@0?t(B*@pi) --> 0 */
                     33:   Rule2=[quote(0*pn("y")),       ["qt_zero"]];       /* 0*any --> 0 */
                     34:   Rule3=[quote(pn("y")*0),       ["qt_zero"]];       /* any*0 --> 0 */
                     35:   Rule4=[quote(pn("y")+0),       ["qt_id","y"]];       /* any+0 --> any */
                     36:   Rule5=[quote(0+pn("y")),       ["qt_id","y"]];       /* 0+any --> any */
                     37:   Rule6=[quote(sin(0)),          ["qt_zero"]];       /* sin(0) --> 0 */
                     38:   R0 = quote(1+sin(sin(2*@pi)*sin(@pi/2))+sin(5*@pi));
                     39:   print(print_input_form(R0));
                     40:   R=tr_apply_rule1(R0,Rule1[0],Rule1[1]);
                     41:   print(print_input_form(R));
                     42:   R=tr_apply_rule1(R,Rule2[0],Rule2[1]);
                     43:   print(print_input_form(R));
                     44:   R=tr_apply_rule1(R,Rule4[0],Rule4[1]);
                     45:   print(print_input_form(R));
                     46:   R=tr_apply_rule1(R,Rule6[0],Rule6[1]);
                     47:   print(print_input_form(R));
                     48:   R=tr_apply_rule1(R,Rule4[0],Rule4[1]);
                     49:   print(print_input_form(R));
                     50:   return R;
                     51: }
                     52:
                     53:
                     54: /* $BITDj@QJ,7W;;$NNc(B
                     55:     c x^n $B$NOB$NITDj@QJ,(B (c $B$O(B x $B$K0MB8$;$:(B)
                     56:    $B$$$m$$$m(B $BLdBjE@$"$j(B:  $B$?$H$($P(B c $B$,(B $BL5$$$H$-$N=hM}$G$-$:(B.
                     57: */
                     58:
                     59: /* $B1&JU4X?t(B.  c x^n $B$NITDj@QJ,(B (c $B$O(B x $B$K0MB8$;$:(B)
                     60:    Todo: $B1&JU4X?t$rMF0W$K=q$/J}K!(B.
                     61: */
                     62: def r_integral0(C,N) {
                     63:   NN = eval_str(quote_input_form_quote_list(quotetolist(N)));
                     64:   CC = quote_input_form_quote_list(quotetolist(C));
                     65:   if (NN == -1) {
                     66:      R = "quote("+CC+"*log(x))";
                     67:   }else{
                     68:      R = "quote("+CC+"/"+rtostr(NN+1)+"*x^"+rtostr(NN+1)+")";
                     69:   }
                     70:   print("r_integral0:",0);print(R);
                     71:   R = eval_str(R);
                     72:   return quotetolist(R);
                     73: }
                     74: /* $B1&JU4X?t(B $B@QJ,$N@~7?@-(B */
                     75: def r_int_linear(F,G) {
                     76:   FF = quote_input_form_quote_list(quotetolist(F));
                     77:   GG = quote_input_form_quote_list(quotetolist(G));
                     78:   R = "quote(integral("+FF+")+integral("+GG+"))";
                     79:   print("r_int_linear:",0);print(R);
                     80:   R = eval_str(R);
                     81:   return quotetolist(R);
                     82: }
                     83: def test3() {
                     84:   R0 = quote(1+integral(2*x^(-1)+2*x^2));
                     85:   return test3a(R0);
                     86: }
                     87: def test3a(R0)  {
                     88:   Rules=[
                     89:      /* c*x^n --> (c/(n+1))*x^(n+1) or c*log(x) */
                     90:      [quote(integral(pn("c")*x^pn("n"))),["r_integral0","c","n"]],
                     91:      [quote(integral(pn("f")+pn("g"))),  ["r_int_linear","f","g"]]
                     92:   ];
                     93:   print("Input=",0); print(print_input_form(R0));
                     94:   N = length(Rules);
                     95:   R = R0;
                     96:   for (J=0; J<3; J++) {  /* Todo: $B%U%i%0$,$J$$$N$G(B, $B$H$j$"$($:(B 3 $B2s(B */
                     97:     for (I=0; I<N; I++) {
                     98:       print(print_input_form(R));
                     99:       R=tr_apply_rule1(R,Rules[I][0],Rules[I][1]);
                    100:     }
                    101:   }
1.3     ! takayama  102:   return R;
        !           103: }
        !           104:
        !           105:
        !           106: /* $B4X?t$N%^%C%A(B.  N[] $BAjEv(B.  test4(). */
        !           107: /*  quote(nn(pn(f),qt_is_function(f))); $B$OITMW(B. qt_map_arg $B$,=hM}(B */
        !           108: def test4() {
        !           109:   Rule=[quote(nn(pn(f))),[qt_map_arg,nn,f]];
        !           110:   R0 = quote(nn(sin(1/2)*cos(1/3)));
        !           111:   print(print_input_form(R0));
        !           112:   R=tr_apply_rule1(R0,Rule[0],Rule[1]);
        !           113:   return R;
        !           114: }
        !           115:
        !           116: /* tr_apply_or_rule $B$N;n:n(B */
        !           117:
        !           118: /* Flag $BIU$-(B $B$N(B tr_rp. $BB0@-$,$J$$$N$G$3$l$G$d$k(B. */
        !           119: def tr_rp_flag(F,P,Q) {
        !           120:   Flag = 0;
        !           121:   dprint0("tr_rp, F="); dprint(F);
        !           122:   dprint0("tr_rp, P="); dprint(P);
        !           123:   dprint0("tr_rp, Q="); dprint(Q);
        !           124:   if (tr_match0(F,P)) {
        !           125:      BindTable = tr_make_binding(F,P);
        !           126:      dprint0("BindTable="); dprint(BindTable);
        !           127:      return [1,tr_apply_function0(Q,BindTable)];
        !           128:   }
        !           129:   if (type(F) != 4) return F;
        !           130:   Node = qt_node(F);
        !           131:   N = qt_nchild(F);
        !           132:   Ans = Node;
        !           133:   for (I=0; I<N; I++) {
        !           134:     T = tr_rp_flag(qt_child(F,I),P,Q);
        !           135:     if (T[0] == 1) Flag = 1;
        !           136:     Ans = append(Ans,[T[1]]);
        !           137:   }
        !           138:   return [Flag,Ans];
        !           139: }
        !           140:
        !           141: /* $B=q$-49$((B flag $BIU$-$N(B tr_apply_rule_flag */
        !           142: def tr_apply_rule1_flag(Obj,L,R) {
        !           143:   Flag = 0;
        !           144:   dprint("--------  start of tr_apply_rule1_flag ------------ ");
        !           145:   Obj = quotetolist(Obj);
        !           146:   L = quotetolist(L);
        !           147:   R = tr_rp_flag(Obj,L,R);
        !           148:   Flag=R[0]; R=R[1];
        !           149:   if (type(R) == 17) R=quotetolist(R);
        !           150:   RR = "quote("+listtoquote_str(R)+")";
        !           151:   dprint("--------  end of tr_apply_rule1_flag ------------ ");
        !           152:   return [Flag,eval_str(RR)];
        !           153: }
        !           154:
        !           155: def tr_apply_or_rules(Q,R) {
        !           156:   Flag = 1;
        !           157:   N = length(R);
        !           158:   while (Flag) {
        !           159:    Flag = 0;
        !           160:    for (I=0; I<N; I++) {
        !           161:      Q = tr_apply_rule1_flag(Q,R[I][0],R[I][1]);
        !           162:      if (Q[0]) {
        !           163:        Flag = 1;
        !           164:        dprint("Applied the rule "+rtostr(I));
        !           165:      }
        !           166:      Q = Q[1];
        !           167:    }
        !           168:   }
        !           169:   return Q;
        !           170: }
        !           171: def test5() {
        !           172:   Rule1=[quote(sin(pn(x)*@pi)),[qt_sin_int,x]]; /* sin($B@0?t(B*@pi) --> 0 */
        !           173:   Rule2=[quote(0*pn(y)),       [qt_zero]];       /* 0*any --> 0 */
        !           174:   Rule3=[quote(pn(y)*0),       [qt_zero]];       /* any*0 --> 0 */
        !           175:   Rule4=[quote(pn(y)+0),       [qt_id,y]];       /* any+0 --> any */
        !           176:   Rule5=[quote(0+pn(y)),       [qt_id,y]];       /* 0+any --> any */
        !           177:   Rule6=[quote(sin(0)),          [qt_zero]];       /* sin(0) --> 0 */
        !           178:   R0 = quote(1+sin(sin(2*@pi)*sin(@pi/2))+sin(5*@pi));
        !           179:   print(print_input_form(R0));
        !           180:   R=tr_apply_rule1_flag(R0,Rule1[0],Rule1[1]);
        !           181:   print([R[0],print_input_form(R[1])]);
        !           182:   R=tr_apply_or_rules(R0,[Rule1,Rule2,Rule3,Rule4,Rule5,Rule6]);
1.2       takayama  183:   return R;
                    184: }
                    185:
                    186: end$

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