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
|
Require Export NAxioms.
Module Type NOrderSignature.
Declare Module Export NatModule : NatSignature.
Open Local Scope NatScope.
Parameter Inline lt : N -> N -> bool.
Parameter Inline le : N -> N -> bool.
Notation "x < y" := (lt x y) : NatScope.
Notation "x <= y" := (le x y) : NatScope.
Add Morphism lt with signature E ==> E ==> eq_bool as lt_wd.
Add Morphism le with signature E ==> E ==> eq_bool as le_wd.
Axiom le_lt : forall x y, x <= y <-> x < y \/ x == y.
Axiom lt_0 : forall x, ~ (x < 0).
Axiom lt_S : forall x y, x < S y <-> x <= y.
End NOrderSignature.
Module NOrderProperties (Import NOrderModule : NOrderSignature).
Module Export NatPropertiesModule := NatProperties NatModule.
Open Local Scope NatScope.
Ltac le_intro1 := rewrite le_lt; left.
Ltac le_intro2 := rewrite le_lt; right.
Ltac le_elim H := rewrite le_lt in H; destruct H as [H | H].
Theorem le_refl : forall n, n <= n.
Proof.
intro; now le_intro2.
Qed.
Theorem le_0_r : forall n, n <= 0 -> n == 0.
Proof.
intros n H; le_elim H; [false_hyp H lt_0 | assumption].
Qed.
Theorem lt_n_Sn : forall n, n < S n.
Proof.
intro n. apply <- lt_S. now le_intro2.
Qed.
Theorem lt_closed_S : forall n m, n < m -> n < S m.
Proof.
intros. apply <- lt_S. now le_intro1.
Qed.
Theorem lt_S_lt : forall n m, S n < m -> n < m.
Proof.
intro n; induct m.
intro H; absurd_hyp H; [apply lt_0 | assumption].
intros x IH H.
apply -> lt_S in H. le_elim H.
apply IH in H; now apply lt_closed_S.
rewrite <- H.
apply lt_closed_S; apply lt_n_Sn.
Qed.
Theorem lt_0_Sn : forall n, 0 < S n.
Proof.
induct n; [apply lt_n_Sn | intros x H; now apply lt_closed_S].
Qed.
Theorem lt_transitive : forall n m p, n < m -> m < p -> n < p.
Proof.
intros n m p; induct m.
intros H1 H2; absurd_hyp H1; [ apply lt_0 | assumption].
intros x IH H1 H2.
apply -> lt_S in H1. le_elim H1.
apply IH; [assumption | apply lt_S_lt; assumption].
rewrite H1; apply lt_S_lt; assumption.
Qed.
Theorem lt_positive : forall n m, n < m -> 0 < m.
Proof.
intros n m; induct n.
trivial.
intros x IH H.
apply lt_transitive with (m := S x); [apply lt_0_Sn | apply H].
Qed.
Theorem lt_resp_S : forall n m, S n < S m <-> n < m.
Proof.
intros n m; split.
intro H; apply -> lt_S in H; le_elim H.
intros; apply lt_S_lt; assumption.
rewrite <- H; apply lt_n_Sn.
induct m.
intro H; false_hyp H lt_0.
intros x IH H.
apply -> lt_S in H; le_elim H.
apply lt_transitive with (m := S x).
apply IH; assumption.
apply lt_n_Sn.
rewrite H; apply lt_n_Sn.
Qed.
Theorem le_resp_S : forall n m, S n <= S m <-> n <= m.
Proof.
intros n m; do 2 rewrite le_lt.
pose proof (S_wd n m); pose proof (S_inj n m); pose proof (lt_resp_S n m); tauto.
Qed.
Theorem lt_le_S_l : forall n m, n < m <-> S n <= m.
Proof.
intros n m; nondep_induct m.
split; intro H; [false_hyp H lt_0 |
le_elim H; [false_hyp H lt_0 | false_hyp H S_0]].
intros m; split; intro H.
apply -> lt_S in H. le_elim H; [le_intro1; now apply <- lt_resp_S | le_intro2; now apply S_wd].
le_elim H; [apply lt_transitive with (m := S n); [apply lt_n_Sn | assumption] |
apply S_inj in H; rewrite H; apply lt_n_Sn].
Qed.
Theorem le_S_0 : forall n, ~ (S n <= 0).
Proof.
intros n H; apply <- lt_le_S_l in H; false_hyp H lt_0.
Qed.
Theorem le_S_l_le : forall n m, S n <= m -> n <= m.
Proof.
intros; le_intro1; now apply <- lt_le_S_l.
Qed.
Theorem lt_irreflexive : forall n, ~ (n < n).
Proof.
induct n.
apply lt_0.
intro x; unfold not; intros H1 H2; apply H1; now apply -> lt_resp_S.
Qed.
Theorem neq_0_lt : forall n, 0 # n -> 0 < n.
Proof.
induct n.
intro H; now elim H.
intros; apply lt_0_Sn.
Qed.
Theorem lt_0_neq : forall n, 0 < n -> 0 # n.
Proof.
induct n.
intro H; absurd_hyp H; [apply lt_0 | assumption].
unfold not; intros; now apply S_0 with (n := n).
Qed.
Theorem lt_asymmetric : forall n m, ~ (n < m /\ m < n).
Proof.
unfold not; intros n m [H1 H2].
now apply (lt_transitive n m n) in H1; [false_hyp H1 lt_irreflexive|].
Qed.
Theorem le_0_l: forall n, 0 <= n.
Proof.
induct n; [now le_intro2 | intros; le_intro1; apply lt_0_Sn].
Qed.
Theorem lt_trichotomy : forall n m, n < m \/ n == m \/ m < n.
Proof.
intros n m; induct n.
assert (H : 0 <= m); [apply le_0_l | apply -> le_lt in H; tauto].
intros n IH. destruct IH as [H | H].
assert (H1 : S n <= m); [now apply -> lt_le_S_l | apply -> le_lt in H1; tauto].
destruct H as [H | H].
right; right; rewrite H; apply lt_n_Sn.
right; right; apply lt_transitive with (m := n); [assumption | apply lt_n_Sn].
Qed.
Theorem lt_dichotomy : forall n m, n < m \/ ~ n < m.
Proof.
intros n m; pose proof (lt_trichotomy n m) as H.
destruct H as [H1 | H1]; [now left |].
destruct H1 as [H2 | H2].
right; rewrite H2; apply lt_irreflexive.
right; intro; apply (lt_asymmetric n m); split; assumption.
Qed.
Theorem nat_total_order : forall n m, n # m -> n < m \/ m < n.
Proof.
intros n m H; destruct (lt_trichotomy n m) as [A | A]; [now left |].
now destruct A as [A | A]; [elim H | right].
Qed.
Theorem lt_exists_pred : forall n, 0 < n -> exists m, n == S m.
Proof.
induct n.
intro H; false_hyp H lt_0.
intros n IH H; now exists n.
Qed.
(** Elimination principles for < and <= *)
Section Induction1.
Variable Q : N -> Prop.
Hypothesis Q_wd : pred_wd E Q.
Variable n : N.
Add Morphism Q with signature E ==> iff as Q_morph1.
Proof Q_wd.
Theorem le_ind :
Q n ->
(forall m, n <= m -> Q m -> Q (S m)) ->
forall m, n <= m -> Q m.
Proof.
intros Base Step. induct m.
intro H. apply le_0_r in H. now rewrite <- H.
intros m IH H. le_elim H.
apply -> lt_S in H. now apply Step; [| apply IH].
now rewrite <- H.
Qed.
Theorem lt_ind :
Q (S n) ->
(forall m, n < m -> Q m -> Q (S m)) ->
forall m, n < m -> Q m.
Proof.
intros Base Step. induct m.
intro H; false_hyp H lt_0.
intros m IH H. apply -> lt_S in H. le_elim H.
now apply Step; [| apply IH]. now rewrite <- H.
Qed.
End Induction1.
Section Induction2.
(* Variable Q : relation N. -- does not work !!! *)
Variable Q : N -> N -> Prop.
Hypothesis Q_wd : rel_wd E Q.
Add Morphism Q with signature E ==> E ==> iff as Q_morph2.
Proof Q_wd.
Theorem le_ind_rel :
(forall m, Q 0 m) ->
(forall n m, n <= m -> Q n m -> Q (S n) (S m)) ->
forall n m, n <= m -> Q n m.
Proof.
intros Base Step; induct n.
intros; apply Base.
intros n IH m; nondep_induct m.
intro H; false_hyp H le_S_0.
intros m H. apply -> le_resp_S in H. now apply Step; [| apply IH].
Qed.
Theorem lt_ind_rel :
(forall m, Q 0 (S m)) ->
(forall n m, n < m -> Q n m -> Q (S n) (S m)) ->
forall n m, n < m -> Q n m.
Proof.
intros Base Step; induct n.
intros m H. apply lt_exists_pred in H; destruct H as [m' H].
rewrite H; apply Base.
intros n IH m; nondep_induct m.
intro H; false_hyp H lt_0.
intros m H. apply -> lt_resp_S in H. now apply Step; [| apply IH].
Qed.
End Induction2.
End NOrderProperties.
|