6 |
6 |
7 subsection "Interval Analysis" |
7 subsection "Interval Analysis" |
8 |
8 |
9 datatype ivl = I "int option" "int option" |
9 datatype ivl = I "int option" "int option" |
10 |
10 |
11 definition "rep_ivl i = (case i of |
11 definition "\<gamma>_ivl i = (case i of |
12 I (Some l) (Some h) \<Rightarrow> {l..h} | |
12 I (Some l) (Some h) \<Rightarrow> {l..h} | |
13 I (Some l) None \<Rightarrow> {l..} | |
13 I (Some l) None \<Rightarrow> {l..} | |
14 I None (Some h) \<Rightarrow> {..h} | |
14 I None (Some h) \<Rightarrow> {..h} | |
15 I None None \<Rightarrow> UNIV)" |
15 I None None \<Rightarrow> UNIV)" |
16 |
16 |
24 "{\<dots>} == I None None" |
24 "{\<dots>} == I None None" |
25 |
25 |
26 definition "num_ivl n = {n\<dots>n}" |
26 definition "num_ivl n = {n\<dots>n}" |
27 |
27 |
28 definition |
28 definition |
29 [code_abbrev]: "contained_in i k \<longleftrightarrow> k \<in> rep_ivl i" |
29 [code_abbrev]: "contained_in i k \<longleftrightarrow> k \<in> \<gamma>_ivl i" |
30 |
30 |
31 lemma contained_in_simps [code]: |
31 lemma contained_in_simps [code]: |
32 "contained_in (I (Some l) (Some h)) k \<longleftrightarrow> l \<le> k \<and> k \<le> h" |
32 "contained_in (I (Some l) (Some h)) k \<longleftrightarrow> l \<le> k \<and> k \<le> h" |
33 "contained_in (I (Some l) None) k \<longleftrightarrow> l \<le> k" |
33 "contained_in (I (Some l) None) k \<longleftrightarrow> l \<le> k" |
34 "contained_in (I None (Some h)) k \<longleftrightarrow> k \<le> h" |
34 "contained_in (I None (Some h)) k \<longleftrightarrow> k \<le> h" |
35 "contained_in (I None None) k \<longleftrightarrow> True" |
35 "contained_in (I None None) k \<longleftrightarrow> True" |
36 by (simp_all add: contained_in_def rep_ivl_def) |
36 by (simp_all add: contained_in_def \<gamma>_ivl_def) |
37 |
37 |
38 instantiation option :: (plus)plus |
38 instantiation option :: (plus)plus |
39 begin |
39 begin |
40 |
40 |
41 fun plus_option where |
41 fun plus_option where |
54 |
54 |
55 lemma [simp]: "is_empty(I l h) = |
55 lemma [simp]: "is_empty(I l h) = |
56 (case l of Some l \<Rightarrow> (case h of Some h \<Rightarrow> h<l | None \<Rightarrow> False) | None \<Rightarrow> False)" |
56 (case l of Some l \<Rightarrow> (case h of Some h \<Rightarrow> h<l | None \<Rightarrow> False) | None \<Rightarrow> False)" |
57 by(auto split:option.split) |
57 by(auto split:option.split) |
58 |
58 |
59 lemma [simp]: "is_empty i \<Longrightarrow> rep_ivl i = {}" |
59 lemma [simp]: "is_empty i \<Longrightarrow> \<gamma>_ivl i = {}" |
60 by(auto simp add: rep_ivl_def split: ivl.split option.split) |
60 by(auto simp add: \<gamma>_ivl_def split: ivl.split option.split) |
61 |
61 |
62 definition "plus_ivl i1 i2 = (if is_empty i1 | is_empty i2 then empty else |
62 definition "plus_ivl i1 i2 = (if is_empty i1 | is_empty i2 then empty else |
63 case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow> I (l1+l2) (h1+h2))" |
63 case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow> I (l1+l2) (h1+h2))" |
64 |
64 |
65 instantiation ivl :: SL_top |
65 instantiation ivl :: SL_top |
152 end |
152 end |
153 |
153 |
154 definition "minus_ivl i1 i2 = (if is_empty i1 | is_empty i2 then empty else |
154 definition "minus_ivl i1 i2 = (if is_empty i1 | is_empty i2 then empty else |
155 case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow> I (l1-h2) (h1-l2))" |
155 case (i1,i2) of (I l1 h1, I l2 h2) \<Rightarrow> I (l1-h2) (h1-l2))" |
156 |
156 |
157 lemma rep_minus_ivl: |
157 lemma gamma_minus_ivl: |
158 "n1 : rep_ivl i1 \<Longrightarrow> n2 : rep_ivl i2 \<Longrightarrow> n1-n2 : rep_ivl(minus_ivl i1 i2)" |
158 "n1 : \<gamma>_ivl i1 \<Longrightarrow> n2 : \<gamma>_ivl i2 \<Longrightarrow> n1-n2 : \<gamma>_ivl(minus_ivl i1 i2)" |
159 by(auto simp add: minus_ivl_def rep_ivl_def split: ivl.splits option.splits) |
159 by(auto simp add: minus_ivl_def \<gamma>_ivl_def split: ivl.splits option.splits) |
160 |
160 |
161 |
161 |
162 definition "filter_plus_ivl i i1 i2 = ((*if is_empty i then empty else*) |
162 definition "filter_plus_ivl i i1 i2 = ((*if is_empty i then empty else*) |
163 i1 \<sqinter> minus_ivl i i2, i2 \<sqinter> minus_ivl i i1)" |
163 i1 \<sqinter> minus_ivl i i2, i2 \<sqinter> minus_ivl i i1)" |
164 |
164 |
168 if res |
168 if res |
169 then (I l1 (min_option True h1 (h2 - Some 1)), |
169 then (I l1 (min_option True h1 (h2 - Some 1)), |
170 I (max_option False (l1 + Some 1) l2) h2) |
170 I (max_option False (l1 + Some 1) l2) h2) |
171 else (I (max_option False l1 l2) h1, I l2 (min_option True h1 h2)))" |
171 else (I (max_option False l1 l2) h1, I l2 (min_option True h1 h2)))" |
172 |
172 |
173 interpretation Val_abs rep_ivl num_ivl plus_ivl |
173 interpretation Val_abs \<gamma>_ivl num_ivl plus_ivl |
174 defines aval_ivl is aval' |
174 defines aval_ivl is aval' |
175 proof |
175 proof |
176 case goal1 thus ?case |
176 case goal1 thus ?case |
177 by(auto simp: rep_ivl_def le_ivl_def le_option_def split: ivl.split option.split if_splits) |
177 by(auto simp: \<gamma>_ivl_def le_ivl_def le_option_def split: ivl.split option.split if_splits) |
178 next |
178 next |
179 case goal2 show ?case by(simp add: rep_ivl_def Top_ivl_def) |
179 case goal2 show ?case by(simp add: \<gamma>_ivl_def Top_ivl_def) |
180 next |
180 next |
181 case goal3 thus ?case by(simp add: rep_ivl_def num_ivl_def) |
181 case goal3 thus ?case by(simp add: \<gamma>_ivl_def num_ivl_def) |
182 next |
182 next |
183 case goal4 thus ?case |
183 case goal4 thus ?case |
184 by(auto simp add: rep_ivl_def plus_ivl_def split: ivl.split option.splits) |
184 by(auto simp add: \<gamma>_ivl_def plus_ivl_def split: ivl.split option.splits) |
185 qed |
185 qed |
186 |
186 |
187 interpretation Val_abs1_rep rep_ivl num_ivl plus_ivl |
187 interpretation Val_abs1_gamma \<gamma>_ivl num_ivl plus_ivl |
188 proof |
188 proof |
189 case goal1 thus ?case |
189 case goal1 thus ?case |
190 by(auto simp add: rep_ivl_def meet_ivl_def empty_def min_option_def max_option_def split: ivl.split option.split) |
190 by(auto simp add: \<gamma>_ivl_def meet_ivl_def empty_def min_option_def max_option_def split: ivl.split option.split) |
191 next |
191 next |
192 case goal2 show ?case by(auto simp add: bot_ivl_def rep_ivl_def empty_def) |
192 case goal2 show ?case by(auto simp add: bot_ivl_def \<gamma>_ivl_def empty_def) |
193 qed |
193 qed |
194 |
194 |
195 lemma mono_minus_ivl: |
195 lemma mono_minus_ivl: |
196 "i1 \<sqsubseteq> i1' \<Longrightarrow> i2 \<sqsubseteq> i2' \<Longrightarrow> minus_ivl i1 i2 \<sqsubseteq> minus_ivl i1' i2'" |
196 "i1 \<sqsubseteq> i1' \<Longrightarrow> i2 \<sqsubseteq> i2' \<Longrightarrow> minus_ivl i1 i2 \<sqsubseteq> minus_ivl i1' i2'" |
197 apply(auto simp add: minus_ivl_def empty_def le_ivl_def le_option_def split: ivl.splits) |
197 apply(auto simp add: minus_ivl_def empty_def le_ivl_def le_option_def split: ivl.splits) |
200 apply(simp split: option.splits) |
200 apply(simp split: option.splits) |
201 done |
201 done |
202 |
202 |
203 |
203 |
204 interpretation |
204 interpretation |
205 Val_abs1 rep_ivl num_ivl plus_ivl filter_plus_ivl filter_less_ivl |
205 Val_abs1 \<gamma>_ivl num_ivl plus_ivl filter_plus_ivl filter_less_ivl |
206 proof |
206 proof |
207 case goal1 thus ?case |
207 case goal1 thus ?case |
208 by(auto simp add: filter_plus_ivl_def) |
208 by(auto simp add: filter_plus_ivl_def) |
209 (metis rep_minus_ivl add_diff_cancel add_commute)+ |
209 (metis gamma_minus_ivl add_diff_cancel add_commute)+ |
210 next |
210 next |
211 case goal2 thus ?case |
211 case goal2 thus ?case |
212 by(cases a1, cases a2, |
212 by(cases a1, cases a2, |
213 auto simp: rep_ivl_def min_option_def max_option_def le_option_def split: if_splits option.splits) |
213 auto simp: \<gamma>_ivl_def min_option_def max_option_def le_option_def split: if_splits option.splits) |
214 qed |
214 qed |
215 |
215 |
216 interpretation |
216 interpretation |
217 Abs_Int1 rep_ivl num_ivl plus_ivl filter_plus_ivl filter_less_ivl |
217 Abs_Int1 \<gamma>_ivl num_ivl plus_ivl filter_plus_ivl filter_less_ivl |
218 defines afilter_ivl is afilter |
218 defines afilter_ivl is afilter |
219 and bfilter_ivl is bfilter |
219 and bfilter_ivl is bfilter |
220 and step_ivl is step' |
220 and step_ivl is step' |
221 and AI_ivl is AI |
221 and AI_ivl is AI |
222 and aval_ivl' is aval'' |
222 and aval_ivl' is aval'' |
224 |
224 |
225 |
225 |
226 text{* Monotonicity: *} |
226 text{* Monotonicity: *} |
227 |
227 |
228 interpretation |
228 interpretation |
229 Abs_Int1_mono rep_ivl num_ivl plus_ivl filter_plus_ivl filter_less_ivl |
229 Abs_Int1_mono \<gamma>_ivl num_ivl plus_ivl filter_plus_ivl filter_less_ivl |
230 proof |
230 proof |
231 case goal1 thus ?case |
231 case goal1 thus ?case |
232 by(auto simp: plus_ivl_def le_ivl_def le_option_def empty_def split: if_splits ivl.splits option.splits) |
232 by(auto simp: plus_ivl_def le_ivl_def le_option_def empty_def split: if_splits ivl.splits option.splits) |
233 next |
233 next |
234 case goal2 thus ?case |
234 case goal2 thus ?case |