Library UniMath.Foundations.NaturalNumbers
Natural numbers and their properties. Vladimir Voevodsky. Apr. - Sep. 2011
Contents
- Equality and inequality on nat
- Inequalities on nat
- Boolean "less of equal" and "greater or equal" on nat
- Semi-boolean "greater" on nat or natgth
- Semi-boolean "less" on nat or natlth
- Semi-boolean "less or equal" on nat or natleh
- Semi-boolean "greater or equal" on nat or natgeh
- Simple implications between comparisons
- Comparison alternatives
- Mixed transitivities
- Two comparisons and S
- Comparison alternatives and S
- Some properties of plus on nat
- The structure of the additive abelian monoid on nat
- Addition and comparisons
- Comparisons and n -> n + 1
- Two comparisons and n -> n + 1
- Comparison alternatives and n -> n + 1
- Cancellation properties of plus on nat
- Some properties of minus on nat
- Basic algebraic properties of mul on nat
- nat as a commutative rig
- Cancellation properties of mul on nat
- Multiplication and comparisons
- Properties of comparisons in the terminology of algebra1.v
- Submonoid of non-zero elements in nat
- Division with a remainder on nat
- Exponentiation natpower n m ("n to the power of m") on nat
- Factorial on nat
- The order-preserving functions di i : nat -> nat whose image is the complement of one element i.
- The order-preserving functions si i : nat -> nat that take the value i twice.
- Inductive types le with values in UU
Preamble
Definition natnegpaths (x y : nat) : hProp := make_hProp (x != y) (isapropneg _).
Fixpoint natneq_hProp (n m : nat) : hProp :=
match n, m with
| S n, S m => natneq_hProp n m
| O, O => hfalse
| _, _ => htrue
end.
Notation " x ≠ y " := (natneq_hProp x y) (at level 70, no associativity) : nat_scope.
Lemma negpaths0sx (x : nat) : ¬ (0 = S x).
Show proof.
set (f := λ n : nat, match n with O => true | S m => false end).
apply (negf (@maponpaths _ _ f 0 (S x)) nopathstruetofalse).
apply (negf (@maponpaths _ _ f 0 (S x)) nopathstruetofalse).
Lemma negpathssx0 (x : nat) : ¬ (S x = 0).
Show proof.
Lemma invmaponpathsS (n m : nat) : S n = S m -> n = m.
Show proof.
intros e.
set (f := λ n : nat, match n with O => O | S m => m end).
apply (@maponpaths _ _ f (S n) (S m) e).
set (f := λ n : nat, match n with O => O | S m => m end).
apply (@maponpaths _ _ f (S n) (S m) e).
Lemma noeqinjS (x x' : nat) : ¬ (x = x') -> ¬ (S x = S x').
Show proof.
Lemma natneq_iff_neq n m : ¬ (n = m) <-> n ≠ m.
Show proof.
revert m.
induction n as [|n N].
- intro m. induction m as [|m _].
+ apply logeq_both_false.
* intro n. exact (n (idpath 0)).
* simpl. exact (idfun ∅).
+ apply logeq_both_true.
* apply negpaths0sx.
* simpl. exact tt.
- intro m. induction m as [|m _].
+ apply logeq_both_true.
* apply negpathssx0.
* simpl. exact tt.
+ split.
* intro ne. apply (pr1 (N m)).
intro r. exact (ne (maponpaths S r)).
* intro neq. apply noeqinjS.
apply (pr2 (N m)). exact neq.
induction n as [|n N].
- intro m. induction m as [|m _].
+ apply logeq_both_false.
* intro n. exact (n (idpath 0)).
* simpl. exact (idfun ∅).
+ apply logeq_both_true.
* apply negpaths0sx.
* simpl. exact tt.
- intro m. induction m as [|m _].
+ apply logeq_both_true.
* apply negpathssx0.
* simpl. exact tt.
+ split.
* intro ne. apply (pr1 (N m)).
intro r. exact (ne (maponpaths S r)).
* intro neq. apply noeqinjS.
apply (pr2 (N m)). exact neq.
Lemma nat_neq_to_nopath {n m : nat} : ¬ (n = m) <- n ≠ m.
Show proof.
Lemma nat_nopath_to_neq {n m : nat} : ¬ (n = m) -> n ≠ m.
Show proof.
Lemma natneq0sx (x : nat) : 0 ≠ S x.
Show proof.
Lemma natneqsx0 (x : nat) : S x ≠ 0.
Show proof.
Lemma natneqinjS (x x' : nat) : x ≠ x' -> S x ≠ S x'.
Show proof.
Lemma isirrefl_natneq i : ¬ (i ≠ i).
Show proof.
Lemma issymm_natneq i j : i ≠ j -> j ≠ i.
Show proof.
Definition isdeceqnat: isdeceq nat.
Show proof.
unfold isdeceq. intro x. induction x as [ | x IHx ].
- intro x'. induction x'.
+ apply (ii1 (idpath O)).
+ apply (ii2 (negpaths0sx x')).
- intro x'. induction x'.
+ apply (ii2 (negpathssx0 x)).
+ induction (IHx x') as [ p | e ].
* apply (ii1 (maponpaths S p)).
* apply (ii2 (noeqinjS _ _ e)).
- intro x'. induction x'.
+ apply (ii1 (idpath O)).
+ apply (ii2 (negpaths0sx x')).
- intro x'. induction x'.
+ apply (ii2 (negpathssx0 x)).
+ induction (IHx x') as [ p | e ].
* apply (ii1 (maponpaths S p)).
* apply (ii2 (noeqinjS _ _ e)).
Definition isisolatedn (n : nat) : isisolated _ n.
Show proof.
Theorem isasetnat: isaset nat.
Show proof.
Definition natset : hSet := make_hSet _ isasetnat.
Lemma nat_eq_or_neq (m n : nat) : (m = n) ⨿ (m ≠ n).
Show proof.
revert m. induction n as [|n N].
- intro m. induction m as [|m _].
+ apply ii1. apply idpath.
+ apply ii2. exact tt.
- intro m. induction m as [|m _].
+ apply ii2. exact tt.
+ induction (N m) as [eq|neq].
* apply ii1, maponpaths. assumption.
* apply ii2. assumption.
- intro m. induction m as [|m _].
+ apply ii1. apply idpath.
+ apply ii2. exact tt.
- intro m. induction m as [|m _].
+ apply ii2. exact tt.
+ induction (N m) as [eq|neq].
* apply ii1, maponpaths. assumption.
* apply ii2. assumption.
Definition isdecrel_natneq : isdecrel (λ m n, m ≠ n).
Show proof.
intros n. induction n as [|n N].
- intro m. induction m as [|m _].
+ simpl. exact (ii2 (idfun ∅)).
+ simpl. exact (ii1 tt).
- intro m. induction m as [|m _].
+ simpl. exact (ii1 tt).
+ exact (N m).
- intro m. induction m as [|m _].
+ simpl. exact (ii2 (idfun ∅)).
+ simpl. exact (ii1 tt).
- intro m. induction m as [|m _].
+ simpl. exact (ii1 tt).
+ exact (N m).
Definition nateq (x y : nat) : hProp := make_hProp (x = y) (isasetnat _ _).
Definition isdecrelnateq : isdecrel nateq := λ a b, isdeceqnat a b.
Definition natdeceq : decrel nat := make_decrel isdecrelnateq.
Definition natdecneq : decrel nat := make_decrel isdecrel_natneq.
Definition natboolneq : brel nat := decreltobrel natdecneq.
Theorem isinclS : isincl S.
Show proof.
Theorem isdecinclS : isdecincl S.
Show proof.
intro n. apply isdecpropif.
- apply (isinclS n).
- destruct n as [ | n ].
+ assert (nh : ¬ (hfiber S 0)).
* intro hf. induction hf as [ m e ]. apply (negpathssx0 _ e).
* apply (ii2 nh).
+ apply (ii1 (make_hfiber _ n (idpath _))).
- apply (isinclS n).
- destruct n as [ | n ].
+ assert (nh : ¬ (hfiber S 0)).
* intro hf. induction hf as [ m e ]. apply (negpathssx0 _ e).
* apply (ii2 nh).
+ apply (ii1 (make_hfiber _ n (idpath _))).
Fixpoint natgtb (n m : nat) : bool :=
match n, m with
| S n, S m => natgtb n m
| O, _ => false
| _, _ => true
end.
Semi-boolean "greater" on nat or natgth
Definition natgth (n m : nat) : hProp := make_hProp (natgtb n m = true) (isasetbool _ _).
Notation " x > y " := (natgth x y) : nat_scope.
Lemma negnatgth0n (n : nat) : ¬ (0 > n).
Show proof.
Lemma natgthsnn (n : nat) : S n > n.
Show proof.
Lemma natgthsn0 (n : nat) : S n > 0.
Show proof.
Lemma negnatgth0tois0 (n : nat) (ng : ¬ (n > 0)) : n = 0.
Show proof.
Lemma natneq0togth0 (n : nat) (ne : n ≠ 0) : n > 0.
Show proof.
Lemma nat1gthtois0 (n : nat) (g : 1 > n) : n = 0.
Show proof.
Lemma istransnatgth (n m k : nat) : n > m -> m > k -> n > k.
Show proof.
revert m k. induction n as [ | n IHn ].
- intros m k g. induction (negnatgth0n _ g).
- intro m. destruct m as [ | m ].
+ intros k g g'. induction (negnatgth0n _ g').
+ intro k. destruct k as [ | k ].
* intros. apply natgthsn0.
* apply (IHn m k).
- intros m k g. induction (negnatgth0n _ g).
- intro m. destruct m as [ | m ].
+ intros k g g'. induction (negnatgth0n _ g').
+ intro k. destruct k as [ | k ].
* intros. apply natgthsn0.
* apply (IHn m k).
Lemma isirreflnatgth (n : nat) : ¬ (n > n).
Show proof.
Notation negnatlthnn := isirreflnatgth.
Lemma natgthtoneq (n m : nat) (g : n > m) : n ≠ m.
Show proof.
Lemma isasymmnatgth (n m : nat) : n > m -> m > n -> empty.
Show proof.
Lemma isantisymmnegnatgth (n m : nat) : ¬ (n > m) -> ¬ (m > n) -> n = m.
Show proof.
revert m. induction n as [ | n IHn ].
- intros m ng0m ngm0. apply (pathsinv0 (negnatgth0tois0 _ ngm0)).
- intro m. destruct m as [ | m ].
+ intros ngsn0 ng0sn. induction (ngsn0 (natgthsn0 _)).
+ intros ng1 ng2. apply (maponpaths S (IHn m ng1 ng2)).
- intros m ng0m ngm0. apply (pathsinv0 (negnatgth0tois0 _ ngm0)).
- intro m. destruct m as [ | m ].
+ intros ngsn0 ng0sn. induction (ngsn0 (natgthsn0 _)).
+ intros ng1 ng2. apply (maponpaths S (IHn m ng1 ng2)).
Lemma isdecrelnatgth : isdecrel natgth.
Show proof.
Definition natgthdec := make_decrel isdecrelnatgth.
Lemma isnegrelnatgth : isnegrel natgth.
Show proof.
Lemma iscoantisymmnatgth (n m : nat) : ¬ (n > m) -> (m > n) ⨿ (n = m).
Show proof.
revert n m.
apply isantisymmnegtoiscoantisymm.
- apply isdecrelnatgth.
- intros n m. apply isantisymmnegnatgth.
apply isantisymmnegtoiscoantisymm.
- apply isdecrelnatgth.
- intros n m. apply isantisymmnegnatgth.
Lemma iscotransnatgth (n m k : nat) : n > k -> (n > m) ⨿ (m > k).
Show proof.
intros gnk. induction (isdecrelnatgth n m) as [ p | np ].
- apply ii1. assumption.
- apply ii2. induction (isdecrelnatgth m n) as [r|nr].
+ apply (istransnatgth _ _ _ r gnk).
+ assert (e := isantisymmnegnatgth _ _ np nr); clear np nr.
induction e. assumption.
- apply ii1. assumption.
- apply ii2. induction (isdecrelnatgth m n) as [r|nr].
+ apply (istransnatgth _ _ _ r gnk).
+ assert (e := isantisymmnegnatgth _ _ np nr); clear np nr.
induction e. assumption.
Definition natlth (n m : nat) := m > n.
Notation " x < y " := (natlth x y) : nat_scope.
Definition negnatlthn0 (n : nat) : ¬ (n < 0) := negnatgth0n n.
Definition natlthnsn (n : nat) : n < S n := natgthsnn n.
Definition negnat0lthtois0 (n : nat) (nl : ¬ (0 < n)) : n = 0 := negnatgth0tois0 n nl.
Definition natneq0to0lth (n : nat) : n ≠ 0 -> 0 < n := natneq0togth0 n.
Definition natlth1tois0 (n : nat) : n < 1 -> n = 0 := nat1gthtois0 _.
Definition istransnatlth (n m k : nat) : n < m -> m < k -> n < k :=
λ lnm lmk, istransnatgth _ _ _ lmk lnm.
Definition isirreflnatlth (n : nat) : ¬ (natlth n n) := isirreflnatgth n.
Notation negnatgthnn := isirreflnatlth.
Lemma natlthtoneq (n m : nat) (g : natlth n m) : n ≠ m.
Show proof.
Definition isasymmnatlth (n m : nat) : natlth n m -> natlth m n -> empty :=
λ lnm lmn, isasymmnatgth _ _ lmn lnm.
Definition isantisymmnegnattth (n m : nat) :
¬ (natlth n m) -> ¬ (natlth m n) -> n = m := λ nlnm nlmn, isantisymmnegnatgth _ _ nlmn nlnm.
Definition isdecrelnatlth : isdecrel natlth := λ n m, isdecrelnatgth m n.
Definition natlthdec := make_decrel isdecrelnatlth.
Definition isnegrelnatlth : isnegrel natlth := λ n m, isnegrelnatgth m n.
Definition iscoantisymmnatlth (n m : nat) : ¬ (natlth n m) -> (natlth m n) ⨿ (n = m).
Show proof.
intros nlnm.
induction (iscoantisymmnatgth m n nlnm) as [ l | e ].
- apply (ii1 l).
- apply (ii2 (pathsinv0 e)).
induction (iscoantisymmnatgth m n nlnm) as [ l | e ].
- apply (ii1 l).
- apply (ii2 (pathsinv0 e)).
Definition iscotransnatlth (n m k : nat) : n < k -> (n < m) ⨿ (m < k).
Show proof.
Definition natleh (n m : nat) := S m > n.
Notation " x <= y " := (natleh x y) : nat_scope.
Notation " x ≤ y " := (natleh x y) (at level 70, no associativity) : nat_scope.
Definition isdecrelnatleh : isdecrel natleh := λ m n, isdecrelnatgth _ _.
Definition negnatlehsn0 (n : nat) : ¬ (S n ≤ 0) := negnatlthn0 n.
Lemma natlehneggth {n m : nat} : n ≤ m -> ¬ (n > m).
Show proof.
revert m. induction n as [|n N].
- intros m _. exact (negnatgth0n m).
- intros m. induction m as [|m _].
+ intros r _. exact (negnatlehsn0 n r).
+ exact (N m).
- intros m _. exact (negnatgth0n m).
- intros m. induction m as [|m _].
+ intros r _. exact (negnatlehsn0 n r).
+ exact (N m).
Lemma natgthnegleh {n m : nat} : n > m -> ¬ (n ≤ m).
Show proof.
Lemma negnatSleh n : ¬ (S n ≤ n).
Show proof.
Lemma negnatgthtoleh {n m : nat} : ¬ (n > m) -> n ≤ m.
Show proof.
unfold natleh. revert m. induction n as [|n N].
- intros m r. exact (natgthsn0 m).
- intro m. change (S m > S n) with (m > n). induction m as [|m _].
+ intro r. contradicts (natgthsn0 n) r.
+ change (S n > S m) with (n > m). intro r. exact (N m r).
- intros m r. exact (natgthsn0 m).
- intro m. change (S m > S n) with (m > n). induction m as [|m _].
+ intro r. contradicts (natgthsn0 n) r.
+ change (S n > S m) with (n > m). intro r. exact (N m r).
Lemma negnatlehtogth {n m : nat} : n > m <- ¬ (n ≤ m).
Show proof.
Definition neggth_logeq_leh (n m : nat) : ¬ (n > m) <-> n ≤ m := (negnatgthtoleh,,natlehneggth).
Definition natleh0tois0 {n : nat} (l : n ≤ 0) : n = 0 := natlth1tois0 n l.
Definition natleh0n (n : nat) : 0 ≤ n := natgthsn0 _.
Definition negnatlehsnn (n : nat) : ¬ (S n ≤ n) := isirreflnatlth _.
Definition istransnatleh {n m k : nat} : n ≤ m -> m ≤ k -> n ≤ k.
Show proof.
intros r s.
apply negnatgthtoleh.
assert (b := natlehneggth r); clear r.
assert (c := natlehneggth s); clear s.
intro r.
induction (iscotransnatgth _ m _ r) as [t|t].
- contradicts b t.
- contradicts c t.
apply negnatgthtoleh.
assert (b := natlehneggth r); clear r.
assert (c := natlehneggth s); clear s.
intro r.
induction (iscotransnatgth _ m _ r) as [t|t].
- contradicts b t.
- contradicts c t.
Definition isreflnatleh n : n ≤ n.
Show proof.
Definition isantisymmnatleh : isantisymm natleh.
Show proof.
intros m. induction m as [|m M].
- intros n _ s. unfold natleh in s.
apply pathsinv0. apply nat1gthtois0. exact s.
- intros n. induction n as [|n _].
+ intros r _. contradicts r (negnatlehsn0 m).
+ intros r s.
change (S m ≤ S n) with (m ≤ n) in r.
change (S n ≤ S m) with (n ≤ m) in s.
apply (maponpaths S).
apply M.
* assumption.
* assumption.
- intros n _ s. unfold natleh in s.
apply pathsinv0. apply nat1gthtois0. exact s.
- intros n. induction n as [|n _].
+ intros r _. contradicts r (negnatlehsn0 m).
+ intros r s.
change (S m ≤ S n) with (m ≤ n) in r.
change (S n ≤ S m) with (n ≤ m) in s.
apply (maponpaths S).
apply M.
* assumption.
* assumption.
Definition natlehdec : decrel nat := make_decrel isdecrelnatleh.
Definition isnegrelnatleh : isnegrel natleh.
Show proof.
Definition natlthtoleh (m n : nat) : m < n -> m ≤ n.
Show proof.
intros r. unfold natleh. unfold natlth in r.
generalize r. clear r. generalize m. clear m.
induction n as [|n N].
- intros ? r. contradicts r (negnatgth0n m).
- intros ? r. induction m as [|m _].
+ apply natgthsn0.
+ change (S n > S m) with (n > m) in r.
change (S (S n) > S m) with (S n > m).
apply N. assumption.
generalize r. clear r. generalize m. clear m.
induction n as [|n N].
- intros ? r. contradicts r (negnatgth0n m).
- intros ? r. induction m as [|m _].
+ apply natgthsn0.
+ change (S n > S m) with (n > m) in r.
change (S (S n) > S m) with (S n > m).
apply N. assumption.
Definition iscoasymmnatleh (n m : nat) : ¬ (n ≤ m) -> m ≤ n.
Show proof.
intros r. apply negnatgthtoleh. intros s. unfold natleh in r.
apply r. apply natlthtoleh. assumption.
apply r. apply natlthtoleh. assumption.
Definition istotalnatleh : istotal natleh.
Show proof.
intros x y. induction (isdecrelnatleh x y) as [ lxy | lyx ].
- apply (hinhpr (ii1 lxy)).
- apply hinhpr. apply ii2. apply (iscoasymmnatleh _ _ lyx).
- apply (hinhpr (ii1 lxy)).
- apply hinhpr. apply ii2. apply (iscoasymmnatleh _ _ lyx).
Definition natgeh (n m : nat) : hProp := m ≤ n.
Notation " x >= y " := (natgeh x y) : nat_scope.
Notation " x ≥ y " := (natgeh x y) (at level 70, no associativity) : nat_scope.
Definition nat0gehtois0 (n : nat) (g : 0 ≥ n) : n = 0 := natleh0tois0 g.
Definition natgehn0 (n : nat) : n ≥ 0 := natleh0n n.
Definition negnatgeh0sn (n : nat) : ¬ (0 ≥ (S n)) := negnatlehsn0 n.
Definition negnatgehnsn (n : nat) : ¬ (n ≥ (S n)) := negnatlehsnn n.
Definition istransnatgeh (n m k : nat) : n ≥ m -> m ≥ k -> n ≥ k := λ gnm gmk, istransnatleh gmk gnm.
Definition isreflnatgeh (n : nat) : n ≥ n := isreflnatleh _.
Definition isantisymmnatgeh (n m : nat) : n ≥ m -> m ≥ n -> n = m :=
λ gnm gmn, isantisymmnatleh _ _ gmn gnm.
Definition isdecrelnatgeh : isdecrel natgeh := λ n m, isdecrelnatleh m n.
Definition natgehdec : decrel nat := make_decrel isdecrelnatgeh.
Definition isnegrelnatgeh : isnegrel natgeh := λ n m, isnegrelnatleh m n.
Definition iscoasymmnatgeh (n m : nat) (nl : ¬ (n ≥ m)) : m ≥ n := iscoasymmnatleh _ _ nl.
Definition istotalnatgeh : istotal natgeh := λ n m, istotalnatleh m n.
Definition natgthtogeh (n m : nat) : n > m -> n ≥ m.
Show proof.
Definition natlehtonegnatgth (n m : nat) : n ≤ m -> ¬ (n > m).
Show proof.
Definition natgthtonegnatleh (n m : nat) : n > m -> ¬ (n ≤ m) := λ g l, natlehtonegnatgth _ _ l g.
Definition natgehtonegnatlth (n m : nat) : n ≥ m -> ¬ (n < m) :=
λ gnm lnm, natlehtonegnatgth _ _ gnm lnm.
Definition natlthtonegnatgeh (n m : nat) : n < m -> ¬ (n ≥ m) :=
λ gnm lnm, natlehtonegnatgth _ _ lnm gnm.
Definition negnatgehtolth (n m : nat) : ¬ (n ≥ m) -> n < m.
Show proof.
Definition negnatlthtogeh (n m : nat) : ¬ (n < m) -> n ≥ m := λ nl, negnatgthtoleh nl.
Definition natlehnsn (n : nat) : n ≤ S n := natlthtoleh _ _ (natgthsnn n).
Definition natgehsnn (n : nat) : (S n) ≥ n := natlehnsn n.
Definition natgthorleh (n m : nat) : (n > m) ⨿ (n ≤ m).
Show proof.
intros.
induction (isdecrelnatgth n m) as [a|a].
- apply ii1. assumption.
- apply ii2. apply negnatgthtoleh. assumption.
induction (isdecrelnatgth n m) as [a|a].
- apply ii1. assumption.
- apply ii2. apply negnatgthtoleh. assumption.
Definition natlthorgeh (n m : nat) : (n < m) ⨿ (n ≥ m) := natgthorleh _ _.
Definition natchoice0 (n : nat) : (0 = n) ⨿ (0 < n).
Show proof.
Definition natneqchoice (n m : nat) (ne : n ≠ m) : (n > m) ⨿ (n < m).
Show proof.
intros. induction (natgthorleh n m) as [ l | g ].
- exact (ii1 l).
- induction (natlthorgeh n m) as [ l' | g' ].
+ apply (ii2 l').
+ contradicts (nat_neq_to_nopath ne) (isantisymmnatleh _ _ g g').
- exact (ii1 l).
- induction (natlthorgeh n m) as [ l' | g' ].
+ apply (ii2 l').
+ contradicts (nat_neq_to_nopath ne) (isantisymmnatleh _ _ g g').
Definition natlehchoice (n m : nat) (l : n ≤ m) : (n < m) ⨿ (n = m).
Show proof.
intros. induction (natlthorgeh n m) as [ l' | g ].
- apply (ii1 l').
- apply (ii2 (isantisymmnatleh _ _ l g)).
- apply (ii1 l').
- apply (ii2 (isantisymmnatleh _ _ l g)).
Definition natgehchoice (n m : nat) (g : n ≥ m) : (n > m) ⨿ (n = m).
Show proof.
intros. induction (natgthorleh n m) as [ g' | l ].
- apply (ii1 g').
- apply (ii2 (isantisymmnatleh _ _ l g)).
- apply (ii1 g').
- apply (ii2 (isantisymmnatleh _ _ l g)).
Lemma natgthgehtrans (n m k : nat) : n > m -> m ≥ k -> n > k.
Show proof.
intros gnm gmk. induction (natgehchoice m k gmk) as [ g' | e ].
- apply (istransnatgth _ _ _ gnm g').
- rewrite e in gnm. apply gnm.
- apply (istransnatgth _ _ _ gnm g').
- rewrite e in gnm. apply gnm.
Lemma natgehgthtrans (n m k : nat) : n ≥ m -> m > k -> n > k.
Show proof.
intros gnm gmk. induction (natgehchoice n m gnm) as [ g' | e ].
- apply (istransnatgth _ _ _ g' gmk).
- rewrite e. apply gmk.
- apply (istransnatgth _ _ _ g' gmk).
- rewrite e. apply gmk.
Lemma natlthlehtrans (n m k : nat) : n < m -> m ≤ k -> n < k.
Show proof.
Lemma natlehlthtrans (n m k : nat) : n ≤ m -> m < k -> n < k.
Show proof.
Lemma natltltSlt (i j n : nat) : i < j -> j < S n -> i < n.
Show proof.
Two comparisons and S
Lemma natgthtogehsn (n m : nat) : n > m -> n ≥ (S m).
Show proof.
revert m. induction n as [ | n IHn ].
- intros m X. induction (negnatgth0n _ X).
- intros m X. destruct m as [ | m ].
+ apply (natgehn0 n).
+ apply (IHn m X).
- intros m X. induction (negnatgth0n _ X).
- intros m X. destruct m as [ | m ].
+ apply (natgehn0 n).
+ apply (IHn m X).
Lemma natgthsntogeh (n m : nat) : S n > m -> n ≥ m.
Show proof.
Lemma natgehtogthsn (n m : nat) : n ≥ m -> S n > m.
Show proof.
Lemma natgehsntogth (n m : nat) : n ≥ (S m) -> n > m.
Show proof.
Lemma natlthtolehsn (n m : nat) : n < m -> S n ≤ m.
Show proof.
Lemma natlehsntolth (n m : nat) : S n ≤ m -> n < m.
Show proof.
Lemma natlehtolthsn (n m : nat) : n ≤ m -> n < S m.
Show proof.
Lemma natlthsntoleh (n m : nat) : n < S m -> n ≤ m.
Show proof.
Comparision alternatives and S
Lemma natlehchoice2 (n m : nat) : n ≤ m -> (S n ≤ m) ⨿ (n = m).
Show proof.
intros l. induction (natlehchoice n m l) as [ l' | e ].
- apply (ii1 (natlthtolehsn _ _ l')).
- apply (ii2 e).
- apply (ii1 (natlthtolehsn _ _ l')).
- apply (ii2 e).
Lemma natgehchoice2 (n m : nat) : n ≥ m -> (n ≥ (S m)) ⨿ (n = m).
Show proof.
intros g. induction (natgehchoice n m g) as [ g' | e ].
- apply (ii1 (natgthtogehsn _ _ g')).
- apply (ii2 e).
- apply (ii1 (natgthtogehsn _ _ g')).
- apply (ii2 e).
Lemma natgthchoice2 (n m : nat) : n > m -> (n > S m) ⨿ (n = (S m)).
Show proof.
intros g.
induction (natgehchoice _ _ (natgthtogehsn _ _ g)) as [ g' | e ].
- apply (ii1 g').
- apply (ii2 e).
induction (natgehchoice _ _ (natgthtogehsn _ _ g)) as [ g' | e ].
- apply (ii1 g').
- apply (ii2 e).
Lemma natlthchoice2 (n m : nat) : n < m -> (S n < m) ⨿ ((S n) = m).
Show proof.
intros l.
induction (natlehchoice _ _ (natlthtolehsn _ _ l)) as [ l' | e ].
- apply (ii1 l').
- apply (ii2 e).
induction (natlehchoice _ _ (natlthtolehsn _ _ l)) as [ l' | e ].
- apply (ii1 l').
- apply (ii2 e).
Some properties of plus on nat
The structure of the additive abelian monoid on nat
Lemma natplusl0 (n : nat) : (0 + n) = n.
Show proof.
Lemma natplusr0 (n : nat) : (n + 0) = n.
Show proof.
#[global]
Hint Resolve natplusr0: natarith.
Lemma natplusnsm (n m : nat) : n + S m = S n + m.
Show proof.
revert m.
simpl. induction n as [ | n IHn ].
- auto with natarith.
- simpl. intro. apply (maponpaths S (IHn m)).
#[global]simpl. induction n as [ | n IHn ].
- auto with natarith.
- simpl. intro. apply (maponpaths S (IHn m)).
Hint Resolve natplusnsm : natarith.
#[global]
Hint Resolve pathsinv0 : natarith.
Lemma natpluscomm (n m : nat) : n + m = m + n.
Show proof.
revert m. induction n as [ | n IHn ].
- intro.
auto with natarith.
- intro. set (int := IHn (S m)).
set (int2 := pathsinv0 (natplusnsm n m)).
set (int3 := pathsinv0 (natplusnsm m n)).
set (int4 := pathscomp0 int2 int).
apply (pathscomp0 int4 int3).
#[global]- intro.
auto with natarith.
- intro. set (int := IHn (S m)).
set (int2 := pathsinv0 (natplusnsm n m)).
set (int3 := pathsinv0 (natplusnsm m n)).
set (int4 := pathscomp0 int2 int).
apply (pathscomp0 int4 int3).
Hint Resolve natpluscomm : natarith.
Lemma natplusassoc (n m k : nat) : ((n + m) + k) = (n + (m + k)).
Show proof.
revert m k. induction n as [ | n IHn ].
- auto with natarith.
- intros. simpl. apply (maponpaths S (IHn m k)).
#[global]- auto with natarith.
- intros. simpl. apply (maponpaths S (IHn m k)).
Hint Resolve natplusassoc : natarith.
Definition natgthtogths (n m : nat) : n > m -> (S n) > m.
Show proof.
Definition negnatgthmplusnm (n m : nat) : ¬ (m > n + m).
Show proof.
intros. induction n as [ | n IHn ].
- apply isirreflnatgth.
- apply natlehtonegnatgth.
assert (r := negnatgthtoleh IHn); clear IHn.
apply (istransnatleh r (natlthtoleh _ _ (natlthnsn _))).
- apply isirreflnatgth.
- apply natlehtonegnatgth.
assert (r := negnatgthtoleh IHn); clear IHn.
apply (istransnatleh r (natlthtoleh _ _ (natlthnsn _))).
Definition negnatgthnplusnm (n m : nat) : ¬ (n > (n + m)).
Show proof.
Definition natgthandplusl (n m k : nat) : n > m -> (k + n) > (k + m).
Show proof.
intros l. induction k as [ | k IHk ].
- assumption.
- assumption.
- assumption.
- assumption.
Definition natgthandplusr (n m k : nat) : n > m -> (n + k) > (m + k).
Show proof.
Definition natgthandpluslinv (n m k : nat) : (k + n) > (k + m) -> n > m.
Show proof.
intros l. induction k as [ | k IHk ].
- assumption.
- apply (IHk l).
- assumption.
- apply (IHk l).
Definition natgthandplusrinv (n m k : nat) : (n + k) > (m + k) -> n > m.
Show proof.
intros l.
rewrite (natpluscomm n k) in l.
rewrite (natpluscomm m k) in l.
apply (natgthandpluslinv _ _ _ l).
rewrite (natpluscomm n k) in l.
rewrite (natpluscomm m k) in l.
apply (natgthandpluslinv _ _ _ l).
Definition natgthandplusm (n m : nat) (H : m > 0) : n + m > n.
Show proof.
revert m H. induction n as [ | n].
- intros m H. rewrite natplusl0. exact H.
- intros m H. rewrite <- natplusnsm. change (S n) with (1 + n). rewrite (natpluscomm 1 n).
apply natgthandplusl. apply H.
- intros m H. rewrite natplusl0. exact H.
- intros m H. rewrite <- natplusnsm. change (S n) with (1 + n). rewrite (natpluscomm 1 n).
apply natgthandplusl. apply H.
Definition natlthtolths (n m : nat) : n < m -> n < S m := natgthtogths _ _.
Definition negnatlthplusnmm (n m : nat) : ¬ (n + m < m) := negnatgthmplusnm _ _.
Definition negnatlthplusnmn (n m : nat) : ¬ (n + m < n) := negnatgthnplusnm _ _.
Definition natlthandplusl (n m k : nat) : n < m -> k + n < k + m := natgthandplusl _ _ _.
Definition natlthandplusr (n m k : nat) : n < m -> n + k < m + k := natgthandplusr _ _ _.
Definition natlthandpluslinv (n m k : nat) : k + n < k + m -> n < m := natgthandpluslinv _ _ _.
Definition natlthandplusrinv (n m k : nat) : n + k < m + k -> n < m := natgthandplusrinv _ _ _.
Definition natlthandplusm (n m : nat) (H : 0 < m) : n < n + m := natgthandplusm _ _ H.
Definition natlehtolehs (n m : nat) : n ≤ m -> n ≤ S m.
Show proof.
Definition natlehmplusnm (n m : nat) : m ≤ n + m.
Show proof.
intros. induction n as [|n N].
- change (0+m) with m. apply isreflnatleh.
- apply natlehtolehs. assumption.
- change (0+m) with m. apply isreflnatleh.
- apply natlehtolehs. assumption.
Lemma plus_n_Sm : ∏ n m:nat, S (n + m) = n + S m.
Show proof.
Definition natlehnplusnm (n m : nat) : n ≤ n + m.
Show proof.
intros. induction m as [|m M].
- induction (!natplusr0 n). apply isreflnatleh.
- induction (plus_n_Sm n m). apply natlehtolehs. assumption.
- induction (!natplusr0 n). apply isreflnatleh.
- induction (plus_n_Sm n m). apply natlehtolehs. assumption.
Definition natlehandplusl (n m k : nat) : n ≤ m -> k + n ≤ k + m.
Show proof.
Definition natlehandplusr (n m k : nat) : n ≤ m -> n + k ≤ m + k.
Show proof.
Definition natlehandplus (i j k l : nat) : i ≤ j -> k ≤ l -> i + k ≤ j + l.
Show proof.
intros r s.
use (@istransnatleh _ (j + k) _).
- apply natlehandplusr. apply r.
- apply natlehandplusl. apply s.
use (@istransnatleh _ (j + k) _).
- apply natlehandplusr. apply r.
- apply natlehandplusl. apply s.
Definition natlehandpluslinv (n m k : nat) : k + n ≤ k + m -> n ≤ m.
Show proof.
Definition natlehandplusrinv (n m k : nat) : n + k ≤ m + k -> n ≤ m.
Show proof.
unfold natleh. intros r.
change (S (m + k)) with (S m + k) in r.
apply (natgthandplusrinv _ _ k). assumption.
change (S (m + k)) with (S m + k) in r.
apply (natgthandplusrinv _ _ k). assumption.
Definition natgehtogehs (n m : nat) : n ≥ m -> S n ≥ m := natlehtolehs _ _.
Definition natgehplusnmm (n m : nat) : n + m ≥ m := natlehmplusnm _ _.
Definition natgehplusnmn (n m : nat) : n + m ≥ n := natlehnplusnm _ _.
Definition natgehandplusl (n m k : nat) : n ≥ m -> k + n ≥ k + m := natlehandplusl _ _ _.
Definition natgehandplusr (n m k : nat) : n ≥ m -> n + k ≥ m + k := natlehandplusr _ _ _.
Definition natgehandpluslinv (n m k : nat) : k + n ≥ k + m -> n ≥ m := natlehandpluslinv _ _ _.
Definition natgehandplusrinv (n m k : nat) : n + k ≥ m + k -> n ≥ m := natlehandplusrinv _ _ _.
Definition natgthtogthp1 (n m : nat) : n > m -> (n + 1) > m.
Show proof.
Definition natlthtolthp1 (n m : nat) : n < m -> n < m + 1 := natgthtogthp1 _ _.
Definition natlehtolehp1 (n m : nat) : n ≤ m -> n ≤ m + 1.
Show proof.
Definition natgehtogehp1 (n m : nat) : n ≥ m -> (n + 1) ≥ m := natlehtolehp1 _ _.
Lemma natgthtogehp1 (n m : nat) : n > m -> n ≥ (m + 1).
Show proof.
Lemma natgthp1togeh (n m : nat) : (n + 1) > m -> n ≥ m.
Show proof.
Lemma natlehp1tolth (n m : nat) : n + 1 ≤ m -> n < m.
Show proof.
Lemma natlthtolehp1 (n m : nat) : n < m -> n + 1 ≤ m.
Show proof.
Lemma natlthp1toleh (n m : nat) : n < m + 1 -> n ≤ m.
Show proof.
Lemma natgehp1togth (n m : nat) : n ≥ (m + 1) -> n > m.
Show proof.
Lemma natlehchoice3 (n m : nat) : n ≤ m -> (n + 1 ≤ m) ⨿ (n = m).
Show proof.
intros l. induction (natlehchoice n m l) as [ l' | e ].
- apply (ii1 (natlthtolehp1 _ _ l')).
- apply (ii2 e).
- apply (ii1 (natlthtolehp1 _ _ l')).
- apply (ii2 e).
Lemma natgehchoice3 (n m : nat) : n ≥ m -> (n ≥ (m + 1)) ⨿ (n = m).
Show proof.
intros g. induction (natgehchoice n m g) as [ g' | e ].
- apply (ii1 (natgthtogehp1 _ _ g')).
- apply (ii2 e).
- apply (ii1 (natgthtogehp1 _ _ g')).
- apply (ii2 e).
Lemma natgthchoice3 (n m : nat) : n > m -> (n > (m + 1)) ⨿ (n = (m + 1)).
Show proof.
intros g.
induction (natgehchoice _ _ (natgthtogehp1 _ _ g)) as [ g' | e ].
- apply (ii1 g').
- apply (ii2 e).
induction (natgehchoice _ _ (natgthtogehp1 _ _ g)) as [ g' | e ].
- apply (ii1 g').
- apply (ii2 e).
Lemma natlthchoice3 (n m : nat) : n < m -> (n + 1 < m) ⨿ ((n + 1) = m).
Show proof.
intros l.
induction (natlehchoice _ _ (natlthtolehp1 _ _ l)) as [ l' | e ].
- apply (ii1 l').
- apply (ii2 e).
induction (natlehchoice _ _ (natlthtolehp1 _ _ l)) as [ l' | e ].
- apply (ii1 l').
- apply (ii2 e).
Lemma natlehchoice4 (n m : nat) : n < S m -> (n < m) ⨿ (n = m).
Show proof.
intros b.
induction (natlthorgeh n m) as [p|p].
- exact (ii1 p).
- exact (ii2 (isantisymmnatleh _ _ (natlthsntoleh _ _ b) p)).
induction (natlthorgeh n m) as [p|p].
- exact (ii1 p).
- exact (ii2 (isantisymmnatleh _ _ (natlthsntoleh _ _ b) p)).
Cancellation properties of plus on nat
Lemma pathsitertoplus (n m : nat) : (iteration S n m) = (n + m).
Show proof.
Lemma isinclnatplusr (n : nat) : isincl (λ m : nat, m + n).
Show proof.
induction n as [ | n IHn ].
- apply (isofhlevelfhomot 1 _ _ (λ m : nat, pathsinv0 (natplusr0 m))).
apply (isofhlevelfweq 1 (idweq nat)).
- apply (isofhlevelfhomot 1 _ _ (λ m : nat, pathsinv0 (natplusnsm m n))).
simpl. apply (isofhlevelfgf 1 _ _ isinclS IHn).
- apply (isofhlevelfhomot 1 _ _ (λ m : nat, pathsinv0 (natplusr0 m))).
apply (isofhlevelfweq 1 (idweq nat)).
- apply (isofhlevelfhomot 1 _ _ (λ m : nat, pathsinv0 (natplusnsm m n))).
simpl. apply (isofhlevelfgf 1 _ _ isinclS IHn).
Lemma isinclnatplusl (n : nat) : isincl (λ m : nat, n + m).
Show proof.
Lemma natplusrcan (a b c : nat) (is : a + c = b + c) : a = b.
Show proof.
Lemma natpluslcan (a b c : nat) (is : c + a = c + b) : a = b.
Show proof.
intros. rewrite (natpluscomm _ _) in is.
rewrite (natpluscomm c b) in is.
apply (natplusrcan a b c is).
rewrite (natpluscomm c b) in is.
apply (natplusrcan a b c is).
Lemma iscontrhfibernatplusr (n m : nat) (is : m ≥ n) : iscontr (hfiber (λ i : nat, i + n) m).
Show proof.
intros. apply iscontraprop1.
- apply isinclnatplusr.
- induction m as [ | m IHm ].
+ set (e := natleh0tois0 is). split with 0. apply e.
+ induction (natlehchoice2 _ _ is) as [ l | e ].
* set (j := IHm l). induction j as [ j e' ]. split with (S j). simpl.
apply (maponpaths S e').
* split with 0. simpl. assumption.
- apply isinclnatplusr.
- induction m as [ | m IHm ].
+ set (e := natleh0tois0 is). split with 0. apply e.
+ induction (natlehchoice2 _ _ is) as [ l | e ].
* set (j := IHm l). induction j as [ j e' ]. split with (S j). simpl.
apply (maponpaths S e').
* split with 0. simpl. assumption.
Lemma iscontrhfibernatplusl (n m : nat) (is : m ≥ n) : iscontr (hfiber (λ i : nat, n + i) m).
Show proof.
intros. apply iscontraprop1.
- apply isinclnatplusl.
- induction m as [ | m IHm ].
+ set (e := natleh0tois0 is). split with 0.
rewrite natplusr0. apply e.
+ induction (natlehchoice2 _ _ is) as [ l | e ].
* set (j := IHm l). induction j as [ j e' ]. split with (S j). simpl.
rewrite <- plus_n_Sm. apply (maponpaths S e').
* split with 0. simpl. rewrite natplusr0. assumption.
- apply isinclnatplusl.
- induction m as [ | m IHm ].
+ set (e := natleh0tois0 is). split with 0.
rewrite natplusr0. apply e.
+ induction (natlehchoice2 _ _ is) as [ l | e ].
* set (j := IHm l). induction j as [ j e' ]. split with (S j). simpl.
rewrite <- plus_n_Sm. apply (maponpaths S e').
* split with 0. simpl. rewrite natplusr0. assumption.
Lemma neghfibernatplusr (n m : nat) (is : m < n) : ¬ (hfiber (λ i : nat, i + n) m).
Show proof.
intros. intro h. induction h as [ i e ]. rewrite (pathsinv0 e) in is.
induction (natlehtonegnatgth _ _ (natlehmplusnm i n) is).
induction (natlehtonegnatgth _ _ (natlehmplusnm i n) is).
Lemma isdecinclnatplusr (n : nat) : isdecincl (λ i : nat, i + n).
Show proof.
intros. intro m. apply isdecpropif.
- apply (isinclnatplusr _ m).
- induction (natlthorgeh m n) as [ ni | i ].
+ apply (ii2 (neghfibernatplusr n m ni)).
+ apply (ii1 (pr1 (iscontrhfibernatplusr n m i))).
- apply (isinclnatplusr _ m).
- induction (natlthorgeh m n) as [ ni | i ].
+ apply (ii2 (neghfibernatplusr n m ni)).
+ apply (ii1 (pr1 (iscontrhfibernatplusr n m i))).
Some properties of minus on nat
Definition minuseq0 (n m : nat) (is : n <= m) : n - m = 0.
Show proof.
revert is. generalize n. clear n. induction m as [|m IHm].
- intros n is. rewrite (natleh0tois0 is). simpl. apply idpath.
- intro n. destruct n.
+ intro. apply idpath.
+ apply (IHm n).
- intros n is. rewrite (natleh0tois0 is). simpl. apply idpath.
- intro n. destruct n.
+ intro. apply idpath.
+ apply (IHm n).
Definition minuseq0' (n : nat) : n - n = 0.
Show proof.
Definition minusgth0 (n m : nat) (is : n > m) : n - m > 0.
Show proof.
revert m is. induction n as [ | n IHn ].
- intros. induction (negnatgth0n _ is).
- intro m. induction m as [ | m ].
+ intro. apply natgthsn0.
+ intro is. apply (IHn m is).
- intros. induction (negnatgth0n _ is).
- intro m. induction m as [ | m ].
+ intro. apply natgthsn0.
+ intro is. apply (IHn m is).
Definition minusgth0inv (n m : nat) (is : n - m > 0) : n > m.
Show proof.
revert m is. induction n as [ | n IHn ].
- intros. induction (negnatgth0n _ is).
- intro. destruct m as [ | m ].
+ intros. apply natgthsn0.
+ intro. apply (IHn m is).
- intros. induction (negnatgth0n _ is).
- intro. destruct m as [ | m ].
+ intros. apply natgthsn0.
+ intro. apply (IHn m is).
Definition natminuseqn (n : nat) : n - 0 = n.
Show proof.
Definition natminuslehn (n m : nat) : n - m <= n.
Show proof.
revert m. induction n as [ | n IHn ].
- intro. apply isreflnatleh.
- intro. destruct m as [ | m ].
+ apply isreflnatleh.
+ simpl. apply (istransnatleh (IHn m) (natlehnsn n)).
- intro. apply isreflnatleh.
- intro. destruct m as [ | m ].
+ apply isreflnatleh.
+ simpl. apply (istransnatleh (IHn m) (natlehnsn n)).
Definition natminusgehn (n m : nat) : n ≥ n - m := natminuslehn _ _.
Definition natminuslthn (n m : nat) (is : n > 0) (is' : m > 0) : n - m < n.
Show proof.
revert m is is'. induction n as [ | n IHn ].
- intros. induction (negnatgth0n _ is).
- intro m. induction m.
+ intros. induction (negnatgth0n _ is').
+ intros. apply (natlehlthtrans _ n _).
* apply (natminuslehn n m).
* apply natlthnsn.
- intros. induction (negnatgth0n _ is).
- intro m. induction m.
+ intros. induction (negnatgth0n _ is').
+ intros. apply (natlehlthtrans _ n _).
* apply (natminuslehn n m).
* apply natlthnsn.
Definition natminuslthninv (n m : nat) (is : n - m < n) : m > 0.
Show proof.
revert m is. induction n as [ | n IHn ].
- intros. induction (negnatlthn0 _ is).
- intro m. destruct m as [ | m ].
+ intro. induction (negnatlthnn _ is).
+ intro. apply (natgthsn0 m).
- intros. induction (negnatlthn0 _ is).
- intro m. destruct m as [ | m ].
+ intro. induction (negnatlthnn _ is).
+ intro. apply (natgthsn0 m).
Definition minusplusnmm (n m : nat) (is : n ≥ m) : (n - m) + m = n.
Show proof.
revert m is. induction n as [ | n IHn].
- intro m. intro is. simpl. apply (natleh0tois0 is).
- intro m. destruct m as [ | m ].
+ intro. simpl. rewrite (natplusr0 n). apply idpath.
+ simpl. intro is. rewrite (natplusnsm (n - m) m).
apply (maponpaths S (IHn m is)).
- intro m. intro is. simpl. apply (natleh0tois0 is).
- intro m. destruct m as [ | m ].
+ intro. simpl. rewrite (natplusr0 n). apply idpath.
+ simpl. intro is. rewrite (natplusnsm (n - m) m).
apply (maponpaths S (IHn m is)).
Definition minusplusnmmineq (n m : nat) : (n - m) + m ≥ n.
Show proof.
intros. induction (natlthorgeh n m) as [ lt | ge ].
- rewrite (minuseq0 _ _ (natlthtoleh _ _ lt)).
apply (natgthtogeh _ _ lt).
- rewrite (minusplusnmm _ _ ge).
apply isreflnatgeh.
- rewrite (minuseq0 _ _ (natlthtoleh _ _ lt)).
apply (natgthtogeh _ _ lt).
- rewrite (minusplusnmm _ _ ge).
apply isreflnatgeh.
Definition plusminusnmm (n m : nat) : (n + m) - m = n.
Show proof.
intros.
set (int1 := natgehplusnmm n m).
apply (natplusrcan _ _ m).
rewrite (minusplusnmm _ _ int1).
apply idpath.
set (int1 := natgehplusnmm n m).
apply (natplusrcan _ _ m).
rewrite (minusplusnmm _ _ int1).
apply idpath.
Definition minusminusmmn (n m : nat) (H : m ≥ n) : m - (m - n) = n.
Show proof.
apply (natplusrcan (m - (m - n)) n (m - n)).
- rewrite minusplusnmm.
+ rewrite natpluscomm. rewrite minusplusnmm.
* apply idpath.
* apply H.
+ apply natminusgehn.
- rewrite minusplusnmm.
+ rewrite natpluscomm. rewrite minusplusnmm.
* apply idpath.
* apply H.
+ apply natminusgehn.
Definition natgthtogthm1 (n m : nat) : n > m -> n > m - 1.
Show proof.
intros is. induction m as [ | m].
- apply is.
- cbn. rewrite natminuseqn. apply (natgehgthtrans n (S m) m).
+ apply (natgthtogeh _ _ is).
+ apply natgthsnn.
- apply is.
- cbn. rewrite natminuseqn. apply (natgehgthtrans n (S m) m).
+ apply (natgthtogeh _ _ is).
+ apply natgthsnn.
Definition natlthtolthm1 (n m : nat) : n < m -> n - 1 < m := natgthtogthm1 _ _.
Definition natlehtolehm1 (n m : nat) : n ≤ m -> n - 1 ≤ m := (fun X : n ≤ m => natlthtolthm1 n (S m) X).
Definition natgehtogehm1 (n m : nat) : n ≥ m -> n ≥ m - 1 := natlehtolehm1 _ _.
Definition natgthtogehm1 (n m : nat) : n > m -> n - 1 ≥ m.
Show proof.
revert m. induction n as [ | n].
- intros m X. apply fromempty. apply (negnatgth0n m X).
- intros m X. induction m as [ | m].
+ apply idpath.
+ cbn. rewrite natminuseqn. apply X.
- intros m X. apply fromempty. apply (negnatgth0n m X).
- intros m X. induction m as [ | m].
+ apply idpath.
+ cbn. rewrite natminuseqn. apply X.
Definition natgehandminusr (n m k : nat) (is : n ≥ m) : n - k ≥ m - k.
Show proof.
revert m k is. induction n as [ | n IHn ].
- intros. rewrite (nat0gehtois0 _ is). apply isreflnatleh.
- intro m. induction m.
+ intros. destruct k.
* apply natgehn0.
* apply natgehn0.
+ intro k. induction k.
* intro is. apply is.
* intro is. apply (IHn m k is).
- intros. rewrite (nat0gehtois0 _ is). apply isreflnatleh.
- intro m. induction m.
+ intros. destruct k.
* apply natgehn0.
* apply natgehn0.
+ intro k. induction k.
* intro is. apply is.
* intro is. apply (IHn m k is).
Definition natgehandminusl (n m k : nat) (is : n ≥ m) : n - k ≥ m - k.
Show proof.
revert m k is. induction n as [ | n IHn ].
- intros. rewrite (nat0gehtois0 _ is). apply isreflnatleh.
- intro m. induction m.
+ intros. destruct k.
* apply natgehn0.
* apply natgehn0.
+ intro k. induction k.
* intro is. apply is.
* intro is. apply (IHn m k is).
- intros. rewrite (nat0gehtois0 _ is). apply isreflnatleh.
- intro m. induction m.
+ intros. destruct k.
* apply natgehn0.
* apply natgehn0.
+ intro k. induction k.
* intro is. apply is.
* intro is. apply (IHn m k is).
Definition natgehandminusrinv (n m k : nat) (is' : n ≥ k) (is : n - k ≥ m - k) : n ≥ m.
Show proof.
revert m k is' is. induction n as [ | n IHn ].
- intros. rewrite (nat0gehtois0 _ is') in is.
rewrite (natminuseqn m) in is. rewrite (nat0gehtois0 _ is).
apply isreflnatleh.
- intro m. induction m.
+ intros. apply natgehn0.
+ intros. destruct k.
* rewrite natminuseqn in is. rewrite natminuseqn in is. apply is.
* apply (IHn m k is' is).
- intros. rewrite (nat0gehtois0 _ is') in is.
rewrite (natminuseqn m) in is. rewrite (nat0gehtois0 _ is).
apply isreflnatleh.
- intro m. induction m.
+ intros. apply natgehn0.
+ intros. destruct k.
* rewrite natminuseqn in is. rewrite natminuseqn in is. apply is.
* apply (IHn m k is' is).
Definition natlthandminusl (n m i : nat) (is : n < m) (is' : i < m) : n - i < m - i.
Show proof.
revert is is'. induction i as [ | i].
- intros is is'. rewrite natminuseqn. rewrite natminuseqn. apply is.
- intros is is'.
induction (natlthorgeh n (S i)) as [H | H].
+ assert (e : n - S i = 0).
{
apply minuseq0.
exact (natlthtoleh _ _ H).
}
rewrite e. apply (natlthandplusrinv _ _ (S i)). rewrite natplusl0.
rewrite minusplusnmm. apply is'.
apply natlthtoleh. apply is'.
+ apply (natlthandplusrinv _ _ (S i)).
rewrite (minusplusnmm m (S i)).
* rewrite (minusplusnmm n (S i)).
{ apply is. }
{ apply H. }
* apply natlthtoleh. apply is'.
- intros is is'. rewrite natminuseqn. rewrite natminuseqn. apply is.
- intros is is'.
induction (natlthorgeh n (S i)) as [H | H].
+ assert (e : n - S i = 0).
{
apply minuseq0.
exact (natlthtoleh _ _ H).
}
rewrite e. apply (natlthandplusrinv _ _ (S i)). rewrite natplusl0.
rewrite minusplusnmm. apply is'.
apply natlthtoleh. apply is'.
+ apply (natlthandplusrinv _ _ (S i)).
rewrite (minusplusnmm m (S i)).
* rewrite (minusplusnmm n (S i)).
{ apply is. }
{ apply H. }
* apply natlthtoleh. apply is'.
Lemma natmult0n (n : nat) : (0 * n) = 0.
Show proof.
#[global]
Hint Resolve natmult0n : natarith.
Lemma natmultn0 (n : nat) : n * 0 = 0.
Show proof.
#[global]
Hint Resolve natmultn0 : natarith.
Lemma multsnm (n m : nat) : S n * m = m + n * m.
Show proof.
#[global]
Hint Resolve multsnm : natarith.
Lemma multnsm (n m : nat) : n * S m = n + n * m.
Show proof.
revert m.
induction n as [|n IHn].
- intros.
apply idpath.
- intro m. simpl.
rewrite <- natplusassoc.
rewrite (natpluscomm _ m).
change (S (m + (n + n * m))) with (S m + (n + n * m)).
rewrite (natpluscomm (S m) _).
apply (maponpaths (λ x, x + S m)).
apply IHn.
#[global]induction n as [|n IHn].
- intros.
apply idpath.
- intro m. simpl.
rewrite <- natplusassoc.
rewrite (natpluscomm _ m).
change (S (m + (n + n * m))) with (S m + (n + n * m)).
rewrite (natpluscomm (S m) _).
apply (maponpaths (λ x, x + S m)).
apply IHn.
Hint Resolve multnsm : natarith.
Lemma natmultcomm (n m : nat) : (n * m) = (m * n).
Show proof.
revert m. induction n as [ | n IHn ].
- intro. auto with natarith.
- intro m. rewrite (multsnm n m). rewrite (multnsm m n).
apply (maponpaths (λ x : _, m + x) (IHn m)).
- intro. auto with natarith.
- intro m. rewrite (multsnm n m). rewrite (multnsm m n).
apply (maponpaths (λ x : _, m + x) (IHn m)).
Lemma natrdistr (n m k : nat) : (n + m) * k = n * k + m * k.
Show proof.
intros.
induction n as [ | n IHn ].
- apply idpath.
- simpl.
rewrite natplusassoc. rewrite (natpluscomm k _).
rewrite <- natplusassoc.
exact (maponpaths (λ x, x+k) IHn).
induction n as [ | n IHn ].
- apply idpath.
- simpl.
rewrite natplusassoc. rewrite (natpluscomm k _).
rewrite <- natplusassoc.
exact (maponpaths (λ x, x+k) IHn).
Lemma natldistr (m k n : nat) : (n * (m + k)) = (n * m + n * k).
Show proof.
induction m as [ | m IHm ].
- simpl. rewrite (natmultn0 n). auto with natarith.
- simpl. rewrite (multnsm n (m + k)). rewrite (multnsm n m).
rewrite (natplusassoc _ _ _).
apply (maponpaths (λ x : _, n + x) (IHm)).
- simpl. rewrite (natmultn0 n). auto with natarith.
- simpl. rewrite (multnsm n (m + k)). rewrite (multnsm n m).
rewrite (natplusassoc _ _ _).
apply (maponpaths (λ x : _, n + x) (IHm)).
Lemma natmultassoc (n m k : nat) : ((n * m) * k) = (n * (m * k)).
Show proof.
induction n as [ | n IHn ].
- apply idpath.
- simpl.
rewrite natrdistr.
apply (maponpaths (λ x, x + m * k)).
apply IHn.
- apply idpath.
- simpl.
rewrite natrdistr.
apply (maponpaths (λ x, x + m * k)).
apply IHn.
Lemma natmultl1 (n : nat) : (1 * n) = n.
Show proof.
simpl. auto with natarith.
#[global]Hint Resolve natmultl1 : natarith.
Lemma natmultr1 (n : nat) : (n * 1) = n.
Show proof.
#[global]
Hint Resolve natmultr1 : natarith.
Definition natplusnonzero (n m : nat) : m ≠ 0 -> n+m ≠ 0.
Show proof.
Definition natneq0andmult (n m : nat) : n ≠ 0 -> m ≠ 0 -> n * m ≠ 0.
Show proof.
intros isn ism. induction n as [|n].
- apply fromempty. apply isn.
- clear isn. simpl. apply natplusnonzero. assumption.
- apply fromempty. apply isn.
- clear isn. simpl. apply natplusnonzero. assumption.
Definition natneq0andmultlinv (n m : nat) : n * m ≠ 0 -> n ≠ 0.
Show proof.
Definition natneq0andmultrinv (n m : nat) : n * m ≠ 0 -> m ≠ 0.
Show proof.
induction m as [|m _].
- intro r. apply fromempty. apply (nat_neq_to_nopath r), natmultn0.
- intros _. apply natneqsx0.
- intro r. apply fromempty. apply (nat_neq_to_nopath r), natmultn0.
- intros _. apply natneqsx0.
Definition natgthandmultl (n m k : nat) : k ≠ 0 -> n > m -> (k * n) > (k * m).
Show proof.
revert m k. induction n as [ | n IHn ].
- intros m k g g'. induction (negnatgth0n _ g').
- intro m. destruct m as [ | m ].
+ intros k g g'.
rewrite (natmultn0 k). rewrite (multnsm k n).
apply (natgehgthtrans _ _ _ (natgehplusnmn k (k* n)) (natneq0togth0 _ g)).
+ intros k g g'. rewrite (multnsm k n). rewrite (multnsm k m).
apply (natgthandplusl _ _ _). apply (IHn m k g g').
- intros m k g g'. induction (negnatgth0n _ g').
- intro m. destruct m as [ | m ].
+ intros k g g'.
rewrite (natmultn0 k). rewrite (multnsm k n).
apply (natgehgthtrans _ _ _ (natgehplusnmn k (k* n)) (natneq0togth0 _ g)).
+ intros k g g'. rewrite (multnsm k n). rewrite (multnsm k m).
apply (natgthandplusl _ _ _). apply (IHn m k g g').
Definition natgthandmultr (n m k : nat) : k ≠ 0 -> n > m -> (n * k) > (m * k).
Show proof.
Definition natgthandmultlinv (n m k : nat) : (k * n) > (k * m) -> n > m.
Show proof.
revert m k. induction n as [ | n IHn ].
- intros m k g. rewrite (natmultn0 k) in g. induction (negnatgth0n _ g).
- intro m. destruct m as [ | m ].
+ intros. apply (natgthsn0 _).
+ intros k g. rewrite (multnsm k n) in g. rewrite (multnsm k m) in g.
apply (IHn m k (natgthandpluslinv _ _ k g)).
- intros m k g. rewrite (natmultn0 k) in g. induction (negnatgth0n _ g).
- intro m. destruct m as [ | m ].
+ intros. apply (natgthsn0 _).
+ intros k g. rewrite (multnsm k n) in g. rewrite (multnsm k m) in g.
apply (IHn m k (natgthandpluslinv _ _ k g)).
Definition natgthandmultrinv (n m k : nat) : (n * k) > (m * k) -> n > m.
Show proof.
intros g.
rewrite (natmultcomm n k) in g. rewrite (natmultcomm m k) in g.
apply (natgthandmultlinv n m k g).
rewrite (natmultcomm n k) in g. rewrite (natmultcomm m k) in g.
apply (natgthandmultlinv n m k g).
Definition natlthandmultl (n m k : nat) : k ≠ 0 -> n < m -> k * n < k * m := natgthandmultl _ _ _.
Definition natlthandmultr (n m k : nat) : k ≠ 0 -> n < m -> n * k < m * k := natgthandmultr _ _ _.
Definition natlthandmultlinv (n m k : nat) : k * n < k * m -> n < m := natgthandmultlinv _ _ _.
Definition natlthandmultrinv (n m k : nat) : n * k < m * k -> n < m := natgthandmultrinv _ _ _.
Definition natlehandmultl (n m k : nat) : n ≤ m -> k * n ≤ k * m.
Show proof.
intros r. apply negnatgthtoleh; intro t.
apply (natlehtonegnatgth _ _ r). apply (natgthandmultlinv _ _ k). assumption.
apply (natlehtonegnatgth _ _ r). apply (natgthandmultlinv _ _ k). assumption.
Definition natlehandmultr (n m k : nat) : n ≤ m -> n * k ≤ m * k.
Show proof.
intros r. apply negnatgthtoleh; intro t.
apply (natlehtonegnatgth _ _ r).
apply (natgthandmultrinv _ _ k). assumption.
apply (natlehtonegnatgth _ _ r).
apply (natgthandmultrinv _ _ k). assumption.
Definition natlehandmultlinv (n m k : nat) : k ≠ 0 -> k * n ≤ k * m -> n ≤ m.
Show proof.
intros r s. apply negnatgthtoleh; intro t.
apply (natlehtonegnatgth _ _ s).
apply (natgthandmultl _ _ _ r). assumption.
apply (natlehtonegnatgth _ _ s).
apply (natgthandmultl _ _ _ r). assumption.
Definition natlehandmultrinv (n m k : nat) : k ≠ 0 -> n * k ≤ m * k -> n ≤ m.
Show proof.
intros r s. apply negnatgthtoleh; intro t.
apply (natlehtonegnatgth _ _ s).
apply (natgthandmultr _ _ _ r). assumption.
apply (natlehtonegnatgth _ _ s).
apply (natgthandmultr _ _ _ r). assumption.
Definition natgehandmultl (n m k : nat) : n ≥ m -> (k * n) ≥ (k * m) := natlehandmultl _ _ _.
Definition natgehandmultr (n m k : nat) : n ≥ m -> (n * k) ≥ (m * k) := natlehandmultr _ _ _.
Definition natgehandmultlinv (n m k : nat) : k ≠ 0 -> k * n ≥ k * m -> n ≥ m := natlehandmultlinv _ _ _.
Definition natgehandmultrinv (n m k : nat) : k ≠ 0 -> n * k ≥ m * k -> n ≥ m := natlehandmultrinv _ _ _.
Division with a remainder on nat
Definition natdivrem (n m : nat) : dirprod nat nat.
Show proof.
intros. induction n as [ | n IHn ].
- intros. apply (make_dirprod 0 0).
- induction (natlthorgeh (S (pr2 IHn)) m).
+ apply (make_dirprod (pr1 IHn) (S (pr2 IHn))).
+ apply (make_dirprod (S (pr1 IHn)) 0).
- intros. apply (make_dirprod 0 0).
- induction (natlthorgeh (S (pr2 IHn)) m).
+ apply (make_dirprod (pr1 IHn) (S (pr2 IHn))).
+ apply (make_dirprod (S (pr1 IHn)) 0).
Definition natdiv (n m : nat) : nat := pr1 (natdivrem n m).
Definition natrem (n m : nat) : nat := pr2 (natdivrem n m).
Notation " x /+ y " := (natrem x y) (at level 40, left associativity) : nat_scope.
Notation " x / y " := (natdiv x y) (at level 40, left associativity) : nat_scope.
Lemma lthnatrem (n m : nat) : m ≠ 0 -> n /+ m < m.
Show proof.
unfold natrem. intros is. destruct n as [ | n ].
- simpl. intros. apply (natneq0togth0 _ is).
- simpl. induction (natlthorgeh (S (pr2 (natdivrem n m))) m) as [ nt | t ].
+ simpl. apply nt.
+ simpl. apply (natneq0togth0 _ is).
- simpl. intros. apply (natneq0togth0 _ is).
- simpl. induction (natlthorgeh (S (pr2 (natdivrem n m))) m) as [ nt | t ].
+ simpl. apply nt.
+ simpl. apply (natneq0togth0 _ is).
Theorem natdivremrule (n m : nat) (is : m ≠ 0) : n = ((natrem n m) + (natdiv n m) * m).
Show proof.
revert m is. induction n as [ | n IHn ].
- simpl. intros. apply idpath.
- intros m is. unfold natrem. unfold natdiv. simpl.
induction (natlthorgeh (S (pr2 (natdivrem n m))) m) as [ nt | t ].
+ simpl. apply (maponpaths S (IHn m is)).
+ simpl. set (is' := lthnatrem n m is).
induction (natgthchoice2 _ _ is') as [ h | e ].
induction (natlehtonegnatgth _ _ t h).
fold (natdiv n m).
set (e'' := maponpaths S (IHn m is)).
change (S (natrem n m + natdiv n m * m))
with (S (natrem n m) + natdiv n m * m) in e''.
rewrite (pathsinv0 e) in e''. rewrite (natpluscomm _ m).
apply e''.
Opaque natdivremrule.- simpl. intros. apply idpath.
- intros m is. unfold natrem. unfold natdiv. simpl.
induction (natlthorgeh (S (pr2 (natdivrem n m))) m) as [ nt | t ].
+ simpl. apply (maponpaths S (IHn m is)).
+ simpl. set (is' := lthnatrem n m is).
induction (natgthchoice2 _ _ is') as [ h | e ].
induction (natlehtonegnatgth _ _ t h).
fold (natdiv n m).
set (e'' := maponpaths S (IHn m is)).
change (S (natrem n m + natdiv n m * m))
with (S (natrem n m) + natdiv n m * m) in e''.
rewrite (pathsinv0 e) in e''. rewrite (natpluscomm _ m).
apply e''.
Lemma natlehmultnatdiv (n m : nat) (is : m ≠ 0) : natdiv n m * m ≤ n.
Show proof.
intros.
set (e := natdivremrule n m is).
set (int := (natdiv n m) * m).
rewrite e. apply natlehmplusnm.
set (e := natdivremrule n m is).
set (int := (natdiv n m) * m).
rewrite e. apply natlehmplusnm.
Theorem natdivremunique (m i j i' j' : nat) (lj : j < m) (lj' : j' < m)
(e : j + i * m = j' + i' * m) : i = i' × j = j'.
Show proof.
revert j i' j' lj lj' e. induction i as [ | i IHi ].
- intros j i' j' lj lj'.
simpl.
intro e.
simpl in e.
rewrite natplusr0 in e.
rewrite e in lj.
induction i'.
+ simpl in e.
rewrite natplusr0 in e.
exact (idpath _,,e).
+ change (S i' * m) with (i' * m + m) in lj.
rewrite <- natplusassoc in lj.
induction (negnatgthmplusnm _ _ lj).
- intros j i' j' lj lj' e.
induction i' as [ | i' ].
+ simpl in e.
rewrite natplusr0 in e.
rewrite <- e in lj'.
rewrite <- natplusassoc in lj'.
induction (negnatgthmplusnm _ _ lj').
+ simpl in e.
rewrite <- (natplusassoc j) in e.
rewrite <- (natplusassoc j') in e.
set (e' := invmaponpathsincl _ (isinclnatplusr m) _ _ e).
set (ee := IHi j i' j' lj lj' e').
exact (make_dirprod (maponpaths S (pr1 ee)) (pr2 ee)).
Opaque natdivremunique.- intros j i' j' lj lj'.
simpl.
intro e.
simpl in e.
rewrite natplusr0 in e.
rewrite e in lj.
induction i'.
+ simpl in e.
rewrite natplusr0 in e.
exact (idpath _,,e).
+ change (S i' * m) with (i' * m + m) in lj.
rewrite <- natplusassoc in lj.
induction (negnatgthmplusnm _ _ lj).
- intros j i' j' lj lj' e.
induction i' as [ | i' ].
+ simpl in e.
rewrite natplusr0 in e.
rewrite <- e in lj'.
rewrite <- natplusassoc in lj'.
induction (negnatgthmplusnm _ _ lj').
+ simpl in e.
rewrite <- (natplusassoc j) in e.
rewrite <- (natplusassoc j') in e.
set (e' := invmaponpathsincl _ (isinclnatplusr m) _ _ e).
set (ee := IHi j i' j' lj lj' e').
exact (make_dirprod (maponpaths S (pr1 ee)) (pr2 ee)).
Lemma natdivremandmultl (n m k : nat) (ism : m ≠ 0) (iskm : (k * m) ≠ 0) :
dirprod (paths (natdiv (k * n) (k * m)) (natdiv n m))
(paths (natrem (k * n) (k * m)) (k * (natrem n m))).
Show proof.
intros.
set (ak := natdiv (k * n) (k * m)).
set (bk := natrem (k * n) (k * m)).
set (a := natdiv n m). set (b := natrem n m).
assert (e1 : paths (bk + ak * (k * m)) ((b * k) + a * (k * m))).
{
unfold ak. unfold bk.
rewrite (pathsinv0 (natdivremrule (k * n) (k * m) iskm)).
rewrite (natmultcomm k m).
rewrite (pathsinv0 (natmultassoc _ _ _)).
rewrite (pathsinv0 (natrdistr _ _ _)).
unfold a. unfold b.
rewrite (pathsinv0 (natdivremrule n m ism)).
apply (natmultcomm k n).
}
set (l1 := lthnatrem n m ism).
set (l1' := (natlthandmultr _ _ _ (natneq0andmultlinv _ _ iskm) l1)).
rewrite (natmultcomm m k) in l1'.
set (int := natdivremunique
_ _ _ _ _ (lthnatrem (k * n) (k * m) iskm) l1' e1).
split with (pr1 int).
rewrite (natmultcomm k b). apply (pr2 int).
Opaque natdivremandmultl.set (ak := natdiv (k * n) (k * m)).
set (bk := natrem (k * n) (k * m)).
set (a := natdiv n m). set (b := natrem n m).
assert (e1 : paths (bk + ak * (k * m)) ((b * k) + a * (k * m))).
{
unfold ak. unfold bk.
rewrite (pathsinv0 (natdivremrule (k * n) (k * m) iskm)).
rewrite (natmultcomm k m).
rewrite (pathsinv0 (natmultassoc _ _ _)).
rewrite (pathsinv0 (natrdistr _ _ _)).
unfold a. unfold b.
rewrite (pathsinv0 (natdivremrule n m ism)).
apply (natmultcomm k n).
}
set (l1 := lthnatrem n m ism).
set (l1' := (natlthandmultr _ _ _ (natneq0andmultlinv _ _ iskm) l1)).
rewrite (natmultcomm m k) in l1'.
set (int := natdivremunique
_ _ _ _ _ (lthnatrem (k * n) (k * m) iskm) l1' e1).
split with (pr1 int).
rewrite (natmultcomm k b). apply (pr2 int).
Definition natdivandmultl (n m k : nat) (ism : m ≠ 0) (iskm : (k * m) ≠ 0) :
paths (natdiv (k * n) (k * m)) (natdiv n m) := pr1 (natdivremandmultl _ _ _ ism iskm).
Definition natremandmultl (n m k : nat) (ism : m ≠ 0) (iskm : (k * m) ≠ 0) :
paths (natrem (k * n) (k * m)) (k * (natrem n m)) := pr2 (natdivremandmultl _ _ _ ism iskm).
Lemma natdivremandmultr (n m k : nat) (ism : m ≠ 0) (ismk : (m * k) ≠ 0) :
dirprod (paths (natdiv (n * k) (m * k)) (natdiv n m))
(paths (natrem (n * k) (m * k)) ((natrem n m) * k)).
Show proof.
intros. rewrite (natmultcomm m k). rewrite (natmultcomm m k) in ismk.
rewrite (natmultcomm n k). rewrite (natmultcomm (natrem _ _) k).
apply (natdivremandmultl _ _ _ ism ismk).
Opaque natdivremandmultr.rewrite (natmultcomm n k). rewrite (natmultcomm (natrem _ _) k).
apply (natdivremandmultl _ _ _ ism ismk).
Definition natdivandmultr (n m k : nat) (ism : m ≠ 0) (ismk : (m * k) ≠ 0) :
paths (natdiv (n * k) (m * k)) (natdiv n m) := pr1 (natdivremandmultr _ _ _ ism ismk).
Definition natremandmultr (n m k : nat) (ism : m ≠ 0) (ismk : (m * k) ≠ 0) :
natrem (n * k) (m * k) = (natrem n m) * k := pr2 (natdivremandmultr _ _ _ ism ismk).
Factorial on nat
Definition di (i : nat) (x : nat) : nat :=
match natlthorgeh x i with
| ii1 _ => x
| ii2 _ => S x
end.
Lemma di_eq1 {i x} : x < i → di i x = x.
Show proof.
intros lt. unfold di.
induction (natlthorgeh x i) as [_|P].
- apply idpath.
- apply fromempty. exact (natgehtonegnatlth _ _ P lt).
induction (natlthorgeh x i) as [_|P].
- apply idpath.
- apply fromempty. exact (natgehtonegnatlth _ _ P lt).
Lemma di_eq2 {i x} : x ≥ i → di i x = S x.
Show proof.
intros lt. unfold di.
induction (natlthorgeh x i) as [P|_].
- apply fromempty. exact (natlthtonegnatgeh _ _ P lt).
- apply idpath.
induction (natlthorgeh x i) as [P|_].
- apply fromempty. exact (natlthtonegnatgeh _ _ P lt).
- apply idpath.
Lemma di_neq_i (i x : nat) : i ≠ di i x.
Show proof.
intros. apply nat_nopath_to_neq. intro eq.
unfold di in eq. induction (natlthorgeh x i) as [lt|ge].
- induction eq. exact (isirreflnatlth i lt).
- induction (!eq); clear eq. exact (negnatgehnsn _ ge).
unfold di in eq. induction (natlthorgeh x i) as [lt|ge].
- induction eq. exact (isirreflnatlth i lt).
- induction (!eq); clear eq. exact (negnatgehnsn _ ge).
Lemma natlehdinsn (i n : nat) : (di i n) ≤ (S n).
Show proof.
intros. unfold di. induction (natlthorgeh n i).
- apply natlthtoleh. apply natlthnsn.
- apply isreflnatleh.
- apply natlthtoleh. apply natlthnsn.
- apply isreflnatleh.
Lemma natgehdinn (i n : nat) : (di i n) ≥ n.
Show proof.
intros. unfold di. induction (natlthorgeh n i).
- apply isreflnatleh.
- apply natlthtoleh. apply natlthnsn.
- apply isreflnatleh.
- apply natlthtoleh. apply natlthnsn.
Lemma isincldi (i : nat) : isincl (di i).
Show proof.
intro. apply (isinclbetweensets (di i) isasetnat isasetnat).
intros x x'. unfold di. intro e.
induction (natlthorgeh x i) as [ l | nel ].
- induction (natlthorgeh x' i) as [ l' | nel' ].
+ apply e.
+ rewrite e in l. assert (e' := natgthtogths _ _ l).
change (S i > S x') with (i > x') in e'.
contradicts (natlehtonegnatgth _ _ nel') e'.
- induction (natlthorgeh x' i) as [ l' | nel' ].
+ induction e.
set (e' := natgthtogths _ _ l').
contradicts (natlehtonegnatgth _ _ nel) e'.
+ apply (invmaponpathsS _ _ e).
intros x x'. unfold di. intro e.
induction (natlthorgeh x i) as [ l | nel ].
- induction (natlthorgeh x' i) as [ l' | nel' ].
+ apply e.
+ rewrite e in l. assert (e' := natgthtogths _ _ l).
change (S i > S x') with (i > x') in e'.
contradicts (natlehtonegnatgth _ _ nel') e'.
- induction (natlthorgeh x' i) as [ l' | nel' ].
+ induction e.
set (e' := natgthtogths _ _ l').
contradicts (natlehtonegnatgth _ _ nel) e'.
+ apply (invmaponpathsS _ _ e).
Lemma neghfiberdi (i : nat) : ¬ (hfiber (di i) i).
Show proof.
intros hf. unfold di in hf. induction hf as [ j e ].
induction (natlthorgeh j i) as [ l | g ]. induction e.
apply (isirreflnatlth _ l). induction e in g. apply (negnatgehnsn _ g).
induction (natlthorgeh j i) as [ l | g ]. induction e.
apply (isirreflnatlth _ l). induction e in g. apply (negnatgehnsn _ g).
Lemma iscontrhfiberdi (i j : nat) (ne : i ≠ j) : iscontr (hfiber (di i) j).
Show proof.
intros. apply iscontraprop1. apply (isincldi i j).
induction (natlthorgeh j i) as [ l | nel ].
- split with j. unfold di.
induction (natlthorgeh j i) as [ l' | nel' ].
+ apply idpath.
+ contradicts (natlehtonegnatgth _ _ nel') l.
- induction (natgehchoice2 _ _ nel) as [ g | e ].
destruct j as [ | j ].
+ induction (negnatgeh0sn _ g).
+ split with j. unfold di. induction (natlthorgeh j i) as [ l' | g' ].
* contradicts (natlehtonegnatgth _ _ g) l'.
* apply idpath.
+ induction ((nat_neq_to_nopath ne) (pathsinv0 e)).
induction (natlthorgeh j i) as [ l | nel ].
- split with j. unfold di.
induction (natlthorgeh j i) as [ l' | nel' ].
+ apply idpath.
+ contradicts (natlehtonegnatgth _ _ nel') l.
- induction (natgehchoice2 _ _ nel) as [ g | e ].
destruct j as [ | j ].
+ induction (negnatgeh0sn _ g).
+ split with j. unfold di. induction (natlthorgeh j i) as [ l' | g' ].
* contradicts (natlehtonegnatgth _ _ g) l'.
* apply idpath.
+ induction ((nat_neq_to_nopath ne) (pathsinv0 e)).
Lemma isdecincldi (i : nat) : isdecincl (di i).
Show proof.
intros j. apply isdecpropif.
- apply (isincldi i j).
- induction (nat_eq_or_neq i j) as [ eq | neq ].
+ apply ii2. induction eq. apply (neghfiberdi i).
+ apply ii1. apply (pr1 (iscontrhfiberdi i j neq)).
- apply (isincldi i j).
- induction (nat_eq_or_neq i j) as [ eq | neq ].
+ apply ii2. induction eq. apply (neghfiberdi i).
+ apply ii1. apply (pr1 (iscontrhfiberdi i j neq)).
Definition si (i : nat) (x : nat) : nat :=
match natlthorgeh i x with
| ii1 _ => x - 1
| ii2 _ => x
end.
Lemma natleh_neq {i j : nat} : i ≤ j -> i ≠ j -> i < j.
Show proof.
intros le ne.
induction (natlehchoice _ _ le) as [lt|eq].
- exact lt.
- induction eq. apply fromempty. exact (isirrefl_natneq _ ne).
induction (natlehchoice _ _ le) as [lt|eq].
- exact lt.
- induction eq. apply fromempty. exact (isirrefl_natneq _ ne).
Lemma natminusminus (n i j : nat) : n - i - j = n - (i + j).
Show proof.
revert i j; induction n as [|n N].
- intros. apply idpath.
- intros i; induction i as [|i _].
+ intros. apply idpath.
+ apply N.
- intros. apply idpath.
- intros i; induction i as [|i _].
+ intros. apply idpath.
+ apply N.
Lemma natltplusS (n i : nat) : i < i + S n.
Show proof.
Lemma nat_split {n m i : nat} : (i < n + m) -> (i ≥ n) -> i - n < m.
Show proof.
intros p H.
induction (plusminusnmm m n).
apply natlthandminusl.
- induction (natpluscomm n m). exact p.
- induction (natpluscomm n m). apply (natlehlthtrans _ i).
* assumption.
* assumption.
induction (plusminusnmm m n).
apply natlthandminusl.
- induction (natpluscomm n m). exact p.
- induction (natpluscomm n m). apply (natlehlthtrans _ i).
* assumption.
* assumption.
Lemma natplusminusle {a b c} : b ≥ c -> a+(b-c) = (a+b)-c.
Show proof.
intros e. assert (E := minusplusnmm b c e). rewrite <- E. clear E e.
rewrite <- natplusassoc. rewrite plusminusnmm. rewrite plusminusnmm. apply idpath.
rewrite <- natplusassoc. rewrite plusminusnmm. rewrite plusminusnmm. apply idpath.
Lemma natdiffplusdiff {a b c} : a ≥ b -> b ≥ c -> a-c = (a-b) + (b-c).
Show proof.
intros r s. apply (natplusrcan _ _ c). rewrite natplusassoc.
rewrite (minusplusnmm _ _ s). rewrite (minusplusnmm _ _ (istransnatleh s r)).
exact (! minusplusnmm _ _ r).
rewrite (minusplusnmm _ _ s). rewrite (minusplusnmm _ _ (istransnatleh s r)).
exact (! minusplusnmm _ _ r).