File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,9 +45,13 @@ We also register the fact that `ℂ` is an `RCLike` field.
4545
4646assert_not_exists Absorbs
4747
48+ namespace Complex
49+
4850/-- A shortcut instance to ensure computability; otherwise we get the noncomputable instance
4951`Complex.instNormedField.toNormedModule.toModule`. -/
50- instance Complex.instModuleSelf : Module ℂ ℂ := delta% inferInstance
52+ instance instModuleSelf : Module ℂ ℂ := delta% inferInstance
53+
54+ end Complex
5155
5256noncomputable section
5357
Original file line number Diff line number Diff line change @@ -389,19 +389,34 @@ instance commRing : CommRing ℂ :=
389389 mul_one := by intros; ext <;> simp
390390 mul_comm := by intros; ext <;> simp <;> ring }
391391
392+ section computable_shortcuts
393+
392394/-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field`
393395instance. -/
394- instance : Ring ℂ := by infer_instance
396+ instance : Ring ℂ :=
397+ delta% inferInstance
398+
399+ /-- This shortcut instance ensures we do not find `NonUnitalCommRing` via the noncomputable
400+ `instCommCStarAlgebraComplex` instance. -/
401+ instance : NonUnitalCommRing ℂ :=
402+ delta% inferInstance
395403
396404/-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable
397405`Complex.field` instance. -/
398406instance : CommSemiring ℂ :=
399- inferInstance
407+ delta% inferInstance
400408
401409/-- This shortcut instance ensures we do not find `Semiring` via the noncomputable
402410`Complex.field` instance. -/
403411instance : Semiring ℂ :=
404- inferInstance
412+ delta% inferInstance
413+
414+ /-- This shortcut instance ensures we do not find `AddCommMonoid` via the noncomputable
415+ `Complex.instNormedField` instance. -/
416+ instance : AddCommMonoid ℂ :=
417+ delta% inferInstance
418+
419+ end computable_shortcuts
405420
406421/-- The "real part" map, considered as an additive group homomorphism. -/
407422def reAddGroupHom : ℂ →+ ℝ where
Original file line number Diff line number Diff line change 1+ /-
2+ This test must import everything to make the noncomputable instances which we don't want available.
3+ -/
4+ import Mathlib
5+
6+ /-!
7+ # Tests that basic algebraic typeclasses are computable
8+
9+ Frequently mathlib will have instances of the form
10+ ```
11+ instance : FooAndBar X := ...
12+
13+ -- in a later file
14+ noncomputable instance : VeryNoncomputableFoo X := ...
15+ ```
16+ which means that `Foo X` will sometimes be synthesized noncomputably even though a computable
17+ version is available.
18+
19+ TODO: test this more exhaustively.
20+ -/
21+
22+ macro "#guard_computable" t:term : command =>
23+ `(#guard_msgs (drop info) in #eval $t)
24+
25+ section Real
26+
27+ #guard_computable LinearMap.mul ℝ ℝ 2 3
28+ #guard_computable LinearEquiv.neg ℝ (2 : ℝ)
29+
30+ end Real
31+
32+ section Complex
33+
34+ #guard_computable LinearMap.mul ℂ ℂ 2 3
35+ #guard_computable LinearEquiv.neg ℂ (2 : ℂ)
36+
37+ end Complex
You can’t perform that action at this time.
0 commit comments