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