Initial revision
[LeanCalc.git] / help / det
1 NAME
2     det - determinant
3
4 SYNOPSIS
5     det(m)
6
7 TYPES
8     m           square matrix with elements of suitable type
9
10     return      zero or value of type determined by types of elements
11
12 DESCRIPTION
13     The matrix m has to be square, i.e. of dimension 2 with:
14
15         matmax(m,1) - matmin(m,1) == matmax(m,2) - matmin(m,2).
16
17     If the elements of m are numbers (real or complex), det(m)
18     returns the value of the determinant of m.
19
20     If some or all of the elements of m are not numbers, the algorithm
21     used to evaluate det(m) assumes the definitions of *, unary -, binary -,
22     being zero or nonzero, are consistent with commutative ring structure,
23     and if the m is larger than 2 x 2, division by nonzero elements is
24     consistent with integral-domain structure.
25
26     If m is a 2 x 2 matrix with elements a, b, c, d, where a tests as
27     nonzero, det(m) is evaluated by
28
29         det(m) = (a * d) - (c * b).
30
31     If a tests as zero, det(m) = - ((c * b) - (a * d)) is used.
32
33     If m is 3 * 3 with elements a, b, c, d, e, f, g, h, i, where a and
34     a * e - d * b test as nonzero, det(m) is evaluated by
35
36         det(m) = ((a * e - d * b) * (a * i - g * c)
37                         - (a * h - g * b) * (a * f - d * c))/a.
38
39 EXAMPLE
40     > mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23}
41     > c = config("mode", "frac")
42     > print det(A), det(A^2), det(A^3), det(A^-1)
43     -78 6084 -474552 -1/78
44
45     > obj res {r}
46     > global md
47     > define res_test(a) = !ismult(a.r, md)
48     > define res_sub(a,b) {local obj res v = {(a.r - b.r) % md}; return v;}
49     > define res_mul(a,b) {local obj res v = {(a.r * b.r) % md}; return v;}
50     > define res_neg(a) {local obj res v = {(-a.r) % md}; return v;}
51     > define res(x) {local obj res v = {x % md}; return v;}
52     > md = 0
53     > mat A[2,2] = {res(2), res(3), res(5), res(7)}
54     > md = 5
55     > print det(A)
56     obj res {4}
57     > md = 6
58     > print det(A)
59     obj res {5}
60
61     Note that if A had been a 3 x 3 or larger matrix, res_div(a,b) for
62     non-zero b would have had to be defined (assuming at least one
63     division is necessary); for consistent results when md is composite,
64     res_div(a,b) should be defined only when b and md are relatively
65     prime; there is no problem when md is prime.
66
67 LIMITS
68     none
69
70 LINK LIBRARY
71     VALUE matdet(MATRIX *m)
72
73 SEE ALSO
74     matdim, matmax, matmin, inverse
75