src/Pure/Isar/auto_bind.ML
author wenzelm
Fri Oct 01 20:37:38 1999 +0200 (1999-10-01 ago)
changeset 7675 c859160e78b0
parent 7599 40b7f7f51208
child 8227 d67db92897df
permissions -rw-r--r--
added atomic_thesis;
wenzelm@6783
     1
(*  Title:      Pure/Isar/auto_bind.ML
wenzelm@6783
     2
    ID:         $Id$
wenzelm@6783
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@6783
     4
wenzelm@6783
     5
Automatic term bindings -- logic specific patterns.
wenzelm@7675
     6
wenzelm@7675
     7
The implementation below works fine with the more common
wenzelm@7675
     8
object-logics, such as HOL, ZF.
wenzelm@6783
     9
*)
wenzelm@6783
    10
wenzelm@6783
    11
signature AUTO_BIND =
wenzelm@6783
    12
sig
wenzelm@7599
    13
  val goal: term -> (indexname * term option) list
wenzelm@7599
    14
  val facts: string -> term list -> (indexname * term option) list
wenzelm@7675
    15
  val atomic_thesis: term -> (string * term) * term
wenzelm@6783
    16
end;
wenzelm@6783
    17
wenzelm@6783
    18
structure AutoBind: AUTO_BIND =
wenzelm@6783
    19
struct
wenzelm@6783
    20
wenzelm@7675
    21
val thesisN = "thesis";
wenzelm@7675
    22
val thisN = "this";
wenzelm@6796
    23
wenzelm@7675
    24
wenzelm@7675
    25
(* goal *)
wenzelm@6783
    26
wenzelm@6796
    27
fun statement_binds (name, prop) =
wenzelm@6796
    28
  let
wenzelm@7331
    29
    val concl = Logic.strip_assums_concl prop;
wenzelm@7331
    30
    val parms = Logic.strip_params prop;
wenzelm@7331
    31
    fun list_abs tm = foldr (fn ((x, T), t) => Abs (x, T, t)) (parms, tm);
wenzelm@7331
    32
wenzelm@7599
    33
    val env = [(name ^ "_prop", Some prop), (name ^ "_concl", Some (list_abs concl)),
wenzelm@7599
    34
      (name, case concl of Const ("Trueprop", _) $ t => Some (list_abs t) | _ => None)];
wenzelm@7474
    35
  in map (fn (s, t) => ((s, 0), t)) env end;
wenzelm@6783
    36
wenzelm@7675
    37
fun goal prop = statement_binds (thesisN, prop);
wenzelm@6783
    38
wenzelm@6783
    39
wenzelm@6796
    40
(* facts *)
wenzelm@6796
    41
wenzelm@6796
    42
fun dddot_bind prop =
wenzelm@7599
    43
  [(Syntax.dddot_indexname,
wenzelm@7599
    44
      case Logic.strip_imp_concl prop of Const ("Trueprop", _) $ (_ $ t) => Some t | _ => None)];
wenzelm@6796
    45
wenzelm@6796
    46
fun facts _ [] = []
wenzelm@7452
    47
  | facts name props =
wenzelm@7452
    48
      let val prop = Library.last_elem props
wenzelm@7675
    49
      in dddot_bind prop @ statement_binds (thisN, prop) end;
wenzelm@7675
    50
wenzelm@7675
    51
wenzelm@7675
    52
(* atomic_thesis *)
wenzelm@7675
    53
wenzelm@7675
    54
fun mk_free t = Free (thesisN, Term.fastype_of t);
wenzelm@7675
    55
wenzelm@7675
    56
fun atomic_thesis ((c as Const ("Trueprop", _)) $ t) = ((thesisN, t), c $ mk_free t)
wenzelm@7675
    57
  | atomic_thesis t = ((thesisN, t), mk_free t);
wenzelm@6796
    58
      
wenzelm@6796
    59
wenzelm@6783
    60
end;