Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * INRIA, CNRS and contributors - Copyright 1999-2018 *) (* <O___,, * (see CREDITS file for the list of authors) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************) (* Evgeny Makarov, INRIA, 2007 *) (************************************************************************) Require Export NMulOrder. Module Type NSubProp (Import N : NAxiomsMiniSig'). Include NMulOrderProp N.forall n : t, 0 - n == 0forall n : t, 0 - n == 00 - 0 == 0forall n : t, 0 - n == 0 -> 0 - S n == 0forall n : t, 0 - n == 0 -> 0 - S n == 0now apply pred_0. Qed.n:tIH:0 - n == 0P 0 == 0forall n m : t, S n - S m == n - mforall n m : t, S n - S m == n - mn:tS n - S 0 == n - 0n:tforall n0 : t, S n - S n0 == n - n0 -> S n - S (S n0) == n - S n0n:tP (S n - 0) == n - 0n:tforall n0 : t, S n - S n0 == n - n0 -> S n - S (S n0) == n - S n0n:tP (S n) == nn:tforall n0 : t, S n - S n0 == n - n0 -> S n - S (S n0) == n - S n0n:tforall n0 : t, S n - S n0 == n - n0 -> S n - S (S n0) == n - S n0n, m:tIH:S n - S m == n - mS n - S (S m) == n - S mn, m:tIH:S n - S m == n - mP (S n - S m) == n - S mnow rewrite sub_succ_r. Qed.n, m:tIH:S n - S m == n - mP (n - m) == n - S mforall n : t, n - n == 0forall n : t, n - n == 00 - 0 == 0forall n : t, n - n == 0 -> S n - S n == 0intros n IH; rewrite sub_succ; now rewrite IH. Qed.forall n : t, n - n == 0 -> S n - S n == 0forall n m : t, m < n -> n - m ~= 0forall n m : t, m < n -> n - m ~= 0Proper (eq ==> eq ==> iff) (fun m n : t => n - m ~= 0)forall m : t, S m - 0 ~= 0forall n m : t, n < m -> m - n ~= 0 -> S m - S n ~= 0forall m : t, S m - 0 ~= 0forall n m : t, n < m -> m - n ~= 0 -> S m - S n ~= 0intros; now rewrite sub_succ. Qed.forall n m : t, n < m -> m - n ~= 0 -> S m - S n ~= 0forall n m p : t, p <= m -> n + (m - p) == n + m - pforall n m p : t, p <= m -> n + (m - p) == n + m - pn, m:t0 <= m -> n + (m - 0) == n + m - 0n, m:tforall n0 : t, (n0 <= m -> n + (m - n0) == n + m - n0) -> S n0 <= m -> n + (m - S n0) == n + m - S n0n, m:tforall n0 : t, (n0 <= m -> n + (m - n0) == n + m - n0) -> S n0 <= m -> n + (m - S n0) == n + m - S n0n, m, p:tIH:p <= m -> n + (m - p) == n + m - pH:S p <= mn + (m - S p) == n + m - S pn, m, p:tIH:p <= m -> n + (m - p) == n + m - pH:S p <= mn + P (m - p) == P (n + m - p)n, m, p:tIH:p <= m -> n + (m - p) == n + m - pH:S p <= mn + P (m - p) == P (n + (m - p))reflexivity. Qed.n, m, p:tIH:p <= m -> n + (m - p) == n + m - pH:S p <= mP (n + (m - p)) == P (n + (m - p))forall n m : t, n <= m -> S m - n == S (m - n)forall n m : t, n <= m -> S m - n == S (m - n)n, m:tH:n <= mS m - n == S (m - n)n, m:tH:n <= m1 + m - n == S (m - n)symmetry; now apply add_sub_assoc. Qed.n, m:tH:n <= m1 + m - n == 1 + (m - n)forall n m : t, n + m - m == nforall n m : t, n + m - m == nn, m:tn + m - m == nrewrite sub_diag; now rewrite add_0_r. Qed.n, m:tn + (m - m) == nforall n m : t, n <= m -> m - n + n == mforall n m : t, n <= m -> m - n + n == mn, m:tH:n <= mm - n + n == mn, m:tH:n <= mn + (m - n) == mn, m:tH:n <= mn + m - n == mapply add_sub. Qed.n, m:tH:n <= mm + n - n == mforall n m p : t, m + p == n -> n - m == pforall n m p : t, m + p == n -> n - m == pn, m, p:tH:m + p == nn - m == pn, m, p:tH:m + p == np == n - mn, m, p:tH:m + p == nH1:m + p - m == n - mp == n - mnow rewrite add_sub in H1. Qed.n, m, p:tH:m + p == nH1:p + m - m == n - mp == n - mforall n m p : t, m + p == n -> n - p == mintros n m p H; rewrite add_comm in H; now apply add_sub_eq_l. Qed. (* This could be proved by adding m to both sides. Then the proof would use add_sub_assoc and sub_0_le, which is proven below. *)forall n m p : t, m + p == n -> n - p == mforall n m p : t, p ~= 0 -> n - m == p -> m + p == nforall n m p : t, p ~= 0 -> n - m == p -> m + p == np:tH:p ~= 0forall m : t, 0 - m == p -> m + p == 0p:tH:p ~= 0forall n : t, S n - 0 == p -> 0 + p == S np:tH:p ~= 0forall n m : t, (n - m == p -> m + p == n) -> S n - S m == p -> S m + p == S np:tH:p ~= 0m:tH1:0 == pm + p == 0p:tH:p ~= 0forall n : t, S n - 0 == p -> 0 + p == S np:tH:p ~= 0forall n m : t, (n - m == p -> m + p == n) -> S n - S m == p -> S m + p == S np:tH:p ~= 0forall n : t, S n - 0 == p -> 0 + p == S np:tH:p ~= 0forall n m : t, (n - m == p -> m + p == n) -> S n - S m == p -> S m + p == S np:tH:p ~= 0forall n m : t, (n - m == p -> m + p == n) -> S n - S m == p -> S m + p == S np:tH:p ~= 0n, m:tIH:n - m == p -> m + p == nH1:S n - S m == pS m + p == S np:tH:p ~= 0n, m:tIH:n - m == p -> m + p == nH1:n - m == pS m + p == S nrewrite add_succ_l; now rewrite H1. Qed.p:tH:p ~= 0n, m:tIH:n - m == p -> m + p == nH1:m + p == nS m + p == S nforall n m p : t, n - (m + p) == n - m - pforall n m p : t, n - (m + p) == n - m - pn, m:tn - (m + 0) == n - m - 0n, m:tforall n0 : t, n - (m + n0) == n - m - n0 -> n - (m + S n0) == n - m - S n0n, m:tforall n0 : t, n - (m + n0) == n - m - n0 -> n - (m + S n0) == n - m - S n0n, m, p:tIH:n - (m + p) == n - m - pn - (m + S p) == n - m - S pnow rewrite IH. Qed.n, m, p:tIH:n - (m + p) == n - m - pP (n - (m + p)) == P (n - m - p)forall n m p : t, p <= n -> n + m - p == n - p + mforall n m p : t, p <= n -> n + m - p == n - p + mn, m, p:tH:p <= nn + m - p == n - p + mn, m, p:tH:p <= nm + n - p == n - p + mnow rewrite (add_comm m (n - p)). Qed.n, m, p:tH:p <= nm + (n - p) == n - p + m
Sub and order
forall n m : t, n - m <= nforall n m : t, n - m <= nn:tn - 0 <= nn:tforall n0 : t, n - n0 <= n -> n - S n0 <= nn:tforall n0 : t, n - n0 <= n -> n - S n0 <= nn, m:tIH:n - m <= nn - S m <= napply le_trans with (n - m); [apply le_pred_l | assumption]. Qed.n, m:tIH:n - m <= nP (n - m) <= nforall n m : t, n - m == 0 <-> n <= mforall n m : t, n - m == 0 <-> n <= mforall m : t, 0 - m == 0 <-> 0 <= mforall n : t, S n - 0 == 0 <-> S n <= 0forall n m : t, n - m == 0 <-> n <= m -> S n - S m == 0 <-> S n <= S mforall n : t, S n - 0 == 0 <-> S n <= 0forall n m : t, n - m == 0 <-> n <= m -> S n - S m == 0 <-> S n <= S mforall n m : t, n - m == 0 <-> n <= m -> S n - S m == 0 <-> S n <= S mn, m:tH:n - m == 0 <-> n <= mS n - S m == 0 <-> S n <= S mnow rewrite sub_succ. Qed.n, m:tH:n - m == 0 <-> n <= mS n - S m == 0 <-> n <= mforall n m : t, n <= n - m + mforall n m : t, n <= n - m + mn, m:tn <= n - m + mn, m:tLE:n <= mn <= n - m + mn, m:tGE:m <= nn <= n - m + mn, m:tLE:n - m == 0n <= n - m + mn, m:tGE:m <= nn <= n - m + mn, m:tLE:n - m == 0n <= mn, m:tGE:m <= nn <= n - m + mn, m:tGE:m <= nn <= n - m + mapply le_refl. Qed.n, m:tGE:m <= nn <= nforall n m p : t, n - p <= m <-> n <= m + pforall n m p : t, n - p <= m <-> n <= m + pn, m, p:tn - p <= m <-> n <= m + pn, m, p:tLE:n - p <= mn <= m + pn, m, p:tLE:n <= m + pn - p <= mn, m, p:tLE:n - p + p <= m + pn <= m + pn, m, p:tLE:n <= m + pn - p <= mn, m, p:tLE:n <= m + pn - p <= mn, m, p:tLE:n <= m + pLE':n <= pn - p <= mn, m, p:tLE:n <= m + pGE:p <= nn - p <= mn, m, p:tLE:n <= m + pLE':n - p == 0n - p <= mn, m, p:tLE:n <= m + pGE:p <= nn - p <= mn, m, p:tLE:n <= m + pLE':n - p == 00 <= mn, m, p:tLE:n <= m + pGE:p <= nn - p <= mn, m, p:tLE:n <= m + pGE:p <= nn - p <= mnow rewrite sub_add. Qed.n, m, p:tLE:n <= m + pGE:p <= nn - p + p <= m + pforall n m p : t, n - m <= p <-> n <= m + pforall n m p : t, n - m <= p <-> n <= m + prewrite add_comm; apply le_sub_le_add_r. Qed.n, m, p:tn - m <= p <-> n <= m + pforall n m p : t, n - p < m -> n < m + pforall n m p : t, n - p < m -> n < m + pn, m, p:tLT:n - p < mn < m + papply le_lt_trans with (n-p+p); auto using sub_add_le. Qed.n, m, p:tLT:n - p + p < m + pn < m + p
Unfortunately, we do not have n < m + p → n - p < m.
For instance 1<0+2 but not 1-2<0.
forall n m p : t, n - m < p -> n < m + pforall n m p : t, n - m < p -> n < m + prewrite add_comm; apply lt_sub_lt_add_r. Qed.n, m, p:tn - m < p -> n < m + pforall n m p : t, n + p <= m -> n <= m - pforall n m p : t, n + p <= m -> n <= m - pn, m, p:tLE:n + p <= mn <= m - pn, m, p:tLE:n + p <= mn + p <= m - p + pn, m, p:tLE:n + p <= mn + p <= mn, m, p:tLE:n + p <= mp <= mn, m, p:tLE:n + p <= mp <= mn, m, p:tLE:n + p <= mp <= n + pn, m, p:tLE:n + p <= m0 + p <= n + papply le_0_l. Qed.n, m, p:tLE:n + p <= m0 <= n
Unfortunately, we do not have n ≤ m - p → n + p ≤ m.
For instance 0<=1-2 but not 2+0<=1.
forall n m p : t, n + p <= m -> p <= m - nforall n m p : t, n + p <= m -> p <= m - nrewrite add_comm; apply le_add_le_sub_r. Qed.n, m, p:tn + p <= m -> p <= m - nforall n m p : t, n + p < m <-> n < m - pforall n m p : t, n + p < m <-> n < m - pn, m, p:tn + p < m <-> n < m - pn, m, p:tLE:p <= mn + p < m <-> n < m - pn, m, p:tGE:m <= pn + p < m <-> n < m - pn, m, p:tLE:p <= mn + p < m - p + p <-> n < m - pn, m, p:tGE:m <= pn + p < m <-> n < m - pn, m, p:tGE:m <= pn + p < m <-> n < m - pn, m, p:tGE, GE':m <= pn + p < m <-> n < m - pn, m, p:tGE:m <= pGE':m - p == 0n + p < m <-> n < 0n, m, p:tGE:m <= pGE':m - p == 0LT:n + p < mn < 0n, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mn, m, p:tGE:m <= pGE':m - p == 0LT:n + p < mm < mn, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mn, m, p:tGE:m <= pGE':m - p == 0LT:n + p < mm <= n + pn, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mn, m, p:tGE:m <= pGE':m - p == 0LT:n + p < m0 + m <= n + pn, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mn, m, p:tGE:m <= pGE':m - p == 0LT:n + p < m0 <= nn, m, p:tGE:m <= pGE':m - p == 0LT:n + p < mm <= pn, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mn, m, p:tGE:m <= pGE':m - p == 0LT:n + p < mm <= pn, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mnow elim (nlt_0_r n). Qed.n, m, p:tGE:m <= pGE':m - p == 0LT:n < 0n + p < mforall n m p : t, n + p < m <-> p < m - nforall n m p : t, n + p < m <-> p < m - nrewrite add_comm; apply lt_add_lt_sub_r. Qed.n, m, p:tn + p < m <-> p < m - nforall n m : t, m <= n -> 0 < m -> n - m < nforall n m : t, m <= n -> 0 < m -> n - m < nn, m:tLE:m <= nLT:0 < mn - m < nn, m:tLE:m <= nLT:0 < mLE':n - m <= nn - m < nn, m:tLE:m <= nLT:0 < mLE':n - m < n \/ n - m == nn - m < nn, m:tLE:m <= nLT:0 < mLT':n - m < nn - m < nn, m:tLE:m <= nLT:0 < mEQ:n - m == nn - m < nn, m:tLE:m <= nLT:0 < mEQ:n - m == nn - m < nn, m:tLE:m <= nLT:0 < mEQ:m + n == nn - m < norder. Qed.n, m:tLE:m <= nLT:n < m + nEQ:m + n == nn - m < nforall n m p : t, n <= m -> n - p <= m - pforall n m p : t, n <= m -> n - p <= m - pn, m, p:tH:n <= mn - p <= m - pn, m, p:tH:n <= mn <= m - p + pn, m, p:tH:n <= mn <= mn, m, p:tH:n <= mm <= m - p + papply sub_add_le. Qed.n, m, p:tH:n <= mm <= m - p + pforall n m p : t, n <= m -> p - m <= p - nforall n m p : t, n <= m -> p - m <= p - nn, m, p:tH:n <= mp - m <= p - ntransitivity (p-n+n); [ apply sub_add_le | now apply add_le_mono_l]. Qed.n, m, p:tH:n <= mp <= p - n + m
Sub and mul
forall n m : t, n * P m == n * m - nforall n m : t, n * P m == n * m - nn:tn * P 0 == n * 0 - nn:tforall n0 : t, n * P (S n0) == n * S n0 - nn:tforall n0 : t, n * P (S n0) == n * S n0 - nn, m:tn * m == n * m + (n - n)n, m:tn <= nnow apply eq_le_incl. Qed.n, m:tn <= nforall n m p : t, (n - m) * p == n * p - m * pforall n m p : t, (n - m) * p == n * p - m * pm, p:t(0 - m) * p == 0 * p - m * pm, p:tforall n : t, (n - m) * p == n * p - m * p -> (S n - m) * p == S n * p - m * pm, p:tforall n : t, (n - m) * p == n * p - m * p -> (S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * p(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:m <= n(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:m <= nS (n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:m <= n(n - m) * p + p == n * p + p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:m <= np + (n - m) * p == p + n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:m <= np + (n - m) * p == p + (n * p - m * p)m, p, n:tIH:(n - m) * p == n * p - m * pH:n < m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < mH1:S n <= m(S n - m) * p == S n * p - m * pm, p, n:tIH:(n - m) * p == n * p - m * pH:n < mH1:S n <= m0 * p == S n * p - m * papply mul_0_l. Qed.m, p, n:tIH:(n - m) * p == n * p - m * pH:n < mH1:S n <= m0 * p == 0forall n m p : t, p * (n - m) == p * n - p * mforall n m p : t, p * (n - m) == p * n - p * mapply mul_sub_distr_r. Qed.n, m, p:t(n - m) * p == n * p - m * p
Alternative definitions of ≤ and < based on +
Definition le_alt n m := exists p, p + n == m. Definition lt_alt n m := exists p, S p + n == m.forall n m : t, le_alt n m <-> n <= mforall n m : t, le_alt n m <-> n <= mn, m:tle_alt n m -> n <= mn, m:tn <= m -> le_alt n mn, m, p:tH:p + n == mn <= mn, m:tn <= m -> le_alt n mn, m, p:tH:p + n == mn <= n + pn, m:tn <= m -> le_alt n mn, m:tn <= m -> le_alt n mn, m:tH:n <= mle_alt n mnow apply sub_add. Qed.n, m:tH:n <= mm - n + n == mforall n m : t, lt_alt n m <-> n < mforall n m : t, lt_alt n m <-> n < mn, m:tlt_alt n m -> n < mn, m:tn < m -> lt_alt n mn, m, p:tH:S p + n == mn < mn, m:tn < m -> lt_alt n mn, m, p:tH:S p + n == mn <= n + pn, m:tn < m -> lt_alt n mn, m:tn < m -> lt_alt n mn, m:tH:n < mlt_alt n mn, m:tH:n < mS (m - S n) + n == mn, m:tH:n < mm - S n + S n == mnow rewrite le_succ_l. Qed.n, m:tH:n < mS n <= mProper (eq ==> eq ==> iff) le_altProper (eq ==> eq ==> iff) le_altx, x':tHx:x == x'y, y':tHy:y == y'(exists p : t, p + x == y) <-> (exists p : t, p + x' == y')x, x':tHx:x == x'y, y':tHy:y == y'(exists p : t, p + x' == y) <-> (exists p : t, p + x' == y')auto with *. Qed.x, x':tHx:x == x'y, y':tHy:y == y'(exists p : t, p + x' == y') <-> (exists p : t, p + x' == y')Proper (eq ==> eq ==> iff) lt_altProper (eq ==> eq ==> iff) lt_altx, x':tHx:x == x'y, y':tHy:y == y'(exists p : t, S p + x == y) <-> (exists p : t, S p + x' == y')x, x':tHx:x == x'y, y':tHy:y == y'(exists p : t, S p + x' == y) <-> (exists p : t, S p + x' == y')auto with *. Qed.x, x':tHx:x == x'y, y':tHy:y == y'(exists p : t, S p + x' == y') <-> (exists p : t, S p + x' == y')
With these alternative definition, the dichotomy:
∀ n m, n ≤ m ∨ m ≤ n
becomes:
∀ n m, (∃ p, p + n == m) ∨ (∃ p, p + m == n)
We will need this in the proof of induction principle for integers
constructed as pairs of natural numbers. This formula can be proved
from know properties of ≤. However, it can also be done directly.
forall n m : t, le_alt n m \/ le_alt m nforall n m : t, le_alt n m \/ le_alt m nm:tle_alt 0 m \/ le_alt m 0m:tforall n : t, le_alt n m \/ le_alt m n -> le_alt (S n) m \/ le_alt m (S n)m:tforall n : t, le_alt n m \/ le_alt m n -> le_alt (S n) m \/ le_alt m (S n)m, n:tIH:le_alt n m \/ le_alt m nle_alt (S n) m \/ le_alt m (S n)m, n, p:tH:p + n == mle_alt (S n) m \/ le_alt m (S n)m, n, p:tH:p + m == nle_alt (S n) m \/ le_alt m (S n)m, n, p:tH:0 + n == mH1:p == 0le_alt (S n) m \/ le_alt m (S n)m, n, p, p':tH:S p' + n == mH1:p == S p'le_alt (S n) m \/ le_alt m (S n)m, n, p:tH:p + m == nle_alt (S n) m \/ le_alt m (S n)m, n, p:tH:n == mH1:p == 0le_alt (S n) m \/ le_alt m (S n)m, n, p, p':tH:S p' + n == mH1:p == S p'le_alt (S n) m \/ le_alt m (S n)m, n, p:tH:p + m == nle_alt (S n) m \/ le_alt m (S n)m, n, p, p':tH:S p' + n == mH1:p == S p'le_alt (S n) m \/ le_alt m (S n)m, n, p:tH:p + m == nle_alt (S n) m \/ le_alt m (S n)m, n, p:tH:p + m == nle_alt (S n) m \/ le_alt m (S n)rewrite add_succ_l; now rewrite H. Qed.m, n, p:tH:p + m == nS p + m == S nforall n m : t, (exists p : t, p + n == m) \/ (exists p : t, p + m == n)exact le_alt_dichotomy. Qed. End NSubProp.forall n m : t, (exists p : t, p + n == m) \/ (exists p : t, p + m == n)