src/Tools/isac/calcelems.sml
branchisac-update-Isa09-2
changeset 38031 460c24a6a6ba
parent 38024 20231cdf39e7
child 38036 02a9b2540eb7
equal deleted inserted replaced
38030:95d956108461 38031:460c24a6a6ba
   142 fun Isac _ = ProofContext.theory_of (thy2ctxt' "Isac");
   142 fun Isac _ = ProofContext.theory_of (thy2ctxt' "Isac");
   143 
   143 
   144 val e_rule = 
   144 val e_rule = 
   145     Thm ("refl", ProofContext.get_thm (thy2ctxt' "Complex_Main") "refl" );
   145     Thm ("refl", ProofContext.get_thm (thy2ctxt' "Complex_Main") "refl" );
   146 fun id_of_thm (Thm (id, _)) = id
   146 fun id_of_thm (Thm (id, _)) = id
   147   | id_of_thm _ = raise error "id_of_thm";
   147   | id_of_thm _ = error "id_of_thm";
   148 fun thm_of_thm (Thm (_, thm)) = thm
   148 fun thm_of_thm (Thm (_, thm)) = thm
   149   | thm_of_thm _ = raise error "thm_of_thm";
   149   | thm_of_thm _ = error "thm_of_thm";
   150 fun rep_thm_G' (Thm (thmid, thm)) = (thmid, thm);
   150 fun rep_thm_G' (Thm (thmid, thm)) = (thmid, thm);
   151 fun eq_thmI ((thmid1 : thmID, _ : thm), (thmid2 : thmID, _ : thm)) =
   151 fun eq_thmI ((thmid1 : thmID, _ : thm), (thmid2 : thmID, _ : thm)) =
   152     (strip_thy thmid1) = (strip_thy thmid2);
   152     (strip_thy thmid1) = (strip_thy thmid2);
   153 (*version typed weaker WN100910*)
   153 (*version typed weaker WN100910*)
   154 fun eq_thmI' ((thmid1, _), (thmid2, _)) =
   154 fun eq_thmI' ((thmid1, _), (thmid2, _)) =
   305 val e_theID = ["e_theID"];
   305 val e_theID = ["e_theID"];
   306 val theID2str = strs2str;
   306 val theID2str = strs2str;
   307 (*theID eg. is ["IsacKnowledge", "Test", "Rulesets", "ac_plus_times"]*)
   307 (*theID eg. is ["IsacKnowledge", "Test", "Rulesets", "ac_plus_times"]*)
   308 fun theID2thyID (theID:theID) =
   308 fun theID2thyID (theID:theID) =
   309     if length theID >= 3 then (last_elem o (drop_last_n 2)) theID : thyID
   309     if length theID >= 3 then (last_elem o (drop_last_n 2)) theID : thyID
   310     else raise error ("theID2thyID called with "^ theID2str theID);
   310     else error ("theID2thyID called with "^ theID2str theID);
   311 
   311 
   312 (*the key into the hierarchy ob problems*)
   312 (*the key into the hierarchy ob problems*)
   313 type pblID = string list; (* domID::...*)
   313 type pblID = string list; (* domID::...*)
   314 val e_pblID = ["e_pblID"]:pblID;
   314 val e_pblID = ["e_pblID"]:pblID;
   315 val pblID2str = strs2str;
   315 val pblID2str = strs2str;
   449   | rep_rls (Seq {id,preconds,rew_ord,erls,srls,calc,(*asm_thm,*)rules,scr}) =
   449   | rep_rls (Seq {id,preconds,rew_ord,erls,srls,calc,(*asm_thm,*)rules,scr}) =
   450   {id=id,preconds=preconds,rew_ord=rew_ord,erls=erls,srls=srls,calc=calc,
   450   {id=id,preconds=preconds,rew_ord=rew_ord,erls=erls,srls=srls,calc=calc,
   451    (*asm_thm=asm_thm,*)rules=rules,scr=scr}
   451    (*asm_thm=asm_thm,*)rules=rules,scr=scr}
   452   | rep_rls Erls = rep_rls e_rls
   452   | rep_rls Erls = rep_rls e_rls
   453   | rep_rls (Rrls {id,...})  = rep_rls e_rls
   453   | rep_rls (Rrls {id,...})  = rep_rls e_rls
   454     (*raise error("rep_rls doesn't take apart reverse-rewrite-rule-sets: "^id)*);
   454     (*error("rep_rls doesn't take apart reverse-rewrite-rule-sets: "^id)*);
   455 (*| rep_rls (Seq {id,...})  = 
   455 (*| rep_rls (Seq {id,...})  = 
   456     raise error("rep_rls doesn't take apart reverse-rewrite-rule-sets: "^id);
   456     error("rep_rls doesn't take apart reverse-rewrite-rule-sets: "^id);
   457 --1.7.03*)
   457 --1.7.03*)
   458 fun rep_rrls 
   458 fun rep_rrls 
   459 	(Rrls {id,(*asm_thm,*) calc, erls, prepat, rew_ord, 
   459 	(Rrls {id,(*asm_thm,*) calc, erls, prepat, rew_ord, 
   460 	       scr=Rfuns
   460 	       scr=Rfuns
   461 		       {attach_form,init_state,locate_rule,
   461 		       {attach_form,init_state,locate_rule,
   462 			next_rule,normal_form}}) =
   462 			next_rule,normal_form}}) =
   463     {id=id,(*asm_thm=asm_thm,*) calc=calc, erls=erls, prepat=prepat, 
   463     {id=id,(*asm_thm=asm_thm,*) calc=calc, erls=erls, prepat=prepat, 
   464      rew_ord=rew_ord, attach_form=attach_form, init_state=init_state, 
   464      rew_ord=rew_ord, attach_form=attach_form, init_state=init_state, 
   465      locate_rule=locate_rule, next_rule=next_rule, normal_form=normal_form}
   465      locate_rule=locate_rule, next_rule=next_rule, normal_form=normal_form}
   466   | rep_rrls (Rls {id,...}) = 
   466   | rep_rrls (Rls {id,...}) = 
   467     raise error ("rep_rrls doesn't take apart (normal) rule-sets: "^id)
   467     error ("rep_rrls doesn't take apart (normal) rule-sets: "^id)
   468   | rep_rrls (Seq {id,...}) = 
   468   | rep_rrls (Seq {id,...}) = 
   469     raise error ("rep_rrls doesn't take apart (normal) rule-sets: "^id);
   469     error ("rep_rrls doesn't take apart (normal) rule-sets: "^id);
   470 
   470 
   471 fun append_rls id (Rls {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   471 fun append_rls id (Rls {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   472 			rules =rs,scr=sc}) r =
   472 			rules =rs,scr=sc}) r =
   473     (Rls{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   473     (Rls{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   474 	 rules = rs @ r,scr=sc}:rls)
   474 	 rules = rs @ r,scr=sc}:rls)
   475   | append_rls id (Seq {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   475   | append_rls id (Seq {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   476 			rules =rs,scr=sc}) r =
   476 			rules =rs,scr=sc}) r =
   477     (Seq{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   477     (Seq{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   478 	 rules = rs @ r,scr=sc}:rls)
   478 	 rules = rs @ r,scr=sc}:rls)
   479   | append_rls id (Rrls _) _ = 
   479   | append_rls id (Rrls _) _ = 
   480     raise error ("append_rls: not for reverse-rewrite-rule-set "^id);
   480     error ("append_rls: not for reverse-rewrite-rule-set "^id);
   481 
   481 
   482 (*. are _atomic_ rules equal ?.*)
   482 (*. are _atomic_ rules equal ?.*)
   483 (*WN080102 compare eqrule ?!?*)
   483 (*WN080102 compare eqrule ?!?*)
   484 fun eq_rule (Thm (thm1,_), Thm (thm2,_)) = thm1 = thm2
   484 fun eq_rule (Thm (thm1,_), Thm (thm2,_)) = thm1 = thm2
   485   | eq_rule (Calc (id1,_), Calc (id2,_)) = id1 = id2
   485   | eq_rule (Calc (id1,_), Calc (id2,_)) = id1 = id2
   514 	      calc=ca1 @ ((#calc o rep_rls) r2),
   514 	      calc=ca1 @ ((#calc o rep_rls) r2),
   515 	      (*asm_thm=at1 @ ((#asm_thm o rep_rls) r2),*)
   515 	      (*asm_thm=at1 @ ((#asm_thm o rep_rls) r2),*)
   516 	      rules = gen_union eq_rule rule2str (rs1, (#rules o rep_rls) r2),
   516 	      rules = gen_union eq_rule rule2str (rs1, (#rules o rep_rls) r2),
   517 	      scr=sc1}:rls)
   517 	      scr=sc1}:rls)
   518   | merge_rls _ _ _ = 
   518   | merge_rls _ _ _ = 
   519     raise error "merge_rls: not for reverse-rewrite-rule-sets\
   519     error "merge_rls: not for reverse-rewrite-rule-sets\
   520 		\and not for mixed Rls -- Seq";
   520 		\and not for mixed Rls -- Seq";
   521 fun remove_rls id (Rls {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   521 fun remove_rls id (Rls {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   522 		     (*asm_thm=at,*)rules =rs,scr=sc}) r =
   522 		     (*asm_thm=at,*)rules =rs,scr=sc}) r =
   523     (Rls{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   523     (Rls{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   524 	 (*asm_thm=at,*)rules = gen_rems eq_rule (rs, r),
   524 	 (*asm_thm=at,*)rules = gen_rems eq_rule (rs, r),
   526   | remove_rls id (Seq {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   526   | remove_rls id (Seq {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   527 		     (*asm_thm=at,*)rules =rs,scr=sc}) r =
   527 		     (*asm_thm=at,*)rules =rs,scr=sc}) r =
   528     (Seq{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   528     (Seq{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
   529 	 (*asm_thm=at,*)rules = gen_rems eq_rule (rs, r),
   529 	 (*asm_thm=at,*)rules = gen_rems eq_rule (rs, r),
   530 	 scr=sc}:rls)
   530 	 scr=sc}:rls)
   531   | remove_rls id (Rrls _) _ = raise error 
   531   | remove_rls id (Rrls _) _ = error 
   532                    ("remove_rls: not for reverse-rewrite-rule-set "^id);
   532                    ("remove_rls: not for reverse-rewrite-rule-set "^id);
   533 
   533 
   534 (*!!!> gen_rems (op=) ([1,2,3,4], [3,4,5]);
   534 (*!!!> gen_rems (op=) ([1,2,3,4], [3,4,5]);
   535 val it = [1, 2] : int list*)
   535 val it = [1, 2] : int list*)
   536 
   536 
   538 fun mem_rls id rls = 
   538 fun mem_rls id rls = 
   539     case find_first ((curry op=) id) (map id_rule ((#rules o rep_rls) rls)) of
   539     case find_first ((curry op=) id) (map id_rule ((#rules o rep_rls) rls)) of
   540 	SOME _ => true | NONE => false;*)
   540 	SOME _ => true | NONE => false;*)
   541 fun memrls r (Rls {rules,...}) = gen_mem eqrule (r, rules)
   541 fun memrls r (Rls {rules,...}) = gen_mem eqrule (r, rules)
   542   | memrls r (Seq {rules,...}) = gen_mem eqrule (r, rules)
   542   | memrls r (Seq {rules,...}) = gen_mem eqrule (r, rules)
   543   | memrls r _ = raise error ("memrls: incomplete impl. r= "^(rule2str r));
   543   | memrls r _ = error ("memrls: incomplete impl. r= "^(rule2str r));
   544 fun rls_get_thm rls (id: xstring) =
   544 fun rls_get_thm rls (id: xstring) =
   545     case find_first (curry eq_rule e_rule) 
   545     case find_first (curry eq_rule e_rule) 
   546 		    ((#rules o rep_rls) rls) of
   546 		    ((#rules o rep_rls) rls) of
   547 	SOME thm => SOME thm | NONE => NONE;
   547 	SOME thm => SOME thm | NONE => NONE;
   548 
   548 
   549 fun assoc' ([], key) = raise error ("ME_Isa: '"^key^"' not known")
   549 fun assoc' ([], key) = error ("ME_Isa: '"^key^"' not known")
   550   | assoc' ((keyi, xi) :: pairs, key) =
   550   | assoc' ((keyi, xi) :: pairs, key) =
   551       if key = keyi then SOME xi else assoc' (pairs, key);
   551       if key = keyi then SOME xi else assoc' (pairs, key);
   552 
   552 
   553 (*100818 fun assoc_thy (thy:theory') = ((the o assoc')(!theory',thy))
   553 (*100818 fun assoc_thy (thy:theory') = ((the o assoc')(!theory',thy))
   554   handle _ => raise error ("ME_Isa: thy '"^thy^"' not in system");*)
   554   handle _ => error ("ME_Isa: thy '"^thy^"' not in system");*)
   555 fun assoc_thy (thy:theory') = (*FIXME100818 abolish*)
   555 fun assoc_thy (thy:theory') = (*FIXME100818 abolish*)
   556     (theory ((implode o (curry takelast 4) o explode) thy))
   556     (theory ((implode o (curry takelast 4) o explode) thy))
   557     handle _ => raise error ("ME_Isa: thy '" ^ thy ^ "' not in system");
   557     handle _ => error ("ME_Isa: thy '" ^ thy ^ "' not in system");
   558     
   558     
   559 (*.associate an rls-identifier with an rls; related to 'fun assoc_rls';
   559 (*.associate an rls-identifier with an rls; related to 'fun assoc_rls';
   560    these are NOT compatible to "fun assoc_thm'" in that they do NOT handle
   560    these are NOT compatible to "fun assoc_thm'" in that they do NOT handle
   561    overlays by re-using an identifier in different thys.*)
   561    overlays by re-using an identifier in different thys.*)
   562 fun assoc_rls (rls:rls') = ((#2 o the o assoc')(!ruleset',rls))
   562 fun assoc_rls (rls:rls') = ((#2 o the o assoc')(!ruleset',rls))
   563   handle _ => raise error ("ME_Isa: '"^rls^"' not in system");
   563   handle _ => error ("ME_Isa: '"^rls^"' not in system");
   564 (*fun assoc_rls (rls:rls') = ((the o assoc')(!ruleset',rls))
   564 (*fun assoc_rls (rls:rls') = ((the o assoc')(!ruleset',rls))
   565   handle _ => raise error ("ME_Isa: '"^rls^"' not in system");*)
   565   handle _ => error ("ME_Isa: '"^rls^"' not in system");*)
   566 
   566 
   567 (*.overwrite an element in an association list and pair it with a thyID
   567 (*.overwrite an element in an association list and pair it with a thyID
   568    in order to create the thy_hierarchy;
   568    in order to create the thy_hierarchy;
   569    overwrites existing rls' even if they are defined in a different thy;
   569    overwrites existing rls' even if they are defined in a different thy;
   570    this is related to assoc_rls, TODO.WN060120: assoc_rew_ord, assoc_calc;.*)
   570    this is related to assoc_rls, TODO.WN060120: assoc_rew_ord, assoc_calc;.*)
   577 fun overwritelthy thy (al, bl:(rls' * rls) list) =
   577 fun overwritelthy thy (al, bl:(rls' * rls) list) =
   578     let val bl' = map (insthy ((get_thy o theory2theory') thy)) bl
   578     let val bl' = map (insthy ((get_thy o theory2theory') thy)) bl
   579     in overwritel (al, bl') end;
   579     in overwritel (al, bl') end;
   580 
   580 
   581 fun assoc_rew_ord ro = ((the o assoc') (!rew_ord',ro))
   581 fun assoc_rew_ord ro = ((the o assoc') (!rew_ord',ro))
   582   handle _ => raise error ("ME_Isa: rew_ord '"^ro^"' not in system");
   582   handle _ => error ("ME_Isa: rew_ord '"^ro^"' not in system");
   583 (*get the string for stac from rule*)
   583 (*get the string for stac from rule*)
   584 fun assoc_calc ([], key) = raise error ("assoc_calc: '"^ key ^"' not found")
   584 fun assoc_calc ([], key) = error ("assoc_calc: '"^ key ^"' not found")
   585   | assoc_calc ((calc, (keyi, xi)) :: pairs, key) =
   585   | assoc_calc ((calc, (keyi, xi)) :: pairs, key) =
   586       if key = keyi then calc else assoc_calc (pairs, key);
   586       if key = keyi then calc else assoc_calc (pairs, key);
   587 (*only used for !calclist'...*)
   587 (*only used for !calclist'...*)
   588 fun assoc1 ([], key) = raise error ("assoc1 (for met.calc=): '"^ key 
   588 fun assoc1 ([], key) = error ("assoc1 (for met.calc=): '"^ key 
   589 				    ^"' not found")
   589 				    ^"' not found")
   590   | assoc1 ((all as (keyi, _)) :: pairs, key) =
   590   | assoc1 ((all as (keyi, _)) :: pairs, key) =
   591       if key = keyi then all else assoc1 (pairs, key);
   591       if key = keyi then all else assoc1 (pairs, key);
   592 
   592 
   593 (*TODO.WN080102 clarify usage of type cal and type calc..*)
   593 (*TODO.WN080102 clarify usage of type cal and type calc..*)
   594 fun calID2calcID (calID : calID) = 
   594 fun calID2calcID (calID : calID) = 
   595     let fun ass [] = raise error ("calID2calcID: "^calID^"not in calclist'")
   595     let fun ass [] = error ("calID2calcID: "^calID^"not in calclist'")
   596 	  | ass ((calci, (cali, eval_fn))::ids) =
   596 	  | ass ((calci, (cali, eval_fn))::ids) =
   597 	    if calID = cali then calci
   597 	    if calID = cali then calci
   598 	    else ass ids
   598 	    else ass ids
   599     in ass (!calclist') : calcID end;
   599     in ass (!calclist') : calcID end;
   600 
   600