113 simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms semiring_norm}); |
113 simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms semiring_norm}); |
114 |
114 |
115 val semiring_funs = |
115 val semiring_funs = |
116 {is_const = can HOLogic.dest_number o Thm.term_of, |
116 {is_const = can HOLogic.dest_number o Thm.term_of, |
117 dest_const = (fn ct => |
117 dest_const = (fn ct => |
118 Rat.rat_of_int (snd |
118 Rat.of_int (snd |
119 (HOLogic.dest_number (Thm.term_of ct) |
119 (HOLogic.dest_number (Thm.term_of ct) |
120 handle TERM _ => error "ring_dest_const"))), |
120 handle TERM _ => error "ring_dest_const"))), |
121 mk_const = (fn cT => fn x => Numeral.mk_cnumber cT |
121 mk_const = (fn cT => fn x => Numeral.mk_cnumber cT |
122 (case Rat.quotient_of_rat x of (i, 1) => i | _ => error "int_of_rat: bad int")), |
122 (case Rat.dest x of (i, 1) => i | _ => error "int_of_rat: bad int")), |
123 conv = (fn ctxt => |
123 conv = (fn ctxt => |
124 Simplifier.rewrite (put_simpset semiring_norm_ss ctxt) |
124 Simplifier.rewrite (put_simpset semiring_norm_ss ctxt) |
125 then_conv Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms numeral_One}))}; |
125 then_conv Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms numeral_One}))}; |
126 |
126 |
127 val divide_const = Thm.cterm_of @{context} (Logic.varify_global @{term "op /"}); |
127 val divide_const = Thm.cterm_of @{context} (Logic.varify_global @{term "op /"}); |
135 can HOLogic.dest_number a andalso can HOLogic.dest_number b |
135 can HOLogic.dest_number a andalso can HOLogic.dest_number b |
136 | Const (@{const_name Fields.inverse},_)$t => can HOLogic.dest_number t |
136 | Const (@{const_name Fields.inverse},_)$t => can HOLogic.dest_number t |
137 | t => can HOLogic.dest_number t |
137 | t => can HOLogic.dest_number t |
138 fun dest_const ct = ((case Thm.term_of ct of |
138 fun dest_const ct = ((case Thm.term_of ct of |
139 Const (@{const_name Rings.divide},_) $ a $ b=> |
139 Const (@{const_name Rings.divide},_) $ a $ b=> |
140 Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b)) |
140 Rat.make (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b)) |
141 | Const (@{const_name Fields.inverse},_)$t => |
141 | Const (@{const_name Fields.inverse},_)$t => |
142 Rat.inv (Rat.rat_of_int (snd (HOLogic.dest_number t))) |
142 Rat.inv (Rat.of_int (snd (HOLogic.dest_number t))) |
143 | t => Rat.rat_of_int (snd (HOLogic.dest_number t))) |
143 | t => Rat.of_int (snd (HOLogic.dest_number t))) |
144 handle TERM _ => error "ring_dest_const") |
144 handle TERM _ => error "ring_dest_const") |
145 fun mk_const cT x = |
145 fun mk_const cT x = |
146 let val (a, b) = Rat.quotient_of_rat x |
146 let val (a, b) = Rat.dest x |
147 in if b = 1 then Numeral.mk_cnumber cT a |
147 in if b = 1 then Numeral.mk_cnumber cT a |
148 else Thm.apply |
148 else Thm.apply |
149 (Thm.apply (Thm.instantiate_cterm ([(divide_tvar, cT)], []) divide_const) |
149 (Thm.apply (Thm.instantiate_cterm ([(divide_tvar, cT)], []) divide_const) |
150 (Numeral.mk_cnumber cT a)) |
150 (Numeral.mk_cnumber cT a)) |
151 (Numeral.mk_cnumber cT b) |
151 (Numeral.mk_cnumber cT b) |