Zulip Chat Archive

Stream: maths

Topic: Proving product of two matrices


Anirudh Suresh (Mar 20 2025 at 17:20):

What are tactics to use to prove that the product of simple matrices are equal to another matrix?

import Mathlib
open scoped Matrix


theorem t1:![![1, 0, 0, 0],
             ![0, 1, 0, 0],
             ![0, 0, 0, 1],
             ![0, 0, 1, 0]] *


           ![![1, 0, 0, 0],
             ![0, 0, 0, 1],
             ![0, 0, 1, 0],
             ![0, 1, 0, 0]] *


           ![![1, 0, 0, 0],
             ![0, 1, 0, 0],
             ![0, 0, 0, 1],
             ![0, 0, 1, 0]] =


          ![![1, 0, 0, 0],
            ![0, 0, 1, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1]]:=
  by {
    sorry
  }

Aaron Liu (Mar 20 2025 at 17:23):

import Mathlib
open scoped Matrix


example : ![![1, 0, 0, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1],
            ![0, 0, 1, 0]] *


          ![![1, 0, 0, 0],
            ![0, 0, 0, 1],
            ![0, 0, 1, 0],
            ![0, 1, 0, 0]] *


          ![![1, 0, 0, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1],
            ![0, 0, 1, 0]] =


          ![![1, 0, 0, 0],
            ![0, 0, 1, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1]] := by
  -- tactic 'decide' proved that the proposition ... is false
  decide

Eric Wieser (Mar 20 2025 at 17:28):

Matrices are !![...] not ![![...]]

Eric Wieser (Mar 20 2025 at 17:28):

If you picked up the ![![ from documentation somewhere, can you say where so that we can fix it?

Anirudh Suresh (Mar 20 2025 at 17:34):

I tried to define it as a vector of vectors which is why I made that mistake. The type checker did not give me any error so I assumed it was right.

Eric Wieser (Mar 20 2025 at 17:34):

What you got was a vector of vectors, which has elementwise multiplication

Anirudh Suresh (Mar 20 2025 at 17:36):

import Mathlib
open scoped Matrix

def A : Matrix (Fin 4) (Fin 4)  :=
  ![ ![1, 0, 0, 0],
     ![0, 0, 0, 1],
     ![0, 0, 1, 0],
     ![0, 1, 0, 0] ]

Why is the type checker not showing any error for this though when they are clearly different types in terms of how the operations work on them

Eric Wieser (Mar 20 2025 at 17:37):

Ah, this is indeed unfortunate. The problem is that the types are equal at semireducible equality

Eric Wieser (Mar 20 2025 at 17:37):

Adding a Matrix.of to explicit convert from that representation to a Matrix is the right thing to do, but I agree it's not very discoverable

Yakov Pechersky (Mar 20 2025 at 17:41):

import Mathlib
open scoped Matrix


example : Matrix.of ![![1, 0, 0, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1],
            ![0, 0, 1, 0]] *


          Matrix.of ![![1, 0, 0, 0],
            ![0, 0, 0, 1],
            ![0, 0, 1, 0],
            ![0, 1, 0, 0]] *


          Matrix.of ![![1, 0, 0, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1],
            ![0, 0, 1, 0]] =


          Matrix.of ![![1, 0, 0, 0],
            ![0, 0, 1, 0],
            ![0, 1, 0, 0],
            ![0, 0, 0, 1]] := by
  ext i j
  fin_cases i <;> fin_cases j <;> simp

Yakov Pechersky (Mar 20 2025 at 17:42):

decide also works, but that's because of no free vars. fin_cases followed by simp will work in a situation where there are variables in the matrices.

Anirudh Suresh (Mar 20 2025 at 17:49):

ahh I see. Thanks!


Last updated: May 02 2025 at 03:31 UTC