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