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 instead predicates Nat.Even and Nat.Odd
and Boolean functions Nat.even and Nat.odd.
Here we define the predicates even and odd by mutual induction
and we prove the decidability and the exclusion of those predicates.
The main results about parity are proved in the module Div2.
Require Import PeanoNat. Local Open Scope nat_scope. Implicit Types m n : nat.
Inductive even : nat -> Prop := | even_O : even 0 | even_S : forall n, odd n -> even (S n) with odd : nat -> Prop := odd_S : forall n, even n -> odd (S n). Hint Constructors even: arith. Hint Constructors odd: arith.
forall n : nat, even n <-> Nat.Even nforall n : nat, even n <-> Nat.Even neven_equiv:forall n : nat, even n <-> Nat.Even nforall n : nat, even n <-> Nat.Even neven_equiv:forall n : nat, even n <-> Nat.Even neven 0 <-> Nat.Even 0even_equiv:forall n : nat, even n <-> Nat.Even neven 1 <-> Nat.Even 1even_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven (S (S n)) <-> Nat.Even (S (S n))split; [now exists 0 | constructor].even_equiv:forall n : nat, even n <-> Nat.Even neven 0 <-> Nat.Even 0even_equiv:forall n : nat, even n <-> Nat.Even neven 1 <-> Nat.Even 1even_equiv:forall n : nat, even n <-> Nat.Even neven 1 -> Nat.Even 1even_equiv:forall n : nat, even n <-> Nat.Even nNat.Even 1 -> even 1even_equiv:forall n : nat, even n <-> Nat.Even neven 1 -> Nat.Even 1inversion_clear H0.even_equiv:forall n : nat, even n <-> Nat.Even nH0:odd 0Nat.Even 1now rewrite <- Nat.even_spec.even_equiv:forall n : nat, even n <-> Nat.Even nNat.Even 1 -> even 1even_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven (S (S n)) <-> Nat.Even (S (S n))even_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven (S (S n)) <-> even neven_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven (S (S n)) -> even neven_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven n -> even (S (S n))even_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven (S (S n)) -> even nnow inversion_clear H0.even_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:natH0:odd (S n)even nnow do 2 constructor. Qed.even_equiv:forall n0 : nat, even n0 <-> Nat.Even n0n:nateven n -> even (S (S n))forall n : nat, odd n <-> Nat.Odd nforall n : nat, odd n <-> Nat.Odd nodd_equiv:forall n : nat, odd n <-> Nat.Odd nforall n : nat, odd n <-> Nat.Odd nodd_equiv:forall n : nat, odd n <-> Nat.Odd nodd 0 <-> Nat.Odd 0odd_equiv:forall n : nat, odd n <-> Nat.Odd nodd 1 <-> Nat.Odd 1odd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd (S (S n)) <-> Nat.Odd (S (S n))odd_equiv:forall n : nat, odd n <-> Nat.Odd nodd 0 <-> Nat.Odd 0odd_equiv:forall n : nat, odd n <-> Nat.Odd nodd 0 -> Nat.Odd 0odd_equiv:forall n : nat, odd n <-> Nat.Odd nNat.Odd 0 -> odd 0inversion_clear 1.odd_equiv:forall n : nat, odd n <-> Nat.Odd nodd 0 -> Nat.Odd 0now rewrite <- Nat.odd_spec.odd_equiv:forall n : nat, odd n <-> Nat.Odd nNat.Odd 0 -> odd 0split; [ now exists 0 | do 2 constructor ].odd_equiv:forall n : nat, odd n <-> Nat.Odd nodd 1 <-> Nat.Odd 1odd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd (S (S n)) <-> Nat.Odd (S (S n))odd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd (S (S n)) <-> odd nodd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd (S (S n)) -> odd nodd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd n -> odd (S (S n))odd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd (S (S n)) -> odd nnow inversion_clear H0.odd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natH0:even (S n)odd nnow do 2 constructor. Qed.odd_equiv:forall n0 : nat, odd n0 <-> Nat.Odd n0n:natodd n -> odd (S (S n))
Basic facts
n:nateven n \/ odd nn:nateven n \/ odd neven 0 \/ odd 0n:natIHn:even n \/ odd neven (S n) \/ odd (S n)auto with arith.even 0 \/ odd 0elim IHn; auto with arith. Qed.n:natIHn:even n \/ odd neven (S n) \/ odd (S n)n:nat{even n} + {odd n}n:nat{even n} + {odd n}{even 0} + {odd 0}n:natIHn:{even n} + {odd n}{even (S n)} + {odd (S n)}auto with arith.{even 0} + {odd 0}elim IHn; auto with arith. Defined.n:natIHn:{even n} + {odd n}{even (S n)} + {odd (S n)}n:nateven n -> odd n -> Falsen:nateven n -> odd n -> Falseeven 0 -> odd 0 -> Falsen:natIHn:even n -> odd n -> Falseeven (S n) -> odd (S n) -> Falseeven 0 -> odd 0 -> Falseinversion Od.Ev:even 0Od:odd 0Falsen:natIHn:even n -> odd n -> Falseeven (S n) -> odd (S n) -> Falsen:natIHn:even n -> odd n -> FalseEv:even (S n)Od:odd (S n)Falsen:natIHn:even n -> odd n -> FalseEv:even (S n)Od:odd (S n)n0:natH0:odd nH:n0 = nFalseauto with arith. Qed.n:natIHn:even n -> odd n -> FalseEv:even (S n)Od:odd (S n)n0:natH0:odd nH:n0 = nn1:natH2:even nH1:n1 = nFalse
Ltac parity2bool := rewrite ?even_equiv, ?odd_equiv, <- ?Nat.even_spec, <- ?Nat.odd_spec. Ltac parity_binop_spec := rewrite ?Nat.even_add, ?Nat.odd_add, ?Nat.even_mul, ?Nat.odd_mul. Ltac parity_binop := parity2bool; parity_binop_spec; unfold Nat.odd; do 2 destruct Nat.even; simpl; tauto.n, m:nateven (n + m) -> even n /\ even m \/ odd n /\ odd mparity_binop. Qed.n, m:nateven (n + m) -> even n /\ even m \/ odd n /\ odd mn, m:natodd (n + m) -> odd n /\ even m \/ even n /\ odd mparity_binop. Qed.n, m:natodd (n + m) -> odd n /\ even m \/ even n /\ odd mn, m:nateven n -> even m -> even (n + m)parity_binop. Qed.n, m:nateven n -> even m -> even (n + m)n, m:natodd n -> even m -> odd (n + m)parity_binop. Qed.n, m:natodd n -> even m -> odd (n + m)n, m:nateven n -> odd m -> odd (n + m)parity_binop. Qed.n, m:nateven n -> odd m -> odd (n + m)n, m:natodd n -> odd m -> even (n + m)parity_binop. Qed.n, m:natodd n -> odd m -> even (n + m)n, m:nat(odd (n + m) <-> odd n /\ even m \/ even n /\ odd m) /\ (even (n + m) <-> even n /\ even m \/ odd n /\ odd m)parity_binop. Qed.n, m:nat(odd (n + m) <-> odd n /\ even m \/ even n /\ odd m) /\ (even (n + m) <-> even n /\ even m \/ odd n /\ odd m)n, m:nateven (n + m) -> even n -> even mparity_binop. Qed.n, m:nateven (n + m) -> even n -> even mn, m:nateven (n + m) -> even m -> even nparity_binop. Qed.n, m:nateven (n + m) -> even m -> even nn, m:nateven (n + m) -> odd n -> odd mparity_binop. Qed.n, m:nateven (n + m) -> odd n -> odd mn, m:nateven (n + m) -> odd m -> odd nparity_binop. Qed.n, m:nateven (n + m) -> odd m -> odd nn, m:natodd (n + m) -> odd m -> even nparity_binop. Qed.n, m:natodd (n + m) -> odd m -> even nn, m:natodd (n + m) -> odd n -> even mparity_binop. Qed.n, m:natodd (n + m) -> odd n -> even mn, m:natodd (n + m) -> even m -> odd nparity_binop. Qed.n, m:natodd (n + m) -> even m -> odd nn, m:natodd (n + m) -> even n -> odd mparity_binop. Qed.n, m:natodd (n + m) -> even n -> odd m
n, m:nat(odd (n * m) <-> odd n /\ odd m) /\ (even (n * m) <-> even n \/ even m)parity_binop. Qed.n, m:nat(odd (n * m) <-> odd n /\ odd m) /\ (even (n * m) <-> even n \/ even m)n, m:nateven n -> even (n * m)parity_binop. Qed.n, m:nateven n -> even (n * m)n, m:nateven m -> even (n * m)parity_binop. Qed.n, m:nateven m -> even (n * m)n, m:nateven (n * m) -> odd n -> even mparity_binop. Qed.n, m:nateven (n * m) -> odd n -> even mn, m:nateven (n * m) -> odd m -> even nparity_binop. Qed.n, m:nateven (n * m) -> odd m -> even nn, m:natodd n -> odd m -> odd (n * m)parity_binop. Qed.n, m:natodd n -> odd m -> odd (n * m)n, m:natodd (n * m) -> odd nparity_binop. Qed.n, m:natodd (n * m) -> odd nn, m:natodd (n * m) -> odd mparity_binop. Qed. Hint Resolve even_even_plus odd_even_plus odd_plus_l odd_plus_r even_mult_l even_mult_r even_mult_l even_mult_r odd_mult : arith.n, m:natodd (n * m) -> odd m