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