src/Tools/more_conv.ML
changeset 32843 c8f5a7c8353f
parent 32821 99843bbfaeb2
equal deleted inserted replaced
32842:98702c579ad0 32843:c8f5a7c8353f
     1 (* Title:  Tools/more_conv.ML
     1 (*  Title:       Tools/more_conv.ML
     2    Author: Sascha Boehme
     2     Author:      Sascha Boehme, TU Muenchen
     3 
     3 
     4 Further conversions and conversionals.
     4 Further conversions and conversionals.
     5 *)
     5 *)
     6 
     6 
     7 signature MORE_CONV =
     7 signature MORE_CONV =
    12   val bottom_conv: (Proof.context -> conv) -> Proof.context -> conv
    12   val bottom_conv: (Proof.context -> conv) -> Proof.context -> conv
    13   val top_conv: (Proof.context -> conv) -> Proof.context -> conv
    13   val top_conv: (Proof.context -> conv) -> Proof.context -> conv
    14   val top_sweep_conv: (Proof.context -> conv) -> Proof.context -> conv
    14   val top_sweep_conv: (Proof.context -> conv) -> Proof.context -> conv
    15 
    15 
    16   val binder_conv: (Proof.context -> conv) -> Proof.context -> conv
    16   val binder_conv: (Proof.context -> conv) -> Proof.context -> conv
    17 
       
    18   val cache_conv: conv -> conv
       
    19 end
    17 end
    20 
       
    21 
       
    22 
    18 
    23 structure More_Conv : MORE_CONV =
    19 structure More_Conv : MORE_CONV =
    24 struct
    20 struct
    25 
       
    26 
    21 
    27 fun rewrs_conv eqs = Conv.first_conv (map Conv.rewr_conv eqs)
    22 fun rewrs_conv eqs = Conv.first_conv (map Conv.rewr_conv eqs)
    28 
    23 
    29 
    24 
    30 fun sub_conv conv ctxt =
    25 fun sub_conv conv ctxt =
    43 
    38 
    44 
    39 
    45 fun binder_conv cv ctxt =
    40 fun binder_conv cv ctxt =
    46   Conv.arg_conv (Conv.abs_conv (fn (_, cx) => cv cx) ctxt)
    41   Conv.arg_conv (Conv.abs_conv (fn (_, cx) => cv cx) ctxt)
    47 
    42 
    48 
       
    49 fun cache_conv conv =
       
    50   let
       
    51     val cache = Synchronized.var "cache_conv" Termtab.empty
       
    52     fun lookup t =
       
    53       Synchronized.change_result cache (fn tab => (Termtab.lookup tab t, tab))
       
    54     val keep = Synchronized.change cache o Termtab.insert Thm.eq_thm
       
    55     fun keep_result t thm = (keep (t, thm); thm)
       
    56 
       
    57     fun cconv ct =
       
    58       (case lookup (Thm.term_of ct) of
       
    59         SOME thm => thm
       
    60       | NONE => keep_result (Thm.term_of ct) (conv ct))
       
    61   in cconv end
       
    62 
       
    63 end
    43 end