[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.2

1.1       takayama    1: /*&generate-prologue
                      2: */
1.2     ! takayama    3: $Id: tr.oxt,v 1.3 2005/04/01 11:33:16 taka Exp $
        !             4: $OpenXM: OpenXM/src/asir-contrib/testing/tr-ja.oxt,v 1.1 2005/04/01 08:08:36 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.
                     29: end: */
                     30:
                     31: @c --------------------------------------------------------------------
                     32: @subsection quote $B$KBP$9$k=R8l(B
                     33:
                     34: /*&usage begin: qt_is_integer(Q)
                     35:  quote $B%G!<%?(B {Q} $B$,@0?t$J$i(B 1
                     36:  example: qt_is_integer(quote(0))
                     37: end: */
                     38:
                     39: /*&usage begin: qt_depend(Q,x)
                     40:  quote $B%G!<%?(B {Q} $B$,ITDj85(B {x} $B$r4^$`$H(B 1, $B4^$^$J$$$H(B 0.
                     41:  example: qt_depend(quote(1+1/x),x)
                     42: end: */
                     43:
                     44: @c --------------------------------------------------------------------
                     45: @subsection quote $B$KBP$9$k%3%s%9%H%i%/%?(B
                     46:
                     47: /*&usage begin: qt_zero()
                     48:  quote 0 $B$rLa$9(B.
                     49: end: */
                     50:
                     51: /*&usage begin: qt_id(Qobj)
                     52:  quote object {Qobj} $B$r$=$N$^$^La$9(B.
                     53: end: */
                     54:
                     55: /*&usage begin: qt_replace(Qobj,[[x,Valuex],[y,Valuey],...])
                     56:    quote object {Qobj} $B$NCf$N(B x $B$r(B Valuex, y $B$r(B Valuey, ... $B$KCV$-49$($?(B
                     57:    quote object $B$rLa$9(B.
                     58: end: */
                     59:
                     60: /*&usage begin: qt_parenthesis(Qobj)
                     61:    quote object {Qobj} $B$NCf$N3g8L$,B-$j$J$$$H$-$K$OJd$$(B, $BB?$$$H$-$K$O<h$j5n$C$?(B
                     62:    quote object $B$r:n$k(B.
                     63:    +, *, /, ^, - $BEy$K$D$$$F$N(B asir $B$NJ8K!$G$N1i;;;R$N6/$5$r2>Dj$9$k(B.
                     64: end: */
                     65:
1.2     ! takayama   66: /*&usage begin: qt_eval(Qobj,type)
        !            67:    Qobj $B$r(B asir $B$NB>$N(B object $B$KJQ49(B.
        !            68: end: */
        !            69:
        !            70: /*&usage begin: qt_(Obj)
        !            71:    asir $B$N(B Obj $B$r(B quote $B7?$KJQ49(B.
        !            72: end: */
        !            73:
        !            74: $B$=$NB>(B qt_expand, qt_sort, qt_ht, qt_rest, qt_mtov $B$b4pAC4X?t$H$7$FM_$7$$(B.
1.1       takayama   75:
                     76: @c --------------------------------------------------------------------
                     77: @section tr (term rewriting) $B$N%H%C%W%l%Y%k$N4X?t(B
                     78:
                     79: /*&usage begin: tr_match0(Qobj,P)
                     80:  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
                     81:  $B$rLa$9(B.
                     82:  example: tr_match0(quote(1+2*3),quote(pn(x)+pn(y)))
                     83:           tr_match0(quote(1+2*3),quote(pn(x)+pn(y,qt_is_integer,x)))
                     84: end: */
                     85:
                     86: 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.
                     87: tr_match0(quote(1+2*3),quote(pn(x)+pn(y)))  $B$O(B 1 $B$rLa$9$,(B,
                     88: 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.
                     89: 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
                     90: $B$,(B 0 $B$rLa$9$?$a(B.
                     91:
                     92: /*&usage begin: tr_match1(Qobj,P,Act)
                     93:  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.
                     94:  $B%Q%?!<%s(B {P} $B$K%^%C%A$7$J$$$H$-$O(B 0.
                     95:
                     96:  example: tr_match1(quote(1+2*3),quote(pn(x)+pn(y)),[myadd,x,y])
                     97: end: */
                     98:
                     99: /*&usage begin: tr_or_match1(Qobj,Rules)
                    100: end: */
                    101:
                    102: /*&usage begin: tr_apply_rule1(Qobj,P,Act)
                    103:  quote $B%G!<%?(B {Qobj} $B$NLZ$rI}M%@hC5:w$7(B,
                    104:  $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.
                    105:  $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
                    106:   tr_apply_rule1 $B$rE,MQ$9$k(B ($B$3$3$,(B tr_match1 $B$H$O0[$J$k(B).
                    107:  $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).
                    108:
                    109:  example: tr_apply_rule1(quote(1+sin(2*@pi)),quote(sin(pn(x)*@pi)),[sin_int,x])
                    110: end: */
                    111:
                    112:  $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
                    113:  $B$h$$(B.
                    114:
                    115: /*&usage begin: tr_apply_or_rules(Qobj,Rules)
                    116: end: */
                    117:
1.2     ! takayama  118: @subsection $BFbIt4X?t(B
        !           119:
        !           120: /*&usage begin: tr_apply_function0(Qobj,Arg1,...)
        !           121: end: */
        !           122:
        !           123: /*&usage begin: tr_rp(Qobj,P,A)
        !           124: end: */
        !           125:
        !           126: /*&usage begin: tr_make_binding(Qobj,P)
        !           127: end: */
        !           128:
1.1       takayama  129: @c ---------------------------------------------------------
                    130: @section $BJQ?t%Q%?!<%s$H4X?t%Q%?!<%s(B
                    131:
                    132: $BNc(B:
1.2     ! takayama  133: 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  134: pn(x,qt_is_integer(x))
1.2     ! takayama  135: fn(f)                    $BG$0U$N4X?t$K%^%C%A(B. $B%^%C%A$7$?4X?tL>$r(B f $B$K(B bind.
        !           136: 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.
        !           137:                          f $B$N0z?t$r(B x, y $B$K(B bind
1.1       takayama  138:
                    139: @c ---------------------------------------------------------
                    140: @section $B%Q%?!<%s(B
                    141:
                    142: $B%Q%?!<%s$O(B quote $B$GM?$($k(B.
                    143: $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.
                    144: $B$?$H$($P(B
                    145: quote(tr_and(pn(x,qt_is_integer),pn(x,qt_is_non_negative)))
                    146: $B$O(B x $B$,(B $B@0?t$G(B - $B$,@hF,$K$D$$$F$$$J$$>l9g%^%C%A$9$k(B.
                    147:
                    148: @c ---------------------------------------------------------
                    149: @section $BNcBj(B  sin($B@0?t(B*@pi) $B$r(B 0 $B$K(B.
                    150:
1.2     ! takayama  151:    /* $B=`Hw(B */
        !           152:    extern P,A;
        !           153:    P=quote(sin(pn(x)*@pi));  /* $B%Q%?!<%s(B */
        !           154:    A=[sin_int,x]             /* action, action $B4X?t(B */
        !           155:    def sin_int(X) {
        !           156:      X = tr_apply_rule1(X,P,A); /* $B;R6!$K(B [P,A] $B$r:F5"E*$KE,MQ(B */
        !           157:      if (qt_is_integer(X)) return qt_zero();
        !           158:      else qt_replace(sin(y*@pi),[[y,X]]);  /* sin(x*@pi) $B$r$=$N$^$^La$9(B.*/
        !           159:    }
        !           160:
        !           161:    /* $B7W;;(B */
        !           162:    Qobj=quote(1+sin(sin(2*@pi)*@pi)*sin((1/2)*@pi));
        !           163:    tr_apply_rule1(Qobj,P,A);
        !           164:
1.1       takayama  165:
                    166: @c ---------------------------------------------------------
                    167: @section $BNcBj(B  $BITDj@QJ,(B
                    168:
1.2     ! takayama  169:    /* integral(f+g) => integral(f)+integral(g) */
        !           170:    S1=[quote(integral(pn(f)+pn(g))),
        !           171:        [int_linear1,f,g]];
        !           172:    def int_linear1(X,Y) {
        !           173:       return qt_replace(quote(integral(f)+integral(g)),[[f,X],[g,Y]]);
        !           174:    }
        !           175:
        !           176:    /* integral(c*f) => c*integral(f) */
        !           177:    def qt_independent(F,X) { return !qt_dependent(F,X); }
        !           178:    S2=[quote(integral(pn(c,qt_independent(c,x))*f)),
        !           179:        [int_linear2,c,f]];
        !           180:    def int_linear2(X,Y) {
        !           181:       return qt_replace(quote(c*integral(f)),[[c,X],[f,Y]]);
        !           182:    }
        !           183:
        !           184:    apply_or_rules(quote(integral(a*x^2+x+2/x)),[S1,S2]);
        !           185:    $B$3$l$r$3$l0J>e=q$-49$($,5/$-$J$$$^$G7+$jJV$9(B.
        !           186:    $B$3$N%k!<%k$N>l9gEz$($O(B
        !           187:    a*integral(x^2)+integral(x)+integral(2/x);
        !           188:
        !           189:    quote(integral(x^pn(n))) --> x^(n+1)/(n+1) or log(x) $B$r=q$/(B.
        !           190:
1.1       takayama  191: @c ---------------------------------------------------------
                    192: @section $BNcBj(B  $B4JC1$J9=J82r@O(B
                    193:
1.2     ! takayama  194:    $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
        !           195:
        !           196:    extern R1,R2,R3,R4,S1,S2,S3,S4;
        !           197:    /* $BJ8K!$rK~$?$9$+$I$&$+$N(B check $BMQ(B. Action $BIt$O(B 1 $B$+(B 0 */
        !           198:    R1=[quote(pn(x,is_expression(x))+pn(y,is_expression(y))), 1];
        !           199:    R2=[quote(pn(x,is_expression(x))*pn(y,is_expression(y))), 1];
        !           200:    R3=[quote((pn(x,is_expression(x)))), 1];
        !           201:    R4=[quote(pn(x,qt_is_integer(x))), 1];
        !           202:    def is_expression(Qobj) {
        !           203:      R = [R1,R2,R3,R4];
        !           204:      A = apply_or_match0(Qobj,R);
        !           205:      if (A == 0) return 0; else return 1;
        !           206:    }
        !           207:
        !           208:    /* $B7W;;MQ(B. R1,R2,R3,R4 $B$H:8$O6&DL(B. */
        !           209:    S1=[quote(pn(x,is_expression(x))+pn(y,is_expression(y))), [myadd,x,y]];
        !           210:    S2=[quote(pn(x,is_expression(x))*pn(y,is_expression(y))), [mymul,x,y]];
        !           211:    S3=[quote((pn(x,is_expression(x)))), [qt_id,x]];
        !           212:    S4=[quote(pn(x,qt_is_integer(x))), [qt_id,x]];
        !           213:
        !           214:    def eval_expression(Qobj) {
        !           215:      S = [S1,S2,S3,S4];
        !           216:      return apply_or_rules(Qobj,S);
        !           217:    }
        !           218:
        !           219:    def myadd(X,Y) {
        !           220:      return qt_(qt_eval(X,1)+qt_eval(Y,1));
        !           221:    }
        !           222:
        !           223:    def mymul(X,Y) {
        !           224:      return qt_(qt_eval(X,1)*qt_eval(Y,1));
        !           225:    }
        !           226:
        !           227:    /* $B7W;;(B */
        !           228:    tr_eval_expression(quote(1+2*(3+15)));
1.1       takayama  229:
                    230: @c ---------------------------------------------------------
                    231: @section $BNcBj(B  $BHs2D494D$N4JC1$J9=J82r@O(B
                    232:
                    233:
                    234:
                    235:
                    236:
                    237: /*&generate-epilogue
                    238: */

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