Skip to content

Commit 51ef4a9

Browse files
kim-emclaude
andcommitted
fix(Analysis/InnerProductSpace): define instInnerProductSpaceRealComplex as RCLike.toInnerProductSpaceReal
Previously `instInnerProductSpaceRealComplex` was defined as `InnerProductSpace.complexToReal`, which internally uses `NormedSpace.restrictScalars ℝ ℂ ℂ`. The `Module ℝ ℂ` from that path disagrees with `Algebra.toModule ℝ ℂ` at `.instances` transparency, causing `rw [one_smul]` to fail with `set_option backward.isDefEq.respectTransparency true`. The fix moves the instance to after `RCLike.toInnerProductSpaceReal` and defines it as `RCLike.toInnerProductSpaceReal` directly. The `NormedSpace ℝ ℂ` in `RCLike.toInnerProductSpaceReal` is synthesized in a context with only `[RCLike 𝕜]`, so synthesis finds `NormedAlgebra.toNormedSpace` (non-leaky) rather than `NormedSpace.complexToReal = RestrictScalars.normedSpace` (leaky). The two instances were already proven equal by `rfl` in the existing file (since `InnerProductSpace.complexToReal = InnerProductSpace.rclikeToReal ℂ ℂ` and `RCLike.toInnerProductSpaceReal` use the same underlying `Inner.rclikeToReal`); this PR just makes the canonical non-leaky one the definition. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cd57315 commit 51ef4a9

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Mathlib/Analysis/InnerProductSpace/Basic.lean

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,12 +957,6 @@ def InnerProductSpace.complexToReal [SeminormedAddCommGroup G] [InnerProductSpac
957957
InnerProductSpace ℝ G :=
958958
InnerProductSpace.rclikeToReal ℂ G
959959

960-
instance : InnerProductSpace ℝ ℂ := InnerProductSpace.complexToReal
961-
962-
@[simp]
963-
protected theorem Complex.inner (w z : ℂ) : ⟪w, z⟫_ℝ = (z * conj w).re :=
964-
rfl
965-
966960
end RCLikeToReal
967961

968962
/-- An `RCLike` field is a real inner product space. -/
@@ -976,12 +970,22 @@ noncomputable instance RCLike.toInnerProductSpaceReal : InnerProductSpace ℝ
976970
show re (_ * _) = _ * re (_ * _) by
977971
simp only [mul_re, conj_re, conj_im, conj_trivial, smul_re, smul_im]; ring
978972

979-
-- The instance above does not create diamonds for concrete `𝕜`:
973+
-- The instance above directly subsumes the complexToReal construction for ℂ.
974+
-- We define this here (after `RCLike.toInnerProductSpaceReal`) rather than above, so that
975+
-- `fast_instance%` and instance synthesis can find the canonical non-leaky form.
976+
noncomputable instance : InnerProductSpace ℝ ℂ := RCLike.toInnerProductSpaceReal
977+
978+
-- Check that this does not create diamonds for concrete `𝕜`:
980979
example : (innerProductSpace : InnerProductSpace ℝ ℝ) = RCLike.toInnerProductSpaceReal := rfl
981980
example :
982981
(instInnerProductSpaceRealComplex : InnerProductSpace ℝ ℂ) = RCLike.toInnerProductSpaceReal :=
983982
rfl
984983

984+
open scoped InnerProductSpace in
985+
@[simp]
986+
protected theorem Complex.inner (w z : ℂ) : ⟪w, z⟫_ℝ = (z * conj w).re :=
987+
rfl
988+
985989
section IsPosSemidef
986990

987991
variable [NormedAddCommGroup E] [InnerProductSpace ℝ E]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/-
2+
Copyright (c) 2024 Kim Morrison. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kim Morrison
5+
-/
6+
import Mathlib.Analysis.InnerProductSpace.Basic
7+
8+
/-!
9+
# Test: `instInnerProductSpaceRealComplex` is canonical at `instances` transparency
10+
11+
Previously `instInnerProductSpaceRealComplex` was defined as `InnerProductSpace.complexToReal`,
12+
which goes through `NormedSpace.restrictScalars ℝ ℂ ℂ`. The `Module ℝ ℂ` arising from that path
13+
disagrees with `Algebra.toModule ℝ ℂ` at `.instances` transparency, causing `rw [one_smul]` to
14+
fail with `set_option backward.isDefEq.respectTransparency true`.
15+
16+
The fix redefines `instInnerProductSpaceRealComplex := RCLike.toInnerProductSpaceReal`, whose
17+
`NormedSpace ℝ ℂ` comes from `NormedAlgebra.toNormedSpace` (via `RCLike.toNormedAlgebra`),
18+
so its `Module ℝ ℂ` agrees with `Algebra.toModule` at `.instances` transparency.
19+
-/
20+
21+
-- The `Module ℝ ℂ` from `InnerProductSpace ℝ ℂ` now agrees with `Algebra.toModule` at instances
22+
-- transparency.
23+
example : (inferInstance : InnerProductSpace ℝ ℂ).toNormedSpace.toModule =
24+
(inferInstance : Algebra ℝ ℂ).toModule := by
25+
with_reducible_and_instances rfl
26+
27+
-- As a consequence, `rw [one_smul]` works with strict transparency.
28+
set_option backward.isDefEq.respectTransparency true in
29+
example (z : ℂ) : (1 : ℝ) • z = z := by
30+
rw [one_smul]

0 commit comments

Comments
 (0)