src/HOL/Hyperreal/HTranscendental.thy
author paulson
Thu Jul 01 12:29:53 2004 +0200 (2004-07-01)
changeset 15013 34264f5e4691
parent 14641 79b7bd936264
child 15077 89840837108e
permissions -rw-r--r--
new treatment of binary numerals
     1 (*  Title       : HTranscendental.thy
     2     Author      : Jacques D. Fleuriot
     3     Copyright   : 2001 University of Edinburgh
     4 
     5 Converted to Isar and polished by lcp
     6 *)
     7 
     8 header{*Nonstandard Extensions of Transcendental Functions*}
     9 
    10 theory HTranscendental = Transcendental + Integration:
    11 
    12 text{*really belongs in Transcendental*}
    13 lemma sqrt_divide_self_eq:
    14   assumes nneg: "0 \<le> x"
    15   shows "sqrt x / x = inverse (sqrt x)"
    16 proof cases
    17   assume "x=0" thus ?thesis by simp
    18 next
    19   assume nz: "x\<noteq>0" 
    20   hence pos: "0<x" using nneg by arith
    21   show ?thesis
    22   proof (rule right_inverse_eq [THEN iffD1, THEN sym]) 
    23     show "sqrt x / x \<noteq> 0" by (simp add: divide_inverse nneg nz) 
    24     show "inverse (sqrt x) / (sqrt x / x) = 1"
    25       by (simp add: divide_inverse mult_assoc [symmetric] 
    26                   power2_eq_square [symmetric] real_inv_sqrt_pow2 pos nz) 
    27   qed
    28 qed
    29 
    30 
    31 constdefs
    32 
    33   exphr :: "real => hypreal"
    34     --{*define exponential function using standard part *}
    35     "exphr x ==  st(sumhr (0, whn, %n. inverse(real (fact n)) * (x ^ n)))" 
    36 
    37   sinhr :: "real => hypreal"
    38     "sinhr x == st(sumhr (0, whn, %n. (if even(n) then 0 else
    39              ((-1) ^ ((n - 1) div 2))/(real (fact n))) * (x ^ n)))"
    40   
    41   coshr :: "real => hypreal"
    42     "coshr x == st(sumhr (0, whn, %n. (if even(n) then
    43             ((-1) ^ (n div 2))/(real (fact n)) else 0) * x ^ n))"
    44 
    45 
    46 subsection{*Nonstandard Extension of Square Root Function*}
    47 
    48 lemma STAR_sqrt_zero [simp]: "( *f* sqrt) 0 = 0"
    49 by (simp add: starfun hypreal_zero_num)
    50 
    51 lemma STAR_sqrt_one [simp]: "( *f* sqrt) 1 = 1"
    52 by (simp add: starfun hypreal_one_num)
    53 
    54 lemma hypreal_sqrt_pow2_iff: "(( *f* sqrt)(x) ^ 2 = x) = (0 \<le> x)"
    55 apply (cases x)
    56 apply (auto simp add: hypreal_le hypreal_zero_num starfun hrealpow 
    57                       real_sqrt_pow2_iff 
    58             simp del: hpowr_Suc realpow_Suc)
    59 done
    60 
    61 lemma hypreal_sqrt_gt_zero_pow2: "0 < x ==> ( *f* sqrt) (x) ^ 2 = x"
    62 apply (cases x)
    63 apply (auto intro: FreeUltrafilterNat_subset real_sqrt_gt_zero_pow2
    64             simp add: hypreal_less starfun hrealpow hypreal_zero_num 
    65             simp del: hpowr_Suc realpow_Suc)
    66 done
    67 
    68 lemma hypreal_sqrt_pow2_gt_zero: "0 < x ==> 0 < ( *f* sqrt) (x) ^ 2"
    69 by (frule hypreal_sqrt_gt_zero_pow2, auto)
    70 
    71 lemma hypreal_sqrt_not_zero: "0 < x ==> ( *f* sqrt) (x) \<noteq> 0"
    72 apply (frule hypreal_sqrt_pow2_gt_zero)
    73 apply (auto simp add: numeral_2_eq_2)
    74 done
    75 
    76 lemma hypreal_inverse_sqrt_pow2:
    77      "0 < x ==> inverse (( *f* sqrt)(x)) ^ 2 = inverse x"
    78 apply (cut_tac n1 = 2 and a1 = "( *f* sqrt) x" in power_inverse [symmetric])
    79 apply (auto dest: hypreal_sqrt_gt_zero_pow2)
    80 done
    81 
    82 lemma hypreal_sqrt_mult_distrib: 
    83     "[|0 < x; 0 <y |] ==> ( *f* sqrt)(x*y) =  ( *f* sqrt)(x) * ( *f* sqrt)(y)"
    84 apply (cases x, cases y)
    85 apply (simp add: hypreal_zero_def starfun hypreal_mult hypreal_less hypreal_zero_num, ultra)
    86 apply (auto intro: real_sqrt_mult_distrib) 
    87 done
    88 
    89 lemma hypreal_sqrt_mult_distrib2:
    90      "[|0\<le>x; 0\<le>y |] ==>  
    91      ( *f* sqrt)(x*y) =  ( *f* sqrt)(x) * ( *f* sqrt)(y)"
    92 by (auto intro: hypreal_sqrt_mult_distrib simp add: order_le_less)
    93 
    94 lemma hypreal_sqrt_approx_zero [simp]:
    95      "0 < x ==> (( *f* sqrt)(x) @= 0) = (x @= 0)"
    96 apply (auto simp add: mem_infmal_iff [symmetric])
    97 apply (rule hypreal_sqrt_gt_zero_pow2 [THEN subst])
    98 apply (auto intro: Infinitesimal_mult 
    99             dest!: hypreal_sqrt_gt_zero_pow2 [THEN ssubst] 
   100             simp add: numeral_2_eq_2)
   101 done
   102 
   103 lemma hypreal_sqrt_approx_zero2 [simp]:
   104      "0 \<le> x ==> (( *f* sqrt)(x) @= 0) = (x @= 0)"
   105 by (auto simp add: order_le_less)
   106 
   107 lemma hypreal_sqrt_sum_squares [simp]:
   108      "(( *f* sqrt)(x*x + y*y + z*z) @= 0) = (x*x + y*y + z*z @= 0)"
   109 apply (rule hypreal_sqrt_approx_zero2)
   110 apply (rule hypreal_le_add_order)+
   111 apply (auto simp add: zero_le_square)
   112 done
   113 
   114 lemma hypreal_sqrt_sum_squares2 [simp]:
   115      "(( *f* sqrt)(x*x + y*y) @= 0) = (x*x + y*y @= 0)"
   116 apply (rule hypreal_sqrt_approx_zero2)
   117 apply (rule hypreal_le_add_order)
   118 apply (auto simp add: zero_le_square)
   119 done
   120 
   121 lemma hypreal_sqrt_gt_zero: "0 < x ==> 0 < ( *f* sqrt)(x)"
   122 apply (cases x)
   123 apply (auto simp add: starfun hypreal_zero_def hypreal_less hypreal_zero_num, ultra)
   124 apply (auto intro: real_sqrt_gt_zero)
   125 done
   126 
   127 lemma hypreal_sqrt_ge_zero: "0 \<le> x ==> 0 \<le> ( *f* sqrt)(x)"
   128 by (auto intro: hypreal_sqrt_gt_zero simp add: order_le_less)
   129 
   130 lemma hypreal_sqrt_hrabs [simp]: "( *f* sqrt)(x ^ 2) = abs(x)"
   131 apply (cases x)
   132 apply (simp add: starfun hypreal_hrabs hypreal_mult numeral_2_eq_2)
   133 done
   134 
   135 lemma hypreal_sqrt_hrabs2 [simp]: "( *f* sqrt)(x*x) = abs(x)"
   136 apply (rule hrealpow_two [THEN subst])
   137 apply (rule numeral_2_eq_2 [THEN subst])
   138 apply (rule hypreal_sqrt_hrabs)
   139 done
   140 
   141 lemma hypreal_sqrt_hyperpow_hrabs [simp]:
   142      "( *f* sqrt)(x pow (hypnat_of_nat 2)) = abs(x)"
   143 apply (cases x)
   144 apply (simp add: starfun hypreal_hrabs hypnat_of_nat_eq hyperpow)
   145 done
   146 
   147 lemma star_sqrt_HFinite: "\<lbrakk>x \<in> HFinite; 0 \<le> x\<rbrakk> \<Longrightarrow> ( *f* sqrt) x \<in> HFinite"
   148 apply (rule HFinite_square_iff [THEN iffD1])
   149 apply (simp only: hypreal_sqrt_mult_distrib2 [symmetric], simp) 
   150 done
   151 
   152 lemma st_hypreal_sqrt:
   153      "[| x \<in> HFinite; 0 \<le> x |] ==> st(( *f* sqrt) x) = ( *f* sqrt)(st x)"
   154 apply (rule power_inject_base [where n=1])
   155 apply (auto intro!: st_zero_le hypreal_sqrt_ge_zero)
   156 apply (rule st_mult [THEN subst])
   157 apply (rule_tac [3] hypreal_sqrt_mult_distrib2 [THEN subst])
   158 apply (rule_tac [5] hypreal_sqrt_mult_distrib2 [THEN subst])
   159 apply (auto simp add: st_hrabs st_zero_le star_sqrt_HFinite)
   160 done
   161 
   162 lemma hypreal_sqrt_sum_squares_ge1 [simp]: "x \<le> ( *f* sqrt)(x ^ 2 + y ^ 2)"
   163 apply (cases x, cases y)
   164 apply (simp add: starfun hypreal_add hrealpow hypreal_le 
   165             del: hpowr_Suc realpow_Suc)
   166 done
   167 
   168 lemma HFinite_hypreal_sqrt:
   169      "[| 0 \<le> x; x \<in> HFinite |] ==> ( *f* sqrt) x \<in> HFinite"
   170 apply (auto simp add: order_le_less)
   171 apply (rule HFinite_square_iff [THEN iffD1])
   172 apply (drule hypreal_sqrt_gt_zero_pow2)
   173 apply (simp add: numeral_2_eq_2)
   174 done
   175 
   176 lemma HFinite_hypreal_sqrt_imp_HFinite:
   177      "[| 0 \<le> x; ( *f* sqrt) x \<in> HFinite |] ==> x \<in> HFinite"
   178 apply (auto simp add: order_le_less)
   179 apply (drule HFinite_square_iff [THEN iffD2])
   180 apply (drule hypreal_sqrt_gt_zero_pow2)
   181 apply (simp add: numeral_2_eq_2 del: HFinite_square_iff)
   182 done
   183 
   184 lemma HFinite_hypreal_sqrt_iff [simp]:
   185      "0 \<le> x ==> (( *f* sqrt) x \<in> HFinite) = (x \<in> HFinite)"
   186 by (blast intro: HFinite_hypreal_sqrt HFinite_hypreal_sqrt_imp_HFinite)
   187 
   188 lemma HFinite_sqrt_sum_squares [simp]:
   189      "(( *f* sqrt)(x*x + y*y) \<in> HFinite) = (x*x + y*y \<in> HFinite)"
   190 apply (rule HFinite_hypreal_sqrt_iff)
   191 apply (rule hypreal_le_add_order)
   192 apply (auto simp add: zero_le_square)
   193 done
   194 
   195 lemma Infinitesimal_hypreal_sqrt:
   196      "[| 0 \<le> x; x \<in> Infinitesimal |] ==> ( *f* sqrt) x \<in> Infinitesimal"
   197 apply (auto simp add: order_le_less)
   198 apply (rule Infinitesimal_square_iff [THEN iffD2])
   199 apply (drule hypreal_sqrt_gt_zero_pow2)
   200 apply (simp add: numeral_2_eq_2)
   201 done
   202 
   203 lemma Infinitesimal_hypreal_sqrt_imp_Infinitesimal:
   204      "[| 0 \<le> x; ( *f* sqrt) x \<in> Infinitesimal |] ==> x \<in> Infinitesimal"
   205 apply (auto simp add: order_le_less)
   206 apply (drule Infinitesimal_square_iff [THEN iffD1])
   207 apply (drule hypreal_sqrt_gt_zero_pow2)
   208 apply (simp add: numeral_2_eq_2 del: Infinitesimal_square_iff [symmetric])
   209 done
   210 
   211 lemma Infinitesimal_hypreal_sqrt_iff [simp]:
   212      "0 \<le> x ==> (( *f* sqrt) x \<in> Infinitesimal) = (x \<in> Infinitesimal)"
   213 by (blast intro: Infinitesimal_hypreal_sqrt_imp_Infinitesimal Infinitesimal_hypreal_sqrt)
   214 
   215 lemma Infinitesimal_sqrt_sum_squares [simp]:
   216      "(( *f* sqrt)(x*x + y*y) \<in> Infinitesimal) = (x*x + y*y \<in> Infinitesimal)"
   217 apply (rule Infinitesimal_hypreal_sqrt_iff)
   218 apply (rule hypreal_le_add_order)
   219 apply (auto simp add: zero_le_square)
   220 done
   221 
   222 lemma HInfinite_hypreal_sqrt:
   223      "[| 0 \<le> x; x \<in> HInfinite |] ==> ( *f* sqrt) x \<in> HInfinite"
   224 apply (auto simp add: order_le_less)
   225 apply (rule HInfinite_square_iff [THEN iffD1])
   226 apply (drule hypreal_sqrt_gt_zero_pow2)
   227 apply (simp add: numeral_2_eq_2)
   228 done
   229 
   230 lemma HInfinite_hypreal_sqrt_imp_HInfinite:
   231      "[| 0 \<le> x; ( *f* sqrt) x \<in> HInfinite |] ==> x \<in> HInfinite"
   232 apply (auto simp add: order_le_less)
   233 apply (drule HInfinite_square_iff [THEN iffD2])
   234 apply (drule hypreal_sqrt_gt_zero_pow2)
   235 apply (simp add: numeral_2_eq_2 del: HInfinite_square_iff)
   236 done
   237 
   238 lemma HInfinite_hypreal_sqrt_iff [simp]:
   239      "0 \<le> x ==> (( *f* sqrt) x \<in> HInfinite) = (x \<in> HInfinite)"
   240 by (blast intro: HInfinite_hypreal_sqrt HInfinite_hypreal_sqrt_imp_HInfinite)
   241 
   242 lemma HInfinite_sqrt_sum_squares [simp]:
   243      "(( *f* sqrt)(x*x + y*y) \<in> HInfinite) = (x*x + y*y \<in> HInfinite)"
   244 apply (rule HInfinite_hypreal_sqrt_iff)
   245 apply (rule hypreal_le_add_order)
   246 apply (auto simp add: zero_le_square)
   247 done
   248 
   249 lemma HFinite_exp [simp]:
   250      "sumhr (0, whn, %n. inverse (real (fact n)) * x ^ n) \<in> HFinite"
   251 by (auto intro!: NSBseq_HFinite_hypreal NSconvergent_NSBseq 
   252          simp add: starfunNat_sumr [symmetric] starfunNat hypnat_omega_def
   253                    convergent_NSconvergent_iff [symmetric] 
   254                    summable_convergent_sumr_iff [symmetric] summable_exp)
   255 
   256 lemma exphr_zero [simp]: "exphr 0 = 1"
   257 apply (simp add: exphr_def sumhr_split_add
   258                    [OF hypnat_one_less_hypnat_omega, symmetric]) 
   259 apply (simp add: sumhr hypnat_zero_def starfunNat hypnat_one_def hypnat_add
   260                  hypnat_omega_def hypreal_add 
   261             del: hypnat_add_zero_left)
   262 apply (simp add: hypreal_one_num [symmetric])
   263 done
   264 
   265 lemma coshr_zero [simp]: "coshr 0 = 1"
   266 apply (simp add: coshr_def sumhr_split_add
   267                    [OF hypnat_one_less_hypnat_omega, symmetric]) 
   268 apply (simp add: sumhr hypnat_zero_def starfunNat hypnat_one_def 
   269          hypnat_add hypnat_omega_def st_add [symmetric] 
   270          hypreal_one_def [symmetric] hypreal_zero_def [symmetric]
   271        del: hypnat_add_zero_left)
   272 done
   273 
   274 lemma STAR_exp_zero_approx_one [simp]: "( *f* exp) 0 @= 1"
   275 by (simp add: hypreal_zero_def hypreal_one_def starfun hypreal_one_num)
   276 
   277 lemma STAR_exp_Infinitesimal: "x \<in> Infinitesimal ==> ( *f* exp) x @= 1"
   278 apply (case_tac "x = 0")
   279 apply (cut_tac [2] x = 0 in DERIV_exp)
   280 apply (auto simp add: NSDERIV_DERIV_iff [symmetric] nsderiv_def)
   281 apply (drule_tac x = x in bspec, auto)
   282 apply (drule_tac c = x in approx_mult1)
   283 apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD] 
   284             simp add: mult_assoc)
   285 apply (rule approx_add_right_cancel [where d="-1"])
   286 apply (rule approx_sym [THEN [2] approx_trans2])
   287 apply (auto simp add: mem_infmal_iff)
   288 done
   289 
   290 lemma STAR_exp_epsilon [simp]: "( *f* exp) epsilon @= 1"
   291 by (auto intro: STAR_exp_Infinitesimal)
   292 
   293 lemma STAR_exp_add: "( *f* exp)(x + y) = ( *f* exp) x * ( *f* exp) y"
   294 apply (cases x, cases y)
   295 apply (simp add: starfun hypreal_add hypreal_mult exp_add)
   296 done
   297 
   298 lemma exphr_hypreal_of_real_exp_eq: "exphr x = hypreal_of_real (exp x)"
   299 apply (simp add: exphr_def)
   300 apply (rule st_hypreal_of_real [THEN subst])
   301 apply (rule approx_st_eq, auto)
   302 apply (rule approx_minus_iff [THEN iffD2])
   303 apply (auto simp add: mem_infmal_iff [symmetric] hypreal_of_real_def hypnat_zero_def hypnat_omega_def sumhr hypreal_minus hypreal_add)
   304 apply (rule NSLIMSEQ_zero_Infinitesimal_hypreal)
   305 apply (insert exp_converges [of x]) 
   306 apply (simp add: sums_def) 
   307 apply (drule LIMSEQ_const [THEN [2] LIMSEQ_add, where b = "- exp x"])
   308 apply (simp add: LIMSEQ_NSLIMSEQ_iff)
   309 done
   310 
   311 lemma starfun_exp_ge_add_one_self [simp]: "0 \<le> x ==> (1 + x) \<le> ( *f* exp) x"
   312 apply (cases x)
   313 apply (simp add: starfun hypreal_add hypreal_le hypreal_zero_num hypreal_one_num, ultra)
   314 done
   315 
   316 (* exp (oo) is infinite *)
   317 lemma starfun_exp_HInfinite:
   318      "[| x \<in> HInfinite; 0 \<le> x |] ==> ( *f* exp) x \<in> HInfinite"
   319 apply (frule starfun_exp_ge_add_one_self)
   320 apply (rule HInfinite_ge_HInfinite, assumption)
   321 apply (rule order_trans [of _ "1+x"], auto) 
   322 done
   323 
   324 lemma starfun_exp_minus: "( *f* exp) (-x) = inverse(( *f* exp) x)"
   325 apply (cases x)
   326 apply (simp add: starfun hypreal_inverse hypreal_minus exp_minus)
   327 done
   328 
   329 (* exp (-oo) is infinitesimal *)
   330 lemma starfun_exp_Infinitesimal:
   331      "[| x \<in> HInfinite; x \<le> 0 |] ==> ( *f* exp) x \<in> Infinitesimal"
   332 apply (subgoal_tac "\<exists>y. x = - y")
   333 apply (rule_tac [2] x = "- x" in exI)
   334 apply (auto intro!: HInfinite_inverse_Infinitesimal starfun_exp_HInfinite
   335             simp add: starfun_exp_minus HInfinite_minus_iff)
   336 done
   337 
   338 lemma starfun_exp_gt_one [simp]: "0 < x ==> 1 < ( *f* exp) x"
   339 apply (cases x)
   340 apply (simp add: starfun hypreal_one_num hypreal_zero_num hypreal_less, ultra)
   341 done
   342 
   343 (* needs derivative of inverse function
   344    TRY a NS one today!!!
   345 
   346 Goal "x @= 1 ==> ( *f* ln) x @= 1"
   347 by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   348 by (auto_tac (claset(),simpset() addsimps [hypreal_one_def]));
   349 
   350 
   351 Goalw [nsderiv_def] "0r < x ==> NSDERIV ln x :> inverse x";
   352 
   353 *)
   354 
   355 
   356 lemma starfun_ln_exp [simp]: "( *f* ln) (( *f* exp) x) = x"
   357 apply (cases x)
   358 apply (simp add: starfun)
   359 done
   360 
   361 lemma starfun_exp_ln_iff [simp]: "(( *f* exp)(( *f* ln) x) = x) = (0 < x)"
   362 apply (cases x)
   363 apply (simp add: starfun hypreal_zero_num hypreal_less)
   364 done
   365 
   366 lemma starfun_exp_ln_eq: "( *f* exp) u = x ==> ( *f* ln) x = u"
   367 by (auto simp add: starfun)
   368 
   369 lemma starfun_ln_less_self [simp]: "0 < x ==> ( *f* ln) x < x"
   370 apply (cases x)
   371 apply (simp add: starfun hypreal_zero_num hypreal_less, ultra)
   372 done
   373 
   374 lemma starfun_ln_ge_zero [simp]: "1 \<le> x ==> 0 \<le> ( *f* ln) x"
   375 apply (cases x)
   376 apply (simp add: starfun hypreal_zero_num hypreal_le hypreal_one_num, ultra)
   377 done
   378 
   379 lemma starfun_ln_gt_zero [simp]: "1 < x ==> 0 < ( *f* ln) x"
   380 apply (cases x)
   381 apply (simp add: starfun hypreal_zero_num hypreal_less hypreal_one_num, ultra)
   382 done
   383 
   384 lemma starfun_ln_not_eq_zero [simp]: "[| 0 < x; x \<noteq> 1 |] ==> ( *f* ln) x \<noteq> 0"
   385 apply (cases x)
   386 apply (auto simp add: starfun hypreal_zero_num hypreal_less hypreal_one_num, ultra)
   387 apply (auto dest: ln_not_eq_zero) 
   388 done
   389 
   390 lemma starfun_ln_HFinite: "[| x \<in> HFinite; 1 \<le> x |] ==> ( *f* ln) x \<in> HFinite"
   391 apply (rule HFinite_bounded)
   392 apply (rule_tac [2] order_less_imp_le)
   393 apply (rule_tac [2] starfun_ln_less_self)
   394 apply (rule_tac [2] order_less_le_trans, auto)
   395 done
   396 
   397 lemma starfun_ln_inverse: "0 < x ==> ( *f* ln) (inverse x) = -( *f* ln) x"
   398 apply (cases x)
   399 apply (simp add: starfun hypreal_zero_num hypreal_minus hypreal_inverse hypreal_less, ultra)
   400 apply (simp add: ln_inverse)
   401 done
   402 
   403 lemma starfun_exp_HFinite: "x \<in> HFinite ==> ( *f* exp) x \<in> HFinite"
   404 apply (cases x)
   405 apply (auto simp add: starfun HFinite_FreeUltrafilterNat_iff)
   406 apply (rule bexI, rule_tac [2] lemma_hyprel_refl, auto)
   407 apply (rule_tac x = "exp u" in exI)
   408 apply (ultra, arith)
   409 done
   410 
   411 lemma starfun_exp_add_HFinite_Infinitesimal_approx:
   412      "[|x \<in> Infinitesimal; z \<in> HFinite |] ==> ( *f* exp) (z + x) @= ( *f* exp) z"
   413 apply (simp add: STAR_exp_add)
   414 apply (frule STAR_exp_Infinitesimal)
   415 apply (drule approx_mult2)
   416 apply (auto intro: starfun_exp_HFinite)
   417 done
   418 
   419 (* using previous result to get to result *)
   420 lemma starfun_ln_HInfinite:
   421      "[| x \<in> HInfinite; 0 < x |] ==> ( *f* ln) x \<in> HInfinite"
   422 apply (rule ccontr, drule HFinite_HInfinite_iff [THEN iffD2])
   423 apply (drule starfun_exp_HFinite)
   424 apply (simp add: starfun_exp_ln_iff [THEN iffD2] HFinite_HInfinite_iff)
   425 done
   426 
   427 lemma starfun_exp_HInfinite_Infinitesimal_disj:
   428  "x \<in> HInfinite ==> ( *f* exp) x \<in> HInfinite | ( *f* exp) x \<in> Infinitesimal"
   429 apply (insert linorder_linear [of x 0]) 
   430 apply (auto intro: starfun_exp_HInfinite starfun_exp_Infinitesimal)
   431 done
   432 
   433 (* check out this proof!!! *)
   434 lemma starfun_ln_HFinite_not_Infinitesimal:
   435      "[| x \<in> HFinite - Infinitesimal; 0 < x |] ==> ( *f* ln) x \<in> HFinite"
   436 apply (rule ccontr, drule HInfinite_HFinite_iff [THEN iffD2])
   437 apply (drule starfun_exp_HInfinite_Infinitesimal_disj)
   438 apply (simp add: starfun_exp_ln_iff [symmetric] HInfinite_HFinite_iff
   439             del: starfun_exp_ln_iff)
   440 done
   441 
   442 (* we do proof by considering ln of 1/x *)
   443 lemma starfun_ln_Infinitesimal_HInfinite:
   444      "[| x \<in> Infinitesimal; 0 < x |] ==> ( *f* ln) x \<in> HInfinite"
   445 apply (drule Infinitesimal_inverse_HInfinite)
   446 apply (frule positive_imp_inverse_positive)
   447 apply (drule_tac [2] starfun_ln_HInfinite)
   448 apply (auto simp add: starfun_ln_inverse HInfinite_minus_iff)
   449 done
   450 
   451 lemma starfun_ln_less_zero: "[| 0 < x; x < 1 |] ==> ( *f* ln) x < 0"
   452 apply (cases x)
   453 apply (simp add: hypreal_zero_num hypreal_one_num hypreal_less starfun, ultra)
   454 apply (auto intro: ln_less_zero) 
   455 done
   456 
   457 lemma starfun_ln_Infinitesimal_less_zero:
   458      "[| x \<in> Infinitesimal; 0 < x |] ==> ( *f* ln) x < 0"
   459 apply (auto intro!: starfun_ln_less_zero simp add: Infinitesimal_def)
   460 apply (drule bspec [where x = 1])
   461 apply (auto simp add: abs_if)
   462 done
   463 
   464 lemma starfun_ln_HInfinite_gt_zero:
   465      "[| x \<in> HInfinite; 0 < x |] ==> 0 < ( *f* ln) x"
   466 apply (auto intro!: starfun_ln_gt_zero simp add: HInfinite_def)
   467 apply (drule bspec [where x = 1])
   468 apply (auto simp add: abs_if)
   469 done
   470 
   471 (*
   472 Goalw [NSLIM_def] "(%h. ((x powr h) - 1) / h) -- 0 --NS> ln x"
   473 *)
   474 
   475 lemma HFinite_sin [simp]:
   476      "sumhr (0, whn, %n. (if even(n) then 0 else  
   477               ((- 1) ^ ((n - 1) div 2))/(real (fact n))) * x ^ n)  
   478               \<in> HFinite"
   479 apply (auto intro!: NSBseq_HFinite_hypreal NSconvergent_NSBseq 
   480             simp add: starfunNat_sumr [symmetric] starfunNat hypnat_omega_def
   481                       convergent_NSconvergent_iff [symmetric] 
   482                       summable_convergent_sumr_iff [symmetric])
   483 apply (simp only: One_nat_def summable_sin)
   484 done
   485 
   486 lemma STAR_sin_zero [simp]: "( *f* sin) 0 = 0"
   487 by (simp add: starfun hypreal_zero_num)
   488 
   489 lemma STAR_sin_Infinitesimal [simp]: "x \<in> Infinitesimal ==> ( *f* sin) x @= x"
   490 apply (case_tac "x = 0")
   491 apply (cut_tac [2] x = 0 in DERIV_sin)
   492 apply (auto simp add: NSDERIV_DERIV_iff [symmetric] nsderiv_def hypreal_of_real_zero)
   493 apply (drule bspec [where x = x], auto)
   494 apply (drule approx_mult1 [where c = x])
   495 apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD]
   496            simp add: mult_assoc)
   497 done
   498 
   499 lemma HFinite_cos [simp]:
   500      "sumhr (0, whn, %n. (if even(n) then  
   501             ((- 1) ^ (n div 2))/(real (fact n)) else  
   502             0) * x ^ n) \<in> HFinite"
   503 by (auto intro!: NSBseq_HFinite_hypreal NSconvergent_NSBseq 
   504          simp add: starfunNat_sumr [symmetric] starfunNat hypnat_omega_def
   505                    convergent_NSconvergent_iff [symmetric] 
   506                    summable_convergent_sumr_iff [symmetric] summable_cos)
   507 
   508 lemma STAR_cos_zero [simp]: "( *f* cos) 0 = 1"
   509 by (simp add: starfun hypreal_zero_num hypreal_one_num)
   510 
   511 lemma STAR_cos_Infinitesimal [simp]: "x \<in> Infinitesimal ==> ( *f* cos) x @= 1"
   512 apply (case_tac "x = 0")
   513 apply (cut_tac [2] x = 0 in DERIV_cos)
   514 apply (auto simp add: NSDERIV_DERIV_iff [symmetric] nsderiv_def hypreal_of_real_zero)
   515 apply (drule bspec [where x = x])
   516 apply (auto simp add: hypreal_of_real_zero hypreal_of_real_one)
   517 apply (drule approx_mult1 [where c = x])
   518 apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD]
   519             simp add: mult_assoc hypreal_of_real_one)
   520 apply (rule approx_add_right_cancel [where d = "-1"], auto)
   521 done
   522 
   523 lemma STAR_tan_zero [simp]: "( *f* tan) 0 = 0"
   524 by (simp add: starfun hypreal_zero_num)
   525 
   526 lemma STAR_tan_Infinitesimal: "x \<in> Infinitesimal ==> ( *f* tan) x @= x"
   527 apply (case_tac "x = 0")
   528 apply (cut_tac [2] x = 0 in DERIV_tan)
   529 apply (auto simp add: NSDERIV_DERIV_iff [symmetric] nsderiv_def hypreal_of_real_zero)
   530 apply (drule bspec [where x = x], auto)
   531 apply (drule approx_mult1 [where c = x])
   532 apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD]
   533              simp add: mult_assoc)
   534 done
   535 
   536 lemma STAR_sin_cos_Infinitesimal_mult:
   537      "x \<in> Infinitesimal ==> ( *f* sin) x * ( *f* cos) x @= x"
   538 apply (insert approx_mult_HFinite [of "( *f* sin) x" _ "( *f* cos) x" 1]) 
   539 apply (simp add: Infinitesimal_subset_HFinite [THEN subsetD])
   540 done
   541 
   542 lemma HFinite_pi: "hypreal_of_real pi \<in> HFinite"
   543 by simp
   544 
   545 (* lemmas *)
   546 
   547 lemma lemma_split_hypreal_of_real:
   548      "N \<in> HNatInfinite  
   549       ==> hypreal_of_real a =  
   550           hypreal_of_hypnat N * (inverse(hypreal_of_hypnat N) * hypreal_of_real a)"
   551 by (simp add: mult_assoc [symmetric] HNatInfinite_not_eq_zero)
   552 
   553 lemma STAR_sin_Infinitesimal_divide:
   554      "[|x \<in> Infinitesimal; x \<noteq> 0 |] ==> ( *f* sin) x/x @= 1"
   555 apply (cut_tac x = 0 in DERIV_sin)
   556 apply (simp add: NSDERIV_DERIV_iff [symmetric] nsderiv_def hypreal_of_real_zero hypreal_of_real_one)
   557 done
   558 
   559 (*------------------------------------------------------------------------*) 
   560 (* sin* (1/n) * 1/(1/n) @= 1 for n = oo                                   *)
   561 (*------------------------------------------------------------------------*)
   562 
   563 lemma lemma_sin_pi:
   564      "n \<in> HNatInfinite  
   565       ==> ( *f* sin) (inverse (hypreal_of_hypnat n))/(inverse (hypreal_of_hypnat n)) @= 1"
   566 apply (rule STAR_sin_Infinitesimal_divide)
   567 apply (auto simp add: HNatInfinite_not_eq_zero)
   568 done
   569 
   570 lemma STAR_sin_inverse_HNatInfinite:
   571      "n \<in> HNatInfinite  
   572       ==> ( *f* sin) (inverse (hypreal_of_hypnat n)) * hypreal_of_hypnat n @= 1"
   573 apply (frule lemma_sin_pi)
   574 apply (simp add: divide_inverse)
   575 done
   576 
   577 lemma Infinitesimal_pi_divide_HNatInfinite: 
   578      "N \<in> HNatInfinite  
   579       ==> hypreal_of_real pi/(hypreal_of_hypnat N) \<in> Infinitesimal"
   580 apply (simp add: divide_inverse)
   581 apply (auto intro: Infinitesimal_HFinite_mult2)
   582 done
   583 
   584 lemma pi_divide_HNatInfinite_not_zero [simp]:
   585      "N \<in> HNatInfinite ==> hypreal_of_real pi/(hypreal_of_hypnat N) \<noteq> 0"
   586 by (simp add: HNatInfinite_not_eq_zero)
   587 
   588 lemma STAR_sin_pi_divide_HNatInfinite_approx_pi:
   589      "n \<in> HNatInfinite  
   590       ==> ( *f* sin) (hypreal_of_real pi/(hypreal_of_hypnat n)) * hypreal_of_hypnat n  
   591           @= hypreal_of_real pi"
   592 apply (frule STAR_sin_Infinitesimal_divide
   593                [OF Infinitesimal_pi_divide_HNatInfinite 
   594                    pi_divide_HNatInfinite_not_zero])
   595 apply (auto simp add: inverse_mult_distrib)
   596 apply (rule approx_SReal_mult_cancel [of "inverse (hypreal_of_real pi)"])
   597 apply (auto intro: SReal_inverse simp add: divide_inverse mult_ac)
   598 done
   599 
   600 lemma STAR_sin_pi_divide_HNatInfinite_approx_pi2:
   601      "n \<in> HNatInfinite  
   602       ==> hypreal_of_hypnat n *  
   603           ( *f* sin) (hypreal_of_real pi/(hypreal_of_hypnat n))  
   604           @= hypreal_of_real pi"
   605 apply (rule mult_commute [THEN subst])
   606 apply (erule STAR_sin_pi_divide_HNatInfinite_approx_pi)
   607 done
   608 
   609 lemma starfunNat_pi_divide_n_Infinitesimal: 
   610      "N \<in> HNatInfinite ==> ( *fNat* (%x. pi / real x)) N \<in> Infinitesimal"
   611 by (auto intro!: Infinitesimal_HFinite_mult2 
   612          simp add: starfunNat_mult [symmetric] divide_inverse
   613                    starfunNat_inverse [symmetric] starfunNat_real_of_nat)
   614 
   615 lemma STAR_sin_pi_divide_n_approx:
   616      "N \<in> HNatInfinite ==>  
   617       ( *f* sin) (( *fNat* (%x. pi / real x)) N) @=  
   618       hypreal_of_real pi/(hypreal_of_hypnat N)"
   619 by (auto intro!: STAR_sin_Infinitesimal Infinitesimal_HFinite_mult2 
   620          simp add: starfunNat_mult [symmetric] divide_inverse
   621                    starfunNat_inverse_real_of_nat_eq)
   622 
   623 lemma NSLIMSEQ_sin_pi: "(%n. real n * sin (pi / real n)) ----NS> pi"
   624 apply (auto simp add: NSLIMSEQ_def starfunNat_mult [symmetric] starfunNat_real_of_nat)
   625 apply (rule_tac f1 = sin in starfun_stafunNat_o2 [THEN subst])
   626 apply (auto simp add: starfunNat_mult [symmetric] starfunNat_real_of_nat divide_inverse)
   627 apply (rule_tac f1 = inverse in starfun_stafunNat_o2 [THEN subst])
   628 apply (auto dest: STAR_sin_pi_divide_HNatInfinite_approx_pi 
   629             simp add: starfunNat_real_of_nat mult_commute divide_inverse)
   630 done
   631 
   632 lemma NSLIMSEQ_cos_one: "(%n. cos (pi / real n))----NS> 1"
   633 apply (simp add: NSLIMSEQ_def, auto)
   634 apply (rule_tac f1 = cos in starfun_stafunNat_o2 [THEN subst])
   635 apply (rule STAR_cos_Infinitesimal)
   636 apply (auto intro!: Infinitesimal_HFinite_mult2 
   637             simp add: starfunNat_mult [symmetric] divide_inverse
   638                       starfunNat_inverse [symmetric] starfunNat_real_of_nat)
   639 done
   640 
   641 lemma NSLIMSEQ_sin_cos_pi:
   642      "(%n. real n * sin (pi / real n) * cos (pi / real n)) ----NS> pi"
   643 by (insert NSLIMSEQ_mult [OF NSLIMSEQ_sin_pi NSLIMSEQ_cos_one], simp)
   644 
   645 
   646 text{*A familiar approximation to @{term "cos x"} when @{term x} is small*}
   647 
   648 lemma STAR_cos_Infinitesimal_approx:
   649      "x \<in> Infinitesimal ==> ( *f* cos) x @= 1 - x ^ 2"
   650 apply (rule STAR_cos_Infinitesimal [THEN approx_trans])
   651 apply (auto simp add: Infinitesimal_approx_minus [symmetric] 
   652             diff_minus add_assoc [symmetric] numeral_2_eq_2)
   653 done
   654 
   655 lemma STAR_cos_Infinitesimal_approx2:
   656      "x \<in> Infinitesimal ==> ( *f* cos) x @= 1 - (x ^ 2)/2"
   657 apply (rule STAR_cos_Infinitesimal [THEN approx_trans])
   658 apply (auto intro: Infinitesimal_SReal_divide 
   659             simp add: Infinitesimal_approx_minus [symmetric] numeral_2_eq_2)
   660 done
   661 
   662 ML
   663 {*
   664 val STAR_sqrt_zero = thm "STAR_sqrt_zero";
   665 val STAR_sqrt_one = thm "STAR_sqrt_one";
   666 val hypreal_sqrt_pow2_iff = thm "hypreal_sqrt_pow2_iff";
   667 val hypreal_sqrt_gt_zero_pow2 = thm "hypreal_sqrt_gt_zero_pow2";
   668 val hypreal_sqrt_pow2_gt_zero = thm "hypreal_sqrt_pow2_gt_zero";
   669 val hypreal_sqrt_not_zero = thm "hypreal_sqrt_not_zero";
   670 val hypreal_inverse_sqrt_pow2 = thm "hypreal_inverse_sqrt_pow2";
   671 val hypreal_sqrt_mult_distrib = thm "hypreal_sqrt_mult_distrib";
   672 val hypreal_sqrt_mult_distrib2 = thm "hypreal_sqrt_mult_distrib2";
   673 val hypreal_sqrt_approx_zero = thm "hypreal_sqrt_approx_zero";
   674 val hypreal_sqrt_approx_zero2 = thm "hypreal_sqrt_approx_zero2";
   675 val hypreal_sqrt_sum_squares = thm "hypreal_sqrt_sum_squares";
   676 val hypreal_sqrt_sum_squares2 = thm "hypreal_sqrt_sum_squares2";
   677 val hypreal_sqrt_gt_zero = thm "hypreal_sqrt_gt_zero";
   678 val hypreal_sqrt_ge_zero = thm "hypreal_sqrt_ge_zero";
   679 val hypreal_sqrt_hrabs = thm "hypreal_sqrt_hrabs";
   680 val hypreal_sqrt_hrabs2 = thm "hypreal_sqrt_hrabs2";
   681 val hypreal_sqrt_hyperpow_hrabs = thm "hypreal_sqrt_hyperpow_hrabs";
   682 val star_sqrt_HFinite = thm "star_sqrt_HFinite";
   683 val st_hypreal_sqrt = thm "st_hypreal_sqrt";
   684 val hypreal_sqrt_sum_squares_ge1 = thm "hypreal_sqrt_sum_squares_ge1";
   685 val HFinite_hypreal_sqrt = thm "HFinite_hypreal_sqrt";
   686 val HFinite_hypreal_sqrt_imp_HFinite = thm "HFinite_hypreal_sqrt_imp_HFinite";
   687 val HFinite_hypreal_sqrt_iff = thm "HFinite_hypreal_sqrt_iff";
   688 val HFinite_sqrt_sum_squares = thm "HFinite_sqrt_sum_squares";
   689 val Infinitesimal_hypreal_sqrt = thm "Infinitesimal_hypreal_sqrt";
   690 val Infinitesimal_hypreal_sqrt_imp_Infinitesimal = thm "Infinitesimal_hypreal_sqrt_imp_Infinitesimal";
   691 val Infinitesimal_hypreal_sqrt_iff = thm "Infinitesimal_hypreal_sqrt_iff";
   692 val Infinitesimal_sqrt_sum_squares = thm "Infinitesimal_sqrt_sum_squares";
   693 val HInfinite_hypreal_sqrt = thm "HInfinite_hypreal_sqrt";
   694 val HInfinite_hypreal_sqrt_imp_HInfinite = thm "HInfinite_hypreal_sqrt_imp_HInfinite";
   695 val HInfinite_hypreal_sqrt_iff = thm "HInfinite_hypreal_sqrt_iff";
   696 val HInfinite_sqrt_sum_squares = thm "HInfinite_sqrt_sum_squares";
   697 val HFinite_exp = thm "HFinite_exp";
   698 val exphr_zero = thm "exphr_zero";
   699 val coshr_zero = thm "coshr_zero";
   700 val STAR_exp_zero_approx_one = thm "STAR_exp_zero_approx_one";
   701 val STAR_exp_Infinitesimal = thm "STAR_exp_Infinitesimal";
   702 val STAR_exp_epsilon = thm "STAR_exp_epsilon";
   703 val STAR_exp_add = thm "STAR_exp_add";
   704 val exphr_hypreal_of_real_exp_eq = thm "exphr_hypreal_of_real_exp_eq";
   705 val starfun_exp_ge_add_one_self = thm "starfun_exp_ge_add_one_self";
   706 val starfun_exp_HInfinite = thm "starfun_exp_HInfinite";
   707 val starfun_exp_minus = thm "starfun_exp_minus";
   708 val starfun_exp_Infinitesimal = thm "starfun_exp_Infinitesimal";
   709 val starfun_exp_gt_one = thm "starfun_exp_gt_one";
   710 val starfun_ln_exp = thm "starfun_ln_exp";
   711 val starfun_exp_ln_iff = thm "starfun_exp_ln_iff";
   712 val starfun_exp_ln_eq = thm "starfun_exp_ln_eq";
   713 val starfun_ln_less_self = thm "starfun_ln_less_self";
   714 val starfun_ln_ge_zero = thm "starfun_ln_ge_zero";
   715 val starfun_ln_gt_zero = thm "starfun_ln_gt_zero";
   716 val starfun_ln_not_eq_zero = thm "starfun_ln_not_eq_zero";
   717 val starfun_ln_HFinite = thm "starfun_ln_HFinite";
   718 val starfun_ln_inverse = thm "starfun_ln_inverse";
   719 val starfun_exp_HFinite = thm "starfun_exp_HFinite";
   720 val starfun_exp_add_HFinite_Infinitesimal_approx = thm "starfun_exp_add_HFinite_Infinitesimal_approx";
   721 val starfun_ln_HInfinite = thm "starfun_ln_HInfinite";
   722 val starfun_exp_HInfinite_Infinitesimal_disj = thm "starfun_exp_HInfinite_Infinitesimal_disj";
   723 val starfun_ln_HFinite_not_Infinitesimal = thm "starfun_ln_HFinite_not_Infinitesimal";
   724 val starfun_ln_Infinitesimal_HInfinite = thm "starfun_ln_Infinitesimal_HInfinite";
   725 val starfun_ln_less_zero = thm "starfun_ln_less_zero";
   726 val starfun_ln_Infinitesimal_less_zero = thm "starfun_ln_Infinitesimal_less_zero";
   727 val starfun_ln_HInfinite_gt_zero = thm "starfun_ln_HInfinite_gt_zero";
   728 val HFinite_sin = thm "HFinite_sin";
   729 val STAR_sin_zero = thm "STAR_sin_zero";
   730 val STAR_sin_Infinitesimal = thm "STAR_sin_Infinitesimal";
   731 val HFinite_cos = thm "HFinite_cos";
   732 val STAR_cos_zero = thm "STAR_cos_zero";
   733 val STAR_cos_Infinitesimal = thm "STAR_cos_Infinitesimal";
   734 val STAR_tan_zero = thm "STAR_tan_zero";
   735 val STAR_tan_Infinitesimal = thm "STAR_tan_Infinitesimal";
   736 val STAR_sin_cos_Infinitesimal_mult = thm "STAR_sin_cos_Infinitesimal_mult";
   737 val HFinite_pi = thm "HFinite_pi";
   738 val lemma_split_hypreal_of_real = thm "lemma_split_hypreal_of_real";
   739 val STAR_sin_Infinitesimal_divide = thm "STAR_sin_Infinitesimal_divide";
   740 val lemma_sin_pi = thm "lemma_sin_pi";
   741 val STAR_sin_inverse_HNatInfinite = thm "STAR_sin_inverse_HNatInfinite";
   742 val Infinitesimal_pi_divide_HNatInfinite = thm "Infinitesimal_pi_divide_HNatInfinite";
   743 val pi_divide_HNatInfinite_not_zero = thm "pi_divide_HNatInfinite_not_zero";
   744 val STAR_sin_pi_divide_HNatInfinite_approx_pi = thm "STAR_sin_pi_divide_HNatInfinite_approx_pi";
   745 val STAR_sin_pi_divide_HNatInfinite_approx_pi2 = thm "STAR_sin_pi_divide_HNatInfinite_approx_pi2";
   746 val starfunNat_pi_divide_n_Infinitesimal = thm "starfunNat_pi_divide_n_Infinitesimal";
   747 val STAR_sin_pi_divide_n_approx = thm "STAR_sin_pi_divide_n_approx";
   748 val NSLIMSEQ_sin_pi = thm "NSLIMSEQ_sin_pi";
   749 val NSLIMSEQ_cos_one = thm "NSLIMSEQ_cos_one";
   750 val NSLIMSEQ_sin_cos_pi = thm "NSLIMSEQ_sin_cos_pi";
   751 val STAR_cos_Infinitesimal_approx = thm "STAR_cos_Infinitesimal_approx";
   752 val STAR_cos_Infinitesimal_approx2 = thm "STAR_cos_Infinitesimal_approx2";
   753 *}
   754 
   755 
   756 end