src/HOL/Statespace/state_fun.ML
author Norbert Schirmer <norbert.schirmer@web.de>
Thu, 18 Dec 2008 11:16:48 +0100
changeset 29247 95d3a82857e5
parent 29064 70a61d58460e
child 29302 eb782d1dc07c
permissions -rw-r--r--
adapted statespace module to new locales;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28308
d4396a28fb29 fixed headers
haftmann
parents: 27330
diff changeset
     1
(*  Title:      HOL/Statespace/state_fun.ML
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
     2
    ID:         $Id$
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
     3
    Author:     Norbert Schirmer, TU Muenchen
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
     4
*)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
     5
25408
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
     6
signature STATE_FUN =
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
     7
sig
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
     8
  val lookupN : string
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
     9
  val updateN : string
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    10
25408
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    11
  val mk_constr : Context.theory -> Term.typ -> Term.term
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    12
  val mk_destr : Context.theory -> Term.typ -> Term.term
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    13
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    14
  val lookup_simproc : MetaSimplifier.simproc
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    15
  val update_simproc : MetaSimplifier.simproc
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    16
  val ex_lookup_eq_simproc : MetaSimplifier.simproc
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    17
  val ex_lookup_ss : MetaSimplifier.simpset
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    18
  val lazy_conj_simproc : MetaSimplifier.simproc
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    19
  val string_eq_simp_tac : int -> Tactical.tactic
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    20
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    21
  val setup : Context.theory -> Context.theory
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    22
end;
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    23
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    24
structure StateFun: STATE_FUN = 
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    25
struct
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    26
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    27
val lookupN = "StateFun.lookup";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    28
val updateN = "StateFun.update";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    29
25408
156f6f7082b8 added signatures;
schirmer
parents: 25171
diff changeset
    30
val sel_name = HOLogic.dest_string;
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    31
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    32
fun mk_name i t =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    33
  (case try sel_name t of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    34
     SOME name => name
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    35
   | NONE => (case t of 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    36
               Free (x,_) => x
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    37
              |Const (x,_) => x
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    38
              |_ => "x"^string_of_int i))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    39
               
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    40
local
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    41
val conj1_False = thm "conj1_False";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    42
val conj2_False = thm "conj2_False";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    43
val conj_True = thm "conj_True";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    44
val conj_cong = thm "conj_cong";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    45
fun isFalse (Const ("False",_)) = true
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    46
  | isFalse _ = false;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    47
fun isTrue (Const ("True",_)) = true
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    48
  | isTrue _ = false;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    49
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    50
in
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    51
val lazy_conj_simproc =
29064
70a61d58460e more antiquotations;
wenzelm
parents: 28308
diff changeset
    52
  Simplifier.simproc @{theory HOL} "lazy_conj_simp" ["P & Q"]
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    53
    (fn thy => fn ss => fn t =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    54
      (case t of (Const ("op &",_)$P$Q) => 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    55
         let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    56
            val P_P' = Simplifier.rewrite ss (cterm_of thy P);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    57
            val P' = P_P' |> prop_of |> Logic.dest_equals |> #2 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    58
         in if isFalse P'
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    59
            then SOME (conj1_False OF [P_P'])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    60
            else 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    61
              let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    62
                val Q_Q' = Simplifier.rewrite ss (cterm_of thy Q);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    63
                val Q' = Q_Q' |> prop_of |> Logic.dest_equals |> #2 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    64
              in if isFalse Q'
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    65
                 then SOME (conj2_False OF [Q_Q'])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    66
                 else if isTrue P' andalso isTrue Q'
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    67
                      then SOME (conj_True OF [P_P', Q_Q'])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    68
                      else if P aconv P' andalso Q aconv Q' then NONE
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    69
                           else SOME (conj_cong OF [P_P', Q_Q'])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    70
              end 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    71
         end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    72
        
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    73
      | _ => NONE));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    74
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    75
val string_eq_simp_tac =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    76
     simp_tac (HOL_basic_ss 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    77
                 addsimps (thms "list.inject"@thms "char.inject"@simp_thms)
27099
2a91d9575935 DatatypePackage.distinct_simproc;
wenzelm
parents: 26496
diff changeset
    78
                 addsimprocs [DatatypePackage.distinct_simproc,lazy_conj_simproc]
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    79
                 addcongs [thm "block_conj_cong"])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    80
end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    81
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    82
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    83
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    84
local
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    85
val rules = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    86
 [thm "StateFun.lookup_update_id_same",
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    87
  thm "StateFun.id_id_cancel",
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    88
  thm "StateFun.lookup_update_same",thm "StateFun.lookup_update_other"
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    89
  ]
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    90
in
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    91
val lookup_ss = (HOL_basic_ss 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    92
                 addsimps (thms "list.inject"@thms "char.inject"@simp_thms@rules)
27099
2a91d9575935 DatatypePackage.distinct_simproc;
wenzelm
parents: 26496
diff changeset
    93
                 addsimprocs [DatatypePackage.distinct_simproc,lazy_conj_simproc]
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    94
                 addcongs [thm "block_conj_cong"]
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    95
                 addSolver StateSpace.distinctNameSolver) 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    96
end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    97
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    98
val ex_lookup_ss = HOL_ss addsimps [thm "StateFun.ex_id"];
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
    99
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   100
structure StateFunArgs =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   101
struct
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   102
  type T = (simpset * simpset * bool); 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   103
           (* lookup simpset, ex_lookup simpset, are simprocs installed *)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   104
  val empty = (empty_ss, empty_ss, false);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   105
  val extend = I;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   106
  fun merge pp ((ss1,ex_ss1,b1),(ss2,ex_ss2,b2)) = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   107
               (merge_ss (ss1,ss2)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   108
               ,merge_ss (ex_ss1,ex_ss2)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   109
               ,b1 orelse b2);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   110
end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   111
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   112
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   113
structure StateFunData = GenericDataFun(StateFunArgs);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   114
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   115
val init_state_fun_data =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   116
  Context.theory_map (StateFunData.put (lookup_ss,ex_lookup_ss,false));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   117
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   118
val lookup_simproc =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   119
  Simplifier.simproc (the_context ()) "lookup_simp" ["lookup d n (update d' c m v s)"]
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   120
    (fn thy => fn ss => fn t =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   121
      (case t of (Const ("StateFun.lookup",lT)$destr$n$
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   122
                   (s as Const ("StateFun.update",uT)$_$_$_$_$_)) =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   123
        (let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   124
          val (_::_::_::_::sT::_) = binder_types uT;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   125
          val mi = maxidx_of_term t;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   126
          fun mk_upds (Const ("StateFun.update",uT)$d'$c$m$v$s) =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   127
               let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   128
                 val (_::_::_::fT::_::_) = binder_types uT;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   129
                 val vT = domain_type fT;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   130
                 val (s',cnt) = mk_upds s;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   131
                 val (v',cnt') = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   132
                      (case v of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   133
                        Const ("StateFun.K_statefun",KT)$v''
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   134
                         => (case v'' of 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   135
                             (Const ("StateFun.lookup",_)$(d as (Const ("Fun.id",_)))$n'$_)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   136
                              => if d aconv c andalso n aconv m andalso m aconv n' 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   137
                                 then (v,cnt) (* Keep value so that 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   138
                                                 lookup_update_id_same can fire *)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   139
                                 else (Const ("StateFun.K_statefun",KT)$Var (("v",cnt),vT),
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   140
                                       cnt+1)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   141
                              | _ => (Const ("StateFun.K_statefun",KT)$Var (("v",cnt),vT),
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   142
                                       cnt+1))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   143
                       | _ => (v,cnt));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   144
               in (Const ("StateFun.update",uT)$d'$c$m$v'$s',cnt')
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   145
               end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   146
            | mk_upds s = (Var (("s",mi+1),sT),mi+2);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   147
          
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   148
          val ct = cterm_of thy 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   149
                    (Const ("StateFun.lookup",lT)$destr$n$(fst (mk_upds s)));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   150
          val ctxt = the (#context (#1 (rep_ss ss)));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   151
          val basic_ss = #1 (StateFunData.get (Context.Proof ctxt));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   152
          val ss' = Simplifier.context 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   153
                     (Config.map MetaSimplifier.simp_depth_limit (K 100) ctxt) basic_ss;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   154
          val thm = Simplifier.rewrite ss' ct;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   155
        in if (op aconv) (Logic.dest_equals (prop_of thm))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   156
           then NONE
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   157
           else SOME thm
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   158
        end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   159
        handle Option => NONE)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   160
         
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   161
      | _ => NONE ));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   162
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   163
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   164
fun foldl1 f (x::xs) = foldl f x xs;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   165
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   166
local
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   167
val update_apply = thm "StateFun.update_apply";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   168
val meta_ext = thm "StateFun.meta_ext";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   169
val o_apply = thm "Fun.o_apply";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   170
val ss' = (HOL_ss addsimps (update_apply::o_apply::thms "list.inject"@thms "char.inject")
27099
2a91d9575935 DatatypePackage.distinct_simproc;
wenzelm
parents: 26496
diff changeset
   171
                 addsimprocs [DatatypePackage.distinct_simproc,lazy_conj_simproc,StateSpace.distinct_simproc]
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   172
                 addcongs [thm "block_conj_cong"]);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   173
in
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   174
val update_simproc =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   175
  Simplifier.simproc (the_context ()) "update_simp" ["update d c n v s"]
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   176
    (fn thy => fn ss => fn t =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   177
      (case t of ((upd as Const ("StateFun.update", uT)) $ d $ c $ n $ v $ s) =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   178
         let 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   179
            
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   180
             val (_::_::_::_::sT::_) = binder_types uT;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   181
                (*"('v => 'a1) => ('a2 => 'v) => 'n => ('a1 => 'a2) => ('n => 'v) => ('n => 'v)"*)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   182
             fun init_seed s = (Bound 0,Bound 0, [("s",sT)],[], false);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   183
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   184
             fun mk_comp f fT g gT =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   185
               let val T = (domain_type fT --> range_type gT) 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   186
               in (Const ("Fun.comp",gT --> fT --> T)$g$f,T) end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   187
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   188
             fun mk_comps fs = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   189
                   foldl1 (fn ((f,fT),(g,gT)) => mk_comp f fT g gT) fs;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   190
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   191
             fun append n c cT f fT d dT comps =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   192
               (case AList.lookup (op aconv) comps n of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   193
                  SOME gTs => AList.update (op aconv) 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   194
                                    (n,[(c,cT),(f,fT),(d,dT)]@gTs) comps
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   195
                | NONE => AList.update (op aconv) (n,[(c,cT),(f,fT),(d,dT)]) comps)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   196
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   197
             fun split_list (x::xs) = let val (xs',y) = split_last xs in (x,xs',y) end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   198
               | split_list _ = error "StateFun.split_list";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   199
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   200
             fun merge_upds n comps =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   201
               let val ((c,cT),fs,(d,dT)) = split_list (the (AList.lookup (op aconv) comps n))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   202
               in ((c,cT),fst (mk_comps fs),(d,dT)) end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   203
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   204
             (* mk_updterm returns 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   205
              *  - (orig-term-skeleton,simplified-term-skeleton, vars, b)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   206
              *     where boolean b tells if a simplification has occured.
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   207
                    "orig-term-skeleton = simplified-term-skeleton" is
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   208
              *     the desired simplification rule.
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   209
              * The algorithm first walks down the updates to the seed-state while
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   210
              * memorising the updates in the already-table. While walking up the
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   211
              * updates again, the optimised term is constructed.
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   212
              *)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   213
             fun mk_updterm already
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   214
                 (t as ((upd as Const ("StateFun.update", uT)) $ d $ c $ n $ v $ s)) =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   215
                      let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   216
                         fun rest already = mk_updterm already;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   217
                         val (dT::cT::nT::vT::sT::_) = binder_types uT;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   218
                          (*"('v => 'a1) => ('a2 => 'v) => 'n => ('a1 => 'a2) => 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   219
                                ('n => 'v) => ('n => 'v)"*)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   220
                      in if member (op aconv) already n
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   221
                         then (case rest already s of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   222
                                 (trm,trm',vars,comps,_) =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   223
                                   let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   224
                                     val i = length vars;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   225
                                     val kv = (mk_name i n,vT);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   226
                                     val kb = Bound i;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   227
                                     val comps' = append n c cT kb vT d dT comps;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   228
                                   in (upd$d$c$n$kb$trm, trm', kv::vars,comps',true) end)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   229
                         else
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   230
                          (case rest (n::already) s of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   231
                             (trm,trm',vars,comps,b) =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   232
                                let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   233
                                   val i = length vars;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   234
                                   val kv = (mk_name i n,vT);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   235
                                   val kb = Bound i;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   236
                                   val comps' = append n c cT kb vT d dT comps;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   237
                                   val ((c',c'T),f',(d',d'T)) = merge_upds n comps';
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   238
                                   val vT' = range_type d'T --> domain_type c'T;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   239
                                   val upd' = Const ("StateFun.update",d'T --> c'T --> nT --> vT' --> sT --> sT);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   240
                                in (upd$d$c$n$kb$trm, upd'$d'$c'$n$f'$trm', kv::vars,comps',b) 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   241
                                end)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   242
                      end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   243
               | mk_updterm _ t = init_seed t;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   244
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   245
	     val ctxt = the (#context (#1 (rep_ss ss))) |>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   246
                        Config.map MetaSimplifier.simp_depth_limit (K 100);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   247
             val ss1 = Simplifier.context ctxt ss';
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   248
             val ss2 = Simplifier.context ctxt 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   249
                         (#1 (StateFunData.get (Context.Proof ctxt)));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   250
         in (case mk_updterm [] t of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   251
               (trm,trm',vars,_,true)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   252
                => let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   253
                     val eq1 = Goal.prove ctxt [] [] 
27330
1af2598b5f7d Logic.all/mk_equals/mk_implies;
wenzelm
parents: 27099
diff changeset
   254
                                      (list_all (vars, Logic.mk_equals (trm, trm')))
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   255
                                      (fn _ => rtac meta_ext 1 THEN 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   256
                                               simp_tac ss1 1);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   257
                     val eq2 = Simplifier.asm_full_rewrite ss2 (Thm.dest_equals_rhs (cprop_of eq1));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   258
                   in SOME (transitive eq1 eq2) end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   259
             | _ => NONE)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   260
         end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   261
       | _ => NONE));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   262
end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   263
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   264
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   265
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   266
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   267
local
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   268
val swap_ex_eq = thm "StateFun.swap_ex_eq";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   269
fun is_selector thy T sel =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   270
     let 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   271
       val (flds,more) = RecordPackage.get_recT_fields thy T 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   272
     in member (fn (s,(n,_)) => n=s) (more::flds) sel
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   273
     end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   274
in
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   275
val ex_lookup_eq_simproc =
29064
70a61d58460e more antiquotations;
wenzelm
parents: 28308
diff changeset
   276
  Simplifier.simproc @{theory HOL} "ex_lookup_eq_simproc" ["Ex t"]
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   277
    (fn thy => fn ss => fn t =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   278
       let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   279
         val ctxt = Simplifier.the_context ss |>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   280
                    Config.map MetaSimplifier.simp_depth_limit (K 100)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   281
         val ex_lookup_ss = #2 (StateFunData.get (Context.Proof ctxt));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   282
         val ss' = (Simplifier.context ctxt ex_lookup_ss);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   283
         fun prove prop =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   284
           Goal.prove_global thy [] [] prop 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   285
             (fn _ => record_split_simp_tac [] (K ~1) 1 THEN
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   286
                      simp_tac ss' 1);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   287
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   288
         fun mkeq (swap,Teq,lT,lo,d,n,x,s) i =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   289
               let val (_::nT::_) = binder_types lT;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   290
                         (*  ('v => 'a) => 'n => ('n => 'v) => 'a *)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   291
                   val x' = if not (loose_bvar1 (x,0))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   292
			    then Bound 1
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   293
                            else raise TERM ("",[x]);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   294
                   val n' = if not (loose_bvar1 (n,0))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   295
			    then Bound 2
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   296
                            else raise TERM ("",[n]);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   297
                   val sel' = lo $ d $ n' $ s;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   298
                  in (Const ("op =",Teq)$sel'$x',hd (binder_types Teq),nT,swap) end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   299
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   300
         fun dest_state (s as Bound 0) = s
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   301
           | dest_state (s as (Const (sel,sT)$Bound 0)) =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   302
               if is_selector thy (domain_type sT) sel
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   303
               then s
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   304
               else raise TERM ("StateFun.ex_lookup_eq_simproc: not a record slector",[s])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   305
           | dest_state s = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   306
                    raise TERM ("StateFun.ex_lookup_eq_simproc: not a record slector",[s]);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   307
  
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   308
         fun dest_sel_eq (Const ("op =",Teq)$
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   309
                           ((lo as (Const ("StateFun.lookup",lT)))$d$n$s)$X) =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   310
                           (false,Teq,lT,lo,d,n,X,dest_state s)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   311
           | dest_sel_eq (Const ("op =",Teq)$X$
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   312
                            ((lo as (Const ("StateFun.lookup",lT)))$d$n$s)) =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   313
                           (true,Teq,lT,lo,d,n,X,dest_state s)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   314
           | dest_sel_eq _ = raise TERM ("",[]);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   315
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   316
       in
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   317
         (case t of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   318
           (Const ("Ex",Tex)$Abs(s,T,t)) =>
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   319
             (let val (eq,eT,nT,swap) = mkeq (dest_sel_eq t) 0;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   320
                  val prop = list_all ([("n",nT),("x",eT)],
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   321
                              Logic.mk_equals (Const ("Ex",Tex)$Abs(s,T,eq),
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   322
                                               HOLogic.true_const));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   323
                  val thm = standard (prove prop);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   324
                  val thm' = if swap then swap_ex_eq OF [thm] else thm
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   325
             in SOME thm' end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   326
             handle TERM _ => NONE)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   327
          | _ => NONE)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   328
        end handle Option => NONE) 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   329
end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   330
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   331
val val_sfx = "V";
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   332
val val_prfx = "StateFun."
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   333
fun deco base_prfx s = val_prfx ^ (base_prfx ^ suffix val_sfx s);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   334
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   335
fun mkUpper str = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   336
  (case String.explode str of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   337
    [] => ""
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   338
   | c::cs => String.implode (Char.toUpper c::cs ))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   339
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   340
fun mkName (Type (T,args)) = concat (map mkName args) ^ mkUpper (NameSpace.base T)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   341
  | mkName (TFree (x,_)) = mkUpper (NameSpace.base x)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   342
  | mkName (TVar ((x,_),_)) = mkUpper (NameSpace.base x);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   343
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   344
fun is_datatype thy n = is_some (Symtab.lookup (DatatypePackage.get_datatypes thy) n);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   345
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   346
fun mk_map ("List.list") = Syntax.const "List.map"
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   347
  | mk_map n = Syntax.const ("StateFun." ^  "map_" ^ NameSpace.base n);
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   348
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   349
fun gen_constr_destr comp prfx thy (Type (T,[])) = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   350
      Syntax.const (deco prfx (mkUpper (NameSpace.base T)))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   351
  | gen_constr_destr comp prfx thy (T as Type ("fun",_)) =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   352
     let val (argTs,rangeT) = strip_type T;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   353
     in comp 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   354
          (Syntax.const (deco prfx (concat (map mkName argTs) ^ "Fun")))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   355
          (fold (fn x => fn y => x$y)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   356
               (replicate (length argTs) (Syntax.const "StateFun.map_fun"))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   357
               (gen_constr_destr comp prfx thy rangeT))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   358
     end
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   359
  | gen_constr_destr comp prfx thy (T' as Type (T,argTs)) = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   360
     if is_datatype thy T
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   361
     then (* datatype args are recursively embedded into val *)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   362
         (case argTs of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   363
           [argT] => comp 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   364
                     ((Syntax.const (deco prfx (mkUpper (NameSpace.base T)))))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   365
                     ((mk_map T $ gen_constr_destr comp prfx thy argT))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   366
          | _ => raise (TYPE ("StateFun.gen_constr_destr",[T'],[])))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   367
     else (* type args are not recursively embedded into val *)
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   368
           Syntax.const (deco prfx (concat (map mkName argTs) ^ mkUpper (NameSpace.base T)))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   369
  | gen_constr_destr thy _ _ T = raise (TYPE ("StateFun.gen_constr_destr",[T],[]));
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   370
                   
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   371
val mk_constr = gen_constr_destr (fn a => fn b => Syntax.const "Fun.comp" $ a $ b) ""
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   372
val mk_destr =  gen_constr_destr (fn a => fn b => Syntax.const "Fun.comp" $ b $ a) "the_"
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   373
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   374
  
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   375
fun statefun_simp_attr src (ctxt,thm) = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   376
  let
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   377
     val (lookup_ss,ex_lookup_ss,simprocs_active) = StateFunData.get ctxt;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   378
     val (lookup_ss', ex_lookup_ss') = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   379
	   (case (concl_of thm) of
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   380
            (_$((Const ("Ex",_)$_))) => (lookup_ss, ex_lookup_ss addsimps [thm])
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   381
            | _ => (lookup_ss addsimps [thm], ex_lookup_ss))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   382
     fun activate_simprocs ctxt =
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   383
          if simprocs_active then ctxt
26496
49ae9456eba9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 25408
diff changeset
   384
          else Simplifier.map_ss (fn ss => ss addsimprocs [lookup_simproc,update_simproc]) ctxt
25171
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   385
               
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   386
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   387
     val ctxt' = ctxt 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   388
         |> activate_simprocs
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   389
         |> (StateFunData.put (lookup_ss',ex_lookup_ss',true))
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   390
  in (ctxt', thm) end;
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   391
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   392
val setup = 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   393
    init_state_fun_data 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   394
    #> Attrib.add_attributes 
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   395
	  [("statefun_simp",statefun_simp_attr,"simplification in statespaces")]     
4a9c25bffc9b added Statespace library
schirmer
parents:
diff changeset
   396
end