Skip to content

Commit 737db8d

Browse files
feat(Analysis.NormedSpace): add normalized vectors (#26308)
Add normalized vectors to Mathlib (zero vector for zero vector, the corresponding unit vectors for nonzero vectors)
1 parent 59c724d commit 737db8d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,7 @@ import Mathlib.Analysis.NormedSpace.MStructure
18631863
import Mathlib.Analysis.NormedSpace.Multilinear.Basic
18641864
import Mathlib.Analysis.NormedSpace.Multilinear.Curry
18651865
import Mathlib.Analysis.NormedSpace.MultipliableUniformlyOn
1866+
import Mathlib.Analysis.NormedSpace.Normalize
18661867
import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics
18671868
import Mathlib.Analysis.NormedSpace.OperatorNorm.Basic
18681869
import Mathlib.Analysis.NormedSpace.OperatorNorm.Bilinear
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/-
2+
Copyright (c) 2025 Ilmārs Cīrulis. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Ilmārs Cīrulis, Alex Meiburg
5+
-/
6+
import Mathlib.Analysis.RCLike.Basic
7+
8+
/-!
9+
# Normalized vector
10+
11+
Function that returns unit length vector that points in the same direction
12+
(if the given vector is nonzero vector) or returns zero vector
13+
(if the given vector is zero vector).
14+
-/
15+
16+
variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V]
17+
18+
/-- For a nonzero vector `x`, `normalize x` is the unit-length vector that points
19+
in the same direction as `x`. If `x = 0`, then `normalize x = 0`. -/
20+
noncomputable def NormedSpace.normalize (x : V) : V := ‖x‖⁻¹ • x
21+
22+
namespace NormedSpace
23+
24+
@[simp]
25+
theorem normalize_zero_eq_zero : normalize (0 : V) = 0 := by
26+
simp [normalize]
27+
28+
@[simp]
29+
theorem norm_smul_normalize (x : V) : ‖x‖ • normalize x = x := by
30+
by_cases hx : x = 0
31+
all_goals simp [normalize, hx]
32+
33+
@[simp]
34+
lemma norm_normalize_eq_one_iff {x : V} : ‖normalize x‖ = 1 ↔ x ≠ 0 :=
35+
by rintro hx rfl; simp at hx, fun h ↦ by simp [normalize, h, norm_smul]⟩
36+
37+
lemma normalize_eq_self_of_norm_eq_one {x : V} (h : ‖x‖ = 1) : normalize x = x := by
38+
simp [normalize, h]
39+
40+
@[simp]
41+
theorem normalize_normalize (x : V) : normalize (normalize x) = normalize x := by
42+
by_cases hx : x = 0
43+
· simp [hx]
44+
· simp [normalize_eq_self_of_norm_eq_one, hx]
45+
46+
@[simp]
47+
theorem normalize_neg (x : V) : normalize (- x) = - normalize x := by
48+
simp [normalize]
49+
50+
theorem normalize_smul_of_pos {r : ℝ} (hr : 0 < r) (x : V) :
51+
normalize (r • x) = normalize x := by
52+
simp [normalize, norm_smul, smul_smul, abs_of_pos hr, mul_assoc, inv_mul_cancel₀ hr.ne']
53+
54+
theorem normalize_smul_of_neg {r : ℝ} (hr : r < 0) (x : V) :
55+
normalize (r • x) = - normalize x := by
56+
simpa using normalize_smul_of_pos (show 0 < -r by linarith) (-x)
57+
58+
end NormedSpace

0 commit comments

Comments
 (0)