src/HOL/NSA/StarDef.thy
author huffman
Thu Jul 03 17:47:22 2008 +0200 (2008-07-03)
changeset 27468 0783dd1dc13d
child 27651 16a26996c30e
permissions -rw-r--r--
move nonstandard analysis theories to NSA directory
huffman@27468
     1
(*  Title       : HOL/Hyperreal/StarDef.thy
huffman@27468
     2
    ID          : $Id$
huffman@27468
     3
    Author      : Jacques D. Fleuriot and Brian Huffman
huffman@27468
     4
*)
huffman@27468
     5
huffman@27468
     6
header {* Construction of Star Types Using Ultrafilters *}
huffman@27468
     7
huffman@27468
     8
theory StarDef
huffman@27468
     9
imports Filter
huffman@27468
    10
uses ("transfer.ML")
huffman@27468
    11
begin
huffman@27468
    12
huffman@27468
    13
subsection {* A Free Ultrafilter over the Naturals *}
huffman@27468
    14
huffman@27468
    15
definition
huffman@27468
    16
  FreeUltrafilterNat :: "nat set set"  ("\<U>") where
huffman@27468
    17
  "\<U> = (SOME U. freeultrafilter U)"
huffman@27468
    18
huffman@27468
    19
lemma freeultrafilter_FreeUltrafilterNat: "freeultrafilter \<U>"
huffman@27468
    20
apply (unfold FreeUltrafilterNat_def)
huffman@27468
    21
apply (rule someI_ex [where P=freeultrafilter])
huffman@27468
    22
apply (rule freeultrafilter_Ex)
huffman@27468
    23
apply (rule nat_infinite)
huffman@27468
    24
done
huffman@27468
    25
huffman@27468
    26
interpretation FreeUltrafilterNat: freeultrafilter [FreeUltrafilterNat]
huffman@27468
    27
by (rule freeultrafilter_FreeUltrafilterNat)
huffman@27468
    28
huffman@27468
    29
text {* This rule takes the place of the old ultra tactic *}
huffman@27468
    30
huffman@27468
    31
lemma ultra:
huffman@27468
    32
  "\<lbrakk>{n. P n} \<in> \<U>; {n. P n \<longrightarrow> Q n} \<in> \<U>\<rbrakk> \<Longrightarrow> {n. Q n} \<in> \<U>"
huffman@27468
    33
by (simp add: Collect_imp_eq
huffman@27468
    34
    FreeUltrafilterNat.Un_iff FreeUltrafilterNat.Compl_iff)
huffman@27468
    35
huffman@27468
    36
huffman@27468
    37
subsection {* Definition of @{text star} type constructor *}
huffman@27468
    38
huffman@27468
    39
definition
huffman@27468
    40
  starrel :: "((nat \<Rightarrow> 'a) \<times> (nat \<Rightarrow> 'a)) set" where
huffman@27468
    41
  "starrel = {(X,Y). {n. X n = Y n} \<in> \<U>}"
huffman@27468
    42
huffman@27468
    43
typedef 'a star = "(UNIV :: (nat \<Rightarrow> 'a) set) // starrel"
huffman@27468
    44
by (auto intro: quotientI)
huffman@27468
    45
huffman@27468
    46
definition
huffman@27468
    47
  star_n :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a star" where
huffman@27468
    48
  "star_n X = Abs_star (starrel `` {X})"
huffman@27468
    49
huffman@27468
    50
theorem star_cases [case_names star_n, cases type: star]:
huffman@27468
    51
  "(\<And>X. x = star_n X \<Longrightarrow> P) \<Longrightarrow> P"
huffman@27468
    52
by (cases x, unfold star_n_def star_def, erule quotientE, fast)
huffman@27468
    53
huffman@27468
    54
lemma all_star_eq: "(\<forall>x. P x) = (\<forall>X. P (star_n X))"
huffman@27468
    55
by (auto, rule_tac x=x in star_cases, simp)
huffman@27468
    56
huffman@27468
    57
lemma ex_star_eq: "(\<exists>x. P x) = (\<exists>X. P (star_n X))"
huffman@27468
    58
by (auto, rule_tac x=x in star_cases, auto)
huffman@27468
    59
huffman@27468
    60
text {* Proving that @{term starrel} is an equivalence relation *}
huffman@27468
    61
huffman@27468
    62
lemma starrel_iff [iff]: "((X,Y) \<in> starrel) = ({n. X n = Y n} \<in> \<U>)"
huffman@27468
    63
by (simp add: starrel_def)
huffman@27468
    64
huffman@27468
    65
lemma equiv_starrel: "equiv UNIV starrel"
huffman@27468
    66
proof (rule equiv.intro)
huffman@27468
    67
  show "reflexive starrel" by (simp add: refl_def)
huffman@27468
    68
  show "sym starrel" by (simp add: sym_def eq_commute)
huffman@27468
    69
  show "trans starrel" by (auto intro: transI elim!: ultra)
huffman@27468
    70
qed
huffman@27468
    71
huffman@27468
    72
lemmas equiv_starrel_iff =
huffman@27468
    73
  eq_equiv_class_iff [OF equiv_starrel UNIV_I UNIV_I]
huffman@27468
    74
huffman@27468
    75
lemma starrel_in_star: "starrel``{x} \<in> star"
huffman@27468
    76
by (simp add: star_def quotientI)
huffman@27468
    77
huffman@27468
    78
lemma star_n_eq_iff: "(star_n X = star_n Y) = ({n. X n = Y n} \<in> \<U>)"
huffman@27468
    79
by (simp add: star_n_def Abs_star_inject starrel_in_star equiv_starrel_iff)
huffman@27468
    80
huffman@27468
    81
huffman@27468
    82
subsection {* Transfer principle *}
huffman@27468
    83
huffman@27468
    84
text {* This introduction rule starts each transfer proof. *}
huffman@27468
    85
lemma transfer_start:
huffman@27468
    86
  "P \<equiv> {n. Q} \<in> \<U> \<Longrightarrow> Trueprop P \<equiv> Trueprop Q"
huffman@27468
    87
by (subgoal_tac "P \<equiv> Q", simp, simp add: atomize_eq)
huffman@27468
    88
huffman@27468
    89
text {*Initialize transfer tactic.*}
huffman@27468
    90
use "transfer.ML"
huffman@27468
    91
setup Transfer.setup
huffman@27468
    92
huffman@27468
    93
text {* Transfer introduction rules. *}
huffman@27468
    94
huffman@27468
    95
lemma transfer_ex [transfer_intro]:
huffman@27468
    96
  "\<lbrakk>\<And>X. p (star_n X) \<equiv> {n. P n (X n)} \<in> \<U>\<rbrakk>
huffman@27468
    97
    \<Longrightarrow> \<exists>x::'a star. p x \<equiv> {n. \<exists>x. P n x} \<in> \<U>"
huffman@27468
    98
by (simp only: ex_star_eq FreeUltrafilterNat.Collect_ex)
huffman@27468
    99
huffman@27468
   100
lemma transfer_all [transfer_intro]:
huffman@27468
   101
  "\<lbrakk>\<And>X. p (star_n X) \<equiv> {n. P n (X n)} \<in> \<U>\<rbrakk>
huffman@27468
   102
    \<Longrightarrow> \<forall>x::'a star. p x \<equiv> {n. \<forall>x. P n x} \<in> \<U>"
huffman@27468
   103
by (simp only: all_star_eq FreeUltrafilterNat.Collect_all)
huffman@27468
   104
huffman@27468
   105
lemma transfer_not [transfer_intro]:
huffman@27468
   106
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>\<rbrakk> \<Longrightarrow> \<not> p \<equiv> {n. \<not> P n} \<in> \<U>"
huffman@27468
   107
by (simp only: FreeUltrafilterNat.Collect_not)
huffman@27468
   108
huffman@27468
   109
lemma transfer_conj [transfer_intro]:
huffman@27468
   110
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>; q \<equiv> {n. Q n} \<in> \<U>\<rbrakk>
huffman@27468
   111
    \<Longrightarrow> p \<and> q \<equiv> {n. P n \<and> Q n} \<in> \<U>"
huffman@27468
   112
by (simp only: FreeUltrafilterNat.Collect_conj)
huffman@27468
   113
huffman@27468
   114
lemma transfer_disj [transfer_intro]:
huffman@27468
   115
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>; q \<equiv> {n. Q n} \<in> \<U>\<rbrakk>
huffman@27468
   116
    \<Longrightarrow> p \<or> q \<equiv> {n. P n \<or> Q n} \<in> \<U>"
huffman@27468
   117
by (simp only: FreeUltrafilterNat.Collect_disj)
huffman@27468
   118
huffman@27468
   119
lemma transfer_imp [transfer_intro]:
huffman@27468
   120
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>; q \<equiv> {n. Q n} \<in> \<U>\<rbrakk>
huffman@27468
   121
    \<Longrightarrow> p \<longrightarrow> q \<equiv> {n. P n \<longrightarrow> Q n} \<in> \<U>"
huffman@27468
   122
by (simp only: imp_conv_disj transfer_disj transfer_not)
huffman@27468
   123
huffman@27468
   124
lemma transfer_iff [transfer_intro]:
huffman@27468
   125
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>; q \<equiv> {n. Q n} \<in> \<U>\<rbrakk>
huffman@27468
   126
    \<Longrightarrow> p = q \<equiv> {n. P n = Q n} \<in> \<U>"
huffman@27468
   127
by (simp only: iff_conv_conj_imp transfer_conj transfer_imp)
huffman@27468
   128
huffman@27468
   129
lemma transfer_if_bool [transfer_intro]:
huffman@27468
   130
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>; x \<equiv> {n. X n} \<in> \<U>; y \<equiv> {n. Y n} \<in> \<U>\<rbrakk>
huffman@27468
   131
    \<Longrightarrow> (if p then x else y) \<equiv> {n. if P n then X n else Y n} \<in> \<U>"
huffman@27468
   132
by (simp only: if_bool_eq_conj transfer_conj transfer_imp transfer_not)
huffman@27468
   133
huffman@27468
   134
lemma transfer_eq [transfer_intro]:
huffman@27468
   135
  "\<lbrakk>x \<equiv> star_n X; y \<equiv> star_n Y\<rbrakk> \<Longrightarrow> x = y \<equiv> {n. X n = Y n} \<in> \<U>"
huffman@27468
   136
by (simp only: star_n_eq_iff)
huffman@27468
   137
huffman@27468
   138
lemma transfer_if [transfer_intro]:
huffman@27468
   139
  "\<lbrakk>p \<equiv> {n. P n} \<in> \<U>; x \<equiv> star_n X; y \<equiv> star_n Y\<rbrakk>
huffman@27468
   140
    \<Longrightarrow> (if p then x else y) \<equiv> star_n (\<lambda>n. if P n then X n else Y n)"
huffman@27468
   141
apply (rule eq_reflection)
huffman@27468
   142
apply (auto simp add: star_n_eq_iff transfer_not elim!: ultra)
huffman@27468
   143
done
huffman@27468
   144
huffman@27468
   145
lemma transfer_fun_eq [transfer_intro]:
huffman@27468
   146
  "\<lbrakk>\<And>X. f (star_n X) = g (star_n X) 
huffman@27468
   147
    \<equiv> {n. F n (X n) = G n (X n)} \<in> \<U>\<rbrakk>
huffman@27468
   148
      \<Longrightarrow> f = g \<equiv> {n. F n = G n} \<in> \<U>"
huffman@27468
   149
by (simp only: expand_fun_eq transfer_all)
huffman@27468
   150
huffman@27468
   151
lemma transfer_star_n [transfer_intro]: "star_n X \<equiv> star_n (\<lambda>n. X n)"
huffman@27468
   152
by (rule reflexive)
huffman@27468
   153
huffman@27468
   154
lemma transfer_bool [transfer_intro]: "p \<equiv> {n. p} \<in> \<U>"
huffman@27468
   155
by (simp add: atomize_eq)
huffman@27468
   156
huffman@27468
   157
huffman@27468
   158
subsection {* Standard elements *}
huffman@27468
   159
huffman@27468
   160
definition
huffman@27468
   161
  star_of :: "'a \<Rightarrow> 'a star" where
huffman@27468
   162
  "star_of x == star_n (\<lambda>n. x)"
huffman@27468
   163
huffman@27468
   164
definition
huffman@27468
   165
  Standard :: "'a star set" where
huffman@27468
   166
  "Standard = range star_of"
huffman@27468
   167
huffman@27468
   168
text {* Transfer tactic should remove occurrences of @{term star_of} *}
huffman@27468
   169
setup {* Transfer.add_const "StarDef.star_of" *}
huffman@27468
   170
huffman@27468
   171
declare star_of_def [transfer_intro]
huffman@27468
   172
huffman@27468
   173
lemma star_of_inject: "(star_of x = star_of y) = (x = y)"
huffman@27468
   174
by (transfer, rule refl)
huffman@27468
   175
huffman@27468
   176
lemma Standard_star_of [simp]: "star_of x \<in> Standard"
huffman@27468
   177
by (simp add: Standard_def)
huffman@27468
   178
huffman@27468
   179
huffman@27468
   180
subsection {* Internal functions *}
huffman@27468
   181
huffman@27468
   182
definition
huffman@27468
   183
  Ifun :: "('a \<Rightarrow> 'b) star \<Rightarrow> 'a star \<Rightarrow> 'b star" ("_ \<star> _" [300,301] 300) where
huffman@27468
   184
  "Ifun f \<equiv> \<lambda>x. Abs_star
huffman@27468
   185
       (\<Union>F\<in>Rep_star f. \<Union>X\<in>Rep_star x. starrel``{\<lambda>n. F n (X n)})"
huffman@27468
   186
huffman@27468
   187
lemma Ifun_congruent2:
huffman@27468
   188
  "congruent2 starrel starrel (\<lambda>F X. starrel``{\<lambda>n. F n (X n)})"
huffman@27468
   189
by (auto simp add: congruent2_def equiv_starrel_iff elim!: ultra)
huffman@27468
   190
huffman@27468
   191
lemma Ifun_star_n: "star_n F \<star> star_n X = star_n (\<lambda>n. F n (X n))"
huffman@27468
   192
by (simp add: Ifun_def star_n_def Abs_star_inverse starrel_in_star
huffman@27468
   193
    UN_equiv_class2 [OF equiv_starrel equiv_starrel Ifun_congruent2])
huffman@27468
   194
huffman@27468
   195
text {* Transfer tactic should remove occurrences of @{term Ifun} *}
huffman@27468
   196
setup {* Transfer.add_const "StarDef.Ifun" *}
huffman@27468
   197
huffman@27468
   198
lemma transfer_Ifun [transfer_intro]:
huffman@27468
   199
  "\<lbrakk>f \<equiv> star_n F; x \<equiv> star_n X\<rbrakk> \<Longrightarrow> f \<star> x \<equiv> star_n (\<lambda>n. F n (X n))"
huffman@27468
   200
by (simp only: Ifun_star_n)
huffman@27468
   201
huffman@27468
   202
lemma Ifun_star_of [simp]: "star_of f \<star> star_of x = star_of (f x)"
huffman@27468
   203
by (transfer, rule refl)
huffman@27468
   204
huffman@27468
   205
lemma Standard_Ifun [simp]:
huffman@27468
   206
  "\<lbrakk>f \<in> Standard; x \<in> Standard\<rbrakk> \<Longrightarrow> f \<star> x \<in> Standard"
huffman@27468
   207
by (auto simp add: Standard_def)
huffman@27468
   208
huffman@27468
   209
text {* Nonstandard extensions of functions *}
huffman@27468
   210
huffman@27468
   211
definition
huffman@27468
   212
  starfun :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a star \<Rightarrow> 'b star)"  ("*f* _" [80] 80) where
huffman@27468
   213
  "starfun f == \<lambda>x. star_of f \<star> x"
huffman@27468
   214
huffman@27468
   215
definition
huffman@27468
   216
  starfun2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a star \<Rightarrow> 'b star \<Rightarrow> 'c star)"
huffman@27468
   217
    ("*f2* _" [80] 80) where
huffman@27468
   218
  "starfun2 f == \<lambda>x y. star_of f \<star> x \<star> y"
huffman@27468
   219
huffman@27468
   220
declare starfun_def [transfer_unfold]
huffman@27468
   221
declare starfun2_def [transfer_unfold]
huffman@27468
   222
huffman@27468
   223
lemma starfun_star_n: "( *f* f) (star_n X) = star_n (\<lambda>n. f (X n))"
huffman@27468
   224
by (simp only: starfun_def star_of_def Ifun_star_n)
huffman@27468
   225
huffman@27468
   226
lemma starfun2_star_n:
huffman@27468
   227
  "( *f2* f) (star_n X) (star_n Y) = star_n (\<lambda>n. f (X n) (Y n))"
huffman@27468
   228
by (simp only: starfun2_def star_of_def Ifun_star_n)
huffman@27468
   229
huffman@27468
   230
lemma starfun_star_of [simp]: "( *f* f) (star_of x) = star_of (f x)"
huffman@27468
   231
by (transfer, rule refl)
huffman@27468
   232
huffman@27468
   233
lemma starfun2_star_of [simp]: "( *f2* f) (star_of x) = *f* f x"
huffman@27468
   234
by (transfer, rule refl)
huffman@27468
   235
huffman@27468
   236
lemma Standard_starfun [simp]: "x \<in> Standard \<Longrightarrow> starfun f x \<in> Standard"
huffman@27468
   237
by (simp add: starfun_def)
huffman@27468
   238
huffman@27468
   239
lemma Standard_starfun2 [simp]:
huffman@27468
   240
  "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> starfun2 f x y \<in> Standard"
huffman@27468
   241
by (simp add: starfun2_def)
huffman@27468
   242
huffman@27468
   243
lemma Standard_starfun_iff:
huffman@27468
   244
  assumes inj: "\<And>x y. f x = f y \<Longrightarrow> x = y"
huffman@27468
   245
  shows "(starfun f x \<in> Standard) = (x \<in> Standard)"
huffman@27468
   246
proof
huffman@27468
   247
  assume "x \<in> Standard"
huffman@27468
   248
  thus "starfun f x \<in> Standard" by simp
huffman@27468
   249
next
huffman@27468
   250
  have inj': "\<And>x y. starfun f x = starfun f y \<Longrightarrow> x = y"
huffman@27468
   251
    using inj by transfer
huffman@27468
   252
  assume "starfun f x \<in> Standard"
huffman@27468
   253
  then obtain b where b: "starfun f x = star_of b"
huffman@27468
   254
    unfolding Standard_def ..
huffman@27468
   255
  hence "\<exists>x. starfun f x = star_of b" ..
huffman@27468
   256
  hence "\<exists>a. f a = b" by transfer
huffman@27468
   257
  then obtain a where "f a = b" ..
huffman@27468
   258
  hence "starfun f (star_of a) = star_of b" by transfer
huffman@27468
   259
  with b have "starfun f x = starfun f (star_of a)" by simp
huffman@27468
   260
  hence "x = star_of a" by (rule inj')
huffman@27468
   261
  thus "x \<in> Standard"
huffman@27468
   262
    unfolding Standard_def by auto
huffman@27468
   263
qed
huffman@27468
   264
huffman@27468
   265
lemma Standard_starfun2_iff:
huffman@27468
   266
  assumes inj: "\<And>a b a' b'. f a b = f a' b' \<Longrightarrow> a = a' \<and> b = b'"
huffman@27468
   267
  shows "(starfun2 f x y \<in> Standard) = (x \<in> Standard \<and> y \<in> Standard)"
huffman@27468
   268
proof
huffman@27468
   269
  assume "x \<in> Standard \<and> y \<in> Standard"
huffman@27468
   270
  thus "starfun2 f x y \<in> Standard" by simp
huffman@27468
   271
next
huffman@27468
   272
  have inj': "\<And>x y z w. starfun2 f x y = starfun2 f z w \<Longrightarrow> x = z \<and> y = w"
huffman@27468
   273
    using inj by transfer
huffman@27468
   274
  assume "starfun2 f x y \<in> Standard"
huffman@27468
   275
  then obtain c where c: "starfun2 f x y = star_of c"
huffman@27468
   276
    unfolding Standard_def ..
huffman@27468
   277
  hence "\<exists>x y. starfun2 f x y = star_of c" by auto
huffman@27468
   278
  hence "\<exists>a b. f a b = c" by transfer
huffman@27468
   279
  then obtain a b where "f a b = c" by auto
huffman@27468
   280
  hence "starfun2 f (star_of a) (star_of b) = star_of c"
huffman@27468
   281
    by transfer
huffman@27468
   282
  with c have "starfun2 f x y = starfun2 f (star_of a) (star_of b)"
huffman@27468
   283
    by simp
huffman@27468
   284
  hence "x = star_of a \<and> y = star_of b"
huffman@27468
   285
    by (rule inj')
huffman@27468
   286
  thus "x \<in> Standard \<and> y \<in> Standard"
huffman@27468
   287
    unfolding Standard_def by auto
huffman@27468
   288
qed
huffman@27468
   289
huffman@27468
   290
huffman@27468
   291
subsection {* Internal predicates *}
huffman@27468
   292
huffman@27468
   293
definition unstar :: "bool star \<Rightarrow> bool" where
huffman@27468
   294
  [code func del]: "unstar b \<longleftrightarrow> b = star_of True"
huffman@27468
   295
huffman@27468
   296
lemma unstar_star_n: "unstar (star_n P) = ({n. P n} \<in> \<U>)"
huffman@27468
   297
by (simp add: unstar_def star_of_def star_n_eq_iff)
huffman@27468
   298
huffman@27468
   299
lemma unstar_star_of [simp]: "unstar (star_of p) = p"
huffman@27468
   300
by (simp add: unstar_def star_of_inject)
huffman@27468
   301
huffman@27468
   302
text {* Transfer tactic should remove occurrences of @{term unstar} *}
huffman@27468
   303
setup {* Transfer.add_const "StarDef.unstar" *}
huffman@27468
   304
huffman@27468
   305
lemma transfer_unstar [transfer_intro]:
huffman@27468
   306
  "p \<equiv> star_n P \<Longrightarrow> unstar p \<equiv> {n. P n} \<in> \<U>"
huffman@27468
   307
by (simp only: unstar_star_n)
huffman@27468
   308
huffman@27468
   309
definition
huffman@27468
   310
  starP :: "('a \<Rightarrow> bool) \<Rightarrow> 'a star \<Rightarrow> bool"  ("*p* _" [80] 80) where
huffman@27468
   311
  "*p* P = (\<lambda>x. unstar (star_of P \<star> x))"
huffman@27468
   312
huffman@27468
   313
definition
huffman@27468
   314
  starP2 :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a star \<Rightarrow> 'b star \<Rightarrow> bool"  ("*p2* _" [80] 80) where
huffman@27468
   315
  "*p2* P = (\<lambda>x y. unstar (star_of P \<star> x \<star> y))"
huffman@27468
   316
huffman@27468
   317
declare starP_def [transfer_unfold]
huffman@27468
   318
declare starP2_def [transfer_unfold]
huffman@27468
   319
huffman@27468
   320
lemma starP_star_n: "( *p* P) (star_n X) = ({n. P (X n)} \<in> \<U>)"
huffman@27468
   321
by (simp only: starP_def star_of_def Ifun_star_n unstar_star_n)
huffman@27468
   322
huffman@27468
   323
lemma starP2_star_n:
huffman@27468
   324
  "( *p2* P) (star_n X) (star_n Y) = ({n. P (X n) (Y n)} \<in> \<U>)"
huffman@27468
   325
by (simp only: starP2_def star_of_def Ifun_star_n unstar_star_n)
huffman@27468
   326
huffman@27468
   327
lemma starP_star_of [simp]: "( *p* P) (star_of x) = P x"
huffman@27468
   328
by (transfer, rule refl)
huffman@27468
   329
huffman@27468
   330
lemma starP2_star_of [simp]: "( *p2* P) (star_of x) = *p* P x"
huffman@27468
   331
by (transfer, rule refl)
huffman@27468
   332
huffman@27468
   333
huffman@27468
   334
subsection {* Internal sets *}
huffman@27468
   335
huffman@27468
   336
definition
huffman@27468
   337
  Iset :: "'a set star \<Rightarrow> 'a star set" where
huffman@27468
   338
  "Iset A = {x. ( *p2* op \<in>) x A}"
huffman@27468
   339
huffman@27468
   340
lemma Iset_star_n:
huffman@27468
   341
  "(star_n X \<in> Iset (star_n A)) = ({n. X n \<in> A n} \<in> \<U>)"
huffman@27468
   342
by (simp add: Iset_def starP2_star_n)
huffman@27468
   343
huffman@27468
   344
text {* Transfer tactic should remove occurrences of @{term Iset} *}
huffman@27468
   345
setup {* Transfer.add_const "StarDef.Iset" *}
huffman@27468
   346
huffman@27468
   347
lemma transfer_mem [transfer_intro]:
huffman@27468
   348
  "\<lbrakk>x \<equiv> star_n X; a \<equiv> Iset (star_n A)\<rbrakk>
huffman@27468
   349
    \<Longrightarrow> x \<in> a \<equiv> {n. X n \<in> A n} \<in> \<U>"
huffman@27468
   350
by (simp only: Iset_star_n)
huffman@27468
   351
huffman@27468
   352
lemma transfer_Collect [transfer_intro]:
huffman@27468
   353
  "\<lbrakk>\<And>X. p (star_n X) \<equiv> {n. P n (X n)} \<in> \<U>\<rbrakk>
huffman@27468
   354
    \<Longrightarrow> Collect p \<equiv> Iset (star_n (\<lambda>n. Collect (P n)))"
huffman@27468
   355
by (simp add: atomize_eq expand_set_eq all_star_eq Iset_star_n)
huffman@27468
   356
huffman@27468
   357
lemma transfer_set_eq [transfer_intro]:
huffman@27468
   358
  "\<lbrakk>a \<equiv> Iset (star_n A); b \<equiv> Iset (star_n B)\<rbrakk>
huffman@27468
   359
    \<Longrightarrow> a = b \<equiv> {n. A n = B n} \<in> \<U>"
huffman@27468
   360
by (simp only: expand_set_eq transfer_all transfer_iff transfer_mem)
huffman@27468
   361
huffman@27468
   362
lemma transfer_ball [transfer_intro]:
huffman@27468
   363
  "\<lbrakk>a \<equiv> Iset (star_n A); \<And>X. p (star_n X) \<equiv> {n. P n (X n)} \<in> \<U>\<rbrakk>
huffman@27468
   364
    \<Longrightarrow> \<forall>x\<in>a. p x \<equiv> {n. \<forall>x\<in>A n. P n x} \<in> \<U>"
huffman@27468
   365
by (simp only: Ball_def transfer_all transfer_imp transfer_mem)
huffman@27468
   366
huffman@27468
   367
lemma transfer_bex [transfer_intro]:
huffman@27468
   368
  "\<lbrakk>a \<equiv> Iset (star_n A); \<And>X. p (star_n X) \<equiv> {n. P n (X n)} \<in> \<U>\<rbrakk>
huffman@27468
   369
    \<Longrightarrow> \<exists>x\<in>a. p x \<equiv> {n. \<exists>x\<in>A n. P n x} \<in> \<U>"
huffman@27468
   370
by (simp only: Bex_def transfer_ex transfer_conj transfer_mem)
huffman@27468
   371
huffman@27468
   372
lemma transfer_Iset [transfer_intro]:
huffman@27468
   373
  "\<lbrakk>a \<equiv> star_n A\<rbrakk> \<Longrightarrow> Iset a \<equiv> Iset (star_n (\<lambda>n. A n))"
huffman@27468
   374
by simp
huffman@27468
   375
huffman@27468
   376
text {* Nonstandard extensions of sets. *}
huffman@27468
   377
huffman@27468
   378
definition
huffman@27468
   379
  starset :: "'a set \<Rightarrow> 'a star set" ("*s* _" [80] 80) where
huffman@27468
   380
  "starset A = Iset (star_of A)"
huffman@27468
   381
huffman@27468
   382
declare starset_def [transfer_unfold]
huffman@27468
   383
huffman@27468
   384
lemma starset_mem: "(star_of x \<in> *s* A) = (x \<in> A)"
huffman@27468
   385
by (transfer, rule refl)
huffman@27468
   386
huffman@27468
   387
lemma starset_UNIV: "*s* (UNIV::'a set) = (UNIV::'a star set)"
huffman@27468
   388
by (transfer UNIV_def, rule refl)
huffman@27468
   389
huffman@27468
   390
lemma starset_empty: "*s* {} = {}"
huffman@27468
   391
by (transfer empty_def, rule refl)
huffman@27468
   392
huffman@27468
   393
lemma starset_insert: "*s* (insert x A) = insert (star_of x) ( *s* A)"
huffman@27468
   394
by (transfer insert_def Un_def, rule refl)
huffman@27468
   395
huffman@27468
   396
lemma starset_Un: "*s* (A \<union> B) = *s* A \<union> *s* B"
huffman@27468
   397
by (transfer Un_def, rule refl)
huffman@27468
   398
huffman@27468
   399
lemma starset_Int: "*s* (A \<inter> B) = *s* A \<inter> *s* B"
huffman@27468
   400
by (transfer Int_def, rule refl)
huffman@27468
   401
huffman@27468
   402
lemma starset_Compl: "*s* -A = -( *s* A)"
huffman@27468
   403
by (transfer Compl_eq, rule refl)
huffman@27468
   404
huffman@27468
   405
lemma starset_diff: "*s* (A - B) = *s* A - *s* B"
huffman@27468
   406
by (transfer set_diff_eq, rule refl)
huffman@27468
   407
huffman@27468
   408
lemma starset_image: "*s* (f ` A) = ( *f* f) ` ( *s* A)"
huffman@27468
   409
by (transfer image_def, rule refl)
huffman@27468
   410
huffman@27468
   411
lemma starset_vimage: "*s* (f -` A) = ( *f* f) -` ( *s* A)"
huffman@27468
   412
by (transfer vimage_def, rule refl)
huffman@27468
   413
huffman@27468
   414
lemma starset_subset: "( *s* A \<subseteq> *s* B) = (A \<subseteq> B)"
huffman@27468
   415
by (transfer subset_eq, rule refl)
huffman@27468
   416
huffman@27468
   417
lemma starset_eq: "( *s* A = *s* B) = (A = B)"
huffman@27468
   418
by (transfer, rule refl)
huffman@27468
   419
huffman@27468
   420
lemmas starset_simps [simp] =
huffman@27468
   421
  starset_mem     starset_UNIV
huffman@27468
   422
  starset_empty   starset_insert
huffman@27468
   423
  starset_Un      starset_Int
huffman@27468
   424
  starset_Compl   starset_diff
huffman@27468
   425
  starset_image   starset_vimage
huffman@27468
   426
  starset_subset  starset_eq
huffman@27468
   427
huffman@27468
   428
huffman@27468
   429
subsection {* Syntactic classes *}
huffman@27468
   430
huffman@27468
   431
instantiation star :: (zero) zero
huffman@27468
   432
begin
huffman@27468
   433
huffman@27468
   434
definition
huffman@27468
   435
  star_zero_def [code func del]:    "0 \<equiv> star_of 0"
huffman@27468
   436
huffman@27468
   437
instance ..
huffman@27468
   438
huffman@27468
   439
end
huffman@27468
   440
huffman@27468
   441
instantiation star :: (one) one
huffman@27468
   442
begin
huffman@27468
   443
huffman@27468
   444
definition
huffman@27468
   445
  star_one_def [code func del]:     "1 \<equiv> star_of 1"
huffman@27468
   446
huffman@27468
   447
instance ..
huffman@27468
   448
huffman@27468
   449
end
huffman@27468
   450
huffman@27468
   451
instantiation star :: (plus) plus
huffman@27468
   452
begin
huffman@27468
   453
huffman@27468
   454
definition
huffman@27468
   455
  star_add_def [code func del]:     "(op +) \<equiv> *f2* (op +)"
huffman@27468
   456
huffman@27468
   457
instance ..
huffman@27468
   458
huffman@27468
   459
end
huffman@27468
   460
huffman@27468
   461
instantiation star :: (times) times
huffman@27468
   462
begin
huffman@27468
   463
huffman@27468
   464
definition
huffman@27468
   465
  star_mult_def [code func del]:    "(op *) \<equiv> *f2* (op *)"
huffman@27468
   466
huffman@27468
   467
instance ..
huffman@27468
   468
huffman@27468
   469
end
huffman@27468
   470
huffman@27468
   471
instantiation star :: (uminus) uminus
huffman@27468
   472
begin
huffman@27468
   473
huffman@27468
   474
definition
huffman@27468
   475
  star_minus_def [code func del]:   "uminus \<equiv> *f* uminus"
huffman@27468
   476
huffman@27468
   477
instance ..
huffman@27468
   478
huffman@27468
   479
end
huffman@27468
   480
huffman@27468
   481
instantiation star :: (minus) minus
huffman@27468
   482
begin
huffman@27468
   483
huffman@27468
   484
definition
huffman@27468
   485
  star_diff_def [code func del]:    "(op -) \<equiv> *f2* (op -)"
huffman@27468
   486
huffman@27468
   487
instance ..
huffman@27468
   488
huffman@27468
   489
end
huffman@27468
   490
huffman@27468
   491
instantiation star :: (abs) abs
huffman@27468
   492
begin
huffman@27468
   493
huffman@27468
   494
definition
huffman@27468
   495
  star_abs_def:     "abs \<equiv> *f* abs"
huffman@27468
   496
huffman@27468
   497
instance ..
huffman@27468
   498
huffman@27468
   499
end
huffman@27468
   500
huffman@27468
   501
instantiation star :: (sgn) sgn
huffman@27468
   502
begin
huffman@27468
   503
huffman@27468
   504
definition
huffman@27468
   505
  star_sgn_def:     "sgn \<equiv> *f* sgn"
huffman@27468
   506
huffman@27468
   507
instance ..
huffman@27468
   508
huffman@27468
   509
end
huffman@27468
   510
huffman@27468
   511
instantiation star :: (inverse) inverse
huffman@27468
   512
begin
huffman@27468
   513
huffman@27468
   514
definition
huffman@27468
   515
  star_divide_def:  "(op /) \<equiv> *f2* (op /)"
huffman@27468
   516
huffman@27468
   517
definition
huffman@27468
   518
  star_inverse_def: "inverse \<equiv> *f* inverse"
huffman@27468
   519
huffman@27468
   520
instance ..
huffman@27468
   521
huffman@27468
   522
end
huffman@27468
   523
huffman@27468
   524
instantiation star :: (number) number
huffman@27468
   525
begin
huffman@27468
   526
huffman@27468
   527
definition
huffman@27468
   528
  star_number_def:  "number_of b \<equiv> star_of (number_of b)"
huffman@27468
   529
huffman@27468
   530
instance ..
huffman@27468
   531
huffman@27468
   532
end
huffman@27468
   533
huffman@27468
   534
instantiation star :: (Divides.div) Divides.div
huffman@27468
   535
begin
huffman@27468
   536
huffman@27468
   537
definition
huffman@27468
   538
  star_div_def:     "(op div) \<equiv> *f2* (op div)"
huffman@27468
   539
huffman@27468
   540
definition
huffman@27468
   541
  star_mod_def:     "(op mod) \<equiv> *f2* (op mod)"
huffman@27468
   542
huffman@27468
   543
instance ..
huffman@27468
   544
huffman@27468
   545
end
huffman@27468
   546
huffman@27468
   547
instantiation star :: (power) power
huffman@27468
   548
begin
huffman@27468
   549
huffman@27468
   550
definition
huffman@27468
   551
  star_power_def:   "(op ^) \<equiv> \<lambda>x n. ( *f* (\<lambda>x. x ^ n)) x"
huffman@27468
   552
huffman@27468
   553
instance ..
huffman@27468
   554
huffman@27468
   555
end
huffman@27468
   556
huffman@27468
   557
instantiation star :: (ord) ord
huffman@27468
   558
begin
huffman@27468
   559
huffman@27468
   560
definition
huffman@27468
   561
  star_le_def:      "(op \<le>) \<equiv> *p2* (op \<le>)"
huffman@27468
   562
huffman@27468
   563
definition
huffman@27468
   564
  star_less_def:    "(op <) \<equiv> *p2* (op <)"
huffman@27468
   565
huffman@27468
   566
instance ..
huffman@27468
   567
huffman@27468
   568
end
huffman@27468
   569
huffman@27468
   570
lemmas star_class_defs [transfer_unfold] =
huffman@27468
   571
  star_zero_def     star_one_def      star_number_def
huffman@27468
   572
  star_add_def      star_diff_def     star_minus_def
huffman@27468
   573
  star_mult_def     star_divide_def   star_inverse_def
huffman@27468
   574
  star_le_def       star_less_def     star_abs_def       star_sgn_def
huffman@27468
   575
  star_div_def      star_mod_def      star_power_def
huffman@27468
   576
huffman@27468
   577
text {* Class operations preserve standard elements *}
huffman@27468
   578
huffman@27468
   579
lemma Standard_zero: "0 \<in> Standard"
huffman@27468
   580
by (simp add: star_zero_def)
huffman@27468
   581
huffman@27468
   582
lemma Standard_one: "1 \<in> Standard"
huffman@27468
   583
by (simp add: star_one_def)
huffman@27468
   584
huffman@27468
   585
lemma Standard_number_of: "number_of b \<in> Standard"
huffman@27468
   586
by (simp add: star_number_def)
huffman@27468
   587
huffman@27468
   588
lemma Standard_add: "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> x + y \<in> Standard"
huffman@27468
   589
by (simp add: star_add_def)
huffman@27468
   590
huffman@27468
   591
lemma Standard_diff: "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> x - y \<in> Standard"
huffman@27468
   592
by (simp add: star_diff_def)
huffman@27468
   593
huffman@27468
   594
lemma Standard_minus: "x \<in> Standard \<Longrightarrow> - x \<in> Standard"
huffman@27468
   595
by (simp add: star_minus_def)
huffman@27468
   596
huffman@27468
   597
lemma Standard_mult: "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> x * y \<in> Standard"
huffman@27468
   598
by (simp add: star_mult_def)
huffman@27468
   599
huffman@27468
   600
lemma Standard_divide: "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> x / y \<in> Standard"
huffman@27468
   601
by (simp add: star_divide_def)
huffman@27468
   602
huffman@27468
   603
lemma Standard_inverse: "x \<in> Standard \<Longrightarrow> inverse x \<in> Standard"
huffman@27468
   604
by (simp add: star_inverse_def)
huffman@27468
   605
huffman@27468
   606
lemma Standard_abs: "x \<in> Standard \<Longrightarrow> abs x \<in> Standard"
huffman@27468
   607
by (simp add: star_abs_def)
huffman@27468
   608
huffman@27468
   609
lemma Standard_div: "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> x div y \<in> Standard"
huffman@27468
   610
by (simp add: star_div_def)
huffman@27468
   611
huffman@27468
   612
lemma Standard_mod: "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> x mod y \<in> Standard"
huffman@27468
   613
by (simp add: star_mod_def)
huffman@27468
   614
huffman@27468
   615
lemma Standard_power: "x \<in> Standard \<Longrightarrow> x ^ n \<in> Standard"
huffman@27468
   616
by (simp add: star_power_def)
huffman@27468
   617
huffman@27468
   618
lemmas Standard_simps [simp] =
huffman@27468
   619
  Standard_zero  Standard_one  Standard_number_of
huffman@27468
   620
  Standard_add  Standard_diff  Standard_minus
huffman@27468
   621
  Standard_mult  Standard_divide  Standard_inverse
huffman@27468
   622
  Standard_abs  Standard_div  Standard_mod
huffman@27468
   623
  Standard_power
huffman@27468
   624
huffman@27468
   625
text {* @{term star_of} preserves class operations *}
huffman@27468
   626
huffman@27468
   627
lemma star_of_add: "star_of (x + y) = star_of x + star_of y"
huffman@27468
   628
by transfer (rule refl)
huffman@27468
   629
huffman@27468
   630
lemma star_of_diff: "star_of (x - y) = star_of x - star_of y"
huffman@27468
   631
by transfer (rule refl)
huffman@27468
   632
huffman@27468
   633
lemma star_of_minus: "star_of (-x) = - star_of x"
huffman@27468
   634
by transfer (rule refl)
huffman@27468
   635
huffman@27468
   636
lemma star_of_mult: "star_of (x * y) = star_of x * star_of y"
huffman@27468
   637
by transfer (rule refl)
huffman@27468
   638
huffman@27468
   639
lemma star_of_divide: "star_of (x / y) = star_of x / star_of y"
huffman@27468
   640
by transfer (rule refl)
huffman@27468
   641
huffman@27468
   642
lemma star_of_inverse: "star_of (inverse x) = inverse (star_of x)"
huffman@27468
   643
by transfer (rule refl)
huffman@27468
   644
huffman@27468
   645
lemma star_of_div: "star_of (x div y) = star_of x div star_of y"
huffman@27468
   646
by transfer (rule refl)
huffman@27468
   647
huffman@27468
   648
lemma star_of_mod: "star_of (x mod y) = star_of x mod star_of y"
huffman@27468
   649
by transfer (rule refl)
huffman@27468
   650
huffman@27468
   651
lemma star_of_power: "star_of (x ^ n) = star_of x ^ n"
huffman@27468
   652
by transfer (rule refl)
huffman@27468
   653
huffman@27468
   654
lemma star_of_abs: "star_of (abs x) = abs (star_of x)"
huffman@27468
   655
by transfer (rule refl)
huffman@27468
   656
huffman@27468
   657
text {* @{term star_of} preserves numerals *}
huffman@27468
   658
huffman@27468
   659
lemma star_of_zero: "star_of 0 = 0"
huffman@27468
   660
by transfer (rule refl)
huffman@27468
   661
huffman@27468
   662
lemma star_of_one: "star_of 1 = 1"
huffman@27468
   663
by transfer (rule refl)
huffman@27468
   664
huffman@27468
   665
lemma star_of_number_of: "star_of (number_of x) = number_of x"
huffman@27468
   666
by transfer (rule refl)
huffman@27468
   667
huffman@27468
   668
text {* @{term star_of} preserves orderings *}
huffman@27468
   669
huffman@27468
   670
lemma star_of_less: "(star_of x < star_of y) = (x < y)"
huffman@27468
   671
by transfer (rule refl)
huffman@27468
   672
huffman@27468
   673
lemma star_of_le: "(star_of x \<le> star_of y) = (x \<le> y)"
huffman@27468
   674
by transfer (rule refl)
huffman@27468
   675
huffman@27468
   676
lemma star_of_eq: "(star_of x = star_of y) = (x = y)"
huffman@27468
   677
by transfer (rule refl)
huffman@27468
   678
huffman@27468
   679
text{*As above, for 0*}
huffman@27468
   680
huffman@27468
   681
lemmas star_of_0_less = star_of_less [of 0, simplified star_of_zero]
huffman@27468
   682
lemmas star_of_0_le   = star_of_le   [of 0, simplified star_of_zero]
huffman@27468
   683
lemmas star_of_0_eq   = star_of_eq   [of 0, simplified star_of_zero]
huffman@27468
   684
huffman@27468
   685
lemmas star_of_less_0 = star_of_less [of _ 0, simplified star_of_zero]
huffman@27468
   686
lemmas star_of_le_0   = star_of_le   [of _ 0, simplified star_of_zero]
huffman@27468
   687
lemmas star_of_eq_0   = star_of_eq   [of _ 0, simplified star_of_zero]
huffman@27468
   688
huffman@27468
   689
text{*As above, for 1*}
huffman@27468
   690
huffman@27468
   691
lemmas star_of_1_less = star_of_less [of 1, simplified star_of_one]
huffman@27468
   692
lemmas star_of_1_le   = star_of_le   [of 1, simplified star_of_one]
huffman@27468
   693
lemmas star_of_1_eq   = star_of_eq   [of 1, simplified star_of_one]
huffman@27468
   694
huffman@27468
   695
lemmas star_of_less_1 = star_of_less [of _ 1, simplified star_of_one]
huffman@27468
   696
lemmas star_of_le_1   = star_of_le   [of _ 1, simplified star_of_one]
huffman@27468
   697
lemmas star_of_eq_1   = star_of_eq   [of _ 1, simplified star_of_one]
huffman@27468
   698
huffman@27468
   699
text{*As above, for numerals*}
huffman@27468
   700
huffman@27468
   701
lemmas star_of_number_less =
huffman@27468
   702
  star_of_less [of "number_of w", standard, simplified star_of_number_of]
huffman@27468
   703
lemmas star_of_number_le   =
huffman@27468
   704
  star_of_le   [of "number_of w", standard, simplified star_of_number_of]
huffman@27468
   705
lemmas star_of_number_eq   =
huffman@27468
   706
  star_of_eq   [of "number_of w", standard, simplified star_of_number_of]
huffman@27468
   707
huffman@27468
   708
lemmas star_of_less_number =
huffman@27468
   709
  star_of_less [of _ "number_of w", standard, simplified star_of_number_of]
huffman@27468
   710
lemmas star_of_le_number   =
huffman@27468
   711
  star_of_le   [of _ "number_of w", standard, simplified star_of_number_of]
huffman@27468
   712
lemmas star_of_eq_number   =
huffman@27468
   713
  star_of_eq   [of _ "number_of w", standard, simplified star_of_number_of]
huffman@27468
   714
huffman@27468
   715
lemmas star_of_simps [simp] =
huffman@27468
   716
  star_of_add     star_of_diff    star_of_minus
huffman@27468
   717
  star_of_mult    star_of_divide  star_of_inverse
huffman@27468
   718
  star_of_div     star_of_mod
huffman@27468
   719
  star_of_power   star_of_abs
huffman@27468
   720
  star_of_zero    star_of_one     star_of_number_of
huffman@27468
   721
  star_of_less    star_of_le      star_of_eq
huffman@27468
   722
  star_of_0_less  star_of_0_le    star_of_0_eq
huffman@27468
   723
  star_of_less_0  star_of_le_0    star_of_eq_0
huffman@27468
   724
  star_of_1_less  star_of_1_le    star_of_1_eq
huffman@27468
   725
  star_of_less_1  star_of_le_1    star_of_eq_1
huffman@27468
   726
  star_of_number_less star_of_number_le star_of_number_eq
huffman@27468
   727
  star_of_less_number star_of_le_number star_of_eq_number
huffman@27468
   728
huffman@27468
   729
subsection {* Ordering and lattice classes *}
huffman@27468
   730
huffman@27468
   731
instance star :: (order) order
huffman@27468
   732
apply (intro_classes)
huffman@27468
   733
apply (transfer, rule order_less_le)
huffman@27468
   734
apply (transfer, rule order_refl)
huffman@27468
   735
apply (transfer, erule (1) order_trans)
huffman@27468
   736
apply (transfer, erule (1) order_antisym)
huffman@27468
   737
done
huffman@27468
   738
huffman@27468
   739
instantiation star :: (lower_semilattice) lower_semilattice
huffman@27468
   740
begin
huffman@27468
   741
huffman@27468
   742
definition
huffman@27468
   743
  star_inf_def [transfer_unfold]: "inf \<equiv> *f2* inf"
huffman@27468
   744
huffman@27468
   745
instance
huffman@27468
   746
  by default (transfer star_inf_def, auto)+
huffman@27468
   747
huffman@27468
   748
end
huffman@27468
   749
huffman@27468
   750
instantiation star :: (upper_semilattice) upper_semilattice
huffman@27468
   751
begin
huffman@27468
   752
huffman@27468
   753
definition
huffman@27468
   754
  star_sup_def [transfer_unfold]: "sup \<equiv> *f2* sup"
huffman@27468
   755
huffman@27468
   756
instance
huffman@27468
   757
  by default (transfer star_sup_def, auto)+
huffman@27468
   758
huffman@27468
   759
end
huffman@27468
   760
huffman@27468
   761
instance star :: (lattice) lattice ..
huffman@27468
   762
huffman@27468
   763
instance star :: (distrib_lattice) distrib_lattice
huffman@27468
   764
  by default (transfer, auto simp add: sup_inf_distrib1)
huffman@27468
   765
huffman@27468
   766
lemma Standard_inf [simp]:
huffman@27468
   767
  "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> inf x y \<in> Standard"
huffman@27468
   768
by (simp add: star_inf_def)
huffman@27468
   769
huffman@27468
   770
lemma Standard_sup [simp]:
huffman@27468
   771
  "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> sup x y \<in> Standard"
huffman@27468
   772
by (simp add: star_sup_def)
huffman@27468
   773
huffman@27468
   774
lemma star_of_inf [simp]: "star_of (inf x y) = inf (star_of x) (star_of y)"
huffman@27468
   775
by transfer (rule refl)
huffman@27468
   776
huffman@27468
   777
lemma star_of_sup [simp]: "star_of (sup x y) = sup (star_of x) (star_of y)"
huffman@27468
   778
by transfer (rule refl)
huffman@27468
   779
huffman@27468
   780
instance star :: (linorder) linorder
huffman@27468
   781
by (intro_classes, transfer, rule linorder_linear)
huffman@27468
   782
huffman@27468
   783
lemma star_max_def [transfer_unfold]: "max = *f2* max"
huffman@27468
   784
apply (rule ext, rule ext)
huffman@27468
   785
apply (unfold max_def, transfer, fold max_def)
huffman@27468
   786
apply (rule refl)
huffman@27468
   787
done
huffman@27468
   788
huffman@27468
   789
lemma star_min_def [transfer_unfold]: "min = *f2* min"
huffman@27468
   790
apply (rule ext, rule ext)
huffman@27468
   791
apply (unfold min_def, transfer, fold min_def)
huffman@27468
   792
apply (rule refl)
huffman@27468
   793
done
huffman@27468
   794
huffman@27468
   795
lemma Standard_max [simp]:
huffman@27468
   796
  "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> max x y \<in> Standard"
huffman@27468
   797
by (simp add: star_max_def)
huffman@27468
   798
huffman@27468
   799
lemma Standard_min [simp]:
huffman@27468
   800
  "\<lbrakk>x \<in> Standard; y \<in> Standard\<rbrakk> \<Longrightarrow> min x y \<in> Standard"
huffman@27468
   801
by (simp add: star_min_def)
huffman@27468
   802
huffman@27468
   803
lemma star_of_max [simp]: "star_of (max x y) = max (star_of x) (star_of y)"
huffman@27468
   804
by transfer (rule refl)
huffman@27468
   805
huffman@27468
   806
lemma star_of_min [simp]: "star_of (min x y) = min (star_of x) (star_of y)"
huffman@27468
   807
by transfer (rule refl)
huffman@27468
   808
huffman@27468
   809
huffman@27468
   810
subsection {* Ordered group classes *}
huffman@27468
   811
huffman@27468
   812
instance star :: (semigroup_add) semigroup_add
huffman@27468
   813
by (intro_classes, transfer, rule add_assoc)
huffman@27468
   814
huffman@27468
   815
instance star :: (ab_semigroup_add) ab_semigroup_add
huffman@27468
   816
by (intro_classes, transfer, rule add_commute)
huffman@27468
   817
huffman@27468
   818
instance star :: (semigroup_mult) semigroup_mult
huffman@27468
   819
by (intro_classes, transfer, rule mult_assoc)
huffman@27468
   820
huffman@27468
   821
instance star :: (ab_semigroup_mult) ab_semigroup_mult
huffman@27468
   822
by (intro_classes, transfer, rule mult_commute)
huffman@27468
   823
huffman@27468
   824
instance star :: (comm_monoid_add) comm_monoid_add
huffman@27468
   825
by (intro_classes, transfer, rule comm_monoid_add_class.zero_plus.add_0)
huffman@27468
   826
huffman@27468
   827
instance star :: (monoid_mult) monoid_mult
huffman@27468
   828
apply (intro_classes)
huffman@27468
   829
apply (transfer, rule mult_1_left)
huffman@27468
   830
apply (transfer, rule mult_1_right)
huffman@27468
   831
done
huffman@27468
   832
huffman@27468
   833
instance star :: (comm_monoid_mult) comm_monoid_mult
huffman@27468
   834
by (intro_classes, transfer, rule mult_1)
huffman@27468
   835
huffman@27468
   836
instance star :: (cancel_semigroup_add) cancel_semigroup_add
huffman@27468
   837
apply (intro_classes)
huffman@27468
   838
apply (transfer, erule add_left_imp_eq)
huffman@27468
   839
apply (transfer, erule add_right_imp_eq)
huffman@27468
   840
done
huffman@27468
   841
huffman@27468
   842
instance star :: (cancel_ab_semigroup_add) cancel_ab_semigroup_add
huffman@27468
   843
by (intro_classes, transfer, rule add_imp_eq)
huffman@27468
   844
huffman@27468
   845
instance star :: (ab_group_add) ab_group_add
huffman@27468
   846
apply (intro_classes)
huffman@27468
   847
apply (transfer, rule left_minus)
huffman@27468
   848
apply (transfer, rule diff_minus)
huffman@27468
   849
done
huffman@27468
   850
huffman@27468
   851
instance star :: (pordered_ab_semigroup_add) pordered_ab_semigroup_add
huffman@27468
   852
by (intro_classes, transfer, rule add_left_mono)
huffman@27468
   853
huffman@27468
   854
instance star :: (pordered_cancel_ab_semigroup_add) pordered_cancel_ab_semigroup_add ..
huffman@27468
   855
huffman@27468
   856
instance star :: (pordered_ab_semigroup_add_imp_le) pordered_ab_semigroup_add_imp_le
huffman@27468
   857
by (intro_classes, transfer, rule add_le_imp_le_left)
huffman@27468
   858
huffman@27468
   859
instance star :: (pordered_comm_monoid_add) pordered_comm_monoid_add ..
huffman@27468
   860
instance star :: (pordered_ab_group_add) pordered_ab_group_add ..
huffman@27468
   861
huffman@27468
   862
instance star :: (pordered_ab_group_add_abs) pordered_ab_group_add_abs 
huffman@27468
   863
  by intro_classes (transfer,
huffman@27468
   864
    simp add: abs_ge_self abs_leI abs_triangle_ineq)+
huffman@27468
   865
huffman@27468
   866
instance star :: (ordered_cancel_ab_semigroup_add) ordered_cancel_ab_semigroup_add ..
huffman@27468
   867
instance star :: (lordered_ab_group_add_meet) lordered_ab_group_add_meet ..
huffman@27468
   868
instance star :: (lordered_ab_group_add_meet) lordered_ab_group_add_meet ..
huffman@27468
   869
instance star :: (lordered_ab_group_add) lordered_ab_group_add ..
huffman@27468
   870
huffman@27468
   871
instance star :: (lordered_ab_group_add_abs) lordered_ab_group_add_abs
huffman@27468
   872
by (intro_classes, transfer, rule abs_lattice)
huffman@27468
   873
huffman@27468
   874
subsection {* Ring and field classes *}
huffman@27468
   875
huffman@27468
   876
instance star :: (semiring) semiring
huffman@27468
   877
apply (intro_classes)
huffman@27468
   878
apply (transfer, rule left_distrib)
huffman@27468
   879
apply (transfer, rule right_distrib)
huffman@27468
   880
done
huffman@27468
   881
huffman@27468
   882
instance star :: (semiring_0) semiring_0 
huffman@27468
   883
by intro_classes (transfer, simp)+
huffman@27468
   884
huffman@27468
   885
instance star :: (semiring_0_cancel) semiring_0_cancel ..
huffman@27468
   886
huffman@27468
   887
instance star :: (comm_semiring) comm_semiring 
huffman@27468
   888
by (intro_classes, transfer, rule left_distrib)
huffman@27468
   889
huffman@27468
   890
instance star :: (comm_semiring_0) comm_semiring_0 ..
huffman@27468
   891
instance star :: (comm_semiring_0_cancel) comm_semiring_0_cancel ..
huffman@27468
   892
huffman@27468
   893
instance star :: (zero_neq_one) zero_neq_one
huffman@27468
   894
by (intro_classes, transfer, rule zero_neq_one)
huffman@27468
   895
huffman@27468
   896
instance star :: (semiring_1) semiring_1 ..
huffman@27468
   897
instance star :: (comm_semiring_1) comm_semiring_1 ..
huffman@27468
   898
huffman@27468
   899
instance star :: (no_zero_divisors) no_zero_divisors
huffman@27468
   900
by (intro_classes, transfer, rule no_zero_divisors)
huffman@27468
   901
huffman@27468
   902
instance star :: (semiring_1_cancel) semiring_1_cancel ..
huffman@27468
   903
instance star :: (comm_semiring_1_cancel) comm_semiring_1_cancel ..
huffman@27468
   904
instance star :: (ring) ring ..
huffman@27468
   905
instance star :: (comm_ring) comm_ring ..
huffman@27468
   906
instance star :: (ring_1) ring_1 ..
huffman@27468
   907
instance star :: (comm_ring_1) comm_ring_1 ..
huffman@27468
   908
instance star :: (ring_no_zero_divisors) ring_no_zero_divisors ..
huffman@27468
   909
instance star :: (ring_1_no_zero_divisors) ring_1_no_zero_divisors ..
huffman@27468
   910
instance star :: (idom) idom .. 
huffman@27468
   911
huffman@27468
   912
instance star :: (division_ring) division_ring
huffman@27468
   913
apply (intro_classes)
huffman@27468
   914
apply (transfer, erule left_inverse)
huffman@27468
   915
apply (transfer, erule right_inverse)
huffman@27468
   916
done
huffman@27468
   917
huffman@27468
   918
instance star :: (field) field
huffman@27468
   919
apply (intro_classes)
huffman@27468
   920
apply (transfer, erule left_inverse)
huffman@27468
   921
apply (transfer, rule divide_inverse)
huffman@27468
   922
done
huffman@27468
   923
huffman@27468
   924
instance star :: (division_by_zero) division_by_zero
huffman@27468
   925
by (intro_classes, transfer, rule inverse_zero)
huffman@27468
   926
huffman@27468
   927
instance star :: (pordered_semiring) pordered_semiring
huffman@27468
   928
apply (intro_classes)
huffman@27468
   929
apply (transfer, erule (1) mult_left_mono)
huffman@27468
   930
apply (transfer, erule (1) mult_right_mono)
huffman@27468
   931
done
huffman@27468
   932
huffman@27468
   933
instance star :: (pordered_cancel_semiring) pordered_cancel_semiring ..
huffman@27468
   934
huffman@27468
   935
instance star :: (ordered_semiring_strict) ordered_semiring_strict
huffman@27468
   936
apply (intro_classes)
huffman@27468
   937
apply (transfer, erule (1) mult_strict_left_mono)
huffman@27468
   938
apply (transfer, erule (1) mult_strict_right_mono)
huffman@27468
   939
done
huffman@27468
   940
huffman@27468
   941
instance star :: (pordered_comm_semiring) pordered_comm_semiring
huffman@27468
   942
by (intro_classes, transfer, rule mult_mono1_class.less_eq_less_times_zero.mult_mono1)
huffman@27468
   943
huffman@27468
   944
instance star :: (pordered_cancel_comm_semiring) pordered_cancel_comm_semiring ..
huffman@27468
   945
huffman@27468
   946
instance star :: (ordered_comm_semiring_strict) ordered_comm_semiring_strict
huffman@27468
   947
by (intro_classes, transfer, rule ordered_comm_semiring_strict_class.plus_less_eq_less_zero_times.mult_strict_left_mono_comm)
huffman@27468
   948
huffman@27468
   949
instance star :: (pordered_ring) pordered_ring ..
huffman@27468
   950
instance star :: (pordered_ring_abs) pordered_ring_abs
huffman@27468
   951
  by intro_classes  (transfer, rule abs_eq_mult)
huffman@27468
   952
instance star :: (lordered_ring) lordered_ring ..
huffman@27468
   953
huffman@27468
   954
instance star :: (abs_if) abs_if
huffman@27468
   955
by (intro_classes, transfer, rule abs_if)
huffman@27468
   956
huffman@27468
   957
instance star :: (sgn_if) sgn_if
huffman@27468
   958
by (intro_classes, transfer, rule sgn_if)
huffman@27468
   959
huffman@27468
   960
instance star :: (ordered_ring_strict) ordered_ring_strict ..
huffman@27468
   961
instance star :: (pordered_comm_ring) pordered_comm_ring ..
huffman@27468
   962
huffman@27468
   963
instance star :: (ordered_semidom) ordered_semidom
huffman@27468
   964
by (intro_classes, transfer, rule zero_less_one)
huffman@27468
   965
huffman@27468
   966
instance star :: (ordered_idom) ordered_idom ..
huffman@27468
   967
instance star :: (ordered_field) ordered_field ..
huffman@27468
   968
huffman@27468
   969
subsection {* Power classes *}
huffman@27468
   970
huffman@27468
   971
text {*
huffman@27468
   972
  Proving the class axiom @{thm [source] power_Suc} for type
huffman@27468
   973
  @{typ "'a star"} is a little tricky, because it quantifies
huffman@27468
   974
  over values of type @{typ nat}. The transfer principle does
huffman@27468
   975
  not handle quantification over non-star types in general,
huffman@27468
   976
  but we can work around this by fixing an arbitrary @{typ nat}
huffman@27468
   977
  value, and then applying the transfer principle.
huffman@27468
   978
*}
huffman@27468
   979
huffman@27468
   980
instance star :: (recpower) recpower
huffman@27468
   981
proof
huffman@27468
   982
  show "\<And>a::'a star. a ^ 0 = 1"
huffman@27468
   983
    by transfer (rule power_0)
huffman@27468
   984
next
huffman@27468
   985
  fix n show "\<And>a::'a star. a ^ Suc n = a * a ^ n"
huffman@27468
   986
    by transfer (rule power_Suc)
huffman@27468
   987
qed
huffman@27468
   988
huffman@27468
   989
subsection {* Number classes *}
huffman@27468
   990
huffman@27468
   991
lemma star_of_nat_def [transfer_unfold]: "of_nat n = star_of (of_nat n)"
huffman@27468
   992
by (induct n, simp_all)
huffman@27468
   993
huffman@27468
   994
lemma Standard_of_nat [simp]: "of_nat n \<in> Standard"
huffman@27468
   995
by (simp add: star_of_nat_def)
huffman@27468
   996
huffman@27468
   997
lemma star_of_of_nat [simp]: "star_of (of_nat n) = of_nat n"
huffman@27468
   998
by transfer (rule refl)
huffman@27468
   999
huffman@27468
  1000
lemma star_of_int_def [transfer_unfold]: "of_int z = star_of (of_int z)"
huffman@27468
  1001
by (rule_tac z=z in int_diff_cases, simp)
huffman@27468
  1002
huffman@27468
  1003
lemma Standard_of_int [simp]: "of_int z \<in> Standard"
huffman@27468
  1004
by (simp add: star_of_int_def)
huffman@27468
  1005
huffman@27468
  1006
lemma star_of_of_int [simp]: "star_of (of_int z) = of_int z"
huffman@27468
  1007
by transfer (rule refl)
huffman@27468
  1008
huffman@27468
  1009
instance star :: (semiring_char_0) semiring_char_0
huffman@27468
  1010
by intro_classes (simp only: star_of_nat_def star_of_eq of_nat_eq_iff)
huffman@27468
  1011
huffman@27468
  1012
instance star :: (ring_char_0) ring_char_0 ..
huffman@27468
  1013
huffman@27468
  1014
instance star :: (number_ring) number_ring
huffman@27468
  1015
by (intro_classes, simp only: star_number_def star_of_int_def number_of_eq)
huffman@27468
  1016
huffman@27468
  1017
subsection {* Finite class *}
huffman@27468
  1018
huffman@27468
  1019
lemma starset_finite: "finite A \<Longrightarrow> *s* A = star_of ` A"
huffman@27468
  1020
by (erule finite_induct, simp_all)
huffman@27468
  1021
huffman@27468
  1022
instance star :: (finite) finite
huffman@27468
  1023
apply (intro_classes)
huffman@27468
  1024
apply (subst starset_UNIV [symmetric])
huffman@27468
  1025
apply (subst starset_finite [OF finite])
huffman@27468
  1026
apply (rule finite_imageI [OF finite])
huffman@27468
  1027
done
huffman@27468
  1028
huffman@27468
  1029
end