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

Annotation of OpenXM/src/asir-contrib/testing/tr-ja.oxt, Revision 1.3

1.1       takayama    1: /*&generate-prologue
                      2: */
1.3     ! takayama    3: $Id: tr.oxt,v 1.5 2005/04/02 05:55:37 taka Exp $
        !             4: $OpenXM: OpenXM/src/asir-contrib/testing/tr-ja.oxt,v 1.2 2005/04/01 11:34:21 takayama Exp $
1.1       takayama    5:
                      6: $BCm0U(B: testing/tr.rr $B$G$O(B quote $B$r(B quotetolist $B$G(B list $B$KJQ49$7$F07$&$?$a(B,
                      7:       $B2<$N;EMM$H$O$3$H$J$j(B, list $B7?$G%G!<%?$rLa$9>l9g$bB?$$(B.
                      8:       $B%f!<%68@8l$G=q$$$F$$$k4X78>e(B pn(x) $B$r(B pn("x") $B$H$7$F$$$k(B.
                      9:       $BB>$K$bF1MM$J4X?t$,$"$j(B.
                     10:
                     11: @c --------------------------------------------------------------------
                     12: @section quote $B$KBP$9$k4pK\4X?t(B
                     13:
                     14: /*&usage begin: qt_node(Q)
                     15:  quote $B%G!<%?(B {Q} $B$N(B node $B$r<h$j=P$9(B.
                     16:  example: qt_node(quote(1+2*3))
                     17: end: */
                     18:
                     19:
                     20: /*&usage begin: qt_nchild(Q)
                     21:  quote $B%G!<%?(B {Q} $B$N(B $B;R6!$N?t$rLa$9(B.
                     22:  example: qt_nchild(quote(1+2*3))     2 $B$rLa$9(B.
                     23: end: */
                     24:
                     25:
                     26: /*&usage begin: qt_child(Q,K)
                     27:  quote $B%G!<%?(B {Q} $B$N(B {K} $BHVL\$N;R6!$rLa$9(B.
                     28:  example: qt_child(quote(1+2*3),1)     quote(2*3) $B$rLa$9(B.
1.3     ! takayama   29:  example: qt_child(quote(1+2*3),0)     quote(1) $B$rLa$9(B.
1.1       takayama   30: end: */
                     31:
                     32: @c --------------------------------------------------------------------
                     33: @subsection quote $B$KBP$9$k=R8l(B
                     34:
                     35: /*&usage begin: qt_is_integer(Q)
                     36:  quote $B%G!<%?(B {Q} $B$,@0?t$J$i(B 1
                     37:  example: qt_is_integer(quote(0))
                     38: end: */
                     39:
                     40: /*&usage begin: qt_depend(Q,x)
                     41:  quote $B%G!<%?(B {Q} $B$,ITDj85(B {x} $B$r4^$`$H(B 1, $B4^$^$J$$$H(B 0.
                     42:  example: qt_depend(quote(1+1/x),x)
                     43: end: */
                     44:
                     45: @c --------------------------------------------------------------------
                     46: @subsection quote $B$KBP$9$k%3%s%9%H%i%/%?(B
                     47:
                     48: /*&usage begin: qt_zero()
                     49:  quote 0 $B$rLa$9(B.
                     50: end: */
                     51:
                     52: /*&usage begin: qt_id(Qobj)
                     53:  quote object {Qobj} $B$r$=$N$^$^La$9(B.
                     54: end: */
                     55:
                     56: /*&usage begin: qt_replace(Qobj,[[x,Valuex],[y,Valuey],...])
                     57:    quote object {Qobj} $B$NCf$N(B x $B$r(B Valuex, y $B$r(B Valuey, ... $B$KCV$-49$($?(B
                     58:    quote object $B$rLa$9(B.
1.3     ! takayama   59:    example: qt_replace(quote(sin(x*@pi)), [[x,quote( (2*t+3) )]])
1.1       takayama   60: end: */
                     61:
1.3     ! takayama   62:    qt_replace $B$O(B asir-contrib $B$N(B base_replace $B$H;w$?5!G=(B.
        !            63:    quote $B$NFbIt$KBgJ8;z$G$O$8$^$kJQ?t(B($BI>2A$9$k(B)$B$,=q$1$J$$$?$a(B.
        !            64:
1.1       takayama   65: /*&usage begin: qt_parenthesis(Qobj)
                     66:    quote object {Qobj} $B$NCf$N3g8L$,B-$j$J$$$H$-$K$OJd$$(B, $BB?$$$H$-$K$O<h$j5n$C$?(B
                     67:    quote object $B$r:n$k(B.
1.3     ! takayama   68:    +, *, /, ^, - $BEy$K$D$$$F(B asir $B$NJ8K!$G$N1i;;;R$N6/$5$r2>Dj$9$k(B.
1.1       takayama   69: end: */
                     70:
1.2       takayama   71: /*&usage begin: qt_eval(Qobj,type)
                     72:    Qobj $B$r(B asir $B$NB>$N(B object $B$KJQ49(B.
                     73: end: */
                     74:
                     75: /*&usage begin: qt_(Obj)
                     76:    asir $B$N(B Obj $B$r(B quote $B7?$KJQ49(B.
                     77: end: */
                     78:
1.1       takayama   79:
                     80: @c --------------------------------------------------------------------
                     81: @section tr (term rewriting) $B$N%H%C%W%l%Y%k$N4X?t(B
                     82:
                     83: /*&usage begin: tr_match0(Qobj,P)
                     84:  quote $B%G!<%?(B {Qobj} $B$,(B $B%Q%?!<%s(B {P} $B$KE,9g$9$l$P(B 1 $B$rLa$7(B, $B$=$&$G$J$1$l$P(B 0
                     85:  $B$rLa$9(B.
1.3     ! takayama   86:  example: tr_match0(quote(1+2*3),quote(pn(x)+pn(y)))
        !            87:                  x $B$K(B quote(1), y $B$K(B quote(2*3)
        !            88:           tr_match0(quote(1+2*3),quote(pn(x)+pn(y,qt_is_integer,y)))
        !            89:                  qt_is_integer(2*3) $B$O(B 0 $B$J$N$G(B y $B$K$O%^%C%A$7$J$$(B.
1.1       takayama   90: end: */
                     91:
                     92: pn(x) $B$OG$0U$N(B quote object $B$K%^%C%A$7(B, $BL>A0(B x $B$r$D$1$k(B.
                     93: tr_match0(quote(1+2*3),quote(pn(x)+pn(y)))  $B$O(B 1 $B$rLa$9$,(B,
                     94: tr_match0(quote(1+2*3),quote(pn(x)+pn(y,tr_is_integer,x))) $B$O(B 0 $B$r$b$I$9(B.
                     95: 2*3 $B$O(B integer $B$+$i:n$i$l$?(B fnode $B$G$O$"$k$,(B integer $B$G$O$J$$$N$G(B qt_is_integer
                     96: $B$,(B 0 $B$rLa$9$?$a(B.
                     97:
1.3     ! takayama   98: /*&usage begin: tr_match_act(Qobj,P,Act)
1.1       takayama   99:  quote $B%G!<%?(B {Qobj} $B$,(B $B%Q%?!<%s(B {P} $B$KE,9g$9$l$P(B {Act} $B$r8F$S=P$7$=$NCM$rLa$9(B.
                    100:  $B%Q%?!<%s(B {P} $B$K%^%C%A$7$J$$$H$-$O(B 0.
                    101:
1.3     ! takayama  102:  example: tr_match_act(quote(1+2*3),quote(pn(x)+pn(y)),[myadd,x,y])
1.1       takayama  103: end: */
                    104:
                    105: /*&usage begin: tr_or_match1(Qobj,Rules)
                    106: end: */
                    107:
                    108: /*&usage begin: tr_apply_rule1(Qobj,P,Act)
                    109:  quote $B%G!<%?(B {Qobj} $B$NLZ$rI}M%@hC5:w$7(B,
                    110:  $B%Q%?!<%s(B {P} $B$KE,9g$9$k$b$N$,$"$k$H$-$O(B {Act} $B$r8F$S=P$7$=$NCM$rLa$9(B.
                    111:  $B$D$^$j(B top node $B$,(B {P} $B$KE,9g$9$k$+D4$Y(B, $BE,9g$7$J$$>l9g$O$=$N;R6!$K(B
1.3     ! takayama  112:   tr_apply_rule1 $B$rE,MQ$9$k(B ($B$3$3$,(B tr_match_act $B$H$O0[$J$k(B).
1.1       takayama  113:  $B%^%C%A$7$J$$>l9g$O(B Qobj $B$r$=$N$^$^La$9(B ($B$3$l$,:F5"E*$KE,MQ$5$l$k(B).
                    114:
                    115:  example: tr_apply_rule1(quote(1+sin(2*@pi)),quote(sin(pn(x)*@pi)),[sin_int,x])
                    116: end: */
                    117:
1.3     ! takayama  118:  $B$3$3$G(B sin_int(X) $B$O(B X $B$,(B integer $B$N;~$O(B quote(0) $B$rLa$7(B,
        !           119:  $B$=$&$G$J$$$H$-$O(B quote(sin(X*@pi)) $B$rLa$9(B.
1.1       takayama  120:  $B?<$5M%@h$G=q$-49$($r$9$k$K$O(B $B4X?t(B sin_int $B$NCf$G$^$?(B tr_apply_rule1 $B$r8F$S=P$;$P(B
                    121:  $B$h$$(B.
                    122:
                    123: /*&usage begin: tr_apply_or_rules(Qobj,Rules)
                    124: end: */
                    125:
1.2       takayama  126: @subsection $BFbIt4X?t(B
                    127:
1.3     ! takayama  128: /*&usage begin: tr_apply_function0(Qobj,BindingTable)
1.2       takayama  129: end: */
                    130:
                    131: /*&usage begin: tr_rp(Qobj,P,A)
                    132: end: */
                    133:
                    134: /*&usage begin: tr_make_binding(Qobj,P)
                    135: end: */
                    136:
1.1       takayama  137: @c ---------------------------------------------------------
                    138: @section $BJQ?t%Q%?!<%s$H4X?t%Q%?!<%s(B
                    139:
                    140: $BNc(B:
1.2       takayama  141: pn(x)                    $BG$0U$N$b$N$K%^%C%A(B. $B%^%C%A$7$?$b$N$r(B x $B$K(B bind.
1.1       takayama  142: pn(x,qt_is_integer(x))
1.2       takayama  143: fn(f)                    $BG$0U$N4X?t$K%^%C%A(B. $B%^%C%A$7$?4X?tL>$r(B f $B$K(B bind.
                    144: fn(f,pn(x),pn(y))        $BG$0U$N4X?t$K%^%C%A(B. $B%^%C%A$7$?4X?tL>$r(B f $B$K(B bind.
                    145:                          f $B$N0z?t$r(B x, y $B$K(B bind
1.1       takayama  146:
                    147: @c ---------------------------------------------------------
                    148: @section $B%Q%?!<%s(B
                    149:
                    150: $B%Q%?!<%s$O(B quote $B$GM?$($k(B.
                    151: $BM=Ls8l(B  tr_and, tr_or, tr_not  $B$O%Q%?!<%s$N%^%C%A$K4X$7$FO@M}1i;;$r$*$3$J$&(B.
                    152: $B$?$H$($P(B
1.3     ! takayama  153: quote(tr_and(pn(x,qt_is_integer),pn(x,qt_is_non_negative(x))))
1.1       takayama  154: $B$O(B x $B$,(B $B@0?t$G(B - $B$,@hF,$K$D$$$F$$$J$$>l9g%^%C%A$9$k(B.
                    155:
                    156: @c ---------------------------------------------------------
                    157: @section $BNcBj(B  sin($B@0?t(B*@pi) $B$r(B 0 $B$K(B.
                    158:
1.2       takayama  159:    /* $B=`Hw(B */
                    160:    extern P,A;
                    161:    P=quote(sin(pn(x)*@pi));  /* $B%Q%?!<%s(B */
                    162:    A=[sin_int,x]             /* action, action $B4X?t(B */
                    163:    def sin_int(X) {
                    164:      X = tr_apply_rule1(X,P,A); /* $B;R6!$K(B [P,A] $B$r:F5"E*$KE,MQ(B */
                    165:      if (qt_is_integer(X)) return qt_zero();
                    166:      else qt_replace(sin(y*@pi),[[y,X]]);  /* sin(x*@pi) $B$r$=$N$^$^La$9(B.*/
                    167:    }
                    168:
                    169:    /* $B7W;;(B */
                    170:    Qobj=quote(1+sin(sin(2*@pi)*@pi)*sin((1/2)*@pi));
                    171:    tr_apply_rule1(Qobj,P,A);
                    172:
1.1       takayama  173:
                    174: @c ---------------------------------------------------------
                    175: @section $BNcBj(B  $BITDj@QJ,(B
                    176:
1.2       takayama  177:    /* integral(f+g) => integral(f)+integral(g) */
                    178:    S1=[quote(integral(pn(f)+pn(g))),
                    179:        [int_linear1,f,g]];
                    180:    def int_linear1(X,Y) {
                    181:       return qt_replace(quote(integral(f)+integral(g)),[[f,X],[g,Y]]);
                    182:    }
                    183:
                    184:    /* integral(c*f) => c*integral(f) */
                    185:    def qt_independent(F,X) { return !qt_dependent(F,X); }
                    186:    S2=[quote(integral(pn(c,qt_independent(c,x))*f)),
                    187:        [int_linear2,c,f]];
                    188:    def int_linear2(X,Y) {
                    189:       return qt_replace(quote(c*integral(f)),[[c,X],[f,Y]]);
                    190:    }
                    191:
                    192:    apply_or_rules(quote(integral(a*x^2+x+2/x)),[S1,S2]);
                    193:    $B$3$l$r$3$l0J>e=q$-49$($,5/$-$J$$$^$G7+$jJV$9(B.
                    194:    $B$3$N%k!<%k$N>l9gEz$($O(B
                    195:    a*integral(x^2)+integral(x)+integral(2/x);
                    196:
                    197:    quote(integral(x^pn(n))) --> x^(n+1)/(n+1) or log(x) $B$r=q$/(B.
                    198:
1.1       takayama  199: @c ---------------------------------------------------------
                    200: @section $BNcBj(B  $B4JC1$J9=J82r@O(B
                    201:
1.2       takayama  202:    $B<0(B(expression) $B$O(B $B<0(B+$B<0(B | $B<0(B*$B<0(B | ($B<0(B) | $B@0?t(B
                    203:
                    204:    extern R1,R2,R3,R4,S1,S2,S3,S4;
                    205:    /* $BJ8K!$rK~$?$9$+$I$&$+$N(B check $BMQ(B. Action $BIt$O(B 1 $B$+(B 0 */
                    206:    R1=[quote(pn(x,is_expression(x))+pn(y,is_expression(y))), 1];
                    207:    R2=[quote(pn(x,is_expression(x))*pn(y,is_expression(y))), 1];
                    208:    R3=[quote((pn(x,is_expression(x)))), 1];
                    209:    R4=[quote(pn(x,qt_is_integer(x))), 1];
                    210:    def is_expression(Qobj) {
                    211:      R = [R1,R2,R3,R4];
                    212:      A = apply_or_match0(Qobj,R);
                    213:      if (A == 0) return 0; else return 1;
                    214:    }
                    215:
                    216:    /* $B7W;;MQ(B. R1,R2,R3,R4 $B$H:8$O6&DL(B. */
                    217:    S1=[quote(pn(x,is_expression(x))+pn(y,is_expression(y))), [myadd,x,y]];
                    218:    S2=[quote(pn(x,is_expression(x))*pn(y,is_expression(y))), [mymul,x,y]];
                    219:    S3=[quote((pn(x,is_expression(x)))), [qt_id,x]];
                    220:    S4=[quote(pn(x,qt_is_integer(x))), [qt_id,x]];
                    221:
                    222:    def eval_expression(Qobj) {
                    223:      S = [S1,S2,S3,S4];
                    224:      return apply_or_rules(Qobj,S);
                    225:    }
                    226:
                    227:    def myadd(X,Y) {
                    228:      return qt_(qt_eval(X,1)+qt_eval(Y,1));
                    229:    }
                    230:
                    231:    def mymul(X,Y) {
                    232:      return qt_(qt_eval(X,1)*qt_eval(Y,1));
                    233:    }
                    234:
                    235:    /* $B7W;;(B */
                    236:    tr_eval_expression(quote(1+2*(3+15)));
1.1       takayama  237:
                    238: @c ---------------------------------------------------------
                    239: @section $BNcBj(B  $BHs2D494D$N4JC1$J9=J82r@O(B
                    240:
                    241:
                    242:
1.3     ! takayama  243: @section  Todo:
        !           244:  $BNc(B. Mathematica $B$N(B N[ ] $BAjEv$N4X?t$r%f!<%6$,=q$1$k$h$&$K(B.
        !           245:     nn(sin(cos(@pi)+sqrt(2)))
        !           246:     --> nn(sin(nn(cos(nn(@pi)))+nn(sqrt(nn(2)))))
        !           247:     $BG$0U4X?t$H$N(B match.
        !           248:
        !           249:  $BNc(B: $BQQ5i?t$N7W;;$r(B quote $B$G<B8=(B.
        !           250:         sort $B$d(B expand $B$OAH$_9~$_$G(B.
        !           251:
        !           252:  $BNc(B: Mathematica $B$N(B Expand[], Toghether[] $BAjEv$N$b$N(B.
        !           253:
        !           254:  $BNc(B: D $B$N3]$1;;$r(B $B%Q%?!<%s%^%C%A$G<B8=(B.
        !           255:
        !           256:  $BNc(B: (x^(1/n))^n --> x $BEy(B.
        !           257:
        !           258:  $BNc(B: $B5-9fHyJ,$HHyJ,4D$G$N7W;;(B.
        !           259:        y''+xy=0,  y''=y^2+x $BEy(B.
        !           260:
        !           261:  $BNc(B: QE, $BO@M}<0(B.
        !           262:
        !           263: @section $B9M$(J}$K$D$$$F$N35@b(B
        !           264:
        !           265:  $B%H%C%W%l%Y%k$N4X?tC#(B.  (stylesheet $B$N9M$($K;w$F$k(B.)
        !           266:   iterator $B$N0l<o(B.
        !           267:
        !           268: @c ------------------------------------------------
        !           269: @section   $B$^$@%9%1%C%A$N$_$N4X?t;EMM(B
        !           270:
        !           271:   qt_ltor, qt_rtol : $BLZ$N9=B$$NJQ49(B; $BNc(B (x*y)*z --> x*(y*z)
        !           272:
        !           273:   idxtov(x,i)  x_i $B$r@8@.(B.  x_i $B$N(B index (idx) $BB0@-(B $B$r(B i $B$K(B.
        !           274:                                     base_name $BB0@-$r(B  x $B$K(B.
        !           275:   idxtov(x,[i,j])  x_i_j $B$r@8@.(B.  x_i_i $B$N(B index (idx) $BB0@-(B $B$r(B [i,j] $B$K(B.
        !           276:   vtoidx(x_i) $B$O(B i $B$rLa$9(B. $BB0@-$N8!:w$J$N$G9bB.(B. idx $BB0@-$,L5$$>l9g$O(B i $B$r@_Dj(B.
        !           277:
        !           278:   idxtov $B4X?t$O(B $B4X?tL>$K$b;H$($k$h$&$K$9$k(B --> $BHyJ,4DBP1~(B.
        !           279:
        !           280:   qt_function($BL>A0(B, $B0z?t(B) --> quote($BL>A0(B($B0z?t(B)) $B$r@8@.(B.
        !           281:    index $BIU$-4X?t$OHyJ,4D$N<h07$KI,MW(B.
        !           282:
        !           283:   $B6R5i?t$N<h07(B, dp $B$N(B pretty print $B$N$?$a(B.
        !           284:   qt_qttodp(Qobj | vlist,  order?)  quote $B$+$i(B dp $B$r:n$k(B.
        !           285:        exponent $B$,?t$G$J$$$H:n$l$:(B.
        !           286:   qt_dptoqt(Qobj | vlist)  dp $B$+$i(B quote $B$r:n$k(B.  vlist $B$OB0@-$GBP1~(B?
1.1       takayama  287:
1.3     ! takayama  288:   qt_expand, qt_sort, qt_ht, qt_rest, qt_mtov $B$b4pAC4X?t$H$7$FM_$7$$(B.
1.1       takayama  289:
                    290: /*&generate-epilogue
                    291: */

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