Mode of #cas

matrixPower

The power Ak of a square matrix with rational entries, for k up to 1000, with a theorem that it is right.

#cas [matrixPower k] A
gives the power Ak of the square matrix A with rational entries, for a natural number k up to 1000, and proves A ^ k = B.

A linear recurrence or a Markov chain takes the same linear step over and over, so k steps of it are the k-th power of a matrix, and matrixPower computes that power for the k you choose. A good first example is (1110), 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.

Details and Options

  • k is a natural number literal with k≤1000. A is a square matrix literal !![a, b; c, d] or a list of rows [[a, b], [c, d]], with closed rational entries such as -3/2, 0.25 or 1/10^15.
  • The theorem is A ^ k = B for the matrices over ℚ, decided by kernel evaluation (decide +kernel).
  • In a proof, decide +kernel proves the printed equation. A larger exponent splits with pow_add and pow_mul into powers that the mode computes.
  • The exponent is a natural number. For a negative power, take a power of the matrix that inverse prints.
  • There are no options.

Examples (13)#

Basic Examples (2)

The tenth power of the Fibonacci matrix:

In[1]:=
#cas [matrixPower 10] !![1, 1; 1, 0]
Out[1]=

power

(89555534)
!![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
  1. Decided by kernel evaluation

    !![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]

    Checked by Lean’s kernel


A Jordan block with fractions. The upper right entry of (λ10λ)k is kλk−1, here 3·14=34:

In[2]:=
#cas [matrixPower 3] !![1/2, 1; 0, 1/2]
Out[2]=

power

(1834018)
!![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
  1. Decided by kernel evaluation

    !![1 / 2, 1; 0, 1 / 2] ^ 3 = !![1 / 8, 3 / 4; 0, 1 / 8]

    Checked by Lean’s kernel

Scope (3)

A rotation by a right angle has order 4:

In[3]:=
#cas [matrixPower 4] !![0, -1; 1, 0]
Out[3]=

power

(1001)
!![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
  1. Decided by kernel evaluation

    !![0, -1; 1, 0] ^ 4 = !![1, 0; 0, 1]

    Checked by Lean’s kernel


A nilpotent matrix:

In[4]:=
#cas [matrixPower 2] !![0, 1; 0, 0]
Out[4]=

power

(0000)
!![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
  1. Decided by kernel evaluation

    !![0, 1; 0, 0] ^ 2 = !![0, 0; 0, 0]

    Checked by Lean’s kernel


The zeroth power is the identity:

In[5]:=
#cas [matrixPower 0] !![1, 2; 3, 4]
Out[5]=

power

(1001)
!![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
  1. Decided by kernel evaluation

    !![1, 2; 3, 4] ^ 0 = !![1, 0; 0, 1]

    Checked by Lean’s kernel

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:

In[6]:=
theorem fibonacci_matrix : !![(1 : ℚ), 1; 1, 0] ^ 10 = !![89, 55; 55, 34] := by
  decide +kernel

#print axioms fibonacci_matrix
Out[6]=

fibonacci_matrix depends on the axioms propext, Classical.choice, Quot.sound.


Twenty steps of the Fibonacci recurrence. The upper right entry is F20, which fibonacci gives too:

In[7]:=
#cas [matrixPower 20] !![1, 1; 1, 0]
Out[7]=

power

(10946676567654181)
!![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
  1. Decided by kernel evaluation

    !![1, 1; 1, 0] ^ 20 = !![10946, 6765; 6765, 4181]

    Checked by Lean’s kernel

In[8]:=
#cas (fibonacci 20)
Out[8]=

fibonacci

6765
Domain
ℕ
Input (natural numbers)
20

Checked by Lean’s kernel: fibonacci

Nat.fib 20 = 6765
The certificate: 1 checked step
  1. fibonacci

    Nat.fib 20 = 6765

    Checked by Lean’s kernel


A Markov chain with two states. Row i of P3 is the distribution after three steps from state i:

In[9]:=
#cas [matrixPower 3] !![1/2, 1/2; 1/4, 3/4]
Out[9]=

power

(1132213221644364)
!![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
  1. Decided by kernel evaluation

    !![1 / 2, 1 / 2; 1 / 4, 3 / 4] ^ 3 = !![11 / 32, 21 / 32; 21 / 64, 43 / 64]

    Checked by Lean’s kernel

Properties and Relations (2)

The characteristic polynomial of this matrix is x3−2, so by the Cayley-Hamilton theorem A3=2I:

In[10]:=
#cas [characteristicPolynomial] !![0, 0, 2; 1, 0, 0; 0, 1, 0]
Out[10]=

det (x I - A)

x3−2
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
  1. Characteristic polynomial in ℚ[X]

    !![0, 0, 2; 1, 0, 0; 0, 1, 0].charpoly = Polynomial.X ^ 3 - 2

    Checked by Lean’s kernel

In[11]:=
#cas [matrixPower 3] !![0, 0, 2; 1, 0, 0; 0, 1, 0]
Out[11]=

power

(200020002)
!![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
  1. Decided by kernel evaluation

    !![0, 0, 2; 1, 0, 0; 0, 1, 0] ^ 3 = !![2, 0, 0; 0, 2, 0; 0, 0, 2]

    Checked by Lean’s kernel


The eigenvalues of A2 are the squares of the eigenvalues of A. Those of A are 1, 2 and 11 (see eigenvalues):

In[12]:=
#cas [matrixPower 2] !![2, 0, 0; 0, 3, 4; 0, 4, 9]
Out[12]=

power

(4000254804897)
!![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
  1. Decided by kernel evaluation

    !![2, 0, 0; 0, 3, 4; 0, 4, 9] ^ 2 = !![4, 0, 0; 0, 25, 48; 0, 48, 97]

    Checked by Lean’s kernel

In[13]:=
#cas [eigenvalues] !![4, 0, 0; 0, 25, 48; 0, 48, 97]
Out[13]=

eigenvalues with multiplicity

[1, 4, 121]
[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
  1. Characteristic polynomial factored over ℚ

    !![4, 0, 0; 0, 25, 48; 0, 48, 97].charpoly =
      (Polynomial.X - 1) * (Polynomial.X - 4) * (Polynomial.X - 121)

    Checked by Lean’s kernel

Possible Issues (2)

The kernel evaluates the power, and the exponent is at most 1000:

In[14]:=
#cas [matrixPower 1001] !![1, 1; 1, 0]
Out[14]=

Error

matrixPower 1001: the power is decided by kernel evaluation, up to exponent 1000

The matrix has to be square:

In[15]:=
#cas [matrixPower 2] !![1, 2, 3; 4, 5, 6]
Out[15]=

Error

matrixPower 2: the matrix must be square

Neat Examples (1)

The powers of (3423) solve Pell’s equation x2−2y2=1: the first column of each power is a solution. Here it is (3363,2378):

In[16]:=
#cas [matrixPower 5] !![3, 4; 2, 3]
Out[16]=

power

(3363475623783363)
!![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
  1. Decided by kernel evaluation

    !![3, 4; 2, 3] ^ 5 = !![3363, 4756; 2378, 3363]

    Checked by Lean’s kernel

See Also

dot · inverse · eigenvalues · characteristicPolynomial · fibonacci