| author | wenzelm | 
| Sat, 24 May 2008 22:04:57 +0200 | |
| changeset 26990 | a91f7741967a | 
| parent 26653 | 60e0cf6bef89 | 
| child 28674 | 08a77c495dc1 | 
| permissions | -rw-r--r-- | 
| 19416 | 1 | (* Title: Pure/conjunction.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: Makarius | |
| 4 | ||
| 5 | Meta-level conjunction. | |
| 6 | *) | |
| 7 | ||
| 8 | signature CONJUNCTION = | |
| 9 | sig | |
| 10 | val conjunction: cterm | |
| 11 | val mk_conjunction: cterm * cterm -> cterm | |
| 23422 | 12 | val mk_conjunction_balanced: cterm list -> cterm | 
| 19416 | 13 | val dest_conjunction: cterm -> cterm * cterm | 
| 14 | val cong: thm -> thm -> thm | |
| 23422 | 15 | val convs: (cterm -> thm) -> cterm -> thm | 
| 19416 | 16 | val conjunctionD1: thm | 
| 17 | val conjunctionD2: thm | |
| 18 | val conjunctionI: thm | |
| 19 | val intr: thm -> thm -> thm | |
| 23422 | 20 | val intr_balanced: thm list -> thm | 
| 19416 | 21 | val elim: thm -> thm * thm | 
| 23422 | 22 | val elim_balanced: int -> thm -> thm list | 
| 23 | val curry_balanced: int -> thm -> thm | |
| 24 | val uncurry_balanced: int -> thm -> thm | |
| 19416 | 25 | end; | 
| 26 | ||
| 27 | structure Conjunction: CONJUNCTION = | |
| 28 | struct | |
| 29 | ||
| 30 | (** abstract syntax **) | |
| 31 | ||
| 26485 | 32 | fun certify t = Thm.cterm_of (Context.the_theory (Context.the_thread_data ())) t; | 
| 33 | val read_prop = certify o SimpleSyntax.read_prop; | |
| 19416 | 34 | |
| 26485 | 35 | val true_prop = certify Logic.true_prop; | 
| 36 | val conjunction = certify Logic.conjunction; | |
| 23422 | 37 | |
| 19416 | 38 | fun mk_conjunction (A, B) = Thm.capply (Thm.capply conjunction A) B; | 
| 39 | ||
| 23422 | 40 | fun mk_conjunction_balanced [] = true_prop | 
| 41 | | mk_conjunction_balanced ts = BalancedTree.make mk_conjunction ts; | |
| 42 | ||
| 19416 | 43 | fun dest_conjunction ct = | 
| 44 | (case Thm.term_of ct of | |
| 26424 | 45 |     (Const ("Pure.conjunction", _) $ _ $ _) => Thm.dest_binop ct
 | 
| 23422 | 46 |   | _ => raise TERM ("dest_conjunction", [Thm.term_of ct]));
 | 
| 19416 | 47 | |
| 48 | ||
| 49 | ||
| 50 | (** derived rules **) | |
| 51 | ||
| 52 | (* conversion *) | |
| 53 | ||
| 54 | val cong = Thm.combination o Thm.combination (Thm.reflexive conjunction); | |
| 55 | ||
| 23422 | 56 | fun convs cv ct = | 
| 57 | (case try dest_conjunction ct of | |
| 58 | NONE => cv ct | |
| 59 | | SOME (A, B) => cong (convs cv A) (convs cv B)); | |
| 19416 | 60 | |
| 61 | ||
| 62 | (* intro/elim *) | |
| 63 | ||
| 64 | local | |
| 65 | ||
| 24241 | 66 | val A = read_prop "A" and vA = read_prop "?A"; | 
| 67 | val B = read_prop "B" and vB = read_prop "?B"; | |
| 68 | val C = read_prop "C"; | |
| 69 | val ABC = read_prop "A ==> B ==> C"; | |
| 70 | val A_B = read_prop "A && B"; | |
| 19416 | 71 | |
| 26424 | 72 | val conjunction_def = | 
| 73 | Thm.unvarify (Thm.get_axiom (Context.the_theory (Context.the_thread_data ())) "conjunction_def"); | |
| 19416 | 74 | |
| 75 | fun conjunctionD which = | |
| 76 | Drule.implies_intr_list [A, B] (Thm.assume (which (A, B))) COMP | |
| 26653 | 77 | Thm.forall_elim_vars 0 (Thm.equal_elim conjunction_def (Thm.assume A_B)); | 
| 19416 | 78 | |
| 79 | in | |
| 80 | ||
| 81 | val conjunctionD1 = Drule.store_standard_thm "conjunctionD1" (conjunctionD #1); | |
| 82 | val conjunctionD2 = Drule.store_standard_thm "conjunctionD2" (conjunctionD #2); | |
| 83 | ||
| 84 | val conjunctionI = Drule.store_standard_thm "conjunctionI" | |
| 85 | (Drule.implies_intr_list [A, B] | |
| 86 | (Thm.equal_elim | |
| 87 | (Thm.symmetric conjunction_def) | |
| 88 | (Thm.forall_intr C (Thm.implies_intr ABC | |
| 89 | (Drule.implies_elim_list (Thm.assume ABC) [Thm.assume A, Thm.assume B]))))); | |
| 90 | ||
| 23422 | 91 | |
| 20508 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 92 | fun intr tha thb = | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 93 | Thm.implies_elim | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 94 | (Thm.implies_elim | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 95 | (Thm.instantiate ([], [(vA, Thm.cprop_of tha), (vB, Thm.cprop_of thb)]) conjunctionI) | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 96 | tha) | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 97 | thb; | 
| 19416 | 98 | |
| 99 | fun elim th = | |
| 20508 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 100 | let | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 101 | val (A, B) = dest_conjunction (Thm.cprop_of th) | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 102 | handle TERM (msg, _) => raise THM (msg, 0, [th]); | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 103 | val inst = Thm.instantiate ([], [(vA, A), (vB, B)]); | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 104 | in | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 105 | (Thm.implies_elim (inst conjunctionD1) th, | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 106 | Thm.implies_elim (inst conjunctionD2) th) | 
| 
8182d961c7cc
intr/elim: use constant complexity thanks to tuned Thm.instantiate/implies_elim;
 wenzelm parents: 
20260diff
changeset | 107 | end; | 
| 19416 | 108 | |
| 23422 | 109 | end; | 
| 110 | ||
| 111 | ||
| 23535 
58147e5bd070
removed obsolete mk_conjunction_list, intr/elim_list;
 wenzelm parents: 
23422diff
changeset | 112 | (* balanced conjuncts *) | 
| 23422 | 113 | |
| 114 | fun intr_balanced [] = asm_rl | |
| 115 | | intr_balanced ths = BalancedTree.make (uncurry intr) ths; | |
| 116 | ||
| 117 | fun elim_balanced 0 _ = [] | |
| 118 | | elim_balanced n th = BalancedTree.dest elim n th; | |
| 19416 | 119 | |
| 120 | ||
| 121 | (* currying *) | |
| 122 | ||
| 123 | local | |
| 124 | ||
| 26424 | 125 | fun conjs thy n = | 
| 126 | let val As = map (fn A => Thm.cterm_of thy (Free (A, propT))) (Name.invents Name.context "A" n) | |
| 23422 | 127 | in (As, mk_conjunction_balanced As) end; | 
| 19416 | 128 | |
| 24241 | 129 | val B = read_prop "B"; | 
| 19416 | 130 | |
| 131 | fun comp_rule th rule = | |
| 20260 | 132 | Thm.adjust_maxidx_thm ~1 (th COMP | 
| 26653 | 133 | (rule |> Drule.forall_intr_frees |> Thm.forall_elim_vars (Thm.maxidx_of th + 1))); | 
| 19416 | 134 | |
| 135 | in | |
| 136 | ||
| 137 | (* | |
| 138 | A1 && ... && An ==> B | |
| 139 | ----------------------- | |
| 140 | A1 ==> ... ==> An ==> B | |
| 141 | *) | |
| 23422 | 142 | fun curry_balanced n th = | 
| 143 | if n < 2 then th | |
| 144 | else | |
| 145 | let | |
| 26424 | 146 | val thy = Thm.theory_of_thm th; | 
| 147 | val (As, C) = conjs thy n; | |
| 23422 | 148 | val D = Drule.mk_implies (C, B); | 
| 149 | in | |
| 150 | comp_rule th | |
| 151 | (Thm.implies_elim (Thm.assume D) (intr_balanced (map Thm.assume As)) | |
| 152 | |> Drule.implies_intr_list (D :: As)) | |
| 153 | end; | |
| 19416 | 154 | |
| 155 | (* | |
| 156 | A1 ==> ... ==> An ==> B | |
| 157 | ----------------------- | |
| 23422 | 158 | A1 && ... && An ==> B | 
| 19416 | 159 | *) | 
| 23422 | 160 | fun uncurry_balanced n th = | 
| 161 | if n < 2 then th | |
| 162 | else | |
| 163 | let | |
| 26424 | 164 | val thy = Thm.theory_of_thm th; | 
| 165 | val (As, C) = conjs thy n; | |
| 23422 | 166 | val D = Drule.list_implies (As, B); | 
| 167 | in | |
| 168 | comp_rule th | |
| 169 | (Drule.implies_elim_list (Thm.assume D) (elim_balanced n (Thm.assume C)) | |
| 170 | |> Drule.implies_intr_list [D, C]) | |
| 171 | end; | |
| 19416 | 172 | |
| 173 | end; | |
| 174 | ||
| 175 | end; |