Skip to content

Commit 9e66b28

Browse files
committed
wip: copied the missing code; need to dedup
And probably, want to insert a coercion...
1 parent 8edd4eb commit 9e66b28

2 files changed

Lines changed: 47 additions & 14 deletions

File tree

Mathlib/Geometry/Manifold/Notation.lean

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,40 @@ def findModels (e : Expr) (es : Option Expr) : TermElabM (Expr × Expr) := do
339339
return (srcI, tgtI)
340340
| _ =>
341341
match_expr etype with
342-
| OpenPartialHomeomorph X Y _ _ =>
343-
trace[Elab.DiffGeo.MDiff] m!"found a partial homeomorphism from {X} to {Y}"
344-
return (X, Y)
345-
| PartialEquiv X Y =>
346-
trace[Elab.DiffGeo.MDiff] m!"found a partial equivalence from {X} to {Y}"
347-
return (X, Y)
342+
| OpenPartialHomeomorph src tgt _ _ =>
343+
trace[Elab.DiffGeo.MDiff] m!"found a partial homeomorphism from {src} to {tgt}"
344+
if tgt.hasLooseBVars then
345+
-- TODO: try `T%` here, and if it works, add an interactive suggestion to use it
346+
throwError "Term {e} is a dependent function, of type {etype}\nHint: you can use the `T%` \
347+
elaborator to convert a dependent function to a non-dependent one"
348+
let srcI ← findModel src
349+
if let some es := es then
350+
let estype ← inferType es
351+
/- Note: we use `isDefEq` here since persistent metavariable assignments in `src` and
352+
`estype` are acceptable.
353+
TODO: consider attempting to coerce `es` to a `Set`. -/
354+
if !(← isDefEq estype <|← mkAppM ``Set #[src]) then
355+
throwError "The domain {src} of {e} is not definitionally equal to the carrier type of \
356+
the set {es} : {estype}"
357+
let tgtI ← findModel tgt (src, srcI)
358+
return (srcI, tgtI)
359+
| PartialEquiv src tgt =>
360+
trace[Elab.DiffGeo.MDiff] m!"found a partial equivalence from {src} to {tgt}"
361+
if tgt.hasLooseBVars then
362+
-- TODO: try `T%` here, and if it works, add an interactive suggestion to use it
363+
throwError "Term {e} is a dependent function, of type {etype}\nHint: you can use the `T%` \
364+
elaborator to convert a dependent function to a non-dependent one"
365+
let srcI ← findModel src
366+
if let some es := es then
367+
let estype ← inferType es
368+
/- Note: we use `isDefEq` here since persistent metavariable assignments in `src` and
369+
`estype` are acceptable.
370+
TODO: consider attempting to coerce `es` to a `Set`. -/
371+
if !(← isDefEq estype <|← mkAppM ``Set #[src]) then
372+
throwError "The domain {src} of {e} is not definitionally equal to the carrier type of \
373+
the set {es} : {estype}"
374+
let tgtI ← findModel tgt (src, srcI)
375+
return (srcI, tgtI)
348376
| _ => throwError "Expected{indentD e}\nof type{indentD etype}\nto be a function"
349377

350378
end Elab

MathlibTest/DifferentialGeometry/Notation.lean

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,36 @@ variable {φ : OpenPartialHomeomorph M E} {ψ : PartialEquiv M E}
125125

126126
#check MDifferentiableWithinAt I 𝓘(𝕜, E) ψ
127127
#check MDifferentiableWithinAt I 𝓘(𝕜, E) ψ s
128+
129+
128130
/--
129131
error: Application type mismatch: The argument
130-
M
132+
φ
131133
has type
132-
Type u_4
134+
OpenPartialHomeomorph M E
133135
but is expected to have type
134-
ModelWithCorners ?𝕜 ?E ?H
136+
?M → ?M'
135137
in the application
136-
@MDifferentiableWithinAt ?𝕜 ?inst✝ ?E ?inst✝¹ ?inst✝² ?H ?inst✝³ M
138+
MDifferentiableWithinAt I 𝓘(𝕜, E) φ
137139
-/
138140
#guard_msgs in
139141
#check MDiffAt[s] φ
142+
140143
/--
141144
error: Application type mismatch: The argument
142-
M
145+
ψ
143146
has type
144-
Type u_4
147+
PartialEquiv M E
145148
but is expected to have type
146-
ModelWithCorners ?𝕜 ?E ?H
149+
?M → ?M'
147150
in the application
148-
@MDifferentiableWithinAt ?𝕜 ?inst✝ ?E ?inst✝¹ ?inst✝² ?H ?inst✝³ M
151+
MDifferentiableWithinAt I 𝓘(𝕜, E) ψ
149152
-/
150153
#guard_msgs in
151154
#check MDiffAt[s] ψ
152155

156+
#exit
157+
153158
-- Testing an error message.
154159
section
155160

0 commit comments

Comments
 (0)