30 shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} = |
30 shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} = |
31 rep_thm_G thm; |
31 rep_thm_G thm; |
32 val (lhs,rhs) = (dest_equals' o strip_trueprop |
32 val (lhs,rhs) = (dest_equals' o strip_trueprop |
33 o Logic.strip_imp_concl) prop; |
33 o Logic.strip_imp_concl) prop; |
34 val prop' = case strip_imp_prems' prop of |
34 val prop' = case strip_imp_prems' prop of |
35 None => Trueprop $ (mk_equality (rhs, lhs)) |
35 NONE => Trueprop $ (mk_equality (rhs, lhs)) |
36 | Some cs => |
36 | SOME cs => |
37 ins_concl cs (Trueprop $ (mk_equality (rhs, lhs))); |
37 ins_concl cs (Trueprop $ (mk_equality (rhs, lhs))); |
38 in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end; |
38 in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end; |
39 (* |
39 (* |
40 (sym RS real_mult_div_cancel1) handle e => print_exn e; |
40 (sym RS real_mult_div_cancel1) handle e => print_exn e; |
41 Exception THM 1 raised: |
41 Exception THM 1 raised: |
84 |
84 |
85 WN060825 too complicated for the intended use by cancel_, common_nominator_ |
85 WN060825 too complicated for the intended use by cancel_, common_nominator_ |
86 and unreflectedly adapted to extion of rules by Rls_: returns Rls_("sym_simpl.. |
86 and unreflectedly adapted to extion of rules by Rls_: returns Rls_("sym_simpl.. |
87 -- replaced below*) |
87 -- replaced below*) |
88 (* val (thy, erls, rs, ro, goal, tt) = (thy, erls, rs, ro, goal, t); |
88 (* val (thy, erls, rs, ro, goal, tt) = (thy, erls, rs, ro, goal, t); |
89 val (thy, erls, rs, ro, goal, tt) = (thy, Atools_erls, rules, ro, None, tt); |
89 val (thy, erls, rs, ro, goal, tt) = (thy, Atools_erls, rules, ro, NONE, tt); |
90 *) |
90 *) |
91 fun make_deriv thy erls (rs:rule list) ro(*rew_ord*) goal tt = |
91 fun make_deriv thy erls (rs:rule list) ro(*rew_ord*) goal tt = |
92 let datatype switch = Appl | Noap |
92 let datatype switch = Appl | Noap |
93 fun rew_once lim rts t Noap [] = |
93 fun rew_once lim rts t Noap [] = |
94 (case goal of |
94 (case goal of |
95 None => rts |
95 NONE => rts |
96 | Some g => |
96 | SOME g => |
97 raise error ("make_deriv: no derivation for "^(term2str t))) |
97 raise error ("make_deriv: no derivation for "^(term2str t))) |
98 | rew_once lim rts t Appl [] = |
98 | rew_once lim rts t Appl [] = |
99 (*(case rs of Rls _ =>*) rew_once lim rts t Noap rs |
99 (*(case rs of Rls _ =>*) rew_once lim rts t Noap rs |
100 (*| Seq _ => rts) FIXXXXXME 14.3.03*) |
100 (*| Seq _ => rts) FIXXXXXME 14.3.03*) |
101 | rew_once lim rts t apno rs' = |
101 | rew_once lim rts t apno rs' = |
102 (case goal of |
102 (case goal of |
103 None => rew_or_calc lim rts t apno rs' |
103 NONE => rew_or_calc lim rts t apno rs' |
104 | Some g => |
104 | SOME g => |
105 if g = t then rts |
105 if g = t then rts |
106 else rew_or_calc lim rts t apno rs') |
106 else rew_or_calc lim rts t apno rs') |
107 and rew_or_calc lim rts t apno (rrs' as (r::rs')) = |
107 and rew_or_calc lim rts t apno (rrs' as (r::rs')) = |
108 if lim < 0 |
108 if lim < 0 |
109 then (writeln ("make_deriv exceeds " ^ int2str (!lim_deriv) ^ |
109 then (writeln ("make_deriv exceeds " ^ int2str (!lim_deriv) ^ |
112 case r of |
112 case r of |
113 Thm (thmid, tm) => |
113 Thm (thmid, tm) => |
114 (if not (!trace_rewrite) then () else |
114 (if not (!trace_rewrite) then () else |
115 writeln ("### trying thm '" ^ thmid ^ "'"); |
115 writeln ("### trying thm '" ^ thmid ^ "'"); |
116 case rewrite_ thy ro erls true tm t of |
116 case rewrite_ thy ro erls true tm t of |
117 None => rew_once lim rts t apno rs' |
117 NONE => rew_once lim rts t apno rs' |
118 | Some (t',a') => |
118 | SOME (t',a') => |
119 (if ! trace_rewrite |
119 (if ! trace_rewrite |
120 then writeln ("### rewrites to: "^(term2str t')) else(); |
120 then writeln ("### rewrites to: "^(term2str t')) else(); |
121 rew_once (lim-1) (rts@[(t,r,(t',a'))]) t' Appl rrs')) |
121 rew_once (lim-1) (rts@[(t,r,(t',a'))]) t' Appl rrs')) |
122 | Calc (c as (op_,_)) => |
122 | Calc (c as (op_,_)) => |
123 let val _ = if not (!trace_rewrite) then () else |
123 let val _ = if not (!trace_rewrite) then () else |
124 writeln ("### trying calc. '" ^ op_ ^ "'") |
124 writeln ("### trying calc. '" ^ op_ ^ "'") |
125 val t = uminus_to_string t |
125 val t = uminus_to_string t |
126 in case get_calculation_ thy c t of |
126 in case get_calculation_ thy c t of |
127 None => rew_once lim rts t apno rs' |
127 NONE => rew_once lim rts t apno rs' |
128 | Some (thmid, tm) => |
128 | SOME (thmid, tm) => |
129 (let val Some (t',a') = rewrite_ thy ro erls true tm t |
129 (let val SOME (t',a') = rewrite_ thy ro erls true tm t |
130 val _ = if not (!trace_rewrite) then () else |
130 val _ = if not (!trace_rewrite) then () else |
131 writeln("### calc. to: " ^ (term2str t')) |
131 writeln("### calc. to: " ^ (term2str t')) |
132 val r' = Thm (thmid, tm) |
132 val r' = Thm (thmid, tm) |
133 in rew_once (lim-1) (rts@[(t,r',(t',a'))]) t' Appl rrs' |
133 in rew_once (lim-1) (rts@[(t,r',(t',a'))]) t' Appl rrs' |
134 end) |
134 end) |
139 | Cal1 (cc as (op_,_)) => |
139 | Cal1 (cc as (op_,_)) => |
140 (let val _= if !trace_rewrite andalso i < ! depth then |
140 (let val _= if !trace_rewrite andalso i < ! depth then |
141 writeln((idt"#"(i+1))^" try cal1: "^op_^"'") else (); |
141 writeln((idt"#"(i+1))^" try cal1: "^op_^"'") else (); |
142 val ct = uminus_to_string ct |
142 val ct = uminus_to_string ct |
143 in case get_calculation_ thy cc ct of |
143 in case get_calculation_ thy cc ct of |
144 None => (ct, asm) |
144 NONE => (ct, asm) |
145 | Some (thmid, thm') => |
145 | SOME (thmid, thm') => |
146 let |
146 let |
147 val pairopt = |
147 val pairopt = |
148 rewrite__ thy (i+1) bdv ((snd o #rew_ord o rep_rls) rls) |
148 rewrite__ thy (i+1) bdv ((snd o #rew_ord o rep_rls) rls) |
149 ((#erls o rep_rls) rls) put_asm thm' ct; |
149 ((#erls o rep_rls) rls) put_asm thm' ct; |
150 val _ = if pairopt <> None then () |
150 val _ = if pairopt <> NONE then () |
151 else raise error("rewrite_set_, rewrite_ \""^ |
151 else raise error("rewrite_set_, rewrite_ \""^ |
152 (string_of_thmI thm')^"\" "^(term2str ct)^" = None") |
152 (string_of_thmI thm')^"\" "^(term2str ct)^" = NONE") |
153 val _ = if ! trace_rewrite andalso i < ! depth |
153 val _ = if ! trace_rewrite andalso i < ! depth |
154 then writeln((idt"="(i+1))^" cal1. to: "^ |
154 then writeln((idt"="(i+1))^" cal1. to: "^ |
155 (term2str ((fst o the) pairopt))) |
155 (term2str ((fst o the) pairopt))) |
156 else() |
156 else() |
157 in the pairopt end |
157 in the pairopt end |
158 end) |
158 end) |
159 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*) |
159 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*) |
160 | Rls_ rls => |
160 | Rls_ rls => |
161 (case rewrite_set_ thy true rls t of |
161 (case rewrite_set_ thy true rls t of |
162 None => rew_once lim rts t apno rs' |
162 NONE => rew_once lim rts t apno rs' |
163 | Some (t',a') => |
163 | SOME (t',a') => |
164 rew_once (lim-1) (rts @ [(t,r,(t',a'))]) t' Appl rrs'); |
164 rew_once (lim-1) (rts @ [(t,r,(t',a'))]) t' Appl rrs'); |
165 (*WN060829 | Rls_ rls => |
165 (*WN060829 | Rls_ rls => |
166 (case rewrite_set_ thy true rls t of |
166 (case rewrite_set_ thy true rls t of |
167 None => rew_once lim rts t apno rs' |
167 NONE => rew_once lim rts t apno rs' |
168 | Some (t',a') => |
168 | SOME (t',a') => |
169 if ro [] (t, t') then rew_once lim rts t apno rs' |
169 if ro [] (t, t') then rew_once lim rts t apno rs' |
170 else rew_once (lim-1) (rts@[(t,r,(t',a'))]) t' Appl rrs'); |
170 else rew_once (lim-1) (rts@[(t,r,(t',a'))]) t' Appl rrs'); |
171 ...lead to deriv = [] with make_polynomial. |
171 ...lead to deriv = [] with make_polynomial. |
172 THERE IS SOMETHING DIFFERENT beetween rewriting with the code above |
172 THERE IS SOMETHING DIFFERENT beetween rewriting with the code above |
173 and between rewriting with rewrite_set: with rules from make_polynomial and |
173 and between rewriting with rewrite_set: with rules from make_polynomial and |
225 Thm ("sym_real_one_collect","?m is_const ==> (1 + ?m) * ?n = ?n + ?m * ?n")*) |
225 Thm ("sym_real_one_collect","?m is_const ==> (1 + ?m) * ?n = ?n + ?m * ?n")*) |
226 |
226 |
227 |
227 |
228 (*version for reverse rewrite used before 040214*) |
228 (*version for reverse rewrite used before 040214*) |
229 fun rev_deriv (t, r, (t', a)) = (sym_Thm r, (t, a)); |
229 fun rev_deriv (t, r, (t', a)) = (sym_Thm r, (t, a)); |
230 (* val (thy, erls, rs, ro, goal, t) = (thy, eval_rls, rules, ro, None, t'); |
230 (* val (thy, erls, rs, ro, goal, t) = (thy, eval_rls, rules, ro, NONE, t'); |
231 *) |
231 *) |
232 fun reverse_deriv thy erls (rs:rule list) ro(*rew_ord*) goal t = |
232 fun reverse_deriv thy erls (rs:rule list) ro(*rew_ord*) goal t = |
233 (rev o (map rev_deriv)) (make_deriv thy erls (rs:rule list) ro goal t); |
233 (rev o (map rev_deriv)) (make_deriv thy erls (rs:rule list) ro goal t); |
234 (* |
234 (* |
235 val rev_rew = reverse_deriv thy e_rls ; |
235 val rev_rew = reverse_deriv thy e_rls ; |
380 val str = sym_drop str |
380 val str = sym_drop str |
381 val startsearch = dropuntil ((curry op= thy') o |
381 val startsearch = dropuntil ((curry op= thy') o |
382 (#1:theory' * theory -> theory')) |
382 (#1:theory' * theory -> theory')) |
383 (rev (!theory')) |
383 (rev (!theory')) |
384 in case find_first (thy_contains_thm str) startsearch of |
384 in case find_first (thy_contains_thm str) startsearch of |
385 Some (thy',_) => ("IsacKnowledge", thy') |
385 SOME (thy',_) => ("IsacKnowledge", thy') |
386 | None => (case assoc (!isab_thm_thy (*see Isac.ML*), str) of |
386 | NONE => (case assoc (!isab_thm_thy (*see Isac.ML*), str) of |
387 Some (thyID,_) => ("Isabelle", thyID) |
387 SOME (thyID,_) => ("Isabelle", thyID) |
388 | None => |
388 | NONE => |
389 raise error ("thy_containing_thm: theorem '"^str^ |
389 raise error ("thy_containing_thm: theorem '"^str^ |
390 "' not in !theory' above thy '"^thy'^"'")) |
390 "' not in !theory' above thy '"^thy'^"'")) |
391 end; |
391 end; |
392 |
392 |
393 |
393 |
408 val startsearch = filter_out ((curry ((op mem) o swap) dropthy's) o |
408 val startsearch = filter_out ((curry ((op mem) o swap) dropthy's) o |
409 ((#1 o #2) : rls' * (theory' * rls) |
409 ((#1 o #2) : rls' * (theory' * rls) |
410 -> theory')) |
410 -> theory')) |
411 (rev (!ruleset')) |
411 (rev (!ruleset')) |
412 in case assoc (startsearch, rls') of |
412 in case assoc (startsearch, rls') of |
413 Some (thy', _) => ("IsacKnowledge", thyID2theory' thy') |
413 SOME (thy', _) => ("IsacKnowledge", thyID2theory' thy') |
414 | _ => raise error ("thy_containing_rls : rls '"^rls'^ |
414 | _ => raise error ("thy_containing_rls : rls '"^rls'^ |
415 "' not in !rulset' above thy '"^thy'^"'") |
415 "' not in !rulset' above thy '"^thy'^"'") |
416 end; |
416 end; |
417 (* val (thy', termop) = (thyID, termop); |
417 (* val (thy', termop) = (thyID, termop); |
418 *) |
418 *) |
424 val dropthy's = map (get_thy o (#1 : (theory' * theory) -> theory')) |
424 val dropthy's = map (get_thy o (#1 : (theory' * theory) -> theory')) |
425 dropthys |
425 dropthys |
426 val startsearch = filter_out ((curry ((op mem) o swap) dropthy's) o |
426 val startsearch = filter_out ((curry ((op mem) o swap) dropthy's) o |
427 (#1 : calc -> string)) (rev (!calclist')) |
427 (#1 : calc -> string)) (rev (!calclist')) |
428 in case assoc (startsearch, strip_thy termop) of |
428 in case assoc (startsearch, strip_thy termop) of |
429 Some (th_termop, _) => ("IsacKnowledge", strip_thy th_termop) |
429 SOME (th_termop, _) => ("IsacKnowledge", strip_thy th_termop) |
430 | _ => raise error ("thy_containing_rls : rls '"^termop^ |
430 | _ => raise error ("thy_containing_rls : rls '"^termop^ |
431 "' not in !calclist' above thy '"^thy'^"'") |
431 "' not in !calclist' above thy '"^thy'^"'") |
432 end; |
432 end; |
433 |
433 |
434 (* print_depth 99; map #1 startsearch; print_depth 3; |
434 (* print_depth 99; map #1 startsearch; print_depth 3; |
651 (*. try if a rewrite-rule is applicable to a given formula; |
651 (*. try if a rewrite-rule is applicable to a given formula; |
652 in case of rule-sets (recursivley) collect all _atomic_ rewrites .*) |
652 in case of rule-sets (recursivley) collect all _atomic_ rewrites .*) |
653 fun try_rew thy ((_, ro):rew_ord) erls (subst:subst) f (thm' as Thm(id, thm)) = |
653 fun try_rew thy ((_, ro):rew_ord) erls (subst:subst) f (thm' as Thm(id, thm)) = |
654 if contains_bdv thm |
654 if contains_bdv thm |
655 then case rewrite_inst_ thy ro erls false subst thm f of |
655 then case rewrite_inst_ thy ro erls false subst thm f of |
656 Some (f',_) =>[rule2tac subst thm'] |
656 SOME (f',_) =>[rule2tac subst thm'] |
657 | None => [] |
657 | NONE => [] |
658 else (case rewrite_ thy ro erls false thm f of |
658 else (case rewrite_ thy ro erls false thm f of |
659 Some (f',_) => [rule2tac [] thm'] |
659 SOME (f',_) => [rule2tac [] thm'] |
660 | None => []) |
660 | NONE => []) |
661 | try_rew thy _ _ _ f (cal as Calc c) = |
661 | try_rew thy _ _ _ f (cal as Calc c) = |
662 (case get_calculation_ thy c f of |
662 (case get_calculation_ thy c f of |
663 Some (str, _) => [rule2tac [] cal] |
663 SOME (str, _) => [rule2tac [] cal] |
664 | None => []) |
664 | NONE => []) |
665 | try_rew thy _ _ _ f (cal as Cal1 c) = |
665 | try_rew thy _ _ _ f (cal as Cal1 c) = |
666 (case get_calculation_ thy c f of |
666 (case get_calculation_ thy c f of |
667 Some (str, _) => [rule2tac [] cal] |
667 SOME (str, _) => [rule2tac [] cal] |
668 | None => []) |
668 | NONE => []) |
669 | try_rew thy _ _ subst f (Rls_ rls) = filter_appl_rews thy subst f rls |
669 | try_rew thy _ _ subst f (Rls_ rls) = filter_appl_rews thy subst f rls |
670 and filter_appl_rews thy subst f (Rls {rew_ord = ro, erls, rules,...}) = |
670 and filter_appl_rews thy subst f (Rls {rew_ord = ro, erls, rules,...}) = |
671 distinct (flat (map (try_rew thy ro erls subst f) rules)) |
671 distinct (flat (map (try_rew thy ro erls subst f) rules)) |
672 | filter_appl_rews thy subst f (Seq {rew_ord = ro, erls, rules,...}) = |
672 | filter_appl_rews thy subst f (Seq {rew_ord = ro, erls, rules,...}) = |
673 distinct (flat (map (try_rew thy ro erls subst f) rules)) |
673 distinct (flat (map (try_rew thy ro erls subst f) rules)) |