Skip to content

Commit 0dd5c91

Browse files
committed
chore(LinearAlgebra/Ray): remove a defeq abuse (#39477)
Previously, the code uses Subtype constructor to construct RayVector, and the instance cannot see through this. As a common practice, RayVector declares its own constructor to resolve this
1 parent 8e3a342 commit 0dd5c91

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

Mathlib/LinearAlgebra/Ray.lean

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,20 @@ set_option linter.unusedVariables false in
5050
def RayVector (R M : Type*) [Zero M] :=
5151
{ v : M // v ≠ 0 }
5252

53+
/-- Equivalence between `RayVector` and non-zero vectors. -/
54+
def RayVector.equiv (R M : Type*) [Zero M] : RayVector R M ≃ { v : M // v ≠ 0 } :=
55+
Equiv.refl _
56+
5357
instance RayVector.coe {R M : Type*} [Zero M] : CoeOut (RayVector R M) M where
54-
coe := Subtype.val
58+
coe x := (equiv R M x).val
59+
60+
@[simp]
61+
theorem RayVector.coe_equiv_symm {R M : Type*} [Zero M] {v : M} (h : v ≠ 0) :
62+
(RayVector.equiv R M).symm ⟨v, h⟩ = v := rfl
63+
64+
@[ext]
65+
theorem RayVector.ext {R M : Type*} [Zero M] {x y : RayVector R M} (h : (x : M) = (y : M)) :
66+
x = y := Subtype.ext h
5567

5668
instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) :=
5769
⟨Classical.indefiniteDescription _ <| exists_ne (0 : M)⟩
@@ -225,7 +237,7 @@ variable (R)
225237

226238
/-- The ray given by a nonzero vector. -/
227239
def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M :=
228-
⟦⟨v, h⟩⟧
240+
(RayVector.equiv R M).symm ⟨v, h⟩⟧
229241

230242
/-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/
231243
theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv))
@@ -371,17 +383,16 @@ namespace RayVector
371383

372384
/-- Negating a nonzero vector. -/
373385
instance {R : Type*} : Neg (RayVector R M) :=
374-
fun v => ⟨-v, neg_ne_zero.2 v.prop⟩⟩
386+
fun v => (equiv R M).symm ⟨-v, neg_ne_zero.2 v.prop⟩⟩
375387

376388
/-- Negating a nonzero vector commutes with coercion to the underlying module. -/
377389
@[simp, norm_cast]
378390
theorem coe_neg {R : Type*} (v : RayVector R M) : ↑(-v) = -(v : M) :=
379391
rfl
380392

381-
set_option backward.isDefEq.respectTransparency false in
382393
/-- Negating a nonzero vector twice produces the original vector. -/
383394
instance {R : Type*} : InvolutiveNeg (RayVector R M) where
384-
neg_neg v := by rw [Subtype.ext_iff, coe_neg, coe_neg, neg_neg]
395+
neg_neg v := by rw [RayVector.ext_iff, coe_neg, coe_neg, neg_neg]
385396

386397
/-- If two nonzero vectors are equivalent, so are their negations. -/
387398
@[simp]

0 commit comments

Comments
 (0)