2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department of the University of Bologna, Italy.
7 ||A|| This file is distributed under the terms of the
8 \ / GNU General Public License Version 2
10 V_______________________________________________________________ *)
12 include "basics/relations.ma".
14 (* Definitions **************************************************************)
18 inductive nat : Type[0] ≝
22 interpretation "Natural numbers" 'N = nat.
24 alias num (instance 0) = "natural number".
27 λn. match n with [ O ⇒ O | S p ⇒ p].
29 definition not_zero: nat → Prop ≝
30 λn: nat. match n with [ O ⇒ False | (S p) ⇒ True ].
34 inductive le (n:nat) : nat → Prop ≝
36 | le_S : ∀ m:nat. le n m → le n (S m).
38 interpretation "natural 'less or equal to'" 'leq x y = (le x y).
40 interpretation "natural 'neither less nor equal to'" 'nleq x y = (Not (le x y)).
42 definition lt: nat → nat → Prop ≝ λn,m. S n ≤ m.
44 interpretation "natural 'less than'" 'lt x y = (lt x y).
46 interpretation "natural 'not less than'" 'nless x y = (Not (lt x y)).
48 definition ge: nat → nat → Prop ≝ λn,m.m ≤ n.
50 interpretation "natural 'greater or equal to'" 'geq x y = (ge x y).
52 definition gt: nat → nat → Prop ≝ λn,m.m<n.
54 interpretation "natural 'greater than'" 'gt x y = (gt x y).
56 interpretation "natural 'not greater than'" 'ngtr x y = (Not (gt x y)).
58 (* abstract properties *)
60 definition increasing ≝ λf:nat → nat. ∀n:nat. f n < f (S n).
62 (* arithmetic operations *)
65 match n with [ O ⇒ m | S p ⇒ S (plus p m) ].
67 interpretation "natural plus" 'plus x y = (plus x y).
70 match n with [ O ⇒ 0 | S p ⇒ m + (times p m) ].
72 interpretation "natural times" 'times x y = (times x y).
82 interpretation "natural minus" 'minus x y = (minus x y).
84 (* Generic conclusion ******************************************************)
88 (n=O → P O) → (∀m:nat. n= S m → P (S m)) → P n.
89 #n #P (elim n) /2/ qed.
95 → (∀n,m:nat. R n m → R (S n) (S m))
97 #R #ROn #RSO #RSS #n (elim n) // #n0 #Rn0m #m (cases m) /2/ qed.
99 lemma le_gen: ∀P:nat → Prop.∀n.(∀i. i ≤ n → P i) → P n.
102 (* Equalities ***************************************************************)
104 theorem pred_Sn : ∀n. n = pred (S n).
107 theorem injective_S : injective nat nat S.
110 theorem S_pred: ∀n. 0 < n → S(pred n) = n.
111 #n #posn (cases posn) //
114 theorem plus_O_n: ∀n:nat. n = 0 + n.
117 theorem plus_n_O: ∀n:nat. n = n + 0.
118 #n (elim n) normalize // qed.
120 theorem plus_n_Sm : ∀n,m:nat. S (n+m) = n + S m.
121 #n (elim n) normalize // qed.
123 theorem commutative_plus: commutative ? plus.
124 #n (elim n) normalize // qed.
126 theorem associative_plus : associative nat plus.
127 #n (elim n) normalize // qed.
129 theorem assoc_plus1: ∀a,b,c. c + (b + a) = b + c + a.
132 theorem injective_plus_r: ∀n:nat.injective nat nat (λm.n+m).
133 #n (elim n) normalize /3/ qed.
135 theorem injective_plus_l: ∀n:nat.injective nat nat (λm.m+n).
138 theorem times_Sn_m: ∀n,m:nat. m+n*m = S n*m.
141 theorem times_O_n: ∀n:nat. 0 = 0 * n.
144 theorem times_n_O: ∀n:nat. 0 = n * 0.
147 theorem times_n_Sm : ∀n,m:nat. n+(n*m) = n*(S m).
148 #n (elim n) normalize // qed.
150 theorem commutative_times : commutative nat times.
151 #n (elim n) normalize // qed.
153 theorem distributive_times_plus : distributive nat times plus.
154 #n (elim n) normalize // qed.
156 theorem distributive_times_plus_r :
157 ∀a,b,c:nat. (b+c)*a = b*a + c*a.
160 theorem associative_times: associative nat times.
161 #n (elim n) normalize // qed.
163 lemma times_times: ∀x,y,z. x*(y*z) = y*(x*z).
166 theorem times_n_1 : ∀n:nat. n = n * 1.
169 theorem minus_S_S: ∀n,m:nat.S n - S m = n -m.
172 theorem minus_O_n: ∀n:nat.0=0-n.
175 theorem minus_n_O: ∀n:nat.n=n-0.
178 theorem minus_n_n: ∀n:nat.0=n-n.
181 theorem minus_Sn_n: ∀n:nat. S 0 = (S n)-n.
182 #n (elim n) normalize // qed.
184 theorem eq_minus_S_pred: ∀n,m. n - (S m) = pred(n -m).
185 @nat_elim2 normalize // qed.
187 lemma plus_plus_comm_23: ∀x,y,z. x + y + z = x + z + y.
190 (* Negated equalities *******************************************************)
192 theorem not_eq_S: ∀n,m:nat. n ≠ m → S n ≠ S m.
195 theorem not_eq_O_S : ∀n:nat. 0 ≠ S n.
196 #n @nmk #eqOS (change with (not_zero O)) >eqOS // qed.
198 theorem not_eq_n_Sn: ∀n:nat. n ≠ S n.
201 (* Atomic conclusion *******************************************************)
205 theorem lt_to_not_zero : ∀n,m:nat. n < m → not_zero m.
206 #n #m #Hlt (elim Hlt) // qed.
210 theorem le_S_S: ∀n,m:nat. n ≤ m → S n ≤ S m.
211 #n #m #lenm (elim lenm) /2/ qed.
213 theorem le_O_n : ∀n:nat. 0 ≤ n.
216 theorem le_n_Sn : ∀n:nat. n ≤ S n.
219 theorem transitive_le : transitive nat le.
220 #a #b #c #leab #lebc (elim lebc) /2/
223 theorem le_pred_n : ∀n:nat. pred n ≤ n.
226 theorem monotonic_pred: monotonic ? le pred.
227 #n #m #lenm (elim lenm) /2/ qed.
229 theorem le_S_S_to_le: ∀n,m:nat. S n ≤ S m → n ≤ m.
233 theorem monotonic_le_plus_r:
234 ∀n:nat.monotonic nat le (λm.n + m).
235 #n #a #b (elim n) normalize //
236 #m #H #leab @le_S_S /2/ qed.
238 theorem monotonic_le_plus_l:
239 ∀m:nat.monotonic nat le (λn.n + m).
242 theorem le_plus: ∀n1,n2,m1,m2:nat. n1 ≤ n2 → m1 ≤ m2
244 #n1 #n2 #m1 #m2 #len #lem @(transitive_le ? (n1+m2))
247 theorem le_plus_n :∀n,m:nat. m ≤ n + m.
250 lemma le_plus_a: ∀a,n,m. n ≤ m → n ≤ a + m.
253 lemma le_plus_b: ∀b,n,m. n + b ≤ m → n ≤ m.
256 theorem le_plus_n_r :∀n,m:nat. m ≤ m + n.
259 theorem eq_plus_to_le: ∀n,m,p:nat.n=m+p → m ≤ n.
262 theorem le_plus_to_le: ∀a,n,m. a + n ≤ a + m → n ≤ m.
263 #a (elim a) normalize /3/ qed.
265 theorem le_plus_to_le_r: ∀a,n,m. n + a ≤ m +a → n ≤ m.
268 theorem monotonic_le_times_r:
269 ∀n:nat.monotonic nat le (λm. n * m).
270 #n #x #y #lexy (elim n) normalize//(* lento /2/*)
274 theorem le_times: ∀n1,n2,m1,m2:nat.
275 n1 ≤ n2 → m1 ≤ m2 → n1*m1 ≤ n2*m2.
276 #n1 #n2 #m1 #m2 #len #lem @(transitive_le ? (n1*m2)) /2/
280 theorem lt_times_n: ∀n,m:nat. O < n → m ≤ n*m.
283 theorem le_times_to_le:
284 ∀a,n,m. O < a → a * n ≤ a * m → n ≤ m.
285 #a @nat_elim2 normalize
288 @(transitive_le ? (a*S n)) /2/
294 theorem le_plus_minus_m_m: ∀n,m:nat. n ≤ (n-m)+m.
295 #n (elim n) // #a #Hind #m (cases m) // normalize #n/2/
298 theorem le_plus_to_minus_r: ∀a,b,c. a + b ≤ c → a ≤ c -b.
299 #a #b #c #H @(le_plus_to_le_r … b) /2/
302 lemma lt_to_le: ∀x,y. x < y → x ≤ y.
305 lemma inv_eq_minus_O: ∀x,y. x - y = 0 → x ≤ y.
308 lemma le_x_times_x: ∀x. x ≤ x * x.
314 theorem transitive_lt: transitive nat lt.
315 #a #b #c #ltab #ltbc (elim ltbc) /2/
318 theorem lt_to_le_to_lt: ∀n,m,p:nat. n < m → m ≤ p → n < p.
319 #n #m #p #H #H1 (elim H1) /2/ qed.
321 theorem le_to_lt_to_lt: ∀n,m,p:nat. n ≤ m → m < p → n < p.
322 #n #m #p #H (elim H) /3/ qed.
324 theorem lt_S_to_lt: ∀n,m. S n < m → n < m.
327 theorem ltn_to_ltO: ∀n,m:nat. n < m → 0 < m.
330 theorem lt_O_S : ∀n:nat. O < S n.
333 theorem monotonic_lt_plus_r:
334 ∀n:nat.monotonic nat lt (λm.n+m).
337 theorem monotonic_lt_plus_l:
338 ∀n:nat.monotonic nat lt (λm.m+n).
341 theorem lt_plus: ∀n,m,p,q:nat. n < m → p < q → n + p < m + q.
342 #n #m #p #q #ltnm #ltpq
343 @(transitive_lt ? (n+q))/2/ qed.
345 theorem lt_plus_to_lt_l :∀n,p,q:nat. p+n < q+n → p<q.
348 theorem lt_plus_to_lt_r :∀n,p,q:nat. n+p < n+q → p<q.
351 theorem increasing_to_monotonic: ∀f:nat → nat.
352 increasing f → monotonic nat lt f.
353 #f #incr #n #m #ltnm (elim ltnm) /2/
356 theorem monotonic_lt_times_r:
357 ∀c:nat. O < c → monotonic nat lt (λt.(c*t)).
359 (elim ltnm) normalize
361 |#a #_ #lt1 @(transitive_le … lt1) //
365 theorem monotonic_lt_times_l:
366 ∀c:nat. 0 < c → monotonic nat lt (λt.(t*c)).
370 theorem lt_to_le_to_lt_times:
371 ∀n,m,p,q:nat. n < m → p ≤ q → O < q → n*p < m*q.
372 #n #m #p #q #ltnm #lepq #posq
373 @(le_to_lt_to_lt ? (n*q))
374 [@monotonic_le_times_r //
375 |@monotonic_lt_times_l //
379 theorem lt_times:∀n,m,p,q:nat. n<m → p<q → n*p < m*q.
380 #n #m #p #q #ltnm #ltpq @lt_to_le_to_lt_times/2/
383 theorem lt_plus_to_minus_r: ∀a,b,c. a + b < c → a < c - b.
384 #a #b #c #H @le_plus_to_minus_r //
387 lemma lt_plus_Sn_r: ∀a,x,n. a < a + x + (S n).
390 theorem lt_S_S_to_lt: ∀n,m:nat. S n < S m → n < m.
396 theorem not_le_Sn_O: ∀ n:nat. S n ≰ 0.
397 #n @nmk #Hlen0 @(lt_to_not_zero ?? Hlen0) qed.
399 theorem not_le_to_not_le_S_S: ∀ n,m:nat. n ≰ m → S n ≰ S m.
402 theorem not_le_S_S_to_not_le: ∀ n,m:nat. S n ≰ S m → n ≰ m.
405 theorem not_le_Sn_n: ∀n:nat. S n ≰ n.
408 theorem lt_to_not_le: ∀n,m. n < m → m ≰ n.
409 #n #m #Hltnm (elim Hltnm) /3/ qed.
411 theorem not_le_to_lt: ∀n,m. n ≰ m → m < n.
415 |#m #Hind #HnotleSS @le_S_S @Hind /2/
421 theorem not_lt_to_le: ∀n,m:nat. n ≮ m → m ≤ n.
422 #n #m #H @le_S_S_to_le @not_le_to_lt /2/ qed.
424 theorem le_to_not_lt: ∀n,m:nat. n ≤ m → m ≮ n.
425 #n #m #H @lt_to_not_le /2/ (* /3/ *) qed.
427 (* Compound conclusion ******************************************************)
429 theorem decidable_eq_nat : ∀n,m:nat.decidable (n=m).
430 @nat_elim2 #n [ (cases n) /2/ | /3/ | #m #Hind (cases Hind) /3/]
433 theorem decidable_le: ∀n,m. decidable (n≤m).
434 @nat_elim2 #n /2/ #m * /3/ qed.
436 theorem decidable_lt: ∀n,m. decidable (n < m).
437 #n #m @decidable_le qed.
439 theorem le_to_or_lt_eq: ∀n,m:nat. n ≤ m → n < m ∨ n = m.
440 #n #m #lenm (elim lenm) /3/ qed.
442 theorem increasing_to_le2: ∀f:nat → nat. increasing f →
443 ∀m:nat. f 0 ≤ m → ∃i. f i ≤ m ∧ m < f (S i).
444 #f #incr #m #lem (elim lem)
445 [@(ex_intro ? ? O) /2/
446 |#n #len * #a * #len #ltnr (cases(le_to_or_lt_eq … ltnr)) #H
447 [@(ex_intro ? ? a) % /2/
448 |@(ex_intro ? ? (S a)) % //
453 lemma le_inv_plus_l: ∀x,y,z. x + y ≤ z → x ≤ z - y ∧ y ≤ z.
456 lemma lt_inv_plus_l: ∀x,y,z. x + y < z → x < z ∧ y < z - x.
459 lemma lt_or_ge: ∀m,n. m < n ∨ n ≤ m.
460 #m #n elim (decidable_lt m n) /2/ /3/
463 lemma le_or_ge: ∀m,n. m ≤ n ∨ n ≤ m.
464 #m #n elim (decidable_le m n) /2/ /4/
467 (* More general conclusion **************************************************)
469 theorem nat_ind_plus: ∀R:predicate nat.
470 R 0 → (∀n. R n → R (n + 1)) → ∀n. R n.
473 theorem lt_O_n_elim: ∀n:nat. 0 < n →
474 ∀P:nat → Prop.(∀m:nat.P (S m)) → P n.
475 #n (elim n) // #abs @False_ind /2/ @absurd
478 theorem le_n_O_elim: ∀n:nat. n ≤ O → ∀P: nat →Prop. P O → P n.
479 #n (cases n) // #a #abs @False_ind /2/ qed.
481 theorem le_n_Sm_elim : ∀n,m:nat.n ≤ S m →
482 ∀P:Prop. (S n ≤ S m → P) → (n=S m → P) → P.
483 #n #m #Hle #P (elim Hle) /3/ qed.
485 theorem nat_elim1 : ∀n:nat.∀P:nat → Prop.
486 (∀m.(∀p. p < m → P p) → P m) → P n.
488 cut (∀q:nat. q ≤ n → P q) /2/
490 [#q #HleO (* applica male *)
491 @(le_n_O_elim ? HleO)
492 @H #p #ltpO @False_ind /2/ (* 3 *)
494 @H #a #lta @Hind @le_S_S_to_le /2/
498 lemma f_ind: ∀A. ∀f:A→ℕ. ∀P:predicate A.
499 (∀n. (∀a. f a < n → P a) → ∀a. f a = n → P a) → ∀a. P a.
501 cut (∀n,a. f a = n → P a) /2 width=3/ -a
502 #n @(nat_elim1 … n) -n #n /3 width=3/ (**) (* auto very slow (274s) without #n *)
505 (* More negated equalities **************************************************)
507 theorem lt_to_not_eq : ∀n,m:nat. n < m → n ≠ m.
508 #n #m #H @not_to_not /2/ qed.
510 (* More equalities **********************************************************)
512 theorem le_n_O_to_eq : ∀n:nat. n ≤ 0 → 0=n.
513 #n (cases n) // #a #abs @False_ind /2/ qed.
515 theorem le_to_le_to_eq: ∀n,m. n ≤ m → m ≤ n → n = m.
516 @nat_elim2 /4 by le_n_O_to_eq, monotonic_pred, eq_f, sym_eq/
519 theorem increasing_to_injective: ∀f:nat → nat.
520 increasing f → injective nat nat f.
521 #f #incr #n #m cases(decidable_le n m)
522 [#lenm cases(le_to_or_lt_eq … lenm) //
523 #lenm #eqf @False_ind @(absurd … eqf) @lt_to_not_eq
524 @increasing_to_monotonic //
525 |#nlenm #eqf @False_ind @(absurd … eqf) @sym_not_eq
526 @lt_to_not_eq @increasing_to_monotonic /2/
530 theorem minus_Sn_m: ∀m,n:nat. m ≤ n → S n -m = S (n-m).
531 (* qualcosa da capire qui
532 #n #m #lenm nelim lenm napplyS refl_eq. *)
535 |#n #abs @False_ind /2/
536 |#n #m #Hind #c applyS Hind /2/
541 ∀m,n,p:nat. m ≤ n → (n-m)+p = (n+p)-m.
544 |#n #p #abs @False_ind /2/
549 theorem minus_plus_m_m: ∀n,m:nat.n = (n+m)-m.
552 theorem plus_minus_m_m: ∀n,m:nat.
554 #n #m #lemn @sym_eq /2/ qed.
556 theorem minus_to_plus :∀n,m,p:nat.
557 m ≤ n → n-m = p → n = m+p.
558 #n #m #p #lemn #eqp (applyS plus_minus_m_m) //
561 theorem plus_to_minus :∀n,m,p:nat.n = m+p → n-m = p.
562 #n #m #p #eqp @sym_eq (applyS (minus_plus_m_m p m))
565 theorem minus_pred_pred : ∀n,m:nat. O < n → O < m →
566 pred n - pred m = n - m.
567 #n #m #posn #posm @(lt_O_n_elim n posn) @(lt_O_n_elim m posm) //.
570 theorem plus_minus_commutative: ∀x,y,z. z ≤ y → x + (y - z) = x + y - z.
571 /2 by plus_minus/ qed.
573 (* More atomic conclusion ***************************************************)
577 theorem le_n_fn: ∀f:nat → nat.
578 increasing f → ∀n:nat. n ≤ f n.
579 #f #incr #n (elim n) /2/
582 theorem monotonic_le_minus_l:
583 ∀p,q,n:nat. q ≤ p → q-n ≤ p-n.
585 [#lePO @(le_n_O_elim ? lePO) //
587 |#Hind #n (cases n) // #a #leSS @Hind /2/
591 theorem le_minus_to_plus: ∀n,m,p. n-m ≤ p → n≤ p+m.
592 #n #m #p #lep @transitive_le
593 [|@le_plus_minus_m_m | @monotonic_le_plus_l // ]
596 theorem le_minus_to_plus_r: ∀a,b,c. c ≤ b → a ≤ b - c → a + c ≤ b.
597 #a #b #c #Hlecb #H >(plus_minus_m_m … Hlecb) /2/
600 theorem le_plus_to_minus: ∀n,m,p. n ≤ p+m → n-m ≤ p.
601 #n #m #p #lep /2/ qed.
603 theorem monotonic_le_minus_r:
604 ∀p,q,n:nat. q ≤ p → n-p ≤ n-q.
605 #p #q #n #lepq @le_plus_to_minus
606 @(transitive_le … (le_plus_minus_m_m ? q)) /2/
609 theorem increasing_to_le: ∀f:nat → nat.
610 increasing f → ∀m:nat.∃i.m ≤ f i.
611 #f #incr #m (elim m) /2/#n * #a #lenfa
612 @(ex_intro ?? (S a)) /2/
616 lemma le_plus_compatible: ∀x1,x2,y1,y2. x1 ≤ y1 → x2 ≤ y2 → x1 + x2 ≤ y1 + y2.
617 #x1 #y1 #x2 #y2 #H1 #H2 /2/ @le_plus // /2/ /3 by le_minus_to_plus, monotonic_le_plus_r, transitive_le/ qed.
620 lemma minus_le: ∀x,y. x - y ≤ x.
625 theorem not_eq_to_le_to_lt: ∀n,m. n≠m → n≤m → n<m.
626 #n #m #Hneq #Hle cases (le_to_or_lt_eq ?? Hle) //
627 #Heq @not_le_to_lt /2/ qed-.
629 theorem lt_times_n_to_lt_l:
630 ∀n,p,q:nat. p*n < q*n → p < q.
631 #n #p #q #Hlt (elim (decidable_lt p q)) //
632 #nltpq @False_ind @(absurd ? ? (lt_to_not_le ? ? Hlt))
633 applyS monotonic_le_times_r /2/
636 theorem lt_times_n_to_lt_r:
637 ∀n,p,q:nat. n*p < n*q → p < q.
640 theorem lt_minus_to_plus: ∀a,b,c. a - b < c → a < c + b.
641 #a #b #c #H @not_le_to_lt
642 @(not_to_not … (lt_to_not_le …H)) /2/
645 theorem lt_minus_to_plus_r: ∀a,b,c. a < b - c → a + c < b.
646 #a #b #c #H @not_le_to_lt @(not_to_not … (le_plus_to_minus …))
650 theorem lt_plus_to_minus: ∀n,m,p. m ≤ n → n < p+m → n-m < p.
651 #n #m #p #lenm #H normalize <minus_Sn_m // @le_plus_to_minus //
654 theorem monotonic_lt_minus_l: ∀p,q,n. n ≤ q → q < p → q - n < p - n.
656 @lt_plus_to_minus_r <plus_minus_m_m //
659 (* More compound conclusion *************************************************)
661 lemma discr_minus_x_xy: ∀x,y. x = x - y → x = 0 ∨ y = 0.
662 * /2 width=1/ #x * /2 width=1/ #y normalize #H
663 lapply (minus_le x y) <H -H #H
664 elim (not_le_Sn_n x) #H0 elim (H0 ?) //
667 (* Still more equalities ****************************************************)
669 theorem eq_minus_O: ∀n,m:nat.
671 #n #m #lenm @(le_n_O_elim (n-m)) /2/
674 theorem distributive_times_minus: distributive ? times minus.
676 (cases (decidable_lt b c)) #Hbc
677 [> eq_minus_O [2:/2/] >eq_minus_O //
678 @monotonic_le_times_r /2/
679 |@sym_eq (applyS plus_to_minus) <distributive_times_plus
680 @eq_f (applyS plus_minus_m_m) /2/
683 theorem minus_plus: ∀n,m,p. n-m-p = n -(m+p).
685 cases (decidable_le (m+p) n) #Hlt
686 [@plus_to_minus @plus_to_minus <associative_plus
688 |cut (n ≤ m+p) [@(transitive_le … (le_n_Sn …)) @not_le_to_lt //]
689 #H >eq_minus_O /2/ (* >eq_minus_O // *)
693 theorem minus_minus: ∀n,m,p:nat. p ≤ m → m ≤ n →
696 @sym_eq @plus_to_minus <associative_plus <plus_minus_m_m //
697 <commutative_plus <plus_minus_m_m //
700 lemma minus_minus_comm: ∀a,b,c. a - b - c = a - c - b.
701 /3 by monotonic_le_minus_l, le_to_le_to_eq/ qed.
703 lemma minus_le_minus_minus_comm: ∀b,c,a. c ≤ b → a - (b - c) = a + c - b.
704 #b #c #a #H >(plus_minus_m_m b c) in ⊢ (? ? ?%); //
707 lemma minus_minus_m_m: ∀m,n. n ≤ m → m - (m - n) = n.
710 lemma minus_plus_plus_l: ∀x,y,h. (x + h) - (y + h) = x - y.
713 (* Stilll more atomic conclusion ********************************************)
717 lemma le_fwd_plus_plus_ge: ∀m1,m2. m2 ≤ m1 → ∀n1,n2. m1 + n1 ≤ m2 + n2 → n1 ≤ n2.
718 #m1 #m2 #H #n1 #n2 >commutative_plus
719 #H elim (le_inv_plus_l … H) -H >commutative_plus <minus_le_minus_minus_comm //
720 #H #_ @(transitive_le … H) /2 width=1/
723 (*********************** boolean arithmetics ********************)
725 include "basics/bool.ma".
729 [ O ⇒ match m with [ O ⇒ true | S q ⇒ false]
730 | S p ⇒ match m with [ O ⇒ false | S q ⇒ eqb p q]
733 theorem eqb_elim : ∀ n,m:nat.∀ P:bool → Prop.
734 (n=m → (P true)) → (n ≠ m → (P false)) → (P (eqb n m)).
736 [#n (cases n) normalize /3/
742 theorem eqb_n_n: ∀n. eqb n n = true.
743 #n (elim n) normalize // qed.
745 theorem eqb_true_to_eq: ∀n,m:nat. eqb n m = true → n = m.
746 #n #m @(eqb_elim n m) // #_ #abs @False_ind /2/ qed.
748 theorem eqb_false_to_not_eq: ∀n,m:nat. eqb n m = false → n ≠ m.
749 #n #m @(eqb_elim n m) /2/ qed.
751 theorem eq_to_eqb_true: ∀n,m:nat.n = m → eqb n m = true.
754 theorem not_eq_to_eqb_false: ∀n,m:nat.
755 n ≠ m → eqb n m = false.
756 #n #m #noteq @eqb_elim// #Heq @False_ind /2/ qed.
766 theorem leb_elim: ∀n,m:nat. ∀P:bool → Prop.
767 (n ≤ m → P true) → (n ≰ m → P false) → P (leb n m).
771 |#n #m #Hind #P #Pt #Pf @Hind
772 [#lenm @Pt @le_S_S // |#nlenm @Pf /2/ ]
776 theorem leb_true_to_le:∀n,m.leb n m = true → n ≤ m.
777 #n #m @leb_elim // #_ #abs @False_ind /2/ qed.
779 theorem leb_false_to_not_le:∀n,m.
780 leb n m = false → n ≰ m.
781 #n #m @leb_elim // #_ #abs @False_ind /2/ qed.
783 theorem le_to_leb_true: ∀n,m. n ≤ m → leb n m = true.
784 #n #m @leb_elim // #H #H1 @False_ind /2/ qed.
786 theorem not_le_to_leb_false: ∀n,m. n ≰ m → leb n m = false.
787 #n #m @leb_elim // #H #H1 @False_ind /2/ qed.
789 theorem lt_to_leb_false: ∀n,m. m < n → leb n m = false.
793 definition min: nat →nat →nat ≝
794 λn.λm. if leb n m then n else m.
796 definition max: nat →nat →nat ≝
797 λn.λm. if leb n m then m else n.
799 lemma commutative_min: commutative ? min.
800 #n #m normalize @leb_elim
801 [@leb_elim normalize /2/
802 |#notle >(le_to_leb_true …) // @(transitive_le ? (S m)) /2/
805 lemma le_minr: ∀i,n,m. i ≤ min n m → i ≤ m.
806 #i #n #m normalize @leb_elim normalize /2/ qed.
808 lemma le_minl: ∀i,n,m. i ≤ min n m → i ≤ n.
811 lemma to_min: ∀i,n,m. i ≤ n → i ≤ m → i ≤ min n m.
812 #i #n #m #lein #leim normalize (cases (leb n m))
815 lemma commutative_max: commutative ? max.
816 #n #m normalize @leb_elim
817 [@leb_elim normalize /2/
818 |#notle >(le_to_leb_true …) // @(transitive_le ? (S m)) /2/
821 lemma le_maxl: ∀i,n,m. max n m ≤ i → n ≤ i.
822 #i #n #m normalize @leb_elim normalize /2/ qed.
824 lemma le_maxr: ∀i,n,m. max n m ≤ i → m ≤ i.
827 lemma to_max: ∀i,n,m. n ≤ i → m ≤ i → max n m ≤ i.
828 #i #n #m #leni #lemi normalize (cases (leb n m))