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 eq_sqrt: \forall n. sqrt (n*n) = n.
26 unfold sqrt.apply max_spec_to_max.
31 |rewrite > times_n_SO in ⊢ (? % ?).
33 apply le_S_S.apply le_O_n
35 |apply le_to_leb_true.apply le_n
38 apply lt_to_leb_false.
39 apply lt_times;assumption
43 theorem le_sqrt_to_le_times_l : \forall m,n.n \leq sqrt m \to n*n \leq m.
44 intros;apply (trans_le ? (sqrt m * sqrt m))
45 [apply le_times;assumption
46 |apply leb_true_to_le;apply (f_max_true (λx:nat.leb (x*x) m) m);
47 apply (ex_intro ? ? O);split
49 |simplify;reflexivity]]
52 theorem lt_sqrt_to_le_times_l : \forall m,n.n < sqrt m \to n*n < m.
53 intros;apply (trans_le ? (sqrt m * sqrt m))
54 [apply (trans_le ? (S n * S n))
55 [simplify in \vdash (? ? %);apply le_S_S;apply (trans_le ? (n * S n))
56 [apply le_times_r;apply le_S;apply le_n
57 |rewrite > sym_plus;rewrite > plus_n_O in \vdash (? % ?);
58 apply le_plus_r;apply le_O_n]
59 |apply le_times;assumption]
60 |apply le_sqrt_to_le_times_l;apply le_n]
63 theorem le_sqrt_to_le_times_r : \forall m,n.sqrt m < n \to m < n*n.
64 intros;apply not_le_to_lt;intro;
65 apply ((leb_false_to_not_le ? ?
66 (lt_max_to_false (\lambda x.leb (x*x) m) m n H ?))
68 apply (trans_le ? ? ? ? H1);cases n
70 |rewrite > times_n_SO in \vdash (? % ?);rewrite > sym_times;apply le_times
71 [apply le_S_S;apply le_O_n
75 lemma le_sqrt_n_n : \forall n.sqrt n \leq n.
76 intro.unfold sqrt.apply le_max_n.
79 lemma leq_sqrt_n : \forall n. sqrt n * sqrt n \leq n.
80 intro;unfold sqrt;apply leb_true_to_le;apply f_max_true;apply (ex_intro ? ? O);
83 |simplify;reflexivity]
86 alias num (instance 0) = "natural number".
88 lemma lt_sqrt_n : \forall n.1 < n \to sqrt n < n.
90 elim (le_to_or_lt_eq ? ? (le_sqrt_n_n n))
93 apply (le_to_not_lt ? ? (leq_sqrt_n n)).
95 rewrite > times_n_SO in ⊢ (? % ?).
97 [apply lt_to_le.assumption
103 lemma lt_sqrt: \forall n.n < (exp (S (sqrt n)) 2).
108 [simplify.apply lt_to_le.apply lt_to_le.apply le_n
110 apply leb_false_to_not_le.
112 apply (lt_max_to_false (\lambda x.(leb (x*x) (S(S n2)))) (S(S n2)))
115 apply le_S_S.apply lt_O_S.
121 lemma le_sqrt_n1: \forall n. n - 2*sqrt n \le exp (sqrt n) 2.
123 apply le_plus_to_minus.
125 cut (S ((sqrt n)\sup 2+2*sqrt n) = (exp (S(sqrt n)) 2))
126 [rewrite > Hcut.apply lt_sqrt
127 |rewrite > exp_SSO.rewrite > exp_SSO.
129 rewrite < times_n_Sm.
131 rewrite < assoc_plus in ⊢ (? ? ? %).
137 (* falso per n=2, m=7 e n=3, m =15 *)
138 lemma le_sqrt_nl: \forall n,m. 3 < n \to
139 m*(pred m)*n \le exp (sqrt ((exp m 2)*n)) 2.
141 rewrite > minus_n_O in ⊢ (? (? (? ? (? %)) ?) ?).
142 rewrite < eq_minus_S_pred.
143 rewrite > distr_times_minus.
144 rewrite < times_n_SO.
146 rewrite > distr_times_minus.
148 apply (trans_le ? (m*m*n -2*sqrt(m*m*n)))
149 [apply monotonic_le_minus_r.
150 apply (le_exp_to_le1 ? ? 2)
152 |rewrite < times_exp.
153 apply (trans_le ? ((exp 2 2)*(m*m*n)))
159 rewrite < assoc_times.
160 rewrite < sym_times in ⊢ (? (? % ?) ?).
161 rewrite > assoc_times.
164 rewrite > exp_SSO in ⊢ (? ? %).
174 lemma le_sqrt_log_n : \forall n,b. 2 < b \to sqrt n * log b n \leq n.
176 apply (trans_le ? ? ? ? (leq_sqrt_n ?));
177 apply le_times_r;unfold sqrt;
179 [apply le_log_n_n;apply lt_to_le;assumption
180 |apply le_to_leb_true;elim (le_to_or_lt_eq ? ? (le_O_n n))
181 [apply (trans_le ? (exp b (log b n)))
184 |simplify in \vdash (? ? %);
185 elim (le_to_or_lt_eq ? ? (le_O_n n1))
186 [elim (le_to_or_lt_eq ? ? H3)
187 [apply (trans_le ? (3*(n1*n1)));
188 [simplify in \vdash (? % ?);rewrite > sym_times in \vdash (? % ?);
189 simplify in \vdash (? % ?);
190 simplify;rewrite > sym_plus;
191 rewrite > plus_n_Sm;rewrite > sym_plus in \vdash (? (? % ?) ?);
192 rewrite > assoc_plus;apply le_plus_r;
195 apply lt_plus;rewrite > times_n_SO in \vdash (? % ?);
196 apply lt_times_r1;assumption;
200 |rewrite < H4;apply le_times
201 [apply lt_to_le;assumption
202 |apply lt_to_le;simplify;rewrite < times_n_SO;assumption]]
203 |rewrite < H3;simplify;rewrite < times_n_SO;do 2 apply lt_to_le;assumption]]
204 |simplify;apply le_exp_log;assumption]
205 |rewrite < H1;simplify;apply le_n]]