src/ZF/arith_data.ML
changeset 13462 56610e2ba220
parent 13259 01fa0c8dbc92
child 13487 1291c6375c29
equal deleted inserted replaced
13461:f93f7d766895 13462:56610e2ba220
    10 sig
    10 sig
    11   (*the main outcome*)
    11   (*the main outcome*)
    12   val nat_cancel: simproc list
    12   val nat_cancel: simproc list
    13   (*tools for use in similar applications*)
    13   (*tools for use in similar applications*)
    14   val gen_trans_tac: thm -> thm option -> tactic
    14   val gen_trans_tac: thm -> thm option -> tactic
    15   val prove_conv: string -> tactic list -> Sign.sg -> 
    15   val prove_conv: string -> tactic list -> Sign.sg ->
    16                   thm list -> term * term -> thm option
    16                   thm list -> term * term -> thm option
    17   val simplify_meta_eq: thm list -> thm -> thm
    17   val simplify_meta_eq: thm list -> thm -> thm
    18   (*debugging*)
    18   (*debugging*)
    19   structure EqCancelNumeralsData   : CANCEL_NUMERALS_DATA
    19   structure EqCancelNumeralsData   : CANCEL_NUMERALS_DATA
    20   structure LessCancelNumeralsData : CANCEL_NUMERALS_DATA
    20   structure LessCancelNumeralsData : CANCEL_NUMERALS_DATA
    61   if fastype_of t = iT then FOLogic.mk_eq(t,u)
    61   if fastype_of t = iT then FOLogic.mk_eq(t,u)
    62                        else FOLogic.mk_iff(t,u);
    62                        else FOLogic.mk_iff(t,u);
    63 
    63 
    64 (*We remove equality assumptions because they confuse the simplifier and
    64 (*We remove equality assumptions because they confuse the simplifier and
    65   because only type-checking assumptions are necessary.*)
    65   because only type-checking assumptions are necessary.*)
    66 fun is_eq_thm th = 
    66 fun is_eq_thm th =
    67     can FOLogic.dest_eq (FOLogic.dest_Trueprop (#prop (rep_thm th)));
    67     can FOLogic.dest_eq (FOLogic.dest_Trueprop (#prop (rep_thm th)));
    68 
    68 
    69 fun add_chyps chyps ct = Drule.list_implies (map cprop_of chyps, ct);
    69 fun add_chyps chyps ct = Drule.list_implies (map cprop_of chyps, ct);
    70 
    70 
    71 fun prove_conv name tacs sg hyps (t,u) =
    71 fun prove_conv name tacs sg hyps (t,u) =
    73   else
    73   else
    74   let val hyps' = filter (not o is_eq_thm) hyps
    74   let val hyps' = filter (not o is_eq_thm) hyps
    75       val goal = Logic.list_implies (map (#prop o Thm.rep_thm) hyps',
    75       val goal = Logic.list_implies (map (#prop o Thm.rep_thm) hyps',
    76         FOLogic.mk_Trueprop (mk_eq_iff (t, u)));
    76         FOLogic.mk_Trueprop (mk_eq_iff (t, u)));
    77   in Some (hyps' MRS Tactic.prove sg [] [] goal (K (EVERY tacs)))
    77   in Some (hyps' MRS Tactic.prove sg [] [] goal (K (EVERY tacs)))
    78       handle ERROR_MESSAGE msg => 
    78       handle ERROR_MESSAGE msg =>
    79 	(warning (msg ^ "\nCancellation failed: no typing information? (" ^ name ^ ")"); None)
    79         (warning (msg ^ "\nCancellation failed: no typing information? (" ^ name ^ ")"); None)
    80   end;
    80   end;
    81 
    81 
    82 fun prep_simproc (name, pats, proc) = Simplifier.mk_simproc name pats proc;
    82 fun prep_simproc (name, pats, proc) =
    83 fun prep_pat s = Thm.read_cterm (Theory.sign_of (the_context ()))
    83   Simplifier.simproc (Theory.sign_of (the_context ())) name pats proc;
    84                       (s, TypeInfer.anyT ["logic"]);
    84 
    85 val prep_pats = map prep_pat;
    85 
    86 
    86 (*** Use CancelNumerals simproc without binary numerals,
    87 
       
    88 (*** Use CancelNumerals simproc without binary numerals, 
       
    89      just for cancellation ***)
    87      just for cancellation ***)
    90 
    88 
    91 val mk_times = FOLogic.mk_binop "Arith.mult";
    89 val mk_times = FOLogic.mk_binop "Arith.mult";
    92 
    90 
    93 fun mk_prod [] = one
    91 fun mk_prod [] = one
   130                diff_natify1, diff_natify2];
   128                diff_natify1, diff_natify2];
   131 
   129 
   132 (*Final simplification: cancel + and **)
   130 (*Final simplification: cancel + and **)
   133 fun simplify_meta_eq rules =
   131 fun simplify_meta_eq rules =
   134     mk_meta_eq o
   132     mk_meta_eq o
   135     simplify (FOL_ss addeqcongs[eq_cong2,iff_cong2] 
   133     simplify (FOL_ss addeqcongs[eq_cong2,iff_cong2]
   136                      delsimps iff_simps (*these could erase the whole rule!*)
   134                      delsimps iff_simps (*these could erase the whole rule!*)
   137 		     addsimps rules);
   135                      addsimps rules);
   138 
   136 
   139 val final_rules = add_0s @ mult_1s @ [mult_0, mult_0_right];
   137 val final_rules = add_0s @ mult_1s @ [mult_0, mult_0_right];
   140 
   138 
   141 structure CancelNumeralsCommon =
   139 structure CancelNumeralsCommon =
   142   struct
   140   struct
   156   end;
   154   end;
   157 
   155 
   158 (** The functor argumnets are declared as separate structures
   156 (** The functor argumnets are declared as separate structures
   159     so that they can be exported to ease debugging. **)
   157     so that they can be exported to ease debugging. **)
   160 
   158 
   161 structure EqCancelNumeralsData = 
   159 structure EqCancelNumeralsData =
   162   struct
   160   struct
   163   open CancelNumeralsCommon
   161   open CancelNumeralsCommon
   164   val prove_conv = prove_conv "nateq_cancel_numerals"
   162   val prove_conv = prove_conv "nateq_cancel_numerals"
   165   val mk_bal   = FOLogic.mk_eq
   163   val mk_bal   = FOLogic.mk_eq
   166   val dest_bal = FOLogic.dest_eq
   164   val dest_bal = FOLogic.dest_eq
   169   val trans_tac = gen_trans_tac iff_trans
   167   val trans_tac = gen_trans_tac iff_trans
   170   end;
   168   end;
   171 
   169 
   172 structure EqCancelNumerals = CancelNumeralsFun(EqCancelNumeralsData);
   170 structure EqCancelNumerals = CancelNumeralsFun(EqCancelNumeralsData);
   173 
   171 
   174 structure LessCancelNumeralsData = 
   172 structure LessCancelNumeralsData =
   175   struct
   173   struct
   176   open CancelNumeralsCommon
   174   open CancelNumeralsCommon
   177   val prove_conv = prove_conv "natless_cancel_numerals"
   175   val prove_conv = prove_conv "natless_cancel_numerals"
   178   val mk_bal   = FOLogic.mk_binrel "Ordinal.lt"
   176   val mk_bal   = FOLogic.mk_binrel "Ordinal.lt"
   179   val dest_bal = FOLogic.dest_bin "Ordinal.lt" iT
   177   val dest_bal = FOLogic.dest_bin "Ordinal.lt" iT
   182   val trans_tac = gen_trans_tac iff_trans
   180   val trans_tac = gen_trans_tac iff_trans
   183   end;
   181   end;
   184 
   182 
   185 structure LessCancelNumerals = CancelNumeralsFun(LessCancelNumeralsData);
   183 structure LessCancelNumerals = CancelNumeralsFun(LessCancelNumeralsData);
   186 
   184 
   187 structure DiffCancelNumeralsData = 
   185 structure DiffCancelNumeralsData =
   188   struct
   186   struct
   189   open CancelNumeralsCommon
   187   open CancelNumeralsCommon
   190   val prove_conv = prove_conv "natdiff_cancel_numerals"
   188   val prove_conv = prove_conv "natdiff_cancel_numerals"
   191   val mk_bal   = FOLogic.mk_binop "Arith.diff"
   189   val mk_bal   = FOLogic.mk_binop "Arith.diff"
   192   val dest_bal = FOLogic.dest_bin "Arith.diff" iT
   190   val dest_bal = FOLogic.dest_bin "Arith.diff" iT
   197 
   195 
   198 structure DiffCancelNumerals = CancelNumeralsFun(DiffCancelNumeralsData);
   196 structure DiffCancelNumerals = CancelNumeralsFun(DiffCancelNumeralsData);
   199 
   197 
   200 
   198 
   201 val nat_cancel =
   199 val nat_cancel =
   202       map prep_simproc
   200   map prep_simproc
   203        [("nateq_cancel_numerals",
   201    [("nateq_cancel_numerals",
   204 	 prep_pats ["l #+ m = n", "l = m #+ n",
   202      ["l #+ m = n", "l = m #+ n",
   205 		    "l #* m = n", "l = m #* n",
   203       "l #* m = n", "l = m #* n",
   206 		    "succ(m) = n", "m = succ(n)"],
   204       "succ(m) = n", "m = succ(n)"],
   207 	 EqCancelNumerals.proc),
   205      EqCancelNumerals.proc),
   208 	("natless_cancel_numerals",
   206     ("natless_cancel_numerals",
   209 	 prep_pats ["l #+ m < n", "l < m #+ n",
   207      ["l #+ m < n", "l < m #+ n",
   210 		    "l #* m < n", "l < m #* n",
   208       "l #* m < n", "l < m #* n",
   211 		    "succ(m) < n", "m < succ(n)"],
   209       "succ(m) < n", "m < succ(n)"],
   212 	 LessCancelNumerals.proc),
   210      LessCancelNumerals.proc),
   213 	("natdiff_cancel_numerals",
   211     ("natdiff_cancel_numerals",
   214 	 prep_pats ["(l #+ m) #- n", "l #- (m #+ n)",
   212      ["(l #+ m) #- n", "l #- (m #+ n)",
   215 		    "(l #* m) #- n", "l #- (m #* n)",
   213       "(l #* m) #- n", "l #- (m #* n)",
   216 		    "succ(m) #- n", "m #- succ(n)"],
   214       "succ(m) #- n", "m #- succ(n)"],
   217 	 DiffCancelNumerals.proc)];
   215      DiffCancelNumerals.proc)];
   218 
   216 
   219 end;
   217 end;
   220 
   218 
   221 (*Install the simprocs!*)
       
   222 Addsimprocs ArithData.nat_cancel;
   219 Addsimprocs ArithData.nat_cancel;
   223 
   220 
   224 
   221 
   225 (*examples:
   222 (*examples:
   226 print_depth 22;
   223 print_depth 22;