1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
(*i $Id: Even.v 9245 2006-10-17 12:53:34Z notin $ i*)
(** 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. *)
Open Local Scope nat_scope.
Implicit Types m n : nat.
(** * Definition of [even] and [odd], and basic facts *)
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.
Lemma even_or_odd : forall n, even n \/ odd n.
Proof.
induction n.
auto with arith.
elim IHn; auto with arith.
Qed.
Lemma even_odd_dec : forall n, {even n} + {odd n}.
Proof.
induction n.
auto with arith.
elim IHn; auto with arith.
Qed.
Lemma not_even_and_odd : forall n, even n -> odd n -> False.
Proof.
induction n.
intros even_0 odd_0. inversion odd_0.
intros even_Sn odd_Sn. inversion even_Sn. inversion odd_Sn. auto with arith.
Qed.
(** * Facts about [even] & [odd] wrt. [plus] *)
Lemma even_plus_aux :
forall n m,
(odd (n + m) <-> odd n /\ even m \/ even n /\ odd m) /\
(even (n + m) <-> even n /\ even m \/ odd n /\ odd m).
Proof.
intros n; elim n; simpl in |- *; auto with arith.
intros m; split; auto.
split.
intros H; right; split; auto with arith.
intros H'; case H'; auto with arith.
intros H'0; elim H'0; intros H'1 H'2; inversion H'1.
intros H; elim H; auto.
split; auto with arith.
intros H'; elim H'; auto with arith.
intros H; elim H; auto.
intros H'0; elim H'0; intros H'1 H'2; inversion H'1.
intros n0 H' m; elim (H' m); intros H'1 H'2; elim H'1; intros E1 E2; elim H'2;
intros E3 E4; clear H'1 H'2.
split; split.
intros H'0; case E3.
inversion H'0; auto.
intros H; elim H; intros H0 H1; clear H; auto with arith.
intros H; elim H; intros H0 H1; clear H; auto with arith.
intros H'0; case H'0; intros C0; case C0; intros C1 C2.
apply odd_S.
apply E4; left; split; auto with arith.
inversion C1; auto.
apply odd_S.
apply E4; right; split; auto with arith.
inversion C1; auto.
intros H'0.
case E1.
inversion H'0; auto.
intros H; elim H; intros H0 H1; clear H; auto with arith.
intros H; elim H; intros H0 H1; clear H; auto with arith.
intros H'0; case H'0; intros C0; case C0; intros C1 C2.
apply even_S.
apply E2; left; split; auto with arith.
inversion C1; auto.
apply even_S.
apply E2; right; split; auto with arith.
inversion C1; auto.
Qed.
Lemma even_even_plus : forall n m, even n -> even m -> even (n + m).
Proof.
intros n m; case (even_plus_aux n m).
intros H H0; case H0; auto.
Qed.
Lemma odd_even_plus : forall n m, odd n -> odd m -> even (n + m).
Proof.
intros n m; case (even_plus_aux n m).
intros H H0; case H0; auto.
Qed.
Lemma even_plus_even_inv_r : forall n m, even (n + m) -> even n -> even m.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'0.
intros H'1; case H'1; auto.
intros H0; elim H0; auto.
intros H0 H1 H2; case (not_even_and_odd n); auto.
case H0; auto.
Qed.
Lemma even_plus_even_inv_l : forall n m, even (n + m) -> even m -> even n.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'0.
intros H'1; case H'1; auto.
intros H0; elim H0; auto.
intros H0 H1 H2; case (not_even_and_odd m); auto.
case H0; auto.
Qed.
Lemma even_plus_odd_inv_r : forall n m, even (n + m) -> odd n -> odd m.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'0.
intros H'1; case H'1; auto.
intros H0 H1 H2; case (not_even_and_odd n); auto.
case H0; auto.
intros H0; case H0; auto.
Qed.
Lemma even_plus_odd_inv_l : forall n m, even (n + m) -> odd m -> odd n.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'0.
intros H'1; case H'1; auto.
intros H0 H1 H2; case (not_even_and_odd m); auto.
case H0; auto.
intros H0; case H0; auto.
Qed.
Hint Resolve even_even_plus odd_even_plus: arith.
Lemma odd_plus_l : forall n m, odd n -> even m -> odd (n + m).
Proof.
intros n m; case (even_plus_aux n m).
intros H; case H; auto.
Qed.
Lemma odd_plus_r : forall n m, even n -> odd m -> odd (n + m).
Proof.
intros n m; case (even_plus_aux n m).
intros H; case H; auto.
Qed.
Lemma odd_plus_even_inv_l : forall n m, odd (n + m) -> odd m -> even n.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'.
intros H'1; case H'1; auto.
intros H0 H1 H2; case (not_even_and_odd m); auto.
case H0; auto.
intros H0; case H0; auto.
Qed.
Lemma odd_plus_even_inv_r : forall n m, odd (n + m) -> odd n -> even m.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'.
intros H'1; case H'1; auto.
intros H0; case H0; auto.
intros H0 H1 H2; case (not_even_and_odd n); auto.
case H0; auto.
Qed.
Lemma odd_plus_odd_inv_l : forall n m, odd (n + m) -> even m -> odd n.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'.
intros H'1; case H'1; auto.
intros H0; case H0; auto.
intros H0 H1 H2; case (not_even_and_odd m); auto.
case H0; auto.
Qed.
Lemma odd_plus_odd_inv_r : forall n m, odd (n + m) -> even n -> odd m.
Proof.
intros n m H; case (even_plus_aux n m).
intros H' H'0; elim H'.
intros H'1; case H'1; auto.
intros H0 H1 H2; case (not_even_and_odd n); auto.
case H0; auto.
intros H0; case H0; auto.
Qed.
Hint Resolve odd_plus_l odd_plus_r: arith.
(** * Facts about [even] and [odd] wrt. [mult] *)
Lemma even_mult_aux :
forall n m,
(odd (n * m) <-> odd n /\ odd m) /\ (even (n * m) <-> even n \/ even m).
Proof.
intros n; elim n; simpl in |- *; auto with arith.
intros m; split; split; auto with arith.
intros H'; inversion H'.
intros H'; elim H'; auto.
intros n0 H' m; split; split; auto with arith.
intros H'0.
elim (even_plus_aux m (n0 * m)); intros H'3 H'4; case H'3; intros H'1 H'2;
case H'1; auto.
intros H'5; elim H'5; intros H'6 H'7; auto with arith.
split; auto with arith.
case (H' m).
intros H'8 H'9; case H'9.
intros H'10; case H'10; auto with arith.
intros H'11 H'12; case (not_even_and_odd m); auto with arith.
intros H'5; elim H'5; intros H'6 H'7; case (not_even_and_odd (n0 * m)); auto.
case (H' m).
intros H'8 H'9; case H'9; auto.
intros H'0; elim H'0; intros H'1 H'2; clear H'0.
elim (even_plus_aux m (n0 * m)); auto.
intros H'0 H'3.
elim H'0.
intros H'4 H'5; apply H'5; auto.
left; split; auto with arith.
case (H' m).
intros H'6 H'7; elim H'7.
intros H'8 H'9; apply H'9.
left.
inversion H'1; auto.
intros H'0.
elim (even_plus_aux m (n0 * m)); intros H'3 H'4; case H'4.
intros H'1 H'2.
elim H'1; auto.
intros H; case H; auto.
intros H'5; elim H'5; intros H'6 H'7; auto with arith.
left.
case (H' m).
intros H'8; elim H'8.
intros H'9; elim H'9; auto with arith.
intros H'0; elim H'0; intros H'1.
case (even_or_odd m); intros H'2.
apply even_even_plus; auto.
case (H' m).
intros H H0; case H0; auto.
apply odd_even_plus; auto.
inversion H'1; case (H' m); auto.
intros H1; case H1; auto.
apply even_even_plus; auto.
case (H' m).
intros H H0; case H0; auto.
Qed.
Lemma even_mult_l : forall n m, even n -> even (n * m).
Proof.
intros n m; case (even_mult_aux n m); auto.
intros H H0; case H0; auto.
Qed.
Lemma even_mult_r : forall n m, even m -> even (n * m).
Proof.
intros n m; case (even_mult_aux n m); auto.
intros H H0; case H0; auto.
Qed.
Hint Resolve even_mult_l even_mult_r: arith.
Lemma even_mult_inv_r : forall n m, even (n * m) -> odd n -> even m.
Proof.
intros n m H' H'0.
case (even_mult_aux n m).
intros H'1 H'2; elim H'2.
intros H'3; elim H'3; auto.
intros H; case (not_even_and_odd n); auto.
Qed.
Lemma even_mult_inv_l : forall n m, even (n * m) -> odd m -> even n.
Proof.
intros n m H' H'0.
case (even_mult_aux n m).
intros H'1 H'2; elim H'2.
intros H'3; elim H'3; auto.
intros H; case (not_even_and_odd m); auto.
Qed.
Lemma odd_mult : forall n m, odd n -> odd m -> odd (n * m).
Proof.
intros n m; case (even_mult_aux n m); intros H; case H; auto.
Qed.
Hint Resolve even_mult_l even_mult_r odd_mult: arith.
Lemma odd_mult_inv_l : forall n m, odd (n * m) -> odd n.
Proof.
intros n m H'.
case (even_mult_aux n m).
intros H'1 H'2; elim H'1.
intros H'3; elim H'3; auto.
Qed.
Lemma odd_mult_inv_r : forall n m, odd (n * m) -> odd m.
Proof.
intros n m H'.
case (even_mult_aux n m).
intros H'1 H'2; elim H'1.
intros H'3; elim H'3; auto.
Qed.
|