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