177 raise THM ("No data entry for structure key", 0, [key]); |
177 raise THM ("No data entry for structure key", 0, [key]); |
178 val fns = {is_const = is_const phi, dest_const = dest_const phi, |
178 val fns = {is_const = is_const phi, dest_const = dest_const phi, |
179 mk_const = mk_const phi, conv = conv phi}; |
179 mk_const = mk_const phi, conv = conv phi}; |
180 in AList.map_entry Thm.eq_thm key (apsnd (K fns)) data end); |
180 in AList.map_entry Thm.eq_thm key (apsnd (K fns)) data end); |
181 |
181 |
|
182 val semiring_norm_ss = |
|
183 simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms semiring_norm}); |
|
184 |
182 fun semiring_funs key = funs key |
185 fun semiring_funs key = funs key |
183 {is_const = fn phi => can HOLogic.dest_number o Thm.term_of, |
186 {is_const = fn phi => can HOLogic.dest_number o Thm.term_of, |
184 dest_const = fn phi => fn ct => |
187 dest_const = fn phi => fn ct => |
185 Rat.rat_of_int (snd |
188 Rat.rat_of_int (snd |
186 (HOLogic.dest_number (Thm.term_of ct) |
189 (HOLogic.dest_number (Thm.term_of ct) |
187 handle TERM _ => error "ring_dest_const")), |
190 handle TERM _ => error "ring_dest_const")), |
188 mk_const = fn phi => fn cT => fn x => Numeral.mk_cnumber cT |
191 mk_const = fn phi => fn cT => fn x => Numeral.mk_cnumber cT |
189 (case Rat.quotient_of_rat x of (i, 1) => i | _ => error "int_of_rat: bad int"), |
192 (case Rat.quotient_of_rat x of (i, 1) => i | _ => error "int_of_rat: bad int"), |
190 conv = fn phi => fn ctxt => |
193 conv = fn phi => fn ctxt => |
191 Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms semiring_norm}) |
194 Simplifier.rewrite (put_simpset semiring_norm_ss ctxt) |
192 then_conv Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms numeral_1_eq_1})}; |
195 then_conv Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms numeral_1_eq_1})}; |
193 |
196 |
194 fun field_funs key = |
197 fun field_funs key = |
195 let |
198 let |
196 fun numeral_is_const ct = |
199 fun numeral_is_const ct = |
256 zero1_numeral_conv ctxt then_conv cv then_conv numeral01_conv ctxt; |
259 zero1_numeral_conv ctxt then_conv cv then_conv numeral01_conv ctxt; |
257 val natarith = [@{thm "numeral_plus_numeral"}, @{thm "diff_nat_numeral"}, |
260 val natarith = [@{thm "numeral_plus_numeral"}, @{thm "diff_nat_numeral"}, |
258 @{thm "numeral_times_numeral"}, @{thm "numeral_eq_iff"}, |
261 @{thm "numeral_times_numeral"}, @{thm "numeral_eq_iff"}, |
259 @{thm "numeral_less_iff"}]; |
262 @{thm "numeral_less_iff"}]; |
260 |
263 |
|
264 val nat_add_ss = |
|
265 simpset_of |
|
266 (put_simpset HOL_basic_ss @{context} |
|
267 addsimps @{thms arith_simps} @ natarith @ @{thms rel_simps} |
|
268 @ [@{thm if_False}, @{thm if_True}, @{thm Nat.add_0}, @{thm add_Suc}, |
|
269 @{thm add_numeral_left}, @{thm Suc_eq_plus1}] |
|
270 @ map (fn th => th RS sym) @{thms numerals}); |
|
271 |
261 fun nat_add_conv ctxt = |
272 fun nat_add_conv ctxt = |
262 zerone_conv ctxt |
273 zerone_conv ctxt (Simplifier.rewrite (put_simpset nat_add_ss ctxt)); |
263 (Simplifier.rewrite |
|
264 (put_simpset HOL_basic_ss ctxt |
|
265 addsimps @{thms arith_simps} @ natarith @ @{thms rel_simps} |
|
266 @ [@{thm if_False}, @{thm if_True}, @{thm Nat.add_0}, @{thm add_Suc}, |
|
267 @{thm add_numeral_left}, @{thm Suc_eq_plus1}] |
|
268 @ map (fn th => th RS sym) @{thms numerals})); |
|
269 |
274 |
270 val zeron_tm = @{cterm "0::nat"}; |
275 val zeron_tm = @{cterm "0::nat"}; |
271 val onen_tm = @{cterm "1::nat"}; |
276 val onen_tm = @{cterm "1::nat"}; |
272 val true_tm = @{cterm "True"}; |
277 val true_tm = @{cterm "True"}; |
273 |
278 |