src/HOL/Decision_Procs/Approximation_Bounds.thy
author wenzelm
Mon, 11 Sep 2023 19:30:48 +0200
changeset 78659 b5f3d1051b13
parent 75455 91c16c5ad3e9
child 80521 5c691b178e08
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     1
(* 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     2
  Author:     Johannes Hoelzl, TU Muenchen
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     3
  Coercions removed by Dmitriy Traytel
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     4
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     5
  This file contains only general material about computing lower/upper bounds
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     6
  on real functions. Approximation.thy contains the actual approximation algorithm
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     7
  and the approximation oracle. This is in order to make a clear separation between 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     8
  "morally immaculate" material about upper/lower bounds and the trusted oracle/reflection.
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
     9
*)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    10
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    11
theory Approximation_Bounds
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    12
imports
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    13
  Complex_Main
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
    14
  "HOL-Library.Interval_Float"
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    15
  Dense_Linear_Order
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    16
begin
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    17
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    18
declare powr_neg_one [simp]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    19
declare powr_neg_numeral [simp]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    20
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
    21
context includes interval.lifting begin
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
    22
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    23
section "Horner Scheme"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    24
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    25
subsection \<open>Define auxiliary helper \<open>horner\<close> function\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    26
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    27
primrec horner :: "(nat \<Rightarrow> nat) \<Rightarrow> (nat \<Rightarrow> nat \<Rightarrow> nat) \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> real \<Rightarrow> real" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    28
"horner F G 0 i k x       = 0" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    29
"horner F G (Suc n) i k x = 1 / k - x * horner F G n (F i) (G i k) x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    30
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    31
lemma horner_schema':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    32
  fixes x :: real and a :: "nat \<Rightarrow> real"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    33
  shows "a 0 - x * (\<Sum> i=0..<n. (-1)^i * a (Suc i) * x^i) = (\<Sum> i=0..<Suc n. (-1)^i * a i * x^i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    34
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    35
  have shift_pow: "\<And>i. - (x * ((-1)^i * a (Suc i) * x ^ i)) = (-1)^(Suc i) * a (Suc i) * x ^ (Suc i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    36
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    37
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    38
    unfolding sum_distrib_left shift_pow uminus_add_conv_diff [symmetric] sum_negf[symmetric]
70097
4005298550a6 The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
    39
    sum.atLeast_Suc_lessThan[OF zero_less_Suc]
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    40
    sum.reindex[OF inj_Suc, unfolded comp_def, symmetric, of "\<lambda> n. (-1)^n  *a n * x^n"] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    41
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    42
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    43
lemma horner_schema:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    44
  fixes f :: "nat \<Rightarrow> nat" and G :: "nat \<Rightarrow> nat \<Rightarrow> nat" and F :: "nat \<Rightarrow> nat"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    45
  assumes f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    46
  shows "horner F G n ((F ^^ j') s) (f j') x = (\<Sum> j = 0..< n. (- 1) ^ j * (1 / (f (j' + j))) * x ^ j)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    47
proof (induct n arbitrary: j')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    48
  case 0
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    49
  then show ?case by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    50
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    51
  case (Suc n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    52
  show ?case unfolding horner.simps Suc[where j'="Suc j'", unfolded funpow.simps comp_def f_Suc]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    53
    using horner_schema'[of "\<lambda> j. 1 / (f (j' + j))"] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    54
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    55
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    56
lemma horner_bounds':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    57
  fixes lb :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" and ub :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    58
  assumes "0 \<le> real_of_float x" and f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    59
    and lb_0: "\<And> i k x. lb 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    60
    and lb_Suc: "\<And> n i k x. lb (Suc n) i k x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    61
        (lapprox_rat prec 1 k)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    62
        (- float_round_up prec (x * (ub n (F i) (G i k) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    63
    and ub_0: "\<And> i k x. ub 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    64
    and ub_Suc: "\<And> n i k x. ub (Suc n) i k x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    65
        (rapprox_rat prec 1 k)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    66
        (- float_round_down prec (x * (lb n (F i) (G i k) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    67
  shows "(lb n ((F ^^ j') s) (f j') x) \<le> horner F G n ((F ^^ j') s) (f j') x \<and>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    68
         horner F G n ((F ^^ j') s) (f j') x \<le> (ub n ((F ^^ j') s) (f j') x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    69
  (is "?lb n j' \<le> ?horner n j' \<and> ?horner n j' \<le> ?ub n j'")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    70
proof (induct n arbitrary: j')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    71
  case 0
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    72
  thus ?case unfolding lb_0 ub_0 horner.simps by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    73
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    74
  case (Suc n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    75
  thus ?case using lapprox_rat[of prec 1 "f j'"] using rapprox_rat[of 1 "f j'" prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    76
    Suc[where j'="Suc j'"] \<open>0 \<le> real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    77
    by (auto intro!: add_mono mult_left_mono float_round_down_le float_round_up_le
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    78
      order_trans[OF add_mono[OF _ float_plus_down_le]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    79
      order_trans[OF _ add_mono[OF _ float_plus_up_le]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    80
      simp add: lb_Suc ub_Suc field_simps f_Suc)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    81
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    82
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    83
subsection "Theorems for floating point functions implementing the horner scheme"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    84
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    85
text \<open>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    86
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67573
diff changeset
    87
Here \<^term_type>\<open>f :: nat \<Rightarrow> nat\<close> is the sequence defining the Taylor series, the coefficients are
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67573
diff changeset
    88
all alternating and reciprocs. We use \<^term>\<open>G\<close> and \<^term>\<open>F\<close> to describe the computation of \<^term>\<open>f\<close>.
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    89
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    90
\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    91
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    92
lemma horner_bounds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    93
  fixes F :: "nat \<Rightarrow> nat" and G :: "nat \<Rightarrow> nat \<Rightarrow> nat"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    94
  assumes "0 \<le> real_of_float x" and f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    95
    and lb_0: "\<And> i k x. lb 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    96
    and lb_Suc: "\<And> n i k x. lb (Suc n) i k x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    97
        (lapprox_rat prec 1 k)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    98
        (- float_round_up prec (x * (ub n (F i) (G i k) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
    99
    and ub_0: "\<And> i k x. ub 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   100
    and ub_Suc: "\<And> n i k x. ub (Suc n) i k x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   101
        (rapprox_rat prec 1 k)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   102
        (- float_round_down prec (x * (lb n (F i) (G i k) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   103
  shows "(lb n ((F ^^ j') s) (f j') x) \<le> (\<Sum>j=0..<n. (- 1) ^ j * (1 / (f (j' + j))) * (x ^ j))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   104
      (is "?lb")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   105
    and "(\<Sum>j=0..<n. (- 1) ^ j * (1 / (f (j' + j))) * (x ^ j)) \<le> (ub n ((F ^^ j') s) (f j') x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   106
      (is "?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   107
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   108
  have "?lb  \<and> ?ub"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   109
    using horner_bounds'[where lb=lb, OF \<open>0 \<le> real_of_float x\<close> f_Suc lb_0 lb_Suc ub_0 ub_Suc]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   110
    unfolding horner_schema[where f=f, OF f_Suc] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   111
  thus "?lb" and "?ub" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   112
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   113
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   114
lemma horner_bounds_nonpos:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   115
  fixes F :: "nat \<Rightarrow> nat" and G :: "nat \<Rightarrow> nat \<Rightarrow> nat"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   116
  assumes "real_of_float x \<le> 0" and f_Suc: "\<And>n. f (Suc n) = G ((F ^^ n) s) (f n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   117
    and lb_0: "\<And> i k x. lb 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   118
    and lb_Suc: "\<And> n i k x. lb (Suc n) i k x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   119
        (lapprox_rat prec 1 k)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   120
        (float_round_down prec (x * (ub n (F i) (G i k) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   121
    and ub_0: "\<And> i k x. ub 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   122
    and ub_Suc: "\<And> n i k x. ub (Suc n) i k x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   123
        (rapprox_rat prec 1 k)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   124
        (float_round_up prec (x * (lb n (F i) (G i k) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   125
  shows "(lb n ((F ^^ j') s) (f j') x) \<le> (\<Sum>j=0..<n. (1 / (f (j' + j))) * real_of_float x ^ j)" (is "?lb")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   126
    and "(\<Sum>j=0..<n. (1 / (f (j' + j))) * real_of_float x ^ j) \<le> (ub n ((F ^^ j') s) (f j') x)" (is "?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   127
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   128
  have diff_mult_minus: "x - y * z = x + - y * z" for x y z :: float by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   129
  have sum_eq: "(\<Sum>j=0..<n. (1 / (f (j' + j))) * real_of_float x ^ j) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   130
    (\<Sum>j = 0..<n. (- 1) ^ j * (1 / (f (j' + j))) * real_of_float (- x) ^ j)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   131
    by (auto simp add: field_simps power_mult_distrib[symmetric])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   132
  have "0 \<le> real_of_float (-x)" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   133
  from horner_bounds[where G=G and F=F and f=f and s=s and prec=prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   134
    and lb="\<lambda> n i k x. lb n i k (-x)" and ub="\<lambda> n i k x. ub n i k (-x)",
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   135
    unfolded lb_Suc ub_Suc diff_mult_minus,
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   136
    OF this f_Suc lb_0 _ ub_0 _]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   137
  show "?lb" and "?ub" unfolding minus_minus sum_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   138
    by (auto simp: minus_float_round_up_eq minus_float_round_down_eq)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   139
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   140
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   141
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   142
subsection \<open>Selectors for next even or odd number\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   143
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   144
text \<open>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   145
The horner scheme computes alternating series. To get the upper and lower bounds we need to
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67573
diff changeset
   146
guarantee to access a even or odd member. To do this we use \<^term>\<open>get_odd\<close> and \<^term>\<open>get_even\<close>.
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   147
\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   148
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   149
definition get_odd :: "nat \<Rightarrow> nat" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   150
  "get_odd n = (if odd n then n else (Suc n))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   151
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   152
definition get_even :: "nat \<Rightarrow> nat" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   153
  "get_even n = (if even n then n else (Suc n))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   154
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   155
lemma get_odd[simp]: "odd (get_odd n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   156
  unfolding get_odd_def by (cases "odd n") auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   157
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   158
lemma get_even[simp]: "even (get_even n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   159
  unfolding get_even_def by (cases "even n") auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   160
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   161
lemma get_odd_ex: "\<exists> k. Suc k = get_odd n \<and> odd (Suc k)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   162
  by (auto simp: get_odd_def odd_pos intro!: exI[of _ "n - 1"])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   163
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   164
lemma get_even_double: "\<exists>i. get_even n = 2 * i"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   165
  using get_even by (blast elim: evenE)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   166
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   167
lemma get_odd_double: "\<exists>i. get_odd n = 2 * i + 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   168
  using get_odd by (blast elim: oddE)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   169
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   170
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   171
section "Power function"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   172
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   173
definition float_power_bnds :: "nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float * float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   174
"float_power_bnds prec n l u =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   175
  (if 0 < l then (power_down_fl prec l n, power_up_fl prec u n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   176
  else if odd n then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   177
    (- power_up_fl prec \<bar>l\<bar> n,
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   178
      if u < 0 then - power_down_fl prec \<bar>u\<bar> n else power_up_fl prec u n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   179
  else if u < 0 then (power_down_fl prec \<bar>u\<bar> n, power_up_fl prec \<bar>l\<bar> n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   180
  else (0, power_up_fl prec (max \<bar>l\<bar> \<bar>u\<bar>) n))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   181
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   182
lemma le_minus_power_downI: "0 \<le> x \<Longrightarrow> x ^ n \<le> - a \<Longrightarrow> a \<le> - power_down prec x n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   183
  by (subst le_minus_iff) (auto intro: power_down_le power_mono_odd)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   184
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   185
lemma float_power_bnds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   186
  "(l1, u1) = float_power_bnds prec n l u \<Longrightarrow> x \<in> {l .. u} \<Longrightarrow> (x::real) ^ n \<in> {l1..u1}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   187
  by (auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   188
    simp: float_power_bnds_def max_def real_power_up_fl real_power_down_fl minus_le_iff
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   189
    split: if_split_asm
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   190
    intro!: power_up_le power_down_le le_minus_power_downI
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   191
    intro: power_mono_odd power_mono power_mono_even zero_le_even_power)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   192
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   193
lemma bnds_power:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   194
  "\<forall>(x::real) l u. (l1, u1) = float_power_bnds prec n l u \<and> x \<in> {l .. u} \<longrightarrow>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   195
    l1 \<le> x ^ n \<and> x ^ n \<le> u1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   196
  using float_power_bnds by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   197
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   198
lift_definition power_float_interval :: "nat \<Rightarrow> nat \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   199
  is "\<lambda>p n (l, u). float_power_bnds p n l u"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   200
  using float_power_bnds
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   201
  by (auto simp: bnds_power dest!: float_power_bnds[OF sym])
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   202
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   203
lemma lower_power_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   204
  "lower (power_float_interval p n x) = fst (float_power_bnds p n (lower x) (upper x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   205
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   206
lemma upper_power_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   207
  "upper (power_float_interval p n x) = snd (float_power_bnds p n (lower x) (upper x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   208
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   209
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   210
lemma power_float_intervalI: "x \<in>\<^sub>r X \<Longrightarrow> x ^ n \<in>\<^sub>r power_float_interval p n X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   211
  using float_power_bnds[OF prod.collapse]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   212
  by (auto simp: set_of_eq lower_power_float_interval upper_power_float_interval)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   213
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   214
lemma power_float_interval_mono:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   215
  "set_of (power_float_interval prec n A)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   216
    \<subseteq> set_of (power_float_interval prec n B)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   217
  if "set_of A \<subseteq> set_of B"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   218
proof -
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   219
  define la where "la = real_of_float (lower A)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   220
  define ua where "ua = real_of_float (upper A)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   221
  define lb where "lb = real_of_float (lower B)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   222
  define ub where "ub = real_of_float (upper B)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   223
  have ineqs: "lb \<le> la" "la \<le> ua" "ua \<le> ub" "lb \<le> ub"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   224
    using that lower_le_upper[of A] lower_le_upper[of B]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   225
    by (auto simp: la_def ua_def lb_def ub_def set_of_eq)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   226
  show ?thesis
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   227
    using ineqs
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   228
    by (simp add: set_of_subset_iff float_power_bnds_def max_def
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   229
        power_down_fl.rep_eq power_up_fl.rep_eq
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   230
        lower_power_float_interval upper_power_float_interval
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   231
        la_def[symmetric] ua_def[symmetric] lb_def[symmetric] ub_def[symmetric])
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   232
      (auto intro!: power_down_mono power_up_mono intro: order_trans[where y=0])
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   233
qed
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   234
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   235
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   236
section \<open>Approximation utility functions\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   237
73537
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   238
lift_definition plus_float_interval::"nat \<Rightarrow> float interval \<Rightarrow> float interval \<Rightarrow> float interval"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   239
  is "\<lambda>prec. \<lambda>(a1, a2). \<lambda>(b1, b2). (float_plus_down prec a1 b1, float_plus_up prec a2 b2)"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   240
  by (auto intro!: add_mono simp: float_plus_down_le float_plus_up_le)
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   241
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   242
lemma lower_plus_float_interval:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   243
  "lower (plus_float_interval prec ivl ivl') = float_plus_down prec (lower ivl) (lower ivl')"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   244
  by transfer auto
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   245
lemma upper_plus_float_interval:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   246
  "upper (plus_float_interval prec ivl ivl') = float_plus_up prec (upper ivl) (upper ivl')"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   247
  by transfer auto
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   248
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   249
lemma mult_float_interval_ge:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   250
  "real_interval A + real_interval B \<le> real_interval (plus_float_interval prec A B)"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   251
  unfolding less_eq_interval_def
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   252
  by transfer
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   253
     (auto simp: lower_plus_float_interval upper_plus_float_interval
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   254
           intro!: order.trans[OF float_plus_down] order.trans[OF _ float_plus_up])
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   255
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   256
lemma plus_float_interval:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   257
  "set_of (real_interval A) + set_of (real_interval B) \<subseteq>
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   258
    set_of (real_interval (plus_float_interval prec A B))"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   259
proof -
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   260
  have "set_of (real_interval A) + set_of (real_interval B) \<subseteq>
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   261
          set_of (real_interval A + real_interval B)"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   262
    by (simp add: set_of_plus)
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   263
  also have "\<dots> \<subseteq> set_of (real_interval (plus_float_interval prec A B))"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   264
    using mult_float_interval_ge[of A B prec] by (simp add: set_of_subset_iff')
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   265
  finally show ?thesis .
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   266
qed
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   267
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   268
lemma plus_float_intervalI:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   269
  "x + y \<in>\<^sub>r plus_float_interval prec A B"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   270
  if "x \<in>\<^sub>i real_interval A" "y \<in>\<^sub>i real_interval B"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   271
  using plus_float_interval[of A B] that by auto
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   272
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   273
lemma plus_float_interval_mono:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   274
  "plus_float_interval prec A B \<le> plus_float_interval prec X Y"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   275
  if "A \<le> X" "B \<le> Y"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   276
  using that
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   277
  by (auto simp: less_eq_interval_def lower_plus_float_interval upper_plus_float_interval
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   278
                 float_plus_down.rep_eq float_plus_up.rep_eq plus_down_mono plus_up_mono)
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   279
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   280
lemma plus_float_interval_monotonic:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   281
  "set_of (ivl + ivl') \<subseteq> set_of (plus_float_interval prec ivl ivl')"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   282
  using float_plus_down_le float_plus_up_le lower_plus_float_interval upper_plus_float_interval
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   283
  by (simp add: set_of_subset_iff)
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   284
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   285
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   286
definition bnds_mult :: "nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<times> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   287
  "bnds_mult prec a1 a2 b1 b2 =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   288
      (float_plus_down prec (nprt a1 * pprt b2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   289
          (float_plus_down prec (nprt a2 * nprt b2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   290
            (float_plus_down prec (pprt a1 * pprt b1) (pprt a2 * nprt b1))),
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   291
        float_plus_up prec (pprt a2 * pprt b2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   292
            (float_plus_up prec (pprt a1 * nprt b2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   293
              (float_plus_up prec (nprt a2 * pprt b1) (nprt a1 * nprt b1))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   294
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   295
lemma bnds_mult:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   296
  fixes prec :: nat and a1 aa2 b1 b2 :: float
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   297
  assumes "(l, u) = bnds_mult prec a1 a2 b1 b2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   298
  assumes "a \<in> {real_of_float a1..real_of_float a2}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   299
  assumes "b \<in> {real_of_float b1..real_of_float b2}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   300
  shows   "a * b \<in> {real_of_float l..real_of_float u}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   301
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   302
  from assms have "real_of_float l \<le> a * b" 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   303
    by (intro order.trans[OF _ mult_ge_prts[of a1 a a2 b1 b b2]])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   304
       (auto simp: bnds_mult_def intro!: float_plus_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   305
  moreover from assms have "real_of_float u \<ge> a * b" 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   306
    by (intro order.trans[OF mult_le_prts[of a1 a a2 b1 b b2]])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   307
       (auto simp: bnds_mult_def intro!: float_plus_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   308
  ultimately show ?thesis by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   309
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   310
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   311
lift_definition mult_float_interval::"nat \<Rightarrow> float interval \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   312
  is "\<lambda>prec. \<lambda>(a1, a2). \<lambda>(b1, b2). bnds_mult prec a1 a2 b1 b2"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   313
  by (auto dest!: bnds_mult[OF sym])
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   314
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   315
lemma lower_mult_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   316
  "lower (mult_float_interval p x y) = fst (bnds_mult p (lower x) (upper x) (lower y) (upper y))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   317
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   318
lemma upper_mult_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   319
  "upper (mult_float_interval p x y) = snd (bnds_mult p (lower x) (upper x) (lower y) (upper y))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   320
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   321
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   322
lemma mult_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   323
  "set_of (real_interval A) * set_of (real_interval B) \<subseteq>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   324
    set_of (real_interval (mult_float_interval prec A B))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   325
proof -
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   326
  let ?bm = "bnds_mult prec (lower A) (upper A) (lower B) (upper B)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   327
  show ?thesis
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   328
    using bnds_mult[of "fst ?bm" "snd ?bm", simplified, OF refl]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   329
    by (auto simp: set_of_eq set_times_def upper_mult_float_interval lower_mult_float_interval)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   330
qed
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   331
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   332
lemma mult_float_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   333
  "x * y \<in>\<^sub>r mult_float_interval prec A B"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   334
  if "x \<in>\<^sub>i real_interval A" "y \<in>\<^sub>i real_interval B"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   335
  using mult_float_interval[of A B] that
75455
91c16c5ad3e9 tidied auto / simp with null arguments
paulson <lp15@cam.ac.uk>
parents: 73537
diff changeset
   336
  by auto
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   337
73537
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   338
lemma mult_float_interval_mono':
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   339
  "set_of (mult_float_interval prec A B) \<subseteq> set_of (mult_float_interval prec X Y)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   340
  if "set_of A \<subseteq> set_of X" "set_of B \<subseteq> set_of Y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   341
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   342
  apply transfer
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   343
  unfolding bnds_mult_def atLeastatMost_subset_iff float_plus_down.rep_eq float_plus_up.rep_eq
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   344
  by (auto simp: float_plus_down.rep_eq float_plus_up.rep_eq mult_float_mono1 mult_float_mono2)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   345
73537
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   346
lemma mult_float_interval_mono:
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   347
  "mult_float_interval prec A B \<le> mult_float_interval prec X Y"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   348
  if "A \<le> X" "B \<le> Y"
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   349
  using mult_float_interval_mono'[of A X B Y prec] that
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   350
  by (simp add: set_of_subset_iff')
56db8559eadb fixed problematic addition operation in the 'approximation' package (previous version used much too high precision sometimes)
Manuel Eberl <eberlm@in.tum.de>
parents: 71037
diff changeset
   351
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   352
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   353
definition map_bnds :: "(nat \<Rightarrow> float \<Rightarrow> float) \<Rightarrow> (nat \<Rightarrow> float \<Rightarrow> float) \<Rightarrow>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   354
                           nat \<Rightarrow> (float \<times> float) \<Rightarrow> (float \<times> float)" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   355
  "map_bnds lb ub prec = (\<lambda>(l,u). (lb prec l, ub prec u))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   356
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   357
lemma map_bnds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   358
  assumes "(lf, uf) = map_bnds lb ub prec (l, u)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   359
  assumes "mono f"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   360
  assumes "x \<in> {real_of_float l..real_of_float u}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   361
  assumes "real_of_float (lb prec l) \<le> f (real_of_float l)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   362
  assumes "real_of_float (ub prec u) \<ge> f (real_of_float u)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   363
  shows   "f x \<in> {real_of_float lf..real_of_float uf}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   364
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   365
  from assms have "real_of_float lf = real_of_float (lb prec l)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   366
    by (simp add: map_bnds_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   367
  also have "real_of_float (lb prec l) \<le> f (real_of_float l)"  by fact
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   368
  also from assms have "\<dots> \<le> f x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   369
    by (intro monoD[OF \<open>mono f\<close>]) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   370
  finally have lf: "real_of_float lf \<le> f x" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   371
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   372
  from assms have "f x \<le> f (real_of_float u)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   373
    by (intro monoD[OF \<open>mono f\<close>]) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   374
  also have "\<dots> \<le> real_of_float (ub prec u)" by fact
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   375
  also from assms have "\<dots> = real_of_float uf"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   376
    by (simp add: map_bnds_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   377
  finally have uf: "f x \<le> real_of_float uf" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   378
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   379
  from lf uf show ?thesis by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   380
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   381
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   382
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   383
section "Square root"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   384
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   385
text \<open>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   386
The square root computation is implemented as newton iteration. As first first step we use the
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   387
nearest power of two greater than the square root.
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   388
\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   389
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   390
fun sqrt_iteration :: "nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   391
"sqrt_iteration prec 0 x = Float 1 ((bitlen \<bar>mantissa x\<bar> + exponent x) div 2 + 1)" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   392
"sqrt_iteration prec (Suc m) x = (let y = sqrt_iteration prec m x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   393
                                  in Float 1 (- 1) * float_plus_up prec y (float_divr prec x y))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   394
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   395
lemma compute_sqrt_iteration_base[code]:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   396
  shows "sqrt_iteration prec n (Float m e) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   397
    (if n = 0 then Float 1 ((if m = 0 then 0 else bitlen \<bar>m\<bar> + e) div 2 + 1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   398
    else (let y = sqrt_iteration prec (n - 1) (Float m e) in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   399
      Float 1 (- 1) * float_plus_up prec y (float_divr prec (Float m e) y)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   400
  using bitlen_Float by (cases n) simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   401
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   402
function ub_sqrt lb_sqrt :: "nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   403
"ub_sqrt prec x = (if 0 < x then (sqrt_iteration prec prec x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   404
              else if x < 0 then - lb_sqrt prec (- x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   405
                            else 0)" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   406
"lb_sqrt prec x = (if 0 < x then (float_divl prec x (sqrt_iteration prec prec x))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   407
              else if x < 0 then - ub_sqrt prec (- x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   408
                            else 0)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   409
by pat_completeness auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   410
termination by (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if x < 0 then 1 else 0))", auto)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   411
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   412
declare lb_sqrt.simps[simp del]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   413
declare ub_sqrt.simps[simp del]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   414
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   415
lemma sqrt_ub_pos_pos_1:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   416
  assumes "sqrt x < b" and "0 < b" and "0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   417
  shows "sqrt x < (b + x / b)/2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   418
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   419
  from assms have "0 < (b - sqrt x)\<^sup>2 " by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   420
  also have "\<dots> = b\<^sup>2 - 2 * b * sqrt x + (sqrt x)\<^sup>2" by algebra
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   421
  also have "\<dots> = b\<^sup>2 - 2 * b * sqrt x + x" using assms by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   422
  finally have "0 < b\<^sup>2 - 2 * b * sqrt x + x" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   423
  hence "0 < b / 2 - sqrt x + x / (2 * b)" using assms
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   424
    by (simp add: field_simps power2_eq_square)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   425
  thus ?thesis by (simp add: field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   426
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   427
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   428
lemma sqrt_iteration_bound:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   429
  assumes "0 < real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   430
  shows "sqrt x < sqrt_iteration prec n x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   431
proof (induct n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   432
  case 0
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   433
  show ?case
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   434
  proof (cases x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   435
    case (Float m e)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   436
    hence "0 < m"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   437
      using assms
70817
dd675800469d dedicated fact collections for algebraic simplification rules potentially splitting goals
haftmann
parents: 70350
diff changeset
   438
      by (auto simp: algebra_split_simps)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   439
    hence "0 < sqrt m" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   440
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   441
    have int_nat_bl: "(nat (bitlen m)) = bitlen m"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   442
      using bitlen_nonneg by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   443
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   444
    have "x = (m / 2^nat (bitlen m)) * 2 powr (e + (nat (bitlen m)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   445
      unfolding Float by (auto simp: powr_realpow[symmetric] field_simps powr_add)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   446
    also have "\<dots> < 1 * 2 powr (e + nat (bitlen m))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   447
    proof (rule mult_strict_right_mono, auto)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   448
      show "m < 2^nat (bitlen m)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   449
        using bitlen_bounds[OF \<open>0 < m\<close>, THEN conjunct2]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   450
        unfolding of_int_less_iff[of m, symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   451
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   452
    finally have "sqrt x < sqrt (2 powr (e + bitlen m))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   453
      unfolding int_nat_bl by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   454
    also have "\<dots> \<le> 2 powr ((e + bitlen m) div 2 + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   455
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   456
      let ?E = "e + bitlen m"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   457
      have E_mod_pow: "2 powr (?E mod 2) < 4"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   458
      proof (cases "?E mod 2 = 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   459
        case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   460
        thus ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   461
      next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   462
        case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   463
        have "0 \<le> ?E mod 2" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   464
        have "?E mod 2 < 2" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   465
        from this[THEN zless_imp_add1_zle]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   466
        have "?E mod 2 \<le> 0" using False by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   467
        from xt1(5)[OF \<open>0 \<le> ?E mod 2\<close> this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   468
        show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   469
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   470
      hence "sqrt (2 powr (?E mod 2)) < sqrt (2 * 2)"
66280
0c5eb47e2696 Adapted Approximation_Bounds to changes in Multiset
eberlm <eberlm@in.tum.de>
parents: 65582
diff changeset
   471
        by (intro real_sqrt_less_mono) auto
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   472
      hence E_mod_pow: "sqrt (2 powr (?E mod 2)) < 2" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   473
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   474
      have E_eq: "2 powr ?E = 2 powr (?E div 2 + ?E div 2 + ?E mod 2)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   475
        by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   476
      have "sqrt (2 powr ?E) = sqrt (2 powr (?E div 2) * 2 powr (?E div 2) * 2 powr (?E mod 2))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   477
        unfolding E_eq unfolding powr_add[symmetric] by (metis of_int_add)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   478
      also have "\<dots> = 2 powr (?E div 2) * sqrt (2 powr (?E mod 2))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   479
        unfolding real_sqrt_mult[of _ "2 powr (?E mod 2)"] real_sqrt_abs2 by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   480
      also have "\<dots> < 2 powr (?E div 2) * 2 powr 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   481
        by (rule mult_strict_left_mono) (auto intro: E_mod_pow)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   482
      also have "\<dots> = 2 powr (?E div 2 + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   483
        unfolding add.commute[of _ 1] powr_add[symmetric] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   484
      finally show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   485
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   486
    finally show ?thesis using \<open>0 < m\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   487
      unfolding Float
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   488
      by (subst compute_sqrt_iteration_base) (simp add: ac_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   489
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   490
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   491
  case (Suc n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   492
  let ?b = "sqrt_iteration prec n x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   493
  have "0 < sqrt x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   494
    using \<open>0 < real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   495
  also have "\<dots> < real_of_float ?b"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   496
    using Suc .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   497
  finally have "sqrt x < (?b + x / ?b)/2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   498
    using sqrt_ub_pos_pos_1[OF Suc _ \<open>0 < real_of_float x\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   499
  also have "\<dots> \<le> (?b + (float_divr prec x ?b))/2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   500
    by (rule divide_right_mono, auto simp add: float_divr)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   501
  also have "\<dots> = (Float 1 (- 1)) * (?b + (float_divr prec x ?b))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   502
    by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   503
  also have "\<dots> \<le> (Float 1 (- 1)) * (float_plus_up prec ?b (float_divr prec x ?b))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   504
    by (auto simp add: algebra_simps float_plus_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   505
  finally show ?case
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   506
    unfolding sqrt_iteration.simps Let_def distrib_left .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   507
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   508
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   509
lemma sqrt_iteration_lower_bound:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   510
  assumes "0 < real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   511
  shows "0 < real_of_float (sqrt_iteration prec n x)" (is "0 < ?sqrt")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   512
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   513
  have "0 < sqrt x" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   514
  also have "\<dots> < ?sqrt" using sqrt_iteration_bound[OF assms] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   515
  finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   516
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   517
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   518
lemma lb_sqrt_lower_bound:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   519
  assumes "0 \<le> real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   520
  shows "0 \<le> real_of_float (lb_sqrt prec x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   521
proof (cases "0 < x")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   522
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   523
  hence "0 < real_of_float x" and "0 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   524
    using \<open>0 \<le> real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   525
  hence "0 < sqrt_iteration prec prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   526
    using sqrt_iteration_lower_bound by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   527
  hence "0 \<le> real_of_float (float_divl prec x (sqrt_iteration prec prec x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   528
    using float_divl_lower_bound[OF \<open>0 \<le> x\<close>] unfolding less_eq_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   529
  thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   530
    unfolding lb_sqrt.simps using True by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   531
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   532
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   533
  with \<open>0 \<le> real_of_float x\<close> have "real_of_float x = 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   534
  thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   535
    unfolding lb_sqrt.simps by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   536
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   537
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   538
lemma bnds_sqrt': "sqrt x \<in> {(lb_sqrt prec x) .. (ub_sqrt prec x)}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   539
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   540
  have lb: "lb_sqrt prec x \<le> sqrt x" if "0 < x" for x :: float
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   541
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   542
    from that have "0 < real_of_float x" and "0 \<le> real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   543
    hence sqrt_gt0: "0 < sqrt x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   544
    hence sqrt_ub: "sqrt x < sqrt_iteration prec prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   545
      using sqrt_iteration_bound by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   546
    have "(float_divl prec x (sqrt_iteration prec prec x)) \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   547
          x / (sqrt_iteration prec prec x)" by (rule float_divl)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   548
    also have "\<dots> < x / sqrt x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   549
      by (rule divide_strict_left_mono[OF sqrt_ub \<open>0 < real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   550
               mult_pos_pos[OF order_less_trans[OF sqrt_gt0 sqrt_ub] sqrt_gt0]])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   551
    also have "\<dots> = sqrt x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   552
      unfolding inverse_eq_iff_eq[of _ "sqrt x", symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   553
                sqrt_divide_self_eq[OF \<open>0 \<le> real_of_float x\<close>, symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   554
    finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   555
      unfolding lb_sqrt.simps if_P[OF \<open>0 < x\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   556
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   557
  have ub: "sqrt x \<le> ub_sqrt prec x" if "0 < x" for x :: float
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   558
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   559
    from that have "0 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   560
    hence "0 < sqrt x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   561
    hence "sqrt x < sqrt_iteration prec prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   562
      using sqrt_iteration_bound by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   563
    then show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   564
      unfolding ub_sqrt.simps if_P[OF \<open>0 < x\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   565
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   566
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   567
    using lb[of "-x"] ub[of "-x"] lb[of x] ub[of x]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   568
    by (auto simp add: lb_sqrt.simps ub_sqrt.simps real_sqrt_minus)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   569
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   570
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   571
lemma bnds_sqrt: "\<forall>(x::real) lx ux.
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   572
  (l, u) = (lb_sqrt prec lx, ub_sqrt prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> sqrt x \<and> sqrt x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   573
proof ((rule allI) +, rule impI, erule conjE, rule conjI)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   574
  fix x :: real
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   575
  fix lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   576
  assume "(l, u) = (lb_sqrt prec lx, ub_sqrt prec ux)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   577
    and x: "x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   578
  hence l: "l = lb_sqrt prec lx " and u: "u = ub_sqrt prec ux" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   579
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   580
  have "sqrt lx \<le> sqrt x" using x by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   581
  from order_trans[OF _ this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   582
  show "l \<le> sqrt x" unfolding l using bnds_sqrt'[of lx prec] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   583
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   584
  have "sqrt x \<le> sqrt ux" using x by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   585
  from order_trans[OF this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   586
  show "sqrt x \<le> u" unfolding u using bnds_sqrt'[of ux prec] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   587
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   588
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   589
lift_definition sqrt_float_interval::"nat \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   590
  is "\<lambda>prec. \<lambda>(lx, ux). (lb_sqrt prec lx, ub_sqrt prec ux)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   591
  using bnds_sqrt'
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   592
  by auto (meson order_trans real_sqrt_le_iff)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   593
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   594
lemma lower_float_interval: "lower (sqrt_float_interval prec X) = lb_sqrt prec (lower X)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   595
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   596
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   597
lemma upper_float_interval: "upper (sqrt_float_interval prec X) = ub_sqrt prec (upper X)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   598
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   599
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   600
lemma sqrt_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   601
  "sqrt ` set_of (real_interval X) \<subseteq> set_of (real_interval (sqrt_float_interval prec X))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   602
  using bnds_sqrt
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   603
  by (auto simp: set_of_eq lower_float_interval upper_float_interval)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   604
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   605
lemma sqrt_float_intervalI: "sqrt x \<in>\<^sub>r sqrt_float_interval p X" if "x \<in>\<^sub>r X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   606
  using sqrt_float_interval[of X p] that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   607
  by auto
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   608
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   609
section "Arcus tangens and \<pi>"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   610
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   611
subsection "Compute arcus tangens series"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   612
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   613
text \<open>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   614
As first step we implement the computation of the arcus tangens series. This is only valid in the range
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67573
diff changeset
   615
\<^term>\<open>{-1 :: real .. 1}\<close>. This is used to compute \<pi> and then the entire arcus tangens.
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   616
\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   617
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   618
fun ub_arctan_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   619
and lb_arctan_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   620
  "ub_arctan_horner prec 0 k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   621
| "ub_arctan_horner prec (Suc n) k x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   622
      (rapprox_rat prec 1 k) (- float_round_down prec (x * (lb_arctan_horner prec n (k + 2) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   623
| "lb_arctan_horner prec 0 k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   624
| "lb_arctan_horner prec (Suc n) k x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   625
      (lapprox_rat prec 1 k) (- float_round_up prec (x * (ub_arctan_horner prec n (k + 2) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   626
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   627
lemma arctan_0_1_bounds':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   628
  assumes "0 \<le> real_of_float y" "real_of_float y \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   629
    and "even n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   630
  shows "arctan (sqrt y) \<in>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   631
      {(sqrt y * lb_arctan_horner prec n 1 y) .. (sqrt y * ub_arctan_horner prec (Suc n) 1 y)}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   632
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   633
  let ?c = "\<lambda>i. (- 1) ^ i * (1 / (i * 2 + (1::nat)) * sqrt y ^ (i * 2 + 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   634
  let ?S = "\<lambda>n. \<Sum> i=0..<n. ?c i"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   635
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   636
  have "0 \<le> sqrt y" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   637
  have "sqrt y \<le> 1" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   638
  from \<open>even n\<close> obtain m where "2 * m = n" by (blast elim: evenE)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   639
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   640
  have "arctan (sqrt y) \<in> { ?S n .. ?S (Suc n) }"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   641
  proof (cases "sqrt y = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   642
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   643
    then show ?thesis by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   644
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   645
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   646
    hence "0 < sqrt y" using \<open>0 \<le> sqrt y\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   647
    hence prem: "0 < 1 / (0 * 2 + (1::nat)) * sqrt y ^ (0 * 2 + 1)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   648
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   649
    have "\<bar> sqrt y \<bar> \<le> 1"  using \<open>0 \<le> sqrt y\<close> \<open>sqrt y \<le> 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   650
    from mp[OF summable_Leibniz(2)[OF zeroseq_arctan_series[OF this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   651
      monoseq_arctan_series[OF this]] prem, THEN spec, of m, unfolded \<open>2 * m = n\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   652
    show ?thesis unfolding arctan_series[OF \<open>\<bar> sqrt y \<bar> \<le> 1\<close>] Suc_eq_plus1 atLeast0LessThan .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   653
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   654
  note arctan_bounds = this[unfolded atLeastAtMost_iff]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   655
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   656
  have F: "\<And>n. 2 * Suc n + 1 = 2 * n + 1 + 2" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   657
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   658
  note bounds = horner_bounds[where s=1 and f="\<lambda>i. 2 * i + 1" and j'=0
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   659
    and lb="\<lambda>n i k x. lb_arctan_horner prec n k x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   660
    and ub="\<lambda>n i k x. ub_arctan_horner prec n k x",
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   661
    OF \<open>0 \<le> real_of_float y\<close> F lb_arctan_horner.simps ub_arctan_horner.simps]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   662
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   663
  have "(sqrt y * lb_arctan_horner prec n 1 y) \<le> arctan (sqrt y)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   664
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   665
    have "(sqrt y * lb_arctan_horner prec n 1 y) \<le> ?S n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   666
      using bounds(1) \<open>0 \<le> sqrt y\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   667
      apply (simp only: power_add power_one_right mult.assoc[symmetric] sum_distrib_right[symmetric])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   668
      apply (simp only: mult.commute[where 'a=real] mult.commute[of _ "2::nat"] power_mult)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   669
      apply (auto intro!: mult_left_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   670
      done
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   671
    also have "\<dots> \<le> arctan (sqrt y)" using arctan_bounds ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   672
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   673
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   674
  moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   675
  have "arctan (sqrt y) \<le> (sqrt y * ub_arctan_horner prec (Suc n) 1 y)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   676
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   677
    have "arctan (sqrt y) \<le> ?S (Suc n)" using arctan_bounds ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   678
    also have "\<dots> \<le> (sqrt y * ub_arctan_horner prec (Suc n) 1 y)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   679
      using bounds(2)[of "Suc n"] \<open>0 \<le> sqrt y\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   680
      apply (simp only: power_add power_one_right mult.assoc[symmetric] sum_distrib_right[symmetric])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   681
      apply (simp only: mult.commute[where 'a=real] mult.commute[of _ "2::nat"] power_mult)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   682
      apply (auto intro!: mult_left_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   683
      done
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   684
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   685
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   686
  ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   687
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   688
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   689
lemma arctan_0_1_bounds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   690
  assumes "0 \<le> real_of_float y" "real_of_float y \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   691
  shows "arctan (sqrt y) \<in>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   692
    {(sqrt y * lb_arctan_horner prec (get_even n) 1 y) ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   693
      (sqrt y * ub_arctan_horner prec (get_odd n) 1 y)}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   694
  using
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   695
    arctan_0_1_bounds'[OF assms, of n prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   696
    arctan_0_1_bounds'[OF assms, of "n + 1" prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   697
    arctan_0_1_bounds'[OF assms, of "n - 1" prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   698
  by (auto simp: get_even_def get_odd_def odd_pos
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   699
    simp del: ub_arctan_horner.simps lb_arctan_horner.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   700
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   701
lemma arctan_lower_bound:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   702
  assumes "0 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   703
  shows "x / (1 + x\<^sup>2) \<le> arctan x" (is "?l x \<le> _")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   704
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   705
  have "?l x - arctan x \<le> ?l 0 - arctan 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   706
    using assms
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   707
    by (intro DERIV_nonpos_imp_nonincreasing[where f="\<lambda>x. ?l x - arctan x"])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   708
      (auto intro!: derivative_eq_intros simp: add_nonneg_eq_0_iff field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   709
  thus ?thesis by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   710
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   711
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   712
lemma arctan_divide_mono: "0 < x \<Longrightarrow> x \<le> y \<Longrightarrow> arctan y / y \<le> arctan x / x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   713
  by (rule DERIV_nonpos_imp_nonincreasing[where f="\<lambda>x. arctan x / x"])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   714
    (auto intro!: derivative_eq_intros divide_nonpos_nonneg
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   715
      simp: inverse_eq_divide arctan_lower_bound)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   716
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   717
lemma arctan_mult_mono: "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> x * arctan y \<le> y * arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   718
  using arctan_divide_mono[of x y] by (cases "x = 0") (simp_all add: field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   719
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   720
lemma arctan_mult_le:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   721
  assumes "0 \<le> x" "x \<le> y" "y * z \<le> arctan y"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   722
  shows "x * z \<le> arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   723
proof (cases "x = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   724
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   725
  then show ?thesis by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   726
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   727
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   728
  with assms have "z \<le> arctan y / y" by (simp add: field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   729
  also have "\<dots> \<le> arctan x / x" using assms \<open>x \<noteq> 0\<close> by (auto intro!: arctan_divide_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   730
  finally show ?thesis using assms \<open>x \<noteq> 0\<close> by (simp add: field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   731
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   732
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   733
lemma arctan_le_mult:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   734
  assumes "0 < x" "x \<le> y" "arctan x \<le> x * z"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   735
  shows "arctan y \<le> y * z"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   736
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   737
  from assms have "arctan y / y \<le> arctan x / x" by (auto intro!: arctan_divide_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   738
  also have "\<dots> \<le> z" using assms by (auto simp: field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   739
  finally show ?thesis using assms by (simp add: field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   740
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   741
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   742
lemma arctan_0_1_bounds_le:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   743
  assumes "0 \<le> x" "x \<le> 1" "0 < real_of_float xl" "real_of_float xl \<le> x * x" "x * x \<le> real_of_float xu" "real_of_float xu \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   744
  shows "arctan x \<in>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   745
      {x * lb_arctan_horner p1 (get_even n) 1 xu .. x * ub_arctan_horner p2 (get_odd n) 1 xl}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   746
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   747
  from assms have "real_of_float xl \<le> 1" "sqrt (real_of_float xl) \<le> x" "x \<le> sqrt (real_of_float xu)" "0 \<le> real_of_float xu"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   748
    "0 \<le> real_of_float xl" "0 < sqrt (real_of_float xl)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   749
    by (auto intro!: real_le_rsqrt real_le_lsqrt simp: power2_eq_square)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   750
  from arctan_0_1_bounds[OF \<open>0 \<le> real_of_float xu\<close>  \<open>real_of_float xu \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   751
  have "sqrt (real_of_float xu) * real_of_float (lb_arctan_horner p1 (get_even n) 1 xu) \<le> arctan (sqrt (real_of_float xu))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   752
    by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   753
  from arctan_mult_le[OF \<open>0 \<le> x\<close> \<open>x \<le> sqrt _\<close>  this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   754
  have "x * real_of_float (lb_arctan_horner p1 (get_even n) 1 xu) \<le> arctan x" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   755
  moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   756
  from arctan_0_1_bounds[OF \<open>0 \<le> real_of_float xl\<close>  \<open>real_of_float xl \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   757
  have "arctan (sqrt (real_of_float xl)) \<le> sqrt (real_of_float xl) * real_of_float (ub_arctan_horner p2 (get_odd n) 1 xl)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   758
    by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   759
  from arctan_le_mult[OF \<open>0 < sqrt xl\<close> \<open>sqrt xl \<le> x\<close> this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   760
  have "arctan x \<le> x * real_of_float (ub_arctan_horner p2 (get_odd n) 1 xl)" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   761
  ultimately show ?thesis by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   762
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   763
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   764
lemma arctan_0_1_bounds_round:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   765
  assumes "0 \<le> real_of_float x" "real_of_float x \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   766
  shows "arctan x \<in>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   767
      {real_of_float x * lb_arctan_horner p1 (get_even n) 1 (float_round_up (Suc p2) (x * x)) ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   768
        real_of_float x * ub_arctan_horner p3 (get_odd n) 1 (float_round_down (Suc p4) (x * x))}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   769
  using assms
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   770
  apply (cases "x > 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   771
   apply (intro arctan_0_1_bounds_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   772
   apply (auto simp: float_round_down.rep_eq float_round_up.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   773
    intro!: truncate_up_le1 mult_le_one truncate_down_le truncate_up_le truncate_down_pos
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   774
      mult_pos_pos)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   775
  done
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   776
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   777
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   778
subsection "Compute \<pi>"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   779
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   780
definition ub_pi :: "nat \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   781
  "ub_pi prec =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   782
    (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   783
      A = rapprox_rat prec 1 5 ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   784
      B = lapprox_rat prec 1 239
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   785
    in ((Float 1 2) * float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   786
      ((Float 1 2) * float_round_up prec (A * (ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   787
        (float_round_down (Suc prec) (A * A)))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   788
      (- float_round_down prec (B * (lb_arctan_horner prec (get_even (prec div 14 + 1)) 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   789
        (float_round_up (Suc prec) (B * B)))))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   790
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   791
definition lb_pi :: "nat \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   792
  "lb_pi prec =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   793
    (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   794
      A = lapprox_rat prec 1 5 ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   795
      B = rapprox_rat prec 1 239
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   796
    in ((Float 1 2) * float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   797
      ((Float 1 2) * float_round_down prec (A * (lb_arctan_horner prec (get_even (prec div 4 + 1)) 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   798
        (float_round_up (Suc prec) (A * A)))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   799
      (- float_round_up prec (B * (ub_arctan_horner prec (get_odd (prec div 14 + 1)) 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   800
        (float_round_down (Suc prec) (B * B)))))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   801
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   802
lemma pi_boundaries: "pi \<in> {(lb_pi n) .. (ub_pi n)}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   803
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   804
  have machin_pi: "pi = 4 * (4 * arctan (1 / 5) - arctan (1 / 239))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   805
    unfolding machin[symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   806
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   807
  {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   808
    fix prec n :: nat
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   809
    fix k :: int
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   810
    assume "1 < k" hence "0 \<le> k" and "0 < k" and "1 \<le> k" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   811
    let ?k = "rapprox_rat prec 1 k"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   812
    let ?kl = "float_round_down (Suc prec) (?k * ?k)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   813
    have "1 div k = 0" using div_pos_pos_trivial[OF _ \<open>1 < k\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   814
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   815
    have "0 \<le> real_of_float ?k" by (rule order_trans[OF _ rapprox_rat]) (auto simp add: \<open>0 \<le> k\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   816
    have "real_of_float ?k \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   817
      by (auto simp add: \<open>0 < k\<close> \<open>1 \<le> k\<close> less_imp_le
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   818
        intro!: mult_le_one order_trans[OF _ rapprox_rat] rapprox_rat_le1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   819
    have "1 / k \<le> ?k" using rapprox_rat[where x=1 and y=k] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   820
    hence "arctan (1 / k) \<le> arctan ?k" by (rule arctan_monotone')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   821
    also have "\<dots> \<le> (?k * ub_arctan_horner prec (get_odd n) 1 ?kl)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   822
      using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?k\<close> \<open>real_of_float ?k \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   823
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   824
    finally have "arctan (1 / k) \<le> ?k * ub_arctan_horner prec (get_odd n) 1 ?kl" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   825
  } note ub_arctan = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   826
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   827
  {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   828
    fix prec n :: nat
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   829
    fix k :: int
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   830
    assume "1 < k" hence "0 \<le> k" and "0 < k" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   831
    let ?k = "lapprox_rat prec 1 k"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   832
    let ?ku = "float_round_up (Suc prec) (?k * ?k)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   833
    have "1 div k = 0" using div_pos_pos_trivial[OF _ \<open>1 < k\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   834
    have "1 / k \<le> 1" using \<open>1 < k\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   835
    have "0 \<le> real_of_float ?k" using lapprox_rat_nonneg[where x=1 and y=k, OF zero_le_one \<open>0 \<le> k\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   836
      by (auto simp add: \<open>1 div k = 0\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   837
    have "0 \<le> real_of_float (?k * ?k)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   838
    have "real_of_float ?k \<le> 1" using lapprox_rat by (rule order_trans, auto simp add: \<open>1 / k \<le> 1\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   839
    hence "real_of_float (?k * ?k) \<le> 1" using \<open>0 \<le> real_of_float ?k\<close> by (auto intro!: mult_le_one)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   840
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   841
    have "?k \<le> 1 / k" using lapprox_rat[where x=1 and y=k] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   842
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   843
    have "?k * lb_arctan_horner prec (get_even n) 1 ?ku \<le> arctan ?k"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   844
      using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?k\<close> \<open>real_of_float ?k \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   845
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   846
    also have "\<dots> \<le> arctan (1 / k)" using \<open>?k \<le> 1 / k\<close> by (rule arctan_monotone')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   847
    finally have "?k * lb_arctan_horner prec (get_even n) 1 ?ku \<le> arctan (1 / k)" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   848
  } note lb_arctan = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   849
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   850
  have "pi \<le> ub_pi n "
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   851
    unfolding ub_pi_def machin_pi Let_def times_float.rep_eq Float_num
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   852
    using lb_arctan[of 239] ub_arctan[of 5] powr_realpow[of 2 2]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   853
    by (intro mult_left_mono float_plus_up_le float_plus_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   854
      (auto intro!: mult_left_mono float_round_down_le float_round_up_le diff_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   855
  moreover have "lb_pi n \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   856
    unfolding lb_pi_def machin_pi Let_def times_float.rep_eq Float_num
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   857
    using lb_arctan[of 5] ub_arctan[of 239]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   858
    by (intro mult_left_mono float_plus_up_le float_plus_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   859
      (auto intro!: mult_left_mono float_round_down_le float_round_up_le diff_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   860
  ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   861
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   862
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   863
lift_definition pi_float_interval::"nat \<Rightarrow> float interval" is "\<lambda>prec. (lb_pi prec, ub_pi prec)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   864
  using pi_boundaries
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   865
  by (auto intro: order_trans)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   866
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   867
lemma lower_pi_float_interval: "lower (pi_float_interval prec) = lb_pi prec"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   868
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   869
lemma upper_pi_float_interval: "upper (pi_float_interval prec) = ub_pi prec"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   870
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   871
lemma pi_float_interval: "pi \<in> set_of (real_interval (pi_float_interval prec))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   872
  using pi_boundaries
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   873
  by (auto simp: set_of_eq lower_pi_float_interval upper_pi_float_interval)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
   874
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   875
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   876
subsection "Compute arcus tangens in the entire domain"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   877
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   878
function lb_arctan :: "nat \<Rightarrow> float \<Rightarrow> float" and ub_arctan :: "nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   879
  "lb_arctan prec x =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   880
    (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   881
      ub_horner = \<lambda> x. float_round_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   882
        (x *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   883
          ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x)));
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   884
      lb_horner = \<lambda> x. float_round_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   885
        (x *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   886
          lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   887
    in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   888
      if x < 0 then - ub_arctan prec (-x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   889
      else if x \<le> Float 1 (- 1) then lb_horner x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   890
      else if x \<le> Float 1 1 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   891
        Float 1 1 *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   892
        lb_horner
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   893
          (float_divl prec x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   894
            (float_plus_up prec 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   895
              (ub_sqrt prec (float_plus_up prec 1 (float_round_up prec (x * x))))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   896
      else let inv = float_divr prec 1 x in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   897
        if inv > 1 then 0
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   898
        else float_plus_down prec (lb_pi prec * Float 1 (- 1)) ( - ub_horner inv))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   899
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   900
| "ub_arctan prec x =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   901
    (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   902
      lb_horner = \<lambda> x. float_round_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   903
        (x *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   904
          lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x))) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   905
      ub_horner = \<lambda> x. float_round_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   906
        (x *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   907
          ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   908
    in if x < 0 then - lb_arctan prec (-x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   909
    else if x \<le> Float 1 (- 1) then ub_horner x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   910
    else if x \<le> Float 1 1 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   911
      let y = float_divr prec x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   912
        (float_plus_down
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   913
          (Suc prec) 1 (lb_sqrt prec (float_plus_down prec 1 (float_round_down prec (x * x)))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   914
      in if y > 1 then ub_pi prec * Float 1 (- 1) else Float 1 1 * ub_horner y
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   915
    else float_plus_up prec (ub_pi prec * Float 1 (- 1)) ( - lb_horner (float_divl prec 1 x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   916
by pat_completeness auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   917
termination
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   918
by (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if x < 0 then 1 else 0))", auto)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   919
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   920
declare ub_arctan_horner.simps[simp del]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   921
declare lb_arctan_horner.simps[simp del]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   922
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   923
lemma lb_arctan_bound':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   924
  assumes "0 \<le> real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   925
  shows "lb_arctan prec x \<le> arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   926
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   927
  have "\<not> x < 0" and "0 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   928
    using \<open>0 \<le> real_of_float x\<close> by (auto intro!: truncate_up_le )
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   929
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   930
  let "?ub_horner x" =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   931
      "x * ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   932
    and "?lb_horner x" =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   933
      "x * lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   934
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   935
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   936
  proof (cases "x \<le> Float 1 (- 1)")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   937
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   938
    hence "real_of_float x \<le> 1" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   939
    from arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   940
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   941
      unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] if_P[OF True] using \<open>0 \<le> x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   942
      by (auto intro!: float_round_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   943
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   944
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   945
    hence "0 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   946
    let ?R = "1 + sqrt (1 + real_of_float x * real_of_float x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   947
    let ?sxx = "float_plus_up prec 1 (float_round_up prec (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   948
    let ?fR = "float_plus_up prec 1 (ub_sqrt prec ?sxx)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   949
    let ?DIV = "float_divl prec x ?fR"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   950
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   951
    have divisor_gt0: "0 < ?R" by (auto intro: add_pos_nonneg)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   952
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   953
    have "sqrt (1 + x*x) \<le> sqrt ?sxx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   954
      by (auto simp: float_plus_up.rep_eq plus_up_def float_round_up.rep_eq intro!: truncate_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   955
    also have "\<dots> \<le> ub_sqrt prec ?sxx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   956
      using bnds_sqrt'[of ?sxx prec] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   957
    finally
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   958
    have "sqrt (1 + x*x) \<le> ub_sqrt prec ?sxx" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   959
    hence "?R \<le> ?fR" by (auto simp: float_plus_up.rep_eq plus_up_def intro!: truncate_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   960
    hence "0 < ?fR" and "0 < real_of_float ?fR" using \<open>0 < ?R\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   961
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   962
    have monotone: "?DIV \<le> x / ?R"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   963
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   964
      have "?DIV \<le> real_of_float x / ?fR" by (rule float_divl)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   965
      also have "\<dots> \<le> x / ?R" by (rule divide_left_mono[OF \<open>?R \<le> ?fR\<close> \<open>0 \<le> real_of_float x\<close> mult_pos_pos[OF order_less_le_trans[OF divisor_gt0 \<open>?R \<le> real_of_float ?fR\<close>] divisor_gt0]])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   966
      finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   967
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   968
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   969
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   970
    proof (cases "x \<le> Float 1 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   971
      case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   972
      have "x \<le> sqrt (1 + x * x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   973
        using real_sqrt_sum_squares_ge2[where x=1, unfolded numeral_2_eq_2] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   974
      also note \<open>\<dots> \<le> (ub_sqrt prec ?sxx)\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   975
      finally have "real_of_float x \<le> ?fR"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   976
        by (auto simp: float_plus_up.rep_eq plus_up_def intro!: truncate_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   977
      moreover have "?DIV \<le> real_of_float x / ?fR"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   978
        by (rule float_divl)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   979
      ultimately have "real_of_float ?DIV \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   980
        unfolding divide_le_eq_1_pos[OF \<open>0 < real_of_float ?fR\<close>, symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   981
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   982
      have "0 \<le> real_of_float ?DIV"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   983
        using float_divl_lower_bound[OF \<open>0 \<le> x\<close>] \<open>0 < ?fR\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   984
        unfolding less_eq_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   985
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   986
      from arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float (?DIV)\<close> \<open>real_of_float (?DIV) \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   987
      have "Float 1 1 * ?lb_horner ?DIV \<le> 2 * arctan ?DIV"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   988
        by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   989
      also have "\<dots> \<le> 2 * arctan (x / ?R)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   990
        using arctan_monotone'[OF monotone] by (auto intro!: mult_left_mono arctan_monotone')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   991
      also have "2 * arctan (x / ?R) = arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   992
        using arctan_half[symmetric] unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   993
      finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   994
        unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   995
          if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_P[OF True]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   996
        by (auto simp: float_round_down.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   997
          intro!: order_trans[OF mult_left_mono[OF truncate_down]])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   998
    next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
   999
      case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1000
      hence "2 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1001
      hence "1 \<le> real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1002
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1003
      let "?invx" = "float_divr prec 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1004
      have "0 \<le> arctan x" using arctan_monotone'[OF \<open>0 \<le> real_of_float x\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1005
        using arctan_tan[of 0, unfolded tan_zero] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1006
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1007
      show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1008
      proof (cases "1 < ?invx")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1009
        case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1010
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1011
          unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1012
            if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_not_P[OF False] if_P[OF True]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1013
          using \<open>0 \<le> arctan x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1014
      next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1015
        case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1016
        hence "real_of_float ?invx \<le> 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1017
        have "0 \<le> real_of_float ?invx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1018
          by (rule order_trans[OF _ float_divr]) (auto simp add: \<open>0 \<le> real_of_float x\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1019
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1020
        have "1 / x \<noteq> 0" and "0 < 1 / x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1021
          using \<open>0 < real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1022
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1023
        have "arctan (1 / x) \<le> arctan ?invx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1024
          unfolding one_float.rep_eq[symmetric] by (rule arctan_monotone', rule float_divr)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1025
        also have "\<dots> \<le> ?ub_horner ?invx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1026
          using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?invx\<close> \<open>real_of_float ?invx \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1027
          by (auto intro!: float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1028
        also note float_round_up
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1029
        finally have "pi / 2 - float_round_up prec (?ub_horner ?invx) \<le> arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1030
          using \<open>0 \<le> arctan x\<close> arctan_inverse[OF \<open>1 / x \<noteq> 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1031
          unfolding sgn_pos[OF \<open>0 < 1 / real_of_float x\<close>] le_diff_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1032
        moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1033
        have "lb_pi prec * Float 1 (- 1) \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1034
          unfolding Float_num times_divide_eq_right mult_1_left using pi_boundaries by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1035
        ultimately
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1036
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1037
          unfolding lb_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1038
            if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_not_P[OF \<open>\<not> x \<le> Float 1 1\<close>] if_not_P[OF False]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1039
          by (auto intro!: float_plus_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1040
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1041
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1042
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1043
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1044
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1045
lemma ub_arctan_bound':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1046
  assumes "0 \<le> real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1047
  shows "arctan x \<le> ub_arctan prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1048
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1049
  have "\<not> x < 0" and "0 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1050
    using \<open>0 \<le> real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1051
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1052
  let "?ub_horner x" =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1053
    "float_round_up prec (x * ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (float_round_down (Suc prec) (x * x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1054
  let "?lb_horner x" =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1055
    "float_round_down prec (x * lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (float_round_up (Suc prec) (x * x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1056
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1057
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1058
  proof (cases "x \<le> Float 1 (- 1)")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1059
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1060
    hence "real_of_float x \<le> 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1061
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1062
      unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>] if_P[OF True]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1063
      using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1064
      by (auto intro!: float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1065
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1066
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1067
    hence "0 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1068
    let ?R = "1 + sqrt (1 + real_of_float x * real_of_float x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1069
    let ?sxx = "float_plus_down prec 1 (float_round_down prec (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1070
    let ?fR = "float_plus_down (Suc prec) 1 (lb_sqrt prec ?sxx)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1071
    let ?DIV = "float_divr prec x ?fR"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1072
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1073
    have sqr_ge0: "0 \<le> 1 + real_of_float x * real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1074
      using sum_power2_ge_zero[of 1 "real_of_float x", unfolded numeral_2_eq_2] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1075
    hence "0 \<le> real_of_float (1 + x*x)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1076
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1077
    hence divisor_gt0: "0 < ?R" by (auto intro: add_pos_nonneg)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1078
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1079
    have "lb_sqrt prec ?sxx \<le> sqrt ?sxx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1080
      using bnds_sqrt'[of ?sxx] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1081
    also have "\<dots> \<le> sqrt (1 + x*x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1082
      by (auto simp: float_plus_down.rep_eq plus_down_def float_round_down.rep_eq truncate_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1083
    finally have "lb_sqrt prec ?sxx \<le> sqrt (1 + x*x)" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1084
    hence "?fR \<le> ?R"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1085
      by (auto simp: float_plus_down.rep_eq plus_down_def truncate_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1086
    have "0 < real_of_float ?fR"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1087
      by (auto simp: float_plus_down.rep_eq plus_down_def float_round_down.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1088
        intro!: truncate_down_ge1 lb_sqrt_lower_bound order_less_le_trans[OF zero_less_one]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1089
        truncate_down_nonneg add_nonneg_nonneg)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1090
    have monotone: "x / ?R \<le> (float_divr prec x ?fR)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1091
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1092
      from divide_left_mono[OF \<open>?fR \<le> ?R\<close> \<open>0 \<le> real_of_float x\<close> mult_pos_pos[OF divisor_gt0 \<open>0 < real_of_float ?fR\<close>]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1093
      have "x / ?R \<le> x / ?fR" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1094
      also have "\<dots> \<le> ?DIV" by (rule float_divr)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1095
      finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1096
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1097
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1098
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1099
    proof (cases "x \<le> Float 1 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1100
      case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1101
      show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1102
      proof (cases "?DIV > 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1103
        case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1104
        have "pi / 2 \<le> ub_pi prec * Float 1 (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1105
          unfolding Float_num times_divide_eq_right mult_1_left using pi_boundaries by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1106
        from order_less_le_trans[OF arctan_ubound this, THEN less_imp_le]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1107
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1108
          unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1109
            if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_P[OF \<open>x \<le> Float 1 1\<close>] if_P[OF True] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1110
      next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1111
        case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1112
        hence "real_of_float ?DIV \<le> 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1113
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1114
        have "0 \<le> x / ?R"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1115
          using \<open>0 \<le> real_of_float x\<close> \<open>0 < ?R\<close> unfolding zero_le_divide_iff by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1116
        hence "0 \<le> real_of_float ?DIV"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1117
          using monotone by (rule order_trans)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1118
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1119
        have "arctan x = 2 * arctan (x / ?R)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1120
          using arctan_half unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1121
        also have "\<dots> \<le> 2 * arctan (?DIV)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1122
          using arctan_monotone'[OF monotone] by (auto intro!: mult_left_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1123
        also have "\<dots> \<le> (Float 1 1 * ?ub_horner ?DIV)" unfolding Float_num
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1124
          using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?DIV\<close> \<open>real_of_float ?DIV \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1125
          by (auto intro!: float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1126
        finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1127
          unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1128
            if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_P[OF \<open>x \<le> Float 1 1\<close>] if_not_P[OF False] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1129
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1130
    next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1131
      case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1132
      hence "2 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1133
      hence "1 \<le> real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1134
      hence "0 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1135
      hence "0 < x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1136
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1137
      let "?invx" = "float_divl prec 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1138
      have "0 \<le> arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1139
        using arctan_monotone'[OF \<open>0 \<le> real_of_float x\<close>] and arctan_tan[of 0, unfolded tan_zero] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1140
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1141
      have "real_of_float ?invx \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1142
        unfolding less_float_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1143
        by (rule order_trans[OF float_divl])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1144
          (auto simp add: \<open>1 \<le> real_of_float x\<close> divide_le_eq_1_pos[OF \<open>0 < real_of_float x\<close>])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1145
      have "0 \<le> real_of_float ?invx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1146
        using \<open>0 < x\<close> by (intro float_divl_lower_bound) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1147
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1148
      have "1 / x \<noteq> 0" and "0 < 1 / x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1149
        using \<open>0 < real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1150
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1151
      have "(?lb_horner ?invx) \<le> arctan (?invx)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1152
        using arctan_0_1_bounds_round[OF \<open>0 \<le> real_of_float ?invx\<close> \<open>real_of_float ?invx \<le> 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1153
        by (auto intro!: float_round_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1154
      also have "\<dots> \<le> arctan (1 / x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1155
        unfolding one_float.rep_eq[symmetric] by (rule arctan_monotone') (rule float_divl)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1156
      finally have "arctan x \<le> pi / 2 - (?lb_horner ?invx)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1157
        using \<open>0 \<le> arctan x\<close> arctan_inverse[OF \<open>1 / x \<noteq> 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1158
        unfolding sgn_pos[OF \<open>0 < 1 / x\<close>] le_diff_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1159
      moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1160
      have "pi / 2 \<le> ub_pi prec * Float 1 (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1161
        unfolding Float_num times_divide_eq_right mult_1_right
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1162
        using pi_boundaries by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1163
      ultimately
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1164
      show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1165
        unfolding ub_arctan.simps Let_def if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1166
          if_not_P[OF \<open>\<not> x \<le> Float 1 (- 1)\<close>] if_not_P[OF False]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1167
        by (auto intro!: float_round_up_le float_plus_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1168
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1169
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1170
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1171
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1172
lemma arctan_boundaries: "arctan x \<in> {(lb_arctan prec x) .. (ub_arctan prec x)}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1173
proof (cases "0 \<le> x")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1174
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1175
  hence "0 \<le> real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1176
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1177
    using ub_arctan_bound'[OF \<open>0 \<le> real_of_float x\<close>] lb_arctan_bound'[OF \<open>0 \<le> real_of_float x\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1178
    unfolding atLeastAtMost_iff by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1179
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1180
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1181
  let ?mx = "-x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1182
  from False have "x < 0" and "0 \<le> real_of_float ?mx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1183
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1184
  hence bounds: "lb_arctan prec ?mx \<le> arctan ?mx \<and> arctan ?mx \<le> ub_arctan prec ?mx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1185
    using ub_arctan_bound'[OF \<open>0 \<le> real_of_float ?mx\<close>] lb_arctan_bound'[OF \<open>0 \<le> real_of_float ?mx\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1186
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1187
    unfolding minus_float.rep_eq arctan_minus lb_arctan.simps[where x=x]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1188
      ub_arctan.simps[where x=x] Let_def if_P[OF \<open>x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1189
    unfolding atLeastAtMost_iff using bounds[unfolded minus_float.rep_eq arctan_minus]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1190
    by (simp add: arctan_minus)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1191
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1192
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1193
lemma bnds_arctan: "\<forall> (x::real) lx ux. (l, u) = (lb_arctan prec lx, ub_arctan prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> arctan x \<and> arctan x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1194
proof (rule allI, rule allI, rule allI, rule impI)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1195
  fix x :: real
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1196
  fix lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1197
  assume "(l, u) = (lb_arctan prec lx, ub_arctan prec ux) \<and> x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1198
  hence l: "lb_arctan prec lx = l "
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1199
    and u: "ub_arctan prec ux = u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1200
    and x: "x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1201
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1202
  show "l \<le> arctan x \<and> arctan x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1203
  proof
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1204
    show "l \<le> arctan x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1205
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1206
      from arctan_boundaries[of lx prec, unfolded l]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1207
      have "l \<le> arctan lx" by (auto simp del: lb_arctan.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1208
      also have "\<dots> \<le> arctan x" using x by (auto intro: arctan_monotone')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1209
      finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1210
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1211
    show "arctan x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1212
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1213
      have "arctan x \<le> arctan ux" using x by (auto intro: arctan_monotone')
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1214
      also have "\<dots> \<le> u" using arctan_boundaries[of ux prec, unfolded u] by (auto simp del: ub_arctan.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1215
      finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1216
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1217
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1218
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1219
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1220
lemmas [simp del] = lb_arctan.simps ub_arctan.simps
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1221
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1222
lemma lb_arctan: "arctan (real_of_float x) \<le> y \<Longrightarrow> real_of_float (lb_arctan prec x) \<le> y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1223
  and ub_arctan: "y \<le> arctan x \<Longrightarrow> y \<le> ub_arctan prec x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1224
  for x::float and y::real
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1225
  using arctan_boundaries[of x prec] by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1226
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1227
lift_definition arctan_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1228
  is "\<lambda>prec. \<lambda>(lx, ux). (lb_arctan prec lx, ub_arctan prec ux)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1229
  by (auto intro!: lb_arctan ub_arctan arctan_monotone')
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1230
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1231
lemma lower_arctan_float_interval: "lower (arctan_float_interval p x) = lb_arctan p (lower x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1232
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1233
lemma upper_arctan_float_interval: "upper (arctan_float_interval p x) = ub_arctan p (upper x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1234
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1235
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1236
lemma arctan_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1237
  "arctan ` set_of (real_interval x) \<subseteq> set_of (real_interval (arctan_float_interval p x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1238
  by (auto simp: set_of_eq lower_arctan_float_interval upper_arctan_float_interval
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1239
      intro!: lb_arctan ub_arctan arctan_monotone')
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1240
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1241
lemma arctan_float_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1242
  "arctan x \<in>\<^sub>r arctan_float_interval p X" if "x \<in>\<^sub>r X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1243
  using arctan_float_interval[of X p] that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1244
  by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1245
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1246
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1247
section "Sinus and Cosinus"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1248
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1249
subsection "Compute the cosinus and sinus series"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1250
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1251
fun ub_sin_cos_aux :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1252
and lb_sin_cos_aux :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1253
  "ub_sin_cos_aux prec 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1254
| "ub_sin_cos_aux prec (Suc n) i k x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1255
    (rapprox_rat prec 1 k) (-
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1256
      float_round_down prec (x * (lb_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1257
| "lb_sin_cos_aux prec 0 i k x = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1258
| "lb_sin_cos_aux prec (Suc n) i k x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1259
    (lapprox_rat prec 1 k) (-
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1260
      float_round_up prec (x * (ub_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1261
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1262
lemma cos_aux:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1263
  shows "(lb_sin_cos_aux prec n 1 1 (x * x)) \<le> (\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i))) * x ^(2 * i))" (is "?lb")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1264
  and "(\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i))) * x^(2 * i)) \<le> (ub_sin_cos_aux prec n 1 1 (x * x))" (is "?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1265
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1266
  have "0 \<le> real_of_float (x * x)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1267
  let "?f n" = "fact (2 * n) :: nat"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1268
  have f_eq: "?f (Suc n) = ?f n * ((\<lambda>i. i + 2) ^^ n) 1 * (((\<lambda>i. i + 2) ^^ n) 1 + 1)" for n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1269
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1270
    have "\<And>m. ((\<lambda>i. i + 2) ^^ n) m = m + 2 * n" by (induct n) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1271
    then show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1272
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1273
  from horner_bounds[where lb="lb_sin_cos_aux prec" and ub="ub_sin_cos_aux prec" and j'=0,
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1274
    OF \<open>0 \<le> real_of_float (x * x)\<close> f_eq lb_sin_cos_aux.simps ub_sin_cos_aux.simps]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1275
  show ?lb and ?ub
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1276
    by (auto simp add: power_mult power2_eq_square[of "real_of_float x"])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1277
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1278
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1279
lemma lb_sin_cos_aux_zero_le_one: "lb_sin_cos_aux prec n i j 0 \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1280
  by (cases j n rule: nat.exhaust[case_product nat.exhaust])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1281
    (auto intro!: float_plus_down_le order_trans[OF lapprox_rat])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1282
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1283
lemma one_le_ub_sin_cos_aux: "odd n \<Longrightarrow> 1 \<le> ub_sin_cos_aux prec n i (Suc 0) 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1284
  by (cases n) (auto intro!: float_plus_up_le order_trans[OF _ rapprox_rat])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1285
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1286
lemma cos_boundaries:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1287
  assumes "0 \<le> real_of_float x" and "x \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1288
  shows "cos x \<in> {(lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) .. (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1289
proof (cases "real_of_float x = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1290
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1291
  hence "real_of_float x \<noteq> 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1292
  hence "0 < x" and "0 < real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1293
    using \<open>0 \<le> real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1294
  have "0 < x * x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1295
    using \<open>0 < x\<close> by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1296
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1297
  have morph_to_if_power: "(\<Sum> i=0..<n. (-1::real) ^ i * (1/(fact (2 * i))) * x ^ (2 * i)) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1298
    (\<Sum> i = 0 ..< 2 * n. (if even(i) then ((- 1) ^ (i div 2))/((fact i)) else 0) * x ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1299
    (is "?sum = ?ifsum") for x n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1300
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1301
    have "?sum = ?sum + (\<Sum> j = 0 ..< n. 0)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1302
    also have "\<dots> =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1303
      (\<Sum> j = 0 ..< n. (- 1) ^ ((2 * j) div 2) / ((fact (2 * j))) * x ^(2 * j)) + (\<Sum> j = 0 ..< n. 0)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1304
    also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. if even i then (- 1) ^ (i div 2) / ((fact i)) * x ^ i else 0)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1305
      unfolding sum_split_even_odd atLeast0LessThan ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1306
    also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. (if even i then (- 1) ^ (i div 2) / ((fact i)) else 0) * x ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1307
      by (rule sum.cong) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1308
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1309
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1310
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1311
  { fix n :: nat assume "0 < n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1312
    hence "0 < 2 * n" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1313
    obtain t where "0 < t" and "t < real_of_float x" and
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1314
      cos_eq: "cos x = (\<Sum> i = 0 ..< 2 * n. (if even(i) then ((- 1) ^ (i div 2))/((fact i)) else 0) * (real_of_float x) ^ i)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1315
      + (cos (t + 1/2 * (2 * n) * pi) / (fact (2*n))) * (real_of_float x)^(2*n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1316
      (is "_ = ?SUM + ?rest / ?fact * ?pow")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1317
      using Maclaurin_cos_expansion2[OF \<open>0 < real_of_float x\<close> \<open>0 < 2 * n\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1318
      unfolding cos_coeff_def atLeast0LessThan by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1319
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1320
    have "cos t * (- 1) ^ n = cos t * cos (n * pi) + sin t * sin (n * pi)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1321
    also have "\<dots> = cos (t + n * pi)" by (simp add: cos_add)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1322
    also have "\<dots> = ?rest" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1323
    finally have "cos t * (- 1) ^ n = ?rest" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1324
    moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1325
    have "t \<le> pi / 2" using \<open>t < real_of_float x\<close> and \<open>x \<le> pi / 2\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1326
    hence "0 \<le> cos t" using \<open>0 < t\<close> and cos_ge_zero by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1327
    ultimately have even: "even n \<Longrightarrow> 0 \<le> ?rest" and odd: "odd n \<Longrightarrow> 0 \<le> - ?rest " by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1328
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1329
    have "0 < ?fact" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1330
    have "0 < ?pow" using \<open>0 < real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1331
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1332
    {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1333
      assume "even n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1334
      have "(lb_sin_cos_aux prec n 1 1 (x * x)) \<le> ?SUM"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1335
        unfolding morph_to_if_power[symmetric] using cos_aux by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1336
      also have "\<dots> \<le> cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1337
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1338
        from even[OF \<open>even n\<close>] \<open>0 < ?fact\<close> \<open>0 < ?pow\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1339
        have "0 \<le> (?rest / ?fact) * ?pow" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1340
        thus ?thesis unfolding cos_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1341
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1342
      finally have "(lb_sin_cos_aux prec n 1 1 (x * x)) \<le> cos x" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1343
    } note lb = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1344
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1345
    {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1346
      assume "odd n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1347
      have "cos x \<le> ?SUM"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1348
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1349
        from \<open>0 < ?fact\<close> and \<open>0 < ?pow\<close> and odd[OF \<open>odd n\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1350
        have "0 \<le> (- ?rest) / ?fact * ?pow"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1351
          by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1352
        thus ?thesis unfolding cos_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1353
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1354
      also have "\<dots> \<le> (ub_sin_cos_aux prec n 1 1 (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1355
        unfolding morph_to_if_power[symmetric] using cos_aux by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1356
      finally have "cos x \<le> (ub_sin_cos_aux prec n 1 1 (x * x))" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1357
    } note ub = this and lb
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1358
  } note ub = this(1) and lb = this(2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1359
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1360
  have "cos x \<le> (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1361
    using ub[OF odd_pos[OF get_odd] get_odd] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1362
  moreover have "(lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) \<le> cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1363
  proof (cases "0 < get_even n")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1364
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1365
    show ?thesis using lb[OF True get_even] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1366
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1367
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1368
    hence "get_even n = 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1369
    have "- (pi / 2) \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1370
      by (rule order_trans[OF _ \<open>0 < real_of_float x\<close>[THEN less_imp_le]]) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1371
    with \<open>x \<le> pi / 2\<close> show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1372
      unfolding \<open>get_even n = 0\<close> lb_sin_cos_aux.simps minus_float.rep_eq zero_float.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1373
      using cos_ge_zero by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1374
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1375
  ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1376
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1377
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1378
  hence "x = 0"
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  1379
    by (simp add: real_of_float_eq)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1380
  thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1381
    using lb_sin_cos_aux_zero_le_one one_le_ub_sin_cos_aux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1382
    by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1383
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1384
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1385
lemma sin_aux:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1386
  assumes "0 \<le> real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1387
  shows "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1388
      (\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i + 1))) * x^(2 * i + 1))" (is "?lb")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1389
    and "(\<Sum> i=0..<n. (- 1) ^ i * (1/(fact (2 * i + 1))) * x^(2 * i + 1)) \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1390
      (x * ub_sin_cos_aux prec n 2 1 (x * x))" (is "?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1391
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1392
  have "0 \<le> real_of_float (x * x)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1393
  let "?f n" = "fact (2 * n + 1) :: nat"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1394
  have f_eq: "?f (Suc n) = ?f n * ((\<lambda>i. i + 2) ^^ n) 2 * (((\<lambda>i. i + 2) ^^ n) 2 + 1)" for n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1395
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1396
    have F: "\<And>m. ((\<lambda>i. i + 2) ^^ n) m = m + 2 * n" by (induct n) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1397
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1398
      unfolding F by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1399
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1400
  from horner_bounds[where lb="lb_sin_cos_aux prec" and ub="ub_sin_cos_aux prec" and j'=0,
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1401
    OF \<open>0 \<le> real_of_float (x * x)\<close> f_eq lb_sin_cos_aux.simps ub_sin_cos_aux.simps]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1402
  show "?lb" and "?ub" using \<open>0 \<le> real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1403
    apply (simp_all only: power_add power_one_right mult.assoc[symmetric] sum_distrib_right[symmetric])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1404
    apply (simp_all only: mult.commute[where 'a=real] of_nat_fact)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1405
    apply (auto intro!: mult_left_mono simp add: power_mult power2_eq_square[of "real_of_float x"])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1406
    done
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1407
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1408
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1409
lemma sin_boundaries:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1410
  assumes "0 \<le> real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1411
    and "x \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1412
  shows "sin x \<in> {(x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) .. (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1413
proof (cases "real_of_float x = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1414
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1415
  hence "real_of_float x \<noteq> 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1416
  hence "0 < x" and "0 < real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1417
    using \<open>0 \<le> real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1418
  have "0 < x * x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1419
    using \<open>0 < x\<close> by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1420
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1421
  have sum_morph: "(\<Sum>j = 0 ..< n. (- 1) ^ (((2 * j + 1) - Suc 0) div 2) / ((fact (2 * j + 1))) * x ^(2 * j + 1)) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1422
    (\<Sum> i = 0 ..< 2 * n. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * x ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1423
    (is "?SUM = _") for x :: real and n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1424
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1425
    have pow: "!!i. x ^ (2 * i + 1) = x * x ^ (2 * i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1426
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1427
    have "?SUM = (\<Sum> j = 0 ..< n. 0) + ?SUM"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1428
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1429
    also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. if even i then 0 else (- 1) ^ ((i - Suc 0) div 2) / ((fact i)) * x ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1430
      unfolding sum_split_even_odd atLeast0LessThan ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1431
    also have "\<dots> = (\<Sum> i = 0 ..< 2 * n. (if even i then 0 else (- 1) ^ ((i - Suc 0) div 2) / ((fact i))) * x ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1432
      by (rule sum.cong) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1433
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1434
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1435
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1436
  { fix n :: nat assume "0 < n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1437
    hence "0 < 2 * n + 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1438
    obtain t where "0 < t" and "t < real_of_float x" and
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1439
      sin_eq: "sin x = (\<Sum> i = 0 ..< 2 * n + 1. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * (real_of_float x) ^ i)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1440
      + (sin (t + 1/2 * (2 * n + 1) * pi) / (fact (2*n + 1))) * (real_of_float x)^(2*n + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1441
      (is "_ = ?SUM + ?rest / ?fact * ?pow")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1442
      using Maclaurin_sin_expansion3[OF \<open>0 < 2 * n + 1\<close> \<open>0 < real_of_float x\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1443
      unfolding sin_coeff_def atLeast0LessThan by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1444
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1445
    have "?rest = cos t * (- 1) ^ n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1446
      unfolding sin_add cos_add of_nat_add distrib_right distrib_left by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1447
    moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1448
    have "t \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1449
      using \<open>t < real_of_float x\<close> and \<open>x \<le> pi / 2\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1450
    hence "0 \<le> cos t"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1451
      using \<open>0 < t\<close> and cos_ge_zero by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1452
    ultimately have even: "even n \<Longrightarrow> 0 \<le> ?rest" and odd: "odd n \<Longrightarrow> 0 \<le> - ?rest"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1453
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1454
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1455
    have "0 < ?fact"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1456
      by (simp del: fact_Suc)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1457
    have "0 < ?pow"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1458
      using \<open>0 < real_of_float x\<close> by (rule zero_less_power)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1459
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1460
    {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1461
      assume "even n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1462
      have "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1463
            (\<Sum> i = 0 ..< 2 * n. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * (real_of_float x) ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1464
        using sin_aux[OF \<open>0 \<le> real_of_float x\<close>] unfolding sum_morph[symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1465
      also have "\<dots> \<le> ?SUM" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1466
      also have "\<dots> \<le> sin x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1467
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1468
        from even[OF \<open>even n\<close>] \<open>0 < ?fact\<close> \<open>0 < ?pow\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1469
        have "0 \<le> (?rest / ?fact) * ?pow" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1470
        thus ?thesis unfolding sin_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1471
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1472
      finally have "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \<le> sin x" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1473
    } note lb = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1474
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1475
    {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1476
      assume "odd n"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1477
      have "sin x \<le> ?SUM"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1478
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1479
        from \<open>0 < ?fact\<close> and \<open>0 < ?pow\<close> and odd[OF \<open>odd n\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1480
        have "0 \<le> (- ?rest) / ?fact * ?pow"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1481
          by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1482
        thus ?thesis unfolding sin_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1483
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1484
      also have "\<dots> \<le> (\<Sum> i = 0 ..< 2 * n. (if even(i) then 0 else ((- 1) ^ ((i - Suc 0) div 2))/((fact i))) * (real_of_float x) ^ i)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1485
         by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1486
      also have "\<dots> \<le> (x * ub_sin_cos_aux prec n 2 1 (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1487
        using sin_aux[OF \<open>0 \<le> real_of_float x\<close>] unfolding sum_morph[symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1488
      finally have "sin x \<le> (x * ub_sin_cos_aux prec n 2 1 (x * x))" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1489
    } note ub = this and lb
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1490
  } note ub = this(1) and lb = this(2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1491
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1492
  have "sin x \<le> (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1493
    using ub[OF odd_pos[OF get_odd] get_odd] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1494
  moreover have "(x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) \<le> sin x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1495
  proof (cases "0 < get_even n")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1496
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1497
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1498
      using lb[OF True get_even] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1499
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1500
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1501
    hence "get_even n = 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1502
    with \<open>x \<le> pi / 2\<close> \<open>0 \<le> real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1503
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1504
      unfolding \<open>get_even n = 0\<close> ub_sin_cos_aux.simps minus_float.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1505
      using sin_ge_zero by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1506
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1507
  ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1508
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1509
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1510
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1511
  proof (cases "n = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1512
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1513
    thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1514
      unfolding \<open>n = 0\<close> get_even_def get_odd_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1515
      using \<open>real_of_float x = 0\<close> lapprox_rat[where x="-1" and y=1] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1516
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1517
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1518
    with not0_implies_Suc obtain m where "n = Suc m" by blast
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1519
    thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1520
      unfolding \<open>n = Suc m\<close> get_even_def get_odd_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1521
      using \<open>real_of_float x = 0\<close> rapprox_rat[where x=1 and y=1] lapprox_rat[where x=1 and y=1]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1522
      by (cases "even (Suc m)") auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1523
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1524
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1525
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1526
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1527
subsection "Compute the cosinus in the entire domain"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1528
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1529
definition lb_cos :: "nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1530
"lb_cos prec x = (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1531
    horner = \<lambda> x. lb_sin_cos_aux prec (get_even (prec div 4 + 1)) 1 1 (x * x) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1532
    half = \<lambda> x. if x < 0 then - 1 else float_plus_down prec (Float 1 1 * x * x) (- 1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1533
  in if x < Float 1 (- 1) then horner x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1534
else if x < 1          then half (horner (x * Float 1 (- 1)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1535
                       else half (half (horner (x * Float 1 (- 2)))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1536
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1537
definition ub_cos :: "nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1538
"ub_cos prec x = (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1539
    horner = \<lambda> x. ub_sin_cos_aux prec (get_odd (prec div 4 + 1)) 1 1 (x * x) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1540
    half = \<lambda> x. float_plus_up prec (Float 1 1 * x * x) (- 1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1541
  in if x < Float 1 (- 1) then horner x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1542
else if x < 1          then half (horner (x * Float 1 (- 1)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1543
                       else half (half (horner (x * Float 1 (- 2)))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1544
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1545
lemma lb_cos:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1546
  assumes "0 \<le> real_of_float x" and "x \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1547
  shows "cos x \<in> {(lb_cos prec x) .. (ub_cos prec x)}" (is "?cos x \<in> {(?lb x) .. (?ub x) }")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1548
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1549
  have x_half[symmetric]: "cos x = 2 * cos (x / 2) * cos (x / 2) - 1" for x :: real
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1550
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1551
    have "cos x = cos (x / 2 + x / 2)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1552
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1553
    also have "\<dots> = cos (x / 2) * cos (x / 2) + sin (x / 2) * sin (x / 2) - sin (x / 2) * sin (x / 2) + cos (x / 2) * cos (x / 2) - 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1554
      unfolding cos_add by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1555
    also have "\<dots> = 2 * cos (x / 2) * cos (x / 2) - 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1556
      by algebra
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1557
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1558
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1559
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1560
  have "\<not> x < 0" using \<open>0 \<le> real_of_float x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1561
  let "?ub_horner x" = "ub_sin_cos_aux prec (get_odd (prec div 4 + 1)) 1 1 (x * x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1562
  let "?lb_horner x" = "lb_sin_cos_aux prec (get_even (prec div 4 + 1)) 1 1 (x * x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1563
  let "?ub_half x" = "float_plus_up prec (Float 1 1 * x * x) (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1564
  let "?lb_half x" = "if x < 0 then - 1 else float_plus_down prec (Float 1 1 * x * x) (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1565
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1566
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1567
  proof (cases "x < Float 1 (- 1)")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1568
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1569
    hence "x \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1570
      using pi_ge_two by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1571
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1572
      unfolding lb_cos_def[where x=x] ub_cos_def[where x=x]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1573
        if_not_P[OF \<open>\<not> x < 0\<close>] if_P[OF \<open>x < Float 1 (- 1)\<close>] Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1574
      using cos_boundaries[OF \<open>0 \<le> real_of_float x\<close> \<open>x \<le> pi / 2\<close>] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1575
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1576
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1577
    { fix y x :: float let ?x2 = "(x * Float 1 (- 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1578
      assume "y \<le> cos ?x2" and "-pi \<le> x" and "x \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1579
      hence "- (pi / 2) \<le> ?x2" and "?x2 \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1580
        using pi_ge_two unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1581
      hence "0 \<le> cos ?x2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1582
        by (rule cos_ge_zero)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1583
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1584
      have "(?lb_half y) \<le> cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1585
      proof (cases "y < 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1586
        case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1587
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1588
          using cos_ge_minus_one unfolding if_P[OF True] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1589
      next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1590
        case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1591
        hence "0 \<le> real_of_float y" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1592
        from mult_mono[OF \<open>y \<le> cos ?x2\<close> \<open>y \<le> cos ?x2\<close> \<open>0 \<le> cos ?x2\<close> this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1593
        have "real_of_float y * real_of_float y \<le> cos ?x2 * cos ?x2" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1594
        hence "2 * real_of_float y * real_of_float y \<le> 2 * cos ?x2 * cos ?x2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1595
          by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1596
        hence "2 * real_of_float y * real_of_float y - 1 \<le> 2 * cos (x / 2) * cos (x / 2) - 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1597
          unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1598
        thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1599
          unfolding if_not_P[OF False] x_half Float_num
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1600
          by (auto intro!: float_plus_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1601
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1602
    } note lb_half = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1603
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1604
    { fix y x :: float let ?x2 = "(x * Float 1 (- 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1605
      assume ub: "cos ?x2 \<le> y" and "- pi \<le> x" and "x \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1606
      hence "- (pi / 2) \<le> ?x2" and "?x2 \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1607
        using pi_ge_two unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1608
      hence "0 \<le> cos ?x2" by (rule cos_ge_zero)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1609
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1610
      have "cos x \<le> (?ub_half y)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1611
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1612
        have "0 \<le> real_of_float y"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1613
          using \<open>0 \<le> cos ?x2\<close> ub by (rule order_trans)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1614
        from mult_mono[OF ub ub this \<open>0 \<le> cos ?x2\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1615
        have "cos ?x2 * cos ?x2 \<le> real_of_float y * real_of_float y" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1616
        hence "2 * cos ?x2 * cos ?x2 \<le> 2 * real_of_float y * real_of_float y"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1617
          by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1618
        hence "2 * cos (x / 2) * cos (x / 2) - 1 \<le> 2 * real_of_float y * real_of_float y - 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1619
          unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1620
        thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1621
          unfolding x_half Float_num
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1622
          by (auto intro!: float_plus_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1623
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1624
    } note ub_half = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1625
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1626
    let ?x2 = "x * Float 1 (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1627
    let ?x4 = "x * Float 1 (- 1) * Float 1 (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1628
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1629
    have "-pi \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1630
      using pi_ge_zero[THEN le_imp_neg_le, unfolded minus_zero] \<open>0 \<le> real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1631
      by (rule order_trans)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1632
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1633
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1634
    proof (cases "x < 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1635
      case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1636
      hence "real_of_float x \<le> 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1637
      have "0 \<le> real_of_float ?x2" and "?x2 \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1638
        using pi_ge_two \<open>0 \<le> real_of_float x\<close> using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1639
      from cos_boundaries[OF this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1640
      have lb: "(?lb_horner ?x2) \<le> ?cos ?x2" and ub: "?cos ?x2 \<le> (?ub_horner ?x2)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1641
        by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1642
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1643
      have "(?lb x) \<le> ?cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1644
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1645
        from lb_half[OF lb \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1646
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1647
          unfolding lb_cos_def[where x=x] Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1648
          using \<open>\<not> x < 0\<close> \<open>\<not> x < Float 1 (- 1)\<close> \<open>x < 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1649
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1650
      moreover have "?cos x \<le> (?ub x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1651
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1652
        from ub_half[OF ub \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1653
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1654
          unfolding ub_cos_def[where x=x] Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1655
          using \<open>\<not> x < 0\<close> \<open>\<not> x < Float 1 (- 1)\<close> \<open>x < 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1656
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1657
      ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1658
    next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1659
      case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1660
      have "0 \<le> real_of_float ?x4" and "?x4 \<le> pi / 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1661
        using pi_ge_two \<open>0 \<le> real_of_float x\<close> \<open>x \<le> pi\<close> unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1662
      from cos_boundaries[OF this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1663
      have lb: "(?lb_horner ?x4) \<le> ?cos ?x4" and ub: "?cos ?x4 \<le> (?ub_horner ?x4)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1664
        by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1665
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1666
      have eq_4: "?x2 * Float 1 (- 1) = x * Float 1 (- 2)"
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  1667
        by (auto simp: real_of_float_eq)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1668
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1669
      have "(?lb x) \<le> ?cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1670
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1671
        have "-pi \<le> ?x2" and "?x2 \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1672
          using pi_ge_two \<open>0 \<le> real_of_float x\<close> \<open>x \<le> pi\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1673
        from lb_half[OF lb_half[OF lb this] \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>, unfolded eq_4]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1674
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1675
          unfolding lb_cos_def[where x=x] if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1676
            if_not_P[OF \<open>\<not> x < Float 1 (- 1)\<close>] if_not_P[OF \<open>\<not> x < 1\<close>] Let_def .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1677
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1678
      moreover have "?cos x \<le> (?ub x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1679
      proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1680
        have "-pi \<le> ?x2" and "?x2 \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1681
          using pi_ge_two \<open>0 \<le> real_of_float x\<close> \<open> x \<le> pi\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1682
        from ub_half[OF ub_half[OF ub this] \<open>-pi \<le> x\<close> \<open>x \<le> pi\<close>, unfolded eq_4]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1683
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1684
          unfolding ub_cos_def[where x=x] if_not_P[OF \<open>\<not> x < 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1685
            if_not_P[OF \<open>\<not> x < Float 1 (- 1)\<close>] if_not_P[OF \<open>\<not> x < 1\<close>] Let_def .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1686
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1687
      ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1688
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1689
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1690
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1691
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1692
lemma lb_cos_minus:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1693
  assumes "-pi \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1694
    and "real_of_float x \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1695
  shows "cos (real_of_float(-x)) \<in> {(lb_cos prec (-x)) .. (ub_cos prec (-x))}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1696
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1697
  have "0 \<le> real_of_float (-x)" and "(-x) \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1698
    using \<open>-pi \<le> x\<close> \<open>real_of_float x \<le> 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1699
  from lb_cos[OF this] show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1700
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1701
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1702
definition bnds_cos :: "nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float * float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1703
"bnds_cos prec lx ux = (let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1704
    lpi = float_round_down prec (lb_pi prec) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1705
    upi = float_round_up prec (ub_pi prec) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1706
    k = floor_fl (float_divr prec (lx + lpi) (2 * lpi)) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1707
    lx = float_plus_down prec lx (- k * 2 * (if k < 0 then lpi else upi)) ;
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1708
    ux = float_plus_up prec ux (- k * 2 * (if k < 0 then upi else lpi))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1709
  in   if - lpi \<le> lx \<and> ux \<le> 0    then (lb_cos prec (-lx), ub_cos prec (-ux))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1710
  else if 0 \<le> lx \<and> ux \<le> lpi      then (lb_cos prec ux, ub_cos prec lx)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1711
  else if - lpi \<le> lx \<and> ux \<le> lpi  then (min (lb_cos prec (-lx)) (lb_cos prec ux), Float 1 0)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1712
  else if 0 \<le> lx \<and> ux \<le> 2 * lpi  then (Float (- 1) 0, max (ub_cos prec lx) (ub_cos prec (- (ux - 2 * lpi))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1713
  else if -2 * lpi \<le> lx \<and> ux \<le> 0 then (Float (- 1) 0, max (ub_cos prec (lx + 2 * lpi)) (ub_cos prec (-ux)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1714
                                 else (Float (- 1) 0, Float 1 0))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1715
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1716
lemma floor_int: obtains k :: int where "real_of_int k = (floor_fl f)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1717
  by (simp add: floor_fl_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1718
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1719
lemma cos_periodic_nat[simp]:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1720
  fixes n :: nat
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1721
  shows "cos (x + n * (2 * pi)) = cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1722
proof (induct n arbitrary: x)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1723
  case 0
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1724
  then show ?case by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1725
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1726
  case (Suc n)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1727
  have split_pi_off: "x + (Suc n) * (2 * pi) = (x + n * (2 * pi)) + 2 * pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1728
    unfolding Suc_eq_plus1 of_nat_add of_int_1 distrib_right by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1729
  show ?case
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1730
    unfolding split_pi_off using Suc by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1731
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1732
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1733
lemma cos_periodic_int[simp]:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1734
  fixes i :: int
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1735
  shows "cos (x + i * (2 * pi)) = cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1736
proof (cases "0 \<le> i")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1737
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1738
  hence i_nat: "real_of_int i = nat i" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1739
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1740
    unfolding i_nat by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1741
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1742
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1743
    hence i_nat: "i = - real (nat (-i))" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1744
  have "cos x = cos (x + i * (2 * pi) - i * (2 * pi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1745
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1746
  also have "\<dots> = cos (x + i * (2 * pi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1747
    unfolding i_nat mult_minus_left diff_minus_eq_add by (rule cos_periodic_nat)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1748
  finally show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1749
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1750
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1751
lemma bnds_cos: "\<forall>(x::real) lx ux. (l, u) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1752
  bnds_cos prec lx ux \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> cos x \<and> cos x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1753
proof (rule allI | rule impI | erule conjE)+
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1754
  fix x :: real
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1755
  fix lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1756
  assume bnds: "(l, u) = bnds_cos prec lx ux" and x: "x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1757
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1758
  let ?lpi = "float_round_down prec (lb_pi prec)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1759
  let ?upi = "float_round_up prec (ub_pi prec)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1760
  let ?k = "floor_fl (float_divr prec (lx + ?lpi) (2 * ?lpi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1761
  let ?lx2 = "(- ?k * 2 * (if ?k < 0 then ?lpi else ?upi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1762
  let ?ux2 = "(- ?k * 2 * (if ?k < 0 then ?upi else ?lpi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1763
  let ?lx = "float_plus_down prec lx ?lx2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1764
  let ?ux = "float_plus_up prec ux ?ux2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1765
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1766
  obtain k :: int where k: "k = real_of_float ?k"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1767
    by (rule floor_int)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1768
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1769
  have upi: "pi \<le> ?upi" and lpi: "?lpi \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1770
    using float_round_up[of "ub_pi prec" prec] pi_boundaries[of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1771
      float_round_down[of prec "lb_pi prec"]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1772
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1773
  hence "lx + ?lx2 \<le> x - k * (2 * pi) \<and> x - k * (2 * pi) \<le> ux + ?ux2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1774
    using x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1775
    by (cases "k = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1776
      (auto intro!: add_mono
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1777
        simp add: k [symmetric] uminus_add_conv_diff [symmetric]
70347
e5cd5471c18a official fact collection sign_simps
haftmann
parents: 70097
diff changeset
  1778
        simp del: uminus_add_conv_diff)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1779
  hence "?lx \<le> x - k * (2 * pi) \<and> x - k * (2 * pi) \<le> ?ux"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1780
    by (auto intro!: float_plus_down_le float_plus_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1781
  note lx = this[THEN conjunct1] and ux = this[THEN conjunct2]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1782
  hence lx_less_ux: "?lx \<le> real_of_float ?ux" by (rule order_trans)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1783
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1784
  { assume "- ?lpi \<le> ?lx" and x_le_0: "x - k * (2 * pi) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1785
    with lpi[THEN le_imp_neg_le] lx
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1786
    have pi_lx: "- pi \<le> ?lx" and lx_0: "real_of_float ?lx \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1787
      by simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1788
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1789
    have "(lb_cos prec (- ?lx)) \<le> cos (real_of_float (- ?lx))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1790
      using lb_cos_minus[OF pi_lx lx_0] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1791
    also have "\<dots> \<le> cos (x + (-k) * (2 * pi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1792
      using cos_monotone_minus_pi_0'[OF pi_lx lx x_le_0]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1793
      by (simp only: uminus_float.rep_eq of_int_minus
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1794
        cos_minus mult_minus_left) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1795
    finally have "(lb_cos prec (- ?lx)) \<le> cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1796
      unfolding cos_periodic_int . }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1797
  note negative_lx = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1798
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1799
  { assume "0 \<le> ?lx" and pi_x: "x - k * (2 * pi) \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1800
    with lx
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1801
    have pi_lx: "?lx \<le> pi" and lx_0: "0 \<le> real_of_float ?lx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1802
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1803
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1804
    have "cos (x + (-k) * (2 * pi)) \<le> cos ?lx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1805
      using cos_monotone_0_pi_le[OF lx_0 lx pi_x]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1806
      by (simp only: of_int_minus
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1807
        cos_minus mult_minus_left) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1808
    also have "\<dots> \<le> (ub_cos prec ?lx)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1809
      using lb_cos[OF lx_0 pi_lx] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1810
    finally have "cos x \<le> (ub_cos prec ?lx)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1811
      unfolding cos_periodic_int . }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1812
  note positive_lx = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1813
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1814
  { assume pi_x: "- pi \<le> x - k * (2 * pi)" and "?ux \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1815
    with ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1816
    have pi_ux: "- pi \<le> ?ux" and ux_0: "real_of_float ?ux \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1817
      by simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1818
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1819
    have "cos (x + (-k) * (2 * pi)) \<le> cos (real_of_float (- ?ux))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1820
      using cos_monotone_minus_pi_0'[OF pi_x ux ux_0]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1821
      by (simp only: uminus_float.rep_eq of_int_minus
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1822
          cos_minus mult_minus_left) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1823
    also have "\<dots> \<le> (ub_cos prec (- ?ux))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1824
      using lb_cos_minus[OF pi_ux ux_0, of prec] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1825
    finally have "cos x \<le> (ub_cos prec (- ?ux))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1826
      unfolding cos_periodic_int . }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1827
  note negative_ux = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1828
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1829
  { assume "?ux \<le> ?lpi" and x_ge_0: "0 \<le> x - k * (2 * pi)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1830
    with lpi ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1831
    have pi_ux: "?ux \<le> pi" and ux_0: "0 \<le> real_of_float ?ux"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1832
      by simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1833
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1834
    have "(lb_cos prec ?ux) \<le> cos ?ux"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1835
      using lb_cos[OF ux_0 pi_ux] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1836
    also have "\<dots> \<le> cos (x + (-k) * (2 * pi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1837
      using cos_monotone_0_pi_le[OF x_ge_0 ux pi_ux]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1838
      by (simp only: of_int_minus
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1839
        cos_minus mult_minus_left) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1840
    finally have "(lb_cos prec ?ux) \<le> cos x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1841
      unfolding cos_periodic_int . }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1842
  note positive_ux = this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1843
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1844
  show "l \<le> cos x \<and> cos x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1845
  proof (cases "- ?lpi \<le> ?lx \<and> ?ux \<le> 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1846
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1847
    with bnds have l: "l = lb_cos prec (-?lx)" and u: "u = ub_cos prec (-?ux)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1848
      by (auto simp add: bnds_cos_def Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1849
    from True lpi[THEN le_imp_neg_le] lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1850
    have "- pi \<le> x - k * (2 * pi)" and "x - k * (2 * pi) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1851
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1852
    with True negative_ux negative_lx show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1853
      unfolding l u by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1854
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1855
    case 1: False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1856
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1857
    proof (cases "0 \<le> ?lx \<and> ?ux \<le> ?lpi")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1858
      case True with bnds 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1859
      have l: "l = lb_cos prec ?ux"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1860
        and u: "u = ub_cos prec ?lx"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1861
        by (auto simp add: bnds_cos_def Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1862
      from True lpi lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1863
      have "0 \<le> x - k * (2 * pi)" and "x - k * (2 * pi) \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1864
        by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1865
      with True positive_ux positive_lx show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1866
        unfolding l u by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1867
    next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1868
      case 2: False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1869
      show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1870
      proof (cases "- ?lpi \<le> ?lx \<and> ?ux \<le> ?lpi")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1871
        case Cond: True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1872
        with bnds 1 2 have l: "l = min (lb_cos prec (-?lx)) (lb_cos prec ?ux)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1873
          and u: "u = Float 1 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1874
          by (auto simp add: bnds_cos_def Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1875
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1876
          unfolding u l using negative_lx positive_ux Cond
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1877
          by (cases "x - k * (2 * pi) < 0") (auto simp add: real_of_float_min)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1878
      next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1879
        case 3: False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1880
        show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1881
        proof (cases "0 \<le> ?lx \<and> ?ux \<le> 2 * ?lpi")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1882
          case Cond: True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1883
          with bnds 1 2 3
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1884
          have l: "l = Float (- 1) 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1885
            and u: "u = max (ub_cos prec ?lx) (ub_cos prec (- (?ux - 2 * ?lpi)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1886
            by (auto simp add: bnds_cos_def Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1887
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1888
          have "cos x \<le> real_of_float u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1889
          proof (cases "x - k * (2 * pi) < pi")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1890
            case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1891
            hence "x - k * (2 * pi) \<le> pi" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1892
            from positive_lx[OF Cond[THEN conjunct1] this] show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1893
              unfolding u by (simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1894
          next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1895
            case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1896
            hence "pi \<le> x - k * (2 * pi)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1897
            hence pi_x: "- pi \<le> x - k * (2 * pi) - 2 * pi" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1898
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1899
            have "?ux \<le> 2 * pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1900
              using Cond lpi by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1901
            hence "x - k * (2 * pi) - 2 * pi \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1902
              using ux by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1903
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1904
            have ux_0: "real_of_float (?ux - 2 * ?lpi) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1905
              using Cond by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1906
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1907
            from 2 and Cond have "\<not> ?ux \<le> ?lpi" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1908
            hence "- ?lpi \<le> ?ux - 2 * ?lpi" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1909
            hence pi_ux: "- pi \<le> (?ux - 2 * ?lpi)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1910
              using lpi[THEN le_imp_neg_le] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1911
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1912
            have x_le_ux: "x - k * (2 * pi) - 2 * pi \<le> (?ux - 2 * ?lpi)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1913
              using ux lpi by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1914
            have "cos x = cos (x + (-k) * (2 * pi) + (-1::int) * (2 * pi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1915
              unfolding cos_periodic_int ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1916
            also have "\<dots> \<le> cos ((?ux - 2 * ?lpi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1917
              using cos_monotone_minus_pi_0'[OF pi_x x_le_ux ux_0]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1918
              by (simp only: minus_float.rep_eq of_int_minus of_int_1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1919
                mult_minus_left mult_1_left) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1920
            also have "\<dots> = cos ((- (?ux - 2 * ?lpi)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1921
              unfolding uminus_float.rep_eq cos_minus ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1922
            also have "\<dots> \<le> (ub_cos prec (- (?ux - 2 * ?lpi)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1923
              using lb_cos_minus[OF pi_ux ux_0] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1924
            finally show ?thesis unfolding u by (simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1925
          qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1926
          thus ?thesis unfolding l by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1927
        next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1928
          case 4: False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1929
          show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1930
          proof (cases "-2 * ?lpi \<le> ?lx \<and> ?ux \<le> 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1931
            case Cond: True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1932
            with bnds 1 2 3 4 have l: "l = Float (- 1) 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1933
              and u: "u = max (ub_cos prec (?lx + 2 * ?lpi)) (ub_cos prec (-?ux))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1934
              by (auto simp add: bnds_cos_def Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1935
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1936
            have "cos x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1937
            proof (cases "-pi < x - k * (2 * pi)")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1938
              case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1939
              hence "-pi \<le> x - k * (2 * pi)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1940
              from negative_ux[OF this Cond[THEN conjunct2]] show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1941
                unfolding u by (simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1942
            next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1943
              case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1944
              hence "x - k * (2 * pi) \<le> -pi" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1945
              hence pi_x: "x - k * (2 * pi) + 2 * pi \<le> pi" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1946
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1947
              have "-2 * pi \<le> ?lx" using Cond lpi by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1948
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1949
              hence "0 \<le> x - k * (2 * pi) + 2 * pi" using lx by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1950
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1951
              have lx_0: "0 \<le> real_of_float (?lx + 2 * ?lpi)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1952
                using Cond lpi by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1953
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1954
              from 1 and Cond have "\<not> -?lpi \<le> ?lx" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1955
              hence "?lx + 2 * ?lpi \<le> ?lpi" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1956
              hence pi_lx: "(?lx + 2 * ?lpi) \<le> pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1957
                using lpi[THEN le_imp_neg_le] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1958
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1959
              have lx_le_x: "(?lx + 2 * ?lpi) \<le> x - k * (2 * pi) + 2 * pi"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1960
                using lx lpi by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1961
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1962
              have "cos x = cos (x + (-k) * (2 * pi) + (1 :: int) * (2 * pi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1963
                unfolding cos_periodic_int ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1964
              also have "\<dots> \<le> cos ((?lx + 2 * ?lpi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1965
                using cos_monotone_0_pi_le[OF lx_0 lx_le_x pi_x]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1966
                by (simp only: minus_float.rep_eq of_int_minus of_int_1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1967
                  mult_minus_left mult_1_left) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1968
              also have "\<dots> \<le> (ub_cos prec (?lx + 2 * ?lpi))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1969
                using lb_cos[OF lx_0 pi_lx] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1970
              finally show ?thesis unfolding u by (simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1971
            qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1972
            thus ?thesis unfolding l by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1973
          next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1974
            case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1975
            with bnds 1 2 3 4 show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1976
              by (auto simp add: bnds_cos_def Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1977
          qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1978
        qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1979
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1980
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1981
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1982
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  1983
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1984
lemma bnds_cos_lower: "\<And>x. real_of_float xl \<le> x \<Longrightarrow> x \<le> real_of_float xu \<Longrightarrow> cos x \<le> y \<Longrightarrow> real_of_float (fst (bnds_cos prec xl xu)) \<le> y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1985
  and bnds_cos_upper: "\<And>x. real_of_float xl \<le> x \<Longrightarrow> x \<le> real_of_float xu \<Longrightarrow> y \<le> cos x \<Longrightarrow> y \<le> real_of_float (snd (bnds_cos prec xl xu))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1986
  for xl xu::float and y::real
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1987
  using bnds_cos[of "fst (bnds_cos prec xl xu)" "snd (bnds_cos prec xl xu)" prec]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1988
  by force+
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1989
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1990
lift_definition cos_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1991
  is "\<lambda>prec. \<lambda>(lx, ux). bnds_cos prec lx ux"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1992
  using bnds_cos
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1993
  by auto (metis (full_types) order_refl order_trans)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1994
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1995
lemma lower_cos_float_interval: "lower (cos_float_interval p x) = fst (bnds_cos p (lower x) (upper x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1996
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1997
lemma upper_cos_float_interval: "upper (cos_float_interval p x) = snd (bnds_cos p (lower x) (upper x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1998
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  1999
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2000
lemma cos_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2001
  "cos ` set_of (real_interval x) \<subseteq> set_of (real_interval (cos_float_interval p x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2002
  by (auto simp: set_of_eq bnds_cos_lower bnds_cos_upper lower_cos_float_interval
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2003
      upper_cos_float_interval)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2004
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2005
lemma cos_float_intervalI: "cos x \<in>\<^sub>r cos_float_interval p X" if "x \<in>\<^sub>r X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2006
  using cos_float_interval[of X p] that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2007
  by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2008
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2009
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2010
section "Exponential function"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2011
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2012
subsection "Compute the series of the exponential function"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2013
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2014
fun ub_exp_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2015
  and lb_exp_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2016
where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2017
"ub_exp_horner prec 0 i k x       = 0" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2018
"ub_exp_horner prec (Suc n) i k x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2019
    (rapprox_rat prec 1 (int k)) (float_round_up prec (x * lb_exp_horner prec n (i + 1) (k * i) x))" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2020
"lb_exp_horner prec 0 i k x       = 0" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2021
"lb_exp_horner prec (Suc n) i k x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2022
    (lapprox_rat prec 1 (int k)) (float_round_down prec (x * ub_exp_horner prec n (i + 1) (k * i) x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2023
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2024
lemma bnds_exp_horner:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2025
  assumes "real_of_float x \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2026
  shows "exp x \<in> {lb_exp_horner prec (get_even n) 1 1 x .. ub_exp_horner prec (get_odd n) 1 1 x}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2027
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2028
  have f_eq: "fact (Suc n) = fact n * ((\<lambda>i::nat. i + 1) ^^ n) 1" for n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2029
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2030
    have F: "\<And> m. ((\<lambda>i. i + 1) ^^ n) m = n + m"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2031
      by (induct n) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2032
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2033
      unfolding F by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2034
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2035
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2036
  note bounds = horner_bounds_nonpos[where f="fact" and lb="lb_exp_horner prec" and ub="ub_exp_horner prec" and j'=0 and s=1,
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2037
    OF assms f_eq lb_exp_horner.simps ub_exp_horner.simps]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2038
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2039
  have "lb_exp_horner prec (get_even n) 1 1 x \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2040
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2041
    have "lb_exp_horner prec (get_even n) 1 1 x \<le> (\<Sum>j = 0..<get_even n. 1 / (fact j) * real_of_float x ^ j)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2042
      using bounds(1) by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2043
    also have "\<dots> \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2044
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2045
      obtain t where "\<bar>t\<bar> \<le> \<bar>real_of_float x\<bar>" and "exp x = (\<Sum>m = 0..<get_even n. real_of_float x ^ m / (fact m)) + exp t / (fact (get_even n)) * (real_of_float x) ^ (get_even n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2046
        using Maclaurin_exp_le unfolding atLeast0LessThan by blast
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2047
      moreover have "0 \<le> exp t / (fact (get_even n)) * (real_of_float x) ^ (get_even n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2048
        by (auto simp: zero_le_even_power)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2049
      ultimately show ?thesis using get_odd exp_gt_zero by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2050
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2051
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2052
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2053
  moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2054
  have "exp x \<le> ub_exp_horner prec (get_odd n) 1 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2055
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2056
    have x_less_zero: "real_of_float x ^ get_odd n \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2057
    proof (cases "real_of_float x = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2058
      case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2059
      have "(get_odd n) \<noteq> 0" using get_odd[THEN odd_pos] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2060
      thus ?thesis unfolding True power_0_left by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2061
    next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2062
      case False hence "real_of_float x < 0" using \<open>real_of_float x \<le> 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2063
      show ?thesis by (rule less_imp_le, auto simp add: \<open>real_of_float x < 0\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2064
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2065
    obtain t where "\<bar>t\<bar> \<le> \<bar>real_of_float x\<bar>"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2066
      and "exp x = (\<Sum>m = 0..<get_odd n. (real_of_float x) ^ m / (fact m)) + exp t / (fact (get_odd n)) * (real_of_float x) ^ (get_odd n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2067
      using Maclaurin_exp_le unfolding atLeast0LessThan by blast
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2068
    moreover have "exp t / (fact (get_odd n)) * (real_of_float x) ^ (get_odd n) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2069
      by (auto intro!: mult_nonneg_nonpos divide_nonpos_pos simp add: x_less_zero)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2070
    ultimately have "exp x \<le> (\<Sum>j = 0..<get_odd n. 1 / (fact j) * real_of_float x ^ j)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2071
      using get_odd exp_gt_zero by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2072
    also have "\<dots> \<le> ub_exp_horner prec (get_odd n) 1 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2073
      using bounds(2) by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2074
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2075
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2076
  ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2077
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2078
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2079
lemma ub_exp_horner_nonneg: "real_of_float x \<le> 0 \<Longrightarrow>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2080
  0 \<le> real_of_float (ub_exp_horner prec (get_odd n) (Suc 0) (Suc 0) x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2081
  using bnds_exp_horner[of x prec n]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2082
  by (intro order_trans[OF exp_ge_zero]) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2083
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2084
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2085
subsection "Compute the exponential function on the entire domain"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2086
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2087
function ub_exp :: "nat \<Rightarrow> float \<Rightarrow> float" and lb_exp :: "nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2088
"lb_exp prec x =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2089
  (if 0 < x then float_divl prec 1 (ub_exp prec (-x))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2090
  else
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2091
    let
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2092
      horner = (\<lambda> x. let  y = lb_exp_horner prec (get_even (prec + 2)) 1 1 x in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2093
        if y \<le> 0 then Float 1 (- 2) else y)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2094
    in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2095
      if x < - 1 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2096
        power_down_fl prec (horner (float_divl prec x (- floor_fl x))) (nat (- int_floor_fl x))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2097
      else horner x)" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2098
"ub_exp prec x =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2099
  (if 0 < x then float_divr prec 1 (lb_exp prec (-x))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2100
  else if x < - 1 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2101
    power_up_fl prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2102
      (ub_exp_horner prec (get_odd (prec + 2)) 1 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2103
        (float_divr prec x (- floor_fl x))) (nat (- int_floor_fl x))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2104
  else ub_exp_horner prec (get_odd (prec + 2)) 1 1 x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2105
  by pat_completeness auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2106
termination
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2107
  by (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if 0 < x then 1 else 0))") auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2108
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2109
lemma exp_m1_ge_quarter: "(1 / 4 :: real) \<le> exp (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2110
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2111
  have eq4: "4 = Suc (Suc (Suc (Suc 0)))" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2112
  have "1 / 4 = (Float 1 (- 2))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2113
    unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2114
  also have "\<dots> \<le> lb_exp_horner 3 (get_even 3) 1 1 (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2115
    by (subst less_eq_float.rep_eq [symmetric]) code_simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2116
  also have "\<dots> \<le> exp (- 1 :: float)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2117
    using bnds_exp_horner[where x="- 1"] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2118
  finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2119
    by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2120
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2121
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2122
lemma lb_exp_pos:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2123
  assumes "\<not> 0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2124
  shows "0 < lb_exp prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2125
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2126
  let "?lb_horner x" = "lb_exp_horner prec (get_even (prec + 2)) 1 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2127
  let "?horner x" = "let y = ?lb_horner x in if y \<le> 0 then Float 1 (- 2) else y"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2128
  have pos_horner: "0 < ?horner x" for x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2129
    unfolding Let_def by (cases "?lb_horner x \<le> 0") auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2130
  moreover have "0 < real_of_float ((?horner x) ^ num)" for x :: float and num :: nat
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2131
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2132
    have "0 < real_of_float (?horner x) ^ num" using \<open>0 < ?horner x\<close> by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2133
    also have "\<dots> = (?horner x) ^ num" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2134
    finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2135
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2136
  ultimately show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2137
    unfolding lb_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2138
    by (cases "floor_fl x", cases "x < - 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2139
      (auto simp: real_power_up_fl real_power_down_fl intro!: power_up_less power_down_pos)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2140
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2141
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2142
lemma exp_boundaries':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2143
  assumes "x \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2144
  shows "exp x \<in> { (lb_exp prec x) .. (ub_exp prec x)}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2145
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2146
  let "?lb_exp_horner x" = "lb_exp_horner prec (get_even (prec + 2)) 1 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2147
  let "?ub_exp_horner x" = "ub_exp_horner prec (get_odd (prec + 2)) 1 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2148
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2149
  have "real_of_float x \<le> 0" and "\<not> x > 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2150
    using \<open>x \<le> 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2151
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2152
  proof (cases "x < - 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2153
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2154
    hence "- 1 \<le> real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2155
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2156
    proof (cases "?lb_exp_horner x \<le> 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2157
      case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2158
      from \<open>\<not> x < - 1\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2159
      have "- 1 \<le> real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2160
      hence "exp (- 1) \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2161
        unfolding exp_le_cancel_iff .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2162
      from order_trans[OF exp_m1_ge_quarter this] have "Float 1 (- 2) \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2163
        unfolding Float_num .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2164
      with True show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2165
        using bnds_exp_horner \<open>real_of_float x \<le> 0\<close> \<open>\<not> x > 0\<close> \<open>\<not> x < - 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2166
    next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2167
      case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2168
      thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2169
        using bnds_exp_horner \<open>real_of_float x \<le> 0\<close> \<open>\<not> x > 0\<close> \<open>\<not> x < - 1\<close> by (auto simp add: Let_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2170
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2171
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2172
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2173
    let ?num = "nat (- int_floor_fl x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2174
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2175
    have "real_of_int (int_floor_fl x) < - 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2176
      using int_floor_fl[of x] \<open>x < - 1\<close> by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2177
    hence "real_of_int (int_floor_fl x) < 0" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2178
    hence "int_floor_fl x < 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2179
    hence "1 \<le> - int_floor_fl x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2180
    hence "0 < nat (- int_floor_fl x)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2181
    hence "0 < ?num"  by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2182
    hence "real ?num \<noteq> 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2183
    have num_eq: "real ?num = - int_floor_fl x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2184
      using \<open>0 < nat (- int_floor_fl x)\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2185
    have "0 < - int_floor_fl x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2186
      using \<open>0 < ?num\<close>[unfolded of_nat_less_iff[symmetric]] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2187
    hence "real_of_int (int_floor_fl x) < 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2188
      unfolding less_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2189
    have fl_eq: "real_of_int (- int_floor_fl x) = real_of_float (- floor_fl x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2190
      by (simp add: floor_fl_def int_floor_fl_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2191
    from \<open>0 < - int_floor_fl x\<close> have "0 \<le> real_of_float (- floor_fl x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2192
      by (simp add: floor_fl_def int_floor_fl_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2193
    from \<open>real_of_int (int_floor_fl x) < 0\<close> have "real_of_float (floor_fl x) < 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2194
      by (simp add: floor_fl_def int_floor_fl_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2195
    have "exp x \<le> ub_exp prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2196
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2197
      have div_less_zero: "real_of_float (float_divr prec x (- floor_fl x)) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2198
        using float_divr_nonpos_pos_upper_bound[OF \<open>real_of_float x \<le> 0\<close> \<open>0 \<le> real_of_float (- floor_fl x)\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2199
        unfolding less_eq_float_def zero_float.rep_eq .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2200
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2201
      have "exp x = exp (?num * (x / ?num))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2202
        using \<open>real ?num \<noteq> 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2203
      also have "\<dots> = exp (x / ?num) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2204
        unfolding exp_of_nat_mult ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2205
      also have "\<dots> \<le> exp (float_divr prec x (- floor_fl x)) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2206
        unfolding num_eq fl_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2207
        by (rule power_mono, rule exp_le_cancel_iff[THEN iffD2], rule float_divr) auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2208
      also have "\<dots> \<le> (?ub_exp_horner (float_divr prec x (- floor_fl x))) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2209
        unfolding real_of_float_power
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2210
        by (rule power_mono, rule bnds_exp_horner[OF div_less_zero, unfolded atLeastAtMost_iff, THEN conjunct2], auto)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2211
      also have "\<dots> \<le> real_of_float (power_up_fl prec (?ub_exp_horner (float_divr prec x (- floor_fl x))) ?num)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2212
        by (auto simp add: real_power_up_fl intro!: power_up ub_exp_horner_nonneg div_less_zero)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2213
      finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2214
        unfolding ub_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] if_P[OF \<open>x < - 1\<close>] floor_fl_def Let_def .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2215
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2216
    moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2217
    have "lb_exp prec x \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2218
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2219
      let ?divl = "float_divl prec x (- floor_fl x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2220
      let ?horner = "?lb_exp_horner ?divl"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2221
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2222
      show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2223
      proof (cases "?horner \<le> 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2224
        case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2225
        hence "0 \<le> real_of_float ?horner" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2226
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2227
        have div_less_zero: "real_of_float (float_divl prec x (- floor_fl x)) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2228
          using \<open>real_of_float (floor_fl x) < 0\<close> \<open>real_of_float x \<le> 0\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2229
          by (auto intro!: order_trans[OF float_divl] divide_nonpos_neg)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2230
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2231
        have "(?lb_exp_horner (float_divl prec x (- floor_fl x))) ^ ?num \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2232
          exp (float_divl prec x (- floor_fl x)) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2233
          using \<open>0 \<le> real_of_float ?horner\<close>[unfolded floor_fl_def[symmetric]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2234
            bnds_exp_horner[OF div_less_zero, unfolded atLeastAtMost_iff, THEN conjunct1]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2235
          by (auto intro!: power_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2236
        also have "\<dots> \<le> exp (x / ?num) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2237
          unfolding num_eq fl_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2238
          using float_divl by (auto intro!: power_mono simp del: uminus_float.rep_eq)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2239
        also have "\<dots> = exp (?num * (x / ?num))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2240
          unfolding exp_of_nat_mult ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2241
        also have "\<dots> = exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2242
          using \<open>real ?num \<noteq> 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2243
        finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2244
          using False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2245
          unfolding lb_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] if_P[OF \<open>x < - 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2246
            int_floor_fl_def Let_def if_not_P[OF False]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2247
          by (auto simp: real_power_down_fl intro!: power_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2248
      next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2249
        case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2250
        have "power_down_fl prec (Float 1 (- 2))  ?num \<le> (Float 1 (- 2)) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2251
          by (metis Float_le_zero_iff less_imp_le linorder_not_less
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2252
            not_numeral_le_zero numeral_One power_down_fl)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2253
        then have "power_down_fl prec (Float 1 (- 2))  ?num \<le> real_of_float (Float 1 (- 2)) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2254
          by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2255
        also
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2256
        have "real_of_float (floor_fl x) \<noteq> 0" and "real_of_float (floor_fl x) \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2257
          using \<open>real_of_float (floor_fl x) < 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2258
        from divide_right_mono_neg[OF floor_fl[of x] \<open>real_of_float (floor_fl x) \<le> 0\<close>, unfolded divide_self[OF \<open>real_of_float (floor_fl x) \<noteq> 0\<close>]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2259
        have "- 1 \<le> x / (- floor_fl x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2260
          unfolding minus_float.rep_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2261
        from order_trans[OF exp_m1_ge_quarter this[unfolded exp_le_cancel_iff[where x="- 1", symmetric]]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2262
        have "Float 1 (- 2) \<le> exp (x / (- floor_fl x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2263
          unfolding Float_num .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2264
        hence "real_of_float (Float 1 (- 2)) ^ ?num \<le> exp (x / (- floor_fl x)) ^ ?num"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2265
          by (metis Float_num(5) power_mono zero_le_divide_1_iff zero_le_numeral)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2266
        also have "\<dots> = exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2267
          unfolding num_eq fl_eq exp_of_nat_mult[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2268
          using \<open>real_of_float (floor_fl x) \<noteq> 0\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2269
        finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2270
          unfolding lb_exp.simps if_not_P[OF \<open>\<not> 0 < x\<close>] if_P[OF \<open>x < - 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2271
            int_floor_fl_def Let_def if_P[OF True] real_of_float_power .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2272
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2273
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2274
    ultimately show ?thesis by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2275
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2276
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2277
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2278
lemma exp_boundaries: "exp x \<in> { lb_exp prec x .. ub_exp prec x }"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2279
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2280
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2281
  proof (cases "0 < x")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2282
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2283
    hence "x \<le> 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2284
    from exp_boundaries'[OF this] show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2285
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2286
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2287
    hence "-x \<le> 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2288
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2289
    have "lb_exp prec x \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2290
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2291
      from exp_boundaries'[OF \<open>-x \<le> 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2292
      have ub_exp: "exp (- real_of_float x) \<le> ub_exp prec (-x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2293
        unfolding atLeastAtMost_iff minus_float.rep_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2294
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2295
      have "float_divl prec 1 (ub_exp prec (-x)) \<le> 1 / ub_exp prec (-x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2296
        using float_divl[where x=1] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2297
      also have "\<dots> \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2298
        using ub_exp[unfolded inverse_le_iff_le[OF order_less_le_trans[OF exp_gt_zero ub_exp]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2299
          exp_gt_zero, symmetric]]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2300
        unfolding exp_minus nonzero_inverse_inverse_eq[OF exp_not_eq_zero] inverse_eq_divide
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2301
        by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2302
      finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2303
        unfolding lb_exp.simps if_P[OF True] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2304
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2305
    moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2306
    have "exp x \<le> ub_exp prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2307
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2308
      have "\<not> 0 < -x" using \<open>0 < x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2309
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2310
      from exp_boundaries'[OF \<open>-x \<le> 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2311
      have lb_exp: "lb_exp prec (-x) \<le> exp (- real_of_float x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2312
        unfolding atLeastAtMost_iff minus_float.rep_eq by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2313
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2314
      have "exp x \<le> (1 :: float) / lb_exp prec (-x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2315
        using lb_exp lb_exp_pos[OF \<open>\<not> 0 < -x\<close>, of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2316
        by (simp del: lb_exp.simps add: exp_minus field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2317
      also have "\<dots> \<le> float_divr prec 1 (lb_exp prec (-x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2318
        using float_divr .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2319
      finally show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2320
        unfolding ub_exp.simps if_P[OF True] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2321
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2322
    ultimately show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2323
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2324
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2325
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2326
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2327
lemma bnds_exp: "\<forall>(x::real) lx ux. (l, u) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2328
  (lb_exp prec lx, ub_exp prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> exp x \<and> exp x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2329
proof (rule allI, rule allI, rule allI, rule impI)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2330
  fix x :: real and lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2331
  assume "(l, u) = (lb_exp prec lx, ub_exp prec ux) \<and> x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2332
  hence l: "lb_exp prec lx = l " and u: "ub_exp prec ux = u" and x: "x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2333
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2334
  show "l \<le> exp x \<and> exp x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2335
  proof
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2336
    show "l \<le> exp x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2337
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2338
      from exp_boundaries[of lx prec, unfolded l]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2339
      have "l \<le> exp lx" by (auto simp del: lb_exp.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2340
      also have "\<dots> \<le> exp x" using x by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2341
      finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2342
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2343
    show "exp x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2344
    proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2345
      have "exp x \<le> exp ux" using x by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2346
      also have "\<dots> \<le> u" using exp_boundaries[of ux prec, unfolded u] by (auto simp del: ub_exp.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2347
      finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2348
    qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2349
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2350
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2351
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2352
lemmas [simp del] = lb_exp.simps ub_exp.simps
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2353
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2354
lemma lb_exp: "exp x \<le> y \<Longrightarrow> lb_exp prec x \<le> y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2355
  and ub_exp: "y \<le> exp x \<Longrightarrow> y \<le> ub_exp prec x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2356
  for x::float and y::real using exp_boundaries[of x prec] by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2357
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2358
lift_definition exp_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2359
  is "\<lambda>prec. \<lambda>(lx, ux). (lb_exp prec lx, ub_exp prec ux)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2360
  by (auto simp: lb_exp ub_exp)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2361
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2362
lemma lower_exp_float_interval: "lower (exp_float_interval p x) = lb_exp p (lower x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2363
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2364
lemma upper_exp_float_interval: "upper (exp_float_interval p x) = ub_exp p (upper x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2365
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2366
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2367
lemma exp_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2368
  "exp ` set_of (real_interval x) \<subseteq> set_of (real_interval (exp_float_interval p x))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2369
  using exp_boundaries
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2370
  by (auto simp: set_of_eq lower_exp_float_interval upper_exp_float_interval lb_exp ub_exp)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2371
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2372
lemma exp_float_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2373
  "exp x \<in>\<^sub>r exp_float_interval p X" if "x \<in>\<^sub>r X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2374
  using exp_float_interval[of X p] that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2375
  by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2376
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2377
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2378
section "Logarithm"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2379
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2380
subsection "Compute the logarithm series"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2381
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2382
fun ub_ln_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2383
and lb_ln_horner :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> float \<Rightarrow> float" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2384
"ub_ln_horner prec 0 i x       = 0" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2385
"ub_ln_horner prec (Suc n) i x = float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2386
    (rapprox_rat prec 1 (int i)) (- float_round_down prec (x * lb_ln_horner prec n (Suc i) x))" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2387
"lb_ln_horner prec 0 i x       = 0" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2388
"lb_ln_horner prec (Suc n) i x = float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2389
    (lapprox_rat prec 1 (int i)) (- float_round_up prec (x * ub_ln_horner prec n (Suc i) x))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2390
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2391
lemma ln_bounds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2392
  assumes "0 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2393
    and "x < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2394
  shows "(\<Sum>i=0..<2*n. (- 1) ^ i * (1 / real (i + 1)) * x ^ (Suc i)) \<le> ln (x + 1)" (is "?lb")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2395
  and "ln (x + 1) \<le> (\<Sum>i=0..<2*n + 1. (- 1) ^ i * (1 / real (i + 1)) * x ^ (Suc i))" (is "?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2396
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2397
  let "?a n" = "(1/real (n +1)) * x ^ (Suc n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2398
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2399
  have ln_eq: "(\<Sum> i. (- 1) ^ i * ?a i) = ln (x + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2400
    using ln_series[of "x + 1"] \<open>0 \<le> x\<close> \<open>x < 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2401
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2402
  have "norm x < 1" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2403
  have "?a \<longlonglongrightarrow> 0" unfolding Suc_eq_plus1[symmetric] inverse_eq_divide[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2404
    using tendsto_mult[OF LIMSEQ_inverse_real_of_nat LIMSEQ_Suc[OF LIMSEQ_power_zero[OF \<open>norm x < 1\<close>]]] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2405
  have "0 \<le> ?a n" for n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2406
    by (rule mult_nonneg_nonneg) (auto simp: \<open>0 \<le> x\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2407
  have "?a (Suc n) \<le> ?a n" for n
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2408
    unfolding inverse_eq_divide[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2409
  proof (rule mult_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2410
    show "0 \<le> x ^ Suc (Suc n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2411
      by (auto simp add: \<open>0 \<le> x\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2412
    have "x ^ Suc (Suc n) \<le> x ^ Suc n * 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2413
      unfolding power_Suc2 mult.assoc[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2414
      by (rule mult_left_mono, fact less_imp_le[OF \<open>x < 1\<close>]) (auto simp: \<open>0 \<le> x\<close>)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2415
    thus "x ^ Suc (Suc n) \<le> x ^ Suc n" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2416
  qed auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2417
  from summable_Leibniz'(2,4)[OF \<open>?a \<longlonglongrightarrow> 0\<close> \<open>\<And>n. 0 \<le> ?a n\<close>, OF \<open>\<And>n. ?a (Suc n) \<le> ?a n\<close>, unfolded ln_eq]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2418
  show ?lb and ?ub
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2419
    unfolding atLeast0LessThan by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2420
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2421
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2422
lemma ln_float_bounds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2423
  assumes "0 \<le> real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2424
    and "real_of_float x < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2425
  shows "x * lb_ln_horner prec (get_even n) 1 x \<le> ln (x + 1)" (is "?lb \<le> ?ln")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2426
    and "ln (x + 1) \<le> x * ub_ln_horner prec (get_odd n) 1 x" (is "?ln \<le> ?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2427
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2428
  obtain ev where ev: "get_even n = 2 * ev" using get_even_double ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2429
  obtain od where od: "get_odd n = 2 * od + 1" using get_odd_double ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2430
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2431
  let "?s n" = "(- 1) ^ n * (1 / real (1 + n)) * (real_of_float x)^(Suc n)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2432
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2433
  have "?lb \<le> sum ?s {0 ..< 2 * ev}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2434
    unfolding power_Suc2 mult.assoc[symmetric] times_float.rep_eq sum_distrib_right[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2435
    unfolding mult.commute[of "real_of_float x"] ev 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2436
    using horner_bounds(1)[where G="\<lambda> i k. Suc k" and F="\<lambda>x. x" and f="\<lambda>x. x" 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2437
                    and lb="\<lambda>n i k x. lb_ln_horner prec n k x" 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2438
                    and ub="\<lambda>n i k x. ub_ln_horner prec n k x" and j'=1 and n="2*ev",
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2439
      OF \<open>0 \<le> real_of_float x\<close> refl lb_ln_horner.simps ub_ln_horner.simps] \<open>0 \<le> real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2440
    unfolding real_of_float_power
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2441
    by (rule mult_right_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2442
  also have "\<dots> \<le> ?ln"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2443
    using ln_bounds(1)[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x < 1\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2444
  finally show "?lb \<le> ?ln" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2445
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2446
  have "?ln \<le> sum ?s {0 ..< 2 * od + 1}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2447
    using ln_bounds(2)[OF \<open>0 \<le> real_of_float x\<close> \<open>real_of_float x < 1\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2448
  also have "\<dots> \<le> ?ub"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2449
    unfolding power_Suc2 mult.assoc[symmetric] times_float.rep_eq sum_distrib_right[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2450
    unfolding mult.commute[of "real_of_float x"] od
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2451
    using horner_bounds(2)[where G="\<lambda> i k. Suc k" and F="\<lambda>x. x" and f="\<lambda>x. x" and lb="\<lambda>n i k x. lb_ln_horner prec n k x" and ub="\<lambda>n i k x. ub_ln_horner prec n k x" and j'=1 and n="2 * od + 1",
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2452
      OF \<open>0 \<le> real_of_float x\<close> refl lb_ln_horner.simps ub_ln_horner.simps] \<open>0 \<le> real_of_float x\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2453
    unfolding real_of_float_power
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2454
    by (rule mult_right_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2455
  finally show "?ln \<le> ?ub" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2456
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2457
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2458
lemma ln_add:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2459
  fixes x :: real
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2460
  assumes "0 < x" and "0 < y"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2461
  shows "ln (x + y) = ln x + ln (1 + y / x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2462
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2463
  have "x \<noteq> 0" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2464
  have "x + y = x * (1 + y / x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2465
    unfolding distrib_left times_divide_eq_right nonzero_mult_div_cancel_left[OF \<open>x \<noteq> 0\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2466
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2467
  moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2468
  have "0 < y / x" using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2469
  hence "0 < 1 + y / x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2470
  ultimately show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2471
    using ln_mult assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2472
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2473
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2474
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2475
subsection "Compute the logarithm of 2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2476
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2477
definition ub_ln2 where "ub_ln2 prec = (let third = rapprox_rat (max prec 1) 1 3
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2478
                                        in float_plus_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2479
                                          ((Float 1 (- 1) * ub_ln_horner prec (get_odd prec) 1 (Float 1 (- 1))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2480
                                           (float_round_up prec (third * ub_ln_horner prec (get_odd prec) 1 third)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2481
definition lb_ln2 where "lb_ln2 prec = (let third = lapprox_rat prec 1 3
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2482
                                        in float_plus_down prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2483
                                          ((Float 1 (- 1) * lb_ln_horner prec (get_even prec) 1 (Float 1 (- 1))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2484
                                           (float_round_down prec (third * lb_ln_horner prec (get_even prec) 1 third)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2485
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2486
lemma ub_ln2: "ln 2 \<le> ub_ln2 prec" (is "?ub_ln2")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2487
  and lb_ln2: "lb_ln2 prec \<le> ln 2" (is "?lb_ln2")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2488
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2489
  let ?uthird = "rapprox_rat (max prec 1) 1 3"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2490
  let ?lthird = "lapprox_rat prec 1 3"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2491
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2492
  have ln2_sum: "ln 2 = ln (1/2 + 1) + ln (1 / 3 + 1::real)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2493
    using ln_add[of "3 / 2" "1 / 2"] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2494
  have lb3: "?lthird \<le> 1 / 3" using lapprox_rat[of prec 1 3] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2495
  hence lb3_ub: "real_of_float ?lthird < 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2496
  have lb3_lb: "0 \<le> real_of_float ?lthird" using lapprox_rat_nonneg[of 1 3] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2497
  have ub3: "1 / 3 \<le> ?uthird" using rapprox_rat[of 1 3] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2498
  hence ub3_lb: "0 \<le> real_of_float ?uthird" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2499
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2500
  have lb2: "0 \<le> real_of_float (Float 1 (- 1))" and ub2: "real_of_float (Float 1 (- 1)) < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2501
    unfolding Float_num by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2502
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2503
  have "0 \<le> (1::int)" and "0 < (3::int)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2504
  have ub3_ub: "real_of_float ?uthird < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2505
    by (simp add: Float.compute_rapprox_rat Float.compute_lapprox_rat rapprox_posrat_less1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2506
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2507
  have third_gt0: "(0 :: real) < 1 / 3 + 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2508
  have uthird_gt0: "0 < real_of_float ?uthird + 1" using ub3_lb by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2509
  have lthird_gt0: "0 < real_of_float ?lthird + 1" using lb3_lb by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2510
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2511
  show ?ub_ln2
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2512
    unfolding ub_ln2_def Let_def ln2_sum Float_num(4)[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2513
  proof (rule float_plus_up_le, rule add_mono, fact ln_float_bounds(2)[OF lb2 ub2])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2514
    have "ln (1 / 3 + 1) \<le> ln (real_of_float ?uthird + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2515
      unfolding ln_le_cancel_iff[OF third_gt0 uthird_gt0] using ub3 by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2516
    also have "\<dots> \<le> ?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2517
      using ln_float_bounds(2)[OF ub3_lb ub3_ub] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2518
    also note float_round_up
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2519
    finally show "ln (1 / 3 + 1) \<le> float_round_up prec (?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird)" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2520
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2521
  show ?lb_ln2
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2522
    unfolding lb_ln2_def Let_def ln2_sum Float_num(4)[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2523
  proof (rule float_plus_down_le, rule add_mono, fact ln_float_bounds(1)[OF lb2 ub2])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2524
    have "?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird \<le> ln (real_of_float ?lthird + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2525
      using ln_float_bounds(1)[OF lb3_lb lb3_ub] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2526
    note float_round_down_le[OF this]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2527
    also have "\<dots> \<le> ln (1 / 3 + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2528
      unfolding ln_le_cancel_iff[OF lthird_gt0 third_gt0]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2529
      using lb3 by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2530
    finally show "float_round_down prec (?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird) \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2531
      ln (1 / 3 + 1)" .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2532
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2533
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2534
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2535
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2536
subsection "Compute the logarithm in the entire domain"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2537
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2538
function ub_ln :: "nat \<Rightarrow> float \<Rightarrow> float option" and lb_ln :: "nat \<Rightarrow> float \<Rightarrow> float option" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2539
"ub_ln prec x = (if x \<le> 0          then None
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2540
            else if x < 1          then Some (- the (lb_ln prec (float_divl (max prec 1) 1 x)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2541
            else let horner = \<lambda>x. float_round_up prec (x * ub_ln_horner prec (get_odd prec) 1 x) in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2542
                 if x \<le> Float 3 (- 1) then Some (horner (x - 1))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2543
            else if x < Float 1 1  then Some (float_round_up prec (horner (Float 1 (- 1)) + horner (x * rapprox_rat prec 2 3 - 1)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2544
                                   else let l = bitlen (mantissa x) - 1 in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2545
                                        Some (float_plus_up prec (float_round_up prec (ub_ln2 prec * (Float (exponent x + l) 0))) (horner (Float (mantissa x) (- l) - 1))))" |
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2546
"lb_ln prec x = (if x \<le> 0          then None
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2547
            else if x < 1          then Some (- the (ub_ln prec (float_divr prec 1 x)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2548
            else let horner = \<lambda>x. float_round_down prec (x * lb_ln_horner prec (get_even prec) 1 x) in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2549
                 if x \<le> Float 3 (- 1) then Some (horner (x - 1))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2550
            else if x < Float 1 1  then Some (float_round_down prec (horner (Float 1 (- 1)) +
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2551
                                              horner (max (x * lapprox_rat prec 2 3 - 1) 0)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2552
                                   else let l = bitlen (mantissa x) - 1 in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2553
                                        Some (float_plus_down prec (float_round_down prec (lb_ln2 prec * (Float (exponent x + l) 0))) (horner (Float (mantissa x) (- l) - 1))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2554
  by pat_completeness auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2555
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2556
termination
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2557
proof (relation "measure (\<lambda> v. let (prec, x) = case_sum id id v in (if x < 1 then 1 else 0))", auto)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2558
  fix prec and x :: float
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2559
  assume "\<not> real_of_float x \<le> 0" and "real_of_float x < 1" and "real_of_float (float_divl (max prec (Suc 0)) 1 x) < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2560
  hence "0 < real_of_float x" "1 \<le> max prec (Suc 0)" "real_of_float x < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2561
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2562
  from float_divl_pos_less1_bound[OF \<open>0 < real_of_float x\<close> \<open>real_of_float x < 1\<close>[THEN less_imp_le] \<open>1 \<le> max prec (Suc 0)\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2563
  show False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2564
    using \<open>real_of_float (float_divl (max prec (Suc 0)) 1 x) < 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2565
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2566
  fix prec x
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2567
  assume "\<not> real_of_float x \<le> 0" and "real_of_float x < 1" and "real_of_float (float_divr prec 1 x) < 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2568
  hence "0 < x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2569
  from float_divr_pos_less1_lower_bound[OF \<open>0 < x\<close>, of prec] \<open>real_of_float x < 1\<close> show False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2570
    using \<open>real_of_float (float_divr prec 1 x) < 1\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2571
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2572
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2573
lemmas float_pos_eq_mantissa_pos = mantissa_pos_iff[symmetric]
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2574
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2575
lemma Float_pos_eq_mantissa_pos: "Float m e > 0 \<longleftrightarrow> m > 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2576
  using powr_gt_zero[of 2 "e"]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2577
  by (auto simp add: zero_less_mult_iff zero_float_def simp del: powr_gt_zero dest: less_zeroE)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2578
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2579
lemma Float_representation_aux:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2580
  fixes m e
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2581
  defines [THEN meta_eq_to_obj_eq]: "x \<equiv> Float m e"
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2582
  assumes "x > 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2583
  shows "Float (exponent x + (bitlen (mantissa x) - 1)) 0 = Float (e + (bitlen m - 1)) 0" (is ?th1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2584
    and "Float (mantissa x) (- (bitlen (mantissa x) - 1)) = Float m ( - (bitlen m - 1))"  (is ?th2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2585
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2586
  from assms have mantissa_pos: "m > 0" "mantissa x > 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2587
    using Float_pos_eq_mantissa_pos[of m e] float_pos_eq_mantissa_pos[of x] by simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2588
  thus ?th1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2589
    using bitlen_Float[of m e] assms
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2590
    by (auto simp add: zero_less_mult_iff intro!: arg_cong2[where f=Float])
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2591
  have "x \<noteq> 0"
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2592
    unfolding zero_float_def[symmetric] using \<open>0 < x\<close> by auto
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2593
  from denormalize_shift[OF x_def this] obtain i where
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2594
    i: "m = mantissa x * 2 ^ i" "e = exponent x - int i" .
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2595
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2596
  have "2 powr (1 - (real_of_int (bitlen (mantissa x)) + real_of_int i)) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2597
    2 powr (1 - (real_of_int (bitlen (mantissa x)))) * inverse (2 powr (real i))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2598
    by (simp add: powr_minus[symmetric] powr_add[symmetric] field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2599
  hence "real_of_int (mantissa x) * 2 powr (1 - real_of_int (bitlen (mantissa x))) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2600
    (real_of_int (mantissa x) * 2 ^ i) * 2 powr (1 - real_of_int (bitlen (mantissa x * 2 ^ i)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2601
    using \<open>mantissa x > 0\<close> by (simp add: powr_realpow)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2602
  then show ?th2
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2603
    unfolding i
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2604
    by (auto simp: real_of_float_eq)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2605
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2606
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2607
lemma compute_ln[code]:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2608
  fixes m e
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2609
  defines "x \<equiv> Float m e"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2610
  shows "ub_ln prec x = (if x \<le> 0          then None
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2611
              else if x < 1          then Some (- the (lb_ln prec (float_divl (max prec 1) 1 x)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2612
            else let horner = \<lambda>x. float_round_up prec (x * ub_ln_horner prec (get_odd prec) 1 x) in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2613
                 if x \<le> Float 3 (- 1) then Some (horner (x - 1))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2614
            else if x < Float 1 1  then Some (float_round_up prec (horner (Float 1 (- 1)) + horner (x * rapprox_rat prec 2 3 - 1)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2615
                                   else let l = bitlen m - 1 in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2616
                                        Some (float_plus_up prec (float_round_up prec (ub_ln2 prec * (Float (e + l) 0))) (horner (Float m (- l) - 1))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2617
    (is ?th1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2618
  and "lb_ln prec x = (if x \<le> 0          then None
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2619
            else if x < 1          then Some (- the (ub_ln prec (float_divr prec 1 x)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2620
            else let horner = \<lambda>x. float_round_down prec (x * lb_ln_horner prec (get_even prec) 1 x) in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2621
                 if x \<le> Float 3 (- 1) then Some (horner (x - 1))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2622
            else if x < Float 1 1  then Some (float_round_down prec (horner (Float 1 (- 1)) +
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2623
                                              horner (max (x * lapprox_rat prec 2 3 - 1) 0)))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2624
                                   else let l = bitlen m - 1 in
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2625
                                        Some (float_plus_down prec (float_round_down prec (lb_ln2 prec * (Float (e + l) 0))) (horner (Float m (- l) - 1))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2626
    (is ?th2)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2627
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2628
  from assms Float_pos_eq_mantissa_pos have "x > 0 \<Longrightarrow> m > 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2629
    by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2630
  thus ?th1 ?th2
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2631
    using Float_representation_aux[of m e]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2632
    unfolding x_def[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2633
    by (auto dest: not_le_imp_less)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2634
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2635
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2636
lemma ln_shifted_float:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2637
  assumes "0 < m"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2638
  shows "ln (Float m e) = ln 2 * (e + (bitlen m - 1)) + ln (Float m (- (bitlen m - 1)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2639
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2640
  let ?B = "2^nat (bitlen m - 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2641
  define bl where "bl = bitlen m - 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2642
  have "0 < real_of_int m" and "\<And>X. (0 :: real) < 2^X" and "0 < (2 :: real)" and "m \<noteq> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2643
    using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2644
  hence "0 \<le> bl" by (simp add: bitlen_alt_def bl_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2645
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2646
  proof (cases "0 \<le> e")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2647
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2648
    thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2649
      unfolding bl_def[symmetric] using \<open>0 < real_of_int m\<close> \<open>0 \<le> bl\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2650
      apply (simp add: ln_mult)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2651
      apply (cases "e=0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2652
        apply (cases "bl = 0", simp_all add: powr_minus ln_inverse ln_powr)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2653
        apply (cases "bl = 0", simp_all add: powr_minus ln_inverse ln_powr field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2654
      done
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2655
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2656
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2657
    hence "0 < -e" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2658
    have lne: "ln (2 powr real_of_int e) = ln (inverse (2 powr - e))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2659
      by (simp add: powr_minus)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2660
    hence pow_gt0: "(0::real) < 2^nat (-e)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2661
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2662
    hence inv_gt0: "(0::real) < inverse (2^nat (-e))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2663
      by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2664
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2665
      using False unfolding bl_def[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2666
      using \<open>0 < real_of_int m\<close> \<open>0 \<le> bl\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2667
      by (auto simp add: lne ln_mult ln_powr ln_div field_simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2668
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2669
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2670
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2671
lemma ub_ln_lb_ln_bounds':
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2672
  assumes "1 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2673
  shows "the (lb_ln prec x) \<le> ln x \<and> ln x \<le> the (ub_ln prec x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2674
    (is "?lb \<le> ?ln \<and> ?ln \<le> ?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2675
proof (cases "x < Float 1 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2676
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2677
  hence "real_of_float (x - 1) < 1" and "real_of_float x < 2" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2678
  have "\<not> x \<le> 0" and "\<not> x < 1" using \<open>1 \<le> x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2679
  hence "0 \<le> real_of_float (x - 1)" using \<open>1 \<le> x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2680
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2681
  have [simp]: "(Float 3 (- 1)) = 3 / 2" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2682
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2683
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2684
  proof (cases "x \<le> Float 3 (- 1)")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2685
    case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2686
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2687
      unfolding lb_ln.simps
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2688
      unfolding ub_ln.simps Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2689
      using ln_float_bounds[OF \<open>0 \<le> real_of_float (x - 1)\<close> \<open>real_of_float (x - 1) < 1\<close>, of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2690
        \<open>\<not> x \<le> 0\<close> \<open>\<not> x < 1\<close> True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2691
      by (auto intro!: float_round_down_le float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2692
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2693
    case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2694
    hence *: "3 / 2 < x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2695
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2696
    with ln_add[of "3 / 2" "x - 3 / 2"]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2697
    have add: "ln x = ln (3 / 2) + ln (real_of_float x * 2 / 3)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2698
      by (auto simp add: algebra_simps diff_divide_distrib)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2699
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2700
    let "?ub_horner x" = "float_round_up prec (x * ub_ln_horner prec (get_odd prec) 1 x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2701
    let "?lb_horner x" = "float_round_down prec (x * lb_ln_horner prec (get_even prec) 1 x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2702
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2703
    { have up: "real_of_float (rapprox_rat prec 2 3) \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2704
        by (rule rapprox_rat_le1) simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2705
      have low: "2 / 3 \<le> rapprox_rat prec 2 3"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2706
        by (rule order_trans[OF _ rapprox_rat]) simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2707
      from mult_less_le_imp_less[OF * low] *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2708
      have pos: "0 < real_of_float (x * rapprox_rat prec 2 3 - 1)" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2709
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2710
      have "ln (real_of_float x * 2/3)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2711
        \<le> ln (real_of_float (x * rapprox_rat prec 2 3 - 1) + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2712
      proof (rule ln_le_cancel_iff[symmetric, THEN iffD1])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2713
        show "real_of_float x * 2 / 3 \<le> real_of_float (x * rapprox_rat prec 2 3 - 1) + 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2714
          using * low by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2715
        show "0 < real_of_float x * 2 / 3" using * by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2716
        show "0 < real_of_float (x * rapprox_rat prec 2 3 - 1) + 1" using pos by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2717
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2718
      also have "\<dots> \<le> ?ub_horner (x * rapprox_rat prec 2 3 - 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2719
      proof (rule float_round_up_le, rule ln_float_bounds(2))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2720
        from mult_less_le_imp_less[OF \<open>real_of_float x < 2\<close> up] low *
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2721
        show "real_of_float (x * rapprox_rat prec 2 3 - 1) < 1" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2722
        show "0 \<le> real_of_float (x * rapprox_rat prec 2 3 - 1)" using pos by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2723
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2724
     finally have "ln x \<le> ?ub_horner (Float 1 (-1))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2725
          + ?ub_horner ((x * rapprox_rat prec 2 3 - 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2726
        using ln_float_bounds(2)[of "Float 1 (- 1)" prec prec] add
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2727
        by (auto intro!: add_mono float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2728
      note float_round_up_le[OF this, of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2729
    }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2730
    moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2731
    { let ?max = "max (x * lapprox_rat prec 2 3 - 1) 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2732
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2733
      have up: "lapprox_rat prec 2 3 \<le> 2/3"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2734
        by (rule order_trans[OF lapprox_rat], simp)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2735
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2736
      have low: "0 \<le> real_of_float (lapprox_rat prec 2 3)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2737
        using lapprox_rat_nonneg[of 2 3 prec] by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2738
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2739
      have "?lb_horner ?max
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2740
        \<le> ln (real_of_float ?max + 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2741
      proof (rule float_round_down_le, rule ln_float_bounds(1))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2742
        from mult_less_le_imp_less[OF \<open>real_of_float x < 2\<close> up] * low
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2743
        show "real_of_float ?max < 1" by (cases "real_of_float (lapprox_rat prec 2 3) = 0",
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2744
          auto simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2745
        show "0 \<le> real_of_float ?max" by (auto simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2746
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2747
      also have "\<dots> \<le> ln (real_of_float x * 2/3)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2748
      proof (rule ln_le_cancel_iff[symmetric, THEN iffD1])
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2749
        show "0 < real_of_float ?max + 1" by (auto simp add: real_of_float_max)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2750
        show "0 < real_of_float x * 2/3" using * by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2751
        show "real_of_float ?max + 1 \<le> real_of_float x * 2/3" using * up
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2752
          by (cases "0 < real_of_float x * real_of_float (lapprox_posrat prec 2 3) - 1",
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2753
              auto simp add: max_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2754
      qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2755
      finally have "?lb_horner (Float 1 (- 1)) + ?lb_horner ?max \<le> ln x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2756
        using ln_float_bounds(1)[of "Float 1 (- 1)" prec prec] add
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2757
        by (auto intro!: add_mono float_round_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2758
      note float_round_down_le[OF this, of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2759
    }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2760
    ultimately
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2761
    show ?thesis unfolding lb_ln.simps unfolding ub_ln.simps Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2762
      using \<open>\<not> x \<le> 0\<close> \<open>\<not> x < 1\<close> True False by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2763
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2764
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2765
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2766
  hence "\<not> x \<le> 0" and "\<not> x < 1" "0 < x" "\<not> x \<le> Float 3 (- 1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2767
    using \<open>1 \<le> x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2768
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2769
  proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2770
    define m where "m = mantissa x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2771
    define e where "e = exponent x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2772
    from Float_mantissa_exponent[of x] have Float: "x = Float m e"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2773
      by (simp add: m_def e_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2774
    let ?s = "Float (e + (bitlen m - 1)) 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2775
    let ?x = "Float m (- (bitlen m - 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2776
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2777
    have "0 < m" and "m \<noteq> 0" using \<open>0 < x\<close> Float powr_gt_zero[of 2 e]
67573
ed0a7090167d added lemmas, avoid 'float_of 0'
immler
parents: 66453
diff changeset
  2778
      by (auto simp add: zero_less_mult_iff)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2779
    define bl where "bl = bitlen m - 1"
70350
571ae57313a4 moved some theorems into HOL main corpus
haftmann
parents: 70347
diff changeset
  2780
    then have bitlen: "bitlen m = bl + 1"
571ae57313a4 moved some theorems into HOL main corpus
haftmann
parents: 70347
diff changeset
  2781
      by simp
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2782
    hence "bl \<ge> 0"
70350
571ae57313a4 moved some theorems into HOL main corpus
haftmann
parents: 70347
diff changeset
  2783
      using \<open>m > 0\<close> by (auto simp add: bitlen_alt_def)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2784
    have "1 \<le> Float m e"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2785
      using \<open>1 \<le> x\<close> Float unfolding less_eq_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2786
    from bitlen_div[OF \<open>0 < m\<close>] float_gt1_scale[OF \<open>1 \<le> Float m e\<close>] \<open>bl \<ge> 0\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2787
    have x_bnds: "0 \<le> real_of_float (?x - 1)" "real_of_float (?x - 1) < 1"
70350
571ae57313a4 moved some theorems into HOL main corpus
haftmann
parents: 70347
diff changeset
  2788
      using abs_real_le_2_powr_bitlen [of m] \<open>m > 0\<close>
571ae57313a4 moved some theorems into HOL main corpus
haftmann
parents: 70347
diff changeset
  2789
      by (simp_all add: bitlen powr_realpow [symmetric] powr_minus powr_add field_simps)
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2790
    {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2791
      have "float_round_down prec (lb_ln2 prec * ?s) \<le> ln 2 * (e + (bitlen m - 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2792
          (is "real_of_float ?lb2 \<le> _")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2793
        apply (rule float_round_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2794
        unfolding nat_0 power_0 mult_1_right times_float.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2795
        using lb_ln2[of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2796
      proof (rule mult_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2797
        from float_gt1_scale[OF \<open>1 \<le> Float m e\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2798
        show "0 \<le> real_of_float (Float (e + (bitlen m - 1)) 0)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2799
      qed auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2800
      moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2801
      from ln_float_bounds(1)[OF x_bnds]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2802
      have "float_round_down prec ((?x - 1) * lb_ln_horner prec (get_even prec) 1 (?x - 1)) \<le> ln ?x" (is "real_of_float ?lb_horner \<le> _")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2803
        by (auto intro!: float_round_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2804
      ultimately have "float_plus_down prec ?lb2 ?lb_horner \<le> ln x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2805
        unfolding Float ln_shifted_float[OF \<open>0 < m\<close>, of e] by (auto intro!: float_plus_down_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2806
    }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2807
    moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2808
    {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2809
      from ln_float_bounds(2)[OF x_bnds]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2810
      have "ln ?x \<le> float_round_up prec ((?x - 1) * ub_ln_horner prec (get_odd prec) 1 (?x - 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2811
          (is "_ \<le> real_of_float ?ub_horner")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2812
        by (auto intro!: float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2813
      moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2814
      have "ln 2 * (e + (bitlen m - 1)) \<le> float_round_up prec (ub_ln2 prec * ?s)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2815
          (is "_ \<le> real_of_float ?ub2")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2816
        apply (rule float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2817
        unfolding nat_0 power_0 mult_1_right times_float.rep_eq
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2818
        using ub_ln2[of prec]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2819
      proof (rule mult_mono)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2820
        from float_gt1_scale[OF \<open>1 \<le> Float m e\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2821
        show "0 \<le> real_of_int (e + (bitlen m - 1))" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2822
        have "0 \<le> ln (2 :: real)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2823
        thus "0 \<le> real_of_float (ub_ln2 prec)" using ub_ln2[of prec] by arith
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2824
      qed auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2825
      ultimately have "ln x \<le> float_plus_up prec ?ub2 ?ub_horner"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2826
        unfolding Float ln_shifted_float[OF \<open>0 < m\<close>, of e]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2827
        by (auto intro!: float_plus_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2828
    }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2829
    ultimately show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2830
      unfolding lb_ln.simps
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2831
      unfolding ub_ln.simps
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2832
      unfolding if_not_P[OF \<open>\<not> x \<le> 0\<close>] if_not_P[OF \<open>\<not> x < 1\<close>]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2833
        if_not_P[OF False] if_not_P[OF \<open>\<not> x \<le> Float 3 (- 1)\<close>] Let_def
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2834
      unfolding plus_float.rep_eq e_def[symmetric] m_def[symmetric]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2835
      by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2836
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2837
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2838
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2839
lemma ub_ln_lb_ln_bounds:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2840
  assumes "0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2841
  shows "the (lb_ln prec x) \<le> ln x \<and> ln x \<le> the (ub_ln prec x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2842
    (is "?lb \<le> ?ln \<and> ?ln \<le> ?ub")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2843
proof (cases "x < 1")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2844
  case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2845
  hence "1 \<le> x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2846
    unfolding less_float_def less_eq_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2847
  show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2848
    using ub_ln_lb_ln_bounds'[OF \<open>1 \<le> x\<close>] .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2849
next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2850
  case True
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2851
  have "\<not> x \<le> 0" using \<open>0 < x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2852
  from True have "real_of_float x \<le> 1" "x \<le> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2853
    by simp_all
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2854
  have "0 < real_of_float x" and "real_of_float x \<noteq> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2855
    using \<open>0 < x\<close> by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2856
  hence A: "0 < 1 / real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2857
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2858
  {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2859
    let ?divl = "float_divl (max prec 1) 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2860
    have A': "1 \<le> ?divl" using float_divl_pos_less1_bound[OF \<open>0 < real_of_float x\<close> \<open>real_of_float x \<le> 1\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2861
    hence B: "0 < real_of_float ?divl" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2862
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2863
    have "ln ?divl \<le> ln (1 / x)" unfolding ln_le_cancel_iff[OF B A] using float_divl[of _ 1 x] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2864
    hence "ln x \<le> - ln ?divl" unfolding nonzero_inverse_eq_divide[OF \<open>real_of_float x \<noteq> 0\<close>, symmetric] ln_inverse[OF \<open>0 < real_of_float x\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2865
    from this ub_ln_lb_ln_bounds'[OF A', THEN conjunct1, THEN le_imp_neg_le]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2866
    have "?ln \<le> - the (lb_ln prec ?divl)" unfolding uminus_float.rep_eq by (rule order_trans)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2867
  } moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2868
  {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2869
    let ?divr = "float_divr prec 1 x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2870
    have A': "1 \<le> ?divr" using float_divr_pos_less1_lower_bound[OF \<open>0 < x\<close> \<open>x \<le> 1\<close>] unfolding less_eq_float_def less_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2871
    hence B: "0 < real_of_float ?divr" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2872
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2873
    have "ln (1 / x) \<le> ln ?divr" unfolding ln_le_cancel_iff[OF A B] using float_divr[of 1 x] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2874
    hence "- ln ?divr \<le> ln x" unfolding nonzero_inverse_eq_divide[OF \<open>real_of_float x \<noteq> 0\<close>, symmetric] ln_inverse[OF \<open>0 < real_of_float x\<close>] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2875
    from ub_ln_lb_ln_bounds'[OF A', THEN conjunct2, THEN le_imp_neg_le] this
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2876
    have "- the (ub_ln prec ?divr) \<le> ?ln" unfolding uminus_float.rep_eq by (rule order_trans)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2877
  }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2878
  ultimately show ?thesis unfolding lb_ln.simps[where x=x]  ub_ln.simps[where x=x]
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2879
    unfolding if_not_P[OF \<open>\<not> x \<le> 0\<close>] if_P[OF True] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2880
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2881
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2882
lemma lb_ln:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2883
  assumes "Some y = lb_ln prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2884
  shows "y \<le> ln x" and "0 < real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2885
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2886
  have "0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2887
  proof (rule ccontr)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2888
    assume "\<not> 0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2889
    hence "x \<le> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2890
      unfolding less_eq_float_def less_float_def by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2891
    thus False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2892
      using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2893
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2894
  thus "0 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2895
  have "the (lb_ln prec x) \<le> ln x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2896
    using ub_ln_lb_ln_bounds[OF \<open>0 < x\<close>] ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2897
  thus "y \<le> ln x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2898
    unfolding assms[symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2899
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2900
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2901
lemma ub_ln:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2902
  assumes "Some y = ub_ln prec x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2903
  shows "ln x \<le> y" and "0 < real_of_float x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2904
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2905
  have "0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2906
  proof (rule ccontr)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2907
    assume "\<not> 0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2908
    hence "x \<le> 0" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2909
    thus False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2910
      using assms by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2911
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2912
  thus "0 < real_of_float x" by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2913
  have "ln x \<le> the (ub_ln prec x)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2914
    using ub_ln_lb_ln_bounds[OF \<open>0 < x\<close>] ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2915
  thus "ln x \<le> y"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2916
    unfolding assms[symmetric] by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2917
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2918
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2919
lemma bnds_ln: "\<forall>(x::real) lx ux. (Some l, Some u) =
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2920
  (lb_ln prec lx, ub_ln prec ux) \<and> x \<in> {lx .. ux} \<longrightarrow> l \<le> ln x \<and> ln x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2921
proof (rule allI, rule allI, rule allI, rule impI)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2922
  fix x :: real
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2923
  fix lx ux
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2924
  assume "(Some l, Some u) = (lb_ln prec lx, ub_ln prec ux) \<and> x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2925
  hence l: "Some l = lb_ln prec lx " and u: "Some u = ub_ln prec ux" and x: "x \<in> {lx .. ux}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2926
    by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2927
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2928
  have "ln ux \<le> u" and "0 < real_of_float ux"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2929
    using ub_ln u by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2930
  have "l \<le> ln lx" and "0 < real_of_float lx" and "0 < x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2931
    using lb_ln[OF l] x by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2932
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2933
  from ln_le_cancel_iff[OF \<open>0 < real_of_float lx\<close> \<open>0 < x\<close>] \<open>l \<le> ln lx\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2934
  have "l \<le> ln x"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2935
    using x unfolding atLeastAtMost_iff by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2936
  moreover
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2937
  from ln_le_cancel_iff[OF \<open>0 < x\<close> \<open>0 < real_of_float ux\<close>] \<open>ln ux \<le> real_of_float u\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2938
  have "ln x \<le> u"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2939
    using x unfolding atLeastAtMost_iff by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2940
  ultimately show "l \<le> ln x \<and> ln x \<le> u" ..
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2941
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2942
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2943
lemmas [simp del] = lb_ln.simps ub_ln.simps
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2944
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2945
lemma lb_lnD:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2946
  "y \<le> ln x \<and> 0 < real_of_float x" if "lb_ln prec x = Some y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2947
  using lb_ln[OF that[symmetric]] by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2948
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2949
lemma ub_lnD:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2950
  "ln x \<le> y\<and> 0 < real_of_float x" if "ub_ln prec x = Some y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2951
  using ub_ln[OF that[symmetric]] by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2952
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2953
lift_definition(code_dt) ln_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval option"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2954
  is "\<lambda>prec. \<lambda>(lx, ux).
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2955
    Option.bind (lb_ln prec lx) (\<lambda>l.
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2956
      Option.bind (ub_ln prec ux) (\<lambda>u. Some (l, u)))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2957
  by (auto simp: pred_option_def bind_eq_Some_conv ln_le_cancel_iff[symmetric]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2958
      simp del: ln_le_cancel_iff dest!: lb_lnD ub_lnD)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2959
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2960
lemma ln_float_interval_eq_Some_conv:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2961
  "ln_float_interval p x = Some y \<longleftrightarrow>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2962
    lb_ln p (lower x) = Some (lower y) \<and> ub_ln p (upper x) = Some (upper y)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2963
  by transfer (auto simp: bind_eq_Some_conv)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2964
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2965
lemma ln_float_interval: "ln ` set_of (real_interval x) \<subseteq> set_of (real_interval y)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2966
  if "ln_float_interval p x = Some y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2967
  using that lb_ln[of "lower y" p "lower x"]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2968
    ub_ln[of "lower y" p "lower x"]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2969
  apply (auto simp add: set_of_eq ln_float_interval_eq_Some_conv ln_le_cancel_iff)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2970
   apply (meson less_le_trans ln_less_cancel_iff not_le)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2971
  by (meson less_le_trans ln_less_cancel_iff not_le ub_lnD)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2972
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2973
lemma ln_float_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2974
  "ln x \<in> set_of' (ln_float_interval p X)" if "x \<in>\<^sub>r X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2975
  using ln_float_interval[of p X] that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2976
  by (auto simp: set_of'_def split: option.splits)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  2977
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  2978
lemma ln_float_interval_eqI:
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  2979
  "ln x \<in>\<^sub>r IVL" if "ln_float_interval p X = Some IVL" "x \<in>\<^sub>r X"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  2980
  using ln_float_intervalI[of x X p] that
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  2981
  by (auto simp: set_of'_def split: option.splits)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  2982
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2983
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2984
section \<open>Real power function\<close>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2985
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2986
definition bnds_powr :: "nat \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> (float \<times> float) option" where
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2987
  "bnds_powr prec l1 u1 l2 u2 = (
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2988
     if l1 = 0 \<and> u1 = 0 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2989
       Some (0, 0)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2990
     else if l1 = 0 \<and> l2 \<ge> 1 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2991
       let uln = the (ub_ln prec u1)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2992
       in  Some (0, ub_exp prec (float_round_up prec (uln * (if uln \<ge> 0 then u2 else l2))))
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2993
     else if l1 \<le> 0 then
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2994
       None
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2995
     else
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2996
       Some (map_bnds lb_exp ub_exp prec 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2997
               (bnds_mult prec (the (lb_ln prec l1)) (the (ub_ln prec u1)) l2 u2)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2998
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  2999
lemma mono_exp_real: "mono (exp :: real \<Rightarrow> real)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3000
  by (auto simp: mono_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3001
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3002
lemma ub_exp_nonneg: "real_of_float (ub_exp prec x) \<ge> 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3003
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3004
  have "0 \<le> exp (real_of_float x)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3005
  also from exp_boundaries[of x prec] 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3006
    have "\<dots> \<le> real_of_float (ub_exp prec x)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3007
  finally show ?thesis .
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3008
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3009
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3010
lemma bnds_powr:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3011
  assumes lu: "Some (l, u) = bnds_powr prec l1 u1 l2 u2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3012
  assumes x: "x \<in> {real_of_float l1..real_of_float u1}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3013
  assumes y: "y \<in> {real_of_float l2..real_of_float u2}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3014
  shows   "x powr y \<in> {real_of_float l..real_of_float u}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3015
proof -
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3016
  consider "l1 = 0" "u1 = 0" | "l1 = 0" "u1 \<noteq> 0" "l2 \<ge> 1" | 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3017
           "l1 \<le> 0" "\<not>(l1 = 0 \<and> (u1 = 0 \<or> l2 \<ge> 1))" | "l1 > 0" by force
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3018
  thus ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3019
  proof cases
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3020
    assume "l1 = 0" "u1 = 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3021
    with x lu show ?thesis by (auto simp: bnds_powr_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3022
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3023
    assume A: "l1 = 0" "u1 \<noteq> 0" "l2 \<ge> 1"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3024
    define uln where "uln = the (ub_ln prec u1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3025
    show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3026
    proof (cases "x = 0")
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3027
      case False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3028
      with A x y have "x powr y = exp (ln x * y)" by (simp add: powr_def)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3029
      also {
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3030
        from A x False have "ln x \<le> ln (real_of_float u1)" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3031
        also from ub_ln_lb_ln_bounds[of u1 prec] A y x False
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3032
          have "ln (real_of_float u1) \<le> real_of_float uln" by (simp add: uln_def del: lb_ln.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3033
        also from A x y have "\<dots> * y \<le> real_of_float uln * (if uln \<ge> 0 then u2 else l2)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3034
          by (auto intro: mult_left_mono mult_left_mono_neg)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3035
        also have "\<dots> \<le> real_of_float (float_round_up prec (uln * (if uln \<ge> 0 then u2 else l2)))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3036
          by (simp add: float_round_up_le)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3037
        finally have "ln x * y \<le> \<dots>" using A y by - simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3038
      }
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3039
      also have "exp (real_of_float (float_round_up prec (uln * (if uln \<ge> 0 then u2 else l2)))) \<le>
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3040
                   real_of_float (ub_exp prec (float_round_up prec
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3041
                       (uln * (if uln \<ge> 0 then u2 else l2))))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3042
        using exp_boundaries by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3043
      finally show ?thesis using A x y lu 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3044
        by (simp add: bnds_powr_def uln_def Let_def del: lb_ln.simps ub_ln.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3045
    qed (insert x y lu A, simp_all add: bnds_powr_def Let_def ub_exp_nonneg
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3046
                                   del: lb_ln.simps ub_ln.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3047
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3048
    assume "l1 \<le> 0" "\<not>(l1 = 0 \<and> (u1 = 0 \<or> l2 \<ge> 1))"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3049
    with lu show ?thesis by (simp add: bnds_powr_def split: if_split_asm)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3050
  next
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3051
    assume l1: "l1 > 0"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3052
    obtain lm um where lmum:
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3053
      "(lm, um) = bnds_mult prec (the (lb_ln prec l1)) (the (ub_ln prec u1)) l2 u2"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3054
      by (cases "bnds_mult prec (the (lb_ln prec l1)) (the (ub_ln prec u1)) l2 u2") simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3055
    with l1 have "(l, u) = map_bnds lb_exp ub_exp prec (lm, um)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3056
      using lu by (simp add: bnds_powr_def del: lb_ln.simps ub_ln.simps split: if_split_asm)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3057
    hence "exp (ln x * y) \<in> {real_of_float l..real_of_float u}"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3058
    proof (rule map_bnds[OF _ mono_exp_real], goal_cases)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3059
      case 1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3060
      let ?lln = "the (lb_ln prec l1)" and ?uln = "the (ub_ln prec u1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3061
      from ub_ln_lb_ln_bounds[of l1 prec] ub_ln_lb_ln_bounds[of u1 prec] x l1
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3062
        have "real_of_float ?lln \<le> ln (real_of_float l1) \<and> 
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3063
              ln (real_of_float u1) \<le> real_of_float ?uln"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3064
        by (auto simp del: lb_ln.simps ub_ln.simps)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3065
      moreover from l1 x have "ln (real_of_float l1) \<le> ln x \<and> ln x \<le> ln (real_of_float u1)"
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3066
        by auto
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3067
      ultimately have ln: "real_of_float ?lln \<le> ln x \<and> ln x \<le> real_of_float ?uln" by simp
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3068
      from lmum show ?case
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3069
        by (rule bnds_mult) (insert y ln, simp_all)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3070
    qed (insert exp_boundaries[of lm prec] exp_boundaries[of um prec], simp_all)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3071
    with x l1 show ?thesis
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3072
      by (simp add: powr_def mult_ac)
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3073
  qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3074
qed
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3075
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3076
lift_definition(code_dt) powr_float_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval \<Rightarrow> float interval option"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3077
  is "\<lambda>prec. \<lambda>(l1, u1). \<lambda>(l2, u2). bnds_powr prec l1 u1 l2 u2"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3078
  by (auto simp: pred_option_def dest!: bnds_powr[OF sym])
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3079
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3080
lemma powr_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3081
  "{x powr y | x y. x \<in> set_of (real_interval X) \<and> y \<in> set_of (real_interval Y)}
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3082
    \<subseteq> set_of (real_interval R)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3083
  if "powr_float_interval prec X Y = Some R"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3084
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3085
  by transfer (auto dest!: bnds_powr[OF sym])
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3086
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3087
lemma powr_float_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3088
  "x powr y \<in> set_of' (powr_float_interval p X Y)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3089
  if "x \<in>\<^sub>r X" "y \<in>\<^sub>r Y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3090
  using powr_float_interval[of p X Y] that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3091
  by (auto simp: set_of'_def split: option.splits)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3092
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  3093
lemma powr_float_interval_eqI:
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  3094
  "x powr y \<in>\<^sub>r IVL"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  3095
  if "powr_float_interval p X Y = Some IVL" "x \<in>\<^sub>r X" "y \<in>\<^sub>r Y"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  3096
  using powr_float_intervalI[of x X y Y p] that
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  3097
  by (auto simp: set_of'_def split: option.splits)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
  3098
65582
a1bc1b020cf2 tuned Approximation: separated general material from oracle
eberlm <eberlm@in.tum.de>
parents:
diff changeset
  3099
end
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3100
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents: 70817
diff changeset
  3101
end