
berghofe@13403: (*  Title:      HOL/Extraction.thy
berghofe@13403:     ID:         $Id$
berghofe@13403:     Author:     Stefan Berghofer, TU Muenchen
berghofe@13403: *)
berghofe@13403: 
berghofe@13403: header {* Program extraction for HOL *}
berghofe@13403: 
nipkow@15131: theory Extraction
haftmann@24194: imports Datatype
haftmann@16417: uses "Tools/rewrite_hol_proof.ML"
nipkow@15131: begin
berghofe@13403: 
berghofe@13403: subsection {* Setup *}
berghofe@13403: 
wenzelm@16121: setup {*
wenzelm@16121: let
berghofe@13725: fun realizes_set_proc (Const ("realizes", Type ("fun", [Type ("Null", []), _])) $ r $
berghofe@13725:       (Const ("op :", _) $ x $ S)) = (case strip_comb S of
skalberg@15531:         (Var (ixn, U), ts) => SOME (list_comb (Var (ixn, binder_types U @
berghofe@13725:            [HOLogic.dest_setT (body_type U)] ---> HOLogic.boolT), ts @ [x]))
skalberg@15531:       | (Free (s, U), ts) => SOME (list_comb (Free (s, binder_types U @
berghofe@13725:            [HOLogic.dest_setT (body_type U)] ---> HOLogic.boolT), ts @ [x]))
skalberg@15531:       | _ => NONE)
berghofe@13725:   | realizes_set_proc (Const ("realizes", Type ("fun", [T, _])) $ r $
berghofe@13725:       (Const ("op :", _) $ x $ S)) = (case strip_comb S of
skalberg@15531:         (Var (ixn, U), ts) => SOME (list_comb (Var (ixn, T :: binder_types U @
berghofe@13725:            [HOLogic.dest_setT (body_type U)] ---> HOLogic.boolT), r :: ts @ [x]))
skalberg@15531:       | (Free (s, U), ts) => SOME (list_comb (Free (s, T :: binder_types U @
berghofe@13725:            [HOLogic.dest_setT (body_type U)] ---> HOLogic.boolT), r :: ts @ [x]))
skalberg@15531:       | _ => NONE)
skalberg@15531:   | realizes_set_proc _ = NONE;
berghofe@13725: 
berghofe@13725: fun mk_realizes_set r rT s (setT as Type ("set", [elT])) =
berghofe@13725:   Abs ("x", elT, Const ("realizes", rT --> HOLogic.boolT --> HOLogic.boolT) $
berghofe@13725:     incr_boundvars 1 r $ (Const ("op :", elT --> setT --> HOLogic.boolT) $
berghofe@13725:       Bound 0 $ incr_boundvars 1 s));
wenzelm@16121: in
wenzelm@18708:   Extraction.add_types
skalberg@15531:       [("bool", ([], NONE)),
wenzelm@18708:        ("set", ([realizes_set_proc], SOME mk_realizes_set))] #>
wenzelm@18708:   Extraction.set_preprocessor (fn thy =>
berghofe@13403:       Proofterm.rewrite_proof_notypes
berghofe@13403:         ([], ("HOL/elim_cong", RewriteHOLProof.elim_cong) ::
berghofe@13403:           ProofRewriteRules.rprocs true) o
wenzelm@17203:       Proofterm.rewrite_proof thy
berghofe@13599:         (RewriteHOLProof.rews, ProofRewriteRules.rprocs true) o
haftmann@27982:       ProofRewriteRules.elim_vars (curry Const @{const_name default}))
wenzelm@16121: end
berghofe@13403: *}
berghofe@13403: 
berghofe@13403: lemmas [extraction_expand] =
berghofe@22281:   meta_spec atomize_eq atomize_all atomize_imp atomize_conj
berghofe@13403:   allE rev_mp conjE Eq_TrueI Eq_FalseI eqTrueI eqTrueE eq_cong2
haftmann@20941:   notE' impE' impE iffE imp_cong simp_thms eq_True eq_False
wenzelm@18456:   induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq
wenzelm@18456:   induct_forall_def induct_implies_def induct_equal_def induct_conj_def
wenzelm@18511:   induct_atomize induct_rulify induct_rulify_fallback
berghofe@25424:   True_implies_equals TrueE
berghofe@13403: 
berghofe@13403: datatype sumbool = Left | Right
berghofe@13403: 
berghofe@13403: subsection {* Type of extracted program *}
berghofe@13403: 
berghofe@13403: extract_type
berghofe@13403:   "typeof (Trueprop P) \<equiv> typeof P"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403:      typeof (P \<longrightarrow> Q) \<equiv> Type (TYPE('Q))"
berghofe@13403: 
berghofe@13403:   "typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof (P \<longrightarrow> Q) \<equiv> Type (TYPE(Null))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403:      typeof (P \<longrightarrow> Q) \<equiv> Type (TYPE('P \<Rightarrow> 'Q))"
berghofe@13403: 
berghofe@13403:   "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      typeof (\<forall>x. P x) \<equiv> Type (TYPE(Null))"
berghofe@13403: 
berghofe@13403:   "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE('P))) \<Longrightarrow>
berghofe@13403:      typeof (\<forall>x::'a. P x) \<equiv> Type (TYPE('a \<Rightarrow> 'P))"
berghofe@13403: 
berghofe@13403:   "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      typeof (\<exists>x::'a. P x) \<equiv> Type (TYPE('a))"
berghofe@13403: 
berghofe@13403:   "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE('P))) \<Longrightarrow>
berghofe@13403:      typeof (\<exists>x::'a. P x) \<equiv> Type (TYPE('a \<times> 'P))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403:      typeof (P \<or> Q) \<equiv> Type (TYPE(sumbool))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403:      typeof (P \<or> Q) \<equiv> Type (TYPE('Q option))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403:      typeof (P \<or> Q) \<equiv> Type (TYPE('P option))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403:      typeof (P \<or> Q) \<equiv> Type (TYPE('P + 'Q))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403:      typeof (P \<and> Q) \<equiv> Type (TYPE('Q))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403:      typeof (P \<and> Q) \<equiv> Type (TYPE('P))"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow> typeof Q \<equiv> Type (TYPE('Q)) \<Longrightarrow>
berghofe@13403:      typeof (P \<and> Q) \<equiv> Type (TYPE('P \<times> 'Q))"
berghofe@13403: 
berghofe@13403:   "typeof (P = Q) \<equiv> typeof ((P \<longrightarrow> Q) \<and> (Q \<longrightarrow> P))"
berghofe@13403: 
berghofe@13403:   "typeof (x \<in> P) \<equiv> typeof P"
berghofe@13403: 
berghofe@13403: subsection {* Realizability *}
berghofe@13403: 
berghofe@13403: realizability
berghofe@13403:   "(realizes t (Trueprop P)) \<equiv> (Trueprop (realizes t P))"
berghofe@13403: 
berghofe@13403:   "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<longrightarrow> Q)) \<equiv> (realizes Null P \<longrightarrow> realizes t Q)"
berghofe@13403: 
berghofe@13403:   "(typeof P) \<equiv> (Type (TYPE('P))) \<Longrightarrow>
berghofe@13403:    (typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<longrightarrow> Q)) \<equiv> (\<forall>x::'P. realizes x P \<longrightarrow> realizes Null Q)"
berghofe@13403: 
berghofe@13403:   "(realizes t (P \<longrightarrow> Q)) \<equiv> (\<forall>x. realizes x P \<longrightarrow> realizes (t x) Q)"
berghofe@13403: 
berghofe@13403:   "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (\<forall>x. P x)) \<equiv> (\<forall>x. realizes Null (P x))"
berghofe@13403: 
berghofe@13403:   "(realizes t (\<forall>x. P x)) \<equiv> (\<forall>x. realizes (t x) (P x))"
berghofe@13403: 
berghofe@13403:   "(\<lambda>x. typeof (P x)) \<equiv> (\<lambda>x. Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (\<exists>x. P x)) \<equiv> (realizes Null (P t))"
berghofe@13403: 
berghofe@13403:   "(realizes t (\<exists>x. P x)) \<equiv> (realizes (snd t) (P (fst t)))"
berghofe@13403: 
berghofe@13403:   "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:    (typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<or> Q)) \<equiv>
berghofe@13403:      (case t of Left \<Rightarrow> realizes Null P | Right \<Rightarrow> realizes Null Q)"
berghofe@13403: 
berghofe@13403:   "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<or> Q)) \<equiv>
berghofe@13403:      (case t of None \<Rightarrow> realizes Null P | Some q \<Rightarrow> realizes q Q)"
berghofe@13403: 
berghofe@13403:   "(typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<or> Q)) \<equiv>
berghofe@13403:      (case t of None \<Rightarrow> realizes Null Q | Some p \<Rightarrow> realizes p P)"
berghofe@13403: 
berghofe@13403:   "(realizes t (P \<or> Q)) \<equiv>
berghofe@13403:    (case t of Inl p \<Rightarrow> realizes p P | Inr q \<Rightarrow> realizes q Q)"
berghofe@13403: 
berghofe@13403:   "(typeof P) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<and> Q)) \<equiv> (realizes Null P \<and> realizes t Q)"
berghofe@13403: 
berghofe@13403:   "(typeof Q) \<equiv> (Type (TYPE(Null))) \<Longrightarrow>
berghofe@13403:      (realizes t (P \<and> Q)) \<equiv> (realizes t P \<and> realizes Null Q)"
berghofe@13403: 
berghofe@13403:   "(realizes t (P \<and> Q)) \<equiv> (realizes (fst t) P \<and> realizes (snd t) Q)"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403:      realizes t (\<not> P) \<equiv> \<not> realizes Null P"
berghofe@13403: 
berghofe@13403:   "typeof P \<equiv> Type (TYPE('P)) \<Longrightarrow>
berghofe@13403:      realizes t (\<not> P) \<equiv> (\<forall>x::'P. \<not> realizes x P)"
berghofe@13403: 
berghofe@13403:   "typeof (P::bool) \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403:    typeof Q \<equiv> Type (TYPE(Null)) \<Longrightarrow>
berghofe@13403:      realizes t (P = Q) \<equiv> realizes Null P = realizes Null Q"
berghofe@13403: 
berghofe@13403:   "(realizes t (P = Q)) \<equiv> (realizes t ((P \<longrightarrow> Q) \<and> (Q \<longrightarrow> P)))"
berghofe@13403: 
berghofe@13403: subsection {* Computational content of basic inference rules *}
berghofe@13403: 
berghofe@13403: theorem disjE_realizer:
berghofe@13403:   assumes r: "case x of Inl p \<Rightarrow> P p | Inr q \<Rightarrow> Q q"
berghofe@13403:   and r1: "\<And>p. P p \<Longrightarrow> R (f p)" and r2: "\<And>q. Q q \<Longrightarrow> R (g q)"
berghofe@13403:   shows "R (case x of Inl p \<Rightarrow> f p | Inr q \<Rightarrow> g q)"
berghofe@13403: proof (cases x)
berghofe@13403:   case Inl
berghofe@13403:   with r show ?thesis by simp (rule r1)
berghofe@13403: next
berghofe@13403:   case Inr
berghofe@13403:   with r show ?thesis by simp (rule r2)
berghofe@13403: qed
berghofe@13403: 
berghofe@13403: theorem disjE_realizer2:
berghofe@13403:   assumes r: "case x of None \<Rightarrow> P | Some q \<Rightarrow> Q q"
berghofe@13403:   and r1: "P \<Longrightarrow> R f" and r2: "\<And>q. Q q \<Longrightarrow> R (g q)"
berghofe@13403:   shows "R (case x of None \<Rightarrow> f | Some q \<Rightarrow> g q)"
berghofe@13403: proof (cases x)
berghofe@13403:   case None
berghofe@13403:   with r show ?thesis by simp (rule r1)
berghofe@13403: next
berghofe@13403:   case Some
berghofe@13403:   with r show ?thesis by simp (rule r2)
berghofe@13403: qed
berghofe@13403: 
berghofe@13403: theorem disjE_realizer3:
berghofe@13403:   assumes r: "case x of Left \<Rightarrow> P | Right \<Rightarrow> Q"
berghofe@13403:   and r1: "P \<Longrightarrow> R f" and r2: "Q \<Longrightarrow> R g"
berghofe@13403:   shows "R (case x of Left \<Rightarrow> f | Right \<Rightarrow> g)"
berghofe@13403: proof (cases x)
berghofe@13403:   case Left
berghofe@13403:   with r show ?thesis by simp (rule r1)
berghofe@13403: next
berghofe@13403:   case Right
berghofe@13403:   with r show ?thesis by simp (rule r2)
berghofe@13403: qed
berghofe@13403: 
berghofe@13403: theorem conjI_realizer:
berghofe@13403:   "P p \<Longrightarrow> Q q \<Longrightarrow> P (fst (p, q)) \<and> Q (snd (p, q))"
berghofe@13403:   by simp
berghofe@13403: 
berghofe@13403: theorem exI_realizer:
berghofe@13918:   "P y x \<Longrightarrow> P (snd (x, y)) (fst (x, y))" by simp
berghofe@13918: 
berghofe@13918: theorem exE_realizer: "P (snd p) (fst p) \<Longrightarrow>
berghofe@15393:   (\<And>x y. P y x \<Longrightarrow> Q (f x y)) \<Longrightarrow> Q (let (x, y) = p in f x y)"
berghofe@15393:   by (cases p) (simp add: Let_def)
berghofe@13918: 
berghofe@13918: theorem exE_realizer': "P (snd p) (fst p) \<Longrightarrow>
berghofe@13918:   (\<And>x y. P y x \<Longrightarrow> Q) \<Longrightarrow> Q" by (cases p) simp
berghofe@13403: 
haftmann@27982: setup {*
haftmann@27982:   Sign.add_const_constraint (@{const_name "default"}, SOME @{typ "'a::type"})
haftmann@27982: *}
haftmann@27982: 
berghofe@13403: realizers
berghofe@13725:   impI (P, Q): "\<lambda>pq. pq"
skalberg@14168:     "\<Lambda> P Q pq (h: _). allI \<cdot> _ \<bullet> (\<Lambda> x. impI \<cdot> _ \<cdot> _ \<bullet> (h \<cdot> x))"
berghofe@13403: 
berghofe@13403:   impI (P): "Null"
skalberg@14168:     "\<Lambda> P Q (h: _). allI \<cdot> _ \<bullet> (\<Lambda> x. impI \<cdot> _ \<cdot> _ \<bullet> (h \<cdot> x))"
berghofe@13403: 
skalberg@14168:   impI (Q): "\<lambda>q. q" "\<Lambda> P Q q. impI \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   impI: "Null" "impI"
berghofe@13403: 
berghofe@13725:   mp (P, Q): "\<lambda>pq. pq"
skalberg@14168:     "\<Lambda> P Q pq (h: _) p. mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403: 
berghofe@13403:   mp (P): "Null"
skalberg@14168:     "\<Lambda> P Q (h: _) p. mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403: 
skalberg@14168:   mp (Q): "\<lambda>q. q" "\<Lambda> P Q q. mp \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   mp: "Null" "mp"
berghofe@13403: 
skalberg@14168:   allI (P): "\<lambda>p. p" "\<Lambda> P p. allI \<cdot> _"
berghofe@13403: 
berghofe@13725:   allI: "Null" "allI"
berghofe@13403: 
skalberg@14168:   spec (P): "\<lambda>x p. p x" "\<Lambda> P x p. spec \<cdot> _ \<cdot> x"
berghofe@13403: 
berghofe@13725:   spec: "Null" "spec"
berghofe@13403: 
skalberg@14168:   exI (P): "\<lambda>x p. (x, p)" "\<Lambda> P x p. exI_realizer \<cdot> P \<cdot> p \<cdot> x"
berghofe@13403: 
skalberg@14168:   exI: "\<lambda>x. x" "\<Lambda> P x (h: _). h"
berghofe@13403: 
berghofe@15393:   exE (P, Q): "\<lambda>p pq. let (x, y) = p in pq x y"
skalberg@14168:     "\<Lambda> P Q p (h: _) pq. exE_realizer \<cdot> P \<cdot> p \<cdot> Q \<cdot> pq \<bullet> h"
berghofe@13403: 
berghofe@13403:   exE (P): "Null"
skalberg@14168:     "\<Lambda> P Q p. exE_realizer' \<cdot> _ \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   exE (Q): "\<lambda>x pq. pq x"
skalberg@14168:     "\<Lambda> P Q x (h1: _) pq (h2: _). h2 \<cdot> x \<bullet> h1"
berghofe@13403: 
berghofe@13403:   exE: "Null"
skalberg@14168:     "\<Lambda> P Q x (h1: _) (h2: _). h2 \<cdot> x \<bullet> h1"
berghofe@13403: 
berghofe@13725:   conjI (P, Q): "Pair"
skalberg@14168:     "\<Lambda> P Q p (h: _) q. conjI_realizer \<cdot> P \<cdot> p \<cdot> Q \<cdot> q \<bullet> h"
berghofe@13403: 
berghofe@13725:   conjI (P): "\<lambda>p. p"
skalberg@14168:     "\<Lambda> P Q p. conjI \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   conjI (Q): "\<lambda>q. q"
skalberg@14168:     "\<Lambda> P Q (h: _) q. conjI \<cdot> _ \<cdot> _ \<bullet> h"
berghofe@13403: 
berghofe@13725:   conjI: "Null" "conjI"
berghofe@13403: 
berghofe@13725:   conjunct1 (P, Q): "fst"
skalberg@14168:     "\<Lambda> P Q pq. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   conjunct1 (P): "\<lambda>p. p"
skalberg@14168:     "\<Lambda> P Q p. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13403:   conjunct1 (Q): "Null"
skalberg@14168:     "\<Lambda> P Q q. conjunct1 \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   conjunct1: "Null" "conjunct1"
berghofe@13403: 
berghofe@13725:   conjunct2 (P, Q): "snd"
skalberg@14168:     "\<Lambda> P Q pq. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13403:   conjunct2 (P): "Null"
skalberg@14168:     "\<Lambda> P Q p. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   conjunct2 (Q): "\<lambda>p. p"
skalberg@14168:     "\<Lambda> P Q p. conjunct2 \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   conjunct2: "Null" "conjunct2"
berghofe@13725: 
berghofe@13725:   disjI1 (P, Q): "Inl"
skalberg@14168:     "\<Lambda> P Q p. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sum.cases_1 \<cdot> P \<cdot> _ \<cdot> p)"
berghofe@13403: 
berghofe@13725:   disjI1 (P): "Some"
skalberg@14168:     "\<Lambda> P Q p. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_2 \<cdot> _ \<cdot> P \<cdot> p)"
berghofe@13403: 
berghofe@13725:   disjI1 (Q): "None"
skalberg@14168:     "\<Lambda> P Q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_1 \<cdot> _ \<cdot> _)"
berghofe@13403: 
berghofe@13725:   disjI1: "Left"
skalberg@14168:     "\<Lambda> P Q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sumbool.cases_1 \<cdot> _ \<cdot> _)"
berghofe@13403: 
berghofe@13725:   disjI2 (P, Q): "Inr"
skalberg@14168:     "\<Lambda> Q P q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sum.cases_2 \<cdot> _ \<cdot> Q \<cdot> q)"
berghofe@13403: 
berghofe@13725:   disjI2 (P): "None"
skalberg@14168:     "\<Lambda> Q P. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_1 \<cdot> _ \<cdot> _)"
berghofe@13403: 
berghofe@13725:   disjI2 (Q): "Some"
skalberg@14168:     "\<Lambda> Q P q. iffD2 \<cdot> _ \<cdot> _ \<bullet> (option.cases_2 \<cdot> _ \<cdot> Q \<cdot> q)"
berghofe@13403: 
berghofe@13725:   disjI2: "Right"
skalberg@14168:     "\<Lambda> Q P. iffD2 \<cdot> _ \<cdot> _ \<bullet> (sumbool.cases_2 \<cdot> _ \<cdot> _)"
berghofe@13403: 
berghofe@13725:   disjE (P, Q, R): "\<lambda>pq pr qr.
berghofe@13403:      (case pq of Inl p \<Rightarrow> pr p | Inr q \<Rightarrow> qr q)"
skalberg@14168:     "\<Lambda> P Q R pq (h1: _) pr (h2: _) qr.
berghofe@13725:        disjE_realizer \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> R \<cdot> pr \<cdot> qr \<bullet> h1 \<bullet> h2"
berghofe@13403: 
berghofe@13725:   disjE (Q, R): "\<lambda>pq pr qr.
berghofe@13403:      (case pq of None \<Rightarrow> pr | Some q \<Rightarrow> qr q)"
skalberg@14168:     "\<Lambda> P Q R pq (h1: _) pr (h2: _) qr.
berghofe@13725:        disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> R \<cdot> pr \<cdot> qr \<bullet> h1 \<bullet> h2"
berghofe@13403: 
berghofe@13725:   disjE (P, R): "\<lambda>pq pr qr.
berghofe@13403:      (case pq of None \<Rightarrow> qr | Some p \<Rightarrow> pr p)"
skalberg@14168:     "\<Lambda> P Q R pq (h1: _) pr (h2: _) qr (h3: _).
berghofe@13725:        disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> R \<cdot> qr \<cdot> pr \<bullet> h1 \<bullet> h3 \<bullet> h2"
berghofe@13403: 
berghofe@13725:   disjE (R): "\<lambda>pq pr qr.
berghofe@13403:      (case pq of Left \<Rightarrow> pr | Right \<Rightarrow> qr)"
skalberg@14168:     "\<Lambda> P Q R pq (h1: _) pr (h2: _) qr.
berghofe@13725:        disjE_realizer3 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> R \<cdot> pr \<cdot> qr \<bullet> h1 \<bullet> h2"
berghofe@13403: 
berghofe@13403:   disjE (P, Q): "Null"
skalberg@14168:     "\<Lambda> P Q R pq. disjE_realizer \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>x. R) \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13403:   disjE (Q): "Null"
skalberg@14168:     "\<Lambda> P Q R pq. disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>x. R) \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13403:   disjE (P): "Null"
skalberg@14168:     "\<Lambda> P Q R pq (h1: _) (h2: _) (h3: _).
berghofe@13725:        disjE_realizer2 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>x. R) \<cdot> _ \<cdot> _ \<bullet> h1 \<bullet> h3 \<bullet> h2"
berghofe@13403: 
berghofe@13403:   disjE: "Null"
skalberg@14168:     "\<Lambda> P Q R pq. disjE_realizer3 \<cdot> _ \<cdot> _ \<cdot> pq \<cdot> (\<lambda>x. R) \<cdot> _ \<cdot> _"
berghofe@13403: 
haftmann@27982:   FalseE (P): "default"
skalberg@14168:     "\<Lambda> P. FalseE \<cdot> _"
berghofe@13403: 
berghofe@13725:   FalseE: "Null" "FalseE"
berghofe@13403: 
berghofe@13403:   notI (P): "Null"
skalberg@14168:     "\<Lambda> P (h: _). allI \<cdot> _ \<bullet> (\<Lambda> x. notI \<cdot> _ \<bullet> (h \<cdot> x))"
berghofe@13403: 
berghofe@13725:   notI: "Null" "notI"
berghofe@13403: 
haftmann@27982:   notE (P, R): "\<lambda>p. default"
skalberg@14168:     "\<Lambda> P R (h: _) p. notE \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403: 
berghofe@13403:   notE (P): "Null"
skalberg@14168:     "\<Lambda> P R (h: _) p. notE \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> h)"
berghofe@13403: 
haftmann@27982:   notE (R): "default"
skalberg@14168:     "\<Lambda> P R. notE \<cdot> _ \<cdot> _"
berghofe@13403: 
berghofe@13725:   notE: "Null" "notE"
berghofe@13403: 
berghofe@13725:   subst (P): "\<lambda>s t ps. ps"
skalberg@14168:     "\<Lambda> s t P (h: _) ps. subst \<cdot> s \<cdot> t \<cdot> P ps \<bullet> h"
berghofe@13403: 
berghofe@13725:   subst: "Null" "subst"
berghofe@13725: 
berghofe@13725:   iffD1 (P, Q): "fst"
skalberg@14168:     "\<Lambda> Q P pq (h: _) p.
berghofe@13403:        mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> p \<bullet> (conjunct1 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403: 
berghofe@13725:   iffD1 (P): "\<lambda>p. p"
skalberg@14168:     "\<Lambda> Q P p (h: _). mp \<cdot> _ \<cdot> _ \<bullet> (conjunct1 \<cdot> _ \<cdot> _ \<bullet> h)"
berghofe@13403: 
berghofe@13403:   iffD1 (Q): "Null"
skalberg@14168:     "\<Lambda> Q P q1 (h: _) q2.
berghofe@13403:        mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> q2 \<bullet> (conjunct1 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403: 
berghofe@13725:   iffD1: "Null" "iffD1"
berghofe@13403: 
berghofe@13725:   iffD2 (P, Q): "snd"
skalberg@14168:     "\<Lambda> P Q pq (h: _) q.
berghofe@13403:        mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> q \<bullet> (conjunct2 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403: 
berghofe@13725:   iffD2 (P): "\<lambda>p. p"
skalberg@14168:     "\<Lambda> P Q p (h: _). mp \<cdot> _ \<cdot> _ \<bullet> (conjunct2 \<cdot> _ \<cdot> _ \<bullet> h)"
berghofe@13403: 
berghofe@13403:   iffD2 (Q): "Null"
skalberg@14168:     "\<Lambda> P Q q1 (h: _) q2.
berghofe@13403:        mp \<cdot> _ \<cdot> _ \<bullet> (spec \<cdot> _ \<cdot> q2 \<bullet> (conjunct2 \<cdot> _ \<cdot> _ \<bullet> h))"
berghofe@13403: 
berghofe@13725:   iffD2: "Null" "iffD2"
berghofe@13403: 
berghofe@13725:   iffI (P, Q): "Pair"
skalberg@14168:     "\<Lambda> P Q pq (h1 : _) qp (h2 : _). conjI_realizer \<cdot>
berghofe@13725:        (\<lambda>pq. \<forall>x. P x \<longrightarrow> Q (pq x)) \<cdot> pq \<cdot>
berghofe@13725:        (\<lambda>qp. \<forall>x. Q x \<longrightarrow> P (qp x)) \<cdot> qp \<bullet>
skalberg@14168:        (allI \<cdot> _ \<bullet> (\<Lambda> x. impI \<cdot> _ \<cdot> _ \<bullet> (h1 \<cdot> x))) \<bullet>
skalberg@14168:        (allI \<cdot> _ \<bullet> (\<Lambda> x. impI \<cdot> _ \<cdot> _ \<bullet> (h2 \<cdot> x)))"
berghofe@13403: 
berghofe@13725:   iffI (P): "\<lambda>p. p"
skalberg@14168:     "\<Lambda> P Q (h1 : _) p (h2 : _). conjI \<cdot> _ \<cdot> _ \<bullet>
skalberg@14168:        (allI \<cdot> _ \<bullet> (\<Lambda> x. impI \<cdot> _ \<cdot> _ \<bullet> (h1 \<cdot> x))) \<bullet>
berghofe@13403:        (impI \<cdot> _ \<cdot> _ \<bullet> h2)"
berghofe@13403: 
berghofe@13725:   iffI (Q): "\<lambda>q. q"
skalberg@14168:     "\<Lambda> P Q q (h1 : _) (h2 : _). conjI \<cdot> _ \<cdot> _ \<bullet>
berghofe@13403:        (impI \<cdot> _ \<cdot> _ \<bullet> h1) \<bullet>
skalberg@14168:        (allI \<cdot> _ \<bullet> (\<Lambda> x. impI \<cdot> _ \<cdot> _ \<bullet> (h2 \<cdot> x)))"
berghofe@13403: 
berghofe@13725:   iffI: "Null" "iffI"
berghofe@13403: 
berghofe@13725: (*
berghofe@13403:   classical: "Null"
skalberg@14168:     "\<Lambda> P. classical \<cdot> _"
berghofe@13725: *)
berghofe@13403: 
haftmann@27982: setup {*
haftmann@27982:   Sign.add_const_constraint (@{const_name "default"}, SOME @{typ "'a::default"})
haftmann@27982: *}
haftmann@27982: 
berghofe@13403: end




