diff --git a/RELEASES.md b/RELEASES.md index e513185f81..4100eff59b 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,6 +1,8 @@ Unreleased --------- +* The hypothesis name is now optional in the `by_cases` tactic. + * [Fix inconsistency between `syntax` and kind names](https://github.com/leanprover/lean4/issues/1090). The node kinds `numLit`, `charLit`, `nameLit`, `strLit`, and `scientificLit` are now called `num`, `char`, `name`, `str`, and `scientific` respectively. Example: we now write diff --git a/doc/examples/bintree.lean b/doc/examples/bintree.lean index d071834bf0..2faa4a6a07 100644 --- a/doc/examples/bintree.lean +++ b/doc/examples/bintree.lean @@ -146,9 +146,9 @@ theorem Tree.forall_insert_of_forall (h₁ : ForallTree p t) (h₂ : p key value | node hl hp hr ihl ihr => rename Nat => k simp [insert] - by_cases hlt : key < k <;> simp [hlt] + by_cases key < k <;> simp [*] · exact .node ihl hp hr - · by_cases hgt : k < key <;> simp [hgt] + · by_cases k < key <;> simp [*] · exact .node hl hp ihr · have heq : key = k := by simp_arith at *; apply Nat.le_antisymm <;> assumption -- TODO: improve with linarith subst key @@ -198,9 +198,9 @@ theorem BinTree.find_insert (b : BinTree β) (k : Nat) (v : β) : (b.insert k v) let ⟨t, h⟩ := b; simp induction t with simp | node left key value right ihl ihr => - by_cases hlt : k < key <;> simp [*] + by_cases k < key <;> simp [*] · cases h; apply ihl; assumption - · by_cases hgt : key < k <;> simp [*] + · by_cases key < k <;> simp [*] cases h; apply ihr; assumption theorem BinTree.find_insert_of_ne (b : BinTree β) (h : k ≠ k') (v : β) : (b.insert k v).find? k' = b.find? k' := by @@ -214,11 +214,11 @@ theorem BinTree.find_insert_of_ne (b : BinTree β) (h : k ≠ k') (v : β) : (b. let .node hl hr bl br := h have ihl := ihl bl have ihr := ihr br - by_cases hlt : k < key <;> simp [*] - by_cases hlt : key < k <;> simp [*] + by_cases k < key <;> simp [*] + by_cases key < k <;> simp [*] have heq : key = k := by simp_arith at *; apply Nat.le_antisymm <;> assumption -- TODO: improve with linarith subst key - by_cases hlt : k' < k <;> simp [*] - by_cases hlt : k < k' <;> simp [*] + by_cases k' < k <;> simp [*] + by_cases k < k' <;> simp [*] have heq : k = k' := by simp_arith at *; apply Nat.le_antisymm <;> assumption -- TODO: improve with linarith contradiction diff --git a/src/Init/Classical.lean b/src/Init/Classical.lean index 95262b0173..c2e35dd9d5 100644 --- a/src/Init/Classical.lean +++ b/src/Init/Classical.lean @@ -125,9 +125,18 @@ theorem byCases {p q : Prop} (hpq : p → q) (hnpq : ¬p → q) : q := theorem byContradiction {p : Prop} (h : ¬p → False) : p := Decidable.byContradiction (dec := propDecidable _) h -macro "by_cases" h:ident ":" e:term : tactic => - `(cases em $e:term with - | inl $h:ident => _ - | inr $h:ident => _) +syntax "by_cases" (atomic(ident ":"))? term : tactic + +macro_rules + | `(tactic| by_cases $h:ident : $e:term) => + `(tactic| + cases em $e:term with + | inl $h:ident => _ + | inr $h:ident => _) + | `(tactic| by_cases $e:term) => + `(tactic| + cases em $e:term with + | inl h => _ + | inr h => _) end Classical