src/HOL/Extraction.thy
author berghofe
Sun Jul 21 15:42:30 2002 +0200 (2002-07-21)
changeset 13403 bc2b32ee62fd
child 13452 278f2cba42ab
permissions -rw-r--r--
Added theory for setting up program extraction.
berghofe@13403
     1
(*  Title:      HOL/Extraction.thy
berghofe@13403
     2
    ID:         $Id$
berghofe@13403
     3
    Author:     Stefan Berghofer, TU Muenchen
berghofe@13403
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
berghofe@13403
     5
*)
berghofe@13403
     6
berghofe@13403
     7
header {* Program extraction for HOL *}
berghofe@13403
     8
berghofe@13403
     9
theory Extraction = Datatype
berghofe@13403
    10
files
berghofe@13403
    11
  "Tools/rewrite_hol_proof.ML":
berghofe@13403
    12
berghofe@13403
    13
subsection {* Setup *}
berghofe@13403
    14
berghofe@13403
    15
ML_setup {*
berghofe@13403
    16
  Context.>> (fn thy => thy |>
berghofe@13403
    17
    Extraction.set_preprocessor (fn sg =>
berghofe@13403
    18
      Proofterm.rewrite_proof_notypes
berghofe@13403
    19
        ([], ("HOL/elim_cong", RewriteHOLProof.elim_cong) ::
berghofe@13403
    20
          ProofRewriteRules.rprocs true) o
berghofe@13403
    21
      Proofterm.rewrite_proof (Sign.tsig_of sg)
berghofe@13403
    22
        (RewriteHOLProof.rews, ProofRewriteRules.rprocs true)))
berghofe@13403
    23
*}
berghofe@13403
    24
berghofe@13403
    25
lemmas [extraction_expand] =
berghofe@13403
    26
  nat.exhaust atomize_eq atomize_all atomize_imp
berghofe@13403
    27
  allE rev_mp conjE Eq_TrueI Eq_FalseI eqTrueI eqTrueE eq_cong2
berghofe@13403
    28
  notE' impE' impE iffE imp_cong simp_thms
berghofe@13403
    29
  induct_forall_eq induct_implies_eq induct_equal_eq
berghofe@13403
    30
  induct_forall_def induct_implies_def
berghofe@13403
    31
  induct_atomize induct_rulify1 induct_rulify2
berghofe@13403
    32
berghofe@13403
    33
datatype sumbool = Left | Right
berghofe@13403
    34
berghofe@13403
    35
subsection {* Type of extracted program *}
berghofe@13403
    36
berghofe@13403
    37
extract_type
berghofe@13403
    38
  "typeof (Trueprop P) \<equiv> typeof P"
berghofe@13403
    39
berghofe@13403
    40
  "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403
    41
     typeof (P \<longrightarrow> Q) \<equiv> Type (TYPE('Q))"
berghofe@13403
    42
berghofe@13403
    43
  "typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof (P \<longrightarrow> Q) \<equiv> Type (TYPE(Null))"
berghofe@13403
    44
berghofe@13403
    45
  "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403
    46
     typeof (P \<longrightarrow> Q) \<equiv> Type (TYPE('P \<Rightarrow> 'Q))"
berghofe@13403
    47
berghofe@13403
    48
  "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
    49
     typeof (\<forall>x. P x) \<equiv> Type (TYPE(Null))"
berghofe@13403
    50
berghofe@13403
    51
  "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE('P))) \<Longrightarrow>
berghofe@13403
    52
     typeof (\<forall>x::'a. P x) \<equiv> Type (TYPE('a \<Rightarrow> 'P))"
berghofe@13403
    53
berghofe@13403
    54
  "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
    55
     typeof (\<exists>x::'a. P x) \<equiv> Type (TYPE('a))"
berghofe@13403
    56
berghofe@13403
    57
  "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE('P))) \<Longrightarrow>
berghofe@13403
    58
     typeof (\<exists>x::'a. P x) \<equiv> Type (TYPE('a \<times> 'P))"
berghofe@13403
    59
berghofe@13403
    60
  "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403
    61
     typeof (P \<or> Q) \<equiv> Type (TYPE(sumbool))"
berghofe@13403
    62
berghofe@13403
    63
  "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403
    64
     typeof (P \<or> Q) \<equiv> Type (TYPE('Q option))"
berghofe@13403
    65
berghofe@13403
    66
  "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403
    67
     typeof (P \<or> Q) \<equiv> Type (TYPE('P option))"
berghofe@13403
    68
berghofe@13403
    69
  "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403
    70
     typeof (P \<or> Q) \<equiv> Type (TYPE('P + 'Q))"
berghofe@13403
    71
berghofe@13403
    72
  "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403
    73
     typeof (P \<and> Q) \<equiv> Type (TYPE('Q))"
berghofe@13403
    74
berghofe@13403
    75
  "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403
    76
     typeof (P \<and> Q) \<equiv> Type (TYPE('P))"
berghofe@13403
    77
berghofe@13403
    78
  "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403
    79
     typeof (P \<and> Q) \<equiv> Type (TYPE('P \<times> 'Q))"
berghofe@13403
    80
berghofe@13403
    81
  "typeof (P = Q) \<equiv> typeof ((P \<longrightarrow> Q) \<and> (Q \<longrightarrow> P))"
berghofe@13403
    82
berghofe@13403
    83
  "typeof (x \<in> P) \<equiv> typeof P"
berghofe@13403
    84
berghofe@13403
    85
subsection {* Realizability *}
berghofe@13403
    86
berghofe@13403
    87
realizability
berghofe@13403
    88
  "(realizes t (Trueprop P)) \<equiv> (Trueprop (realizes t P))"
berghofe@13403
    89
berghofe@13403
    90
  "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
    91
     (realizes t (P \<longrightarrow> Q)) \<equiv> (realizes Null P \<longrightarrow> realizes t Q)"
berghofe@13403
    92
berghofe@13403
    93
  "(typeof P) \<equiv> (Type (TYPE('P))) \<Longrightarrow>
berghofe@13403
    94
   (typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
    95
     (realizes t (P \<longrightarrow> Q)) \<equiv> (\<forall>x::'P. realizes x P \<longrightarrow> realizes Null Q)"
berghofe@13403
    96
berghofe@13403
    97
  "(realizes t (P \<longrightarrow> Q)) \<equiv> (\<forall>x. realizes x P \<longrightarrow> realizes (t x) Q)"
berghofe@13403
    98
berghofe@13403
    99
  "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   100
     (realizes t (\<forall>x. P x)) \<equiv> (\<forall>x. realizes Null (P x))"
berghofe@13403
   101
berghofe@13403
   102
  "(realizes t (\<forall>x. P x)) \<equiv> (\<forall>x. realizes (t x) (P x))"
berghofe@13403
   103
berghofe@13403
   104
  "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   105
     (realizes t (\<exists>x. P x)) \<equiv> (realizes Null (P t))"
berghofe@13403
   106
berghofe@13403
   107
  "(realizes t (\<exists>x. P x)) \<equiv> (realizes (snd t) (P (fst t)))"
berghofe@13403
   108
berghofe@13403
   109
  "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   110
   (typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   111
     (realizes t (P \<or> Q)) \<equiv>
berghofe@13403
   112
     (case t of Left \<Rightarrow> realizes Null P | Right \<Rightarrow> realizes Null Q)"
berghofe@13403
   113
berghofe@13403
   114
  "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   115
     (realizes t (P \<or> Q)) \<equiv>
berghofe@13403
   116
     (case t of None \<Rightarrow> realizes Null P | Some q \<Rightarrow> realizes q Q)"
berghofe@13403
   117
berghofe@13403
   118
  "(typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   119
     (realizes t (P \<or> Q)) \<equiv>
berghofe@13403
   120
     (case t of None \<Rightarrow> realizes Null Q | Some p \<Rightarrow> realizes p P)"
berghofe@13403
   121
berghofe@13403
   122
  "(realizes t (P \<or> Q)) \<equiv>
berghofe@13403
   123
   (case t of Inl p \<Rightarrow> realizes p P | Inr q \<Rightarrow> realizes q Q)"
berghofe@13403
   124
berghofe@13403
   125
  "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   126
     (realizes t (P \<and> Q)) \<equiv> (realizes Null P \<and> realizes t Q)"
berghofe@13403
   127
berghofe@13403
   128
  "(typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403
   129
     (realizes t (P \<and> Q)) \<equiv> (realizes t P \<and> realizes Null Q)"
berghofe@13403
   130
berghofe@13403
   131
  "(realizes t (P \<and> Q)) \<equiv> (realizes (fst t) P \<and> realizes (snd t) Q)"
berghofe@13403
   132
berghofe@13403
   133
  "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403
   134
     realizes t (\<not> P) \<equiv> \<not> realizes Null P"
berghofe@13403
   135
berghofe@13403
   136
  "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow>
berghofe@13403
   137
     realizes t (\<not> P) \<equiv> (\<forall>x::'P. \<not> realizes x P)"
berghofe@13403
   138
berghofe@13403
   139
  "typeof (P::bool) \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403
   140
   typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403
   141
     realizes t (P = Q) \<equiv> realizes Null P = realizes Null Q"
berghofe@13403
   142
berghofe@13403
   143
  "(realizes t (P = Q)) \<equiv> (realizes t ((P \<longrightarrow> Q) \<and> (Q \<longrightarrow> P)))"
berghofe@13403
   144
berghofe@13403
   145
subsection {* Computational content of basic inference rules *}
berghofe@13403
   146
berghofe@13403
   147
theorem disjE_realizer:
berghofe@13403
   148
  assumes r: "case x of Inl p \<Rightarrow> P p | Inr q \<Rightarrow> Q q"
berghofe@13403
   149
  and r1: "\<And>p. P p \<Longrightarrow> R (f p)" and r2: "\<And>q. Q q \<Longrightarrow> R (g q)"
berghofe@13403
   150
  shows "R (case x of Inl p \<Rightarrow> f p | Inr q \<Rightarrow> g q)"
berghofe@13403
   151
proof (cases x)
berghofe@13403
   152
  case Inl
berghofe@13403
   153
  with r show ?thesis by simp (rule r1)
berghofe@13403
   154
next
berghofe@13403
   155
  case Inr
berghofe@13403
   156
  with r show ?thesis by simp (rule r2)
berghofe@13403
   157
qed
berghofe@13403
   158
berghofe@13403
   159
theorem disjE_realizer2:
berghofe@13403
   160
  assumes r: "case x of None \<Rightarrow> P | Some q \<Rightarrow> Q q"
berghofe@13403
   161
  and r1: "P \<Longrightarrow> R f" and r2: "\<And>q. Q q \<Longrightarrow> R (g q)"
berghofe@13403
   162
  shows "R (case x of None \<Rightarrow> f | Some q \<Rightarrow> g q)"
berghofe@13403
   163
proof (cases x)
berghofe@13403
   164
  case None
berghofe@13403
   165
  with r show ?thesis by simp (rule r1)
berghofe@13403
   166
next
berghofe@13403
   167
  case Some
berghofe@13403
   168
  with r show ?thesis by simp (rule r2)
berghofe@13403
   169
qed
berghofe@13403
   170
berghofe@13403
   171
theorem disjE_realizer3:
berghofe@13403
   172
  assumes r: "case x of Left \<Rightarrow> P | Right \<Rightarrow> Q"
berghofe@13403
   173
  and r1: "P \<Longrightarrow> R f" and r2: "Q \<Longrightarrow> R g"
berghofe@13403
   174
  shows "R (case x of Left \<Rightarrow> f | Right \<Rightarrow> g)"
berghofe@13403
   175
proof (cases x)
berghofe@13403
   176
  case Left
berghofe@13403
   177
  with r show ?thesis by simp (rule r1)
berghofe@13403
   178
next
berghofe@13403
   179
  case Right
berghofe@13403
   180
  with r show ?thesis by simp (rule r2)
berghofe@13403
   181
qed
berghofe@13403
   182
berghofe@13403
   183
theorem conjI_realizer:
berghofe@13403
   184
  "P p \<Longrightarrow> Q q \<Longrightarrow> P (fst (p, q)) \<and> Q (snd (p, q))"
berghofe@13403
   185
  by simp
berghofe@13403
   186
berghofe@13403
   187
theorem exI_realizer:
berghofe@13403
   188
  "P x y \<Longrightarrow> P (fst (x, y)) (snd (x, y))" by simp
berghofe@13403
   189
berghofe@13403
   190
realizers
berghofe@13403
   191
  impI (P, Q): "\<lambda>P Q pq. pq"
berghofe@13403
   192
    "\<Lambda>P Q pq (h: _). allI \<cdot> _ \<bullet> (\<Lambda>x. impI \<cdot> _ \<cdot> _ \<bullet> (h \<cdot> x))"
berghofe@13403
   193
berghofe@13403
   194
  impI (P): "Null"
berghofe@13403
   195
    "\<Lambda>P Q (h: _). allI \<cdot> _ \<bullet> (\<Lambda>x. impI \<cdot> _ \<cdot> _ \<bullet> (h \<cdot> x))"
berghofe@13403
   196
berghofe@13403
   197
  impI (Q): "\<lambda>P Q q. q" "\<Lambda>P Q q. impI \<cdot> _ \<cdot> _"
berghofe@13403
   198
berghofe@13403
   199
  impI: "Null" "\<Lambda>P Q. impI \<cdot> _ \<cdot> _"
berghofe@13403
   200
berghofe@13403
   201
  mp (P, Q): "\<lambda>P Q pq. pq"
berghofe@13403
   202
    "\<Lambda>P Q pq (h: _) p. mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403
   203
berghofe@13403
   204
  mp (P): "Null"
berghofe@13403
   205
    "\<Lambda>P Q (h: _) p. mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403
   206
berghofe@13403
   207
  mp (Q): "\<lambda>P Q q. q" "\<Lambda>P Q q. mp \<cdot> _ \<cdot> _"
berghofe@13403
   208
berghofe@13403
   209
  mp: "Null" "\<Lambda>P Q. mp \<cdot> _ \<cdot> _"
berghofe@13403
   210
berghofe@13403
   211
  allI (P): "\<lambda>P p. p" "\<Lambda>P p. allI \<cdot> _"
berghofe@13403
   212
berghofe@13403
   213
  allI: "Null" "\<Lambda>P. allI \<cdot> _"
berghofe@13403
   214
berghofe@13403
   215
  spec (P): "\<lambda>P x p. p x" "\<Lambda>P x p. spec \<cdot> _ \<cdot> x"
berghofe@13403
   216
berghofe@13403
   217
  spec: "Null" "\<Lambda>P x. spec \<cdot> _ \<cdot> x"
berghofe@13403
   218
berghofe@13403
   219
  exI (P): "\<lambda>P x p. (x, p)" "\<Lambda>P. exI_realizer \<cdot> _"
berghofe@13403
   220
berghofe@13403
   221
  exI: "\<lambda>P x. x" "\<Lambda>P x (h: _). h"
berghofe@13403
   222
berghofe@13403
   223
  exE (P, Q): "\<lambda>P Q p pq. pq (fst p) (snd p)"
berghofe@13403
   224
    "\<Lambda>P Q p (h1: _) pq (h2: _). h2 \<cdot> (fst p) \<cdot> (snd p) \<bullet> h1"
berghofe@13403
   225
berghofe@13403
   226
  exE (P): "Null"
berghofe@13403
   227
    "\<Lambda>P Q p (h1: _) (h2: _). h2 \<cdot> (fst p) \<cdot> (snd p) \<bullet> h1"
berghofe@13403
   228
berghofe@13403
   229
  exE (Q): "\<lambda>P Q x pq. pq x"
berghofe@13403
   230
    "\<Lambda>P Q x (h1: _) pq (h2: _). h2 \<cdot> x \<bullet> h1"
berghofe@13403
   231
berghofe@13403
   232
  exE: "Null"
berghofe@13403
   233
    "\<Lambda>P Q x (h1: _) (h2: _). h2 \<cdot> x \<bullet> h1"
berghofe@13403
   234
berghofe@13403
   235
  conjI (P, Q): "\<lambda>P Q p q. (p, q)"
berghofe@13403
   236
    "\<Lambda>P Q p (h: _) q. conjI_realizer \<cdot>
berghofe@13403
   237
       (\<lambda>p. realizes p P) \<cdot> p \<cdot> (\<lambda>q. realizes q Q) \<cdot> q \<bullet> h"
berghofe@13403
   238
berghofe@13403
   239
  conjI (P): "\<lambda>P Q p. p"
berghofe@13403
   240
    "\<Lambda>P Q p. conjI \<cdot> _ \<cdot> _"
berghofe@13403
   241
berghofe@13403
   242
  conjI (Q): "\<lambda>P Q q. q"
berghofe@13403
   243
    "\<Lambda>P Q (h: _) q. conjI \<cdot> _ \<cdot> _ \<bullet> h"
berghofe@13403
   244
berghofe@13403
   245
  conjI: "Null"
berghofe@13403
   246
    "\<Lambda>P Q. conjI \<cdot> _ \<cdot> _"
berghofe@13403
   247
berghofe@13403
   248
  conjunct1 (P, Q): "\<lambda>P Q. fst"
berghofe@13403
   249
    "\<Lambda>P Q pq. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403
   250
berghofe@13403
   251
  conjunct1 (P): "\<lambda>P Q p. p"
berghofe@13403
   252
    "\<Lambda>P Q p. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403
   253
berghofe@13403
   254
  conjunct1 (Q): "Null"
berghofe@13403
   255
    "\<Lambda>P Q q. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403
   256
berghofe@13403
   257
  conjunct1: "Null"
berghofe@13403
   258
    "\<Lambda>P Q. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403
   259
berghofe@13403
   260
  conjunct2 (P, Q): "\<lambda>P Q. snd"
berghofe@13403
   261
    "\<Lambda>P Q pq. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403
   262
berghofe@13403
   263
  conjunct2 (P): "Null"
berghofe@13403
   264
    "\<Lambda>P Q p. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403
   265
berghofe@13403
   266
  conjunct2 (Q): "\<lambda>P Q p. p"
berghofe@13403
   267
    "\<Lambda>P Q p. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403
   268
berghofe@13403
   269
  conjunct2: "Null"
berghofe@13403
   270
    "\<Lambda>P Q. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403
   271
berghofe@13403
   272
  disjI1 (P, Q): "\<lambda>P Q. Inl"
berghofe@13403
   273
    "\<Lambda>P Q p. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sum.cases_1 \<cdot> (\<lambda>p. realizes p P) \<cdot> _ \<cdot> p)"
berghofe@13403
   274
berghofe@13403
   275
  disjI1 (P): "\<lambda>P Q. Some"
berghofe@13403
   276
    "\<Lambda>P Q p. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_2 \<cdot> _ \<cdot> (\<lambda>p. realizes p P) \<cdot> p)"
berghofe@13403
   277
berghofe@13403
   278
  disjI1 (Q): "\<lambda>P Q. None"
berghofe@13403
   279
    "\<Lambda>P Q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_1 \<cdot> _ \<cdot> _)"
berghofe@13403
   280
berghofe@13403
   281
  disjI1: "\<lambda>P Q. Left"
berghofe@13403
   282
    "\<Lambda>P Q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sumbool.cases_1 \<cdot> _ \<cdot> _)"
berghofe@13403
   283
berghofe@13403
   284
  disjI2 (P, Q): "\<lambda>Q P. Inr"
berghofe@13403
   285
    "\<Lambda>Q P q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sum.cases_2 \<cdot> _ \<cdot> (\<lambda>q. realizes q Q) \<cdot> q)"
berghofe@13403
   286
berghofe@13403
   287
  disjI2 (P): "\<lambda>Q P. None"
berghofe@13403
   288
    "\<Lambda>Q P. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_1 \<cdot> _ \<cdot> _)"
berghofe@13403
   289
berghofe@13403
   290
  disjI2 (Q): "\<lambda>Q P. Some"
berghofe@13403
   291
    "\<Lambda>Q P q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_2 \<cdot> _ \<cdot> (\<lambda>q. realizes q Q) \<cdot> q)"
berghofe@13403
   292
berghofe@13403
   293
  disjI2: "\<lambda>Q P. Right"
berghofe@13403
   294
    "\<Lambda>Q P. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sumbool.cases_2 \<cdot> _ \<cdot> _)"
berghofe@13403
   295
berghofe@13403
   296
  disjE (P, Q, R): "\<lambda>P Q R pq pr qr.
berghofe@13403
   297
     (case pq of Inl p \<Rightarrow> pr p | Inr q \<Rightarrow> qr q)"
berghofe@13403
   298
    "\<Lambda>P Q R pq (h1: _) pr (h2: _) qr.
berghofe@13403
   299
       disjE_realizer \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes r R) \<cdot> pr \<cdot> qr \<bullet> h1 \<bullet> h2"
berghofe@13403
   300
berghofe@13403
   301
  disjE (Q, R): "\<lambda>P Q R pq pr qr.
berghofe@13403
   302
     (case pq of None \<Rightarrow> pr | Some q \<Rightarrow> qr q)"
berghofe@13403
   303
    "\<Lambda>P Q R pq (h1: _) pr (h2: _) qr.
berghofe@13403
   304
       disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes r R) \<cdot> pr \<cdot> qr \<bullet> h1 \<bullet> h2"
berghofe@13403
   305
berghofe@13403
   306
  disjE (P, R): "\<lambda>P Q R pq pr qr.
berghofe@13403
   307
     (case pq of None \<Rightarrow> qr | Some p \<Rightarrow> pr p)"
berghofe@13403
   308
    "\<Lambda>P Q R pq (h1: _) pr (h2: _) qr (h3: _).
berghofe@13403
   309
       disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes r R) \<cdot> qr \<cdot> pr \<bullet> h1 \<bullet> h3 \<bullet> h2"
berghofe@13403
   310
berghofe@13403
   311
  disjE (R): "\<lambda>P Q R pq pr qr.
berghofe@13403
   312
     (case pq of Left \<Rightarrow> pr | Right \<Rightarrow> qr)"
berghofe@13403
   313
    "\<Lambda>P Q R pq (h1: _) pr (h2: _) qr.
berghofe@13403
   314
       disjE_realizer3 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes r R) \<cdot> pr \<cdot> qr \<bullet> h1 \<bullet> h2"
berghofe@13403
   315
berghofe@13403
   316
  disjE (P, Q): "Null"
berghofe@13403
   317
    "\<Lambda>P Q R pq. disjE_realizer \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes Null R) \<cdot> _ \<cdot> _"
berghofe@13403
   318
berghofe@13403
   319
  disjE (Q): "Null"
berghofe@13403
   320
    "\<Lambda>P Q R pq. disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes Null R) \<cdot> _ \<cdot> _"
berghofe@13403
   321
berghofe@13403
   322
  disjE (P): "Null"
berghofe@13403
   323
    "\<Lambda>P Q R pq (h1: _) (h2: _) (h3: _).
berghofe@13403
   324
       disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes Null R) \<cdot> _ \<cdot> _ \<bullet> h1 \<bullet> h3 \<bullet> h2"
berghofe@13403
   325
berghofe@13403
   326
  disjE: "Null"
berghofe@13403
   327
    "\<Lambda>P Q R pq. disjE_realizer3 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>r. realizes Null R) \<cdot> _ \<cdot> _"
berghofe@13403
   328
berghofe@13403
   329
  FalseE (P): "\<lambda>P. arbitrary"
berghofe@13403
   330
    "\<Lambda>P. FalseE \<cdot> _"
berghofe@13403
   331
berghofe@13403
   332
  FalseE: "Null"
berghofe@13403
   333
    "\<Lambda>P. FalseE \<cdot> _"
berghofe@13403
   334
berghofe@13403
   335
  notI (P): "Null"
berghofe@13403
   336
    "\<Lambda>P (h: _). allI \<cdot> _ \<bullet> (\<Lambda>x. notI \<cdot> _ \<bullet> (h \<cdot> x))"
berghofe@13403
   337
berghofe@13403
   338
  notI: "Null"
berghofe@13403
   339
    "\<Lambda>P. notI \<cdot> _"
berghofe@13403
   340
berghofe@13403
   341
  notE (P, R): "\<lambda>P R p. arbitrary"
berghofe@13403
   342
    "\<Lambda>P R (h: _) p. notE \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403
   343
berghofe@13403
   344
  notE (P): "Null"
berghofe@13403
   345
    "\<Lambda>P R (h: _) p. notE \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403
   346
berghofe@13403
   347
  notE (R): "\<lambda>P R. arbitrary"
berghofe@13403
   348
    "\<Lambda>P R. notE \<cdot> _ \<cdot> _"
berghofe@13403
   349
berghofe@13403
   350
  notE: "Null"
berghofe@13403
   351
    "\<Lambda>P R. notE \<cdot> _ \<cdot> _"
berghofe@13403
   352
berghofe@13403
   353
  subst (P): "\<lambda>s t P ps. ps"
berghofe@13403
   354
    "\<Lambda>s t P (h: _) ps. subst \<cdot> s \<cdot> t \<cdot> (\<lambda>x. realizes ps (P x)) \<bullet> h"
berghofe@13403
   355
berghofe@13403
   356
  subst: "Null"
berghofe@13403
   357
    "\<Lambda>s t P. subst \<cdot> s \<cdot> t \<cdot> (\<lambda>x. realizes Null (P x))"
berghofe@13403
   358
berghofe@13403
   359
  iffD1 (P, Q): "\<lambda>Q P. fst"
berghofe@13403
   360
    "\<Lambda>Q P pq (h: _) p.
berghofe@13403
   361
       mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> (conjunct1 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403
   362
berghofe@13403
   363
  iffD1 (P): "\<lambda>Q P p. p"
berghofe@13403
   364
    "\<Lambda>Q P p (h: _). mp \<cdot> _ \<cdot> _ \<bullet> (conjunct1 \<cdot> _ \<cdot> _ \<bullet> h)"
berghofe@13403
   365
berghofe@13403
   366
  iffD1 (Q): "Null"
berghofe@13403
   367
    "\<Lambda>Q P q1 (h: _) q2.
berghofe@13403
   368
       mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> q2 \<bullet> (conjunct1 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403
   369
berghofe@13403
   370
  iffD1: "Null"
berghofe@13403
   371
    "\<Lambda>Q P. iffD1 \<cdot> _ \<cdot> _"
berghofe@13403
   372
berghofe@13403
   373
  iffD2 (P, Q): "\<lambda>P Q. snd"
berghofe@13403
   374
    "\<Lambda>P Q pq (h: _) q.
berghofe@13403
   375
       mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> q \<bullet> (conjunct2 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403
   376
berghofe@13403
   377
  iffD2 (P): "\<lambda>P Q p. p"
berghofe@13403
   378
    "\<Lambda>P Q p (h: _). mp \<cdot> _ \<cdot> _ \<bullet> (conjunct2 \<cdot> _ \<cdot> _ \<bullet> h)"
berghofe@13403
   379
berghofe@13403
   380
  iffD2 (Q): "Null"
berghofe@13403
   381
    "\<Lambda>P Q q1 (h: _) q2.
berghofe@13403
   382
       mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> q2 \<bullet> (conjunct2 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403
   383
berghofe@13403
   384
  iffD2: "Null"
berghofe@13403
   385
    "\<Lambda>P Q. iffD2 \<cdot> _ \<cdot> _"
berghofe@13403
   386
berghofe@13403
   387
  iffI (P, Q): "\<lambda>P Q pq qp. (pq, qp)"
berghofe@13403
   388
    "\<Lambda>P Q pq (h1 : _) qp (h2 : _). conjI_realizer \<cdot>
berghofe@13403
   389
       (\<lambda>pq. \<forall>x. realizes x P \<longrightarrow> realizes (pq x) Q) \<cdot> pq \<cdot>
berghofe@13403
   390
       (\<lambda>qp. \<forall>x. realizes x Q \<longrightarrow> realizes (qp x) P) \<cdot> qp \<bullet>
berghofe@13403
   391
       (allI \<cdot> _ \<bullet> (\<Lambda>x. impI \<cdot> _ \<cdot> _ \<bullet> (h1 \<cdot> x))) \<bullet>
berghofe@13403
   392
       (allI \<cdot> _ \<bullet> (\<Lambda>x. impI \<cdot> _ \<cdot> _ \<bullet> (h2 \<cdot> x)))"
berghofe@13403
   393
berghofe@13403
   394
  iffI (P): "\<lambda>P Q p. p"
berghofe@13403
   395
    "\<Lambda>P Q (h1 : _) p (h2 : _). conjI \<cdot> _ \<cdot> _ \<bullet>
berghofe@13403
   396
       (allI \<cdot> _ \<bullet> (\<Lambda>x. impI \<cdot> _ \<cdot> _ \<bullet> (h1 \<cdot> x))) \<bullet>
berghofe@13403
   397
       (impI \<cdot> _ \<cdot> _ \<bullet> h2)"
berghofe@13403
   398
berghofe@13403
   399
  iffI (Q): "\<lambda>P Q q. q"
berghofe@13403
   400
    "\<Lambda>P Q q (h1 : _) (h2 : _). conjI \<cdot> _ \<cdot> _ \<bullet>
berghofe@13403
   401
       (impI \<cdot> _ \<cdot> _ \<bullet> h1) \<bullet>
berghofe@13403
   402
       (allI \<cdot> _ \<bullet> (\<Lambda>x. impI \<cdot> _ \<cdot> _ \<bullet> (h2 \<cdot> x)))"
berghofe@13403
   403
berghofe@13403
   404
  iffI: "Null"
berghofe@13403
   405
    "\<Lambda>P Q. iffI \<cdot> _ \<cdot> _"
berghofe@13403
   406
berghofe@13403
   407
  classical: "Null"
berghofe@13403
   408
    "\<Lambda>P. classical \<cdot> _"
berghofe@13403
   409
berghofe@13403
   410
berghofe@13403
   411
subsection {* Induction on natural numbers *}
berghofe@13403
   412
berghofe@13403
   413
theorem nat_ind_realizer:
berghofe@13403
   414
  "R f 0 \<Longrightarrow> (\<And>y h. R h y \<Longrightarrow> R (g y h) (Suc y)) \<Longrightarrow>
berghofe@13403
   415
     (R::'a \<Rightarrow> nat \<Rightarrow> bool) (nat_rec f g x) x"
berghofe@13403
   416
proof -
berghofe@13403
   417
  assume r1: "R f 0"
berghofe@13403
   418
  assume r2: "\<And>y h. R h y \<Longrightarrow> R (g y h) (Suc y)"
berghofe@13403
   419
  show "R (nat_rec f g x) x"
berghofe@13403
   420
  proof (induct x)
berghofe@13403
   421
    case 0
berghofe@13403
   422
    from r1 show ?case by simp
berghofe@13403
   423
  next
berghofe@13403
   424
    case (Suc n)
berghofe@13403
   425
    from Suc have "R (g n (nat_rec f g n)) (Suc n)" by (rule r2)
berghofe@13403
   426
    thus ?case by simp
berghofe@13403
   427
  qed
berghofe@13403
   428
qed
berghofe@13403
   429
berghofe@13403
   430
realizers
berghofe@13403
   431
  NatDef.nat_induct (P): "\<lambda>P n p0 ps. nat_rec p0 ps n"
berghofe@13403
   432
    "\<Lambda>P n p0 (h: _) ps. nat_ind_realizer \<cdot> _ \<cdot> _ \<cdot> _ \<cdot> _ \<bullet> h"
berghofe@13403
   433
berghofe@13403
   434
  NatDef.nat_induct: "Null"
berghofe@13403
   435
    "\<Lambda>P n. nat_induct \<cdot> _ \<cdot> _"
berghofe@13403
   436
berghofe@13403
   437
  Nat.nat.induct (P): "\<lambda>P n p0 ps. nat_rec p0 ps n"
berghofe@13403
   438
    "\<Lambda>P n p0 (h: _) ps. nat_ind_realizer \<cdot> _ \<cdot> _ \<cdot> _ \<cdot> _ \<bullet> h"
berghofe@13403
   439
berghofe@13403
   440
  Nat.nat.induct: "Null"
berghofe@13403
   441
    "\<Lambda>P n. nat_induct \<cdot> _ \<cdot> _"
berghofe@13403
   442
berghofe@13403
   443
end