# Theory Example

Up to index of Isabelle/Cube

theory Example
imports Cube
`header {* Lambda Cube Examples *}theory Exampleimports Cubebegintext {*  Examples taken from:  H. Barendregt. Introduction to Generalised Type Systems.  J. Functional Programming.*}method_setup depth_solve = {*  Attrib.thms >> (fn thms => K (METHOD (fn facts =>    (DEPTH_SOLVE (HEADGOAL (ares_tac (facts @ thms)))))))*}method_setup depth_solve1 = {*  Attrib.thms >> (fn thms => K (METHOD (fn facts =>    (DEPTH_SOLVE_1 (HEADGOAL (ares_tac (facts @ thms)))))))*}method_setup strip_asms =  {*  Attrib.thms >> (fn thms => K (METHOD (fn facts =>    REPEAT (resolve_tac [@{thm strip_b}, @{thm strip_s}] 1 THEN    DEPTH_SOLVE_1 (ares_tac (facts @ thms) 1)))))*}subsection {* Simple types *}schematic_lemma "A:* \<turnstile> A->A : ?T"  by (depth_solve rules)schematic_lemma "A:* \<turnstile> Λ a:A. a : ?T"  by (depth_solve rules)schematic_lemma "A:* B:* b:B \<turnstile> Λ x:A. b : ?T"  by (depth_solve rules)schematic_lemma "A:* b:A \<turnstile> (Λ a:A. a)^b: ?T"  by (depth_solve rules)schematic_lemma "A:* B:* c:A b:B \<turnstile> (Λ x:A. b)^ c: ?T"  by (depth_solve rules)schematic_lemma "A:* B:* \<turnstile> Λ a:A. Λ b:B. a : ?T"  by (depth_solve rules)subsection {* Second-order types *}schematic_lemma (in L2) "\<turnstile> Λ A:*. Λ a:A. a : ?T"  by (depth_solve rules)schematic_lemma (in L2) "A:* \<turnstile> (Λ B:*.Λ b:B. b)^A : ?T"  by (depth_solve rules)schematic_lemma (in L2) "A:* b:A \<turnstile> (Λ B:*.Λ b:B. b) ^ A ^ b: ?T"  by (depth_solve rules)schematic_lemma (in L2) "\<turnstile> Λ B:*.Λ a:(Π A:*.A).a ^ ((Π A:*.A)->B) ^ a: ?T"  by (depth_solve rules)subsection {* Weakly higher-order propositional logic *}schematic_lemma (in Lomega) "\<turnstile> Λ A:*.A->A : ?T"  by (depth_solve rules)schematic_lemma (in Lomega) "B:* \<turnstile> (Λ A:*.A->A) ^ B : ?T"  by (depth_solve rules)schematic_lemma (in Lomega) "B:* b:B \<turnstile> (Λ y:B. b): ?T"  by (depth_solve rules)schematic_lemma (in Lomega) "A:* F:*->* \<turnstile> F^(F^A): ?T"  by (depth_solve rules)schematic_lemma (in Lomega) "A:* \<turnstile> Λ F:*->*.F^(F^A): ?T"  by (depth_solve rules)subsection {* LP *}schematic_lemma (in LP) "A:* \<turnstile> A -> * : ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->* a:A \<turnstile> P^a: ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->A->* a:A \<turnstile> Π a:A. P^a^a: ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->* Q:A->* \<turnstile> Π a:A. P^a -> Q^a: ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->* \<turnstile> Π a:A. P^a -> P^a: ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->* \<turnstile> Λ a:A. Λ x:P^a. x: ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->* Q:* \<turnstile> (Π a:A. P^a->Q) -> (Π a:A. P^a) -> Q : ?T"  by (depth_solve rules)schematic_lemma (in LP) "A:* P:A->* Q:* a0:A \<turnstile>        Λ x:Π a:A. P^a->Q. Λ y:Π a:A. P^a. x^a0^(y^a0): ?T"  by (depth_solve rules)subsection {* Omega-order types *}schematic_lemma (in L2) "A:* B:* \<turnstile> Π C:*.(A->B->C)->C : ?T"  by (depth_solve rules)schematic_lemma (in Lomega2) "\<turnstile> Λ A:*.Λ B:*.Π C:*.(A->B->C)->C : ?T"  by (depth_solve rules)schematic_lemma (in Lomega2) "\<turnstile> Λ A:*.Λ B:*.Λ x:A. Λ y:B. x : ?T"  by (depth_solve rules)schematic_lemma (in Lomega2) "A:* B:* \<turnstile> ?p : (A->B) -> ((B->Π P:*.P)->(A->Π P:*.P))"  apply (strip_asms rules)  apply (rule lam_ss)    apply (depth_solve1 rules)   prefer 2   apply (depth_solve1 rules)  apply (rule lam_ss)    apply (depth_solve1 rules)   prefer 2   apply (depth_solve1 rules)  apply (rule lam_ss)    apply assumption   prefer 2   apply (depth_solve1 rules)  apply (erule pi_elim)   apply assumption  apply (erule pi_elim)   apply assumption  apply assumption  donesubsection {* Second-order Predicate Logic *}schematic_lemma (in LP2) "A:* P:A->* \<turnstile> Λ a:A. P^a->(Π A:*.A) : ?T"  by (depth_solve rules)schematic_lemma (in LP2) "A:* P:A->A->* \<turnstile>    (Π a:A. Π b:A. P^a^b->P^b^a->Π P:*.P) -> Π a:A. P^a^a->Π P:*.P : ?T"  by (depth_solve rules)schematic_lemma (in LP2) "A:* P:A->A->* \<turnstile>    ?p: (Π a:A. Π b:A. P^a^b->P^b^a->Π P:*.P) -> Π a:A. P^a^a->Π P:*.P"  -- {* Antisymmetry implies irreflexivity: *}  apply (strip_asms rules)  apply (rule lam_ss)    apply (depth_solve1 rules)   prefer 2   apply (depth_solve1 rules)  apply (rule lam_ss)    apply assumption   prefer 2   apply (depth_solve1 rules)  apply (rule lam_ss)    apply (depth_solve1 rules)   prefer 2   apply (depth_solve1 rules)  apply (erule pi_elim, assumption, assumption?)+  donesubsection {* LPomega *}schematic_lemma (in LPomega) "A:* \<turnstile> Λ P:A->A->*.Λ a:A. P^a^a : ?T"  by (depth_solve rules)schematic_lemma (in LPomega) "\<turnstile> Λ A:*.Λ P:A->A->*.Λ a:A. P^a^a : ?T"  by (depth_solve rules)subsection {* Constructions *}schematic_lemma (in CC) "\<turnstile> Λ A:*.Λ P:A->*.Λ a:A. P^a->Π P:*.P: ?T"  by (depth_solve rules)schematic_lemma (in CC) "\<turnstile> Λ A:*.Λ P:A->*.Π a:A. P^a: ?T"  by (depth_solve rules)schematic_lemma (in CC) "A:* P:A->* a:A \<turnstile> ?p : (Π a:A. P^a)->P^a"  apply (strip_asms rules)  apply (rule lam_ss)    apply (depth_solve1 rules)   prefer 2   apply (depth_solve1 rules)  apply (erule pi_elim, assumption, assumption)  donesubsection {* Some random examples *}schematic_lemma (in LP2) "A:* c:A f:A->A \<turnstile>    Λ a:A. Π P:A->*.P^c -> (Π x:A. P^x->P^(f^x)) -> P^a : ?T"  by (depth_solve rules)schematic_lemma (in CC) "Λ A:*.Λ c:A. Λ f:A->A.    Λ a:A. Π P:A->*.P^c -> (Π x:A. P^x->P^(f^x)) -> P^a : ?T"  by (depth_solve rules)schematic_lemma (in LP2)  "A:* a:A b:A \<turnstile> ?p: (Π P:A->*.P^a->P^b) -> (Π P:A->*.P^b->P^a)"  -- {* Symmetry of Leibnitz equality *}  apply (strip_asms rules)  apply (rule lam_ss)    apply (depth_solve1 rules)   prefer 2   apply (depth_solve1 rules)  apply (erule_tac a = "Λ x:A. Π Q:A->*.Q^x->Q^a" in pi_elim)   apply (depth_solve1 rules)  apply (unfold beta)  apply (erule imp_elim)   apply (rule lam_bs)     apply (depth_solve1 rules)    prefer 2    apply (depth_solve1 rules)   apply (rule lam_ss)     apply (depth_solve1 rules)    prefer 2    apply (depth_solve1 rules)   apply assumption  apply assumption  doneend`