Annotation of OpenXM/src/asir-contrib/testing/tr-ja.oxt, Revision 1.4
1.1 takayama 1: /*&generate-prologue
2: */
1.4 ! takayama 3: $Id: tr.oxt,v 1.12 2005/04/03 02:10:11 taka Exp $
! 4: $OpenXM: OpenXM/src/asir-contrib/testing/tr-ja.oxt,v 1.3 2005/04/02 05:56:57 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:
1.4 ! takayama 11: gentexi <tr.oxt >t.texi
! 12: t.texi $B$K(B
! 13: \input texinfo
! 14: @def@pi{PI}
! 15: $B$r2C$($F$+$i(B ptex t.texi $B$G(B $BBgBN8+$l$k$,(B,
! 16:
! 17: cat pre.texi >t.texi
! 18: ${OpenXM_HOME}/asir-contrib/packages/doc/gentexi tr.oxt >>t.texi
! 19: echo "@bye" >>t.texi
! 20: ptex t.texi
! 21: $B$H$9$l$P$b$C$H%^%K%e%"%k$C$]$$$b$N$,$G$-$k(B.
! 22:
1.1 takayama 23: @c --------------------------------------------------------------------
24: @section quote $B$KBP$9$k4pK\4X?t(B
25:
1.4 ! takayama 26: begin: qt_node(Q)
1.1 takayama 27: quote $B%G!<%?(B {Q} $B$N(B node $B$r<h$j=P$9(B.
28: example: qt_node(quote(1+2*3))
1.4 ! takayama 29: end:
1.1 takayama 30:
31:
1.4 ! takayama 32: begin: qt_nchild(Q)
1.1 takayama 33: quote $B%G!<%?(B {Q} $B$N(B $B;R6!$N?t$rLa$9(B.
34: example: qt_nchild(quote(1+2*3)) 2 $B$rLa$9(B.
1.4 ! takayama 35: end:
1.1 takayama 36:
37:
1.4 ! takayama 38: begin: qt_child(Q,K)
1.1 takayama 39: quote $B%G!<%?(B {Q} $B$N(B {K} $BHVL\$N;R6!$rLa$9(B.
40: example: qt_child(quote(1+2*3),1) quote(2*3) $B$rLa$9(B.
1.3 takayama 41: example: qt_child(quote(1+2*3),0) quote(1) $B$rLa$9(B.
1.4 ! takayama 42: end:
1.1 takayama 43:
44: @c --------------------------------------------------------------------
45: @subsection quote $B$KBP$9$k=R8l(B
46:
1.4 ! takayama 47: begin: qt_is_integer(Q)
1.1 takayama 48: quote $B%G!<%?(B {Q} $B$,@0?t$J$i(B 1
49: example: qt_is_integer(quote(0))
1.4 ! takayama 50: end:
1.1 takayama 51:
1.4 ! takayama 52: begin: qt_depend(Q,x)
1.1 takayama 53: quote $B%G!<%?(B {Q} $B$,ITDj85(B {x} $B$r4^$`$H(B 1, $B4^$^$J$$$H(B 0.
54: example: qt_depend(quote(1+1/x),x)
1.4 ! takayama 55: end:
! 56:
! 57: begin: qt_is_function(Q)
! 58: quote $B%G!<%?(B {Q} $B$,4X?t$N$H$-(B 1, $B$=$&$G$J$$$H$-(B 0.
! 59: example: qt_is_function(f(x,y));
! 60: end:
1.1 takayama 61:
62: @c --------------------------------------------------------------------
63: @subsection quote $B$KBP$9$k%3%s%9%H%i%/%?(B
64:
1.4 ! takayama 65: begin: qt_zero()
1.1 takayama 66: quote 0 $B$rLa$9(B.
1.4 ! takayama 67: end:
1.1 takayama 68:
1.4 ! takayama 69: begin: qt_id(Qobj)
1.1 takayama 70: quote object {Qobj} $B$r$=$N$^$^La$9(B.
1.4 ! takayama 71: end:
1.1 takayama 72:
1.4 ! takayama 73: begin: qt_replace(Qobj,[[x,Valuex],[y,Valuey],...])
1.1 takayama 74: quote object {Qobj} $B$NCf$N(B x $B$r(B Valuex, y $B$r(B Valuey, ... $B$KCV$-49$($?(B
75: quote object $B$rLa$9(B.
1.3 takayama 76: example: qt_replace(quote(sin(x*@pi)), [[x,quote( (2*t+3) )]])
1.4 ! takayama 77: end:
1.1 takayama 78:
1.3 takayama 79: qt_replace $B$O(B asir-contrib $B$N(B base_replace $B$H;w$?5!G=(B.
80: quote $B$NFbIt$KBgJ8;z$G$O$8$^$kJQ?t(B($BI>2A$9$k(B)$B$,=q$1$J$$$?$a(B.
81:
1.4 ! takayama 82: begin: qt_parenthesis(Qobj)
1.1 takayama 83: quote object {Qobj} $B$NCf$N3g8L$,B-$j$J$$$H$-$K$OJd$$(B, $BB?$$$H$-$K$O<h$j5n$C$?(B
84: quote object $B$r:n$k(B.
1.3 takayama 85: +, *, /, ^, - $BEy$K$D$$$F(B asir $B$NJ8K!$G$N1i;;;R$N6/$5$r2>Dj$9$k(B.
1.4 ! takayama 86: end:
1.1 takayama 87:
1.4 ! takayama 88: begin: qt_eval(Qobj,type)
1.2 takayama 89: Qobj $B$r(B asir $B$NB>$N(B object $B$KJQ49(B.
1.4 ! takayama 90: end:
1.2 takayama 91:
1.4 ! takayama 92: begin: qt_(Obj)
1.2 takayama 93: asir $B$N(B Obj $B$r(B quote $B7?$KJQ49(B.
1.4 ! takayama 94: end:
1.2 takayama 95:
1.1 takayama 96:
97: @c --------------------------------------------------------------------
98: @section tr (term rewriting) $B$N%H%C%W%l%Y%k$N4X?t(B
99:
1.4 ! takayama 100: begin: tr_match0(Qobj,P)
1.1 takayama 101: 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
102: $B$rLa$9(B.
1.3 takayama 103: example: tr_match0(quote(1+2*3),quote(pn(x)+pn(y)))
104: x $B$K(B quote(1), y $B$K(B quote(2*3)
105: tr_match0(quote(1+2*3),quote(pn(x)+pn(y,qt_is_integer,y)))
106: qt_is_integer(2*3) $B$O(B 0 $B$J$N$G(B y $B$K$O%^%C%A$7$J$$(B.
1.4 ! takayama 107: end:
1.1 takayama 108:
1.4 ! takayama 109: begin: pn(X)
! 110: 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.
! 111: description:
! 112: tr_match0(quote(1+2*3),quote(pn(x)+pn(y))) $B$O(B 1 $B$rLa$9$,(B,
! 113: 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.
! 114: 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
! 115: $B$,(B 0 $B$rLa$9$?$a(B.
! 116: end:
1.1 takayama 117:
1.4 ! takayama 118: begin: tr_match0_act(Qobj,P,Act)
1.1 takayama 119: 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.
120: $B%Q%?!<%s(B {P} $B$K%^%C%A$7$J$$$H$-$O(B 0.
121:
1.4 ! takayama 122: example: tr_match0_act(quote(1+2*3),quote(pn(x)+pn(y)),[myadd,x,y])
! 123: end:
1.1 takayama 124:
1.4 ! takayama 125: begin: tr_or_match0_act(Qobj,Rules)
! 126: end:
1.1 takayama 127:
1.4 ! takayama 128: begin: tr_apply_rule1(Qobj,P,Act)
1.1 takayama 129: quote $B%G!<%?(B {Qobj} $B$NLZ$rI}M%@hC5:w$7(B,
130: $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.
131: $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 132: 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 133: $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).
134:
1.4 ! takayama 135: description:
1.3 takayama 136: $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,
137: $B$=$&$G$J$$$H$-$O(B quote(sin(X*@pi)) $B$rLa$9(B.
1.1 takayama 138: $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
139: $B$h$$(B.
140:
1.4 ! takayama 141: example: tr_apply_rule1(quote(1+sin(2*@pi)),quote(sin(pn(x)*@pi)),[sin_int,x])
! 142: end:
! 143:
! 144:
! 145: begin: tr_apply_or_rules(Qobj,Rules)
! 146: end:
1.1 takayama 147:
1.2 takayama 148: @subsection $BFbIt4X?t(B
149:
1.4 ! takayama 150: begin: tr_apply_function0(Qobj,BindingTable)
! 151: end:
1.2 takayama 152:
1.4 ! takayama 153: begin: tr_rp(Qobj,P,A)
! 154: end:
1.2 takayama 155:
1.4 ! takayama 156: begin: tr_make_binding(Qobj,P)
! 157: end:
1.2 takayama 158:
1.1 takayama 159: @c ---------------------------------------------------------
160: @section $BJQ?t%Q%?!<%s$H4X?t%Q%?!<%s(B
161:
1.4 ! takayama 162: begin: remark_on_pn()
! 163: $BJQ?t%Q%?!<%s(B
! 164: example:
1.2 takayama 165: 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 166: pn(x,qt_is_integer(x))
1.4 ! takayama 167:
! 168: Todo; fn $B$OB?J,$$$i$J$$(B. qt_is_function(x) $B$G(B OK.
1.2 takayama 169: fn(f) $BG$0U$N4X?t$K%^%C%A(B. $B%^%C%A$7$?4X?tL>$r(B f $B$K(B bind.
170: 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.
171: f $B$N0z?t$r(B x, y $B$K(B bind
1.4 ! takayama 172: end:
1.1 takayama 173:
174: @c ---------------------------------------------------------
175: @section $B%Q%?!<%s(B
176:
1.4 ! takayama 177: begin: remark_pattern()
1.1 takayama 178: $B%Q%?!<%s$O(B quote $B$GM?$($k(B.
179: $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.
180: $B$?$H$($P(B
1.3 takayama 181: quote(tr_and(pn(x,qt_is_integer),pn(x,qt_is_non_negative(x))))
1.1 takayama 182: $B$O(B x $B$,(B $B@0?t$G(B - $B$,@hF,$K$D$$$F$$$J$$>l9g%^%C%A$9$k(B.
1.4 ! takayama 183: end:
1.1 takayama 184:
185: @c ---------------------------------------------------------
186: @section $BNcBj(B sin($B@0?t(B*@pi) $B$r(B 0 $B$K(B.
187:
1.4 ! takayama 188: begin: example_sin_int();
! 189: $BNcBj(B sin($B@0?t(B*@pi) $B$r(B 0 $B$K(B.
! 190: example:
1.2 takayama 191: /* $B=`Hw(B */
192: extern P,A;
193: P=quote(sin(pn(x)*@pi)); /* $B%Q%?!<%s(B */
194: A=[sin_int,x] /* action, action $B4X?t(B */
195: def sin_int(X) {
196: X = tr_apply_rule1(X,P,A); /* $B;R6!$K(B [P,A] $B$r:F5"E*$KE,MQ(B */
197: if (qt_is_integer(X)) return qt_zero();
198: else qt_replace(sin(y*@pi),[[y,X]]); /* sin(x*@pi) $B$r$=$N$^$^La$9(B.*/
199: }
200:
201: /* $B7W;;(B */
202: Qobj=quote(1+sin(sin(2*@pi)*@pi)*sin((1/2)*@pi));
203: tr_apply_rule1(Qobj,P,A);
1.4 ! takayama 204: end:
1.2 takayama 205:
1.4 ! takayama 206: @c ------------------------------------------------------
! 207: @section $BNcBj(B Mathematica $B$N(B N[ ] $BAjEv$N4X?t$r%f!<%6$,=q$1$k$h$&$K(B.
! 208:
! 209: begin: example_Mathematica_N()
! 210: $BNcBj(B Mathematica $B$N(B N[ ] $BAjEv$N4X?t$r%f!<%6$,=q$1$k$h$&$K(B.
! 211: example:
! 212: nn(sin(cos(@pi)+sqrt(2)))
! 213: --> nn(sin(nn(cos(nn(@pi)))+nn(sqrt(nn(2)))))
! 214: Prog; test1-tr.rr $B$N(B test4().
! 215:
! 216: qt_map_arg $B4X?t$rMQ$$$k(B.
! 217: def test4() {
! 218: Rule=[quote(nn(pn(f))),[qt_map_arg,nn,f]];
! 219: /* nn $B$G0O$^$l$?$b$N$,$"$l$P(B, nn $B$r$=$NFbIt$K:F5"E*$K(B apply $B$9$k(B */
! 220: R0 = quote(nn(sin(1/2)*cos(1/3)));
! 221: print(print_input_form(R0));
! 222: R=tr_apply_rule1(R0,Rule[0],Rule[1]);
! 223: return R;
! 224: }
! 225:
! 226: end:
1.1 takayama 227:
228: @c ---------------------------------------------------------
229: @section $BNcBj(B $BITDj@QJ,(B
230:
1.4 ! takayama 231: begin: example_indefinite_integral()
! 232: $BNcBj(B $BITDj@QJ,(B
! 233: example:
1.2 takayama 234: /* integral(f+g) => integral(f)+integral(g) */
235: S1=[quote(integral(pn(f)+pn(g))),
236: [int_linear1,f,g]];
237: def int_linear1(X,Y) {
238: return qt_replace(quote(integral(f)+integral(g)),[[f,X],[g,Y]]);
239: }
240:
241: /* integral(c*f) => c*integral(f) */
242: def qt_independent(F,X) { return !qt_dependent(F,X); }
243: S2=[quote(integral(pn(c,qt_independent(c,x))*f)),
244: [int_linear2,c,f]];
245: def int_linear2(X,Y) {
246: return qt_replace(quote(c*integral(f)),[[c,X],[f,Y]]);
247: }
248:
249: apply_or_rules(quote(integral(a*x^2+x+2/x)),[S1,S2]);
250: $B$3$l$r$3$l0J>e=q$-49$($,5/$-$J$$$^$G7+$jJV$9(B.
251: $B$3$N%k!<%k$N>l9gEz$($O(B
252: a*integral(x^2)+integral(x)+integral(2/x);
253:
254: quote(integral(x^pn(n))) --> x^(n+1)/(n+1) or log(x) $B$r=q$/(B.
1.4 ! takayama 255: end:
1.2 takayama 256:
1.1 takayama 257: @c ---------------------------------------------------------
258: @section $BNcBj(B $B4JC1$J9=J82r@O(B
259:
1.4 ! takayama 260: begin: example_parsing()
! 261: $BNcBj(B $B4JC1$J9=J82r@O(B
! 262: example:
1.2 takayama 263: $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
264:
265: extern R1,R2,R3,R4,S1,S2,S3,S4;
266: /* $BJ8K!$rK~$?$9$+$I$&$+$N(B check $BMQ(B. Action $BIt$O(B 1 $B$+(B 0 */
267: R1=[quote(pn(x,is_expression(x))+pn(y,is_expression(y))), 1];
268: R2=[quote(pn(x,is_expression(x))*pn(y,is_expression(y))), 1];
269: R3=[quote((pn(x,is_expression(x)))), 1];
270: R4=[quote(pn(x,qt_is_integer(x))), 1];
271: def is_expression(Qobj) {
272: R = [R1,R2,R3,R4];
273: A = apply_or_match0(Qobj,R);
274: if (A == 0) return 0; else return 1;
275: }
276:
277: /* $B7W;;MQ(B. R1,R2,R3,R4 $B$H:8$O6&DL(B. */
278: S1=[quote(pn(x,is_expression(x))+pn(y,is_expression(y))), [myadd,x,y]];
279: S2=[quote(pn(x,is_expression(x))*pn(y,is_expression(y))), [mymul,x,y]];
280: S3=[quote((pn(x,is_expression(x)))), [qt_id,x]];
281: S4=[quote(pn(x,qt_is_integer(x))), [qt_id,x]];
282:
283: def eval_expression(Qobj) {
284: S = [S1,S2,S3,S4];
285: return apply_or_rules(Qobj,S);
286: }
287:
288: def myadd(X,Y) {
289: return qt_(qt_eval(X,1)+qt_eval(Y,1));
290: }
291:
292: def mymul(X,Y) {
293: return qt_(qt_eval(X,1)*qt_eval(Y,1));
294: }
295:
296: /* $B7W;;(B */
297: tr_eval_expression(quote(1+2*(3+15)));
1.4 ! takayama 298: end:
1.1 takayama 299:
300: @c ---------------------------------------------------------
301: @section $BNcBj(B $BHs2D494D$N4JC1$J9=J82r@O(B
302:
303:
304:
1.4 ! takayama 305: @section Todo;
1.3 takayama 306:
1.4 ! takayama 307: $BNc(B; $BQQ5i?t$N7W;;$r(B quote $B$G<B8=(B.
1.3 takayama 308: sort $B$d(B expand $B$OAH$_9~$_$G(B.
309:
1.4 ! takayama 310: $BNc(B; Mathematica $B$N(B Expand[], Toghether[] $BAjEv$N$b$N(B.
1.3 takayama 311:
1.4 ! takayama 312: $BNc(B; D $B$N3]$1;;$r(B $B%Q%?!<%s%^%C%A$G<B8=(B.
1.3 takayama 313:
1.4 ! takayama 314: $BNc(B; (x^(1/n))^n --> x $BEy(B.
1.3 takayama 315:
1.4 ! takayama 316: $BNc(B; $B5-9fHyJ,$HHyJ,4D$G$N7W;;(B.
! 317: y''+xy=0, y''=y^2+x $BEy(B. index $BIU$-$NJQ?t@8@.$,I,MW(B. idxtov
1.3 takayama 318:
1.4 ! takayama 319: $BNc(B; QE, $BO@M}<0(B.
1.3 takayama 320:
321: @section $B9M$(J}$K$D$$$F$N35@b(B
322:
323: $B%H%C%W%l%Y%k$N4X?tC#(B. (stylesheet $B$N9M$($K;w$F$k(B.)
324: iterator $B$N0l<o(B.
325:
326: @c ------------------------------------------------
1.4 ! takayama 327: @section $B<B83E*4X?t(B
! 328:
! 329: begin: qt_map_arg(F,Q)
! 330: $B4X?t(B F $B$r(B quote $B%G!<%?(B {Q} $B$N(B $B$9$Y$F$N%N!<%I$K:F5"E*$K(B
! 331: apply $B$7$?(B quote $B%G!<%?$rLa$9(B.
! 332: example: qt_map_arg(nn,quote(sin(@pi)+2/3))
! 333: nn(nn(sin(nn(@pi)))+nn(nn(2)/nn(3)))
! 334: end:
! 335:
1.3 takayama 336: @section $B$^$@%9%1%C%A$N$_$N4X?t;EMM(B
337:
338: qt_ltor, qt_rtol : $BLZ$N9=B$$NJQ49(B; $BNc(B (x*y)*z --> x*(y*z)
339:
340: 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.
341: base_name $BB0@-$r(B x $B$K(B.
342: 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.
343: 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.
344:
345: idxtov $B4X?t$O(B $B4X?tL>$K$b;H$($k$h$&$K$9$k(B --> $BHyJ,4DBP1~(B.
346:
347: qt_function($BL>A0(B, $B0z?t(B) --> quote($BL>A0(B($B0z?t(B)) $B$r@8@.(B.
348: index $BIU$-4X?t$OHyJ,4D$N<h07$KI,MW(B.
349:
350: $B6R5i?t$N<h07(B, dp $B$N(B pretty print $B$N$?$a(B.
351: qt_qttodp(Qobj | vlist, order?) quote $B$+$i(B dp $B$r:n$k(B.
352: exponent $B$,?t$G$J$$$H:n$l$:(B.
353: qt_dptoqt(Qobj | vlist) dp $B$+$i(B quote $B$r:n$k(B. vlist $B$OB0@-$GBP1~(B?
1.1 takayama 354:
1.3 takayama 355: qt_expand, qt_sort, qt_ht, qt_rest, qt_mtov $B$b4pAC4X?t$H$7$FM_$7$$(B.
1.1 takayama 356:
357: /*&generate-epilogue
358: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>