Zulip Chat Archive
Stream: lean4
Topic: by_cases renames wrong hypothesis
Horațiu Cheval (Dec 02 2022 at 11:29):
In the example below I used the mathlib by_cases
tactic to go by cases on q
and Not
q.
The names
h2 I gave in the two cases rename the hypothesis
¬q → ¬p from its initial name
h` to h2, instead of be used for the newly introduced hypotheses.
import Mathlib
theorem contraposition' (p q : Prop) : (¬q → ¬p) → (p → q) := by
intros h hp
by_cases q
case pos h2 =>
/-
p q : Prop
h2 : ¬q → ¬p
hp : p
h : q
⊢ q
-/
case neg h2 => sorry
Is it a bug in by_cases
or am I misunderstanding how to use it?
Mario Carneiro (Dec 02 2022 at 11:30):
the mathlib by_cases
tactic is "unhygienic" in the sense that it introduces a variable named h
which you are allowed to directly refer to
Mario Carneiro (Dec 02 2022 at 11:31):
which means that the case
tactic will not rename it because it only renames newly introduced inaccessible variables
Horațiu Cheval (Dec 02 2022 at 11:32):
So if I need to give it another name do I just rename the newly introduced h
?
Mario Carneiro (Dec 02 2022 at 11:33):
the syntax for naming the variable in by_cases
is by_cases h2 : q
Horațiu Cheval (Dec 02 2022 at 11:33):
I see, thanks! I was confused by the difference between this and the builtin by_cases
Mario Carneiro (Dec 02 2022 at 11:34):
std also introduces another syntax for by_cases
that IMO looks better:
theorem contraposition' (p q : Prop) : (¬q → ¬p) → (p → q) := by
intros h hp
if h2 : q then
sorry
else
sorry
Jireh Loreaux (Dec 02 2022 at 15:29):
Are we just allowing the unhygienic by_cases
in mathlib4 in order to ease porting? In my mind it would be nice to remove these kinds of "features".
Mario Carneiro (Dec 02 2022 at 15:35):
yes
Mario Carneiro (Dec 02 2022 at 15:35):
the std version of by_cases
doesn't have this "feature"
Mario Carneiro (Dec 02 2022 at 15:37):
once mathlib4 is mostly ported, it will be much easier to do semi-automated linter-powered refactors like replacing induction'
with induction
and fixing the case name references
Mario Carneiro (Dec 02 2022 at 15:38):
these are things that mathport can't do because it needs the lean4-side syntax to typecheck, so it is easier to apply post-port, either as a refactoring step encouraged by a linter like the unnecessarySeqFocus
linter, or a full pass over the library when we are done
Last updated: Dec 20 2023 at 11:08 UTC