Zulip Chat Archive
Stream: new members
Topic: How to substitute in hypotheses on match
Jakub Nowak (Aug 01 2025 at 08:56):
import Mathlib
open SimpleGraph
variable {V : Type*} {G : SimpleGraph V} {u v : V}
def foo (p : G.Walk u v) : G.Walk u v :=
match p with
| .nil => /-here-/p
| .cons hAdj rest => p
In this code if I put cursor at the location marked with /-here-/, then I can see that match substituted v = u in goal, i.e. the goal changed from G.Walk u v to G.Walk u u. However, it didn't substituted in hypotheses. The type of p stayed G.Walk u v. Is it possible to make it so that match also does substitution in hypotheses?
Robin Arnez (Aug 01 2025 at 09:08):
Well, discriminants aren't substituted, that is because the cases used internally would usually eliminate them completely. If you want the "substitution", then:
def foo (p : G.Walk u v) : G.Walk u v :=
match p with
| p@(.nil) => p
| p@(.cons hAdj rest) => p
Jakub Nowak (Aug 01 2025 at 09:14):
For some reason this syntax doesn't work with cons':
import Mathlib
open SimpleGraph
variable {V : Type*} {G : SimpleGraph V} {u v : V}
def foo (p : G.Walk u v) : G.Walk u v :=
match p with
| p@(.nil) => p
| p@(.cons' u v w hAdj rest) => p
Jakub Nowak (Aug 01 2025 at 09:44):
Robin Arnez said:
Well, discriminants aren't substituted, that is because the
casesused internally would usually eliminate them completely.
Eliminating v would actually be desirable imo. Is it possible?
Robin Arnez (Aug 01 2025 at 11:14):
MrQubo schrieb:
For some reason this syntax doesn't work with
cons':
Use:
| p@(.cons' _ w _ hAdj rest) => p
instead
Robin Arnez (Aug 01 2025 at 11:15):
MrQubo schrieb:
Eliminating
vwould actually be desirable imo. Is it possible?
Hmm I think for that you'd need to use cases or induction directly
Robin Arnez (Aug 01 2025 at 11:15):
or use clear
Last updated: Dec 20 2025 at 21:32 UTC