Skip to content

Commit

Permalink
feat: measureRec for strong induction use cases (#829)
Browse files Browse the repository at this point in the history
* feat: `Nat.strongRecOnMeasure`

Co-Authored-By: Joachim Breitner <mail@joachim-breitner.de>
  • Loading branch information
llllvvuu and nomeata authored Jun 8, 2024
1 parent f93c3a7 commit 1659998
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Batteries/Data/Nat/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ protected def strongRec {motive : Nat → Sort _} (ind : ∀ n, (∀ m, m < n
protected def strongRecOn (t : Nat) {motive : Nat → Sort _}
(ind : ∀ n, (∀ m, m < n → motive m) → motive n) : motive t := Nat.strongRec ind t

/--
Strong recursor via a `Nat`-valued measure
-/
@[elab_as_elim]
def strongRecMeasure (f : α → Nat) {motive : α → Sort _}
(ind : ∀ x, (∀ y, f y < f x → motive y) → motive x) (x : α) : motive x :=
ind x fun y _ => strongRecMeasure f ind y
termination_by f x

/--
Simple diagonal recursor for `Nat`
-/
Expand Down

0 comments on commit 1659998

Please sign in to comment.