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