1 /* copyright 2007 by Robert Dodier
2 * I release this file under the terms of the GNU General Public License.
5 (set_random_state (make_random_state (12345)),
7 file_search_maxima : cons ("./###.mac", file_search_maxima),
8 file_search_lisp : cons ("./###.lisp", file_search_lisp),
12 (M0 : make_matrix (0, 0), [nrows (%%), ncols (%%)]);
15 [errcatch (M0[0, 0]), errcatch (M0[1, 0]), errcatch (M0[0, 1]), errcatch (M0[1, 1]), errcatch (M0[2, 2])];
18 (M1 : make_matrix (10, 0), [nrows (%%), ncols (%%)]);
21 [errcatch (M1[0, 0]), errcatch (M1[1, 0]), errcatch (M1[0, 1]), errcatch (M1[1, 1]), errcatch (M1[2, 2])];
24 (M1 : make_matrix (0, 10), [nrows (%%), ncols (%%)]);
27 [errcatch (M1[0, 0]), errcatch (M1[1, 0]), errcatch (M1[0, 1]), errcatch (M1[1, 1]), errcatch (M1[2, 2])];
30 (M : make_matrix (5, 3),
32 fillarray (?get (M@storage, '?storage_array), makelist (i, i, 1, 15)),
33 [M, new2old_matrix (M)]);
34 ''([amatrix (5, 0, 1, 3, 0, 5, a),
35 matrix ([1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9, 14], [5, 10, 15])]);
37 [M[1, 1], M[2, 2], M[3, 3], M[4, 2], M[5, 1], M[5, 3]];
40 [errcatch (M[0, 0]), errcatch (M[10, 10])];
43 [M2 : t (M), new2old_matrix (M2)];
44 ''([amatrix (3, 0, 5, 5, 0, 1, a),
45 matrix ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15])]);
47 [M [all, 2], new2old_matrix (M [all, 2])];
48 ''([amatrix (5, 0, 1, 1, 1, 5, a),
49 matrix ([6], [7], [8], [9], [10])]);
51 [M [2, all], new2old_matrix (M [2, all])];
52 ''([amatrix (1, 1, 1, 3, 0, 5, a),
53 matrix ([2, 7, 12])]);
55 [M2 [all, 2], new2old_matrix (M2 [all, 2])];
56 ''([amatrix (3, 0, 5, 1, 1, 1, a),
57 matrix ([2], [7], [12])]);
59 [M2 [2, all], new2old_matrix (M2 [2, all])];
60 ''([amatrix (1, 1, 5, 5, 0, 1, a),
61 matrix ([6, 7, 8, 9, 10])]);
63 [M [all, all], new2old_matrix (M [all, all])];
64 ''([amatrix (5, 0, 1, 3, 0, 5, a),
65 matrix ([1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9, 14], [5, 10, 15])]);
67 [M2 [all, all], new2old_matrix (M2 [all, all])];
68 ''([amatrix (3, 0, 5, 5, 0, 1, a),
69 matrix ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15])]);
72 ''([5, 0, 1, 3, 0, 5, a]);
75 ''([3, 0, 5, 5, 0, 1, a]);
77 is (M@storage = M2@storage);
87 matrix ([1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9, 14], [5, 10, 15]);
90 matrix ([1, 2, 3, 4, 5], [6, FOOBAR, 8, 9, 10], [11, 12, 13, 14, 15]);
92 is (M@storage = M2@storage);
95 [M3 : M[all, 3], new2old_matrix (M[all, 3])];
96 ''([amatrix (5, 0, 1, 1, 2, 5, a),
97 matrix ([11], [12], [13], [14], [15])]);
99 is (M@storage = M3@storage);
108 is (M@storage = M3@storage);
111 (A1 : make_matrix (10, 10), 0);
114 for i:1 thru 10 do A1[i, i] : i;
117 (A2 : A1[all, all], A3 : A1[all, 1], A4 : A1[1, all], 0);
120 ?get(A3@storage, '?refcount);
123 (A1[1, 1] : 321, [A1[1, 1], A2[1, 1], A3[1, 1], A4[1, 1]]);
126 ?get(A3@storage, '?refcount);
129 (A4[1, 1] : 678, [A1[1, 1], A2[1, 1], A3[1, 1], A4[1, 1]]);
132 ?get(A3@storage, '?refcount);
135 (A2[1, 1] : 456, [A1[1, 1], A2[1, 1], A3[1, 1], A4[1, 1]]);
138 ?get(A3@storage, '?refcount);
141 (A3[1, 1] : 543, [A1[1, 1], A2[1, 1], A3[1, 1], A4[1, 1]]);
142 [321, 456, 543, 678];
144 (B : random_matrix (10, 3),
146 ''(flatten (args (new2old_matrix (B))));
149 Bt_old : new2old_matrix (Bt),
150 [elements (B1 : B[all, 1]), elements (B2 : B[all, 2]), elements (B3 : B[all, 3])]);
151 ''([Bt_old [1], Bt_old [2], Bt_old [3]]);
153 (amatrixmap (">", B1, B2), [%%@nr, %%@nc, elements (%%)]);
154 [10, 1, [0.0703125 > 0.0390625, 0.375 > 0.73046875,
155 0.8515625 > 0.9921875, 0.08203125 > 0.25390625,
156 0.390625 > 0.65234375, 0.04296875 > 0.578125,
157 0.046875 > 0.859375, 0.62890625 > 0.0, 0.578125 > 0.30859375,
158 0.76953125 > 0.796875]];
160 (amatrixmap (lambda ([x, y], is (x < y)), B2, B3), [%%@nr, %%@nc, elements (%%)]);
161 [10, 1, [true, false, false, false, true, true, true, true, true, false]];
163 (amatrixmap ("+", B1, B2, B3), [%%@nr, %%@nc, elements (%%)]);
164 [10, 1, [0.4453125, 1.72265625, 1.90625, 0.45703125,
165 1.71484375, 1.30078125, 1.8828125, 1.20703125, 1.25390625,
168 (amatrixmap ("/", B, amatrixmap (lambda ([x], 1/2 + x), B)), new2old_matrix (%%));
169 matrix([.1232876712328767,.07246376811594203,.4018691588785047],
170 [.4285714285714285,.5936507936507937,.5524475524475524],
171 [0.630057803468208,.6649214659685864,.1111111111111111],
172 [.1409395973154362,.3367875647668394,.1949685534591195],
173 [.4385964912280702,.5661016949152542,.5733333333333334],
174 [.07913669064748201,.5362318840579711,.5761589403973509],
175 [.08571428571428572,0.632183908045977,.6613756613756614],
176 [.5570934256055363,0.0,.5362318840579711],
177 [.5362318840579711,.3816425120772947,.4234234234234234],
178 [.6061538461538462,.6144578313253012,.5974842767295597]);
181 "binary-" (x, y) := x - y,
182 random_matrix (B@nr, B@nc),
183 amatrixmap ("binary-", %%, B),
184 new2old_matrix (%%));
185 matrix([0.12890625,0.875,0.4765625],
186 [0.6015625,0.06640625,0.28125],
187 [-0.4375,-0.921875,0.54296875],
188 [0.12890625,0.078125,0.64453125],
189 [0.06640625,0.09765625,0.1171875],
190 [0.140625,0.37890625,-0.4453125],
191 [0.1953125,-0.80859375,-0.38671875],
192 [-0.1640625,0.61328125,-0.46484375],
193 [0.328125,0.08203125,-0.01953125],
194 [0.06640625,-0.08984375,-0.23828125]);