4 (ratprint : false, float2bf : true,0);
7 (lu_test(m) := block([mp],
8 mp : get_lu_factors(lu_factor(m,generalring)),
9 zeromatrixp(m - mp[1] . mp[2] . mp[3])),0);
15 lu_test(matrix([0,1],[1,0]));
18 lu_test(matrix([0,a],[b,0]));
21 lu_test(matrix([a,b],[c,d]));
24 lu_test(matrix([a,b],[b,d]));
27 lu_test(matrix([1/2,b],[b,2/3]));
30 lu_test(matrix([1/2 + %i, %i - 1],[9 - %i, 19 + %i]));
33 lu_test(matrix([0,1,0],[0,0,1],[1,2,4]));
36 lu_test(matrix([0,a,0],[b,0,0],[0,0,c]));
39 lu_test(matrix([a,b,c],[d,e,f],[g,h,i]));
42 lu_test(matrix([0,0,1],[1,0,0],[0,1,0]));
45 lu_test(matrix([0,0,1],[1,0,0],[0,1,x]));
48 lu_test(hilbert_matrix(3));
51 lu_test(hilbert_matrix(4));
54 lu_test(hilbert_matrix(5));
57 lu_test(vandermonde_matrix([1,2,%i]));
60 lu_test(vandermonde_matrix([1 + %i,1 - %i, 8, 32]));
63 (lu_test(m, tol) := block([mp],
64 mp : get_lu_factors(lu_factor(m,bigfloatfield)),
65 every(lambda([s], is(cabs(s) < tol)), m - mp[1] . mp[2] . mp[3])),0);
71 lu_test(vandermonde_matrix([1,1/2,1/3,1/4]), 1.0e-18);
77 lu_test(vandermonde_matrix([1,1/2,1/3,1/4]), 1.0e-38);
80 lu_test(hilbert_matrix(13), 1.0e-38);
83 lu_test(hilbert_matrix(4) + %i * vandermonde_matrix([1,2,3,4]), 1.0e-15);
86 (lu_test(m, tol) := block([mp],
87 mp : get_lu_factors(lu_factor(m,complexfield)),
88 every(lambda([s], is(cabs(s) < tol)),m - mp[1] . mp[2] . mp[3])),0);
91 lu_test(hilbert_matrix(7) + %i * vandermonde_matrix([1,2,3,4,5,6,7]), 1.0e-10);
94 (m : matrix([1,2,3],[4,5,6],[7,8,10]),0);
97 (b : m . matrix([x],[y],[z]),0);
100 lu_backsub(lu_factor(m,crering), b);
101 ''(rat(matrix([x],[y],[z])))$
103 (m : matrix([0,2,3],[0,5,6],[7,8,10]),0);
106 (b : m . matrix([x],[y],[z]),0);
109 lu_backsub(lu_factor(m, crering), b);
110 ''(rat(matrix([x],[y],[z])))$
112 (m : matrix([0,2,3],[0,5,6],[7,8,10]),0);
115 (b : m . matrix([x],[y],[z]),0);
118 lu_backsub(lu_factor(m, crering), b);
119 ''(rat(matrix([x],[y],[z])))$
122 (m : matrix([0,1,2],[1,0,1],[0,0,8]),0);
125 (b : m . matrix([x],[y],[z]),0);
128 lu_backsub(lu_factor(m, crering), b);
129 ''(rat(matrix([x],[y],[z])))$
131 (m : matrix([matrix([0,1],[1,0]), matrix([1,0],[%i,0])],
132 [matrix([1,0],[0,1]), matrix([1,1],[-1,1])]),0);
135 (m1 : get_lu_factors(lu_factor(m, noncommutingring)),0);
138 (matrix_element_mult : ".",0);
141 zeromatrixp(m1[1] . m1[2] . m1[3] - m);
144 (m : matrix([matrix([matrix([8,4],[4,13]),matrix([2,4],[7,9])],[matrix([2,7],[4,9]),matrix([10,6],[6,15])]),matrix([matrix([4,4],[12,5]),matrix([0,6],[6,8])],[matrix([8,3],[13,3]),matrix([6,5],[5,6])])],[matrix([matrix([4,12],[4,5]),matrix([8,13],[3,3])],[matrix([0,6],[6,8]),matrix([6,5],[5,6])]),matrix([matrix([18,5],[5,4]),matrix([5,9],[2,6])],[matrix([5,2],[9,6]),matrix([6,3],[3,11])])]),0);
147 (m1 : get_lu_factors(lu_factor(m,'noncommutingring)),0);
150 zeromatrixp(m1[1] . m1[2] . m1[3]-m);
153 (matrix_element_mult : "*",0);
156 errcatch(lu_factor(matrix()));
159 get_lu_factors(lu_factor(matrix([0])));
160 [matrix([1]),matrix([1]),matrix([0])]$
162 ratdisrep(get_lu_factors(lu_factor(matrix([0]),'crering)));
163 [matrix([1]),matrix([1]),matrix([0])]$
165 get_lu_factors(lu_factor(matrix([0]), 'floatfield));
166 [matrix([1]),matrix([1]),matrix([0.0])]$
168 get_lu_factors(lu_factor(matrix([0]), 'bigfloatfield));
169 [matrix([1]),matrix([1]),matrix([0.0b0])]$
171 get_lu_factors(lu_factor(matrix([0,1],[0,1])));
172 [matrix([0,1],[1,0]),matrix([1,0],[0,1]),matrix([0,1],[0,1])]$
174 get_lu_factors(lu_factor(matrix([5,0,0],[0,0,0],[0,0,1])));
175 [matrix([1,0,0],[0,0,1],[0,1,0]),matrix([1,0,0],[0,1,0],[0,0,1]),
176 matrix([5,0,0],[0,0,1],[0,0,0])]$
178 get_lu_factors(lu_factor(matrix([5,0,0],[0,0,0],[0,0,0])));
179 [matrix([1,0,0],[0,0,1],[0,1,0]),
180 matrix([1,0,0],[0,1,0],[0,0,1]),
181 matrix([5,0,0],[0,0,0],[0,0,0])]$
183 (lower_triangular_p(mat) := block([n : matrix_size(mat), OK : true],
184 for r :1 thru second(n) do (
185 for c : r thru first(n) do (
186 OK : OK and (if r=c then is (mat[r,c] = 1) else is(mat[r,c] = 0)))),
190 (upper_triangular_p(mat) := block([n : matrix_size(mat), OK : true],
191 for r :1 thru second(n) do (
192 for c : 1 thru r-1 do (
193 OK : OK and is(mat[r,c] = 0))),
197 (perm_mat_p(mat) := zeromatrixp(mat.transpose(mat) - identfor(mat)),0);
200 /* In this file, there are multiple definitions of lu_test." */
203 (lu_test(m) := block([mp],
204 mp : get_lu_factors(lu_factor(m, 'generalring)),
205 lower_triangular_p(second(mp)) and
206 perm_mat_p(first(mp)) and
207 upper_triangular_p(third(mp)) and
208 zeromatrixp(ratsimp(m - first(mp).second(mp).third(mp)))), 0);
211 /* see mailing list, "lu_factor fails on trivial diagonal matrix," 5 Jan 2021. */
212 lu_test(matrix([-1,0,0,0],[0,-3,0,0],[0,0,0,0],[0,0,0,-3]));
215 lu_test(matrix([0,0,0,0],[0,-3,0,0],[0,0,0,0],[0,0,0,-3]));
218 lu_test(matrix([0,0,0,0],[0,0,0,0],[0,0,-3,0],[0,0,0,0]));
221 lu_test(matrix([0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,-3]));
224 lu_test(matrix([0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,-1]));
227 every(lambda([x],x), map('lu_test, flatten(outermap(lambda([a,b,c,d], matrix([a,b],[c,d])),
228 [0,1],[0,1],[0,1],[0,1]))));
231 (remvalue(m,b,m1),0);
234 every(lambda([x],x), map(lu_test, flatten(outermap(lambda([x1,x2,x3,x4], matrix([x1,x2],[x3,x4])),
235 [a,b],[a,b],[a,b],[a,b]))));
238 /* diagonal matrices */
239 lu_test(matrix([46,0,0],[0,107,0],[0,0,28]));
242 lu_test(matrix([46,0,0],[0,107,0],[0,0,0]));
245 lu_test(matrix([0,0,0],[0,46,0],[0,0,107]));
248 lu_test(matrix([107,0,0],[0,0,0],[0,0,46]));
251 lu_test(matrix([0,0,0],[0,0,0],[0,0,46]));
254 lu_test(matrix([0,0,0],[0,107,0],[0,0,0]));
257 lu_test(matrix([107,0,0],[0,0,0],[0,0,0]));
260 lu_test(matrix([0,0,0],[0,0,0],[0,0,107]));
263 lu_test(matrix([0,0,0],[0,0,0],[0,0,0]));
266 lu_test(matrix([107,0,0],[0,46,0],[0,0,107]));
269 (mat : matrix([matrix([0,0],[0,1]), matrix([1,2],[2,1])], [matrix([0,1],[1,0]), matrix([1,2],[2,1])]),0);
272 block([matrix_element_mult : ".", mm : get_lu_factors(lu_factor(mat, 'noncommutingring))],
273 zeromatrixp(mat - first(mm) . second(mm) . third(mm)));
276 (mat : matrix([matrix([0,0],[0,0]), matrix([107,2],[2,107])], [matrix([0,0],[0,0]), matrix([1,2],[2,1])]),0);
279 block([matrix_element_mult : ".", mm : get_lu_factors(lu_factor(mat, 'noncommutingring))],
280 zeromatrixp(mat - first(mm) . second(mm) . third(mm)));
283 (mat : matrix([matrix([0,1],[1,0]), matrix([107,2],[2,107])], [matrix([0,0],[0,0]), matrix([1,2],[2,1])]),0);
286 block([matrix_element_mult : ".", mm : get_lu_factors(lu_factor(mat, 'noncommutingring))],
287 zeromatrixp(mat - first(mm) . second(mm) . third(mm)));
290 (mat : matrix([matrix([0,1],[1,0]), matrix([107,2],[2,107])], [matrix([0,1],[1,0]), matrix([1,46],[46,1])]),0);
293 block([matrix_element_mult : ".", mm : get_lu_factors(lu_factor(mat, 'noncommutingring))],
294 zeromatrixp(mat - first(mm) . second(mm) . third(mm)));
297 (mat : matrix([matrix([0,0],[1,0]), matrix([1,0],[0,0])], [matrix([0,1],[1,0]), matrix([1,46],[46,1])]),0);
300 block([matrix_element_mult : ".", mm : get_lu_factors(lu_factor(mat, 'noncommutingring))],
301 zeromatrixp(mat - first(mm) . second(mm) . third(mm)));
304 (mat : matrix([matrix([0,0],[0,0]), matrix([0,0],[0,0])], [matrix([0,0],[0,0]), matrix([0,0],[0,0])]),0);
307 block([matrix_element_mult : ".", mm : get_lu_factors(lu_factor(mat, 'noncommutingring))],
308 zeromatrixp(mat - first(mm) . second(mm) . third(mm)));
311 (reset(ratprint, float2bf, matrix_element_mult, matrix_element_transpose),0);
314 (remfunction(lu_test, lower_triangular_p,upper_triangular_p,perm_mat_p),0);