src/Tools/isac/ME/ptyps.sml
branchisac-update-Isa09-2
changeset 37926 e6fc98fbcb85
parent 37906 e2b23ba9df13
child 37928 dfec2cf32f77
equal deleted inserted replaced
37925:d957275620d4 37926:e6fc98fbcb85
   448       ppc   : pat list,
   448       ppc   : pat list,
   449       (*this is the model-pattern; 
   449       (*this is the model-pattern; 
   450        it contains "#Given","#Where","#Find","#Relate"-patterns*)
   450        it contains "#Given","#Where","#Find","#Relate"-patterns*)
   451       met   : metID list}; (* methods solving the pbt*)
   451       met   : metID list}; (* methods solving the pbt*)
   452 val e_pbt = {guh="pbl_empty",mathauthors=[],init=e_pblID,thy=ProtoPure.thy,
   452 val e_pbt = {guh="pbl_empty",mathauthors=[],init=e_pblID,thy=ProtoPure.thy,
   453 	     cas=None,prls=Erls,where_=[],ppc=[],met=[]}:pbt;
   453 	     cas=NONE,prls=Erls,where_=[],ppc=[],met=[]}:pbt;
   454 fun pbt2 (str, (t1, t2)) = 
   454 fun pbt2 (str, (t1, t2)) = 
   455     pair2str (str, pair2str (term2str t1, term2str t2));
   455     pair2str (str, pair2str (term2str t1, term2str t2));
   456 fun pbt2str pbt = (strs2str o (map (linefeed o pbt2))) pbt;
   456 fun pbt2str pbt = (strs2str o (map (linefeed o pbt2))) pbt;
   457 
   457 
   458 
   458 
   554 fun guh2kestoreID (guh:guh) =
   554 fun guh2kestoreID (guh:guh) =
   555     case (implode o (take_fromto 1 4) o explode) guh of
   555     case (implode o (take_fromto 1 4) o explode) guh of
   556 	"pbl_" =>
   556 	"pbl_" =>
   557 	let fun node ids gu (Ptyp (id,[n as {guh,...} : pbt], ns)) =
   557 	let fun node ids gu (Ptyp (id,[n as {guh,...} : pbt], ns)) =
   558 		if gu = guh 
   558 		if gu = guh 
   559 		then Some ((ids@[id]) : kestoreID)
   559 		then SOME ((ids@[id]) : kestoreID)
   560 		else nodes (ids@[id]) gu ns
   560 		else nodes (ids@[id]) gu ns
   561 	    and nodes _ _ [] = None 
   561 	    and nodes _ _ [] = NONE 
   562 	      | nodes ids gu (n::ns) = 
   562 	      | nodes ids gu (n::ns) = 
   563 		case node ids gu n of Some id => Some id
   563 		case node ids gu n of SOME id => SOME id
   564 				    | None =>  nodes ids gu ns
   564 				    | NONE =>  nodes ids gu ns
   565 	in case nodes [] guh (!ptyps) of
   565 	in case nodes [] guh (!ptyps) of
   566 	       Some id => rev id
   566 	       SOME id => rev id
   567 	     | None => error ("guh2kestoreID: '" ^ guh ^ "' " ^
   567 	     | NONE => error ("guh2kestoreID: '" ^ guh ^ "' " ^
   568 				    "not found in (!ptyps)")
   568 				    "not found in (!ptyps)")
   569 	end
   569 	end
   570       | "met_" =>
   570       | "met_" =>
   571 	let fun node ids gu (Ptyp (id,[n as {guh,...} : met], ns)) =
   571 	let fun node ids gu (Ptyp (id,[n as {guh,...} : met], ns)) =
   572 		if gu = guh 
   572 		if gu = guh 
   573 		then Some ((ids@[id]) : kestoreID)
   573 		then SOME ((ids@[id]) : kestoreID)
   574 		else nodes (ids@[id]) gu ns
   574 		else nodes (ids@[id]) gu ns
   575 	    and nodes _ _ [] = None 
   575 	    and nodes _ _ [] = NONE 
   576 	      | nodes ids gu (n::ns) = 
   576 	      | nodes ids gu (n::ns) = 
   577 		case node ids gu n of Some id => Some id
   577 		case node ids gu n of SOME id => SOME id
   578 				    | None =>  nodes ids gu ns
   578 				    | NONE =>  nodes ids gu ns
   579 	in case nodes [] guh (!mets) of
   579 	in case nodes [] guh (!mets) of
   580 	       Some id => id
   580 	       SOME id => id
   581 	     | None => error ("guh2kestoreID: '" ^ guh ^ "' " ^
   581 	     | NONE => error ("guh2kestoreID: '" ^ guh ^ "' " ^
   582 				    "not found in (!mets)") end
   582 				    "not found in (!mets)") end
   583       | _ => error ("guh2kestoreID called with '" ^ guh ^ "'");
   583       | _ => error ("guh2kestoreID called with '" ^ guh ^ "'");
   584 (*> guh2kestoreID "pbl_equ_univ_lin";
   584 (*> guh2kestoreID "pbl_equ_univ_lin";
   585 val it = ["linear", "univariate", "equation"] : string list*)
   585 val it = ["linear", "univariate", "equation"] : string list*)
   586 
   586 
   632        ((EqSystem.thy, (["system"],
   632        ((EqSystem.thy, (["system"],
   633 		       [("#Given" ,["equalities es_", "solveForVars vs_"]),
   633 		       [("#Given" ,["equalities es_", "solveForVars vs_"]),
   634 			("#Find"  ,["solution ss___"](*___ is copy-named*))
   634 			("#Find"  ,["solution ss___"](*___ is copy-named*))
   635 			],
   635 			],
   636 		       append_rls "e_rls" e_rls [(*for preds in where_*)], 
   636 		       append_rls "e_rls" e_rls [(*for preds in where_*)], 
   637 		       Some "solveSystem es_ vs_", 
   637 		       SOME "solveSystem es_ vs_", 
   638 		       [])));
   638 		       [])));
   639    *)
   639    *)
   640     let fun eq f (f', _) = f = f';
   640     let fun eq f (f', _) = f = f';
   641 	val gi = filter (eq "#Given") dsc_dats;
   641 	val gi = filter (eq "#Given") dsc_dats;
   642 (*val gi = [("#Given",["equality e_","solveFor v_"])]
   642 (*val gi = [("#Given",["equality e_","solveFor v_"])]
   702 			 (strs2str pblID)))
   702 			 (strs2str pblID)))
   703 		   | _ =>
   703 		   | _ =>
   704 		     (raise error ("prep_pbt: more than one '#Where' in "^
   704 		     (raise error ("prep_pbt: more than one '#Where' in "^
   705 				  (strs2str pblID))));
   705 				  (strs2str pblID))));
   706     in ({guh=guh,mathauthors=maa,init=init,
   706     in ({guh=guh,mathauthors=maa,init=init,
   707 	 thy=thy,cas= case ca of None => None
   707 	 thy=thy,cas= case ca of NONE => NONE
   708 			       | Some s => 
   708 			       | SOME s => 
   709 				 Some ((term_of o the o (parse thy)) s),
   709 				 SOME ((term_of o the o (parse thy)) s),
   710 	 prls=ev,where_=wh,ppc= gi @ fi @ re,
   710 	 prls=ev,where_=wh,ppc= gi @ fi @ re,
   711 	 met=metIDs}, pblID):pbt * pblID end;
   711 	 met=metIDs}, pblID):pbt * pblID end;
   712 (* prep_pbt thy (pblID, dsc_dats, metIDs);   
   712 (* prep_pbt thy (pblID, dsc_dats, metIDs);   
   713  val it =
   713  val it =
   714   ({met=[],
   714   ({met=[],
   880 
   880 
   881 (*. check an item (with arbitrary itm_ from previous matchings) 
   881 (*. check an item (with arbitrary itm_ from previous matchings) 
   882     for matching a problemtype; returns true only for itms found in pbt .*)
   882     for matching a problemtype; returns true only for itms found in pbt .*)
   883 fun chk_ thy pbt ((i,vats,b,f,Cor ((d,vs),_)):itm) =
   883 fun chk_ thy pbt ((i,vats,b,f,Cor ((d,vs),_)):itm) =
   884     (case find_first (eq1 d) pbt of 
   884     (case find_first (eq1 d) pbt of 
   885 	 Some (_,(_,id)) => ((i,vats,b,f,Cor ((d,vs),
   885 	 SOME (_,(_,id)) => ((i,vats,b,f,Cor ((d,vs),
   886 					      (id, pbl_ids' thy d vs))):itm)
   886 					      (id, pbl_ids' thy d vs))):itm)
   887        | None => (i,vats,false,f,Sup (d,vs)))
   887        | NONE => (i,vats,false,f,Sup (d,vs)))
   888   | chk_ thy pbt ((i,vats,b,f,Inc ((d,vs),_)):itm) =
   888   | chk_ thy pbt ((i,vats,b,f,Inc ((d,vs),_)):itm) =
   889     (case find_first (eq1 d) pbt of 
   889     (case find_first (eq1 d) pbt of 
   890 	Some (_,(_,id)) => ((i,vats,b,f,Cor ((d,vs),
   890 	SOME (_,(_,id)) => ((i,vats,b,f,Cor ((d,vs),
   891 					     (id, pbl_ids' thy d vs))):itm)
   891 					     (id, pbl_ids' thy d vs))):itm)
   892       | None => (i,vats,false,f,Sup (d,vs)))
   892       | NONE => (i,vats,false,f,Sup (d,vs)))
   893 
   893 
   894   | chk_ thy pbt (itm as (i,vats,b,f,Syn ct):itm) = itm
   894   | chk_ thy pbt (itm as (i,vats,b,f,Syn ct):itm) = itm
   895   | chk_ thy pbt (itm as (i,vats,b,f,Typ ct):itm) = itm
   895   | chk_ thy pbt (itm as (i,vats,b,f,Typ ct):itm) = itm
   896 
   896 
   897   | chk_ thy pbt ((i,vats,b,f,Sup (d,vs)):itm) =
   897   | chk_ thy pbt ((i,vats,b,f,Sup (d,vs)):itm) =
   898     (case find_first (eq1 d) pbt of 
   898     (case find_first (eq1 d) pbt of 
   899 	Some (_,(_,id)) => ((i,vats,b,f,Cor ((d,vs),
   899 	SOME (_,(_,id)) => ((i,vats,b,f,Cor ((d,vs),
   900 					     (id, pbl_ids' thy d vs))):itm)
   900 					     (id, pbl_ids' thy d vs))):itm)
   901       | None => (i,vats,false,f,Sup (d,vs)))
   901       | NONE => (i,vats,false,f,Sup (d,vs)))
   902 (* val (i,vats,b,f,Mis (d,vs)) = i4;
   902 (* val (i,vats,b,f,Mis (d,vs)) = i4;
   903    *)
   903    *)
   904   | chk_ thy pbt ((i,vats,b,f,Mis (d,vs)):itm) =
   904   | chk_ thy pbt ((i,vats,b,f,Mis (d,vs)):itm) =
   905     (case find_first (eq1 d) pbt of
   905     (case find_first (eq1 d) pbt of
   906 (* val Some (_,(_,id)) = find_first (eq1 d) pbt;
   906 (* val SOME (_,(_,id)) = find_first (eq1 d) pbt;
   907    *) 
   907    *) 
   908 	Some (_,(_,id)) => raise error "chk_: ((i,vats,b,f,Cor ((d,vs),\
   908 	SOME (_,(_,id)) => raise error "chk_: ((i,vats,b,f,Cor ((d,vs),\
   909 				   \(id, pbl_ids' d vs))):itm)"
   909 				   \(id, pbl_ids' d vs))):itm)"
   910       | None => (i,vats,false,f,Sup (d,[vs])));
   910       | NONE => (i,vats,false,f,Sup (d,[vs])));
   911 
   911 
   912 (* chk_ thy pbt i
   912 (* chk_ thy pbt i
   913     *)
   913     *)
   914 
   914 
   915 fun eq2 (_,(d,_)) ((_,_,_,_,itm_):itm) = d = d_in itm_;
   915 fun eq2 (_,(d,_)) ((_,_,_,_,itm_):itm) = d = d_in itm_;
   929 
   929 
   930 (*. find elements of pbt not contained in itms;
   930 (*. find elements of pbt not contained in itms;
   931     if such one is untouched, return this one, otherwise create new itm .*)
   931     if such one is untouched, return this one, otherwise create new itm .*)
   932 fun chk_m (itms:itm list) untouched (p as (f,(d,id))) = 
   932 fun chk_m (itms:itm list) untouched (p as (f,(d,id))) = 
   933     case find_first (eq2 p) itms of
   933     case find_first (eq2 p) itms of
   934 	Some _ => []
   934 	SOME _ => []
   935       | None => (case find_first (eq2 p) untouched of
   935       | NONE => (case find_first (eq2 p) untouched of
   936 		     Some itm => [itm]
   936 		     SOME itm => [itm]
   937 		   | None => [(0,[],false,f,Mis (d,id)):itm]);
   937 		   | NONE => [(0,[],false,f,Mis (d,id)):itm]);
   938 (* val itms = itms'';
   938 (* val itms = itms'';
   939    *) 
   939    *) 
   940 fun chk_mis mvat itms untouched pbt = 
   940 fun chk_mis mvat itms untouched pbt = 
   941     let val mis = (flat o (map (chk_m itms untouched))) pbt; 
   941     let val mis = (flat o (map (chk_m itms untouched))) pbt; 
   942         val mid = max_id itms;
   942         val mid = max_id itms;
   974   let 
   974   let 
   975  (*0*)val mv = max_vt pbl;
   975  (*0*)val mv = max_vt pbl;
   976 
   976 
   977       fun eqdsc_pbt_itm ((_,(d,_))) ((_,_,_,_,itm_):itm) = d = d_in itm_;
   977       fun eqdsc_pbt_itm ((_,(d,_))) ((_,_,_,_,itm_):itm) = d = d_in itm_;
   978       fun notmem pbl pbt1 = case find_first (eqdsc_pbt_itm pbt1) pbl of
   978       fun notmem pbl pbt1 = case find_first (eqdsc_pbt_itm pbt1) pbl of
   979 				Some _ => false | None => true;
   979 				SOME _ => false | NONE => true;
   980  (*1*)val mis = (*(map (cons2 (fst, fst o snd)))o*) (filter (notmem pbl)) pbt;
   980  (*1*)val mis = (*(map (cons2 (fst, fst o snd)))o*) (filter (notmem pbl)) pbt;
   981 
   981 
   982       fun eqdsc_ori (_,(d,_)) ((_,_,_,d',_):ori) = d = d';
   982       fun eqdsc_ori (_,(d,_)) ((_,_,_,d',_):ori) = d = d';
   983       fun ori2itmMis (f,(d,pid)) ((i,v,_,_,ts):ori) = 
   983       fun ori2itmMis (f,(d,pid)) ((i,v,_,_,ts):ori) = 
   984 	  (i,v,false,f,Mis (d,pid)):itm;
   984 	  (i,v,false,f,Mis (d,pid)):itm;
  1000 
  1000 
  1001 (*. check an ori for matching a problemtype by description; 
  1001 (*. check an ori for matching a problemtype by description; 
  1002     returns true only for itms found in pbt .*)
  1002     returns true only for itms found in pbt .*)
  1003 fun chk1_ thy pbt ((i,vats,f,d,vs):ori) =
  1003 fun chk1_ thy pbt ((i,vats,f,d,vs):ori) =
  1004     case find_first (eq1 d) pbt of 
  1004     case find_first (eq1 d) pbt of 
  1005 	Some (_,(_,id)) => [(i,vats,true,f,
  1005 	SOME (_,(_,id)) => [(i,vats,true,f,
  1006 			     Cor ((d,vs), (id, pbl_ids' thy d vs))):itm]
  1006 			     Cor ((d,vs), (id, pbl_ids' thy d vs))):itm]
  1007       | None => [];
  1007       | NONE => [];
  1008 
  1008 
  1009 (* elem 'p' of pbt contained in itms ? *)
  1009 (* elem 'p' of pbt contained in itms ? *)
  1010 fun chk1_m (itms:itm list) p = 
  1010 fun chk1_m (itms:itm list) p = 
  1011     case find_first (eq2 p) itms of
  1011     case find_first (eq2 p) itms of
  1012 	Some _ => true | None => false;
  1012 	SOME _ => true | NONE => false;
  1013 fun chk1_m' (oris: ori list) (p as (f,(d,t))) = 
  1013 fun chk1_m' (oris: ori list) (p as (f,(d,t))) = 
  1014     case find_first (eq2' p) oris of
  1014     case find_first (eq2' p) oris of
  1015 	Some _ => []
  1015 	SOME _ => []
  1016       | None => [(f, Mis (d, t))];
  1016       | NONE => [(f, Mis (d, t))];
  1017 fun pair0vatsfalse (f,itm_) = (0,[],false,f,itm_):itm;
  1017 fun pair0vatsfalse (f,itm_) = (0,[],false,f,itm_):itm;
  1018 
  1018 
  1019 fun chk1_mis mvat itms ppc = foldl and_ (true, map (chk1_m itms) ppc);
  1019 fun chk1_mis mvat itms ppc = foldl and_ (true, map (chk1_m itms) ppc);
  1020 fun chk1_mis' oris ppc = 
  1020 fun chk1_mis' oris ppc = 
  1021     map pair0vatsfalse ((flat o (map (chk1_m' oris))) ppc);
  1021     map pair0vatsfalse ((flat o (map (chk1_m' oris))) ppc);
  1112 
  1112 
  1113   *)
  1113   *)
  1114 fun refin (pblRD:pblRD) ori 
  1114 fun refin (pblRD:pblRD) ori 
  1115 ((Ptyp (pI,[py],[])):pbt ptyp) =
  1115 ((Ptyp (pI,[py],[])):pbt ptyp) =
  1116     if match_oris (#thy py) (#prls py) ori (#ppc py, #where_ py) 
  1116     if match_oris (#thy py) (#prls py) ori (#ppc py, #where_ py) 
  1117     then Some ((pblRD @ [pI]):pblRD)
  1117     then SOME ((pblRD @ [pI]):pblRD)
  1118     else None
  1118     else NONE
  1119   | refin pblRD ori (Ptyp (pI,[py],pys)) =
  1119   | refin pblRD ori (Ptyp (pI,[py],pys)) =
  1120     if match_oris (#thy py) (#prls py) ori (#ppc py, #where_ py) 
  1120     if match_oris (#thy py) (#prls py) ori (#ppc py, #where_ py) 
  1121     then (case refins (pblRD @ [pI]) ori pys of
  1121     then (case refins (pblRD @ [pI]) ori pys of
  1122 	      Some pblRD' => Some pblRD'
  1122 	      SOME pblRD' => SOME pblRD'
  1123 	    | None => Some (pblRD @ [pI]))
  1123 	    | NONE => SOME (pblRD @ [pI]))
  1124     else None
  1124     else NONE
  1125 and refins pblRD ori [] = None
  1125 and refins pblRD ori [] = NONE
  1126   | refins pblRD ori ((p as Ptyp (pI,_,_))::pts) =
  1126   | refins pblRD ori ((p as Ptyp (pI,_,_))::pts) =
  1127     (case refin pblRD ori p of
  1127     (case refin pblRD ori p of
  1128 	 Some pblRD' => Some pblRD'
  1128 	 SOME pblRD' => SOME pblRD'
  1129        | None => refins pblRD ori pts);
  1129        | NONE => refins pblRD ori pts);
  1130 
  1130 
  1131 (*. refine a problem; version providing output for math-experts .*)
  1131 (*. refine a problem; version providing output for math-experts .*)
  1132 fun refin' (pblRD:pblRD) fmz pbls ((Ptyp (pI,[py],[])):pbt ptyp) =
  1132 fun refin' (pblRD:pblRD) fmz pbls ((Ptyp (pI,[py],[])):pbt ptyp) =
  1133 (* val ((pblRD:pblRD), fmz, pbls, ((Ptyp (pI,[py],[])):pbt ptyp)) =
  1133 (* val ((pblRD:pblRD), fmz, pbls, ((Ptyp (pI,[py],[])):pbt ptyp)) =
  1134        (rev ["linear","system"], fmz, [(*match list*)],
  1134        (rev ["linear","system"], fmz, [(*match list*)],
  1211    *)
  1211    *)
  1212 fun refine_ori oris (pblID:pblID) =
  1212 fun refine_ori oris (pblID:pblID) =
  1213     let val opt = app_ptyp (refin ((rev o tl) pblID) oris) 
  1213     let val opt = app_ptyp (refin ((rev o tl) pblID) oris) 
  1214 			   pblID (rev pblID) (!ptyps);
  1214 			   pblID (rev pblID) (!ptyps);
  1215     in case opt of 
  1215     in case opt of 
  1216 	   Some pblRD => let val (pblID':pblID) =(rev pblRD)
  1216 	   SOME pblRD => let val (pblID':pblID) =(rev pblRD)
  1217 			 in if pblID' = pblID then None
  1217 			 in if pblID' = pblID then NONE
  1218 			    else Some pblID' end
  1218 			    else SOME pblID' end
  1219 	 | None => None end;
  1219 	 | NONE => NONE end;
  1220 fun refine_ori' oris pI = (the (refine_ori oris pI)) handle _ => pI;
  1220 fun refine_ori' oris pI = (the (refine_ori oris pI)) handle _ => pI;
  1221 
  1221 
  1222 (*. for tactic Refine_Problem .*); 
  1222 (*. for tactic Refine_Problem .*); 
  1223 (* 10.03: returnvalue -> (pIrefined, itm list) would be sufficient *)
  1223 (* 10.03: returnvalue -> (pIrefined, itm list) would be sufficient *)
  1224 (* val pblID = pI; app_ptyp I pblID (rev pblID) (!ptyps);
  1224 (* val pblID = pI; app_ptyp I pblID (rev pblID) (!ptyps);
  1225    *)
  1225    *)
  1226 fun refine_pbl thy (pblID:pblID) itms =
  1226 fun refine_pbl thy (pblID:pblID) itms =
  1227     case refined_ (app_ptyp (refin'' thy ((rev o tl) pblID) itms []) 
  1227     case refined_ (app_ptyp (refin'' thy ((rev o tl) pblID) itms []) 
  1228 			    pblID (rev pblID) (!ptyps)) of
  1228 			    pblID (rev pblID) (!ptyps)) of
  1229 	None => None
  1229 	NONE => NONE
  1230       | Some (Match_ (rfd as (pI',_))) => 
  1230       | SOME (Match_ (rfd as (pI',_))) => 
  1231 	if pblID = pI' then None else Some rfd;
  1231 	if pblID = pI' then NONE else SOME rfd;
  1232 
  1232 
  1233 
  1233 
  1234 (*. for math-experts .*)
  1234 (*. for math-experts .*)
  1235 (*19.10.02FIXME: needs thy for parsing fmz*)
  1235 (*19.10.02FIXME: needs thy for parsing fmz*)
  1236 (* val fmz = fmz1; val pblID = ["pbla"]; val pblRD = (rev o tl) pblID; 
  1236 (* val fmz = fmz1; val pblID = ["pbla"]; val pblRD = (rev o tl) pblID;