Mode of #cas

transpose

The transpose of a matrix of any shape with rational entries, with a theorem about Mathlib’s Matrix.transpose.

#cas [transpose] A
gives the transpose of the matrix A with rational entries, and proves A.transpose = B.

transpose swaps rows and columns. You need it to form ATA, to test symmetry, or to turn a row vector into a column vector and back. The theorem is A.transpose = B for Mathlib’s Matrix.transpose, which Mathlib writes Aᵀ.

Details and Options

  • A is a matrix literal !![a, b; c, d] or a list of rows [[a, b], [c, d]] of any shape. The entries are closed rational expressions such as -3/2, 0.25 or 1/10^15.
  • The theorem is A.transpose = B for the matrices over ℚ. The kernel decides it by evaluation (decide +kernel).
  • The tactic cas proves the same equations in a proof.
  • There are no options.

Examples (13)#

Basic Examples (2)

The transpose of a 2×3 matrix is 3×2:

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

transpose

(142536)
!![1, 4; 2, 5; 3, 6]
Domain
ℚ^(2×3)
Input (matrix)
!![1, 2, 3; 4, 5, 6]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1, 2, 3; 4, 5, 6].transpose = !![1, 4; 2, 5; 3, 6]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1, 2, 3; 4, 5, 6].transpose = !![1, 4; 2, 5; 3, 6]

    Checked by Lean’s kernel


A row becomes a column:

In[2]:=
#cas [transpose] !![1, 2, 3]
Out[2]=

transpose

(123)
!![1; 2; 3]
Domain
ℚ^(1×3)
Input (matrix)
!![1, 2, 3]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1, 2, 3].transpose = !![1; 2; 3]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1, 2, 3].transpose = !![1; 2; 3]

    Checked by Lean’s kernel

Scope (3)

A column becomes a row:

In[3]:=
#cas [transpose] !![1; 2; 3]
Out[3]=

transpose

(123)
!![1, 2, 3]
Domain
ℚ^(3×1)
Input (matrix)
!![1; 2; 3]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1; 2; 3].transpose = !![1, 2, 3]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1; 2; 3].transpose = !![1, 2, 3]

    Checked by Lean’s kernel


A list of rows works as well as a matrix literal:

In[4]:=
#cas [transpose] [[1, 2], [3, 4]]
Out[4]=

transpose

(1324)
!![1, 3; 2, 4]
Domain
ℚ^(2×2)
Input (matrix)
!![1, 2; 3, 4]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1, 2; 3, 4].transpose = !![1, 3; 2, 4]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1, 2; 3, 4].transpose = !![1, 3; 2, 4]

    Checked by Lean’s kernel


A symmetric matrix is its own transpose:

In[5]:=
#cas [transpose] !![2, 1; 1, 2]
Out[5]=

transpose

(2112)
!![2, 1; 1, 2]
Domain
ℚ^(2×2)
Input (matrix)
!![2, 1; 1, 2]

Checked by Lean’s kernel: Decided by kernel evaluation

!![2, 1; 1, 2].transpose = !![2, 1; 1, 2]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![2, 1; 1, 2].transpose = !![2, 1; 1, 2]

    Checked by Lean’s kernel

Applications (3)

The transpose as a theorem. cas proves it, and only the three standard axioms are used:

In[6]:=
theorem transpose_two : !![(1 : ℚ), 2; 3, 4].transpose = !![1, 3; 2, 4] := by
  cas

#print axioms transpose_two
Out[6]=

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


The Gram matrix ATA holds the dot products of the columns of A. With the transpose from the first example:

In[7]:=
#cas [dot] (!![1, 4; 2, 5; 3, 6], !![1, 2, 3; 4, 5, 6])
Out[7]=

product

(172227222936273645)
!![17, 22, 27; 22, 29, 36; 27, 36, 45]
Domain
ℚ^(3×2)
Input (product)
!![1, 4; 2, 5; 3, 6] . !![1, 2, 3; 4, 5, 6]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1, 4; 2, 5; 3, 6] * !![1, 2, 3; 4, 5, 6] = !![17, 22, 27; 22, 29, 36; 27, 36, 45]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1, 4; 2, 5; 3, 6] * !![1, 2, 3; 4, 5, 6] = !![17, 22, 27; 22, 29, 36; 27, 36, 45]

    Checked by Lean’s kernel


The rows of A are independent, so AAT is positive definite:

In[8]:=
#cas [dot] (!![1, 2, 3; 4, 5, 6], !![1, 4; 2, 5; 3, 6])
Out[8]=

product

(14323277)
!![14, 32; 32, 77]
Domain
ℚ^(2×3)
Input (product)
!![1, 2, 3; 4, 5, 6] . !![1, 4; 2, 5; 3, 6]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1, 2, 3; 4, 5, 6] * !![1, 4; 2, 5; 3, 6] = !![14, 32; 32, 77]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1, 2, 3; 4, 5, 6] * !![1, 4; 2, 5; 3, 6] = !![14, 32; 32, 77]

    Checked by Lean’s kernel

In[9]:=
#cas [positiveDefinite] !![14, 32; 32, 77]
Out[9]=

Boolean

True
Domain
2 × 2 real matrix
Input (matrix)
!![14, 32; 32, 77]

Checked by Lean’s kernel: The matrix is positive definite

!![14, 32; 32, 77].PosDef
The certificate: 1 checked step
  1. The matrix is positive definite

    !![14, 32; 32, 77].PosDef

    Checked by Lean’s kernel

The computation
  • Certificate

    A = L D Lᵀ over ℚ with pivots D = [14, 27/7], all positive

Properties and Relations (2)

Transposing twice gives back the matrix:

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

transpose

(123456)
!![1, 2, 3; 4, 5, 6]
Domain
ℚ^(3×2)
Input (matrix)
!![1, 4; 2, 5; 3, 6]

Checked by Lean’s kernel: Decided by kernel evaluation

!![1, 4; 2, 5; 3, 6].transpose = !![1, 2, 3; 4, 5, 6]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![1, 4; 2, 5; 3, 6].transpose = !![1, 2, 3; 4, 5, 6]

    Checked by Lean’s kernel


A matrix and its transpose have the same determinant. This is the transpose of the matrix with determinant −3 on the det page:

In[11]:=
#cas [det] !![1, 4, 7; 2, 5, 8; 3, 6, 10]
Out[11]=

determinant

-3
Domain
ℚ^(3×3)
Input (matrix)
!![1, 4, 7; 2, 5, 8; 3, 6, 10]

Checked by Lean’s kernel: Determinant

!![1, 4, 7; 2, 5, 8; 3, 6, 10].det = -3
The certificate: 1 checked step
  1. Determinant

    !![1, 4, 7; 2, 5, 8; 3, 6, 10].det = -3

    Checked by Lean’s kernel

Possible Issues (2)

Every row needs the same number of entries:

In[12]:=
#cas [transpose] !![1, 2; 3]
Out[12]=

Error

the rows of the matrix have different lengths

A vector ![1, 2, 3] is not a matrix. Write a row as !![1, 2, 3], as above:

In[13]:=
#cas [transpose] ![1, 2, 3]
Out[13]=

Error

expected a matrix `!![a, b; c, d]` or `[[a, b], [c, d]]`

Neat Examples (1)

The Pythagorean triple 3,4,5 gives a rotation with rational entries. Its transpose is its inverse:

In[14]:=
#cas [transpose] !![3/5, -4/5; 4/5, 3/5]
Out[14]=

transpose

(3545−4535)
!![3/5, 4/5; -4/5, 3/5]
Domain
ℚ^(2×2)
Input (matrix)
!![3/5, -4/5; 4/5, 3/5]

Checked by Lean’s kernel: Decided by kernel evaluation

!![3 / 5, -(4 / 5); 4 / 5, 3 / 5].transpose = !![3 / 5, 4 / 5; -(4 / 5), 3 / 5]
The certificate: 1 checked step
  1. Decided by kernel evaluation

    !![3 / 5, -(4 / 5); 4 / 5, 3 / 5].transpose = !![3 / 5, 4 / 5; -(4 / 5), 3 / 5]

    Checked by Lean’s kernel

In[15]:=
#cas [inverse] !![3/5, -4/5; 4/5, 3/5]
Out[15]=

inverse

(3545−4535)
!![3/5, 4/5; -4/5, 3/5]
Domain
ℚ^(2×2)
Input (matrix)
!![3/5, -4/5; 4/5, 3/5]

Checked by Lean’s kernel: Inverse from the product B * A = 1

!![3 / 5, -(4 / 5); 4 / 5, 3 / 5]⁻¹ = !![3 / 5, 4 / 5; -(4 / 5), 3 / 5]
The certificate: 1 checked step
  1. Inverse from the product B * A = 1

    !![3 / 5, -(4 / 5); 4 / 5, 3 / 5]⁻¹ = !![3 / 5, 4 / 5; -(4 / 5), 3 / 5]

    Checked by Lean’s kernel

See Also

dot · trace · positiveDefinite · inverse · det