| author | haftmann | 
| Mon, 12 Jul 2010 08:58:12 +0200 | |
| changeset 37764 | 3489daf839d5 | 
| parent 37139 | e0bd5934a2fb | 
| permissions | -rw-r--r-- | 
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 1 | (* Title: HOL/Modelcheck/MuckeSyn.thy | 
| 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 2 | Author: Tobias Hamberger | 
| 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 3 | Copyright 1999 TU Muenchen | 
| 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 4 | *) | 
| 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 5 | |
| 17272 | 6 | theory MuckeSyn | 
| 7 | imports MuCalculus | |
| 8 | uses "mucke_oracle.ML" | |
| 9 | begin | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 10 | |
| 17272 | 11 | (* extended with some operators and case treatment (which requires postprocessing with | 
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 12 | transform_case (from MuCalculus) (TH) *) | 
| 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 13 | |
| 17272 | 14 | nonterminals | 
| 15 | mutype | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 16 | decl decls | 
| 17272 | 17 | cases_syn case_syn | 
| 10125 | 18 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 19 | syntax (Mucke output) | 
| 17272 | 20 |   True          :: bool                                 ("true")
 | 
| 21 |   False         :: bool                                 ("false")
 | |
| 22 |   Not           :: "bool => bool"                       ("! _" [40] 40)
 | |
| 23 |   If            :: "[bool, 'a, 'a] => 'a"       ("('(if'((_)')/ '((_)')/ else/ '((_)'))')" 10)
 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 24 | |
| 17272 | 25 | "op &" :: "[bool, bool] => bool" (infixr "&" 35) | 
| 26 | "op |" :: "[bool, bool] => bool" (infixr "|" 30) | |
| 27 | "op -->" :: "[bool, bool] => bool" (infixr "->" 25) | |
| 28 |   "op ="        :: "['a, 'a] => bool"                   ("(_ =/ _)" [51, 51] 50)
 | |
| 29 |   "_not_equal"  :: "['a, 'a] => bool"                   ("(_ !=/ _)" [51, 51] 50)
 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 30 | |
| 21524 | 31 |   All_binder    :: "[idts, bool] => bool"               ("'((3forall _./ _)')" [0, 10] 10)
 | 
| 32 |   Ex_binder     :: "[idts, bool] => bool"               ("'((3exists _./ _)')" [0, 10] 10)
 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 33 | |
| 17272 | 34 |   "_lambda"     :: "[idts, 'a] => 'b"                   ("(3L _./ _)" 10)
 | 
| 35 |   "_applC"      :: "[('b => 'a), cargs] => aprop"       ("(1_/ '(_'))" [1000,1000] 999)
 | |
| 36 |   "_cargs"      :: "['a, cargs] => cargs"               ("_,/ _" [1000,1000] 1000)
 | |
| 37 | ||
| 38 |   "_idts"       :: "[idt, idts] => idts"                ("_,/ _" [1, 0] 0)
 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 39 | |
| 9368 | 40 |   "_tuple"      :: "'a => tuple_args => 'a * 'b"        ("(1_,/ _)")
 | 
| 35109 | 41 | (* "_pttrn"     :: "[pttrn, pttrns] => pttrn"           ("_,/ _" [1, 0] 0)
 | 
| 17272 | 42 |   "_pattern"    :: "[pttrn, patterns] => pttrn"         ("_,/ _" [1, 0] 0) *)
 | 
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 43 | |
| 17272 | 44 |   "_decl"       :: "[mutype,pttrn] => decl"             ("_ _")
 | 
| 45 |   "_decls"      :: "[decl,decls] => decls"              ("_,/ _")
 | |
| 46 |   ""            :: "decl => decls"                      ("_")
 | |
| 47 |   "_mu"         :: "[decl,decls,'a pred] => 'a pred"    ("mu _ '(_') _ ;")
 | |
| 48 |   "_mudec"      :: "[decl,decls] => 'a pred"            ("mu _ '(_') ;")
 | |
| 49 |   "_nu"         :: "[decl,decls,'a pred] => 'a pred"    ("nu _ '(_') _ ;")
 | |
| 50 |   "_nudec"      :: "[decl,decls] => 'a pred"            ("nu _ '(_') ;")
 | |
| 51 |   "_fun"        :: "[decl,decls,'a pred] => 'a pred"    ("_ '(_') _ ;")
 | |
| 52 |   "_dec"        :: "[decl,decls] => 'a pred"            ("_ '(_') ;")
 | |
| 53 | ||
| 54 |   "_Ex"         :: "[decl,idts,'a pred] => 'a pred"     ("'((3exists _ _./ _)')")
 | |
| 55 |   "_All"        :: "[decl,idts,'a pred] => 'a pred"     ("'((3forall _ _./ _)')")
 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 56 | |
| 17272 | 57 |   "Mu "         :: "[idts, 'a pred] => 'a pred"         ("(3mu _./ _)" 1000)
 | 
| 58 |   "Nu "         :: "[idts, 'a pred] => 'a pred"         ("(3nu _./ _)" 1000)
 | |
| 59 | ||
| 60 |   "_case_syntax":: "['a, cases_syn] => 'b"              ("(case*_* / _ / esac*)" 10)
 | |
| 61 |   "_case1"      :: "['a, 'b] => case_syn"               ("(2*= _ :/ _;)" 10)
 | |
| 62 |   ""            :: "case_syn => cases_syn"              ("_")
 | |
| 63 |   "_case2"      :: "[case_syn, cases_syn] => cases_syn" ("_/ _")
 | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 64 | |
| 17272 | 65 | (*Terms containing a case statement must be post-processed with the | 
| 66 | ML function transform_case. There, all asterikses before the "=" | |
| 67 | will be replaced by the expression between the two asterisks | |
| 68 | following "case" and the asterisk after esac will be deleted *) | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 69 | |
| 28290 | 70 | oracle mc_mucke_oracle = mk_mc_mucke_oracle | 
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 71 | |
| 22819 | 72 | ML {*
 | 
| 73 | (* search_mu t searches for Mu terms in term t. In the case of nested Mu's, | |
| 74 | it yields innermost one. If no Mu term is present, search_mu yields NONE | |
| 75 | *) | |
| 76 | ||
| 77 | (* extended for treatment of nu (TH) *) | |
| 78 | fun search_mu ((Const("MuCalculus.mu",tp)) $ t2) = 
 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 79 | (case (search_mu t2) of | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 80 | SOME t => SOME t | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 81 |             | NONE => SOME ((Const("MuCalculus.mu",tp)) $ t2))
 | 
| 22819 | 82 |   | search_mu ((Const("MuCalculus.nu",tp)) $ t2) =
 | 
| 83 | (case (search_mu t2) of | |
| 84 | SOME t => SOME t | |
| 85 |             | NONE => SOME ((Const("MuCalculus.nu",tp)) $ t2))
 | |
| 86 | | search_mu (t1 $ t2) = | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 87 | (case (search_mu t1) of | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 88 | SOME t => SOME t | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 89 | | NONE => search_mu t2) | 
| 22819 | 90 | | search_mu (Abs(_,_,t)) = search_mu t | 
| 91 | | search_mu _ = NONE; | |
| 92 | ||
| 93 | ||
| 94 | ||
| 95 | ||
| 96 | (* seraching a variable in a term. Used in move_mus to extract the | |
| 97 | term-rep of var b in hthm *) | |
| 98 | ||
| 99 | fun search_var s t = | |
| 100 | case t of | |
| 101 | t1 $ t2 => (case (search_var s t1) of | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 102 | SOME tt => SOME tt | | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 103 | NONE => search_var s t2) | | 
| 22819 | 104 | Abs(_,_,t) => search_var s t | | 
| 105 | Var((s1,_),_) => if s = s1 then SOME t else NONE | | |
| 106 | _ => NONE; | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 107 | |
| 22819 | 108 | |
| 109 | (* function move_mus: | |
| 110 | Mucke can't deal with nested Mu terms. move_mus i searches for | |
| 111 | Mu terms in the subgoal i and replaces Mu terms in the conclusion | |
| 112 | by constants and definitions in the premises recursively. | |
| 113 | ||
| 114 | move_thm is the theorem the performs the replacement. To create NEW | |
| 115 | names for the Mu terms, the indizes of move_thm are incremented by | |
| 116 | max_idx of the subgoal. | |
| 117 | *) | |
| 118 | ||
| 119 | local | |
| 120 | ||
| 32178 | 121 |   val move_thm = OldGoals.prove_goal @{theory} "[| a = b ==> P a; a = b |] ==> P b"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 122 | (fn prems => [cut_facts_tac prems 1, dtac sym 1, hyp_subst_tac 1, | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 123 | REPEAT (resolve_tac prems 1)]); | 
| 22819 | 124 | |
| 125 | val sig_move_thm = Thm.theory_of_thm move_thm; | |
| 33035 | 126 | val bCterm = cterm_of sig_move_thm (the (search_var "b" (concl_of move_thm))); | 
| 127 | val aCterm = cterm_of sig_move_thm (the (search_var "a" (hd(prems_of move_thm)))); | |
| 22819 | 128 | |
| 129 | in | |
| 130 | ||
| 131 | fun move_mus i state = | |
| 132 | let val sign = Thm.theory_of_thm state; | |
| 33955 | 133 | val subgoal = nth (prems_of state) i; | 
| 22819 | 134 | val concl = Logic.strip_imp_concl subgoal; (* recursive mu's in prems? *) | 
| 135 | val redex = search_mu concl; | |
| 136 | val idx = let val t = #maxidx (rep_thm state) in | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 137 | if t < 0 then 1 else t+1 end; | 
| 22819 | 138 | in | 
| 139 | case redex of | |
| 140 | NONE => all_tac state | | |
| 141 | SOME redexterm => | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 142 | let val Credex = cterm_of sign redexterm; | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 143 | val aiCterm = | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 144 | cterm_of sig_move_thm (Logic.incr_indexes ([],idx) (term_of aCterm)); | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 145 | val inst_move_thm = cterm_instantiate | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 146 | [(bCterm,Credex),(aCterm,aiCterm)] move_thm; | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 147 | in | 
| 22819 | 148 | ((rtac inst_move_thm i) THEN (dtac eq_reflection i) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 149 | THEN (move_mus i)) state | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 150 | end | 
| 22819 | 151 | end; | 
| 152 | end; | |
| 6466 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 153 | |
| 
2eba94dc5951
added modelchecker mucke besides modelchecker eindhoven;
 mueller parents: diff
changeset | 154 | |
| 28290 | 155 | val call_mucke_tac = CSUBGOAL (fn (cgoal, i) => | 
| 156 | let val OraAss = mc_mucke_oracle cgoal | |
| 157 | in cut_facts_tac [OraAss] i end); | |
| 22819 | 158 | |
| 159 | ||
| 160 | (* transforming fun-defs into lambda-defs *) | |
| 161 | ||
| 32178 | 162 | val [eq] = OldGoals.goal Pure.thy "(!! x. f x == g x) ==> f == g"; | 
| 163 | OldGoals.by (rtac (extensional eq) 1); | |
| 164 | OldGoals.qed "ext_rl"; | |
| 22819 | 165 | |
| 166 | infix cc; | |
| 167 | ||
| 168 | fun NONE cc xl = xl | |
| 169 | | (SOME x) cc xl = x::xl; | |
| 170 | ||
| 171 | fun getargs ((x $ y) $ (Var ((z,_),_))) = getargs (x $ y) ^ " " ^z | |
| 172 | | getargs (x $ (Var ((y,_),_))) = y; | |
| 173 | ||
| 174 | fun getfun ((x $ y) $ z) = getfun (x $ y) | |
| 175 | | getfun (x $ _) = x; | |
| 176 | ||
| 177 | local | |
| 178 | ||
| 179 | fun delete_bold [] = [] | |
| 180 | | delete_bold (x::xs) = if (is_prefix (op =) ("\^["::"["::"0"::"m"::[]) (x::xs))
 | |
| 181 | then (let val (_::_::_::s) = xs in delete_bold s end) | |
| 182 |         else (if (is_prefix (op =) ("\^["::"["::"1"::"m"::[]) (x::xs))
 | |
| 183 | then (let val (_::_::_::s) = xs in delete_bold s end) | |
| 184 | else (x::delete_bold xs)); | |
| 185 | ||
| 186 | fun delete_bold_string s = implode(delete_bold (explode s)); | |
| 187 | ||
| 188 | in | |
| 189 | ||
| 190 | (* extension with removing bold font (TH) *) | |
| 191 | fun mk_lam_def (_::_) _ _ = NONE | |
| 192 |   | mk_lam_def [] ((Const("==",_) $ (Const _)) $ RHS) t = SOME t
 | |
| 193 |   | mk_lam_def [] ((Const("==",_) $ LHS) $ RHS) t = 
 | |
| 194 | let val thy = theory_of_thm t; | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 195 | val fnam = Syntax.string_of_term_global thy (getfun LHS); | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 196 | val rhs = Syntax.string_of_term_global thy (freeze_thaw RHS) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 197 | val gl = delete_bold_string (fnam ^" == % " ^ (getargs LHS) ^" . " ^ rhs); | 
| 22819 | 198 | in | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 199 | SOME (OldGoals.prove_goal thy gl (fn prems => | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32178diff
changeset | 200 | [(REPEAT (rtac ext_rl 1)), (rtac t 1) ])) | 
| 22819 | 201 | end | 
| 202 | | mk_lam_def [] _ t= NONE; | |
| 203 | ||
| 204 | fun mk_lam_defs ([]:thm list) = ([]: thm list) | |
| 205 | | mk_lam_defs (t::l) = | |
| 206 | (mk_lam_def (prems_of t) (concl_of t) t) cc (mk_lam_defs l); | |
| 207 | ||
| 208 | end; | |
| 209 | ||
| 210 | ||
| 211 | (* first simplification, then model checking *) | |
| 212 | ||
| 213 | val pair_eta_expand = Thm.symmetric (mk_meta_eq (thm "split_eta")); | |
| 214 | ||
| 215 | val pair_eta_expand_proc = | |
| 32010 | 216 |   Simplifier.simproc @{theory} "pair_eta_expand" ["f::'a*'b=>'c"]
 | 
| 22819 | 217 | (fn _ => fn _ => fn t => case t of Abs _ => SOME pair_eta_expand | _ => NONE); | 
| 218 | ||
| 26342 | 219 | val Mucke_ss = @{simpset} addsimprocs [pair_eta_expand_proc] addsimps [Let_def];
 | 
| 22819 | 220 | |
| 221 | ||
| 222 | (* the interface *) | |
| 223 | ||
| 224 | fun mc_mucke_tac defs i state = | |
| 33955 | 225 | (case try (nth (Thm.prems_of state)) i of | 
| 226 | NONE => no_tac state | |
| 227 | | SOME subgoal => | |
| 22819 | 228 | EVERY [ | 
| 229 | REPEAT (etac thin_rl i), | |
| 230 | cut_facts_tac (mk_lam_defs defs) i, | |
| 37139 | 231 |         full_simp_tac (Mucke_ss delsimps [not_iff, @{thm split_part}]) i,
 | 
| 22819 | 232 | move_mus i, call_mucke_tac i,atac i, | 
| 233 | REPEAT (rtac refl i)] state); | |
| 234 | *} | |
| 235 | ||
| 236 | end |