2014-12-01 04:34:12 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
2014-12-15 21:43:42 +00:00
|
|
|
|
|
|
|
|
|
Module: init.nat
|
2014-12-01 04:34:12 +00:00
|
|
|
|
Authors: Floris van Doorn, Leonardo de Moura
|
|
|
|
|
-/
|
|
|
|
|
prelude
|
2015-03-03 21:37:38 +00:00
|
|
|
|
import init.wf init.tactic init.num
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
open eq.ops decidable
|
|
|
|
|
|
|
|
|
|
namespace nat
|
|
|
|
|
notation `ℕ` := nat
|
|
|
|
|
|
|
|
|
|
inductive lt (a : nat) : nat → Prop :=
|
2015-02-26 01:00:10 +00:00
|
|
|
|
| base : lt a (succ a)
|
|
|
|
|
| step : Π {b}, lt a b → lt a (succ b)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
notation a < b := lt a b
|
|
|
|
|
|
2015-02-24 22:09:20 +00:00
|
|
|
|
definition le [reducible] (a b : nat) : Prop := a < succ b
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
notation a ≤ b := le a b
|
|
|
|
|
|
|
|
|
|
definition pred (a : nat) : nat :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.cases_on a zero (λ a₁, a₁)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
protected definition is_inhabited [instance] : inhabited nat :=
|
|
|
|
|
inhabited.mk zero
|
|
|
|
|
|
2015-02-26 00:20:44 +00:00
|
|
|
|
protected definition has_decidable_eq [instance] : ∀ x y : nat, decidable (x = y)
|
|
|
|
|
| has_decidable_eq zero zero := inl rfl
|
2015-05-01 04:26:52 +00:00
|
|
|
|
| has_decidable_eq (succ x) zero := inr (by contradiction)
|
|
|
|
|
| has_decidable_eq zero (succ y) := inr (by contradiction)
|
2015-02-26 00:20:44 +00:00
|
|
|
|
| has_decidable_eq (succ x) (succ y) :=
|
2015-05-02 01:18:29 +00:00
|
|
|
|
match has_decidable_eq x y with
|
|
|
|
|
| inl xeqy := inl (by rewrite xeqy)
|
|
|
|
|
| inr xney := inr (λ h : succ x = succ y, by injection h with xeqy; exact absurd xeqy xney)
|
|
|
|
|
end
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
-- less-than is well-founded
|
|
|
|
|
definition lt.wf [instance] : well_founded lt :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
well_founded.intro (λn, nat.rec_on n
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(acc.intro zero (λ (y : nat) (hlt : y < zero),
|
|
|
|
|
have aux : ∀ {n₁}, y < n₁ → zero = n₁ → acc lt y, from
|
2015-02-11 20:49:27 +00:00
|
|
|
|
λ n₁ hlt, nat.lt.cases_on hlt
|
2015-04-30 20:56:12 +00:00
|
|
|
|
(by contradiction)
|
|
|
|
|
(by contradiction),
|
2014-11-22 08:15:51 +00:00
|
|
|
|
aux hlt rfl))
|
|
|
|
|
(λ (n : nat) (ih : acc lt n),
|
|
|
|
|
acc.intro (succ n) (λ (m : nat) (hlt : m < succ n),
|
|
|
|
|
have aux : ∀ {n₁} (hlt : m < n₁), succ n = n₁ → acc lt m, from
|
2015-02-11 20:49:27 +00:00
|
|
|
|
λ n₁ hlt, nat.lt.cases_on hlt
|
2015-05-02 01:18:29 +00:00
|
|
|
|
(λ (sn_eq_sm : succ n = succ m),
|
|
|
|
|
by injection sn_eq_sm with neqm; rewrite neqm at ih; exact ih)
|
|
|
|
|
(λ b (hlt : m < b) (sn_eq_sb : succ n = succ b),
|
|
|
|
|
by injection sn_eq_sb with neqb; rewrite neqb at ih; exact acc.inv ih hlt),
|
2014-11-22 08:15:51 +00:00
|
|
|
|
aux hlt rfl)))
|
|
|
|
|
|
2014-11-23 01:19:03 +00:00
|
|
|
|
definition measure {A : Type} (f : A → nat) : A → A → Prop :=
|
|
|
|
|
inv_image lt f
|
|
|
|
|
|
|
|
|
|
definition measure.wf {A : Type} (f : A → nat) : well_founded (measure f) :=
|
|
|
|
|
inv_image.wf f lt.wf
|
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
definition not_lt_zero (a : nat) : ¬ a < zero :=
|
|
|
|
|
have aux : ∀ {b}, a < b → b = zero → false, from
|
|
|
|
|
λ b H, lt.cases_on H
|
2015-04-30 20:56:12 +00:00
|
|
|
|
(by contradiction)
|
|
|
|
|
(by contradiction),
|
2014-11-22 08:15:51 +00:00
|
|
|
|
λ H, aux H rfl
|
|
|
|
|
|
|
|
|
|
definition zero_lt_succ (a : nat) : zero < succ a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.rec_on a
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(lt.base zero)
|
|
|
|
|
(λ a (hlt : zero < succ a), lt.step hlt)
|
|
|
|
|
|
|
|
|
|
definition lt.trans {a b c : nat} (H₁ : a < b) (H₂ : b < c) : a < c :=
|
2015-04-30 14:46:52 +00:00
|
|
|
|
have aux : a < b → a < c, from
|
|
|
|
|
lt.rec_on H₂
|
|
|
|
|
(λ h₁, lt.step h₁)
|
|
|
|
|
(λ b₁ bb₁ ih h₁, lt.step (ih h₁)),
|
|
|
|
|
aux H₁
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition succ_lt_succ {a b : nat} (H : a < b) : succ a < succ b :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
lt.rec_on H
|
|
|
|
|
(lt.base (succ a))
|
|
|
|
|
(λ b hlt ih, lt.trans ih (lt.base (succ b)))
|
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition lt_of_succ_lt {a b : nat} (H : succ a < b) : a < b :=
|
2015-04-30 14:46:52 +00:00
|
|
|
|
lt.rec_on H
|
|
|
|
|
(lt.step (lt.base a))
|
|
|
|
|
(λ b h ih, lt.step ih)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition lt_of_succ_lt_succ {a b : nat} (H : succ a < succ b) : a < b :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
have aux : pred (succ a) < pred (succ b), from
|
|
|
|
|
lt.rec_on H
|
|
|
|
|
(lt.base a)
|
|
|
|
|
(λ (b : nat) (hlt : succ a < b) ih,
|
|
|
|
|
show pred (succ a) < pred (succ b), from
|
2015-01-08 02:26:51 +00:00
|
|
|
|
lt_of_succ_lt hlt),
|
2014-11-22 08:15:51 +00:00
|
|
|
|
aux
|
|
|
|
|
|
2015-02-25 20:34:49 +00:00
|
|
|
|
definition decidable_lt [instance] : decidable_rel lt :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
λ a b, nat.rec_on b
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(λ (a : nat), inr (not_lt_zero a))
|
2015-02-11 20:49:27 +00:00
|
|
|
|
(λ (b₁ : nat) (ih : ∀ a, decidable (a < b₁)) (a : nat), nat.cases_on a
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(inl !zero_lt_succ)
|
|
|
|
|
(λ a, decidable.rec_on (ih a)
|
2015-01-08 02:26:51 +00:00
|
|
|
|
(λ h_pos : a < b₁, inl (succ_lt_succ h_pos))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(λ h_neg : ¬ a < b₁,
|
|
|
|
|
have aux : ¬ succ a < succ b₁, from
|
2015-01-08 02:26:51 +00:00
|
|
|
|
λ h : succ a < succ b₁, h_neg (lt_of_succ_lt_succ h),
|
2014-11-22 08:15:51 +00:00
|
|
|
|
inr aux)))
|
|
|
|
|
a
|
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition le.refl (a : nat) : a ≤ a :=
|
|
|
|
|
lt.base a
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition le_of_lt {a b : nat} (H : a < b) : a ≤ b :=
|
2014-11-30 23:07:09 +00:00
|
|
|
|
lt.step H
|
|
|
|
|
|
|
|
|
|
definition eq_or_lt_of_le {a b : nat} (H : a ≤ b) : a = b ∨ a < b :=
|
|
|
|
|
begin
|
2015-04-30 18:00:39 +00:00
|
|
|
|
cases H with b hlt,
|
|
|
|
|
apply or.inl rfl,
|
|
|
|
|
apply or.inr hlt
|
2014-11-30 23:07:09 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition le_of_eq_or_lt {a b : nat} (H : a = b ∨ a < b) : a ≤ b :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
or.rec_on H
|
|
|
|
|
(λ hl, eq.rec_on hl !le.refl)
|
2015-01-08 02:26:51 +00:00
|
|
|
|
(λ hr, le_of_lt hr)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-02-25 20:34:49 +00:00
|
|
|
|
definition decidable_le [instance] : decidable_rel le :=
|
2015-01-08 02:26:51 +00:00
|
|
|
|
λ a b, decidable_of_decidable_of_iff _ (iff.intro le_of_eq_or_lt eq_or_lt_of_le)
|
2014-11-30 23:07:09 +00:00
|
|
|
|
|
|
|
|
|
definition le.rec_on {a : nat} {P : nat → Prop} {b : nat} (H : a ≤ b) (H₁ : P a) (H₂ : ∀ b, a < b → P b) : P b :=
|
|
|
|
|
begin
|
2015-04-30 18:00:39 +00:00
|
|
|
|
cases H with b' hlt,
|
2014-11-30 23:07:09 +00:00
|
|
|
|
apply H₁,
|
2015-04-30 18:00:39 +00:00
|
|
|
|
apply H₂ b' hlt
|
2014-11-30 23:07:09 +00:00
|
|
|
|
end
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
definition lt.irrefl (a : nat) : ¬ a < a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.rec_on a
|
2014-11-22 08:15:51 +00:00
|
|
|
|
!not_lt_zero
|
|
|
|
|
(λ (a : nat) (ih : ¬ a < a) (h : succ a < succ a),
|
2015-01-08 02:26:51 +00:00
|
|
|
|
ih (lt_of_succ_lt_succ h))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
definition lt.asymm {a b : nat} (H : a < b) : ¬ b < a :=
|
|
|
|
|
lt.rec_on H
|
2015-01-08 02:26:51 +00:00
|
|
|
|
(λ h : succ a < a, !lt.irrefl (lt_of_succ_lt h))
|
|
|
|
|
(λ b hlt (ih : ¬ b < a) (h : succ b < a), ih (lt_of_succ_lt h))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
definition lt.trichotomy (a b : nat) : a < b ∨ a = b ∨ b < a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.rec_on b
|
|
|
|
|
(λa, nat.cases_on a
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(or.inr (or.inl rfl))
|
|
|
|
|
(λ a₁, or.inr (or.inr !zero_lt_succ)))
|
2015-02-11 20:49:27 +00:00
|
|
|
|
(λ b₁ (ih : ∀a, a < b₁ ∨ a = b₁ ∨ b₁ < a) (a : nat), nat.cases_on a
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(or.inl !zero_lt_succ)
|
|
|
|
|
(λ a, or.rec_on (ih a)
|
2015-01-08 02:26:51 +00:00
|
|
|
|
(λ h : a < b₁, or.inl (succ_lt_succ h))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(λ h, or.rec_on h
|
|
|
|
|
(λ h : a = b₁, or.inr (or.inl (eq.rec_on h rfl)))
|
2015-01-08 02:26:51 +00:00
|
|
|
|
(λ h : b₁ < a, or.inr (or.inr (succ_lt_succ h))))))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
a
|
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition eq_or_lt_of_not_lt {a b : nat} (hnlt : ¬ a < b) : a = b ∨ b < a :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
or.rec_on (lt.trichotomy a b)
|
|
|
|
|
(λ hlt, absurd hlt hnlt)
|
|
|
|
|
(λ h, h)
|
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition lt_succ_of_le {a b : nat} (h : a ≤ b) : a < succ b :=
|
|
|
|
|
h
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition lt_of_succ_le {a b : nat} (h : succ a ≤ b) : a < b :=
|
2015-01-08 02:26:51 +00:00
|
|
|
|
lt_of_succ_lt_succ h
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition le_succ_of_le {a b : nat} (h : a ≤ b) : a ≤ succ b :=
|
2014-11-30 23:07:09 +00:00
|
|
|
|
lt.step h
|
|
|
|
|
|
|
|
|
|
definition succ_le_of_lt {a b : nat} (h : a < b) : succ a ≤ b :=
|
2015-01-08 02:26:51 +00:00
|
|
|
|
succ_lt_succ h
|
2014-11-30 23:07:09 +00:00
|
|
|
|
|
|
|
|
|
definition le.trans {a b c : nat} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c :=
|
|
|
|
|
begin
|
2015-04-30 18:00:39 +00:00
|
|
|
|
cases h₁ with b' hlt,
|
2014-11-30 23:07:09 +00:00
|
|
|
|
apply h₂,
|
2015-04-30 18:00:39 +00:00
|
|
|
|
apply lt.trans hlt h₂
|
2014-11-30 23:07:09 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition lt_of_le_of_lt {a b c : nat} (h₁ : a ≤ b) (h₂ : b < c) : a < c :=
|
2014-11-30 23:07:09 +00:00
|
|
|
|
begin
|
2015-04-30 18:00:39 +00:00
|
|
|
|
cases h₁ with b' hlt,
|
2014-11-30 23:07:09 +00:00
|
|
|
|
apply h₂,
|
2015-04-30 18:00:39 +00:00
|
|
|
|
apply lt.trans hlt h₂
|
2014-11-30 23:07:09 +00:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition lt_of_lt_of_le {a b c : nat} (h₁ : a < b) (h₂ : b ≤ c) : a < c :=
|
2014-11-30 23:07:09 +00:00
|
|
|
|
begin
|
2015-04-30 18:00:39 +00:00
|
|
|
|
cases h₁ with b' hlt,
|
|
|
|
|
apply lt_of_succ_lt_succ h₂,
|
|
|
|
|
apply lt.trans hlt (lt_of_succ_lt_succ h₂)
|
2014-11-30 23:07:09 +00:00
|
|
|
|
end
|
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
calc_trans lt.trans
|
2015-01-08 02:26:51 +00:00
|
|
|
|
calc_trans lt_of_le_of_lt
|
|
|
|
|
calc_trans lt_of_lt_of_le
|
2014-11-22 08:15:51 +00:00
|
|
|
|
calc_trans le.trans
|
|
|
|
|
|
|
|
|
|
definition max (a b : nat) : nat :=
|
|
|
|
|
if a < b then b else a
|
|
|
|
|
|
|
|
|
|
definition min (a b : nat) : nat :=
|
|
|
|
|
if a < b then a else b
|
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition max_self (a : nat) : max a a = a :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
eq.rec_on !if_t_t rfl
|
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition max_eq_right {a b : nat} (H : a < b) : max a b = b :=
|
2014-11-22 17:36:33 +00:00
|
|
|
|
if_pos H
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition max_eq_left {a b : nat} (H : ¬ a < b) : max a b = a :=
|
2014-11-22 17:36:33 +00:00
|
|
|
|
if_neg H
|
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition eq_max_right {a b : nat} (H : a < b) : b = max a b :=
|
|
|
|
|
eq.rec_on (max_eq_right H) rfl
|
2014-11-22 17:36:33 +00:00
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition eq_max_left {a b : nat} (H : ¬ a < b) : a = max a b :=
|
|
|
|
|
eq.rec_on (max_eq_left H) rfl
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition le_max_left (a b : nat) : a ≤ max a b :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
by_cases
|
2015-04-18 17:50:30 +00:00
|
|
|
|
(λ h : a < b, le_of_lt (eq.rec_on (eq_max_right h) h))
|
|
|
|
|
(λ h : ¬ a < b, eq.rec_on (eq_max_left h) !le.refl)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-04-18 17:50:30 +00:00
|
|
|
|
definition le_max_right (a b : nat) : b ≤ max a b :=
|
2014-11-22 08:15:51 +00:00
|
|
|
|
by_cases
|
2015-04-18 17:50:30 +00:00
|
|
|
|
(λ h : a < b, eq.rec_on (eq_max_right h) !le.refl)
|
2014-11-30 23:07:09 +00:00
|
|
|
|
(λ h : ¬ a < b, or.rec_on (eq_or_lt_of_not_lt h)
|
2015-04-18 17:50:30 +00:00
|
|
|
|
(λ heq, eq.rec_on heq (eq.rec_on (eq.symm (max_self a)) !le.refl))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
(λ h : b < a,
|
2015-04-18 17:50:30 +00:00
|
|
|
|
have aux : a = max a b, from eq_max_left (lt.asymm h),
|
2015-01-08 02:26:51 +00:00
|
|
|
|
eq.rec_on aux (le_of_lt h)))
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
2015-01-27 01:38:00 +00:00
|
|
|
|
definition gt [reducible] a b := lt b a
|
2015-04-13 15:08:54 +00:00
|
|
|
|
definition decidable_gt [instance] : decidable_rel gt :=
|
|
|
|
|
_
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
notation a > b := gt a b
|
|
|
|
|
|
2015-01-27 01:38:00 +00:00
|
|
|
|
definition ge [reducible] a b := le b a
|
2015-04-13 15:08:54 +00:00
|
|
|
|
definition decidable_ge [instance] : decidable_rel ge :=
|
|
|
|
|
_
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
notation a ≥ b := ge a b
|
|
|
|
|
|
2015-03-03 21:37:38 +00:00
|
|
|
|
-- add is defined in init.num
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
definition sub (a b : nat) : nat :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.rec_on b a (λ b₁ r, pred r)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
notation a - b := sub a b
|
|
|
|
|
|
|
|
|
|
definition mul (a b : nat) : nat :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.rec_on b zero (λ b₁ r, r + a)
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
notation a * b := mul a b
|
2014-11-22 17:36:33 +00:00
|
|
|
|
|
2015-04-22 02:13:19 +00:00
|
|
|
|
section
|
|
|
|
|
local attribute sub [reducible]
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition succ_sub_succ_eq_sub (a b : nat) : succ a - succ b = a - b :=
|
2015-04-30 14:46:52 +00:00
|
|
|
|
nat.rec_on b
|
2014-11-22 17:36:33 +00:00
|
|
|
|
rfl
|
|
|
|
|
(λ b₁ (ih : succ a - succ b₁ = a - b₁),
|
|
|
|
|
eq.rec_on ih (eq.refl (pred (succ a - succ b₁))))
|
2015-01-09 02:47:44 +00:00
|
|
|
|
end
|
2014-11-22 17:36:33 +00:00
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition sub_eq_succ_sub_succ (a b : nat) : a - b = succ a - succ b :=
|
|
|
|
|
eq.rec_on (succ_sub_succ_eq_sub a b) rfl
|
2014-11-22 17:36:33 +00:00
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition zero_sub_eq_zero (a : nat) : zero - a = zero :=
|
2015-04-30 14:46:52 +00:00
|
|
|
|
nat.rec_on a
|
2014-11-22 17:36:33 +00:00
|
|
|
|
rfl
|
|
|
|
|
(λ a₁ (ih : zero - a₁ = zero),
|
|
|
|
|
eq.rec_on ih (eq.refl (pred (zero - a₁))))
|
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition zero_eq_zero_sub (a : nat) : zero = zero - a :=
|
|
|
|
|
eq.rec_on (zero_sub_eq_zero a) rfl
|
2014-11-22 17:36:33 +00:00
|
|
|
|
|
2015-01-08 02:26:51 +00:00
|
|
|
|
definition sub_lt {a b : nat} : zero < a → zero < b → a - b < a :=
|
2014-11-22 17:36:33 +00:00
|
|
|
|
have aux : Π {a}, zero < a → Π {b}, zero < b → a - b < a, from
|
|
|
|
|
λa h₁, lt.rec_on h₁
|
|
|
|
|
(λb h₂, lt.cases_on h₂
|
|
|
|
|
(lt.base zero)
|
|
|
|
|
(λ b₁ bpos,
|
2014-11-30 23:07:09 +00:00
|
|
|
|
eq.rec_on (sub_eq_succ_sub_succ zero b₁)
|
|
|
|
|
(eq.rec_on (zero_eq_zero_sub b₁) (lt.base zero))))
|
2014-11-22 17:36:33 +00:00
|
|
|
|
(λa₁ apos ih b h₂, lt.cases_on h₂
|
|
|
|
|
(lt.base a₁)
|
|
|
|
|
(λ b₁ bpos,
|
2014-11-30 23:07:09 +00:00
|
|
|
|
eq.rec_on (sub_eq_succ_sub_succ a₁ b₁)
|
2014-11-22 17:36:33 +00:00
|
|
|
|
(lt.trans (@ih b₁ bpos) (lt.base a₁)))),
|
|
|
|
|
λ h₁ h₂, aux h₁ h₂
|
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition pred_le (a : nat) : pred a ≤ a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.cases_on a
|
2014-11-22 21:11:16 +00:00
|
|
|
|
(le.refl zero)
|
2015-01-08 02:26:51 +00:00
|
|
|
|
(λ a₁, le_of_lt (lt.base a₁))
|
2014-11-22 21:11:16 +00:00
|
|
|
|
|
2014-11-30 23:07:09 +00:00
|
|
|
|
definition sub_le (a b : nat) : a - b ≤ a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.induction_on b
|
2014-11-22 21:11:16 +00:00
|
|
|
|
(le.refl a)
|
2014-11-30 23:07:09 +00:00
|
|
|
|
(λ b₁ ih, le.trans !pred_le ih)
|
2014-11-22 21:11:16 +00:00
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
end nat
|