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) *)
(************************************************************************)
Nota : this file is OBSOLETE, and left only for compatibility.
Please consider using Nat.div2 directly, and results about it
(see file PeanoNat).
Require Import PeanoNat Even. Local Open Scope nat_scope. Implicit Type n : nat.
Here we define n/2 and prove some of its properties
Notation div2 := Nat.div2 (only parsing).
Since div2 is recursively defined on 0, 1 and (S (S n)), it is
useful to prove the corresponding induction principle
forall P : nat -> Prop, P 0 -> P 1 -> (forall n : nat, P n -> P (S (S n))) -> forall n : nat, P nforall P : nat -> Prop, P 0 -> P 1 -> (forall n : nat, P n -> P (S (S n))) -> forall n : nat, P nP:nat -> PropH0:P 0H1:P 1H2:forall n : nat, P n -> P (S (S n))forall n : nat, P nP:nat -> PropH0:P 0H1:P 1H2:forall n : nat, P n -> P (S (S n))ind_0_1_SS:forall n : nat, P nforall n : nat, P nP:nat -> PropH0:P 0H1:P 1H2:forall n : nat, P n -> P (S (S n))ind_0_1_SS:forall n : nat, P nP 0P:nat -> PropH0:P 0H1:P 1H2:forall n : nat, P n -> P (S (S n))ind_0_1_SS:forall n : nat, P nP 1P:nat -> PropH0:P 0H1:P 1H2:forall n0 : nat, P n0 -> P (S (S n0))ind_0_1_SS:forall n0 : nat, P n0n:natP (S (S n))exact H0.P:nat -> PropH0:P 0H1:P 1H2:forall n : nat, P n -> P (S (S n))ind_0_1_SS:forall n : nat, P nP 0exact H1.P:nat -> PropH0:P 0H1:P 1H2:forall n : nat, P n -> P (S (S n))ind_0_1_SS:forall n : nat, P nP 1apply H2, ind_0_1_SS. Qed.P:nat -> PropH0:P 0H1:P 1H2:forall n0 : nat, P n0 -> P (S (S n0))ind_0_1_SS:forall n0 : nat, P n0n:natP (S (S n))
0 <n ⇒ n/2 < n
n:nat0 < n -> Nat.div2 n < napply Nat.lt_div2. Qed. Hint Resolve lt_div2: arith.n:nat0 < n -> Nat.div2 n < n
Properties related to the parity
n:nateven n -> Nat.div2 n = Nat.div2 (S n)n:nateven n -> Nat.div2 n = Nat.div2 (S n)n:natNat.Even n -> Nat.div2 n = Nat.div2 (S n)p:natNat.div2 (2 * p) = Nat.div2 (S (2 * p))apply Nat.div2_double. Qed.p:natNat.div2 (2 * p) = pn:natodd n -> S (Nat.div2 n) = Nat.div2 (S n)n:natodd n -> S (Nat.div2 n) = Nat.div2 (S n)n:natNat.Odd n -> S (Nat.div2 n) = Nat.div2 (S n)p:natS (Nat.div2 (2 * p + 1)) = Nat.div2 (S (2 * p + 1))p:natS p = Nat.div2 (S (S (2 * p)))p:natS p = S (Nat.div2 (p + (p + 0)))p:natp = Nat.div2 (p + (p + 0))apply Nat.div2_double. Qed.p:natNat.div2 (p + (p + 0)) = pn:natNat.div2 n = Nat.div2 (S n) -> even nn:natNat.div2 n = Nat.div2 (S n) -> even nn:natOd:odd nNat.div2 n = Nat.div2 (S n) -> even nn:natOd:S (Nat.div2 n) = Nat.div2 (S n)Nat.div2 n = Nat.div2 (S n) -> even nn:natOd:S (Nat.div2 n) = Nat.div2 (S n)Nat.div2 n = S (Nat.div2 n) -> even nelim (n_Sn _ Od'). Qed.n:natOd:S (Nat.div2 n) = Nat.div2 (S n)Od':Nat.div2 n = S (Nat.div2 n)even nn:natS (Nat.div2 n) = Nat.div2 (S n) -> odd nn:natS (Nat.div2 n) = Nat.div2 (S n) -> odd nn:natEv:even nS (Nat.div2 n) = Nat.div2 (S n) -> odd nn:natEv:Nat.div2 n = Nat.div2 (S n)S (Nat.div2 n) = Nat.div2 (S n) -> odd nn:natEv:Nat.div2 n = Nat.div2 (S n)S (Nat.div2 n) = Nat.div2 n -> odd nn:natEv:Nat.div2 n = Nat.div2 (S n)Ev':S (Nat.div2 n) = Nat.div2 nodd nelim (n_Sn _ Ev'). Qed. Hint Resolve even_div2 div2_even odd_div2 div2_odd: arith.n:natEv:Nat.div2 n = Nat.div2 (S n)Ev':Nat.div2 n = S (Nat.div2 n)odd nn:nat(even n <-> Nat.div2 n = Nat.div2 (S n)) /\ (odd n <-> S (Nat.div2 n) = Nat.div2 (S n))split; split; auto using div2_odd, div2_even, odd_div2, even_div2. Qed.n:nat(even n <-> Nat.div2 n = Nat.div2 (S n)) /\ (odd n <-> S (Nat.div2 n) = Nat.div2 (S n))
Properties related to the double (2n)
Notation double := Nat.double (only parsing). Hint Unfold double Nat.double: arith.n:natNat.double (S n) = S (S (Nat.double n))apply Nat.add_succ_r. Qed.n:natNat.double (S n) = S (S (Nat.double n))n, m:natNat.double (n + m) = Nat.double n + Nat.double mapply Nat.add_shuffle1. Qed. Hint Resolve double_S: arith.n, m:natNat.double (n + m) = Nat.double n + Nat.double mn:nat(even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))n:nat(even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))(even 0 <-> 0 = Nat.double (Nat.div2 0)) /\ (odd 0 <-> 0 = S (Nat.double (Nat.div2 0)))even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))(even 1 <-> 1 = Nat.double (Nat.div2 1)) /\ (odd 1 <-> 1 = S (Nat.double (Nat.div2 1)))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:nat(even (S (S n)) <-> S (S n) = Nat.double (Nat.div2 (S (S n)))) /\ (odd (S (S n)) <-> S (S n) = S (Nat.double (Nat.div2 (S (S n)))))even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))(even 0 <-> 0 = Nat.double (Nat.div2 0)) /\ (odd 0 <-> 0 = S (Nat.double (Nat.div2 0)))inversion 1.even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))odd 0 -> 0 = S (Nat.double (Nat.div2 0))even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))(even 1 <-> 1 = Nat.double (Nat.div2 1)) /\ (odd 1 <-> 1 = S (Nat.double (Nat.div2 1)))even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))even 1 -> 1 = Nat.double (Nat.div2 1)inversion H0.even_odd_double:forall n : nat, (even n <-> n = Nat.double (Nat.div2 n)) /\ (odd n <-> n = S (Nat.double (Nat.div2 n)))H0:odd 01 = Nat.double (Nat.div2 1)even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:nat(even (S (S n)) <-> S (S n) = Nat.double (Nat.div2 (S (S n)))) /\ (odd (S (S n)) <-> S (S n) = S (Nat.double (Nat.div2 (S (S n)))))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd n(even (S (S n)) <-> S (S n) = Nat.double (Nat.div2 (S (S n)))) /\ (odd (S (S n)) <-> S (S n) = S (Nat.double (Nat.div2 (S (S n)))))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd neven (S (S n)) -> S (S n) = S (S (Nat.double (Nat.div2 n)))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nS (S n) = S (S (Nat.double (Nat.div2 n))) -> even (S (S n))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nodd (S (S n)) -> S (S n) = S (S (S (Nat.double (Nat.div2 n))))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nS (S n) = S (S (S (Nat.double (Nat.div2 n)))) -> odd (S (S n))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd neven (S (S n)) -> S (S n) = S (S (Nat.double (Nat.div2 n)))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nH0:odd (S n)S (S n) = S (S (Nat.double (Nat.div2 n)))auto.even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nH:even nS (S n) = S (S (Nat.double (Nat.div2 n)))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nS (S n) = S (S (Nat.double (Nat.div2 n))) -> even (S (S n))auto with arith.even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nH:S (S n) = S (S (Nat.double (Nat.div2 n)))n = Nat.double (Nat.div2 n) -> even (S (S n))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nodd (S (S n)) -> S (S n) = S (S (S (Nat.double (Nat.div2 n))))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nH0:even (S n)S (S n) = S (S (S (Nat.double (Nat.div2 n))))auto.even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nH:odd nS (S n) = S (S (S (Nat.double (Nat.div2 n))))even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nS (S n) = S (S (S (Nat.double (Nat.div2 n)))) -> odd (S (S n))auto with arith. Qed.even_odd_double:forall n0 : nat, (even n0 <-> n0 = Nat.double (Nat.div2 n0)) /\ (odd n0 <-> n0 = S (Nat.double (Nat.div2 n0)))n:natEv:even n -> n = Nat.double (Nat.div2 n)Ev':n = Nat.double (Nat.div2 n) -> even nOd:odd n -> n = S (Nat.double (Nat.div2 n))Od':n = S (Nat.double (Nat.div2 n)) -> odd nH:S (S n) = S (S (S (Nat.double (Nat.div2 n))))n = S (Nat.double (Nat.div2 n)) -> odd (S (S n))
Specializations
Proof proj1 (proj1 (even_odd_double n)).n:nateven n -> n = Nat.double (Nat.div2 n)Proof proj2 (proj1 (even_odd_double n)).n:natn = Nat.double (Nat.div2 n) -> even nProof proj1 (proj2 (even_odd_double n)).n:natodd n -> n = S (Nat.double (Nat.div2 n))Proof proj2 (proj2 (even_odd_double n)). Hint Resolve even_double double_even odd_double double_odd: arith.n:natn = S (Nat.double (Nat.div2 n)) -> odd n
Application:
(Immediate: it is n/2)
- if n is even then there is a p such that n = 2p
- if n is odd then there is a p such that n = 2p+1
forall n : nat, even n -> {p : nat | n = Nat.double p}forall n : nat, even n -> {p : nat | n = Nat.double p}n:natH:even n{p : nat | n = Nat.double p}auto with arith. Defined.n:natH:even nn = Nat.double (Nat.div2 n)forall n : nat, odd n -> {p : nat | n = S (Nat.double p)}forall n : nat, odd n -> {p : nat | n = S (Nat.double p)}n:natH:odd n{p : nat | n = S (Nat.double p)}auto with arith. Defined.n:natH:odd nn = S (Nat.double (Nat.div2 n))
Doubling before dividing by two brings back to the initial number.
n:natNat.div2 (2 * n) = napply Nat.div2_double. Qed.n:natNat.div2 (2 * n) = nn:natNat.div2 (S (2 * n)) = napply Nat.div2_succ_double. Qed.n:natNat.div2 (S (2 * n)) = n