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