File: rtest2.mac

package info (click to toggle)
maxima 5.21.1-2squeeze
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 94,928 kB
  • ctags: 43,849
  • sloc: lisp: 298,974; fortran: 14,666; perl: 14,325; tcl: 10,494; sh: 4,052; makefile: 2,975; ansic: 471; awk: 24; sed: 7
file content (142 lines) | stat: -rw-r--r-- 3,251 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*************** -*- Mode: MACSYMA; Package: MAXIMA -*-  ******************/
/***************************************************************************
***                                                                    *****
***     Copyright (c) 1984 by William Schelter,University of Texas     *****
***     All rights reserved                                            *****
***************************************************************************/


kill(functions,arrays,values);
done$
use_fast_arrays:false;
false;
a[n]:=n*a[n-1];
a[n]:=n*a[n-1]$
a[0]:1;
1$
a[5];
120$
a[n]:=n;
a[n]:=n$
a[6];
6$
a[4];
24$
(use_fast_arrays:true,kill(a));
done;
lambda([x,y,z],x^2+y^2+z^2);
lambda([x,y,z],x^2+y^2+z^2)$
%(1,2,a);
a^2+5$
1+2+a;
a+3$
exp:[x^2,y/3,-2];
[x^2,y/3,-2]$
%[1]*x;
x^3$
[a,exp,%];
[a,[x^2,y/3,-2],x^3]$
m:matrix([a,0],[b,1]);
matrix([a,0],[b,1])$
m^2;
matrix([a^2,0],[b^2,1])$
exp:m . m;
matrix([a^2,0],[a*b+b,1])$
m[1,1]*m;
matrix([a^2,0],[a*b,a])$
%-exp+1;
matrix([1,1],[1-b,a])$
m^^(-1);
matrix([1/a,0],[-b/a,1])$
[x,y] . m;
matrix([b*y+a*x,y])$
matrix([a,b,c],[d,e,f],[g,h,i]);
matrix([a,b,c],[d,e,f],[g,h,i])$
%^^2;
matrix([c*g+b*d+a^2,c*h+b*e+a*b,c*i+b*f+a*c],
       [f*g+d*e+a*d,f*h+e^2+b*d,f*i+e*f+c*d],
       [g*i+d*h+a*g,h*i+e*h+b*g,i^2+f*h+c*g])$
exp:x+1 = y^2;
x+1 = y^2$
x-1 = 2*y+1;
x-1 = 2*y+1$
exp+%;
2*x = y^2+2*y+1$
exp/y;
(x+1)/y = y$
1/%;
y/(x+1) = 1/y$
fib[n]:=if n = 1 or n = 2 then 1 else fib[n-1]+fib[n-2];
fib[n]:=if n = 1 or n = 2 then 1 else fib[n-1]+fib[n-2]$
fib[1]+fib[2];
2$
fib[3];
2$
fib[5];
5$
eta(mu,nu):=if mu = nu then mu else (if mu > nu then mu-nu else mu+nu);
eta(mu,nu):=if mu = nu then mu else (if mu > nu then mu-nu else mu+nu)$
eta(5,6);
11$
eta(eta(7,7),eta(1,2));
4$
if not 5 >= 2 and 6 <= 5 or 4+1 > 3 then a else b;
a$
kill(f);
done$

kill(x,y,z);
done$
determinant(hessian(x^3-3*a*x*y*z+y^3,[x,y,z]));
-3*a*y*(9*a^2*x*z+18*a*y^2)-27*a^3*x*y*z-54*a^2*x^3$

subst(1,z,quotient(%,-54*a^2));
y^3+a*x*y+x^3$
f(x):=block([a,y],local(a),y:4,a[y]:x,display(a[y]));
f(x):=block([a,y],local(a),y:4,a[y]:x,display(a[y]))$
y:2;
2$
a[y+2]:0;
0$
f(9);
done$
a[y+2];
0$

(use_fast_arrays : false, kill(a), 0);
0$

/* ensure that matrix construction works as advertised */
(L : makelist ([i], i, 1, 100), apply (matrix, L), [op (%%), args (%%)]);
[matrix, ''(makelist ([i], i, 1, 100))];

(L : makelist ([i], i, 1, 100), apply (matrix, L), transpose (%%));
''(matrix (tree_reduce (append, L)));   /* call tree_reduce instead of append because GCL barfs ... */

(matrix (), [op (%%), args (%%)]);
[matrix, []];

/* construct a matrix of modest size */
(apply (matrix, makelist ([i], i, 1, 1000)), 0);
0;

/* construct a matrix of modest size */
(apply (matrix, makelist ([i], i, 1, 10000)), 0);
0;

/* verify that arguments are evaluated exactly once */
block ([a : b, b : c, c: d, d : 1], matrix ([a, b], [c, d]), [op (%%), args (%%)]);
[matrix, '[[b, c], [d, 1]]];

/* verify that arguments are evaluated exactly once */
block ([a : b, b : c, c: d, d : 1, L1 : '[a, b], L2 : '[c, d]], matrix (L1, L2), [op (%%), args (%%)]);
[matrix, '[[a, b], [c, d]]];

/* should trigger an error */
errcatch (matrix ([1], [1, 2]));
[];

/* should trigger an error */
errcatch (matrix ([1], '(a + b)));
[];