src/HOL/Library/Interval_Float.thy
author immler
Mon, 04 Nov 2019 21:41:55 -0500
changeset 71038 bd3d4702b4f2
parent 71037 f630f2e707a6
child 73537 56db8559eadb
permissions -rw-r--r--
add lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     1
section \<open>Approximate Operations on Intervals of Floating Point Numbers\<close>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     2
theory Interval_Float
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     3
  imports
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     4
    Interval
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     5
    Float
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     6
begin
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     7
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     8
definition mid :: "float interval \<Rightarrow> float"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
     9
  where "mid i = (lower i + upper i) * Float 1 (-1)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    10
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    11
lemma mid_in_interval: "mid i \<in>\<^sub>i i"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    12
  using lower_le_upper[of i]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    13
  by (auto simp: mid_def set_of_eq powr_minus)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    14
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    15
lemma mid_le: "lower i \<le> mid i" "mid i \<le> upper i"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    16
  using mid_in_interval
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    17
  by (auto simp: set_of_eq)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    18
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    19
definition centered :: "float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    20
  where "centered i = i - interval_of (mid i)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    21
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    22
definition "split_float_interval x = split_interval x ((lower x + upper x) * Float 1 (-1))"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    23
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    24
lemma split_float_intervalD: "split_float_interval X = (A, B) \<Longrightarrow> set_of X \<subseteq> set_of A \<union> set_of B"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    25
  by (auto dest!: split_intervalD simp: split_float_interval_def)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    26
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    27
lemma split_float_interval_bounds:
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    28
  shows
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    29
    lower_split_float_interval1: "lower (fst (split_float_interval X)) = lower X"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    30
  and lower_split_float_interval2: "lower (snd (split_float_interval X)) = mid X"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    31
  and upper_split_float_interval1: "upper (fst (split_float_interval X)) = mid X"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    32
  and upper_split_float_interval2: "upper (snd (split_float_interval X)) = upper X"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    33
  using mid_le[of X]
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    34
  by (auto simp: split_float_interval_def mid_def[symmetric] min_def max_def real_of_float_eq
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    35
      lower_split_interval1 lower_split_interval2
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    36
      upper_split_interval1 upper_split_interval2)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    37
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    38
lemmas float_round_down_le[intro] = order_trans[OF float_round_down]
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    39
  and float_round_up_ge[intro] = order_trans[OF _ float_round_up]
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
    40
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    41
text \<open>TODO: many of the lemmas should move to theories Float or Approximation
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    42
  (the latter should be based on type @{type interval}.\<close>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    43
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    44
subsection "Intervals with Floating Point Bounds"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    45
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    46
context includes interval.lifting begin
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    47
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    48
lift_definition round_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    49
  is "\<lambda>p. \<lambda>(l, u). (float_round_down p l, float_round_up p u)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    50
  by (auto simp: intro!: float_round_down_le float_round_up_le)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    51
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    52
lemma lower_round_ivl[simp]: "lower (round_interval p x) = float_round_down p (lower x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    53
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    54
lemma upper_round_ivl[simp]: "upper (round_interval p x) = float_round_up p (upper x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    55
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    56
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    57
lemma round_ivl_correct: "set_of A \<subseteq> set_of (round_interval prec A)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    58
  by (auto simp: set_of_eq float_round_down_le float_round_up_le)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    59
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    60
lift_definition truncate_ivl :: "nat \<Rightarrow> real interval \<Rightarrow> real interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    61
  is "\<lambda>p. \<lambda>(l, u). (truncate_down p l, truncate_up p u)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    62
  by (auto intro!: truncate_down_le truncate_up_le)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    63
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    64
lemma lower_truncate_ivl[simp]: "lower (truncate_ivl p x) = truncate_down p (lower x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    65
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    66
lemma upper_truncate_ivl[simp]: "upper (truncate_ivl p x) = truncate_up p (upper x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    67
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    68
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    69
lemma truncate_ivl_correct: "set_of A \<subseteq> set_of (truncate_ivl prec A)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    70
  by (auto simp: set_of_eq intro!: truncate_down_le truncate_up_le)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    71
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    72
lift_definition real_interval::"float interval \<Rightarrow> real interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    73
  is "\<lambda>(l, u). (real_of_float l, real_of_float u)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    74
  by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    75
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    76
lemma lower_real_interval[simp]: "lower (real_interval x) = lower x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    77
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    78
lemma upper_real_interval[simp]: "upper (real_interval x) = upper x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    79
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    80
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    81
definition "set_of' x = (case x of None \<Rightarrow> UNIV | Some i \<Rightarrow> set_of (real_interval i))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    82
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    83
lemma real_interval_min_interval[simp]:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    84
  "real_interval (min_interval a b) = min_interval (real_interval a) (real_interval b)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    85
  by (auto simp: interval_eq_set_of_iff set_of_eq real_of_float_min)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    86
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    87
lemma real_interval_max_interval[simp]:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    88
  "real_interval (max_interval a b) = max_interval (real_interval a) (real_interval b)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    89
  by (auto simp: interval_eq_set_of_iff set_of_eq real_of_float_max)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    90
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    91
lemma in_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    92
  "x \<in>\<^sub>i X" if "lower X \<le> x" "x \<le> upper X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    93
  using that by (auto simp: set_of_eq)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    94
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    95
abbreviation in_real_interval ("(_/ \<in>\<^sub>r _)" [51, 51] 50) where
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    96
  "x \<in>\<^sub>r X \<equiv> x \<in>\<^sub>i real_interval X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    97
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    98
lemma in_real_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
    99
  "x \<in>\<^sub>r X" if "lower X \<le> x" "x \<le> upper X" for x::real and X::"float interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   100
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   101
  by (intro in_intervalI) auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   102
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   103
subsection \<open>intros for \<open>real_interval\<close>\<close>
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   104
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   105
lemma in_round_intervalI: "x \<in>\<^sub>r A  \<Longrightarrow> x \<in>\<^sub>r (round_interval prec A)"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   106
  by (auto simp: set_of_eq float_round_down_le float_round_up_le)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   107
71038
bd3d4702b4f2 add lemmas
immler
parents: 71037
diff changeset
   108
lemma zero_in_float_intervalI: "0 \<in>\<^sub>r 0"
bd3d4702b4f2 add lemmas
immler
parents: 71037
diff changeset
   109
  by (auto simp: set_of_eq)
bd3d4702b4f2 add lemmas
immler
parents: 71037
diff changeset
   110
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   111
lemma plus_in_float_intervalI: "a + b \<in>\<^sub>r A + B" if "a \<in>\<^sub>r A" "b \<in>\<^sub>r B"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   112
  using that
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   113
  by (auto simp: set_of_eq)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   114
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   115
lemma minus_in_float_intervalI: "a - b \<in>\<^sub>r A - B" if "a \<in>\<^sub>r A" "b \<in>\<^sub>r B"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   116
  using that
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   117
  by (auto simp: set_of_eq)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   118
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   119
lemma uminus_in_float_intervalI: "-a \<in>\<^sub>r -A" if "a \<in>\<^sub>r A"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   120
  using that
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   121
  by (auto simp: set_of_eq)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   122
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   123
lemma real_interval_times: "real_interval (A * B) = real_interval A * real_interval B"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   124
  by (auto simp: interval_eq_iff lower_times upper_times min_def max_def)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   125
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   126
lemma times_in_float_intervalI: "a * b \<in>\<^sub>r A * B" if "a \<in>\<^sub>r A" "b \<in>\<^sub>r B"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   127
  using times_in_intervalI[OF that]
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   128
  by (auto simp: real_interval_times)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   129
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   130
lemma real_interval_abs: "real_interval (abs_interval A) = abs_interval (real_interval A)"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   131
  by (auto simp: interval_eq_iff min_def max_def)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   132
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   133
lemma abs_in_float_intervalI: "abs a \<in>\<^sub>r abs_interval A" if "a \<in>\<^sub>r A"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   134
  by (auto simp: set_of_abs_interval real_interval_abs intro!: imageI that)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   135
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   136
lemma interval_of[intro,simp]: "x \<in>\<^sub>r interval_of x"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   137
  by (auto simp: set_of_eq)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   138
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   139
lemma split_float_interval_realD: "split_float_interval X = (A, B) \<Longrightarrow> x \<in>\<^sub>r X \<Longrightarrow> x \<in>\<^sub>r A \<or> x \<in>\<^sub>r B"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   140
  by (auto simp: set_of_eq prod_eq_iff split_float_interval_bounds)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   141
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   142
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   143
subsection \<open>bounds for lists\<close>
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   144
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   145
lemma lower_Interval: "lower (Interval x) = fst x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   146
  and upper_Interval: "upper (Interval x) = snd x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   147
  if "fst x \<le> snd x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   148
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   149
  by (auto simp: lower_def upper_def Interval_inverse split_beta')
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   150
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   151
definition all_in_i :: "'a::preorder list \<Rightarrow> 'a interval list \<Rightarrow> bool"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   152
  (infix "(all'_in\<^sub>i)" 50)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   153
  where "x all_in\<^sub>i I = (length x = length I \<and> (\<forall>i < length I. x ! i \<in>\<^sub>i I ! i))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   154
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   155
definition all_in :: "real list \<Rightarrow> float interval list \<Rightarrow> bool"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   156
  (infix "(all'_in)" 50)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   157
  where "x all_in I = (length x = length I \<and> (\<forall>i < length I. x ! i \<in>\<^sub>r I ! i))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   158
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   159
definition all_subset :: "'a::order interval list \<Rightarrow> 'a interval list \<Rightarrow> bool"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   160
  (infix "(all'_subset)" 50)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   161
  where "I all_subset J = (length I = length J \<and> (\<forall>i < length I. set_of (I!i) \<subseteq> set_of (J!i)))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   162
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   163
lemmas [simp] = all_in_def all_subset_def
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   164
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   165
lemma all_subsetD:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   166
  assumes "I all_subset J"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   167
  assumes "x all_in I"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   168
  shows "x all_in J"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   169
  using assms
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   170
  by (auto simp: set_of_eq; fastforce)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   171
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   172
lemma round_interval_mono: "set_of (round_interval prec X) \<subseteq> set_of (round_interval prec Y)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   173
  if "set_of X \<subseteq> set_of Y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   174
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   175
  by transfer
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   176
    (auto simp: float_round_down.rep_eq float_round_up.rep_eq truncate_down_mono truncate_up_mono)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   177
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   178
lemma Ivl_simps[simp]: "lower (Ivl a b) = min a b" "upper (Ivl a b) = b"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   179
  subgoal by transfer simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   180
  subgoal by transfer simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   181
  done
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   182
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   183
lemma set_of_subset_iff: "set_of X \<subseteq> set_of Y \<longleftrightarrow> lower Y \<le> lower X \<and> upper X \<le> upper Y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   184
  for X Y::"'a::linorder interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   185
  by (auto simp: set_of_eq subset_iff)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   186
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   187
lemma bounds_of_interval_eq_lower_upper:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   188
  "bounds_of_interval ivl = (lower ivl, upper ivl)" if "lower ivl \<le> upper ivl"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   189
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   190
  by (auto simp: lower.rep_eq upper.rep_eq)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   191
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   192
lemma real_interval_Ivl: "real_interval (Ivl a b) = Ivl a b"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   193
  by transfer (auto simp: min_def)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   194
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   195
lemma set_of_mul_contains_real_zero:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   196
  "0 \<in>\<^sub>r (A * B)" if "0 \<in>\<^sub>r A \<or> 0 \<in>\<^sub>r B"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   197
  using that set_of_mul_contains_zero[of A B]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   198
  by (auto simp: set_of_eq)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   199
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   200
fun subdivide_interval :: "nat \<Rightarrow> float interval \<Rightarrow> float interval list"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   201
  where "subdivide_interval 0 I = [I]"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   202
  | "subdivide_interval (Suc n) I = (
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   203
         let m = mid I
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   204
         in (subdivide_interval n (Ivl (lower I) m)) @ (subdivide_interval n (Ivl m (upper I)))
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   205
       )"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   206
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   207
lemma subdivide_interval_length:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   208
  shows "length (subdivide_interval n I) = 2^n"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   209
  by(induction n arbitrary: I, simp_all add: Let_def)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   210
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   211
lemma lower_le_mid: "lower x \<le> mid x" "real_of_float (lower x) \<le> mid x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   212
  and mid_le_upper: "mid x \<le> upper x" "real_of_float (mid x) \<le> upper x"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   213
  unfolding mid_def
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   214
  subgoal by transfer (auto simp: powr_neg_one)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   215
  subgoal by transfer (auto simp: powr_neg_one)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   216
  subgoal by transfer (auto simp: powr_neg_one)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   217
  subgoal by transfer (auto simp: powr_neg_one)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   218
  done
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   219
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   220
lemma subdivide_interval_correct:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   221
  "list_ex (\<lambda>i. x \<in>\<^sub>r i) (subdivide_interval n I)" if "x \<in>\<^sub>r I" for x::real
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   222
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   223
proof(induction n arbitrary: x I)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   224
  case 0
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   225
  then show ?case by simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   226
next
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   227
  case (Suc n)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   228
  from \<open>x \<in>\<^sub>r I\<close> consider "x \<in>\<^sub>r Ivl (lower I) (mid I)" | "x \<in>\<^sub>r Ivl (mid I) (upper I)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   229
    by (cases "x \<le> real_of_float (mid I)")
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   230
      (auto simp: set_of_eq min_def lower_le_mid mid_le_upper)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   231
  from this[case_names lower upper] show ?case
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   232
    by cases (use Suc.IH in \<open>auto simp: Let_def\<close>)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   233
qed
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   234
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   235
fun interval_list_union :: "'a::lattice interval list \<Rightarrow> 'a interval"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   236
  where "interval_list_union [] = undefined"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   237
  | "interval_list_union [I] = I"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   238
  | "interval_list_union (I#Is) = sup I (interval_list_union Is)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   239
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   240
lemma interval_list_union_correct:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   241
  assumes "S \<noteq> []"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   242
  assumes "i < length S"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   243
  shows "set_of (S!i) \<subseteq> set_of (interval_list_union S)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   244
  using assms
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   245
proof(induction S arbitrary: i)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   246
  case (Cons a S i)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   247
  thus ?case
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   248
  proof(cases S)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   249
    fix b S'
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   250
    assume "S = b # S'"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   251
    hence "S \<noteq> []"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   252
      by simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   253
    show ?thesis
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   254
    proof(cases i)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   255
      case 0
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   256
      show ?thesis
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   257
        apply(cases S)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   258
        using interval_union_mono1
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   259
        by (auto simp add: 0)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   260
    next
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   261
      case (Suc i_prev)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   262
      hence "i_prev < length S"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   263
        using Cons(3) by simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   264
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   265
      from Cons(1)[OF \<open>S \<noteq> []\<close> this] Cons(1)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   266
      have "set_of ((a # S) ! i) \<subseteq> set_of (interval_list_union S)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   267
        by (simp add: \<open>i = Suc i_prev\<close>)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   268
      also have "... \<subseteq> set_of (interval_list_union (a # S))"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   269
        using \<open>S \<noteq> []\<close>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   270
        apply(cases S)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   271
        using interval_union_mono2
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   272
        by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   273
      finally show ?thesis .
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   274
    qed
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   275
  qed simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   276
qed simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   277
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   278
lemma split_domain_correct:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   279
  fixes x :: "real list"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   280
  assumes "x all_in I"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   281
  assumes split_correct: "\<And>x a I. x \<in>\<^sub>r I \<Longrightarrow> list_ex (\<lambda>i::float interval. x \<in>\<^sub>r i) (split I)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   282
  shows "list_ex (\<lambda>s. x all_in s) (split_domain split I)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   283
  using assms(1)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   284
proof(induction I arbitrary: x)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   285
  case (Cons I Is x)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   286
  have "x \<noteq> []"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   287
    using Cons(2) by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   288
  obtain x' xs where x_decomp: "x = x' # xs"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   289
    using \<open>x \<noteq> []\<close> list.exhaust by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   290
  hence "x' \<in>\<^sub>r I" "xs all_in Is"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   291
    using Cons(2)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   292
    by auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   293
  show ?case
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   294
    using Cons(1)[OF \<open>xs all_in Is\<close>]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   295
      split_correct[OF \<open>x' \<in>\<^sub>r I\<close>]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   296
    apply (auto simp add: list_ex_iff set_of_eq)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   297
    by (smt length_Cons less_Suc_eq_0_disj nth_Cons_0 nth_Cons_Suc x_decomp)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   298
qed simp
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   299
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   300
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   301
lift_definition(code_dt) inverse_float_interval::"nat \<Rightarrow> float interval \<Rightarrow> float interval option" is
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   302
  "\<lambda>prec (l, u). if (0 < l \<or> u < 0) then Some (float_divl prec 1 u, float_divr prec 1 l) else None"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   303
  by (auto intro!: order_trans[OF float_divl] order_trans[OF _ float_divr]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   304
      simp: divide_simps)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   305
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   306
lemma inverse_float_interval_eq_Some_conv:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   307
  defines "one \<equiv> (1::float)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   308
  shows 
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   309
    "inverse_float_interval p X = Some R \<longleftrightarrow>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   310
    (lower X > 0 \<or> upper X < 0) \<and>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   311
    lower R = float_divl p one (upper X) \<and>
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   312
    upper R = float_divr p one (lower X)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   313
  by clarsimp (transfer fixing: one, force simp: one_def split: if_splits)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   314
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   315
lemma inverse_float_interval:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   316
  "inverse ` set_of (real_interval X) \<subseteq> set_of (real_interval Y)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   317
  if "inverse_float_interval p X = Some Y"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   318
  using that
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   319
  apply (clarsimp simp: set_of_eq inverse_float_interval_eq_Some_conv)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   320
  by (intro order_trans[OF float_divl] order_trans[OF _ float_divr] conjI)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   321
    (auto simp: divide_simps)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   322
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   323
lemma inverse_float_intervalI:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   324
  "x \<in>\<^sub>r X \<Longrightarrow> inverse x \<in> set_of' (inverse_float_interval p X)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   325
  using inverse_float_interval[of p X]
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   326
  by (auto simp: set_of'_def split: option.splits)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   327
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   328
lemma inverse_float_interval_eqI: "inverse_float_interval p X = Some IVL \<Longrightarrow> x \<in>\<^sub>r X \<Longrightarrow> inverse x \<in>\<^sub>r IVL"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   329
  using inverse_float_intervalI[of x X p]
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   330
  by (auto simp: set_of'_def)
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   331
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   332
lemma real_interval_abs_interval[simp]:
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   333
  "real_interval (abs_interval x) = abs_interval (real_interval x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   334
  by (auto simp: interval_eq_set_of_iff set_of_eq real_of_float_max real_of_float_min)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   335
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   336
lift_definition floor_float_interval::"float interval \<Rightarrow> float interval" is
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   337
  "\<lambda>(l, u). (floor_fl l, floor_fl u)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   338
  by (auto intro!: floor_mono simp: floor_fl.rep_eq)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   339
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   340
lemma lower_floor_float_interval[simp]: "lower (floor_float_interval x) = floor_fl (lower x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   341
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   342
lemma upper_floor_float_interval[simp]: "upper (floor_float_interval x) = floor_fl (upper x)"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   343
  by transfer auto
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   344
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   345
lemma floor_float_intervalI: "\<lfloor>x\<rfloor> \<in>\<^sub>r floor_float_interval X" if "x \<in>\<^sub>r X"
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   346
  using that by (auto simp: set_of_eq floor_fl_def floor_mono)
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   347
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   348
end
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   349
71037
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   350
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   351
subsection \<open>constants for code generation\<close>
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   352
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   353
definition lowerF::"float interval \<Rightarrow> float" where "lowerF = lower"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   354
definition upperF::"float interval \<Rightarrow> float" where "upperF = upper"
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   355
f630f2e707a6 refactor Approximation.thy to use more abstract type of intervals
immler
parents: 71036
diff changeset
   356
71036
dfcc1882d05a moved theory Interval_Approximation from the AFP
immler
parents:
diff changeset
   357
end