src/HOL/Nonstandard_Analysis/Star.thy
 author haftmann Mon Jun 05 15:59:41 2017 +0200 (2017-06-05) changeset 66010 2f7d39285a1a parent 64435 c93b0e6131c3 child 67613 ce654b0e6d69 permissions -rw-r--r--
executable domain membership checks
```     1 (*  Title:      HOL/Nonstandard_Analysis/Star.thy
```
```     2     Author:     Jacques D. Fleuriot
```
```     3     Copyright:  1998  University of Cambridge
```
```     4     Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
```
```     5 *)
```
```     6
```
```     7 section \<open>Star-Transforms in Non-Standard Analysis\<close>
```
```     8
```
```     9 theory Star
```
```    10   imports NSA
```
```    11 begin
```
```    12
```
```    13 definition  \<comment> \<open>internal sets\<close>
```
```    14   starset_n :: "(nat \<Rightarrow> 'a set) \<Rightarrow> 'a star set"  ("*sn* _" [80] 80)
```
```    15   where "*sn* As = Iset (star_n As)"
```
```    16
```
```    17 definition InternalSets :: "'a star set set"
```
```    18   where "InternalSets = {X. \<exists>As. X = *sn* As}"
```
```    19
```
```    20 definition  \<comment> \<open>nonstandard extension of function\<close>
```
```    21   is_starext :: "('a star \<Rightarrow> 'a star) \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> bool"
```
```    22   where "is_starext F f \<longleftrightarrow>
```
```    23     (\<forall>x y. \<exists>X \<in> Rep_star x. \<exists>Y \<in> Rep_star y. y = F x \<longleftrightarrow> eventually (\<lambda>n. Y n = f(X n)) \<U>)"
```
```    24
```
```    25 definition  \<comment> \<open>internal functions\<close>
```
```    26   starfun_n :: "(nat \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a star \<Rightarrow> 'b star"  ("*fn* _" [80] 80)
```
```    27   where "*fn* F = Ifun (star_n F)"
```
```    28
```
```    29 definition InternalFuns :: "('a star => 'b star) set"
```
```    30   where "InternalFuns = {X. \<exists>F. X = *fn* F}"
```
```    31
```
```    32
```
```    33 subsection \<open>Preamble - Pulling \<open>\<exists>\<close> over \<open>\<forall>\<close>\<close>
```
```    34
```
```    35 text \<open>This proof does not need AC and was suggested by the
```
```    36    referee for the JCM Paper: let \<open>f x\<close> be least \<open>y\<close> such
```
```    37    that \<open>Q x y\<close>.\<close>
```
```    38 lemma no_choice: "\<forall>x. \<exists>y. Q x y \<Longrightarrow> \<exists>f :: 'a \<Rightarrow> nat. \<forall>x. Q x (f x)"
```
```    39   by (rule exI [where x = "\<lambda>x. LEAST y. Q x y"]) (blast intro: LeastI)
```
```    40
```
```    41
```
```    42 subsection \<open>Properties of the Star-transform Applied to Sets of Reals\<close>
```
```    43
```
```    44 lemma STAR_star_of_image_subset: "star_of ` A \<subseteq> *s* A"
```
```    45   by auto
```
```    46
```
```    47 lemma STAR_hypreal_of_real_Int: "*s* X \<inter> \<real> = hypreal_of_real ` X"
```
```    48   by (auto simp add: SReal_def)
```
```    49
```
```    50 lemma STAR_star_of_Int: "*s* X \<inter> Standard = star_of ` X"
```
```    51   by (auto simp add: Standard_def)
```
```    52
```
```    53 lemma lemma_not_hyprealA: "x \<notin> hypreal_of_real ` A \<Longrightarrow> \<forall>y \<in> A. x \<noteq> hypreal_of_real y"
```
```    54   by auto
```
```    55
```
```    56 lemma lemma_not_starA: "x \<notin> star_of ` A \<Longrightarrow> \<forall>y \<in> A. x \<noteq> star_of y"
```
```    57   by auto
```
```    58
```
```    59 lemma lemma_Compl_eq: "- {n. X n = xa} = {n. X n \<noteq> xa}"
```
```    60   by auto
```
```    61
```
```    62 lemma STAR_real_seq_to_hypreal: "\<forall>n. (X n) \<notin> M \<Longrightarrow> star_n X \<notin> *s* M"
```
```    63   by (simp add: starset_def star_of_def Iset_star_n FreeUltrafilterNat.proper)
```
```    64
```
```    65 lemma STAR_singleton: "*s* {x} = {star_of x}"
```
```    66   by simp
```
```    67
```
```    68 lemma STAR_not_mem: "x \<notin> F \<Longrightarrow> star_of x \<notin> *s* F"
```
```    69   by transfer
```
```    70
```
```    71 lemma STAR_subset_closed: "x \<in> *s* A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> x \<in> *s* B"
```
```    72   by (erule rev_subsetD) simp
```
```    73
```
```    74 text \<open>Nonstandard extension of a set (defined using a constant
```
```    75    sequence) as a special case of an internal set.\<close>
```
```    76 lemma starset_n_starset: "\<forall>n. As n = A \<Longrightarrow> *sn* As = *s* A"
```
```    77   by (drule fun_eq_iff [THEN iffD2]) (simp add: starset_n_def starset_def star_of_def)
```
```    78
```
```    79
```
```    80 subsection \<open>Theorems about nonstandard extensions of functions\<close>
```
```    81
```
```    82 text \<open>Nonstandard extension of a function (defined using a
```
```    83   constant sequence) as a special case of an internal function.\<close>
```
```    84
```
```    85 lemma starfun_n_starfun: "\<forall>n. F n = f \<Longrightarrow> *fn* F = *f* f"
```
```    86   apply (drule fun_eq_iff [THEN iffD2])
```
```    87   apply (simp add: starfun_n_def starfun_def star_of_def)
```
```    88   done
```
```    89
```
```    90 text \<open>Prove that \<open>abs\<close> for hypreal is a nonstandard extension of abs for real w/o
```
```    91   use of congruence property (proved after this for general
```
```    92   nonstandard extensions of real valued functions).
```
```    93
```
```    94   Proof now Uses the ultrafilter tactic!\<close>
```
```    95
```
```    96 lemma hrabs_is_starext_rabs: "is_starext abs abs"
```
```    97   apply (simp add: is_starext_def, safe)
```
```    98   apply (rule_tac x=x in star_cases)
```
```    99   apply (rule_tac x=y in star_cases)
```
```   100   apply (unfold star_n_def, auto)
```
```   101   apply (rule bexI, rule_tac [2] lemma_starrel_refl)
```
```   102   apply (rule bexI, rule_tac [2] lemma_starrel_refl)
```
```   103   apply (fold star_n_def)
```
```   104   apply (unfold star_abs_def starfun_def star_of_def)
```
```   105   apply (simp add: Ifun_star_n star_n_eq_iff)
```
```   106   done
```
```   107
```
```   108
```
```   109 text \<open>Nonstandard extension of functions.\<close>
```
```   110
```
```   111 lemma starfun: "( *f* f) (star_n X) = star_n (\<lambda>n. f (X n))"
```
```   112   by (rule starfun_star_n)
```
```   113
```
```   114 lemma starfun_if_eq: "\<And>w. w \<noteq> star_of x \<Longrightarrow> ( *f* (\<lambda>z. if z = x then a else g z)) w = ( *f* g) w"
```
```   115   by transfer simp
```
```   116
```
```   117 text \<open>Multiplication: \<open>( *f) x ( *g) = *(f x g)\<close>\<close>
```
```   118 lemma starfun_mult: "\<And>x. ( *f* f) x * ( *f* g) x = ( *f* (\<lambda>x. f x * g x)) x"
```
```   119   by transfer (rule refl)
```
```   120 declare starfun_mult [symmetric, simp]
```
```   121
```
```   122 text \<open>Addition: \<open>( *f) + ( *g) = *(f + g)\<close>\<close>
```
```   123 lemma starfun_add: "\<And>x. ( *f* f) x + ( *f* g) x = ( *f* (\<lambda>x. f x + g x)) x"
```
```   124   by transfer (rule refl)
```
```   125 declare starfun_add [symmetric, simp]
```
```   126
```
```   127 text \<open>Subtraction: \<open>( *f) + -( *g) = *(f + -g)\<close>\<close>
```
```   128 lemma starfun_minus: "\<And>x. - ( *f* f) x = ( *f* (\<lambda>x. - f x)) x"
```
```   129   by transfer (rule refl)
```
```   130 declare starfun_minus [symmetric, simp]
```
```   131
```
```   132 (*FIXME: delete*)
```
```   133 lemma starfun_add_minus: "\<And>x. ( *f* f) x + -( *f* g) x = ( *f* (\<lambda>x. f x + -g x)) x"
```
```   134   by transfer (rule refl)
```
```   135 declare starfun_add_minus [symmetric, simp]
```
```   136
```
```   137 lemma starfun_diff: "\<And>x. ( *f* f) x  - ( *f* g) x = ( *f* (\<lambda>x. f x - g x)) x"
```
```   138   by transfer (rule refl)
```
```   139 declare starfun_diff [symmetric, simp]
```
```   140
```
```   141 text \<open>Composition: \<open>( *f) \<circ> ( *g) = *(f \<circ> g)\<close>\<close>
```
```   142 lemma starfun_o2: "(\<lambda>x. ( *f* f) (( *f* g) x)) = *f* (\<lambda>x. f (g x))"
```
```   143   by transfer (rule refl)
```
```   144
```
```   145 lemma starfun_o: "( *f* f) \<circ> ( *f* g) = ( *f* (f \<circ> g))"
```
```   146   by (transfer o_def) (rule refl)
```
```   147
```
```   148 text \<open>NS extension of constant function.\<close>
```
```   149 lemma starfun_const_fun [simp]: "\<And>x. ( *f* (\<lambda>x. k)) x = star_of k"
```
```   150   by transfer (rule refl)
```
```   151
```
```   152 text \<open>The NS extension of the identity function.\<close>
```
```   153 lemma starfun_Id [simp]: "\<And>x. ( *f* (\<lambda>x. x)) x = x"
```
```   154   by transfer (rule refl)
```
```   155
```
```   156 text \<open>This is trivial, given \<open>starfun_Id\<close>.\<close>
```
```   157 lemma starfun_Idfun_approx: "x \<approx> star_of a \<Longrightarrow> ( *f* (\<lambda>x. x)) x \<approx> star_of a"
```
```   158   by (simp only: starfun_Id)
```
```   159
```
```   160 text \<open>The Star-function is a (nonstandard) extension of the function.\<close>
```
```   161 lemma is_starext_starfun: "is_starext ( *f* f) f"
```
```   162   apply (auto simp: is_starext_def)
```
```   163   apply (rule_tac x = x in star_cases)
```
```   164   apply (rule_tac x = y in star_cases)
```
```   165   apply (auto intro!: bexI [OF _ Rep_star_star_n] simp: starfun star_n_eq_iff)
```
```   166   done
```
```   167
```
```   168 text \<open>Any nonstandard extension is in fact the Star-function.\<close>
```
```   169 lemma is_starfun_starext: "is_starext F f \<Longrightarrow> F = *f* f"
```
```   170   apply (simp add: is_starext_def)
```
```   171   apply (rule ext)
```
```   172   apply (rule_tac x = x in star_cases)
```
```   173   apply (drule_tac x = x in spec)
```
```   174   apply (drule_tac x = "( *f* f) x" in spec)
```
```   175   apply (auto simp add: starfun_star_n)
```
```   176   apply (simp add: star_n_eq_iff [symmetric])
```
```   177   apply (simp add: starfun_star_n [of f, symmetric])
```
```   178   done
```
```   179
```
```   180 lemma is_starext_starfun_iff: "is_starext F f \<longleftrightarrow> F = *f* f"
```
```   181   by (blast intro: is_starfun_starext is_starext_starfun)
```
```   182
```
```   183 text \<open>Extented function has same solution as its standard version
```
```   184   for real arguments. i.e they are the same for all real arguments.\<close>
```
```   185 lemma starfun_eq: "( *f* f) (star_of a) = star_of (f a)"
```
```   186   by (rule starfun_star_of)
```
```   187
```
```   188 lemma starfun_approx: "( *f* f) (star_of a) \<approx> star_of (f a)"
```
```   189   by simp
```
```   190
```
```   191 text \<open>Useful for NS definition of derivatives.\<close>
```
```   192 lemma starfun_lambda_cancel: "\<And>x'. ( *f* (\<lambda>h. f (x + h))) x'  = ( *f* f) (star_of x + x')"
```
```   193   by transfer (rule refl)
```
```   194
```
```   195 lemma starfun_lambda_cancel2: "( *f* (\<lambda>h. f (g (x + h)))) x' = ( *f* (f \<circ> g)) (star_of x + x')"
```
```   196   unfolding o_def by (rule starfun_lambda_cancel)
```
```   197
```
```   198 lemma starfun_mult_HFinite_approx:
```
```   199   "( *f* f) x \<approx> l \<Longrightarrow> ( *f* g) x \<approx> m \<Longrightarrow> l \<in> HFinite \<Longrightarrow> m \<in> HFinite \<Longrightarrow>
```
```   200     ( *f* (\<lambda>x. f x * g x)) x \<approx> l * m"
```
```   201   for l m :: "'a::real_normed_algebra star"
```
```   202   apply (drule (3) approx_mult_HFinite)
```
```   203   apply (auto intro: approx_HFinite [OF _ approx_sym])
```
```   204   done
```
```   205
```
```   206 lemma starfun_add_approx: "( *f* f) x \<approx> l \<Longrightarrow> ( *f* g) x \<approx> m \<Longrightarrow> ( *f* (%x. f x + g x)) x \<approx> l + m"
```
```   207   by (auto intro: approx_add)
```
```   208
```
```   209 text \<open>Examples: \<open>hrabs\<close> is nonstandard extension of \<open>rabs\<close>,
```
```   210   \<open>inverse\<close> is nonstandard extension of \<open>inverse\<close>.\<close>
```
```   211
```
```   212 text \<open>Can be proved easily using theorem \<open>starfun\<close> and
```
```   213   properties of ultrafilter as for inverse below we
```
```   214   use the theorem we proved above instead.\<close>
```
```   215
```
```   216 lemma starfun_rabs_hrabs: "*f* abs = abs"
```
```   217   by (simp only: star_abs_def)
```
```   218
```
```   219 lemma starfun_inverse_inverse [simp]: "( *f* inverse) x = inverse x"
```
```   220   by (simp only: star_inverse_def)
```
```   221
```
```   222 lemma starfun_inverse: "\<And>x. inverse (( *f* f) x) = ( *f* (\<lambda>x. inverse (f x))) x"
```
```   223   by transfer (rule refl)
```
```   224 declare starfun_inverse [symmetric, simp]
```
```   225
```
```   226 lemma starfun_divide: "\<And>x. ( *f* f) x / ( *f* g) x = ( *f* (\<lambda>x. f x / g x)) x"
```
```   227   by transfer (rule refl)
```
```   228 declare starfun_divide [symmetric, simp]
```
```   229
```
```   230 lemma starfun_inverse2: "\<And>x. inverse (( *f* f) x) = ( *f* (\<lambda>x. inverse (f x))) x"
```
```   231   by transfer (rule refl)
```
```   232
```
```   233 text \<open>General lemma/theorem needed for proofs in elementary topology of the reals.\<close>
```
```   234 lemma starfun_mem_starset: "\<And>x. ( *f* f) x : *s* A \<Longrightarrow> x \<in> *s* {x. f x \<in> A}"
```
```   235   by transfer simp
```
```   236
```
```   237 text \<open>Alternative definition for \<open>hrabs\<close> with \<open>rabs\<close> function applied
```
```   238   entrywise to equivalence class representative.
```
```   239   This is easily proved using @{thm [source] starfun} and ns extension thm.\<close>
```
```   240 lemma hypreal_hrabs: "\<bar>star_n X\<bar> = star_n (\<lambda>n. \<bar>X n\<bar>)"
```
```   241   by (simp only: starfun_rabs_hrabs [symmetric] starfun)
```
```   242
```
```   243 text \<open>Nonstandard extension of set through nonstandard extension
```
```   244    of \<open>rabs\<close> function i.e. \<open>hrabs\<close>. A more general result should be
```
```   245    where we replace \<open>rabs\<close> by some arbitrary function \<open>f\<close> and \<open>hrabs\<close>
```
```   246    by its NS extenson. See second NS set extension below.\<close>
```
```   247 lemma STAR_rabs_add_minus: "*s* {x. \<bar>x + - y\<bar> < r} = {x. \<bar>x + -star_of y\<bar> < star_of r}"
```
```   248   by transfer (rule refl)
```
```   249
```
```   250 lemma STAR_starfun_rabs_add_minus:
```
```   251   "*s* {x. \<bar>f x + - y\<bar> < r} = {x. \<bar>( *f* f) x + -star_of y\<bar> < star_of r}"
```
```   252   by transfer (rule refl)
```
```   253
```
```   254 text \<open>Another characterization of Infinitesimal and one of \<open>\<approx>\<close> relation.
```
```   255   In this theory since \<open>hypreal_hrabs\<close> proved here. Maybe move both theorems??\<close>
```
```   256 lemma Infinitesimal_FreeUltrafilterNat_iff2:
```
```   257   "star_n X \<in> Infinitesimal \<longleftrightarrow> (\<forall>m. eventually (\<lambda>n. norm (X n) < inverse (real (Suc m))) \<U>)"
```
```   258   by (simp add: Infinitesimal_hypreal_of_nat_iff star_of_def hnorm_def
```
```   259       star_of_nat_def starfun_star_n star_n_inverse star_n_less)
```
```   260
```
```   261 lemma HNatInfinite_inverse_Infinitesimal [simp]:
```
```   262   "n \<in> HNatInfinite \<Longrightarrow> inverse (hypreal_of_hypnat n) \<in> Infinitesimal"
```
```   263   apply (cases n)
```
```   264   apply (auto simp: of_hypnat_def starfun_star_n star_n_inverse
```
```   265     HNatInfinite_FreeUltrafilterNat_iff Infinitesimal_FreeUltrafilterNat_iff2)
```
```   266   apply (drule_tac x = "Suc m" in spec)
```
```   267   apply (auto elim!: eventually_mono)
```
```   268   done
```
```   269
```
```   270 lemma approx_FreeUltrafilterNat_iff:
```
```   271   "star_n X \<approx> star_n Y \<longleftrightarrow> (\<forall>r>0. eventually (\<lambda>n. norm (X n - Y n) < r) \<U>)"
```
```   272   apply (subst approx_minus_iff)
```
```   273   apply (rule mem_infmal_iff [THEN subst])
```
```   274   apply (simp add: star_n_diff)
```
```   275   apply (simp add: Infinitesimal_FreeUltrafilterNat_iff)
```
```   276   done
```
```   277
```
```   278 lemma approx_FreeUltrafilterNat_iff2:
```
```   279   "star_n X \<approx> star_n Y \<longleftrightarrow> (\<forall>m. eventually (\<lambda>n. norm (X n - Y n) < inverse (real (Suc m))) \<U>)"
```
```   280   apply (subst approx_minus_iff)
```
```   281   apply (rule mem_infmal_iff [THEN subst])
```
```   282   apply (simp add: star_n_diff)
```
```   283   apply (simp add: Infinitesimal_FreeUltrafilterNat_iff2)
```
```   284   done
```
```   285
```
```   286 lemma inj_starfun: "inj starfun"
```
```   287   apply (rule inj_onI)
```
```   288   apply (rule ext, rule ccontr)
```
```   289   apply (drule_tac x = "star_n (\<lambda>n. xa)" in fun_cong)
```
```   290   apply (auto simp add: starfun star_n_eq_iff FreeUltrafilterNat.proper)
```
```   291   done
```
```   292
```
```   293 end
```