Skip to content

Commit

Permalink
feat(data/nat/basic): add strong_sub_recursion and `pincer_recursio…
Browse files Browse the repository at this point in the history
…n` (#15061)

Adding two recursion principles for `P : ℕ → ℕ → Sort*`

`strong_sub_recursion`: if for all `a b : ℕ` we can extend `P` from the rectangle strictly below `(a,b)` to `P a b`, then we have `P n m` for all `n m : ℕ`.

`pincer_recursion`: if we have `P i 0` and `P 0 i` for all `i : ℕ`, and for any `x y : ℕ` we can extend `P` from `(x,y+1)` and `(x+1,y)` to `(x+1,y+1)` then we have `P n m` for all `n m : ℕ`.


`strong_sub_recursion` is adapted by @vihdzp from @CBirkbeck 's #14828

Co-authored-by: Chris Birkbeck <cd.birkbeck@gmail.com>
Co-authored-by: Violeta Hernández <vi.hdz.p@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
  • Loading branch information
4 people committed Jul 12, 2022
1 parent 13f04ec commit eb091f8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/data/nat/basic.lean
Expand Up @@ -764,6 +764,27 @@ begin
end
using_well_founded { rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ p, p.1 + p.2.1)⟩] }

/-- Given `P : ℕ → ℕ → Sort*`, if for all `a b : ℕ` we can extend `P` from the rectangle
strictly below `(a,b)` to `P a b`, then we have `P n m` for all `n m : ℕ`.
Note that for non-`Prop` output it is preferable to use the equation compiler directly if possible,
since this produces equation lemmas. -/
@[elab_as_eliminator]
def strong_sub_recursion {P : ℕ → ℕ → Sort*}
(H : ∀ a b, (∀ x y, x < a → y < b → P x y) → P a b) : Π (n m : ℕ), P n m
| n m := H n m (λ x y hx hy, strong_sub_recursion x y)

/-- Given `P : ℕ → ℕ → Sort*`, if we have `P i 0` and `P 0 i` for all `i : ℕ`,
and for any `x y : ℕ` we can extend `P` from `(x,y+1)` and `(x+1,y)` to `(x+1,y+1)`
then we have `P n m` for all `n m : ℕ`.
Note that for non-`Prop` output it is preferable to use the equation compiler directly if possible,
since this produces equation lemmas. -/
@[elab_as_eliminator]
def pincer_recursion {P : ℕ → ℕ → Sort*} (Ha0 : ∀ a : ℕ, P a 0) (H0b : ∀ b : ℕ, P 0 b)
(H : ∀ x y : ℕ, P x y.succ → P x.succ y → P x.succ y.succ) : ∀ (n m : ℕ), P n m
| a 0 := Ha0 a
| 0 b := H0b b
| (nat.succ a) (nat.succ b) := H _ _ (pincer_recursion _ _) (pincer_recursion _ _)

/-- Recursion starting at a non-zero number: given a map `C k → C (k+1)` for each `k ≥ n`,
there is a map from `C n` to each `C m`, `n ≤ m`. -/
@[elab_as_eliminator]
Expand Down

0 comments on commit eb091f8

Please sign in to comment.