progtut/Tactical.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 13 Sep 2014 04:39:07 +0100
changeset 26 1cde7bf45858
parent 25 a5f5b9336007
permissions -rw-r--r--
deleted *~ files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     1
theory Tactical
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     2
imports Advanced
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     3
begin
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     4
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     5
ML {*
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     6
fun my_print_tac ctxt thm =
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     7
let
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     8
   val _ = tracing (Pretty.string_of (pretty_thm_no_vars ctxt thm))
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
     9
in
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    10
   Seq.single thm
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    11
end
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    12
*}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    13
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    14
ML {*
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    15
let
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    16
   val ctxt = @{context}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    17
   val goal = @{prop "P \<or> Q \<Longrightarrow> Q \<or> P"}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    18
in
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    19
   Goal.prove ctxt ["x", "y", "u", "v", "P", "Q"] [@{prop "x = y"}, @{prop "u = v"}] goal
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    20
    (fn {prems = pms, context = ctxt} =>  
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    21
              (my_print_tac ctxt)
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    22
              THEN etac @{thm disjE} 1 THEN
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    23
               (my_print_tac ctxt) 
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    24
              THEN rtac @{thm disjI2} 1
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    25
              THEN  (my_print_tac ctxt) 
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    26
              THEN atac 1
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    27
              THEN rtac @{thm disjI1} 1
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    28
              THEN atac 1)
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    29
end
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    30
*}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    31
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    32
ML {*
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    33
  Goal.prove
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    34
*}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    35
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    36
ML {*
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    37
fun pretty_cterms ctxt ctrms =
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    38
  Pretty.block (Pretty.commas (map (pretty_cterm ctxt) ctrms))
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    39
*}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    40
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    41
ML {*
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    42
fun foc_tac {prems, params, asms, concl, context, schematics} =
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    43
let
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    44
  fun assgn1 f1 f2 xs =
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    45
    let
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    46
       val out = map (fn (x, y) => Pretty.enum ":=" "" "" [f1 x, f2 y]) xs
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    47
    in
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    48
       Pretty.list "" "" out
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    49
    end
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    50
  fun assgn2 f xs = assgn1 f f xs
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    51
  val pps = map (fn (s, pp) => Pretty.block [Pretty.str s, pp])
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    52
    [("params: ", assgn1 Pretty.str (pretty_cterm context) params),
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    53
     ("assumptions: ", pretty_cterms context asms),
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    54
     ("conclusion: ", pretty_cterm context concl),
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    55
     ("premises: ", pretty_thms_no_vars context prems),
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    56
     ("schematics: ", assgn2 (pretty_cterm context) (snd schematics))]
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    57
in
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    58
  tracing (Pretty.string_of (Pretty.chunks pps)); all_tac
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    59
end
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    60
*}
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    61
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    62
notation (output) "prop"   ("#_" [1000] 1000)
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    63
a5f5b9336007 thys2 added
Xingyuan Zhang <xingyuanzhang@126.com>
parents:
diff changeset
    64
end