1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/nat/sqrt/".
17 include "nat/times.ma".
18 include "nat/compare.ma".
22 \lambda n.max n (\lambda x.leb (x*x) n).
24 theorem le_sqrt_to_le_times_l : \forall m,n.n \leq sqrt m \to n*n \leq m.
25 intros;apply (trans_le ? (sqrt m * sqrt m))
26 [apply le_times;assumption
27 |apply leb_true_to_le;apply (f_max_true (λx:nat.leb (x*x) m) m);
28 apply (ex_intro ? ? O);split
30 |simplify;reflexivity]]
33 theorem lt_sqrt_to_le_times_l : \forall m,n.n < sqrt m \to n*n < m.
34 intros;apply (trans_le ? (sqrt m * sqrt m))
35 [apply (trans_le ? (S n * S n))
36 [simplify in \vdash (? ? %);apply le_S_S;apply (trans_le ? (n * S n))
37 [apply le_times_r;apply le_S;apply le_n
38 |rewrite > sym_plus;rewrite > plus_n_O in \vdash (? % ?);
39 apply le_plus_r;apply le_O_n]
40 |apply le_times;assumption]
41 |apply le_sqrt_to_le_times_l;apply le_n]
44 theorem le_sqrt_to_le_times_r : \forall m,n.sqrt m < n \to m < n*n.
45 intros;apply not_le_to_lt;intro;
46 apply ((leb_false_to_not_le ? ?
47 (lt_max_to_false (\lambda x.leb (x*x) m) m n H ?))
49 apply (trans_le ? ? ? ? H1);cases n
51 |rewrite > times_n_SO in \vdash (? % ?);rewrite > sym_times;apply le_times
52 [apply le_S_S;apply le_O_n
56 lemma le_sqrt_n_n : \forall n.sqrt n \leq n.
57 intro.unfold sqrt.apply le_max_n.
60 lemma leq_sqrt_n : \forall n. sqrt n * sqrt n \leq n.
61 intro;unfold sqrt;apply leb_true_to_le;apply f_max_true;apply (ex_intro ? ? O);
64 |simplify;reflexivity]
67 alias num (instance 0) = "natural number".
68 lemma le_sqrt_log_n : \forall n,b. 2 < b \to sqrt n * log b n \leq n.
70 apply (trans_le ? ? ? ? (leq_sqrt_n ?));
71 apply le_times_r;unfold sqrt;
73 [apply le_log_n_n;apply lt_to_le;assumption
74 |apply le_to_leb_true;elim (le_to_or_lt_eq ? ? (le_O_n n))
75 [apply (trans_le ? (exp b (log b n)))
78 |simplify in \vdash (? ? %);
79 elim (le_to_or_lt_eq ? ? (le_O_n n1))
80 [elim (le_to_or_lt_eq ? ? H3)
81 [apply (trans_le ? (3*(n1*n1)));
82 [simplify in \vdash (? % ?);rewrite > sym_times in \vdash (? % ?);
83 simplify in \vdash (? % ?);
84 simplify;rewrite > sym_plus;
85 rewrite > plus_n_Sm;rewrite > sym_plus in \vdash (? (? % ?) ?);
86 rewrite > assoc_plus;apply le_plus_r;
89 apply lt_plus;rewrite > times_n_SO in \vdash (? % ?);
90 apply lt_times_r1;assumption;
94 |rewrite < H4;apply le_times
95 [apply lt_to_le;assumption
96 |apply lt_to_le;simplify;rewrite < times_n_SO;assumption]]
97 |rewrite < H3;simplify;rewrite < times_n_SO;do 2 apply lt_to_le;assumption]]
98 |simplify;apply le_exp_log;assumption]
99 |rewrite < H1;simplify;apply le_n]]