Zulip Chat Archive
Stream: new members
Topic: matrix and LinearIndependent
Hbz (Aug 12 2025 at 12:38):
import Mathlib
open Matrix
def C : Matrix (Fin 3) (Fin 3) ℝ :=
fun i j => (i.val + 1) + (j.val + 1) - 1
variable (v₁:Fin 3 → ℝ)( v₂:Fin 3 → ℝ)( v₃ : Fin 3 → ℝ)
def V (v₁ v₂ v₃ : Fin 3 → ℝ) : Matrix (Fin 3) (Fin 3) ℝ := ![v₁, v₂, v₃]
lemma V_det_ne_zero (v₁ v₂ v₃ : Fin 3 → ℝ )(h : LinearIndependent ℝ (V v₁ v₂ v₃)): det (V v₁ v₂ v₃) ≠ 0 := by
erw[V]
by_contra h
erw[← exists_mulVec_eq_zero_iff_aux] at h
rcases h with ⟨v,⟨hv1,hv2⟩⟩
have h_lin_comb : ∑ i : Fin 3, v i • ![v₁, v₂, v₃] i = 0 := by
ext k
simp [Pi.zero_apply, Finset.sum_apply]
sorry
sorry
I don't know how to prove this seemingly obvious lemma. Why isn't this theorem, which seems so obvious to me, available in mathlib? Does it involve type conversion issues? (I'm really not good at type conversion. Alas.)
Eric Wieser (Aug 12 2025 at 12:41):
det (V v₁ v₂ v₃) is defeq abuse, it should be det (Matrix.of (V v₁ v₂ v₃))
Kenny Lau (Aug 12 2025 at 12:53):
V itself is defeq abuse
Hbz (Aug 12 2025 at 13:05):
Uhh,so how can i correct the def of V
Kenny Lau (Aug 12 2025 at 13:07):
use Matrix.of
Kenny Lau (Aug 12 2025 at 13:08):
actually C is also defeq abuse
Kenny Lau (Aug 12 2025 at 13:08):
maybe we should just seal Matrix
Kenny Lau (Aug 12 2025 at 13:08):
why do you have +1 +1 -1?
Hbz (Aug 12 2025 at 13:09):
import Mathlib
open Matrix
def C : Matrix (Fin 3) (Fin 3) ℝ :=
fun i j => (i.val + 1) + (j.val + 1) - 1
def V (v₁ v₂ v₃ : Fin 3 → ℝ) : Matrix (Fin 3) (Fin 3) ℝ := ![v₁, v₂, v₃]
lemma V_det_ne_zero (v₁ v₂ v₃ : Fin 3 → ℝ )(h : LinearIndependent ℝ (V v₁ v₂ v₃)): det (Matrix.of (V v₁ v₂ v₃)) ≠ 0 := by
erw[V]
by_contra h_d
erw[← exists_mulVec_eq_zero_iff_aux] at h_d
rcases h_d with ⟨v,⟨hv1,hv2⟩⟩
have h_lin_comb : ∑ i : Fin 3, v i • ![v₁, v₂, v₃] i = 0 := by
ext k
simp [Pi.zero_apply, Finset.sum_apply]
sorry
sorry
lemma det_C_eq_zero : det C = 0 := by
-- 展开为三阶行列式计算
rw [det_fin_three C]
-- 按定义计算每个元素
simp only [C, Fin.val_zero, Fin.val_one, Fin.val_two,
zero_add, Nat.cast_one, Nat.cast_add, Nat.cast_succ]
-- 简化表达式
ring_nf
theorem main_theorem (v₁ v₂ v₃ : Fin 3 → ℝ )(hm : LinearIndependent ℝ ![v₁, v₂, v₃]) :
det (C * (V v₁ v₂ v₃)) = 0 := by
-- 应用行列式乘法公式
rw [det_mul]
have h : det C = 0 := det_C_eq_zero
have hV : det (V v₁ v₂ v₃) ≠ 0 := by exact V_det_ne_zero v₁ v₂ v₃ hm
exact (mul_eq_zero_iff_right hV).mpr h
Hbz (Aug 12 2025 at 13:10):
I use C in the theorem
Kenny Lau (Aug 12 2025 at 13:10):
h is defeq abuse in the other way, which I suppose is tolerable
Eric Wieser (Aug 12 2025 at 13:11):
I think it helps to take a step back here and thing about what the general form of the lemma is
Eric Wieser (Aug 12 2025 at 13:11):
I think the one you want is genuinely missing
Kenny Lau (Aug 12 2025 at 13:11):
why do you know about erw...
Eric Wieser (Aug 12 2025 at 13:11):
docs#Matrix.linearIndependent_rows_of_det_ne_zero is the other direction
Kenny Lau (Aug 12 2025 at 13:11):
please don't use erw
Kenny Lau (Aug 12 2025 at 13:12):
@Hbz I have cleaned up your code:
import Mathlib
open Matrix
def C : Matrix (Fin 3) (Fin 3) ℝ :=
.of fun i j => (i.val + 1) + (j.val + 1) - 1
variable (v₁ v₂ v₃ : Fin 3 → ℝ)
-- temporary def
def V (v₁ v₂ v₃ : Fin 3 → ℝ) : Matrix (Fin 3) (Fin 3) ℝ :=
.of ![v₁, v₂, v₃]
lemma det_V_ne_zero (v₁ v₂ v₃ : Fin 3 → ℝ) (h : LinearIndependent ℝ ![v₁, v₂, v₃]) :
det (V v₁ v₂ v₃) ≠ 0 := by
sorry
Kenny Lau (Aug 12 2025 at 13:12):
and yeah you shouldn't prove this if it's a missing library lemma
Kenny Lau (Aug 12 2025 at 13:12):
(but i guess it can still be a good exercise)
Kenny Lau (Aug 12 2025 at 13:12):
maybe this can be your first PR to mathlib!
Hbz (Aug 12 2025 at 13:13):
Kenny Lau said:
why do you know about
erw...
I saw someone using it, so I gave it a try. Is there any problem with erw?
Kenny Lau (Aug 12 2025 at 13:13):
it's too powerful, you don't need it
Richard Copley (Aug 12 2025 at 13:13):
rw [← isUnit_iff_ne_zero, ← isUnit_iff_isUnit_det]
exact linearIndependent_rows_iff_isUnit.mp h
Hbz (Aug 12 2025 at 13:14):
Kenny Lau said:
it's too powerful, you don't need it
ok
Hbz (Aug 12 2025 at 13:14):
Richard Copley said:
rw [← isUnit_iff_ne_zero, ← isUnit_iff_isUnit_det] exact linearIndependent_rows_iff_isUnit.mp h
No way, dude, you're so awesome!
Kenny Lau (Aug 12 2025 at 13:15):
oh wow
Kenny Lau (Aug 12 2025 at 13:15):
@Hbz so do you want to PR this?
Hbz (Aug 12 2025 at 13:16):
Of course I'd like to.
Hbz (Aug 12 2025 at 13:16):
but i don't know how :joy:
Kenny Lau (Aug 12 2025 at 13:17):
https://leanprover-community.github.io/contribute/index.html
Hbz (Aug 12 2025 at 13:18):
I see :ok:
Richard Copley (Aug 12 2025 at 13:28):
Cleaned up:
import Mathlib
open Matrix
lemma det_V_ne_zero (v₁ v₂ v₃ : Fin 3 → ℝ) (h : LinearIndependent ℝ ![v₁, v₂, v₃]) :
det (.of ![v₁, v₂, v₃]) ≠ 0 := by
rwa [← isUnit_iff_ne_zero, ← isUnit_iff_isUnit_det, ← linearIndependent_rows_iff_isUnit, of_row]
Hbz (Aug 12 2025 at 13:32):
Bro, let me ask one more thing. How did you come up with the idea of using invertible elements to prove this proposition? This kind of mathematical intuition is really stunning!
Aaron Liu (Aug 12 2025 at 13:33):
@loogle Matrix.det _ = 0
loogle (Aug 12 2025 at 13:33):
:search: Matrix.det_zero_of_row_eq, Matrix.det_updateRow_eq_zero, and 13 more
Aaron Liu (Aug 12 2025 at 13:35):
@loogle Matrix.det _ ≠ 0
loogle (Aug 12 2025 at 13:35):
:search: Matrix.linearIndependent_rows_of_det_ne_zero, Matrix.linearIndependent_cols_of_det_ne_zero, and 33 more
Hbz (Aug 12 2025 at 13:36):
Oh, so that's how it is. It seems I should use the robot flexibly. :joy:
Aaron Liu (Aug 12 2025 at 13:37):
surprisingly, it gave few useful results this time
Aaron Liu (Aug 12 2025 at 13:37):
but searching a lot usually gets me useful theorems eventually
Hbz (Aug 12 2025 at 13:39):
Aaron Liu said:
surprisingly, it gave few useful results this time
Actually, It's already a great help to be able to provide some ideas.
Richard Copley (Aug 12 2025 at 13:47):
Looking at what that proof proves, maybe this is better. But it is difficult to know what the most useful level of generality is.
import Mathlib
open Matrix
lemma linearIndependent_rows_iff_det_ne_zero {R α : Type*} [Field R] [Fintype α] [DecidableEq α]
{m : Matrix α α R} : LinearIndependent R m.row ↔ m.det ≠ 0 := by
rw [linearIndependent_rows_iff_isUnit, isUnit_iff_isUnit_det, isUnit_iff_ne_zero]
Hbz (Aug 12 2025 at 13:51):
Richard Copley said:
Looking at what that proof proves, maybe this is better. But it is difficult to know what the most useful level of generality is.
import Mathlib open Matrix lemma linearIndependent_iff_det_ne_zero {R α : Type*} [Field R] [Fintype α] [DecidableEq α] {m: Matrix α α R} : LinearIndependent R m.row ↔ det m ≠ 0 := by rw [linearIndependent_rows_iff_isUnit, isUnit_iff_isUnit_det, isUnit_iff_ne_zero]
I think this one is more universally significant.
Do we need another about
LinearIndependent R m.col ↔ det m ≠ 0
Kenny Lau (Aug 12 2025 at 13:51):
well I wanted Hbz to find this generalisation on their own...
Hbz (Aug 12 2025 at 13:52):
Kenny Lau said:
well I wanted Hbz to find this generalisation on their own...
I want to too. :smiling_face_with_tear:
vxctyxeha (Aug 12 2025 at 13:53):
老哥
vxctyxeha (Aug 12 2025 at 13:53):
@Hbz
Hbz (Aug 12 2025 at 13:53):
怎么出现了同胞
vxctyxeha (Aug 12 2025 at 13:53):
你也在做优化吗
Hbz (Aug 12 2025 at 13:54):
(deleted)
vxctyxeha (Aug 12 2025 at 13:59):
我知道你的id了 :grinning:
Ruben Van de Velde (Aug 12 2025 at 14:35):
This zulip instance uses English.
Eric Wieser (Aug 12 2025 at 15:26):
Richard Copley said:
But it is difficult to know what the most useful level of generality is.
I think we want this for a (char_zero?) integral domain, not just a field
Richard Copley (Aug 12 2025 at 21:03):
The lemmas I used are rather weak, in that their assumptions are strong -- mostly either DivisionRing or Field. Maybe some of them can be strengthened (a big job) or bypassed (who knows?). In the mean time, maybe there's something close to what I stated that would be nice to have. Maybe not! It's not too hard to do inline.
Eric Wieser (Aug 12 2025 at 21:10):
Bypassed I think is probably the approach
Eric Wieser (Aug 12 2025 at 21:11):
but indeed, we probably should have the lemma in mathlib with a TODO comment rather than not having it at all
Eric Wieser (Aug 12 2025 at 21:11):
Previous thread:
Last updated: Dec 20 2025 at 21:32 UTC