Skip to content

Commit b2b4255

Browse files
committed
chore: use more mkApp(Opt)M in the differential geometry elaborators (leanprover-community#40933)
This is more concise (and perhaps even more efficient) than converting an existing expression to Syntax and re-elaborating that. No need for this.
1 parent 48fca28 commit b2b4255

4 files changed

Lines changed: 19 additions & 38 deletions

File tree

Mathlib/Geometry/Manifold/Notation.lean

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ where
430430
let some K ← guessBaseFieldForNormedSpace F
431431
| throwError "Couldn't find a `NormedSpace` structure on `{F}`"
432432
let tgtMod ← mkAppOptM ``modelWithCornersSelf #[K, none, F, none, none]
433-
mkAppM ``ModelWithCorners.prod #[baseModel, tgtMod]
433+
mkAppM ``ModelWithCorners.prod #[baseModel, tgtMod]
434434
| _ =>
435435
throwError s!"{e} is a TotalSpace {F} {V}, but {V} is not a pi type --- \
436436
could not infer base of the bundle"
@@ -440,18 +440,14 @@ where
440440
match_expr V with
441441
| TangentSpace _k _ _E _ _ _H _ I M _ _ => do
442442
trace[Elab.DiffGeo.MDiff] "`{V}` is the total space of the `TangentBundle` of `{M}`"
443-
let srcIT : Term ← Term.exprToSyntax I
444-
let resTerm : Term ← ``(ModelWithCorners.tangent $srcIT)
445-
Term.elabTerm resTerm none
443+
mkAppM ``ModelWithCorners.tangent #[I]
446444
| _ => throwError "`{V}` is not a `TangentSpace`"
447445
/-- Attempt to find a model on a `TangentBundle` -/
448446
fromTangentBundle : TermElabM Expr := do
449447
match_expr e with
450448
| TangentBundle _k _ _E _ _ _H _ I M _ _ => do
451449
trace[Elab.DiffGeo.MDiff] "`{e}` is a `TangentBundle` over model `{I}` on `{M}`"
452-
let srcIT : Term ← Term.exprToSyntax I
453-
let resTerm : Term ← ``(ModelWithCorners.tangent $srcIT)
454-
Term.elabTerm resTerm none
450+
mkAppM ``ModelWithCorners.tangent #[I]
455451
| _ => throwError "`{e}` is not a `TangentBundle`"
456452
/-- Attempt to find the trivial model on a normed space. -/
457453
fromNormedSpace : TermElabM FindModelResult := do
@@ -534,18 +530,13 @@ where
534530
-- the standard model with corners.
535531
-- Therefore, we only check definitional equality at reducible transparency.
536532
let (k, _E, _F) ← isCLMReduciblyDefeqCoefficients e
537-
let eK : Term ← Term.exprToSyntax k
538-
let eT : Term ← Term.exprToSyntax e
539-
let iTerm : Term ← ``(𝓘($eK, $eT))
540-
Term.elabTerm iTerm none
533+
mkAppOptM ``modelWithCornersSelf #[k, none, e, none, none]
541534
/-- Attempt to find a model with corners on a Euclidean space, half-space or quadrant -/
542535
fromEuclideanSpace : TermElabM Expr := do
543536
-- We don't use `match_expr` to avoid importing `EuclideanHalfSpace`.
544537
match (← instantiateMVars e).cleanupAnnotations with
545538
| mkApp2 (.const `EuclideanSpace _) k _n =>
546-
let eK : Term ← Term.exprToSyntax k
547-
let eT : Term ← Term.exprToSyntax e
548-
Term.elabTerm (← ``(𝓘($eK, $eT))) none
539+
mkAppOptM ``modelWithCornersSelf #[k, none, e, none, none]
549540
| mkApp2 (.const `EuclideanHalfSpace _) n _ =>
550541
mkAppOptM `modelWithCornersEuclideanHalfSpace #[n, none]
551542
| mkApp (.const `EuclideanQuadrant _) n =>
@@ -606,9 +597,7 @@ where
606597
| _ => return none
607598
if let some (k, R) := searchNormedAlgebra then
608599
trace[Elab.DiffGeo.MDiff] "found a normed algebra: `{α}` is a normed `{k}`-algebra"
609-
let eK : Term ← Term.exprToSyntax k
610-
let eR : Term ← Term.exprToSyntax R
611-
Term.elabTerm (← ``(𝓘($eK, $eR))) none
600+
mkAppOptM ``modelWithCornersSelf #[k, none, R, none, none]
612601
else
613602
trace[Elab.DiffGeo.MDiff] "`{α}` is not a normed algebra on the nose: try via a space of \
614603
continuous linear maps"
@@ -633,9 +622,7 @@ where
633622
match normedSpace? with
634623
| some (k, _R) =>
635624
trace[Elab.DiffGeo.MDiff] "found a normed space: `{V}` is a normed space over `{k}`"
636-
let eK : Term ← Term.exprToSyntax k
637-
let eα : Term ← Term.exprToSyntax α
638-
Term.elabTerm (← ``(𝓘($eK, $eα))) none
625+
mkAppOptM ``modelWithCornersSelf #[k, none, α, none, none]
639626
| _ => throwError "Found no `NormedSpace` structure on `{V}` among local instances"
640627
else
641628
-- NB. If further instances of `NormedAlgebra` arise in practice, adding another check
@@ -724,10 +711,7 @@ where
724711
| _ => throwError "`{e}` is not a sphere in a real normed space"
725712
/-- Attempt to find a model with corners from a normed field.
726713
We attempt to find a global instance here. -/
727-
fromNormedField : TermElabM Expr := do
728-
let eT : Term ← Term.exprToSyntax e
729-
let iTerm : Term ← ``(𝓘($eT, $eT))
730-
Term.elabTerm iTerm none
714+
fromNormedField : TermElabM Expr := mkAppOptM ``modelWithCornersSelf #[e, none, e, none, none]
731715

732716
/-- Try to find a `ModelWithCorners` instance on a type (represented by an expression `e`),
733717
using the local context to infer the appropriate instance.
@@ -802,10 +786,7 @@ where
802786
throwError "`{e}` is a product of normed spaces, so there are two potential models with \
803787
corners\nFor now, please specify the model by hand."
804788
-- Otherwise, we are not a normed space, and normally form the product model.
805-
let eTerm : Term ← Term.exprToSyntax srcE
806-
let fTerm : Term ← Term.exprToSyntax srcF
807-
let iTerm : Term ← ``(ModelWithCorners.prod $eTerm $fTerm)
808-
return some { model := ← Term.elabTerm iTerm none }
789+
return some { model := ← mkAppM ``ModelWithCorners.prod #[srcE, srcF] }
809790
| Sum E F =>
810791
trace[Elab.DiffGeo.MDiff] "Expression `{e}` is a direct sum of `{E}` and `{F}`\n\
811792
We assume the models match, and only look into the first summand"

MathlibTest/DifferentialGeometry/Notation/Advanced.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ trace: [Elab.DiffGeo.MDiff] Finding a model with corners for: `M`
378378
`ContinuousLinearMap id' E'' E'''` is not a coercion of a set to a type
379379
[Elab.DiffGeo.MDiff] 💥️ NormedField
380380
[Elab.DiffGeo.MDiff] Failed with error:
381-
failed to synthesize instance of type class
381+
failed to synthesize
382382
NontriviallyNormedField (ContinuousLinearMap id' E'' E''')
383383
384-
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
384+
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
385385
[Elab.DiffGeo.MDiff] 💥️ InnerProductSpace
386386
[Elab.DiffGeo.MDiff] Failed with error:
387387
Couldn't find an `InnerProductSpace` structure on `ContinuousLinearMap id' E'' E'''` among local instances.
@@ -481,10 +481,10 @@ trace: [Elab.DiffGeo.MDiff] Finding a model with corners for: `M`
481481
`ContinuousLinearMap σ E'' E''''` is not a coercion of a set to a type
482482
[Elab.DiffGeo.MDiff] 💥️ NormedField
483483
[Elab.DiffGeo.MDiff] Failed with error:
484-
failed to synthesize instance of type class
484+
failed to synthesize
485485
NontriviallyNormedField (ContinuousLinearMap σ E'' E'''')
486486
487-
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
487+
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
488488
[Elab.DiffGeo.MDiff] 💥️ InnerProductSpace
489489
[Elab.DiffGeo.MDiff] Failed with error:
490490
Couldn't find an `InnerProductSpace` structure on `ContinuousLinearMap σ E'' E''''` among local instances.
@@ -686,10 +686,10 @@ trace: [Elab.DiffGeo.MDiff] Finding a model with corners for: `↑(Set.Icc x y)`
686686
`Set.Icc x y` is not a sphere in a real normed space
687687
[Elab.DiffGeo.MDiff] 💥️ NormedField
688688
[Elab.DiffGeo.MDiff] Failed with error:
689-
failed to synthesize instance of type class
689+
failed to synthesize
690690
NontriviallyNormedField ↑(Set.Icc x y)
691691
692-
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
692+
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
693693
[Elab.DiffGeo.MDiff] 💥️ InnerProductSpace
694694
[Elab.DiffGeo.MDiff] Failed with error:
695695
Couldn't find an `InnerProductSpace` structure on `↑(Set.Icc x y)` among local instances.

MathlibTest/DifferentialGeometry/Notation/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,10 @@ trace: [Elab.DiffGeo.MDiff] Finding a model with corners for: `Unit`
14701470
`Unit` is not a coercion of a set to a type
14711471
[Elab.DiffGeo.MDiff] 💥️ NormedField
14721472
[Elab.DiffGeo.MDiff] Failed with error:
1473-
failed to synthesize instance of type class
1473+
failed to synthesize
14741474
NontriviallyNormedField Unit
14751475
1476-
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
1476+
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
14771477
[Elab.DiffGeo.MDiff] 💥️ InnerProductSpace
14781478
[Elab.DiffGeo.MDiff] Failed with error:
14791479
Couldn't find an `InnerProductSpace` structure on `Unit` among local instances.

MathlibTest/DifferentialGeometry/Notation/Sphere.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ trace: [Elab.DiffGeo.MDiff] Finding a model with corners for: `↑(Metric.sphere
230230
Found no fact `finrank ℝ E'' = n + 1` in the local context
231231
[Elab.DiffGeo.MDiff] 💥️ NormedField
232232
[Elab.DiffGeo.MDiff] Failed with error:
233-
failed to synthesize instance of type class
233+
failed to synthesize
234234
NontriviallyNormedField ↑(Metric.sphere 0 1)
235235
236-
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
236+
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
237237
[Elab.DiffGeo.MDiff] 💥️ InnerProductSpace
238238
[Elab.DiffGeo.MDiff] Failed with error:
239239
Couldn't find an `InnerProductSpace` structure on `↑(Metric.sphere 0 1)` among local instances.

0 commit comments

Comments
 (0)