equal
deleted
inserted
replaced
2376 |
2376 |
2377 lemma compute_powr[code]: |
2377 lemma compute_powr[code]: |
2378 fixes i::real |
2378 fixes i::real |
2379 shows "b powr i = |
2379 shows "b powr i = |
2380 (if b \<le> 0 then Code.abort (STR ''op powr with nonpositive base'') (\<lambda>_. b powr i) |
2380 (if b \<le> 0 then Code.abort (STR ''op powr with nonpositive base'') (\<lambda>_. b powr i) |
2381 else if floor i = i then (if 0 \<le> i then b ^ nat(floor i) else 1 / b ^ nat(floor (- i))) |
2381 else if \<lfloor>i\<rfloor> = i then (if 0 \<le> i then b ^ nat \<lfloor>i\<rfloor> else 1 / b ^ nat \<lfloor>- i\<rfloor>) |
2382 else Code.abort (STR ''op powr with non-integer exponent'') (\<lambda>_. b powr i))" |
2382 else Code.abort (STR ''op powr with non-integer exponent'') (\<lambda>_. b powr i))" |
2383 by (auto simp: powr_int) |
2383 by (auto simp: powr_int) |
2384 |
2384 |
2385 lemma powr_one: |
2385 lemma powr_one: |
2386 fixes x::real shows "0 \<le> x \<Longrightarrow> x powr 1 = x" |
2386 fixes x::real shows "0 \<le> x \<Longrightarrow> x powr 1 = x" |
3566 proof - |
3566 proof - |
3567 have xle: "x < (1 + real_of_int \<lfloor>x/pi\<rfloor>) * pi" |
3567 have xle: "x < (1 + real_of_int \<lfloor>x/pi\<rfloor>) * pi" |
3568 using floor_correct [of "x/pi"] |
3568 using floor_correct [of "x/pi"] |
3569 by (simp add: add.commute divide_less_eq) |
3569 by (simp add: add.commute divide_less_eq) |
3570 obtain n where "real n * pi \<le> x" "x < real (Suc n) * pi" |
3570 obtain n where "real n * pi \<le> x" "x < real (Suc n) * pi" |
3571 apply (rule that [of "nat (floor (x/pi))"] ) |
3571 apply (rule that [of "nat \<lfloor>x/pi\<rfloor>"]) |
3572 using assms |
3572 using assms |
3573 apply (simp_all add: xle) |
3573 apply (simp_all add: xle) |
3574 apply (metis floor_less_iff less_irrefl mult_imp_div_pos_less not_le pi_gt_zero) |
3574 apply (metis floor_less_iff less_irrefl mult_imp_div_pos_less not_le pi_gt_zero) |
3575 done |
3575 done |
3576 then have x: "0 \<le> x - n * pi" "(x - n * pi) \<le> pi" "cos (x - n * pi) = 0" |
3576 then have x: "0 \<le> x - n * pi" "(x - n * pi) \<le> pi" "cos (x - n * pi) = 0" |