Theory Lorenz_Approximation
section"Example: Lorenz attractor"
theory Lorenz_Approximation
imports
"HOL-ODE-Numerics.ODE_Numerics"
Result_File_Coarse
begin
lemma replicate_numeral [simp]: "replicate (numeral k) x = x # replicate (pred_numeral k) x"
by (simp add: numeral_eq_Suc)
text ‹\label{sec:lorenz}›
text ‹TODO: move to isabelle? ›
lifting_update blinfun.lifting
lifting_forget blinfun.lifting
lemma eventually_uniformly_on:
"(∀⇩F x in uniformly_on T l. P x) = (∃e>0. ∀f. (∀x∈T. dist (f x) (l x) < e) ⟶ P f)"
unfolding uniformly_on_def
apply (subst eventually_INF)
apply safe
subgoal for E
apply (cases "E = {}")
subgoal by (auto intro!: exI[where x=1])
subgoal
apply (auto simp: INF_principal_finite eventually_principal elim!: )
proof goal_cases
case (1 x)
from 1 have "0 < Min E"
apply (subst Min_gr_iff)
apply force apply force apply force done
have *: "(⋂e∈E. {f. ∀t∈T. dist (f t) (l t) < e}) = {f. ∀t∈T. dist (f t) (l t) < Min E}"
using 1 apply auto
apply (subst Min_gr_iff)
apply force apply force apply force
apply (drule bspec, assumption)
apply (rule less_le_trans, assumption)
apply auto
done
from 1 have "∀f. (∀x∈T. dist (f x) (l x) < Min E) ⟶ P f" unfolding * by simp
then show ?case
using 1(4)[rule_format, OF ‹0 < Min E›] by auto
qed
done
subgoal for e
apply (rule exI[where x="{e}"])
by (auto simp: eventually_principal)
done
lemma op_cast_image_impl[autoref_rules]:
"(λx. x, op_cast_image::'a::executable_euclidean_space set ⇒
'b::executable_euclidean_space set)
∈ aform.appr_rel → aform.appr_rel"
if "DIM('a) = DIM('b)"
using that
apply (auto simp: aform.appr_rel_def intro!: relcompI)
unfolding lv_rel_def set_rel_br
by (force simp: intro!: brI dest!: brD)
lemma cast_bl_blinfun_of_list[simp]:
"cast_bl (blinfun_of_list xs::'a ⇒⇩L 'a) =
(blinfun_of_list xs::'b⇒⇩L'b)"
if "DIM('a::executable_euclidean_space) = DIM('b::executable_euclidean_space)"
using that
apply (auto simp: cast_bl_rep intro!: blinfun_eqI)
by (auto simp: blinfun_of_list_def blinfun_of_matrix_apply
linear_sum linear.scaleR sum_Basis_sum_nth_Basis_list
linear_cast)
lemma cast_idem[simp]: "cast x = x"
by (auto simp: cast_def)
lemma cast_bl_idem[simp]: "cast_bl x = x"
by (auto simp: cast_bl_rep intro!: blinfun_eqI)
lemma op_cast_eucl1_image_impl[autoref_rules]:
"(λx. x, op_cast_eucl1_image::'a::executable_euclidean_space c1_info set ⇒
'b::executable_euclidean_space c1_info set)
∈ aform.appr1_rel → aform.appr1_rel"
if "DIM_precond TYPE('a) D"
"DIM_precond TYPE('b) D"
using that
proof (auto, goal_cases)
case (1 a b a')
then show ?case
apply (auto simp: aform.appr1_rel_br set_rel_br br_def)
subgoal for w x y z
apply (auto simp: aform.c1_info_of_appr_def cast_eucl1_def aform.c1_info_invar_def
split: option.splits)
apply (rule image_eqI)
apply (rule cast_eucl_of_list, force, force simp: Joints_imp_length_eq, force)
subgoal for s t
apply (rule image_eqI[where x="t"])
supply [simp del] = eucl_of_list_take_DIM
apply (auto simp: flow1_of_list_def)
apply (subst cast_eucl_of_list)
subgoal by simp
subgoal
by (auto dest!: Joints_imp_length_eq
simp: power2_eq_square flow1_of_list_def[abs_def])
subgoal by simp
done
done
subgoal for w x
apply (rule image_eqI[where x="cast_eucl1 (w, x)"])
apply (auto simp: aform.c1_info_of_appr_def cast_eucl1_def
aform.c1_info_invar_def
split: option.splits)
apply (rule image_eqI)
apply (rule cast_eucl_of_list, force, force simp: Joints_imp_length_eq, force)
subgoal for s t
apply (rule image_eqI[where x="t"])
supply [simp del] = eucl_of_list_take_DIM
apply (auto simp: flow1_of_list_def)
apply (subst cast_eucl_of_list)
subgoal by simp
subgoal
by (auto dest!: Joints_imp_length_eq
simp: power2_eq_square flow1_of_list_def[abs_def])
subgoal by simp
done
done
done
qed
lemma less_3_iff: "i < (3::nat) ⟷ i = 0 ∨ i = 1 ∨ i = 2"
by arith
definition mat3_of_vec::"R3 ⇒ real^3^3" where
"mat3_of_vec x = (let xs = list_of_eucl x in eucl_of_list [xs!0,0,0, xs!1,0,0, xs!2,0,0])"
lemma ll3: "{..<3} = {0,1,2::nat}"
by (auto simp: less_3_iff)
lemma mat3_of_vec: "cast (mat3_of_vec x *v eucl_of_list [1, 0, 0]) = x"
by (auto simp: mat3_of_vec_def eucl_of_list_matrix_vector_mult_eq_sum_nth_Basis_list
linear_sum linear_cast linear.scaleR ll3 linear_add Basis_list_R3 inner_prod_def
prod_eq_iff)
primrec bisect_form where
"bisect_form p f xs l u 0 = (l, u)"
| "bisect_form p f xs l u (Suc n) =
(let m = (l + u)/2 in
if approx_form_aform p (f m) xs
then bisect_form p f xs l m n
else bisect_form p f xs m u n)"
text ‹This should prove that the expansion estimates are sufficient.›
lemma expansion_main: "expansion_main (coarse_results) = Some True"
by eval
context includes floatarith_syntax begin
definition "matrix_of_degrees2⇩e =
(let
e = Var 2;
ur = Rad_of (Var 0);
vr = Rad_of (Var 1);
x1 = Cos ur;
x2 = Cos vr;
y1 = Sin ur;
y2 = Sin vr
in
[x1 + (e * (x2 - x1)), 0, 0,
y1 + (e * (y2 - y1)), 0, 0,
0, 0, 0])"
definition "matrix_of_degrees2 u v =
approx_floatariths 30 matrix_of_degrees2⇩e (aforms_of_ivls [u, v, 0] [u, v, 1])"
text ‹following ‹vector_field.h› / ‹vector_field.cc››
abbreviation "S ≡ 10::real"
abbreviation "B ≡ 8/3::real"
abbreviation "TEMP ≡ sqrt((S + 1) * (S + 1) + 4 * S * (28 - 1))"
abbreviation "K1 ≡ S / TEMP"
abbreviation "K2 ≡ (S - 1 + TEMP) / (2 * S)"
abbreviation "K3 ≡ (S - 1 - TEMP) / (2 * S)"
abbreviation "E1 ≡ (- (S + 1) + TEMP) / 2"
abbreviation "E2 ≡ (- (S + 1) - TEMP) / 2"
abbreviation "E3 ≡ - B"
abbreviation "C1 ≡ λX. X ! 0 + X ! 1"
abbreviation "C2 ≡ λX. K1 * C1 X * X ! 2"
schematic_goal
lorenz_fas:
"[E1 * X!0 - C2 X,
E2 * X!1 + C2 X,
E3 * X!2 + C1 X * (K2 * X!0 + K3 * X!1)] =
interpret_floatariths ?fas X"
by (reify_floatariths)
concrete_definition lorenz_fas uses lorenz_fas
end