Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(data/pnat/basic): add induction principle #6410

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/data/pnat/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,27 @@ begin
exact hi b hk
end

/-- An induction principle for `pnat`: it takes values in `Sort*`, so it applies also to Types,
not only to `Prop`. -/
-- Proof by Mario Carnerio
-- https://tinyurl.com/4m9r5yf8
adomani marked this conversation as resolved.
Show resolved Hide resolved
@[elab_as_eliminator]
def pnat.rec_on (n : pnat) {p : pnat → Sort*} (p1 : p 1) (hp : ∀ n, p n → p (n + 1)) : p n :=
begin
rcases n with ⟨n, h⟩,
induction n with n IH,
{ exact absurd h dec_trivial },
{ cases n with n,
{ exact p1 },
{ exact hp _ (IH n.succ_pos) } }
end
eric-wieser marked this conversation as resolved.
Show resolved Hide resolved

theorem pnat.rec_on_one (n : pnat) {p} (p1 hp) : @pnat.rec_on 1 p p1 hp = p1 := rfl

theorem pnat.rec_on_succ (n : pnat) {p : pnat → Sort*} (p1 hp) :
@pnat.rec_on (n + 1) p p1 hp = hp n (@pnat.rec_on n p p1 hp) :=
by { cases n with n h, cases n; [exact absurd h dec_trivial, refl] }
eric-wieser marked this conversation as resolved.
Show resolved Hide resolved

/-- We define `m % k` and `m / k` in the same way as for `ℕ`
except that when `m = n * k` we take `m % k = k` and
`m / k = n - 1`. This ensures that `m % k` is always positive
Expand Down