author | haftmann |
Sun, 15 Feb 2015 17:01:22 +0100 | |
changeset 59549 | 6e685f9c9aa5 |
parent 59548 | d9304532c7ab |
child 59550 | ded0ff754037 |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: HOL/Tools/semiring_normalizer.ML |
23252 | 2 |
Author: Amine Chaieb, TU Muenchen |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
3 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
4 |
Normalization of expressions in semirings. |
23252 | 5 |
*) |
6 |
||
36753
5cf4e9128f22
renamed Normalizer to the more specific Semiring_Normalizer
haftmann
parents:
36751
diff
changeset
|
7 |
signature SEMIRING_NORMALIZER = |
23252 | 8 |
sig |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
9 |
type entry |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
10 |
val match: Proof.context -> cterm -> entry option |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
11 |
val del: attribute |
36711 | 12 |
val add: {semiring: cterm list * thm list, ring: cterm list * thm list, |
13 |
field: cterm list * thm list, idom: thm list, ideal: thm list} -> attribute |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
14 |
|
36711 | 15 |
val semiring_normalize_conv: Proof.context -> conv |
16 |
val semiring_normalize_ord_conv: Proof.context -> (cterm -> cterm -> bool) -> conv |
|
17 |
val semiring_normalize_wrapper: Proof.context -> entry -> conv |
|
18 |
val semiring_normalize_ord_wrapper: Proof.context -> entry |
|
19 |
-> (cterm -> cterm -> bool) -> conv |
|
20 |
val semiring_normalizers_conv: cterm list -> cterm list * thm list |
|
21 |
-> cterm list * thm list -> cterm list * thm list -> |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
22 |
(cterm -> bool) * conv * conv * conv -> (cterm -> cterm -> bool) -> |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
23 |
{add: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
24 |
mul: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
25 |
neg: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
26 |
main: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
27 |
pow: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
28 |
sub: Proof.context -> conv} |
36711 | 29 |
val semiring_normalizers_ord_wrapper: Proof.context -> entry -> |
30 |
(cterm -> cterm -> bool) -> |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
31 |
{add: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
32 |
mul: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
33 |
neg: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
34 |
main: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
35 |
pow: Proof.context -> conv, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
36 |
sub: Proof.context -> conv} |
23252 | 37 |
end |
38 |
||
36753
5cf4e9128f22
renamed Normalizer to the more specific Semiring_Normalizer
haftmann
parents:
36751
diff
changeset
|
39 |
structure Semiring_Normalizer: SEMIRING_NORMALIZER = |
23252 | 40 |
struct |
23559 | 41 |
|
36708 | 42 |
(** data **) |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
43 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
44 |
type entry = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
45 |
{vars: cterm list, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
46 |
semiring: cterm list * thm list, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
47 |
ring: cterm list * thm list, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
48 |
field: cterm list * thm list, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
49 |
idom: thm list, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
50 |
ideal: thm list} * |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
51 |
{is_const: cterm -> bool, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
52 |
dest_const: cterm -> Rat.rat, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
53 |
mk_const: ctyp -> Rat.rat -> cterm, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
54 |
conv: Proof.context -> cterm -> thm}; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
55 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
56 |
structure Data = Generic_Data |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
57 |
( |
36705 | 58 |
type T = (thm * entry) list; |
59 |
val empty = []; |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
60 |
val extend = I; |
36771 | 61 |
fun merge data = AList.merge Thm.eq_thm (K true) data; |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
62 |
); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
63 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
64 |
fun match ctxt tm = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
65 |
let |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
66 |
fun match_inst |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
67 |
({vars, semiring = (sr_ops, sr_rules), |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
68 |
ring = (r_ops, r_rules), field = (f_ops, f_rules), idom, ideal}, |
59321 | 69 |
fns) pat = |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
70 |
let |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
71 |
fun h instT = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
72 |
let |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
73 |
val substT = Thm.instantiate (instT, []); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
74 |
val substT_cterm = Drule.cterm_rule substT; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
75 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
76 |
val vars' = map substT_cterm vars; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
77 |
val semiring' = (map substT_cterm sr_ops, map substT sr_rules); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
78 |
val ring' = (map substT_cterm r_ops, map substT r_rules); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
79 |
val field' = (map substT_cterm f_ops, map substT f_rules); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
80 |
val idom' = map substT idom; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
81 |
val ideal' = map substT ideal; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
82 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
83 |
val result = ({vars = vars', semiring = semiring', |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
84 |
ring = ring', field = field', idom = idom', ideal = ideal'}, fns); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
85 |
in SOME result end |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
86 |
in (case try Thm.match (pat, tm) of |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
87 |
NONE => NONE |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
88 |
| SOME (instT, _) => h instT) |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
89 |
end; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
90 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
91 |
fun match_struct (_, |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
92 |
entry as ({semiring = (sr_ops, _), ring = (r_ops, _), field = (f_ops, _), ...}, _): entry) = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
93 |
get_first (match_inst entry) (sr_ops @ r_ops @ f_ops); |
59549
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
94 |
in get_first match_struct (Data.get (Context.Proof ctxt)) end; |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
95 |
|
59539 | 96 |
|
97 |
(* extra-logical functions *) |
|
98 |
||
99 |
val semiring_norm_ss = |
|
100 |
simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms semiring_norm}); |
|
101 |
||
59549
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
102 |
val semiring_funs = |
59548 | 103 |
{is_const = can HOLogic.dest_number o Thm.term_of, |
104 |
dest_const = (fn ct => |
|
59539 | 105 |
Rat.rat_of_int (snd |
106 |
(HOLogic.dest_number (Thm.term_of ct) |
|
59540 | 107 |
handle TERM _ => error "ring_dest_const"))), |
59548 | 108 |
mk_const = (fn cT => fn x => Numeral.mk_cnumber cT |
59540 | 109 |
(case Rat.quotient_of_rat x of (i, 1) => i | _ => error "int_of_rat: bad int")), |
59548 | 110 |
conv = (fn ctxt => |
59539 | 111 |
Simplifier.rewrite (put_simpset semiring_norm_ss ctxt) |
59540 | 112 |
then_conv Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms numeral_1_eq_1}))}; |
59539 | 113 |
|
59549
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
114 |
val field_funs = |
59539 | 115 |
let |
116 |
fun numeral_is_const ct = |
|
117 |
case term_of ct of |
|
118 |
Const (@{const_name Fields.divide},_) $ a $ b => |
|
119 |
can HOLogic.dest_number a andalso can HOLogic.dest_number b |
|
120 |
| Const (@{const_name Fields.inverse},_)$t => can HOLogic.dest_number t |
|
121 |
| t => can HOLogic.dest_number t |
|
122 |
fun dest_const ct = ((case term_of ct of |
|
123 |
Const (@{const_name Fields.divide},_) $ a $ b=> |
|
124 |
Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b)) |
|
125 |
| Const (@{const_name Fields.inverse},_)$t => |
|
126 |
Rat.inv (Rat.rat_of_int (snd (HOLogic.dest_number t))) |
|
127 |
| t => Rat.rat_of_int (snd (HOLogic.dest_number t))) |
|
128 |
handle TERM _ => error "ring_dest_const") |
|
59540 | 129 |
fun mk_const cT x = |
59539 | 130 |
let val (a, b) = Rat.quotient_of_rat x |
131 |
in if b = 1 then Numeral.mk_cnumber cT a |
|
132 |
else Thm.apply |
|
133 |
(Thm.apply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"}) |
|
134 |
(Numeral.mk_cnumber cT a)) |
|
135 |
(Numeral.mk_cnumber cT b) |
|
136 |
end |
|
59549
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
137 |
in |
59548 | 138 |
{is_const = numeral_is_const, |
139 |
dest_const = dest_const, |
|
140 |
mk_const = mk_const, |
|
141 |
conv = Numeral_Simprocs.field_comp_conv} |
|
59539 | 142 |
end; |
143 |
||
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
144 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
145 |
(* logical content *) |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
146 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
147 |
val semiringN = "semiring"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
148 |
val ringN = "ring"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
149 |
val idomN = "idom"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
150 |
val idealN = "ideal"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
151 |
val fieldN = "field"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
152 |
|
36706 | 153 |
val del = Thm.declaration_attribute (Data.map o AList.delete Thm.eq_thm); |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
154 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
155 |
fun add {semiring = (sr_ops, sr_rules), ring = (r_ops, r_rules), |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
156 |
field = (f_ops, f_rules), idom, ideal} = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
157 |
Thm.declaration_attribute (fn key => fn context => context |> Data.map |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
158 |
let |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
159 |
val ctxt = Context.proof_of context; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
160 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
161 |
fun check kind name xs n = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
162 |
null xs orelse length xs = n orelse |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
163 |
error ("Expected " ^ string_of_int n ^ " " ^ kind ^ " for " ^ name); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
164 |
val check_ops = check "operations"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
165 |
val check_rules = check "rules"; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
166 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
167 |
val _ = |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
168 |
check_ops semiringN sr_ops 5 andalso |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
169 |
check_rules semiringN sr_rules 37 andalso |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
170 |
check_ops ringN r_ops 2 andalso |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
171 |
check_rules ringN r_rules 2 andalso |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
172 |
check_ops fieldN f_ops 2 andalso |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
173 |
check_rules fieldN f_rules 2 andalso |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
174 |
check_rules idomN idom 2; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
175 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
176 |
val mk_meta = Local_Defs.meta_rewrite_rule ctxt; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
177 |
val sr_rules' = map mk_meta sr_rules; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
178 |
val r_rules' = map mk_meta r_rules; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
179 |
val f_rules' = map mk_meta f_rules; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
180 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
181 |
fun rule i = nth sr_rules' (i - 1); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
182 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
183 |
val (cx, cy) = Thm.dest_binop (hd sr_ops); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
184 |
val cz = rule 34 |> Thm.rhs_of |> Thm.dest_arg |> Thm.dest_arg; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
185 |
val cn = rule 36 |> Thm.rhs_of |> Thm.dest_arg |> Thm.dest_arg; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
186 |
val ((clx, crx), (cly, cry)) = |
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58826
diff
changeset
|
187 |
rule 13 |> Thm.rhs_of |> Thm.dest_binop |> apply2 Thm.dest_binop; |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
188 |
val ((ca, cb), (cc, cd)) = |
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58826
diff
changeset
|
189 |
rule 20 |> Thm.lhs_of |> Thm.dest_binop |> apply2 Thm.dest_binop; |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
190 |
val cm = rule 1 |> Thm.rhs_of |> Thm.dest_arg; |
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58826
diff
changeset
|
191 |
val (cp, cq) = rule 26 |> Thm.lhs_of |> Thm.dest_binop |> apply2 Thm.dest_arg; |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
192 |
|
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
193 |
val vars = [ca, cb, cc, cd, cm, cn, cp, cq, cx, cy, cz, clx, crx, cly, cry]; |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
194 |
val semiring = (sr_ops, sr_rules'); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
195 |
val ring = (r_ops, r_rules'); |
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
196 |
val field = (f_ops, f_rules'); |
36945 | 197 |
val ideal' = map (Thm.symmetric o mk_meta) ideal |
59549
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
198 |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
199 |
in |
59539 | 200 |
AList.update Thm.eq_thm (key, |
201 |
({vars = vars, semiring = semiring, ring = ring, field = field, idom = idom, ideal = ideal'}, |
|
59549
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
202 |
(if null f_ops then semiring_funs else field_funs))) |
6e685f9c9aa5
more direct expression of syntactic function records
haftmann
parents:
59548
diff
changeset
|
203 |
end) |
36720 | 204 |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
205 |
|
36710 | 206 |
(** auxiliary **) |
25253 | 207 |
|
208 |
fun is_comb ct = |
|
209 |
(case Thm.term_of ct of |
|
210 |
_ $ _ => true |
|
211 |
| _ => false); |
|
212 |
||
213 |
val concl = Thm.cprop_of #> Thm.dest_arg; |
|
214 |
||
215 |
fun is_binop ct ct' = |
|
216 |
(case Thm.term_of ct' of |
|
217 |
c $ _ $ _ => term_of ct aconv c |
|
218 |
| _ => false); |
|
219 |
||
220 |
fun dest_binop ct ct' = |
|
221 |
if is_binop ct ct' then Thm.dest_binop ct' |
|
222 |
else raise CTERM ("dest_binop: bad binop", [ct, ct']) |
|
223 |
||
224 |
fun inst_thm inst = Thm.instantiate ([], inst); |
|
225 |
||
59538 | 226 |
val dest_number = term_of #> HOLogic.dest_number #> snd; |
227 |
val is_number = can dest_number; |
|
23252 | 228 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
229 |
fun numeral01_conv ctxt = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
230 |
Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps [@{thm numeral_1_eq_1}]); |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
231 |
|
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
232 |
fun zero1_numeral_conv ctxt = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
233 |
Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps [@{thm numeral_1_eq_1} RS sym]); |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
234 |
|
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
235 |
fun zerone_conv ctxt cv = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
236 |
zero1_numeral_conv ctxt then_conv cv then_conv numeral01_conv ctxt; |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
237 |
|
59547 | 238 |
val nat_add_ss = simpset_of |
239 |
(put_simpset HOL_basic_ss @{context} |
|
240 |
addsimps @{thms arith_simps} @ @{thms diff_nat_numeral} @ @{thms rel_simps} |
|
241 |
@ @{thms if_False if_True Nat.add_0 add_Suc add_numeral_left Suc_eq_plus1} |
|
242 |
@ map (fn th => th RS sym) @{thms numerals}); |
|
53078
cc06f17d8057
more static simpsets, which also avoids spurious warnings due to duplicate rules provided here;
wenzelm
parents:
51717
diff
changeset
|
243 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
244 |
fun nat_add_conv ctxt = |
53078
cc06f17d8057
more static simpsets, which also avoids spurious warnings due to duplicate rules provided here;
wenzelm
parents:
51717
diff
changeset
|
245 |
zerone_conv ctxt (Simplifier.rewrite (put_simpset nat_add_ss ctxt)); |
23252 | 246 |
|
247 |
val zeron_tm = @{cterm "0::nat"}; |
|
248 |
val onen_tm = @{cterm "1::nat"}; |
|
249 |
val true_tm = @{cterm "True"}; |
|
250 |
||
251 |
||
36710 | 252 |
(** normalizing conversions **) |
253 |
||
254 |
(* core conversion *) |
|
255 |
||
30866 | 256 |
fun semiring_normalizers_conv vars (sr_ops, sr_rules) (r_ops, r_rules) (f_ops, f_rules) |
23252 | 257 |
(is_semiring_constant, semiring_add_conv, semiring_mul_conv, semiring_pow_conv) = |
258 |
let |
|
259 |
||
260 |
val [pthm_02, pthm_03, pthm_04, pthm_05, pthm_07, pthm_08, |
|
261 |
pthm_09, pthm_10, pthm_11, pthm_12, pthm_13, pthm_14, pthm_15, pthm_16, |
|
262 |
pthm_17, pthm_18, pthm_19, pthm_21, pthm_22, pthm_23, pthm_24, |
|
263 |
pthm_25, pthm_26, pthm_27, pthm_28, pthm_29, pthm_30, pthm_31, pthm_32, |
|
59321 | 264 |
pthm_33, pthm_34, pthm_35, pthm_36, pthm_37, pthm_38, _, _] = sr_rules; |
23252 | 265 |
|
266 |
val [ca, cb, cc, cd, cm, cn, cp, cq, cx, cy, cz, clx, crx, cly, cry] = vars; |
|
267 |
val [add_pat, mul_pat, pow_pat, zero_tm, one_tm] = sr_ops; |
|
268 |
val [add_tm, mul_tm, pow_tm] = map (Thm.dest_fun o Thm.dest_fun) [add_pat, mul_pat, pow_pat]; |
|
269 |
||
270 |
val dest_add = dest_binop add_tm |
|
271 |
val dest_mul = dest_binop mul_tm |
|
272 |
fun dest_pow tm = |
|
273 |
let val (l,r) = dest_binop pow_tm tm |
|
59538 | 274 |
in if is_number r then (l,r) else raise CTERM ("dest_pow",[tm]) |
23252 | 275 |
end; |
276 |
val is_add = is_binop add_tm |
|
277 |
val is_mul = is_binop mul_tm |
|
278 |
||
59321 | 279 |
val (neg_mul, sub_add, sub_tm, neg_tm, dest_sub, cx', cy') = |
23252 | 280 |
(case (r_ops, r_rules) of |
30866 | 281 |
([sub_pat, neg_pat], [neg_mul, sub_add]) => |
23252 | 282 |
let |
283 |
val sub_tm = Thm.dest_fun (Thm.dest_fun sub_pat) |
|
284 |
val neg_tm = Thm.dest_fun neg_pat |
|
285 |
val dest_sub = dest_binop sub_tm |
|
59321 | 286 |
in (neg_mul,sub_add,sub_tm,neg_tm,dest_sub, neg_mul |> concl |> Thm.dest_arg, |
23252 | 287 |
sub_add |> concl |> Thm.dest_arg |> Thm.dest_arg) |
30866 | 288 |
end |
59321 | 289 |
| _ => (TrueI, TrueI, true_tm, true_tm, (fn t => (t,t)), true_tm, true_tm)); |
30866 | 290 |
|
59321 | 291 |
val (divide_inverse, divide_tm, inverse_tm) = |
30866 | 292 |
(case (f_ops, f_rules) of |
59321 | 293 |
([divide_pat, inverse_pat], [div_inv, _]) => |
30866 | 294 |
let val div_tm = funpow 2 Thm.dest_fun divide_pat |
295 |
val inv_tm = Thm.dest_fun inverse_pat |
|
59321 | 296 |
in (div_inv, div_tm, inv_tm) |
30866 | 297 |
end |
59321 | 298 |
| _ => (TrueI, true_tm, true_tm)); |
30866 | 299 |
|
23252 | 300 |
in fn variable_order => |
301 |
let |
|
302 |
||
303 |
(* Conversion for "x^n * x^m", with either x^n = x and/or x^m = x possible. *) |
|
304 |
(* Also deals with "const * const", but both terms must involve powers of *) |
|
305 |
(* the same variable, or both be constants, or behaviour may be incorrect. *) |
|
306 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
307 |
fun powvar_mul_conv ctxt tm = |
23252 | 308 |
let |
309 |
val (l,r) = dest_mul tm |
|
310 |
in if is_semiring_constant l andalso is_semiring_constant r |
|
311 |
then semiring_mul_conv tm |
|
312 |
else |
|
313 |
((let |
|
314 |
val (lx,ln) = dest_pow l |
|
315 |
in |
|
59321 | 316 |
((let val (_, rn) = dest_pow r |
23252 | 317 |
val th1 = inst_thm [(cx,lx),(cp,ln),(cq,rn)] pthm_29 |
318 |
val (tm1,tm2) = Thm.dest_comb(concl th1) in |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
319 |
Thm.transitive th1 (Drule.arg_cong_rule tm1 (nat_add_conv ctxt tm2)) end) |
23252 | 320 |
handle CTERM _ => |
321 |
(let val th1 = inst_thm [(cx,lx),(cq,ln)] pthm_31 |
|
322 |
val (tm1,tm2) = Thm.dest_comb(concl th1) in |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
323 |
Thm.transitive th1 (Drule.arg_cong_rule tm1 (nat_add_conv ctxt tm2)) end)) end) |
23252 | 324 |
handle CTERM _ => |
325 |
((let val (rx,rn) = dest_pow r |
|
326 |
val th1 = inst_thm [(cx,rx),(cq,rn)] pthm_30 |
|
327 |
val (tm1,tm2) = Thm.dest_comb(concl th1) in |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
328 |
Thm.transitive th1 (Drule.arg_cong_rule tm1 (nat_add_conv ctxt tm2)) end) |
23252 | 329 |
handle CTERM _ => inst_thm [(cx,l)] pthm_32 |
330 |
||
331 |
)) |
|
332 |
end; |
|
333 |
||
334 |
(* Remove "1 * m" from a monomial, and just leave m. *) |
|
335 |
||
336 |
fun monomial_deone th = |
|
337 |
(let val (l,r) = dest_mul(concl th) in |
|
338 |
if l aconvc one_tm |
|
36945 | 339 |
then Thm.transitive th (inst_thm [(ca,r)] pthm_13) else th end) |
23252 | 340 |
handle CTERM _ => th; |
341 |
||
342 |
(* Conversion for "(monomial)^n", where n is a numeral. *) |
|
343 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
344 |
fun monomial_pow_conv ctxt = |
23252 | 345 |
let |
346 |
fun monomial_pow tm bod ntm = |
|
347 |
if not(is_comb bod) |
|
36945 | 348 |
then Thm.reflexive tm |
23252 | 349 |
else |
350 |
if is_semiring_constant bod |
|
351 |
then semiring_pow_conv tm |
|
352 |
else |
|
353 |
let |
|
354 |
val (lopr,r) = Thm.dest_comb bod |
|
355 |
in if not(is_comb lopr) |
|
36945 | 356 |
then Thm.reflexive tm |
23252 | 357 |
else |
358 |
let |
|
359 |
val (opr,l) = Thm.dest_comb lopr |
|
360 |
in |
|
59538 | 361 |
if opr aconvc pow_tm andalso is_number r |
23252 | 362 |
then |
363 |
let val th1 = inst_thm [(cx,l),(cp,r),(cq,ntm)] pthm_34 |
|
364 |
val (l,r) = Thm.dest_comb(concl th1) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
365 |
in Thm.transitive th1 (Drule.arg_cong_rule l (nat_add_conv ctxt r)) |
23252 | 366 |
end |
367 |
else |
|
368 |
if opr aconvc mul_tm |
|
369 |
then |
|
370 |
let |
|
371 |
val th1 = inst_thm [(cx,l),(cy,r),(cq,ntm)] pthm_33 |
|
372 |
val (xy,z) = Thm.dest_comb(concl th1) |
|
373 |
val (x,y) = Thm.dest_comb xy |
|
374 |
val thl = monomial_pow y l ntm |
|
375 |
val thr = monomial_pow z r ntm |
|
36945 | 376 |
in Thm.transitive th1 (Thm.combination (Drule.arg_cong_rule x thl) thr) |
23252 | 377 |
end |
36945 | 378 |
else Thm.reflexive tm |
23252 | 379 |
end |
380 |
end |
|
381 |
in fn tm => |
|
382 |
let |
|
383 |
val (lopr,r) = Thm.dest_comb tm |
|
384 |
val (opr,l) = Thm.dest_comb lopr |
|
59538 | 385 |
in if not (opr aconvc pow_tm) orelse not(is_number r) |
23252 | 386 |
then raise CTERM ("monomial_pow_conv", [tm]) |
387 |
else if r aconvc zeron_tm |
|
388 |
then inst_thm [(cx,l)] pthm_35 |
|
389 |
else if r aconvc onen_tm |
|
390 |
then inst_thm [(cx,l)] pthm_36 |
|
391 |
else monomial_deone(monomial_pow tm l r) |
|
392 |
end |
|
393 |
end; |
|
394 |
||
395 |
(* Multiplication of canonical monomials. *) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
396 |
fun monomial_mul_conv ctxt = |
23252 | 397 |
let |
398 |
fun powvar tm = |
|
399 |
if is_semiring_constant tm then one_tm |
|
400 |
else |
|
401 |
((let val (lopr,r) = Thm.dest_comb tm |
|
402 |
val (opr,l) = Thm.dest_comb lopr |
|
59538 | 403 |
in if opr aconvc pow_tm andalso is_number r then l |
23252 | 404 |
else raise CTERM ("monomial_mul_conv",[tm]) end) |
405 |
handle CTERM _ => tm) (* FIXME !? *) |
|
406 |
fun vorder x y = |
|
407 |
if x aconvc y then 0 |
|
408 |
else |
|
409 |
if x aconvc one_tm then ~1 |
|
410 |
else if y aconvc one_tm then 1 |
|
411 |
else if variable_order x y then ~1 else 1 |
|
412 |
fun monomial_mul tm l r = |
|
413 |
((let val (lx,ly) = dest_mul l val vl = powvar lx |
|
414 |
in |
|
415 |
((let |
|
416 |
val (rx,ry) = dest_mul r |
|
417 |
val vr = powvar rx |
|
418 |
val ord = vorder vl vr |
|
419 |
in |
|
420 |
if ord = 0 |
|
421 |
then |
|
422 |
let |
|
423 |
val th1 = inst_thm [(clx,lx),(cly,ly),(crx,rx),(cry,ry)] pthm_15 |
|
424 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
425 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
426 |
val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (powvar_mul_conv ctxt tm4)) tm2 |
36945 | 427 |
val th3 = Thm.transitive th1 th2 |
23252 | 428 |
val (tm5,tm6) = Thm.dest_comb(concl th3) |
429 |
val (tm7,tm8) = Thm.dest_comb tm6 |
|
430 |
val th4 = monomial_mul tm6 (Thm.dest_arg tm7) tm8 |
|
36945 | 431 |
in Thm.transitive th3 (Drule.arg_cong_rule tm5 th4) |
23252 | 432 |
end |
433 |
else |
|
434 |
let val th0 = if ord < 0 then pthm_16 else pthm_17 |
|
435 |
val th1 = inst_thm [(clx,lx),(cly,ly),(crx,rx),(cry,ry)] th0 |
|
436 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
437 |
val (tm3,tm4) = Thm.dest_comb tm2 |
|
36945 | 438 |
in Thm.transitive th1 (Drule.arg_cong_rule tm1 (monomial_mul tm2 (Thm.dest_arg tm3) tm4)) |
23252 | 439 |
end |
440 |
end) |
|
441 |
handle CTERM _ => |
|
442 |
(let val vr = powvar r val ord = vorder vl vr |
|
443 |
in |
|
444 |
if ord = 0 then |
|
445 |
let |
|
446 |
val th1 = inst_thm [(clx,lx),(cly,ly),(crx,r)] pthm_18 |
|
447 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
448 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
449 |
val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (powvar_mul_conv ctxt tm4)) tm2 |
36945 | 450 |
in Thm.transitive th1 th2 |
23252 | 451 |
end |
452 |
else |
|
453 |
if ord < 0 then |
|
454 |
let val th1 = inst_thm [(clx,lx),(cly,ly),(crx,r)] pthm_19 |
|
455 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
456 |
val (tm3,tm4) = Thm.dest_comb tm2 |
|
36945 | 457 |
in Thm.transitive th1 (Drule.arg_cong_rule tm1 (monomial_mul tm2 (Thm.dest_arg tm3) tm4)) |
23252 | 458 |
end |
459 |
else inst_thm [(ca,l),(cb,r)] pthm_09 |
|
460 |
end)) end) |
|
461 |
handle CTERM _ => |
|
462 |
(let val vl = powvar l in |
|
463 |
((let |
|
464 |
val (rx,ry) = dest_mul r |
|
465 |
val vr = powvar rx |
|
466 |
val ord = vorder vl vr |
|
467 |
in if ord = 0 then |
|
468 |
let val th1 = inst_thm [(clx,l),(crx,rx),(cry,ry)] pthm_21 |
|
469 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
470 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
471 |
in Thm.transitive th1 (Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (powvar_mul_conv ctxt tm4)) tm2) |
23252 | 472 |
end |
473 |
else if ord > 0 then |
|
474 |
let val th1 = inst_thm [(clx,l),(crx,rx),(cry,ry)] pthm_22 |
|
475 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
476 |
val (tm3,tm4) = Thm.dest_comb tm2 |
|
36945 | 477 |
in Thm.transitive th1 (Drule.arg_cong_rule tm1 (monomial_mul tm2 (Thm.dest_arg tm3) tm4)) |
23252 | 478 |
end |
36945 | 479 |
else Thm.reflexive tm |
23252 | 480 |
end) |
481 |
handle CTERM _ => |
|
482 |
(let val vr = powvar r |
|
483 |
val ord = vorder vl vr |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
484 |
in if ord = 0 then powvar_mul_conv ctxt tm |
23252 | 485 |
else if ord > 0 then inst_thm [(ca,l),(cb,r)] pthm_09 |
36945 | 486 |
else Thm.reflexive tm |
23252 | 487 |
end)) end)) |
488 |
in fn tm => let val (l,r) = dest_mul tm in monomial_deone(monomial_mul tm l r) |
|
489 |
end |
|
490 |
end; |
|
491 |
(* Multiplication by monomial of a polynomial. *) |
|
492 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
493 |
fun polynomial_monomial_mul_conv ctxt = |
23252 | 494 |
let |
495 |
fun pmm_conv tm = |
|
496 |
let val (l,r) = dest_mul tm |
|
497 |
in |
|
498 |
((let val (y,z) = dest_add r |
|
499 |
val th1 = inst_thm [(cx,l),(cy,y),(cz,z)] pthm_37 |
|
500 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
501 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
502 |
val th2 = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
503 |
Thm.combination (Drule.arg_cong_rule tm3 (monomial_mul_conv ctxt tm4)) (pmm_conv tm2) |
36945 | 504 |
in Thm.transitive th1 th2 |
23252 | 505 |
end) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
506 |
handle CTERM _ => monomial_mul_conv ctxt tm) |
23252 | 507 |
end |
508 |
in pmm_conv |
|
509 |
end; |
|
510 |
||
511 |
(* Addition of two monomials identical except for constant multiples. *) |
|
512 |
||
513 |
fun monomial_add_conv tm = |
|
514 |
let val (l,r) = dest_add tm |
|
515 |
in if is_semiring_constant l andalso is_semiring_constant r |
|
516 |
then semiring_add_conv tm |
|
517 |
else |
|
518 |
let val th1 = |
|
519 |
if is_mul l andalso is_semiring_constant(Thm.dest_arg1 l) |
|
520 |
then if is_mul r andalso is_semiring_constant(Thm.dest_arg1 r) then |
|
521 |
inst_thm [(ca,Thm.dest_arg1 l),(cm,Thm.dest_arg r), (cb,Thm.dest_arg1 r)] pthm_02 |
|
522 |
else inst_thm [(ca,Thm.dest_arg1 l),(cm,r)] pthm_03 |
|
523 |
else if is_mul r andalso is_semiring_constant(Thm.dest_arg1 r) |
|
524 |
then inst_thm [(cm,l),(ca,Thm.dest_arg1 r)] pthm_04 |
|
525 |
else inst_thm [(cm,r)] pthm_05 |
|
526 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
527 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
528 |
val th2 = Drule.arg_cong_rule tm3 (semiring_add_conv tm4) |
|
36945 | 529 |
val th3 = Thm.transitive th1 (Drule.fun_cong_rule th2 tm2) |
23252 | 530 |
val tm5 = concl th3 |
531 |
in |
|
532 |
if (Thm.dest_arg1 tm5) aconvc zero_tm |
|
36945 | 533 |
then Thm.transitive th3 (inst_thm [(ca,Thm.dest_arg tm5)] pthm_11) |
23252 | 534 |
else monomial_deone th3 |
535 |
end |
|
536 |
end; |
|
537 |
||
538 |
(* Ordering on monomials. *) |
|
539 |
||
540 |
fun striplist dest = |
|
541 |
let fun strip x acc = |
|
542 |
((let val (l,r) = dest x in |
|
543 |
strip l (strip r acc) end) |
|
544 |
handle CTERM _ => x::acc) (* FIXME !? *) |
|
545 |
in fn x => strip x [] |
|
546 |
end; |
|
547 |
||
548 |
||
549 |
fun powervars tm = |
|
550 |
let val ptms = striplist dest_mul tm |
|
551 |
in if is_semiring_constant (hd ptms) then tl ptms else ptms |
|
552 |
end; |
|
553 |
val num_0 = 0; |
|
554 |
val num_1 = 1; |
|
555 |
fun dest_varpow tm = |
|
59538 | 556 |
((let val (x,n) = dest_pow tm in (x,dest_number n) end) |
23252 | 557 |
handle CTERM _ => |
558 |
(tm,(if is_semiring_constant tm then num_0 else num_1))); |
|
559 |
||
560 |
val morder = |
|
561 |
let fun lexorder l1 l2 = |
|
562 |
case (l1,l2) of |
|
563 |
([],[]) => 0 |
|
59321 | 564 |
| (_ ,[]) => ~1 |
565 |
| ([], _) => 1 |
|
23252 | 566 |
| (((x1,n1)::vs1),((x2,n2)::vs2)) => |
567 |
if variable_order x1 x2 then 1 |
|
568 |
else if variable_order x2 x1 then ~1 |
|
569 |
else if n1 < n2 then ~1 |
|
570 |
else if n2 < n1 then 1 |
|
571 |
else lexorder vs1 vs2 |
|
572 |
in fn tm1 => fn tm2 => |
|
573 |
let val vdegs1 = map dest_varpow (powervars tm1) |
|
574 |
val vdegs2 = map dest_varpow (powervars tm2) |
|
33002 | 575 |
val deg1 = fold (Integer.add o snd) vdegs1 num_0 |
576 |
val deg2 = fold (Integer.add o snd) vdegs2 num_0 |
|
23252 | 577 |
in if deg1 < deg2 then ~1 else if deg1 > deg2 then 1 |
578 |
else lexorder vdegs1 vdegs2 |
|
579 |
end |
|
580 |
end; |
|
581 |
||
582 |
(* Addition of two polynomials. *) |
|
583 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
584 |
fun polynomial_add_conv ctxt = |
23252 | 585 |
let |
586 |
fun dezero_rule th = |
|
587 |
let |
|
588 |
val tm = concl th |
|
589 |
in |
|
590 |
if not(is_add tm) then th else |
|
591 |
let val (lopr,r) = Thm.dest_comb tm |
|
592 |
val l = Thm.dest_arg lopr |
|
593 |
in |
|
594 |
if l aconvc zero_tm |
|
36945 | 595 |
then Thm.transitive th (inst_thm [(ca,r)] pthm_07) else |
23252 | 596 |
if r aconvc zero_tm |
36945 | 597 |
then Thm.transitive th (inst_thm [(ca,l)] pthm_08) else th |
23252 | 598 |
end |
599 |
end |
|
600 |
fun padd tm = |
|
601 |
let |
|
602 |
val (l,r) = dest_add tm |
|
603 |
in |
|
604 |
if l aconvc zero_tm then inst_thm [(ca,r)] pthm_07 |
|
605 |
else if r aconvc zero_tm then inst_thm [(ca,l)] pthm_08 |
|
606 |
else |
|
607 |
if is_add l |
|
608 |
then |
|
609 |
let val (a,b) = dest_add l |
|
610 |
in |
|
611 |
if is_add r then |
|
612 |
let val (c,d) = dest_add r |
|
613 |
val ord = morder a c |
|
614 |
in |
|
615 |
if ord = 0 then |
|
616 |
let val th1 = inst_thm [(ca,a),(cb,b),(cc,c),(cd,d)] pthm_23 |
|
617 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
618 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
619 |
val th2 = Drule.arg_cong_rule tm3 (monomial_add_conv tm4) |
|
36945 | 620 |
in dezero_rule (Thm.transitive th1 (Thm.combination th2 (padd tm2))) |
23252 | 621 |
end |
622 |
else (* ord <> 0*) |
|
623 |
let val th1 = |
|
624 |
if ord > 0 then inst_thm [(ca,a),(cb,b),(cc,r)] pthm_24 |
|
625 |
else inst_thm [(ca,l),(cc,c),(cd,d)] pthm_25 |
|
626 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
36945 | 627 |
in dezero_rule (Thm.transitive th1 (Drule.arg_cong_rule tm1 (padd tm2))) |
23252 | 628 |
end |
629 |
end |
|
630 |
else (* not (is_add r)*) |
|
631 |
let val ord = morder a r |
|
632 |
in |
|
633 |
if ord = 0 then |
|
634 |
let val th1 = inst_thm [(ca,a),(cb,b),(cc,r)] pthm_26 |
|
635 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
636 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
637 |
val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (monomial_add_conv tm4)) tm2 |
|
36945 | 638 |
in dezero_rule (Thm.transitive th1 th2) |
23252 | 639 |
end |
640 |
else (* ord <> 0*) |
|
641 |
if ord > 0 then |
|
642 |
let val th1 = inst_thm [(ca,a),(cb,b),(cc,r)] pthm_24 |
|
643 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
36945 | 644 |
in dezero_rule (Thm.transitive th1 (Drule.arg_cong_rule tm1 (padd tm2))) |
23252 | 645 |
end |
646 |
else dezero_rule (inst_thm [(ca,l),(cc,r)] pthm_27) |
|
647 |
end |
|
648 |
end |
|
649 |
else (* not (is_add l)*) |
|
650 |
if is_add r then |
|
651 |
let val (c,d) = dest_add r |
|
652 |
val ord = morder l c |
|
653 |
in |
|
654 |
if ord = 0 then |
|
655 |
let val th1 = inst_thm [(ca,l),(cc,c),(cd,d)] pthm_28 |
|
656 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
657 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
658 |
val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (monomial_add_conv tm4)) tm2 |
|
36945 | 659 |
in dezero_rule (Thm.transitive th1 th2) |
23252 | 660 |
end |
661 |
else |
|
36945 | 662 |
if ord > 0 then Thm.reflexive tm |
23252 | 663 |
else |
664 |
let val th1 = inst_thm [(ca,l),(cc,c),(cd,d)] pthm_25 |
|
665 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
36945 | 666 |
in dezero_rule (Thm.transitive th1 (Drule.arg_cong_rule tm1 (padd tm2))) |
23252 | 667 |
end |
668 |
end |
|
669 |
else |
|
670 |
let val ord = morder l r |
|
671 |
in |
|
672 |
if ord = 0 then monomial_add_conv tm |
|
36945 | 673 |
else if ord > 0 then dezero_rule(Thm.reflexive tm) |
23252 | 674 |
else dezero_rule (inst_thm [(ca,l),(cc,r)] pthm_27) |
675 |
end |
|
676 |
end |
|
677 |
in padd |
|
678 |
end; |
|
679 |
||
680 |
(* Multiplication of two polynomials. *) |
|
681 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
682 |
fun polynomial_mul_conv ctxt = |
23252 | 683 |
let |
684 |
fun pmul tm = |
|
685 |
let val (l,r) = dest_mul tm |
|
686 |
in |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
687 |
if not(is_add l) then polynomial_monomial_mul_conv ctxt tm |
23252 | 688 |
else |
689 |
if not(is_add r) then |
|
690 |
let val th1 = inst_thm [(ca,l),(cb,r)] pthm_09 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
691 |
in Thm.transitive th1 (polynomial_monomial_mul_conv ctxt (concl th1)) |
23252 | 692 |
end |
693 |
else |
|
694 |
let val (a,b) = dest_add l |
|
695 |
val th1 = inst_thm [(ca,a),(cb,b),(cc,r)] pthm_10 |
|
696 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
697 |
val (tm3,tm4) = Thm.dest_comb tm1 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
698 |
val th2 = Drule.arg_cong_rule tm3 (polynomial_monomial_mul_conv ctxt tm4) |
36945 | 699 |
val th3 = Thm.transitive th1 (Thm.combination th2 (pmul tm2)) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
700 |
in Thm.transitive th3 (polynomial_add_conv ctxt (concl th3)) |
23252 | 701 |
end |
702 |
end |
|
703 |
in fn tm => |
|
704 |
let val (l,r) = dest_mul tm |
|
705 |
in |
|
706 |
if l aconvc zero_tm then inst_thm [(ca,r)] pthm_11 |
|
707 |
else if r aconvc zero_tm then inst_thm [(ca,l)] pthm_12 |
|
708 |
else if l aconvc one_tm then inst_thm [(ca,r)] pthm_13 |
|
709 |
else if r aconvc one_tm then inst_thm [(ca,l)] pthm_14 |
|
710 |
else pmul tm |
|
711 |
end |
|
712 |
end; |
|
713 |
||
714 |
(* Power of polynomial (optimized for the monomial and trivial cases). *) |
|
715 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
716 |
fun num_conv ctxt n = |
59538 | 717 |
nat_add_conv ctxt (Thm.apply @{cterm Suc} (Numeral.mk_cnumber @{ctyp nat} (dest_number n - 1))) |
23580
998a6fda9bb6
moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents:
23559
diff
changeset
|
718 |
|> Thm.symmetric; |
23252 | 719 |
|
720 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
721 |
fun polynomial_pow_conv ctxt = |
23252 | 722 |
let |
723 |
fun ppow tm = |
|
724 |
let val (l,n) = dest_pow tm |
|
725 |
in |
|
726 |
if n aconvc zeron_tm then inst_thm [(cx,l)] pthm_35 |
|
727 |
else if n aconvc onen_tm then inst_thm [(cx,l)] pthm_36 |
|
728 |
else |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
729 |
let val th1 = num_conv ctxt n |
23252 | 730 |
val th2 = inst_thm [(cx,l),(cq,Thm.dest_arg (concl th1))] pthm_38 |
731 |
val (tm1,tm2) = Thm.dest_comb(concl th2) |
|
36945 | 732 |
val th3 = Thm.transitive th2 (Drule.arg_cong_rule tm1 (ppow tm2)) |
733 |
val th4 = Thm.transitive (Drule.arg_cong_rule (Thm.dest_fun tm) th1) th3 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
734 |
in Thm.transitive th4 (polynomial_mul_conv ctxt (concl th4)) |
23252 | 735 |
end |
736 |
end |
|
737 |
in fn tm => |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
738 |
if is_add(Thm.dest_arg1 tm) then ppow tm else monomial_pow_conv ctxt tm |
23252 | 739 |
end; |
740 |
||
741 |
(* Negation. *) |
|
742 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
743 |
fun polynomial_neg_conv ctxt tm = |
23252 | 744 |
let val (l,r) = Thm.dest_comb tm in |
745 |
if not (l aconvc neg_tm) then raise CTERM ("polynomial_neg_conv",[tm]) else |
|
746 |
let val th1 = inst_thm [(cx',r)] neg_mul |
|
36945 | 747 |
val th2 = Thm.transitive th1 (Conv.arg1_conv semiring_mul_conv (concl th1)) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
748 |
in Thm.transitive th2 (polynomial_monomial_mul_conv ctxt (concl th2)) |
23252 | 749 |
end |
750 |
end; |
|
751 |
||
752 |
||
753 |
(* Subtraction. *) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
754 |
fun polynomial_sub_conv ctxt tm = |
23252 | 755 |
let val (l,r) = dest_sub tm |
756 |
val th1 = inst_thm [(cx',l),(cy',r)] sub_add |
|
757 |
val (tm1,tm2) = Thm.dest_comb(concl th1) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
758 |
val th2 = Drule.arg_cong_rule tm1 (polynomial_neg_conv ctxt tm2) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
759 |
in Thm.transitive th1 (Thm.transitive th2 (polynomial_add_conv ctxt (concl th2))) |
23252 | 760 |
end; |
761 |
||
762 |
(* Conversion from HOL term. *) |
|
763 |
||
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
764 |
fun polynomial_conv ctxt tm = |
23407
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
765 |
if is_semiring_constant tm then semiring_add_conv tm |
36945 | 766 |
else if not(is_comb tm) then Thm.reflexive tm |
23252 | 767 |
else |
768 |
let val (lopr,r) = Thm.dest_comb tm |
|
769 |
in if lopr aconvc neg_tm then |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
770 |
let val th1 = Drule.arg_cong_rule lopr (polynomial_conv ctxt r) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
771 |
in Thm.transitive th1 (polynomial_neg_conv ctxt (concl th1)) |
23252 | 772 |
end |
30866 | 773 |
else if lopr aconvc inverse_tm then |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
774 |
let val th1 = Drule.arg_cong_rule lopr (polynomial_conv ctxt r) |
36945 | 775 |
in Thm.transitive th1 (semiring_mul_conv (concl th1)) |
30866 | 776 |
end |
23252 | 777 |
else |
36945 | 778 |
if not(is_comb lopr) then Thm.reflexive tm |
23252 | 779 |
else |
780 |
let val (opr,l) = Thm.dest_comb lopr |
|
59538 | 781 |
in if opr aconvc pow_tm andalso is_number r |
23252 | 782 |
then |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
783 |
let val th1 = Drule.fun_cong_rule (Drule.arg_cong_rule opr (polynomial_conv ctxt l)) r |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
784 |
in Thm.transitive th1 (polynomial_pow_conv ctxt (concl th1)) |
23252 | 785 |
end |
30866 | 786 |
else if opr aconvc divide_tm |
787 |
then |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
788 |
let val th1 = Thm.combination (Drule.arg_cong_rule opr (polynomial_conv ctxt l)) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
789 |
(polynomial_conv ctxt r) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
790 |
val th2 = (Conv.rewr_conv divide_inverse then_conv polynomial_mul_conv ctxt) |
30866 | 791 |
(Thm.rhs_of th1) |
36945 | 792 |
in Thm.transitive th1 th2 |
30866 | 793 |
end |
23252 | 794 |
else |
795 |
if opr aconvc add_tm orelse opr aconvc mul_tm orelse opr aconvc sub_tm |
|
796 |
then |
|
36945 | 797 |
let val th1 = |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
798 |
Thm.combination |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
799 |
(Drule.arg_cong_rule opr (polynomial_conv ctxt l)) (polynomial_conv ctxt r) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
800 |
val f = if opr aconvc add_tm then polynomial_add_conv ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
801 |
else if opr aconvc mul_tm then polynomial_mul_conv ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
802 |
else polynomial_sub_conv ctxt |
36945 | 803 |
in Thm.transitive th1 (f (concl th1)) |
23252 | 804 |
end |
36945 | 805 |
else Thm.reflexive tm |
23252 | 806 |
end |
807 |
end; |
|
808 |
in |
|
809 |
{main = polynomial_conv, |
|
810 |
add = polynomial_add_conv, |
|
811 |
mul = polynomial_mul_conv, |
|
812 |
pow = polynomial_pow_conv, |
|
813 |
neg = polynomial_neg_conv, |
|
814 |
sub = polynomial_sub_conv} |
|
815 |
end |
|
816 |
end; |
|
817 |
||
35410 | 818 |
val nat_exp_ss = |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
819 |
simpset_of |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
820 |
(put_simpset HOL_basic_ss @{context} |
54249 | 821 |
addsimps (@{thms eval_nat_numeral} @ @{thms diff_nat_numeral} @ @{thms arith_simps} @ @{thms rel_simps}) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
822 |
addsimps [@{thm Let_def}, @{thm if_False}, @{thm if_True}, @{thm Nat.add_0}, @{thm add_Suc}]); |
23252 | 823 |
|
35408 | 824 |
fun simple_cterm_ord t u = Term_Ord.term_ord (term_of t, term_of u) = LESS; |
27222 | 825 |
|
36710 | 826 |
|
827 |
(* various normalizing conversions *) |
|
828 |
||
30866 | 829 |
fun semiring_normalizers_ord_wrapper ctxt ({vars, semiring, ring, field, idom, ideal}, |
23407
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
830 |
{conv, dest_const, mk_const, is_const}) ord = |
23252 | 831 |
let |
832 |
val pow_conv = |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
833 |
Conv.arg_conv (Simplifier.rewrite (put_simpset nat_exp_ss ctxt)) |
23252 | 834 |
then_conv Simplifier.rewrite |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
835 |
(put_simpset HOL_basic_ss ctxt addsimps [nth (snd semiring) 31, nth (snd semiring) 34]) |
23330
01c09922ce59
Conversion for computation on constants now depends on the context
chaieb
parents:
23259
diff
changeset
|
836 |
then_conv conv ctxt |
01c09922ce59
Conversion for computation on constants now depends on the context
chaieb
parents:
23259
diff
changeset
|
837 |
val dat = (is_const, conv ctxt, conv ctxt, pow_conv) |
30866 | 838 |
in semiring_normalizers_conv vars semiring ring field dat ord end; |
27222 | 839 |
|
30866 | 840 |
fun semiring_normalize_ord_wrapper ctxt ({vars, semiring, ring, field, idom, ideal}, {conv, dest_const, mk_const, is_const}) ord = |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
841 |
#main (semiring_normalizers_ord_wrapper ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
842 |
({vars = vars, semiring = semiring, ring = ring, field = field, idom = idom, ideal = ideal}, |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47108
diff
changeset
|
843 |
{conv = conv, dest_const = dest_const, mk_const = mk_const, is_const = is_const}) ord) ctxt; |
23252 | 844 |
|
23407
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
845 |
fun semiring_normalize_wrapper ctxt data = |
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
846 |
semiring_normalize_ord_wrapper ctxt data simple_cterm_ord; |
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
847 |
|
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
848 |
fun semiring_normalize_ord_conv ctxt ord tm = |
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
849 |
(case match ctxt tm of |
36945 | 850 |
NONE => Thm.reflexive tm |
23407
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
851 |
| SOME res => semiring_normalize_ord_wrapper ctxt res ord tm); |
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
852 |
|
0e4452fcbeb8
normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents:
23330
diff
changeset
|
853 |
fun semiring_normalize_conv ctxt = semiring_normalize_ord_conv ctxt simple_cterm_ord; |
23252 | 854 |
|
36708 | 855 |
|
856 |
(** Isar setup **) |
|
857 |
||
858 |
local |
|
859 |
||
860 |
fun keyword2 k1 k2 = Scan.lift (Args.$$$ k1 -- Args.$$$ k2 -- Args.colon) >> K (); |
|
861 |
||
862 |
val opsN = "ops"; |
|
863 |
val rulesN = "rules"; |
|
864 |
||
865 |
val delN = "del"; |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
866 |
|
36708 | 867 |
val any_keyword = |
868 |
keyword2 semiringN opsN || keyword2 semiringN rulesN || |
|
869 |
keyword2 ringN opsN || keyword2 ringN rulesN || |
|
870 |
keyword2 fieldN opsN || keyword2 fieldN rulesN || |
|
871 |
keyword2 idomN rulesN || keyword2 idealN rulesN; |
|
872 |
||
873 |
val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat; |
|
874 |
val terms = thms >> map Drule.dest_term; |
|
875 |
||
876 |
fun optional scan = Scan.optional scan []; |
|
877 |
||
878 |
in |
|
879 |
||
58826 | 880 |
val _ = |
881 |
Theory.setup |
|
882 |
(Attrib.setup @{binding normalizer} |
|
883 |
(Scan.lift (Args.$$$ delN >> K del) || |
|
884 |
((keyword2 semiringN opsN |-- terms) -- |
|
885 |
(keyword2 semiringN rulesN |-- thms)) -- |
|
886 |
(optional (keyword2 ringN opsN |-- terms) -- |
|
887 |
optional (keyword2 ringN rulesN |-- thms)) -- |
|
888 |
(optional (keyword2 fieldN opsN |-- terms) -- |
|
889 |
optional (keyword2 fieldN rulesN |-- thms)) -- |
|
890 |
optional (keyword2 idomN rulesN |-- thms) -- |
|
891 |
optional (keyword2 idealN rulesN |-- thms) |
|
892 |
>> (fn ((((sr, r), f), id), idl) => |
|
893 |
add {semiring = sr, ring = r, field = f, idom = id, ideal = idl})) |
|
894 |
"semiring normalizer data"); |
|
36700
9b85b9d74b83
dropped auxiliary method sring_norm; integrated normalizer.ML and normalizer_data.ML
haftmann
parents:
35410
diff
changeset
|
895 |
|
23252 | 896 |
end; |
36708 | 897 |
|
898 |
end; |