summaryrefslogtreecommitdiff
path: root/backend/Order_arith.v
blob: 298468c27d5d4c56c515c24bc80f12e176f61aac (plain)
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
Require Import Arith.
Require Import ZArith.

(* Definition of some facts other arith, for the termination order...
   many uninteresting but necessary lemmas *)

Fixpoint puissance_aux x y res {struct y} : nat :=
match y with
| 0 => res
| S n => puissance_aux x n (x*res)
end.

Definition puissance x y := puissance_aux x y 1.

Lemma dec_base_aux : forall a b c d x,
0 < a ->
a + b +c +d < x ->
a*puissance x 3 + b*puissance x 2 + 
c*x + d > 0.

Proof.
intros a b c d x Ha H.
induction a.
inversion Ha.
unfold puissance;simpl;destruct x.
inversion H.
apply lt_le_trans with (m:=S x * (S x * (S x *1))).
rewrite mult_1_r.
case_eq (S x * (S x * S x)).
intro H0.
inversion H0.
intros n H0.
intuition.
intuition.
Qed.

Lemma inf_diff : forall x y,
x - y > 0 -> x > y.

Proof.
intuition.
Qed.

Lemma plop : forall x y,
y > 0 ->
x <= x*y.

Proof.
induction y;intros.
inversion H.
rewrite mult_succ_r.
intuition.
Qed.

Lemma mult_zero : forall x y,
x*y = 0 -> x = 0 \/ y = 0.

Proof.
intros.
induction x.
left;reflexivity.
induction y.
right;reflexivity.
inversion H.
Qed.

Lemma mult_plop : forall x y z,
x > 0 ->
y < z ->
y*x < z*x.

Proof.
intros x y z H H0.
induction x.
inversion H.
destruct (lt_eq_lt_dec x 0).
destruct s.
inversion l.
do 2 rewrite mult_succ_r.
rewrite e.
do 2 rewrite mult_0_r.
intuition.
generalize (IHx l).
do 2 rewrite mult_succ_r.
intuition.
Qed.

Lemma mult_plop_eq : forall x y z,
x > 0 ->
y <= z ->
y*x <= z*x.

Proof.
intros x y z H H0.
induction x.
inversion H.
destruct (lt_eq_lt_dec x 0).
destruct s.
inversion l.
do 2 rewrite mult_succ_r.
rewrite e.
do 2 rewrite mult_0_r.
intuition.
generalize (IHx l).
do 2 rewrite mult_succ_r.
intuition.
Qed.

Lemma mult_plop_eq2 : forall x y z,
x > 0 ->
y <= z ->
x*y <= x*z.

Proof.
intros x y z H H0.
induction x.
inversion H.
destruct (lt_eq_lt_dec x 0).
destruct s.
inversion l.
do 2 rewrite mult_succ_l.
rewrite e.
do 2 rewrite mult_0_l.
intuition.
generalize (IHx l).
do 2 rewrite mult_succ_l.
intuition.
Qed.

Lemma add_inf : forall x y z,
x <= y -> z+x <= z+y.

Proof.
intuition.
Qed.

Lemma add_hd_eq : forall x y z,
x = y -> z+x = z+y.

Proof.
auto.
Qed.

Lemma add_hd_inf : forall x y z,
x < y -> z+x < z + y.

Proof.
intuition.
Qed.

Lemma dec_base : forall a b c d a' b' c' d' x,
a + b + c + d < x -> x > 0 ->
(a < a' ->
(a *puissance x 3 +b *puissance x 2 + c *x + d < 
  a' *puissance x 3 +b' *puissance x 2 + c' *x + d')).

Proof.
intros a b c d a' b' c' d' x H H0 H1.
unfold puissance;simpl.
rewrite mult_1_r.
apply lt_le_trans with (m := (S a)*x*x*x).
rewrite mult_succ_l.
do 2 rewrite mult_plus_distr_r.
replace (a*(x*(x*x))+b*(x*x)+c*x+d) with (a*x*x*x+(b*x*x+c*x+d)).
apply add_hd_inf.
assert (c*x <= c*x*x).
apply plop.
assumption.
assert (d <= d*x*x).
apply le_trans with (m := d*x).
apply plop.
assumption.
apply plop.
assumption.
apply le_lt_trans with (b*x*x+c*x*x+d*x*x).
intuition.
replace (b*x*x+c*x*x+d*x*x) with ((b+c+d)*x*x).
apply mult_plop.
assumption.
apply mult_plop.
assumption.
intuition.
do 4 rewrite mult_plus_distr_r.
reflexivity.
do 2 rewrite plus_assoc.
replace (a*(x* (x*x))) with (a*x*x*x).
replace (b*(x*x)) with (b*x*x).
reflexivity.
intuition.
replace (x*(x*x)) with (x*x*x).
rewrite mult_assoc.
intuition.
intuition.
apply le_trans with (m := a'*(x*(x*x))).
do 2 rewrite mult_assoc.
intuition.
apply mult_plop_eq.
assumption.
apply mult_plop_eq.
assumption.
apply mult_plop_eq.
assumption.
assumption.
intuition.
Qed.

Lemma dec_base2 : forall a b c a' b' c' x,
a + b + c < x -> x > 0 ->
(a < a' ->
(a *puissance x 2 +b *x+ c < 
  a' *puissance x 2 +b' *x + c')).

Proof.
intros a b c a' b' c' x H H0 H1.
unfold puissance;simpl.
rewrite mult_1_r.
apply lt_le_trans with (m := S a*x*x).
rewrite mult_succ_l.
rewrite mult_plus_distr_r.
rewrite mult_assoc.
rewrite <-plus_assoc.
apply add_hd_inf.
assert (c <= c*x).
apply plop.
assumption.
apply le_lt_trans with (m := b*x+c*x).
intuition.
replace (b*x+c*x) with ((b+c)*x).
apply mult_plop.
assumption.
intuition.
intuition.
apply le_trans with (m := a'*x*x).
apply mult_plop_eq.
assumption.
apply mult_plop_eq.
assumption.
intuition.
rewrite mult_assoc.
intuition.
Qed.

Lemma dec_base3 : forall a b a' b' x,
a + b < x -> x > 0 -> a < a' 
-> (a *x +b <   a' *x + b').

Proof.
intros a b a' b' x H H0 H1.
apply lt_le_trans with (m := S a*x).
rewrite mult_succ_l.
intuition.
assert (S a <= a').
intuition.
apply le_trans with (m:= a'*x).
apply mult_plop_eq;assumption.
intuition.
Qed.

Lemma puiss_aux : forall x y n,
puissance_aux x y n = n*puissance x y.

Proof.
unfold puissance;induction y;simpl.
intuition.
intro n.
rewrite mult_1_r.
rewrite (IHy x).
rewrite (IHy (x*n)).
rewrite mult_assoc.
rewrite (mult_comm x n).
reflexivity.
Qed.

Lemma puiss_step : forall x n,
puissance x (S n) = x*puissance x n.

Proof.
intros.
unfold puissance;simpl.
rewrite puiss_aux;simpl.
intuition.
Qed.

Lemma pos_puiss : forall x y,
x > 0 -> puissance x y > 0.

Proof.
induction y;intros.
unfold puissance;simpl.
intuition.
rewrite puiss_step.
generalize (IHy H);intro H0.
case_eq (x*puissance x y);intros.
generalize (mult_zero _ _ H1);intros.
destruct H2;intuition.
intuition.
Qed.

Lemma incr_puis : forall x y n,
x <= y ->
puissance x n <= puissance y n.

Proof.
induction n;intros;simpl.
intuition.
do 2 rewrite puiss_step.
destruct x.
intuition.
destruct y.
inversion H.
apply le_trans with (m := S x*puissance (S y) n).
apply mult_plop_eq2.
intuition.
apply (IHn H).
apply mult_plop_eq.
apply pos_puiss.
intuition.
assumption.
Qed.

Lemma incr_puis2 : forall x n p,
n <= p ->
x > 0 ->
puissance x n <= puissance x p.

Proof.
induction n;intros.
unfold puissance;simpl.
fold (puissance x p).
generalize (pos_puiss).
intuition.
unfold puissance;simpl.
rewrite mult_1_r.
do 2 rewrite puiss_aux.
rewrite mult_1_l.
generalize (IHn (p-1));intro.
assert (puissance x n <= puissance x (p-1)).
apply H1.
intuition.
assumption.
destruct p.
inversion H.
rewrite puiss_step.
apply mult_plop_eq2.
assumption.
apply IHn.
intuition.
assumption.
Qed.