Zulip Chat Archive
Stream: mathlib4
Topic: Subtype.prop as a simp lemma
Wrenna Robson (Jul 21 2025 at 11:07):
Why do we not have Subtype.prop as a simp lemma? Does it add major performance issues? It seems like a thing that would be useful but maybe that is naive.
Kenny Lau (Jul 21 2025 at 11:08):
Probably because it's impossible to apply
Kenny Lau (Jul 21 2025 at 11:08):
you can't infer the correct term of the subtype
Wrenna Robson (Jul 21 2025 at 11:09):
Right. It's just that if I already have an x : Subtype p in my context, I would quite like simp to know that p ↑x so it can apply lemmas with that as a hypothesis.
Kenny Lau (Jul 21 2025 at 11:11):
huh i tried to make an example to show this but it works in my example!
structure Is37 : Type where
val : Nat
eq : val = 37
instance : Coe Is37 Nat where
coe := Is37.val
@[simp] theorem Is37.coe_eq_37 (n : Is37) : (n : Nat) = 37 := n.eq
theorem foo (n : Is37) : (n : Nat) = 37 := by simp only [Is37.coe_eq_37]
Wrenna Robson (Jul 21 2025 at 11:12):
Hmm. What about {x : Subtype (¬ p ·)} - does it know that \not p ↑x?
Yaël Dillies (Jul 21 2025 at 11:12):
Subtype.prop unfortunately has a metavariable as head symbol, so it would have terrible performance most likely
Wrenna Robson (Jul 21 2025 at 11:13):
And I assume there's no way of fixing/avoiding that really?
Wrenna Robson (Jul 21 2025 at 11:15):
Broadly I am finding that the following very stupid lemmas might have a use.
variable {β : Sort*} {p : β → Prop} [DecidablePred p]
@[simp]
theorem dite_of_subtype {x : Subtype p} {t : p x → α} {e : ¬p x → α} :
(if h : p x then t h else e h) = t x.prop := dif_pos x.2
@[simp]
theorem dite_of_subtype_not {x : Subtype (¬ p ·)} {t : p x → α} {e : ¬ p x → α} :
(if h : p x then t h else e h) = e x.2 := dif_neg x.2
Wrenna Robson (Jul 21 2025 at 11:15):
Which feels real stupid. But simp kinda can't deal with that normally.
Kenny Lau (Jul 21 2025 at 11:16):
@Wrenna Robson but the lemmas you now proposed here are different from the general subtype prop lemma you asked in the beginning
Wrenna Robson (Jul 21 2025 at 11:17):
No, absolutely, but I was wondering if I was missing something and there was a simpler lemma that would be better.
Aaron Liu (Jul 21 2025 at 11:27):
It seems to work?
import Mathlib.Data.Subtype
example : type_of% @Subtype.prop := by
simp
Wrenna Robson (Jul 21 2025 at 11:27):
Hmm!
Edward van de Meent (Jul 21 2025 at 11:35):
that's different though, if you check simp? you'll see why
Edward van de Meent (Jul 21 2025 at 11:37):
in particular, the current issue is having simp work after intros in your example
Wrenna Robson (Jul 21 2025 at 12:24):
In what sense?
Edward van de Meent (Jul 21 2025 at 12:27):
in the sense that the above simp acts on \all x:{a// p a}, foo x rather than on foo x with x : {a//p a}
Wrenna Robson (Jul 21 2025 at 12:28):
My dite_of_subtype?
Wrenna Robson (Jul 21 2025 at 12:28):
It does seem to work for me after intros.
Edward van de Meent (Jul 21 2025 at 12:35):
i think Aaron meant that the example works with current mathlib, and i wanted to point out that that's only before intros and when the subtype value is a variable. i wasn't commenting on your dite_of_subtype
Wrenna Robson (Jul 21 2025 at 12:35):
aha, thanks
Last updated: Dec 20 2025 at 21:32 UTC