Zulip Chat Archive
Stream: general
Topic: Cryptic error in `inverse_spec`
Vasily Ilin (Apr 08 2024 at 19:05):
I get a cryptic error about metavriables and types in the example below, from MIL 4.2. Why does inverse_spec not work with f x
but works with y
?
import Mathlib.Tactic
import Mathlib.Util.Delaborators
import Mathlib.Data.Set.Function
set_option warningAsError false
variable {α β : Type*} [Inhabited α]
noncomputable section
open Classical
def inverse (f : α → β) : β → α := fun y : β ↦
if h : ∃ x, f x = y then Classical.choose h else default
theorem inverse_spec {f : α → β} (y : β) (h : ∃ x, f x = y) : f (inverse f y) = y := by
rw [inverse, dif_pos h]
exact Classical.choose_spec h
variable (f : α → β)
variable (x : α) (hx : ∃ x, f x = f x)
variable (y : β) (hy : ∃ x, f x = y)
#check hx
#check inverse_spec (f x) hx -- cryptic error
#check @inverse_spec f (f x) hx -- cryptic error
#check inverse_spec y hy -- works
Ruben Van de Velde (Apr 08 2024 at 19:23):
What's the error?
Vasily Ilin (Apr 08 2024 at 19:27):
I edited the example so it actually runs. Errors are
application type mismatch
inverse_spec (f x) hx
argument
hx
has type
∃ x, f x = f x : Prop
but is expected to have type
∃ x_1, ?m.3089 x_1 = f x : Prop
and
application type mismatch
@inverse_spec f
argument
f
has type
α → β : Type (max u_1 u_2)
but is expected to have type
Type ?u.3242 : Type (?u.3242 + 1)
Kevin Buzzard (Apr 08 2024 at 19:28):
If you have a variable x
then what do you expect exists x, f x = f x
to mean? At the very least this is bad style and it might be the cause of your problems: you have both a free and a bound variable with the same name.
Vasily Ilin (Apr 08 2024 at 19:30):
Ah, that was it for the first error. Thank you!
Kevin Buzzard (Apr 08 2024 at 19:30):
I was just looking at the error, where lean had helpfully changed one of them to x_1 but not the other one :-)
Vasily Ilin (Apr 08 2024 at 19:32):
I got stumped by ?m.3089
in place of f
.
Kevin Buzzard (Apr 08 2024 at 19:32):
For the other one (sorry I'm not at lean right now) do you understand what @
does? @inverse_spec f
won't typecheck.
Kevin Buzzard (Apr 08 2024 at 19:32):
Because f will map X to Y and @ means "you must give me X and Y before f"
Kevin Buzzard (Apr 08 2024 at 19:33):
It switches off implicit inputs
Vasily Ilin (Apr 08 2024 at 19:35):
Yes, this helps. The following works:
#check @inverse_spec α β _ f (f x) hx
This time I got stumped by Type ?u.3147 : Type (?u.3147 + 1)
. I am scared of these ?u.crazy_number
errors.
Kevin Buzzard (Apr 08 2024 at 19:38):
Would you be less scared of it just said u
? It's just a universe metavariable. Would you be less scared if it just set u to be 0 and the error said "is expected to have type Type : Type 1
? That's the sort of errors my students see because I encourage them, at the beginning, not to use universes at all.
Kevin Buzzard (Apr 08 2024 at 19:38):
The error says "you gave me a function, I was expecting a set" (or a type, as lean calls them)
Vasily Ilin (Apr 08 2024 at 19:39):
I guess I would be less scared because it's fewer weird symbols on screen :). I will get used to it as some point, I'm sure
Kevin Buzzard (Apr 08 2024 at 19:41):
Was there some recent change to lean which would enable people to switch off the numbers? Then you'd get "expected to have type Type ?u
"
Vasily Ilin (Apr 09 2024 at 06:21):
That would be a nice QoL improvement.
Damiano Testa (Apr 09 2024 at 06:53):
Maybe set_option pp.mvars true
?
Last updated: May 02 2025 at 03:31 UTC