Annotation of OpenXM/src/asir-contrib/testing/test1-tr.rr, Revision 1.2
1.2 ! takayama 1: /* $OpenXM$ */
! 2: /* $Id: test1-tr.rr,v 1.2 2005/04/02 05:55:37 taka Exp $ */
! 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: }
! 102: return R;
! 103: }
! 104:
! 105: end$
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>