src/HOL/Tools/semiring_normalizer.ML
changeset 47108 2a1953f0d20d
parent 46497 89ccf66aa73d
child 51717 9e7d1c139569
equal deleted inserted replaced
47107:35807a5d8dc2 47108:2a1953f0d20d
   177           handle TERM _ => error "ring_dest_const")),
   177           handle TERM _ => error "ring_dest_const")),
   178     mk_const = fn phi => fn cT => fn x => Numeral.mk_cnumber cT
   178     mk_const = fn phi => fn cT => fn x => Numeral.mk_cnumber cT
   179       (case Rat.quotient_of_rat x of (i, 1) => i | _ => error "int_of_rat: bad int"),
   179       (case Rat.quotient_of_rat x of (i, 1) => i | _ => error "int_of_rat: bad int"),
   180     conv = fn phi => fn _ => Simplifier.rewrite (HOL_basic_ss addsimps @{thms semiring_norm})
   180     conv = fn phi => fn _ => Simplifier.rewrite (HOL_basic_ss addsimps @{thms semiring_norm})
   181       then_conv Simplifier.rewrite (HOL_basic_ss addsimps
   181       then_conv Simplifier.rewrite (HOL_basic_ss addsimps
   182         (@{thms numeral_1_eq_1} @ @{thms numeral_0_eq_0} @ @{thms numerals(1-2)}))};
   182         @{thms numeral_1_eq_1})};
   183 
   183 
   184 fun field_funs key =
   184 fun field_funs key =
   185   let
   185   let
   186     fun numeral_is_const ct =
   186     fun numeral_is_const ct =
   187       case term_of ct of
   187       case term_of ct of
   235 
   235 
   236 val dest_numeral = term_of #> HOLogic.dest_number #> snd;
   236 val dest_numeral = term_of #> HOLogic.dest_number #> snd;
   237 val is_numeral = can dest_numeral;
   237 val is_numeral = can dest_numeral;
   238 
   238 
   239 val numeral01_conv = Simplifier.rewrite
   239 val numeral01_conv = Simplifier.rewrite
   240                          (HOL_basic_ss addsimps [@{thm numeral_1_eq_1}, @{thm numeral_0_eq_0}]);
   240                          (HOL_basic_ss addsimps [@{thm numeral_1_eq_1}]);
   241 val zero1_numeral_conv = 
   241 val zero1_numeral_conv = 
   242  Simplifier.rewrite (HOL_basic_ss addsimps [@{thm numeral_1_eq_1} RS sym, @{thm numeral_0_eq_0} RS sym]);
   242  Simplifier.rewrite (HOL_basic_ss addsimps [@{thm numeral_1_eq_1} RS sym]);
   243 fun zerone_conv cv = zero1_numeral_conv then_conv cv then_conv numeral01_conv;
   243 fun zerone_conv cv = zero1_numeral_conv then_conv cv then_conv numeral01_conv;
   244 val natarith = [@{thm "add_nat_number_of"}, @{thm "diff_nat_number_of"},
   244 val natarith = [@{thm "numeral_plus_numeral"}, @{thm "diff_nat_numeral"},
   245                 @{thm "mult_nat_number_of"}, @{thm "eq_nat_number_of"}, 
   245                 @{thm "numeral_times_numeral"}, @{thm "numeral_eq_iff"}, 
   246                 @{thm "less_nat_number_of"}];
   246                 @{thm "numeral_less_iff"}];
   247 
   247 
   248 val nat_add_conv = 
   248 val nat_add_conv = 
   249  zerone_conv 
   249  zerone_conv 
   250   (Simplifier.rewrite 
   250   (Simplifier.rewrite 
   251     (HOL_basic_ss 
   251     (HOL_basic_ss 
   252        addsimps @{thms arith_simps} @ natarith @ @{thms rel_simps}
   252        addsimps @{thms arith_simps} @ natarith @ @{thms rel_simps}
   253              @ [@{thm if_False}, @{thm if_True}, @{thm Nat.add_0}, @{thm add_Suc},
   253              @ [@{thm if_False}, @{thm if_True}, @{thm Nat.add_0}, @{thm add_Suc},
   254                  @{thm add_number_of_left}, @{thm Suc_eq_plus1}]
   254                  @{thm add_numeral_left}, @{thm Suc_eq_plus1}]
   255              @ map (fn th => th RS sym) @{thms numerals}));
   255              @ map (fn th => th RS sym) @{thms numerals}));
   256 
   256 
   257 val zeron_tm = @{cterm "0::nat"};
   257 val zeron_tm = @{cterm "0::nat"};
   258 val onen_tm  = @{cterm "1::nat"};
   258 val onen_tm  = @{cterm "1::nat"};
   259 val true_tm = @{cterm "True"};
   259 val true_tm = @{cterm "True"};