Zulip Chat Archive
Stream: mathlib4
Topic: Instances for EuclideanSpace
Sebastian Kumar (Aug 10 2025 at 17:03):
I was working with EuclideanSpace and I would like to have access to the following instances:
import Mathlib
variable {𝕜 : Type*} [RCLike 𝕜]
instance (n : ℕ) : Infinite (EuclideanSpace 𝕜 (Fin (n + 1))) :=
PreconnectedSpace.infinite
instance (n : ℕ) : Fact (Module.finrank 𝕜 (EuclideanSpace 𝕜 (Fin n)) = n) :=
⟨finrank_euclideanSpace_fin⟩
In particular, the second allows the use of stereographic projection in EuclideanSpace (stereographic' from Mathlib.Geometry.Manifold.Instances.Sphere). However, @Kenny Lau pointed out to me why certain theorems aren't given instances. Do the above instances have the right level of generality to be added to Mathlib? If so, where would I add them? I was thinking the second could go after the definition of finrank_euclideanSpace_fin in Mathlib.Analysis.InnerProductSpace.PiL2, but I wasn't sure about the first.
Kenny Lau (Aug 10 2025 at 17:03):
See the comment I left on your PR for the first one
Kenny Lau (Aug 10 2025 at 17:04):
I don't see the point of the second one. We shouldn't just add every Fact to Mathlib
Sebastian Kumar (Aug 10 2025 at 17:05):
The second one was because the definition of stereographic' needs such a Fact as an implicit argument. Is there a better way to get around this?
Kenny Lau (Aug 10 2025 at 17:06):
aha, in that case, yes, please PR with that justification
Wuyang (Aug 11 2025 at 19:05):
Sounds like the first instance needs revisiting per Kenny’s earlier comment, but the second seems justified if it enables stereographic' directly, worth a PR with that reasoning. Also, try searching related usage patterns on LeanFinder.
Wuyang (Aug 11 2025 at 19:06):
@leanfinder Adding Infinite and finrank Fact instances for EuclideanSpace to support stereographic projection in Lean Mathlib
leanfinder (Aug 11 2025 at 19:06):
Here’s what I found:
- definition stereographic' (n : ℕ) [Fact (finrank ℝ E = n + 1)] (v : sphere (0 : E) 1) :
PartialHomeomorph (sphere (0 : E) 1) (EuclideanSpace ℝ (Fin n)) :=
stereographic (norm_eq_of_mem_sphere v) ≫ₕ
(OrthonormalBasis.fromOrthogonalSpanSingleton n
(ne_zero_of_mem_unit_sphere v)).repr.toHomeomorph.toPartialHomeomorph "Given a natural number and a real inner product space with , the stereographic projection
stereographic' n vcentered at a point on the unit sphere in is a partial homeomorphism between the sphere (excluding ) and the Euclidean space .
This is obtained by composing:
- The standard stereographic projection
stereographic(which maps to the orthogonal complement ) - A linear isometry from to given by an orthonormal basis" (score: 0.767)
-
theorem stereographic'_symm_apply {n : ℕ} [Fact (finrank ℝ E = n + 1)] (v : sphere (0 : E) 1) (x : EuclideanSpace ℝ (Fin n)) : ((stereographic' n v).symm x : E) = let U : (ℝ ∙ (v : E))ᗮ ≃ₗᵢ[ℝ] EuclideanSpace ℝ (Fin n) := (OrthonormalBasis.fromOrthogonalSpanSingleton n (ne_zero_of_mem_unit_sphere v)).repr (‖(U.symm x : E)‖ ^ 2 + 4)⁻¹ • (4 : ℝ) • (U.symm x : E) + (‖(U.symm x : E)‖ ^ 2 + 4)⁻¹ • (‖(U.symm x : E)‖ ^ 2 - 4) • v.val := by simp [real_inner_comm, stereographic, stereographic', ← Submodule.coe_norm] "Let be a finite-dimensional real inner product space with , and let be a point on the unit sphere in . For any point , the inverse stereographic projection is given by:
$$
\text{stereographic'}_v^{-1}(x) = \frac{4}{\|U^{-1}x\|^2 + 4} \cdot U^{-1}x + \frac{\|U^{-1}x\|^2 - 4}{\|U^{-1}x\|^2 + 4} \cdot v
$$
where is the linear isometry defined via an orthonormal basis for the orthogonal complement of ." (score: 0.755) -
theorem stereographic'_target {n : ℕ} [Fact (finrank ℝ E = n + 1)] (v : sphere (0 : E) 1) : (stereographic' n v).target = Set.univ := by simp [stereographic'] "For any natural number and a real inner product space with , the target of the stereographic projection
stereographic' n vcentered at a point on the unit sphere in is equal to the entire Euclidean space . That is, the projection maps bijectively from the sphere (minus the point ) onto all of ." (score: 0.747) -
instance EuclideanSpace.instChartedSpaceSphere {n : ℕ} [Fact (finrank ℝ E = n + 1)] : ChartedSpace (EuclideanSpace ℝ (Fin n)) (sphere (0 : E) 1) where atlas := {f | ∃ v : sphere (0 : E) 1, f = stereographic' n v} chartAt v := stereographic' n (-v) mem_chart_source v := by simpa using ne_neg_of_mem_unit_sphere ℝ v chart_mem_atlas v := ⟨-v, rfl⟩ "For any natural number and real inner product space with , the unit sphere in is a charted space modeled on the Euclidean space ." (score: 0.739)
-
private lemma stereographic'_neg {n : ℕ} [Fact (finrank ℝ E = n + 1)] (v : sphere (0 : E) 1) : stereographic' n (-v) v = 0 := by dsimp [stereographic'] simp only [EmbeddingLike.map_eq_zero_iff] apply stereographic_neg_apply "For a vector on the unit sphere in an -dimensional real inner product space , the modified stereographic projection
stereographic'centered at maps the antipodal point to the origin in . This is due to the symmetry of the stereographic projection and the properties of the orthogonal complement." (score: 0.732) -
theorem stereographic'_source {n : ℕ} [Fact (finrank ℝ E = n + 1)] (v : sphere (0 : E) 1) : (stereographic' n v).source = { v }ᶜ := by simp [stereographic'] "For any natural number and a real inner product space with , the source of the stereographic projection centered at a point on the unit sphere in is the complement of the singleton set in the sphere. That is, the projection is defined everywhere on the sphere except at the point itself." (score: 0.731)
-
theorem finrank_euclideanSpace_fin {n : ℕ} : Module.finrank 𝕜 (EuclideanSpace 𝕜 (Fin n)) = n := by simp "For any field satisfying the
RCLikecondition (which includes and ) and any natural number , the finite rank of the Euclidean space over is equal to , i.e.,
" (score: 0.725) -
instance instChartedSpaceEuclideanSpaceRealFinElemHAddNatOfNatSphere (n : ℕ) : ChartedSpace (EuclideanSpace ℝ (Fin n)) (sphere (0 : EuclideanSpace ℝ (Fin (n + 1))) 1) := have := Fact.mk (@finrank_euclideanSpace_fin ℝ _ (n + 1)) EuclideanSpace.instChartedSpaceSphere "For any natural number , the unit sphere in the Euclidean space is a charted space modeled on ." (score: 0.721)
-
theorem finrank_euclideanSpace : Module.finrank 𝕜 (EuclideanSpace 𝕜 ι) = Fintype.card ι := by simp [EuclideanSpace, PiLp, WithLp] "For any field satisfying the
RCLikecondition (which includes and ) and any finite indexing type , the finite rank of the Euclidean space over is equal to the cardinality of , i.e.,
" (score: 0.720) -
instance instIsManifoldRealEuclideanSpaceFinModelWithCornersSelfTopWithTopENatElemHAddNatOfNatSphere (n : ℕ) : IsManifold (𝓡 n) ω (sphere (0 : EuclideanSpace ℝ (Fin (n + 1))) 1) := haveI := Fact.mk (@finrank_euclideanSpace_fin ℝ _ (n + 1)) EuclideanSpace.instIsManifoldSphere "For any natural number , the unit sphere in the Euclidean space is an analytic manifold modeled on with the analytic structure given by the model with corners ." (score: 0.714)
Sebastian Kumar (Aug 11 2025 at 22:00):
I thought I should update that I made the PR: https://github.com/leanprover-community/mathlib4/pull/28198. However, it seems to be falling to the CI bug from #mathlib4 > Failing CI :(.
Bryan Gin-ge Chen (Aug 11 2025 at 22:36):
You can try merging master into your branch again; hopefully the error will go away. If not, please report it again!
Last updated: Dec 20 2025 at 21:32 UTC