src/Provers/typedsimp.ML
changeset 59164 ff40c53d1af9
parent 58963 26bf09b95dda
child 59498 50b60f501b05
equal deleted inserted replaced
59163:857a600f0c94 59164:ff40c53d1af9
     6 Theory with its typed reflexivity axiom a:A ==> a=a:A.  For most logics try
     6 Theory with its typed reflexivity axiom a:A ==> a=a:A.  For most logics try
     7 simp.ML.
     7 simp.ML.
     8 *)
     8 *)
     9 
     9 
    10 signature TSIMP_DATA =
    10 signature TSIMP_DATA =
    11   sig
    11 sig
    12   val refl: thm         (*Reflexive law*)
    12   val refl: thm         (*Reflexive law*)
    13   val sym: thm          (*Symmetric law*)
    13   val sym: thm          (*Symmetric law*)
    14   val trans: thm        (*Transitive law*)
    14   val trans: thm        (*Transitive law*)
    15   val refl_red: thm     (* reduce(a,a) *)
    15   val refl_red: thm     (* reduce(a,a) *)
    16   val trans_red: thm    (* [|a=b; reduce(b,c) |] ==> a=c *)
    16   val trans_red: thm    (* [|a=b; reduce(b,c) |] ==> a=c *)
    17   val red_if_equal: thm (* a=b ==> reduce(a,b) *)
    17   val red_if_equal: thm (* a=b ==> reduce(a,b) *)
    18   (*Built-in rewrite rules*)
    18   (*Built-in rewrite rules*)
    19   val default_rls: thm list
    19   val default_rls: thm list
    20   (*Type checking or similar -- solution of routine conditions*)
    20   (*Type checking or similar -- solution of routine conditions*)
    21   val routine_tac: Proof.context -> thm list -> int -> tactic
    21   val routine_tac: Proof.context -> thm list -> int -> tactic
    22   end;
    22 end;
    23 
    23 
    24 signature TSIMP =
    24 signature TSIMP =
    25   sig
    25 sig
    26   val asm_res_tac: Proof.context -> thm list -> int -> tactic   
    26   val asm_res_tac: Proof.context -> thm list -> int -> tactic
    27   val cond_norm_tac: Proof.context -> ((int->tactic) * thm list * thm list) -> tactic
    27   val cond_norm_tac: Proof.context -> ((int->tactic) * thm list * thm list) -> tactic
    28   val cond_step_tac: Proof.context -> ((int->tactic) * thm list * thm list) -> int -> tactic
    28   val cond_step_tac: Proof.context -> ((int->tactic) * thm list * thm list) -> int -> tactic
    29   val norm_tac: Proof.context -> (thm list * thm list) -> tactic
    29   val norm_tac: Proof.context -> (thm list * thm list) -> tactic
    30   val process_rules: thm list -> thm list * thm list
    30   val process_rules: thm list -> thm list * thm list
    31   val rewrite_res_tac: int -> tactic   
    31   val rewrite_res_tac: Proof.context -> int -> tactic
    32   val split_eqn: thm
    32   val split_eqn: thm
    33   val step_tac: Proof.context -> (thm list * thm list) -> int -> tactic
    33   val step_tac: Proof.context -> (thm list * thm list) -> int -> tactic
    34   val subconv_res_tac: thm list -> int -> tactic   
    34   val subconv_res_tac: Proof.context -> thm list -> int -> tactic
    35   end;
    35 end;
    36 
    36 
    37 
    37 functor TSimpFun (TSimp_data: TSIMP_DATA) : TSIMP =
    38 functor TSimpFun (TSimp_data: TSIMP_DATA) : TSIMP = 
       
    39 struct
    38 struct
    40 local open TSimp_data
    39 local open TSimp_data
    41 in
    40 in
    42 
    41 
    43 (*For simplifying both sides of an equation:
    42 (*For simplifying both sides of an equation:
    70 
    69 
    71 (*Given the list rls, return the pair (simp_rls, other_rls).*)
    70 (*Given the list rls, return the pair (simp_rls, other_rls).*)
    72 fun process_rules rls = fold_rev add_rule rls ([], []);
    71 fun process_rules rls = fold_rev add_rule rls ([], []);
    73 
    72 
    74 (*Given list of rewrite rules, return list of both forms, reject others*)
    73 (*Given list of rewrite rules, return list of both forms, reject others*)
    75 fun process_rewrites rls = 
    74 fun process_rewrites rls =
    76   case process_rules rls of
    75   case process_rules rls of
    77       (simp_rls,[])  =>  simp_rls
    76       (simp_rls,[])  =>  simp_rls
    78     | (_,others) => raise THM 
    77     | (_,others) => raise THM
    79         ("process_rewrites: Ill-formed rewrite", 0, others);
    78         ("process_rewrites: Ill-formed rewrite", 0, others);
    80 
    79 
    81 (*Process the default rewrite rules*)
    80 (*Process the default rewrite rules*)
    82 val simp_rls = process_rewrites default_rls;
    81 val simp_rls = process_rewrites default_rls;
       
    82 val simp_net = Tactic.build_net simp_rls;
    83 
    83 
    84 (*If subgoal is too flexible (e.g. ?a=?b or just ?P) then filt_resolve_tac
    84 (*If subgoal is too flexible (e.g. ?a=?b or just ?P) then filt_resolve_tac
    85   will fail!  The filter will pass all the rules, and the bound permits
    85   will fail!  The filter will pass all the rules, and the bound permits
    86   no ambiguity.*)
    86   no ambiguity.*)
    87 
    87 
    88 (*Resolution with rewrite/sub rules.  Builds the tree for filt_resolve_tac.*)
    88 (*Resolution with rewrite/sub rules.  Builds the tree for filt_resolve_tac.*)
    89 val rewrite_res_tac = filt_resolve_tac simp_rls 2;
    89 fun rewrite_res_tac ctxt = filt_resolve_from_net_tac ctxt 2 simp_net;
    90 
    90 
    91 (*The congruence rules for simplifying subterms.  If subgoal is too flexible
    91 (*The congruence rules for simplifying subterms.  If subgoal is too flexible
    92     then only refl,refl_red will be used (if even them!). *)
    92     then only refl,refl_red will be used (if even them!). *)
    93 fun subconv_res_tac congr_rls =
    93 fun subconv_res_tac ctxt congr_rls =
    94   filt_resolve_tac (map subconv_rule congr_rls) 2
    94   filt_resolve_from_net_tac ctxt 2 (Tactic.build_net (map subconv_rule congr_rls))
    95   ORELSE'  filt_resolve_tac [refl,refl_red] 1;
    95   ORELSE'  filt_resolve_from_net_tac ctxt 1 (Tactic.build_net [refl, refl_red]);
    96 
    96 
    97 (*Resolve with asms, whether rewrites or not*)
    97 (*Resolve with asms, whether rewrites or not*)
    98 fun asm_res_tac ctxt asms =
    98 fun asm_res_tac ctxt asms =
    99     let val (xsimp_rls,xother_rls) = process_rules asms
    99     let val (xsimp_rls, xother_rls) = process_rules asms
   100     in  routine_tac ctxt xother_rls  ORELSE'  
   100     in  routine_tac ctxt xother_rls  ORELSE'
   101         filt_resolve_tac xsimp_rls 2
   101         filt_resolve_from_net_tac ctxt 2 (Tactic.build_net xsimp_rls)
   102     end;
   102     end;
   103 
   103 
   104 (*Single step for simple rewriting*)
   104 (*Single step for simple rewriting*)
   105 fun step_tac ctxt (congr_rls,asms) =
   105 fun step_tac ctxt (congr_rls, asms) =
   106     asm_res_tac ctxt asms   ORELSE'  rewrite_res_tac  ORELSE'  
   106     asm_res_tac ctxt asms   ORELSE'  rewrite_res_tac ctxt  ORELSE'
   107     subconv_res_tac congr_rls;
   107     subconv_res_tac ctxt congr_rls;
   108 
   108 
   109 (*Single step for conditional rewriting: prove_cond_tac handles new subgoals.*)
   109 (*Single step for conditional rewriting: prove_cond_tac handles new subgoals.*)
   110 fun cond_step_tac ctxt (prove_cond_tac, congr_rls, asms) =
   110 fun cond_step_tac ctxt (prove_cond_tac, congr_rls, asms) =
   111     asm_res_tac ctxt asms   ORELSE'  rewrite_res_tac  ORELSE'  
   111     asm_res_tac ctxt asms   ORELSE'  rewrite_res_tac ctxt  ORELSE'
   112     (resolve_tac [trans, red_trans]  THEN'  prove_cond_tac)  ORELSE'  
   112     (resolve_tac [trans, red_trans]  THEN'  prove_cond_tac)  ORELSE'
   113     subconv_res_tac congr_rls;
   113     subconv_res_tac ctxt congr_rls;
   114 
   114 
   115 (*Unconditional normalization tactic*)
   115 (*Unconditional normalization tactic*)
   116 fun norm_tac ctxt arg = REPEAT_FIRST (step_tac ctxt arg)  THEN
   116 fun norm_tac ctxt arg = REPEAT_FIRST (step_tac ctxt arg)  THEN
   117     TRYALL (resolve_tac [red_if_equal]);
   117     TRYALL (resolve_tac [red_if_equal]);
   118 
   118 
   121     TRYALL (resolve_tac [red_if_equal]);
   121     TRYALL (resolve_tac [red_if_equal]);
   122 
   122 
   123 end;
   123 end;
   124 end;
   124 end;
   125 
   125 
   126