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