112 end) |
117 end) |
113 (* simplify asumptions until one evaluates to false, store intermined's (x~=0)*) |
118 (* simplify asumptions until one evaluates to false, store intermined's (x~=0)*) |
114 and eval__true thy i asms bdv rls = |
119 and eval__true thy i asms bdv rls = |
115 if asms = [@{term True}] orelse asms = [] then ([], true) |
120 if asms = [@{term True}] orelse asms = [] then ([], true) |
116 (* this allows to check Rrls with prepat = ([@{term True}], pat) *) |
121 (* this allows to check Rrls with prepat = ([@{term True}], pat) *) |
117 else if asms = [@{term False}] then ([], false) |
122 else if asms = [@{term False}] then ([], false) else |
118 else |
|
119 let |
123 let |
120 fun chk indets [] = (indets, true)(*return asms<>True until false*) |
124 fun chk indets [] = (indets, true)(*return asms<>True until false*) |
121 | chk indets (a::asms) = |
125 | chk indets (a::asms) = |
122 (case rewrite__set_ thy (i+1) false bdv rls a of |
126 (case rewrite__set_ thy (i + 1) false bdv rls a of |
123 NONE => (chk (indets @ [a]) asms) |
127 NONE => (chk (indets @ [a]) asms) |
124 | SOME (t, a') => |
128 | SOME (t, a') => |
125 if t = @{term True} then (chk (indets @ a') asms) |
129 if t = @{term True} then (chk (indets @ a') asms) |
126 else if t = @{term False} then ([], false) |
130 else if t = @{term False} then ([], false) |
127 (*asm false .. thm not applied ^^^; continue until False vvv*) |
131 (*asm false .. thm not applied ^^^; continue until False vvv*) |
128 else chk (indets @ [t] @ a') asms); |
132 else chk (indets @ [t] @ a') asms); |
129 in chk [] asms end |
133 in chk [] asms end |
130 (* rewrite with a rule set, which must not be the empty Erls *) |
134 (* rewrite with a rule set, which must not be the empty Erls *) |
131 and rewrite__set_ _ _ __ Erls t = |
135 and rewrite__set_ _ _ __ Erls t = |
132 error("rewrite__set_ called with 'Erls' for '"^term2str t^"'") |
136 error ("rewrite__set_ called with 'Erls' for '" ^ term2str t ^ "'") |
133 (* rewrite with a 'reverse rule set' implemented by ML code *) |
137 (* rewrite with a 'reverse rule set' implemented by ML code *) |
134 | rewrite__set_ thy i _ _ (rrls as Rrls _) t = |
138 | rewrite__set_ thy i _ _ (rrls as Rrls _) t = |
135 let val _= if ! trace_rewrite andalso i < ! depth |
139 let |
136 then tracing ((idt"#"i)^" rls: "^(id_rls rrls)^" on: "^ |
140 val _= trace i (" rls: " ^ id_rls rrls ^ " on: " ^ term2str t) |
137 (term2str t)) else () |
141 val (t', asm, rew) = app_rev thy (i + 1) rrls t |
138 val (t', asm, rew) = app_rev thy (i+1) rrls t |
142 in if rew then SOME (t', distinct asm) else NONE end |
139 in if rew then SOME (t', distinct asm) |
|
140 else NONE end |
|
141 (* rewrite with a rule set containing Thms or Calculations *) |
143 (* rewrite with a rule set containing Thms or Calculations *) |
142 | rewrite__set_ thy i put_asm bdv rls ct = |
144 | rewrite__set_ thy i put_asm bdv rls ct = |
143 (* val (thy, i, put_asm, bdv, rls, ct) = (thy, 1, bool, [], rls, term); |
145 let |
144 *) |
146 datatype switch = Appl | Noap; |
145 let |
147 fun rew_once ruls asm ct Noap [] = (ct, asm) |
146 datatype switch = Appl | Noap; |
148 | rew_once ruls asm ct Appl [] = |
147 fun rew_once ruls asm ct Noap [] = (ct,asm) |
149 (case rls of Rls _ => rew_once ruls asm ct Noap ruls |
148 | rew_once ruls asm ct Appl [] = |
150 | Seq _ => (ct, asm)) |
149 (case rls of Rls _ => rew_once ruls asm ct Noap ruls |
151 | rew_once ruls asm ct apno (rul::thms) = |
150 | Seq _ => (ct,asm)) |
152 case rul of |
151 | rew_once ruls asm ct apno (rul::thms) = |
153 Thm (thmid, thm) => |
152 (* val (ruls, asm, ct, apno, (rul::thms)) = (ruls, [], ct, Noap, ruls); |
154 (trace1 i (" try thm: " ^ thmid); |
153 val Thm (thmid, thm) = rul; |
155 case rewrite__ thy (i + 1) bdv ((snd o #rew_ord o rep_rls) rls) |
154 *) |
156 ((#erls o rep_rls) rls) put_asm thm ct of |
155 case rul of |
157 NONE => rew_once ruls asm ct apno thms |
156 Thm (thmid, thm) => |
158 | SOME (ct',asm') => |
157 (if !trace_rewrite andalso i < ! depth |
159 (trace1 i (" rewrites to: " ^ term2str ct'); |
158 then tracing((idt"#"(i+1))^" try thm: "^thmid) else (); |
160 rew_once ruls (union (op =) asm asm') ct' Appl (rul::thms))) |
159 case rewrite__ thy (i+1) bdv ((snd o #rew_ord o rep_rls) rls) |
161 | Calc (cc as (op_, _)) => |
160 ((#erls o rep_rls) rls) put_asm thm ct of |
162 let val _= trace1 i (" try calc: " ^ op_ ^ "'") |
161 NONE => rew_once ruls asm ct apno thms |
163 val ct = uminus_to_string ct |
162 | SOME (ct',asm') => (if ! trace_rewrite andalso i < ! depth |
164 in case get_calculation_ thy cc ct of |
163 then tracing((idt"="(i+1))^" rewrites to: "^ |
165 NONE => rew_once ruls asm ct apno thms |
164 (term2str ct')) else (); |
166 | SOME (thmid, thm') => |
165 rew_once ruls (union (op =) asm asm') ct' Appl (rul::thms))) |
167 let |
166 | Calc (cc as (op_,_)) => |
168 val pairopt = rewrite__ thy (i + 1) bdv ((snd o #rew_ord o rep_rls) rls) |
167 (let val _= if !trace_rewrite andalso i < ! depth then |
169 ((#erls o rep_rls) rls) put_asm thm' ct; |
168 tracing((idt"#"(i+1))^" try calc: "^op_^"'") else (); |
170 val _ = if pairopt <> NONE then () else error ("rewrite_set_, rewrite_ \"" ^ |
169 val ct = uminus_to_string ct |
171 string_of_thmI thm' ^ "\" " ^ term2str ct ^ " = NONE") |
170 in case get_calculation_ thy cc ct of |
172 val _ = trace1 i (" calc. to: " ^ term2str ((fst o the) pairopt)) |
171 NONE => rew_once ruls asm ct apno thms |
173 in rew_once ruls asm ((fst o the) pairopt) Appl (rul :: thms) end |
172 | SOME (thmid, thm') => |
174 end |
173 let |
175 | Cal1 (cc as (op_, _)) => |
174 val pairopt = |
176 let val _= trace1 i (" try cal1: " ^ op_ ^ "'"); |
175 rewrite__ thy (i+1) bdv ((snd o #rew_ord o rep_rls) rls) |
177 val ct = uminus_to_string ct |
176 ((#erls o rep_rls) rls) put_asm thm' ct; |
178 in case get_calculation1_ thy cc ct of |
177 val _ = if pairopt <> NONE then () |
179 NONE => (ct, asm) |
178 else error("rewrite_set_, rewrite_ \""^ |
180 | SOME (thmid, thm') => |
179 (string_of_thmI thm')^"\" "^(term2str ct)^" = NONE") |
181 let |
180 val _ = if ! trace_rewrite andalso i < ! depth |
182 val pairopt = rewrite__ thy (i + 1) bdv ((snd o #rew_ord o rep_rls) rls) |
181 then tracing((idt"="(i+1))^" calc. to: "^ |
183 ((#erls o rep_rls) rls) put_asm thm' ct; |
182 (term2str ((fst o the) pairopt))) |
184 val _ = if pairopt <> NONE then () else error ("rewrite_set_, rewrite_ \"" ^ |
183 else() |
185 string_of_thmI thm' ^ "\" " ^ term2str ct ^ " = NONE") |
184 in rew_once ruls asm ((fst o the) pairopt) Appl (rul::thms) end |
186 val _ = trace1 i (" cal1. to: " ^ term2str ((fst o the) pairopt)) |
185 end) |
187 in the pairopt end |
186 | Cal1 (cc as (op_,_)) => |
188 end |
187 (let val _= if !trace_rewrite andalso i < ! depth then |
189 | Rls_ rls' => |
188 tracing((idt"#"(i+1))^" try cal1: "^op_^"'") else (); |
190 (case rewrite__set_ thy (i + 1) put_asm bdv rls' ct of |
189 val ct = uminus_to_string ct |
191 SOME (t', asm') => rew_once ruls (union (op =) asm asm') t' Appl thms |
190 in case get_calculation1_ thy cc ct of |
192 | NONE => rew_once ruls asm ct apno thms); |
191 NONE => (ct, asm) |
193 val ruls = (#rules o rep_rls) rls; |
192 | SOME (thmid, thm') => |
194 val _= trace i (" rls: " ^ id_rls rls ^ " on: " ^ term2str ct) |
193 let |
195 val (ct', asm') = rew_once ruls [] ct Noap ruls; |
194 val pairopt = |
196 in if ct = ct' then NONE else SOME (ct', distinct asm') end |
195 rewrite__ thy (i+1) bdv ((snd o #rew_ord o rep_rls) rls) |
|
196 ((#erls o rep_rls) rls) put_asm thm' ct; |
|
197 val _ = if pairopt <> NONE then () |
|
198 else error("rewrite_set_, rewrite_ \""^ |
|
199 (string_of_thmI thm')^"\" "^(term2str ct)^" = NONE") |
|
200 val _ = if ! trace_rewrite andalso i < ! depth |
|
201 then tracing((idt"="(i+1))^" cal1. to: "^ |
|
202 (term2str ((fst o the) pairopt))) |
|
203 else() |
|
204 in the pairopt end |
|
205 end) |
|
206 | Rls_ rls' => |
|
207 (case rewrite__set_ thy (i+1) put_asm bdv rls' ct of |
|
208 SOME (t',asm') => rew_once ruls (union (op =) asm asm') t' Appl thms |
|
209 | NONE => rew_once ruls asm ct apno thms); |
|
210 |
|
211 val ruls = (#rules o rep_rls) rls; |
|
212 val _= if ! trace_rewrite andalso i < ! depth |
|
213 then tracing ((idt"#"i)^" rls: "^(id_rls rls)^" on: "^ |
|
214 (term2str ct)) else () |
|
215 val (ct',asm') = rew_once ruls [] ct Noap ruls; |
|
216 in if ct = ct' then NONE else SOME (ct', distinct asm') end |
|
217 |
197 |
218 (* apply an Rrls; if not applicable proceed with subterms *) |
198 (* apply an Rrls; if not applicable proceed with subterms *) |
219 and app_rev thy i rrls t = |
199 and app_rev thy i rrls t = |
220 let (* check a (precond, pattern) of a rev-set; stops with 1st true *) |
200 let (* check a (precond, pattern) of a rev-set; stops with 1st true *) |
221 fun chk_prepat thy erls [] t = true |
201 fun chk_prepat thy erls [] t = true |