Mode of #cas
matrixPower
The power of a square matrix with rational entries, for up to 1000, with a theorem that it is right.
#cas [matrixPower k] AA ^ k = B.A linear recurrence or a Markov chain takes the same linear step over and over, so steps of it are the -th power of a matrix, and matrixPower computes that power for the you choose. A good first example is , whose powers hold the Fibonacci numbers. The theorem A ^ k = B is about Mathlib’s power in the ring of matrices over , and the kernel decides it by evaluating the product.
Examples (13)#
Basic Examples (2)
The tenth power of the Fibonacci matrix:
#cas [matrixPower 10] !![1, 1; 1, 0]
power
!![89, 55; 55, 34]- Domain
ℚ^(2×2)- Input (matrix)
!![1, 1; 1, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]
A Jordan block with fractions. The upper right entry of is , here :
#cas [matrixPower 3] !![1/2, 1; 0, 1/2]
power
!![1/8, 3/4; 0, 1/8]- Domain
ℚ^(2×2)- Input (matrix)
!![1/2, 1; 0, 1/2]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1 / 2, 1; 0, 1 / 2] ^ 3 = !![1 / 8, 3 / 4; 0, 1 / 8]
The certificate: 1 checked step
Decided by kernel evaluation
!![1 / 2, 1; 0, 1 / 2] ^ 3 = !![1 / 8, 3 / 4; 0, 1 / 8]
Scope (3)
A rotation by a right angle has order 4:
#cas [matrixPower 4] !![0, -1; 1, 0]
power
!![1, 0; 0, 1]- Domain
ℚ^(2×2)- Input (matrix)
!![0, -1; 1, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![0, -1; 1, 0] ^ 4 = !![1, 0; 0, 1]
The certificate: 1 checked step
Decided by kernel evaluation
!![0, -1; 1, 0] ^ 4 = !![1, 0; 0, 1]
A nilpotent matrix:
#cas [matrixPower 2] !![0, 1; 0, 0]
power
!![0, 0; 0, 0]- Domain
ℚ^(2×2)- Input (matrix)
!![0, 1; 0, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![0, 1; 0, 0] ^ 2 = !![0, 0; 0, 0]
The certificate: 1 checked step
Decided by kernel evaluation
!![0, 1; 0, 0] ^ 2 = !![0, 0; 0, 0]
The zeroth power is the identity:
#cas [matrixPower 0] !![1, 2; 3, 4]
power
!![1, 0; 0, 1]- Domain
ℚ^(2×2)- Input (matrix)
!![1, 2; 3, 4]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 2; 3, 4] ^ 0 = !![1, 0; 0, 1]
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 2; 3, 4] ^ 0 = !![1, 0; 0, 1]
Applications (3)
The power as a theorem. Kernel evaluation, the proof behind the report, proves it directly, and only the three standard axioms are used:
theorem fibonacci_matrix : !![(1 : ℚ), 1; 1, 0] ^ 10 = !![89, 55; 55, 34] := by decide +kernel #print axioms fibonacci_matrix
fibonacci_matrix depends on the axioms propext, Classical.choice, Quot.sound.
Twenty steps of the Fibonacci recurrence. The upper right entry is , which fibonacci gives too:
#cas [matrixPower 20] !![1, 1; 1, 0]
power
!![10946, 6765; 6765, 4181]- Domain
ℚ^(2×2)- Input (matrix)
!![1, 1; 1, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 1; 1, 0] ^ 20 = !![10946, 6765; 6765, 4181]
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 1; 1, 0] ^ 20 = !![10946, 6765; 6765, 4181]
#cas (fibonacci 20)
fibonacci
6765- Domain
ℕ- Input (natural numbers)
20
Checked by Lean’s kernel: fibonacci
Nat.fib 20 = 6765
The certificate: 1 checked step
fibonacci
Nat.fib 20 = 6765
A Markov chain with two states. Row of is the distribution after three steps from state :
#cas [matrixPower 3] !![1/2, 1/2; 1/4, 3/4]
power
!![11/32, 21/32; 21/64, 43/64]- Domain
ℚ^(2×2)- Input (matrix)
!![1/2, 1/2; 1/4, 3/4]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1 / 2, 1 / 2; 1 / 4, 3 / 4] ^ 3 = !![11 / 32, 21 / 32; 21 / 64, 43 / 64]
The certificate: 1 checked step
Decided by kernel evaluation
!![1 / 2, 1 / 2; 1 / 4, 3 / 4] ^ 3 = !![11 / 32, 21 / 32; 21 / 64, 43 / 64]
Properties and Relations (2)
The characteristic polynomial of this matrix is , so by the Cayley-Hamilton theorem :
#cas [characteristicPolynomial] !![0, 0, 2; 1, 0, 0; 0, 1, 0]
det (x I - A)
x^3 - 2- Domain
ℚ^(3×3)- Input (matrix)
!![0, 0, 2; 1, 0, 0; 0, 1, 0]
Checked by Lean’s kernel: Characteristic polynomial in ℚ[X]
!![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly = Polynomial.X ^ 3 - 2
The certificate: 1 checked step
Characteristic polynomial in ℚ[X]
!![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly = Polynomial.X ^ 3 - 2
#cas [matrixPower 3] !![0, 0, 2; 1, 0, 0; 0, 1, 0]
power
!![2, 0, 0; 0, 2, 0; 0, 0, 2]- Domain
ℚ^(3×3)- Input (matrix)
!![0, 0, 2; 1, 0, 0; 0, 1, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![0, 0, 2; 1, 0, 0; 0, 1, 0] ^ 3 = !![2, 0, 0; 0, 2, 0; 0, 0, 2]
The certificate: 1 checked step
Decided by kernel evaluation
!![0, 0, 2; 1, 0, 0; 0, 1, 0] ^ 3 = !![2, 0, 0; 0, 2, 0; 0, 0, 2]
The eigenvalues of are the squares of the eigenvalues of . Those of are , and (see eigenvalues):
#cas [matrixPower 2] !![2, 0, 0; 0, 3, 4; 0, 4, 9]
power
!![4, 0, 0; 0, 25, 48; 0, 48, 97]- Domain
ℚ^(3×3)- Input (matrix)
!![2, 0, 0; 0, 3, 4; 0, 4, 9]
Checked by Lean’s kernel: Decided by kernel evaluation
!![2, 0, 0; 0, 3, 4; 0, 4, 9] ^ 2 = !![4, 0, 0; 0, 25, 48; 0, 48, 97]
The certificate: 1 checked step
Decided by kernel evaluation
!![2, 0, 0; 0, 3, 4; 0, 4, 9] ^ 2 = !![4, 0, 0; 0, 25, 48; 0, 48, 97]
#cas [eigenvalues] !![4, 0, 0; 0, 25, 48; 0, 48, 97]
eigenvalues with multiplicity
[1, 4, 121]- Domain
ℚ^(3×3)- Input (matrix)
!![4, 0, 0; 0, 25, 48; 0, 48, 97]
Checked by Lean’s kernel: Characteristic polynomial factored over ℚ
!![4, 0, 0; 0, 25, 48; 0, 48, 97].charpoly = (Polynomial.X - 1) * (Polynomial.X - 4) * (Polynomial.X - 121)
The certificate: 1 checked step
Characteristic polynomial factored over ℚ
!![4, 0, 0; 0, 25, 48; 0, 48, 97].charpoly = (Polynomial.X - 1) * (Polynomial.X - 4) * (Polynomial.X - 121)
Possible Issues (2)
The kernel evaluates the power, and the exponent is at most 1000:
#cas [matrixPower 1001] !![1, 1; 1, 0]
Error
matrixPower 1001: the power is decided by kernel evaluation, up to exponent 1000
The matrix has to be square:
#cas [matrixPower 2] !![1, 2, 3; 4, 5, 6]
Error
matrixPower 2: the matrix must be square
Neat Examples (1)
The powers of solve Pell’s equation : the first column of each power is a solution. Here it is :
#cas [matrixPower 5] !![3, 4; 2, 3]
power
!![3363, 4756; 2378, 3363]- Domain
ℚ^(2×2)- Input (matrix)
!![3, 4; 2, 3]
Checked by Lean’s kernel: Decided by kernel evaluation
!![3, 4; 2, 3] ^ 5 = !![3363, 4756; 2378, 3363]
The certificate: 1 checked step
Decided by kernel evaluation
!![3, 4; 2, 3] ^ 5 = !![3363, 4756; 2378, 3363]
See Also
dot · inverse · eigenvalues · characteristicPolynomial · fibonacci
