src/Tools/isac/calcelems.sml
changeset 55448 dd65e9fe85a7
parent 55437 9c19751b2ad1
child 55449 b218049a9b4e
equal deleted inserted replaced
55437:9c19751b2ad1 55448:dd65e9fe85a7
   895 	 if length pys = 0
   895 	 if length pys = 0
   896 	 then error ("insert: not found "^(strs2str (d:pblID)))
   896 	 then error ("insert: not found "^(strs2str (d:pblID)))
   897 	 else ((Ptyp (k', [p], ps))::(insrt d pbt (k::ks) pys))
   897 	 else ((Ptyp (k', [p], ps))::(insrt d pbt (k::ks) pys))
   898 );
   898 );
   899 
   899 
       
   900 fun update_ptyps ID _ _ [] =
       
   901     error ("update_ptyps: " ^ strs2str' ID ^ " does not exist")
       
   902   | update_ptyps ID [i] data ((py as Ptyp (key, _, pys)) :: pyss) =
       
   903     if i = key
       
   904     then 
       
   905       if length pys = 0
       
   906       then ((Ptyp (key, [data], [])) :: pyss)
       
   907       else error ("update_ptyps: " ^ strs2str' ID ^ " has descendants")
       
   908     else py :: update_ptyps ID [i] data pyss
       
   909   | update_ptyps ID (i :: is) data ((py as Ptyp (key, d, pys)) :: pyss) =
       
   910     if i = key
       
   911     then ((Ptyp (key,  d, update_ptyps ID is data pys)) :: pyss)
       
   912     else (py :: (update_ptyps ID (i :: is) data pyss))
       
   913 
   900 (* this function only works wrt. the way Isabelle evaluates Theories and is not a general merge
   914 (* this function only works wrt. the way Isabelle evaluates Theories and is not a general merge
   901   function for trees / ptyps *)
   915   function for trees / ptyps *)
   902 fun merge_ptyps ([], pt) = pt
   916 fun merge_ptyps ([], pt) = pt
   903   | merge_ptyps (pt, []) = pt
   917   | merge_ptyps (pt, []) = pt
   904   | merge_ptyps ((x' as Ptyp (k, x, ps)) :: xs, (xs' as Ptyp (k', y, ps') :: ys)) =
   918   | merge_ptyps ((x' as Ptyp (k, x, ps)) :: xs, (xs' as Ptyp (k', y, ps') :: ys)) =
   905       if k = k'
   919       if k = k'
   906       then Ptyp (k, y, merge_ptyps (ps, ps')) :: merge_ptyps (xs, ys)
   920       then Ptyp (k, y, merge_ptyps (ps, ps')) :: merge_ptyps (xs, ys)
   907       else x' :: merge_ptyps (xs, xs');
   921       else x' :: merge_ptyps (xs, xs');
   908 
   922 fun merge_ptyps' pt1 pt2 = merge_ptyps (pt1, pt2)
   909 
   923 
   910 (* data for methods stored in 'methods'-database*)
   924 (* data for methods stored in 'methods'-database*)
   911 type met = 
   925 type met = 
   912      {guh        : guh,        (*unique within this isac-knowledge           *)
   926      {guh        : guh,        (*unique within this isac-knowledge           *)
   913       mathauthors: string list,(*copyright                                   *)
   927       mathauthors: string list,(*copyright                                   *)
  1004    argument 2 "(theID, thydata)::_ : (theID * thydata) list: contains thydata collected
  1018    argument 2 "(theID, thydata)::_ : (theID * thydata) list: contains thydata collected
  1005       automatically in Build_Thydata.thy finally.
  1019       automatically in Build_Thydata.thy finally.
  1006    parents of thydata in list, missing in thehier, are inserted 
  1020    parents of thydata in list, missing in thehier, are inserted 
  1007       (causing msgs '*** insert: not found');
  1021       (causing msgs '*** insert: not found');
  1008    (1) is kept in case (2) contains same theID (causing msgs '*** insert: preserved ') *)
  1022    (1) is kept in case (2) contains same theID (causing msgs '*** insert: preserved ') *)
  1009 fun the_hier th ([]: (theID * thydata) list) = th
  1023 fun (*KEStore_Elems.*)add_thes th thes = (* for tests bypassing setup KEStore_Elems *)
  1010   | the_hier th ((theID, thydata)::ths) =
  1024   let
  1011     if can_insert theID th 
  1025     fun add_the th ((thydata, theID)) =
  1012     then
  1026       if can_insert theID th 
       
  1027       then
       
  1028         if exist_the theID th
       
  1029         then (writeln ("*** insert: preserved " ^ strs2str theID); (fn x => x))
       
  1030         else insrt theID thydata theID
       
  1031       else
       
  1032         let
       
  1033           val th' = fill_parents th theID theID (*..*** insert: not found*)
       
  1034           val th' = insrt theID thydata theID th'
       
  1035         in merge_ptyps' th' end;
       
  1036 in fold (add_the th) thes end
       
  1037 
       
  1038 
       
  1039 fun update_hthm (Hthm {guh, coursedesign, mathauthors, thm, ...}) fillpats' =
       
  1040   Hthm {guh = guh, coursedesign = coursedesign, mathauthors = mathauthors,
       
  1041     fillpats = fillpats', thm = thm}
       
  1042   | update_hthm _ _ = raise ERROR "wrong data";
       
  1043 
       
  1044 (* for interface for dialog-authoring *)
       
  1045 fun update_hrls (Hrls {guh, coursedesign, mathauthors, thy_rls = (thyID, rls)}) errpatIDs =
       
  1046   let
       
  1047     val rls' = 
       
  1048       case rls of
       
  1049         Rls {id, preconds, rew_ord, erls, srls, calc, rules, scr, ...} =>
       
  1050           Rls {id = id, preconds = preconds, rew_ord = rew_ord, erls = erls, srls = srls,
       
  1051             calc = calc, rules = rules, scr = scr, errpatts = errpatIDs}
       
  1052       | Seq {id, preconds, rew_ord, erls, srls, calc, rules, scr, ...} =>
       
  1053             Seq {id = id, preconds = preconds, rew_ord = rew_ord, erls = erls, srls = srls,
       
  1054               calc = calc, rules = rules, scr = scr, errpatts = errpatIDs}
       
  1055       | Rrls {id, prepat, rew_ord, erls, calc, scr, ...} =>
       
  1056             Rrls {id = id, prepat = prepat, rew_ord = rew_ord, erls = erls, calc = calc,
       
  1057               scr = scr, errpatts = errpatIDs}
       
  1058       | Erls => Erls
       
  1059   in
       
  1060     Hrls {guh = guh, coursedesign = coursedesign, mathauthors = mathauthors,
       
  1061       thy_rls = (thyID, rls')}
       
  1062   end
       
  1063   | update_hrls _ _ = raise ERROR "wrong data";
       
  1064 
       
  1065 fun app_py p f (d:pblID) (k(*:pblRD*)) = let
       
  1066     fun py_err _ =
       
  1067           error ("app_py: not found: " ^ (strs2str d));
       
  1068     fun app_py' _ [] = py_err ()
       
  1069       | app_py' [] _ = py_err ()
       
  1070       | app_py' [k0] ((p' as Ptyp (k', _, _  ))::ps) =
       
  1071           if k0 = k' then f p' else app_py' [k0] ps
       
  1072       | app_py' (k' as (k0::ks)) (Ptyp (k'', _, ps)::ps') =
       
  1073           if k0 = k'' then app_py' ks ps else app_py' k' ps';
       
  1074   in app_py' k p end;
       
  1075   
       
  1076 fun get_py p = let
       
  1077         fun extract_py (Ptyp (_, [py], _)) = py
       
  1078           | extract_py _ = error ("extract_py: Ptyp has wrong format.");
       
  1079       in app_py p extract_py end;
       
  1080 
       
  1081 (*
       
  1082 fun (*KEStore_Elems.*)insert_fillpats th fis = (* for tests bypassing setup KEStore_Elems *)
       
  1083   let
       
  1084     fun update_elem th (theID, fillpats) =
  1013       let
  1085       let
  1014         val th' =
  1086         val hthm = get_py th theID theID
  1015           if exist_the theID th
  1087         val hthm' = update_hthm hthm fillpats
  1016           then (writeln ("*** insert: preserved " ^ strs2str theID); th)
  1088           handle ERROR _ => error ("insert_fillpats: " ^ strs2str theID ^ "must address a theorem")
  1017           else insrt theID thydata theID th
  1089       in update_ptyps theID theID hthm' end
  1018       in the_hier th' ths end
  1090   in fold (update_elem th) fis end
  1019     else
  1091   *)
  1020       let
       
  1021         val th' = fill_parents th theID theID (*..*** insert: not found*)
       
  1022         val th' = insrt theID thydata theID th'
       
  1023       in the_hier th' ths end;
       
  1024     
       
  1025 (*
  1092 (*
  1026 end (*struct*)
  1093 end (*struct*)
  1027 *)
  1094 *)