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