src/HOL/Inductive.thy
author hoelzl
Fri Jul 03 08:26:34 2015 +0200 (2015-07-03)
changeset 60636 ee18efe9b246
parent 60174 70d8f7abde8f
child 60758 d8d85a8172b5
permissions -rw-r--r--
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
wenzelm@7700
     1
(*  Title:      HOL/Inductive.thy
wenzelm@10402
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@11688
     3
*)
wenzelm@10727
     4
wenzelm@58889
     5
section {* Knaster-Tarski Fixpoint Theorem and inductive definitions *}
lcp@1187
     6
blanchet@54398
     7
theory Inductive
blanchet@54398
     8
imports Complete_Lattices Ctr_Sugar
wenzelm@46950
     9
keywords
wenzelm@56146
    10
  "inductive" "coinductive" "inductive_cases" "inductive_simps" :: thy_decl and
wenzelm@56146
    11
  "monos" and
blanchet@54398
    12
  "print_inductives" :: diag and
blanchet@58306
    13
  "old_rep_datatype" :: thy_goal and
blanchet@55575
    14
  "primrec" :: thy_decl
nipkow@15131
    15
begin
wenzelm@10727
    16
haftmann@24915
    17
subsection {* Least and greatest fixed points *}
haftmann@24915
    18
haftmann@26013
    19
context complete_lattice
haftmann@26013
    20
begin
haftmann@26013
    21
haftmann@24915
    22
definition
haftmann@26013
    23
  lfp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a" where
haftmann@24915
    24
  "lfp f = Inf {u. f u \<le> u}"    --{*least fixed point*}
haftmann@24915
    25
haftmann@24915
    26
definition
haftmann@26013
    27
  gfp :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a" where
haftmann@24915
    28
  "gfp f = Sup {u. u \<le> f u}"    --{*greatest fixed point*}
haftmann@24915
    29
haftmann@24915
    30
haftmann@24915
    31
subsection{* Proof of Knaster-Tarski Theorem using @{term lfp} *}
haftmann@24915
    32
blanchet@54398
    33
text{*@{term "lfp f"} is the least upper bound of
haftmann@24915
    34
      the set @{term "{u. f(u) \<le> u}"} *}
haftmann@24915
    35
haftmann@24915
    36
lemma lfp_lowerbound: "f A \<le> A ==> lfp f \<le> A"
haftmann@24915
    37
  by (auto simp add: lfp_def intro: Inf_lower)
haftmann@24915
    38
haftmann@24915
    39
lemma lfp_greatest: "(!!u. f u \<le> u ==> A \<le> u) ==> A \<le> lfp f"
haftmann@24915
    40
  by (auto simp add: lfp_def intro: Inf_greatest)
haftmann@24915
    41
haftmann@26013
    42
end
haftmann@26013
    43
haftmann@24915
    44
lemma lfp_lemma2: "mono f ==> f (lfp f) \<le> lfp f"
haftmann@24915
    45
  by (iprover intro: lfp_greatest order_trans monoD lfp_lowerbound)
haftmann@24915
    46
haftmann@24915
    47
lemma lfp_lemma3: "mono f ==> lfp f \<le> f (lfp f)"
haftmann@24915
    48
  by (iprover intro: lfp_lemma2 monoD lfp_lowerbound)
haftmann@24915
    49
haftmann@24915
    50
lemma lfp_unfold: "mono f ==> lfp f = f (lfp f)"
haftmann@24915
    51
  by (iprover intro: order_antisym lfp_lemma2 lfp_lemma3)
haftmann@24915
    52
haftmann@24915
    53
lemma lfp_const: "lfp (\<lambda>x. t) = t"
haftmann@24915
    54
  by (rule lfp_unfold) (simp add:mono_def)
haftmann@24915
    55
haftmann@24915
    56
haftmann@24915
    57
subsection {* General induction rules for least fixed points *}
haftmann@24915
    58
hoelzl@60174
    59
lemma lfp_ordinal_induct[case_names mono step union]:
haftmann@26013
    60
  fixes f :: "'a\<Colon>complete_lattice \<Rightarrow> 'a"
haftmann@26013
    61
  assumes mono: "mono f"
hoelzl@60174
    62
  and P_f: "\<And>S. P S \<Longrightarrow> S \<le> lfp f \<Longrightarrow> P (f S)"
haftmann@26013
    63
  and P_Union: "\<And>M. \<forall>S\<in>M. P S \<Longrightarrow> P (Sup M)"
haftmann@26013
    64
  shows "P (lfp f)"
haftmann@26013
    65
proof -
haftmann@26013
    66
  let ?M = "{S. S \<le> lfp f \<and> P S}"
haftmann@26013
    67
  have "P (Sup ?M)" using P_Union by simp
haftmann@26013
    68
  also have "Sup ?M = lfp f"
haftmann@26013
    69
  proof (rule antisym)
haftmann@26013
    70
    show "Sup ?M \<le> lfp f" by (blast intro: Sup_least)
haftmann@26013
    71
    hence "f (Sup ?M) \<le> f (lfp f)" by (rule mono [THEN monoD])
haftmann@26013
    72
    hence "f (Sup ?M) \<le> lfp f" using mono [THEN lfp_unfold] by simp
hoelzl@60174
    73
    hence "f (Sup ?M) \<in> ?M" using P_Union by simp (intro P_f Sup_least, auto)
haftmann@26013
    74
    hence "f (Sup ?M) \<le> Sup ?M" by (rule Sup_upper)
haftmann@26013
    75
    thus "lfp f \<le> Sup ?M" by (rule lfp_lowerbound)
haftmann@26013
    76
  qed
haftmann@26013
    77
  finally show ?thesis .
haftmann@26013
    78
qed 
haftmann@26013
    79
hoelzl@60174
    80
theorem lfp_induct:
hoelzl@60174
    81
  assumes mono: "mono f" and ind: "f (inf (lfp f) P) \<le> P"
hoelzl@60174
    82
  shows "lfp f \<le> P"
hoelzl@60174
    83
proof (induction rule: lfp_ordinal_induct)
hoelzl@60174
    84
  case (step S) then show ?case
hoelzl@60174
    85
    by (intro order_trans[OF _ ind] monoD[OF mono]) auto
hoelzl@60174
    86
qed (auto intro: mono Sup_least)
hoelzl@60174
    87
hoelzl@60174
    88
lemma lfp_induct_set:
hoelzl@60174
    89
  assumes lfp: "a: lfp(f)"
hoelzl@60174
    90
      and mono: "mono(f)"
hoelzl@60174
    91
      and indhyp: "!!x. [| x: f(lfp(f) Int {x. P(x)}) |] ==> P(x)"
hoelzl@60174
    92
  shows "P(a)"
hoelzl@60174
    93
  by (rule lfp_induct [THEN subsetD, THEN CollectD, OF mono _ lfp])
hoelzl@60174
    94
     (auto simp: intro: indhyp)
hoelzl@60174
    95
haftmann@26013
    96
lemma lfp_ordinal_induct_set: 
haftmann@24915
    97
  assumes mono: "mono f"
haftmann@24915
    98
  and P_f: "!!S. P S ==> P(f S)"
haftmann@24915
    99
  and P_Union: "!!M. !S:M. P S ==> P(Union M)"
haftmann@24915
   100
  shows "P(lfp f)"
wenzelm@46008
   101
  using assms by (rule lfp_ordinal_induct)
haftmann@24915
   102
haftmann@24915
   103
haftmann@24915
   104
text{*Definition forms of @{text lfp_unfold} and @{text lfp_induct}, 
haftmann@24915
   105
    to control unfolding*}
haftmann@24915
   106
haftmann@24915
   107
lemma def_lfp_unfold: "[| h==lfp(f);  mono(f) |] ==> h = f(h)"
wenzelm@45899
   108
  by (auto intro!: lfp_unfold)
haftmann@24915
   109
haftmann@24915
   110
lemma def_lfp_induct: 
haftmann@24915
   111
    "[| A == lfp(f); mono(f);
haftmann@24915
   112
        f (inf A P) \<le> P
haftmann@24915
   113
     |] ==> A \<le> P"
haftmann@24915
   114
  by (blast intro: lfp_induct)
haftmann@24915
   115
haftmann@24915
   116
lemma def_lfp_induct_set: 
haftmann@24915
   117
    "[| A == lfp(f);  mono(f);   a:A;                    
haftmann@24915
   118
        !!x. [| x: f(A Int {x. P(x)}) |] ==> P(x)         
haftmann@24915
   119
     |] ==> P(a)"
haftmann@24915
   120
  by (blast intro: lfp_induct_set)
haftmann@24915
   121
haftmann@24915
   122
(*Monotonicity of lfp!*)
haftmann@24915
   123
lemma lfp_mono: "(!!Z. f Z \<le> g Z) ==> lfp f \<le> lfp g"
haftmann@24915
   124
  by (rule lfp_lowerbound [THEN lfp_greatest], blast intro: order_trans)
haftmann@24915
   125
haftmann@24915
   126
haftmann@24915
   127
subsection {* Proof of Knaster-Tarski Theorem using @{term gfp} *}
haftmann@24915
   128
haftmann@24915
   129
text{*@{term "gfp f"} is the greatest lower bound of 
haftmann@24915
   130
      the set @{term "{u. u \<le> f(u)}"} *}
haftmann@24915
   131
haftmann@24915
   132
lemma gfp_upperbound: "X \<le> f X ==> X \<le> gfp f"
haftmann@24915
   133
  by (auto simp add: gfp_def intro: Sup_upper)
haftmann@24915
   134
haftmann@24915
   135
lemma gfp_least: "(!!u. u \<le> f u ==> u \<le> X) ==> gfp f \<le> X"
haftmann@24915
   136
  by (auto simp add: gfp_def intro: Sup_least)
haftmann@24915
   137
haftmann@24915
   138
lemma gfp_lemma2: "mono f ==> gfp f \<le> f (gfp f)"
haftmann@24915
   139
  by (iprover intro: gfp_least order_trans monoD gfp_upperbound)
haftmann@24915
   140
haftmann@24915
   141
lemma gfp_lemma3: "mono f ==> f (gfp f) \<le> gfp f"
haftmann@24915
   142
  by (iprover intro: gfp_lemma2 monoD gfp_upperbound)
haftmann@24915
   143
haftmann@24915
   144
lemma gfp_unfold: "mono f ==> gfp f = f (gfp f)"
haftmann@24915
   145
  by (iprover intro: order_antisym gfp_lemma2 gfp_lemma3)
haftmann@24915
   146
haftmann@24915
   147
haftmann@24915
   148
subsection {* Coinduction rules for greatest fixed points *}
haftmann@24915
   149
haftmann@24915
   150
text{*weak version*}
haftmann@24915
   151
lemma weak_coinduct: "[| a: X;  X \<subseteq> f(X) |] ==> a : gfp(f)"
wenzelm@45899
   152
  by (rule gfp_upperbound [THEN subsetD]) auto
haftmann@24915
   153
haftmann@24915
   154
lemma weak_coinduct_image: "!!X. [| a : X; g`X \<subseteq> f (g`X) |] ==> g a : gfp f"
wenzelm@45899
   155
  apply (erule gfp_upperbound [THEN subsetD])
wenzelm@45899
   156
  apply (erule imageI)
wenzelm@45899
   157
  done
haftmann@24915
   158
haftmann@24915
   159
lemma coinduct_lemma:
haftmann@24915
   160
     "[| X \<le> f (sup X (gfp f));  mono f |] ==> sup X (gfp f) \<le> f (sup X (gfp f))"
haftmann@24915
   161
  apply (frule gfp_lemma2)
haftmann@24915
   162
  apply (drule mono_sup)
haftmann@24915
   163
  apply (rule le_supI)
haftmann@24915
   164
  apply assumption
haftmann@24915
   165
  apply (rule order_trans)
haftmann@24915
   166
  apply (rule order_trans)
haftmann@24915
   167
  apply assumption
haftmann@24915
   168
  apply (rule sup_ge2)
haftmann@24915
   169
  apply assumption
haftmann@24915
   170
  done
haftmann@24915
   171
haftmann@24915
   172
text{*strong version, thanks to Coen and Frost*}
haftmann@24915
   173
lemma coinduct_set: "[| mono(f);  a: X;  X \<subseteq> f(X Un gfp(f)) |] ==> a : gfp(f)"
noschinl@55604
   174
  by (rule weak_coinduct[rotated], rule coinduct_lemma) blast+
haftmann@24915
   175
haftmann@24915
   176
lemma gfp_fun_UnI2: "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))"
wenzelm@45899
   177
  by (blast dest: gfp_lemma2 mono_Un)
haftmann@24915
   178
hoelzl@60174
   179
lemma gfp_ordinal_induct[case_names mono step union]:
hoelzl@60174
   180
  fixes f :: "'a\<Colon>complete_lattice \<Rightarrow> 'a"
hoelzl@60174
   181
  assumes mono: "mono f"
hoelzl@60174
   182
  and P_f: "\<And>S. P S \<Longrightarrow> gfp f \<le> S \<Longrightarrow> P (f S)"
hoelzl@60174
   183
  and P_Union: "\<And>M. \<forall>S\<in>M. P S \<Longrightarrow> P (Inf M)"
hoelzl@60174
   184
  shows "P (gfp f)"
hoelzl@60174
   185
proof -
hoelzl@60174
   186
  let ?M = "{S. gfp f \<le> S \<and> P S}"
hoelzl@60174
   187
  have "P (Inf ?M)" using P_Union by simp
hoelzl@60174
   188
  also have "Inf ?M = gfp f"
hoelzl@60174
   189
  proof (rule antisym)
hoelzl@60174
   190
    show "gfp f \<le> Inf ?M" by (blast intro: Inf_greatest)
hoelzl@60174
   191
    hence "f (gfp f) \<le> f (Inf ?M)" by (rule mono [THEN monoD])
hoelzl@60174
   192
    hence "gfp f \<le> f (Inf ?M)" using mono [THEN gfp_unfold] by simp
hoelzl@60174
   193
    hence "f (Inf ?M) \<in> ?M" using P_Union by simp (intro P_f Inf_greatest, auto)
hoelzl@60174
   194
    hence "Inf ?M \<le> f (Inf ?M)" by (rule Inf_lower)
hoelzl@60174
   195
    thus "Inf ?M \<le> gfp f" by (rule gfp_upperbound)
hoelzl@60174
   196
  qed
hoelzl@60174
   197
  finally show ?thesis .
hoelzl@60174
   198
qed 
hoelzl@60174
   199
hoelzl@60174
   200
lemma coinduct: assumes mono: "mono f" and ind: "X \<le> f (sup X (gfp f))" shows "X \<le> gfp f"
hoelzl@60174
   201
proof (induction rule: gfp_ordinal_induct)
hoelzl@60174
   202
  case (step S) then show ?case
hoelzl@60174
   203
    by (intro order_trans[OF ind _] monoD[OF mono]) auto
hoelzl@60174
   204
qed (auto intro: mono Inf_greatest)
haftmann@24915
   205
haftmann@24915
   206
subsection {* Even Stronger Coinduction Rule, by Martin Coen *}
haftmann@24915
   207
haftmann@24915
   208
text{* Weakens the condition @{term "X \<subseteq> f(X)"} to one expressed using both
haftmann@24915
   209
  @{term lfp} and @{term gfp}*}
haftmann@24915
   210
haftmann@24915
   211
lemma coinduct3_mono_lemma: "mono(f) ==> mono(%x. f(x) Un X Un B)"
haftmann@24915
   212
by (iprover intro: subset_refl monoI Un_mono monoD)
haftmann@24915
   213
haftmann@24915
   214
lemma coinduct3_lemma:
haftmann@24915
   215
     "[| X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |]
haftmann@24915
   216
      ==> lfp(%x. f(x) Un X Un gfp(f)) \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f)))"
haftmann@24915
   217
apply (rule subset_trans)
haftmann@24915
   218
apply (erule coinduct3_mono_lemma [THEN lfp_lemma3])
haftmann@24915
   219
apply (rule Un_least [THEN Un_least])
haftmann@24915
   220
apply (rule subset_refl, assumption)
haftmann@24915
   221
apply (rule gfp_unfold [THEN equalityD1, THEN subset_trans], assumption)
wenzelm@46008
   222
apply (rule monoD, assumption)
haftmann@24915
   223
apply (subst coinduct3_mono_lemma [THEN lfp_unfold], auto)
haftmann@24915
   224
done
haftmann@24915
   225
haftmann@24915
   226
lemma coinduct3: 
haftmann@24915
   227
  "[| mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)"
haftmann@24915
   228
apply (rule coinduct3_lemma [THEN [2] weak_coinduct])
haftmann@41081
   229
apply (rule coinduct3_mono_lemma [THEN lfp_unfold, THEN ssubst])
haftmann@41081
   230
apply (simp_all)
haftmann@24915
   231
done
haftmann@24915
   232
haftmann@24915
   233
text{*Definition forms of @{text gfp_unfold} and @{text coinduct}, 
haftmann@24915
   234
    to control unfolding*}
haftmann@24915
   235
haftmann@24915
   236
lemma def_gfp_unfold: "[| A==gfp(f);  mono(f) |] ==> A = f(A)"
wenzelm@45899
   237
  by (auto intro!: gfp_unfold)
haftmann@24915
   238
haftmann@24915
   239
lemma def_coinduct:
haftmann@24915
   240
     "[| A==gfp(f);  mono(f);  X \<le> f(sup X A) |] ==> X \<le> A"
wenzelm@45899
   241
  by (iprover intro!: coinduct)
haftmann@24915
   242
haftmann@24915
   243
lemma def_coinduct_set:
haftmann@24915
   244
     "[| A==gfp(f);  mono(f);  a:X;  X \<subseteq> f(X Un A) |] ==> a: A"
wenzelm@45899
   245
  by (auto intro!: coinduct_set)
haftmann@24915
   246
haftmann@24915
   247
(*The version used in the induction/coinduction package*)
haftmann@24915
   248
lemma def_Collect_coinduct:
haftmann@24915
   249
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));   
haftmann@24915
   250
        a: X;  !!z. z: X ==> P (X Un A) z |] ==>  
haftmann@24915
   251
     a : A"
wenzelm@45899
   252
  by (erule def_coinduct_set) auto
haftmann@24915
   253
haftmann@24915
   254
lemma def_coinduct3:
haftmann@24915
   255
    "[| A==gfp(f); mono(f);  a:X;  X \<subseteq> f(lfp(%x. f(x) Un X Un A)) |] ==> a: A"
wenzelm@45899
   256
  by (auto intro!: coinduct3)
haftmann@24915
   257
haftmann@24915
   258
text{*Monotonicity of @{term gfp}!*}
haftmann@24915
   259
lemma gfp_mono: "(!!Z. f Z \<le> g Z) ==> gfp f \<le> gfp g"
haftmann@24915
   260
  by (rule gfp_upperbound [THEN gfp_least], blast intro: order_trans)
haftmann@24915
   261
hoelzl@60173
   262
subsection {* Rules for fixed point calculus *}
hoelzl@60173
   263
hoelzl@60173
   264
hoelzl@60173
   265
lemma lfp_rolling:
hoelzl@60173
   266
  assumes "mono g" "mono f"
hoelzl@60173
   267
  shows "g (lfp (\<lambda>x. f (g x))) = lfp (\<lambda>x. g (f x))"
hoelzl@60173
   268
proof (rule antisym)
hoelzl@60173
   269
  have *: "mono (\<lambda>x. f (g x))"
hoelzl@60173
   270
    using assms by (auto simp: mono_def)
hoelzl@60173
   271
hoelzl@60173
   272
  show "lfp (\<lambda>x. g (f x)) \<le> g (lfp (\<lambda>x. f (g x)))"
hoelzl@60173
   273
    by (rule lfp_lowerbound) (simp add: lfp_unfold[OF *, symmetric])
hoelzl@60173
   274
hoelzl@60173
   275
  show "g (lfp (\<lambda>x. f (g x))) \<le> lfp (\<lambda>x. g (f x))"
hoelzl@60173
   276
  proof (rule lfp_greatest)
hoelzl@60173
   277
    fix u assume "g (f u) \<le> u"
hoelzl@60173
   278
    moreover then have "g (lfp (\<lambda>x. f (g x))) \<le> g (f u)"
hoelzl@60173
   279
      by (intro assms[THEN monoD] lfp_lowerbound)
hoelzl@60173
   280
    ultimately show "g (lfp (\<lambda>x. f (g x))) \<le> u"
hoelzl@60173
   281
      by auto
hoelzl@60173
   282
  qed
hoelzl@60173
   283
qed
hoelzl@60173
   284
hoelzl@60173
   285
lemma lfp_lfp:
hoelzl@60173
   286
  assumes f: "\<And>x y w z. x \<le> y \<Longrightarrow> w \<le> z \<Longrightarrow> f x w \<le> f y z"
hoelzl@60173
   287
  shows "lfp (\<lambda>x. lfp (f x)) = lfp (\<lambda>x. f x x)"
hoelzl@60173
   288
proof (rule antisym)
hoelzl@60173
   289
  have *: "mono (\<lambda>x. f x x)"
hoelzl@60173
   290
    by (blast intro: monoI f)
hoelzl@60173
   291
  show "lfp (\<lambda>x. lfp (f x)) \<le> lfp (\<lambda>x. f x x)"
hoelzl@60173
   292
    by (intro lfp_lowerbound) (simp add: lfp_unfold[OF *, symmetric])
hoelzl@60173
   293
  show "lfp (\<lambda>x. lfp (f x)) \<ge> lfp (\<lambda>x. f x x)" (is "?F \<ge> _")
hoelzl@60173
   294
  proof (intro lfp_lowerbound)
hoelzl@60173
   295
    have *: "?F = lfp (f ?F)"
hoelzl@60173
   296
      by (rule lfp_unfold) (blast intro: monoI lfp_mono f)
hoelzl@60173
   297
    also have "\<dots> = f ?F (lfp (f ?F))"
hoelzl@60173
   298
      by (rule lfp_unfold) (blast intro: monoI lfp_mono f)
hoelzl@60173
   299
    finally show "f ?F ?F \<le> ?F"
hoelzl@60173
   300
      by (simp add: *[symmetric])
hoelzl@60173
   301
  qed
hoelzl@60173
   302
qed
hoelzl@60173
   303
hoelzl@60173
   304
lemma gfp_rolling:
hoelzl@60173
   305
  assumes "mono g" "mono f"
hoelzl@60173
   306
  shows "g (gfp (\<lambda>x. f (g x))) = gfp (\<lambda>x. g (f x))"
hoelzl@60173
   307
proof (rule antisym)
hoelzl@60173
   308
  have *: "mono (\<lambda>x. f (g x))"
hoelzl@60173
   309
    using assms by (auto simp: mono_def)
hoelzl@60173
   310
  show "g (gfp (\<lambda>x. f (g x))) \<le> gfp (\<lambda>x. g (f x))"
hoelzl@60173
   311
    by (rule gfp_upperbound) (simp add: gfp_unfold[OF *, symmetric])
hoelzl@60173
   312
hoelzl@60173
   313
  show "gfp (\<lambda>x. g (f x)) \<le> g (gfp (\<lambda>x. f (g x)))"
hoelzl@60173
   314
  proof (rule gfp_least)
hoelzl@60173
   315
    fix u assume "u \<le> g (f u)"
hoelzl@60173
   316
    moreover then have "g (f u) \<le> g (gfp (\<lambda>x. f (g x)))"
hoelzl@60173
   317
      by (intro assms[THEN monoD] gfp_upperbound)
hoelzl@60173
   318
    ultimately show "u \<le> g (gfp (\<lambda>x. f (g x)))"
hoelzl@60173
   319
      by auto
hoelzl@60173
   320
  qed
hoelzl@60173
   321
qed
hoelzl@60173
   322
hoelzl@60173
   323
lemma gfp_gfp:
hoelzl@60173
   324
  assumes f: "\<And>x y w z. x \<le> y \<Longrightarrow> w \<le> z \<Longrightarrow> f x w \<le> f y z"
hoelzl@60173
   325
  shows "gfp (\<lambda>x. gfp (f x)) = gfp (\<lambda>x. f x x)"
hoelzl@60173
   326
proof (rule antisym)
hoelzl@60173
   327
  have *: "mono (\<lambda>x. f x x)"
hoelzl@60173
   328
    by (blast intro: monoI f)
hoelzl@60173
   329
  show "gfp (\<lambda>x. f x x) \<le> gfp (\<lambda>x. gfp (f x))"
hoelzl@60173
   330
    by (intro gfp_upperbound) (simp add: gfp_unfold[OF *, symmetric])
hoelzl@60173
   331
  show "gfp (\<lambda>x. gfp (f x)) \<le> gfp (\<lambda>x. f x x)" (is "?F \<le> _")
hoelzl@60173
   332
  proof (intro gfp_upperbound)
hoelzl@60173
   333
    have *: "?F = gfp (f ?F)"
hoelzl@60173
   334
      by (rule gfp_unfold) (blast intro: monoI gfp_mono f)
hoelzl@60173
   335
    also have "\<dots> = f ?F (gfp (f ?F))"
hoelzl@60173
   336
      by (rule gfp_unfold) (blast intro: monoI gfp_mono f)
hoelzl@60173
   337
    finally show "?F \<le> f ?F ?F"
hoelzl@60173
   338
      by (simp add: *[symmetric])
hoelzl@60173
   339
  qed
hoelzl@60173
   340
qed
haftmann@24915
   341
berghofe@23734
   342
subsection {* Inductive predicates and sets *}
wenzelm@11688
   343
wenzelm@11688
   344
text {* Package setup. *}
wenzelm@10402
   345
berghofe@23734
   346
theorems basic_monos =
haftmann@22218
   347
  subset_refl imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
wenzelm@11688
   348
  Collect_mono in_mono vimage_mono
wenzelm@11688
   349
wenzelm@48891
   350
ML_file "Tools/inductive.ML"
berghofe@21018
   351
berghofe@23734
   352
theorems [mono] =
haftmann@22218
   353
  imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
berghofe@33934
   354
  imp_mono not_mono
berghofe@21018
   355
  Ball_def Bex_def
berghofe@21018
   356
  induct_rulify_fallback
berghofe@21018
   357
wenzelm@11688
   358
wenzelm@12023
   359
subsection {* Inductive datatypes and primitive recursion *}
wenzelm@11688
   360
wenzelm@11825
   361
text {* Package setup. *}
wenzelm@11825
   362
blanchet@58112
   363
ML_file "Tools/Old_Datatype/old_datatype_aux.ML"
blanchet@58112
   364
ML_file "Tools/Old_Datatype/old_datatype_prop.ML"
blanchet@58187
   365
ML_file "Tools/Old_Datatype/old_datatype_data.ML"
blanchet@58112
   366
ML_file "Tools/Old_Datatype/old_rep_datatype.ML"
blanchet@58112
   367
ML_file "Tools/Old_Datatype/old_datatype_codegen.ML"
blanchet@58112
   368
ML_file "Tools/Old_Datatype/old_primrec.ML"
berghofe@12437
   369
blanchet@55575
   370
ML_file "Tools/BNF/bnf_fp_rec_sugar_util.ML"
blanchet@55575
   371
ML_file "Tools/BNF/bnf_lfp_rec_sugar.ML"
blanchet@55575
   372
nipkow@23526
   373
text{* Lambda-abstractions with pattern matching: *}
nipkow@23526
   374
nipkow@23526
   375
syntax
nipkow@23529
   376
  "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(%_)" 10)
nipkow@23526
   377
syntax (xsymbols)
nipkow@23529
   378
  "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(\<lambda>_)" 10)
nipkow@23526
   379
wenzelm@52143
   380
parse_translation {*
wenzelm@52143
   381
  let
wenzelm@52143
   382
    fun fun_tr ctxt [cs] =
wenzelm@52143
   383
      let
wenzelm@52143
   384
        val x = Syntax.free (fst (Name.variant "x" (Term.declare_term_frees cs Name.context)));
wenzelm@52143
   385
        val ft = Case_Translation.case_tr true ctxt [x, cs];
wenzelm@52143
   386
      in lambda x ft end
wenzelm@52143
   387
  in [(@{syntax_const "_lam_pats_syntax"}, fun_tr)] end
nipkow@23526
   388
*}
nipkow@23526
   389
nipkow@23526
   390
end