src/HOL/Statespace/state_fun.ML
changeset 59582 0fbed69ff081
parent 58825 2065f49da190
child 59621 291934bac95e
equal deleted inserted replaced
59580:cbc38731d42f 59582:0fbed69ff081
    54   Simplifier.simproc_global @{theory HOL} "lazy_conj_simp" ["P & Q"]
    54   Simplifier.simproc_global @{theory HOL} "lazy_conj_simp" ["P & Q"]
    55     (fn ctxt => fn t =>
    55     (fn ctxt => fn t =>
    56       let val thy = Proof_Context.theory_of ctxt in
    56       let val thy = Proof_Context.theory_of ctxt in
    57         (case t of (Const (@{const_name HOL.conj},_) $ P $ Q) =>
    57         (case t of (Const (@{const_name HOL.conj},_) $ P $ Q) =>
    58           let
    58           let
    59             val P_P' = Simplifier.rewrite ctxt (cterm_of thy P);
    59             val P_P' = Simplifier.rewrite ctxt (Thm.cterm_of thy P);
    60             val P' = P_P' |> prop_of |> Logic.dest_equals |> #2;
    60             val P' = P_P' |> Thm.prop_of |> Logic.dest_equals |> #2;
    61           in
    61           in
    62             if isFalse P' then SOME (conj1_False OF [P_P'])
    62             if isFalse P' then SOME (conj1_False OF [P_P'])
    63             else
    63             else
    64               let
    64               let
    65                 val Q_Q' = Simplifier.rewrite ctxt (cterm_of thy Q);
    65                 val Q_Q' = Simplifier.rewrite ctxt (Thm.cterm_of thy Q);
    66                 val Q' = Q_Q' |> prop_of |> Logic.dest_equals |> #2;
    66                 val Q' = Q_Q' |> Thm.prop_of |> Logic.dest_equals |> #2;
    67               in
    67               in
    68                 if isFalse Q' then SOME (conj2_False OF [Q_Q'])
    68                 if isFalse Q' then SOME (conj2_False OF [Q_Q'])
    69                 else if isTrue P' andalso isTrue Q' then SOME (conj_True OF [P_P', Q_Q'])
    69                 else if isTrue P' andalso isTrue Q' then SOME (conj_True OF [P_P', Q_Q'])
    70                 else if P aconv P' andalso Q aconv Q' then NONE
    70                 else if P aconv P' andalso Q aconv Q' then NONE
    71                 else SOME (conj_cong OF [P_P', Q_Q'])
    71                 else SOME (conj_cong OF [P_P', Q_Q'])
   139                      | _ => (v, cnt));
   139                      | _ => (v, cnt));
   140                 in (Const (@{const_name StateFun.update}, uT) $ d' $ c $ m $ v' $ s', cnt') end
   140                 in (Const (@{const_name StateFun.update}, uT) $ d' $ c $ m $ v' $ s', cnt') end
   141             | mk_upds s = (Var (("s", mi + 1), sT), mi + 2);
   141             | mk_upds s = (Var (("s", mi + 1), sT), mi + 2);
   142 
   142 
   143           val ct =
   143           val ct =
   144             cterm_of thy (Const (@{const_name StateFun.lookup}, lT) $ destr $ n $ fst (mk_upds s));
   144             Thm.cterm_of thy (Const (@{const_name StateFun.lookup}, lT) $ destr $ n $ fst (mk_upds s));
   145           val basic_ss = #1 (Data.get (Context.Proof ctxt));
   145           val basic_ss = #1 (Data.get (Context.Proof ctxt));
   146           val ctxt' = ctxt |> Config.put simp_depth_limit 100 |> put_simpset basic_ss;
   146           val ctxt' = ctxt |> Config.put simp_depth_limit 100 |> put_simpset basic_ss;
   147           val thm = Simplifier.rewrite ctxt' ct;
   147           val thm = Simplifier.rewrite ctxt' ct;
   148         in
   148         in
   149           if (op aconv) (Logic.dest_equals (prop_of thm))
   149           if (op aconv) (Logic.dest_equals (Thm.prop_of thm))
   150           then NONE
   150           then NONE
   151           else SOME thm
   151           else SOME thm
   152         end
   152         end
   153         handle Option.Option => NONE)
   153         handle Option.Option => NONE)
   154       | _ => NONE ));
   154       | _ => NONE ));
   249                 let
   249                 let
   250                   val eq1 =
   250                   val eq1 =
   251                     Goal.prove ctxt0 [] []
   251                     Goal.prove ctxt0 [] []
   252                       (Logic.list_all (vars, Logic.mk_equals (trm, trm')))
   252                       (Logic.list_all (vars, Logic.mk_equals (trm, trm')))
   253                       (fn _ => rtac meta_ext 1 THEN simp_tac ctxt1 1);
   253                       (fn _ => rtac meta_ext 1 THEN simp_tac ctxt1 1);
   254                   val eq2 = Simplifier.asm_full_rewrite ctxt2 (Thm.dest_equals_rhs (cprop_of eq1));
   254                   val eq2 = Simplifier.asm_full_rewrite ctxt2 (Thm.dest_equals_rhs (Thm.cprop_of eq1));
   255                 in SOME (Thm.transitive eq1 eq2) end
   255                 in SOME (Thm.transitive eq1 eq2) end
   256             | _ => NONE)
   256             | _ => NONE)
   257           end
   257           end
   258       | _ => NONE));
   258       | _ => NONE));
   259 
   259 
   373       (Scan.succeed (Thm.declaration_attribute (fn thm => fn context =>
   373       (Scan.succeed (Thm.declaration_attribute (fn thm => fn context =>
   374         let
   374         let
   375           val ctxt = Context.proof_of context;
   375           val ctxt = Context.proof_of context;
   376           val (lookup_ss, ex_lookup_ss, simprocs_active) = Data.get context;
   376           val (lookup_ss, ex_lookup_ss, simprocs_active) = Data.get context;
   377           val (lookup_ss', ex_lookup_ss') =
   377           val (lookup_ss', ex_lookup_ss') =
   378             (case concl_of thm of
   378             (case Thm.concl_of thm of
   379               (_ $ ((Const (@{const_name Ex}, _) $ _))) =>
   379               (_ $ ((Const (@{const_name Ex}, _) $ _))) =>
   380                 (lookup_ss, simpset_map ctxt (Simplifier.add_simp thm) ex_lookup_ss)
   380                 (lookup_ss, simpset_map ctxt (Simplifier.add_simp thm) ex_lookup_ss)
   381             | _ =>
   381             | _ =>
   382                 (simpset_map ctxt (Simplifier.add_simp thm) lookup_ss, ex_lookup_ss));
   382                 (simpset_map ctxt (Simplifier.add_simp thm) lookup_ss, ex_lookup_ss));
   383           val activate_simprocs =
   383           val activate_simprocs =