src/Tools/isac/ME/calchead.sml
branchisac-update-Isa09-2
changeset 37932 722c19bfb6ba
parent 37931 2d12beb7f983
child 37934 56f10b13005e
equal deleted inserted replaced
37931:2d12beb7f983 37932:722c19bfb6ba
   277 
   277 
   278 
   278 
   279 (*.to an input (d,ts) find the according ori and insert the ts.*)
   279 (*.to an input (d,ts) find the according ori and insert the ts.*)
   280 (*WN.11.03: + dont take first inter<>[]*)
   280 (*WN.11.03: + dont take first inter<>[]*)
   281 fun seek_oridts thy sel (d,ts) [] = 
   281 fun seek_oridts thy sel (d,ts) [] = 
   282   ("'"^(string_of_cterm (comp_dts thy (d,ts)))^
   282   ("'"^(Syntax.string_of_term (thy2ctxt' thy) (comp_dts thy (d,ts)))^
   283  (*"' not found (typed)", e_ori_:ori, [])          ///11.11.03*)
   283  (*"' not found (typed)", e_ori_:ori, [])          ///11.11.03*)
   284    "' not found (typed)", (0,[],sel,d,ts):ori, [])
   284    "' not found (typed)", (0,[],sel,d,ts):ori, [])
   285   (* val (id,vat,sel',d',ts')::oris = ori;
   285   (* val (id,vat,sel',d',ts')::oris = ori;
   286      val (id,vat,sel',d',ts') = ori;
   286      val (id,vat,sel',d',ts') = ori;
   287      *)
   287      *)
   288   | seek_oridts thy sel (d,ts) ((id,vat,sel',d',ts')::(oris:ori list)) =
   288   | seek_oridts thy sel (d,ts) ((id,vat,sel',d',ts')::(oris:ori list)) =
   289     if sel = sel' andalso d=d' andalso (ts inter ts') <> [] 
   289     if sel = sel' andalso d=d' andalso (ts inter ts') <> [] 
   290       then if sel = sel' 
   290       then if sel = sel' 
   291 	     then ("",(id,vat,sel,d, ts inter(*!overlap!*) ts'):ori, ts')
   291 	     then ("",(id,vat,sel,d, ts inter(*!overlap!*) ts'):ori, ts')
   292 	   else ((string_of_cterm (comp_dts thy(d,ts)))^
   292 	   else ((Syntax.string_of_term (thy2ctxt' thy) (comp_dts thy(d,ts)))^
   293 		 " not for "^sel, e_ori_, [])
   293 		 " not for "^sel, e_ori_, [])
   294     else seek_oridts thy sel (d,ts) oris;
   294     else seek_oridts thy sel (d,ts) oris;
   295 
       
   296 (*FIXXXME.WN.11.03: + dont take first inter<>[] .. ev. variants are following:
       
   297  thus take largest intersection !!!
       
   298  if sel NOTok .. then the correct itm should NOT be overwritten by insert_ppc*)
       
   299 (*fun eq7 d (_,_,_,d',_) = d = d';
       
   300 fun inter_length ((_,_,_,_,ts), (_,_,_,_,ts')) = (length ts) < (length ts');
       
   301 fun seek_oridts _ sel (d,ts) [] = 
       
   302   ("'"^(string_of_cterm (comp_dts thy (d,ts)))^
       
   303  (*"' not found (typed)", e_ori_:ori, [])          ///11.11.03*)
       
   304    "' not found (typed)", (0,[],sel,d,ts):ori, [])
       
   305   (* val (id,vat,sel',d',ts')::oris = ori;
       
   306      val (id,vat,sel',d',ts') = ori;
       
   307      *)
       
   308   | seek_oridts _ sel (d,ts) oris =
       
   309     let val dscOK = filter (eq7 d) oris; 
       
   310     in if dscOK = [] then ("'"^(string_of_cterm (comp_dts thy (d,ts)))^
       
   311 			   "' not found (typed)", (0,[],sel,d,ts):ori, [])
       
   312        else let val (id,vat,sel',d',ts') = gen_max inter_length dscOK;
       
   313 	    in if sel = sel' then ("",(id,vat,sel,d,ts inter ts'), [])
       
   314 	       else ("wrong field",(id,vat,sel,d,ts inter ts'), []) end
       
   315     end;
       
   316 --------------------didnt work with Add_Given/_Find/_Relation 11.03*)
       
   317 
   295 
   318 (*.to an input (_,ts) find the according ori and insert the ts.*)
   296 (*.to an input (_,ts) find the according ori and insert the ts.*)
   319 fun seek_orits thy sel ts [] = 
   297 fun seek_orits thy sel ts [] = 
   320   ("'"^
   298   ("'"^
   321    (strs2str (map (Sign.string_of_term (sign_of thy)) ts))^
   299    (strs2str (map (Syntax.string_of_term (thy2ctxt' thy)) ts))^
   322    "' not found (typed)", e_ori_, [])
   300    "' not found (typed)", e_ori_, [])
   323   | seek_orits thy sel ts ((id,vat,sel',d,ts')::(oris:ori list)) =
   301   | seek_orits thy sel ts ((id,vat,sel',d,ts')::(oris:ori list)) =
   324     if sel = sel' andalso (ts inter ts') <> [] 
   302     if sel = sel' andalso (ts inter ts') <> [] 
   325       then if sel = sel' 
   303       then if sel = sel' 
   326 	   then ("",(id,vat,sel,d,ts inter(*!overlap!*) ts'):ori, ts')
   304 	   then ("",(id,vat,sel,d,ts inter(*!overlap!*) ts'):ori, ts')
   327 	   else (((strs2str' o map (Sign.string_of_term (sign_of thy))) ts)^
   305 	   else (((strs2str' o map (Syntax.string_of_term (thy2ctxt' thy))) ts)^
   328 		 " not for "^sel, e_ori_, [])
   306 		 " not for "^sel, e_ori_, [])
   329     else seek_orits thy sel ts oris;
   307     else seek_orits thy sel ts oris;
   330 (* false
   308 (* false
   331 > val ((id,vat,sel',d,ts')::(ori':ori)) = ori;
   309 > val ((id,vat,sel',d,ts')::(ori':ori)) = ori;
   332 > seek_orits thy sel ts [(id,vat,sel',d,ts')];
   310 > seek_orits thy sel ts [(id,vat,sel',d,ts')];
   428   let 
   406   let 
   429     val tss = flat (map isalist2list ts);
   407     val tss = flat (map isalist2list ts);
   430 (*28.1.     val (dcr,t') = split_dsc_t fdcrs t; *)
   408 (*28.1.     val (dcr,t') = split_dsc_t fdcrs t; *)
   431     val (dcr,[t']) = split_dts t;
   409     val (dcr,[t']) = split_dts t;
   432   in if (typeless t') mem (map typeless tss)
   410   in if (typeless t') mem (map typeless tss)
   433             then ("term '"^(Sign.string_of_term (sign_of thy) t')^
   411             then ("term '"^(Syntax.string_of_term (thy2ctxt' thy) t')^
   434 		  "' already input")
   412 		  "' already input")
   435 	  else "" end;
   413 	  else "" end;
   436 
   414 
   437 > val pts = appc (map (term_of o the o (parse thy))) pbl;
   415 > val pts = appc (map (term_of o the o (parse thy))) pbl;
   438 > val ts = #Relate pts;
   416 > val ts = #Relate pts;
   797 	   SOME (_,_,_,_,itm_) =>
   775 	   SOME (_,_,_,_,itm_) =>
   798 	   let 
   776 	   let 
   799 	       val ts' = (ts_in itm_) inter ts;
   777 	       val ts' = (ts_in itm_) inter ts;
   800 	   in if ts subset ts' 
   778 	   in if ts subset ts' 
   801 	      then (((strs2str' o 
   779 	      then (((strs2str' o 
   802 		      map (Sign.string_of_term (sign_of thy))) ts')^
   780 		      map (Syntax.string_of_term (thy2ctxt' thy))) ts')^
   803 		    " already input", e_itm)                            (*2*)
   781 		    " already input", e_itm)                            (*2*)
   804 	      else ("", ori_2itm thy itm_ pid all (i,v,f,d,ts\\ts'))    (*3,4*)
   782 	      else ("", ori_2itm thy itm_ pid all (i,v,f,d,ts\\ts'))    (*3,4*)
   805 	   end
   783 	   end
   806 	 | NONE => ("", ori_2itm thy (Inc ((e_term,[]),(pid,[]))) 
   784 	 | NONE => ("", ori_2itm thy (Inc ((e_term,[]),(pid,[]))) 
   807 				 pid all (i,v,f,d,ts))                  (*1*)
   785 				 pid all (i,v,f,d,ts))                  (*1*)
   819 	   let 
   797 	   let 
   820 	       val ts' = (ts_in itm_) inter ts;
   798 	       val ts' = (ts_in itm_) inter ts;
   821 	   in if ts'= [] then ("", ori_2itm itm_ (pid, pval) all 
   799 	   in if ts'= [] then ("", ori_2itm itm_ (pid, pval) all 
   822 					    (id,vt,fd,d,(ts_in itm_)@ts))
   800 					    (id,vt,fd,d,(ts_in itm_)@ts))
   823 	      else (((strs2str' o 
   801 	      else (((strs2str' o 
   824 		      map (Sign.string_of_term (sign_of thy))) ts')^
   802 		      map (Syntax.string_of_term (thy2ctxt' thy))) ts')^
   825 		    " already input", e_itm) end
   803 		    " already input", e_itm) end
   826 	 | NONE => 
   804 	 | NONE => 
   827 	   if all = ts 
   805 	   if all = ts 
   828 	   then ("", ori_2itm (Cor ((e_term,[]),(pid,[])))
   806 	   then ("", ori_2itm (Cor ((e_term,[]),(pid,[])))
   829 			      (pid, pval) all (id,vt,fd,d,ts))
   807 			      (pid, pval) all (id,vt,fd,d,ts))
   886 			  | msg => (msg, e_ori_, []))
   864 			  | msg => (msg, e_ori_, []))
   887 		     | (msg,_,_) => (msg, e_ori_, []))
   865 		     | (msg,_,_) => (msg, e_ori_, []))
   888 	 else 
   866 	 else 
   889 	     if d mem (map #4 ori) 
   867 	     if d mem (map #4 ori) 
   890 	     then seek_oridts thy sel (d,ts) ori
   868 	     then seek_oridts thy sel (d,ts) ori
   891 	     else ((Sign.string_of_term (sign_of thy) d)^
   869 	     else ((Syntax.string_of_term (thy2ctxt' thy) d)^
   892 		   (*" not in example", e_ori_, []) ///11.11.03*)
   870 		   (*" not in example", e_ori_, []) ///11.11.03*)
   893 		   " not in example", (0,[],sel,d,ts), [])
   871 		   " not in example", (0,[],sel,d,ts), [])
   894   end;
   872   end;
   895 
   873 
   896 
   874 
  1208 
  1186 
  1209 
  1187 
  1210 (* test-printouts ---
  1188 (* test-printouts ---
  1211 val _=writeln("### insert_ppc: (d,ts)="^(string_of_cterm(comp_dts thy(d,ts))));
  1189 val _=writeln("### insert_ppc: (d,ts)="^(string_of_cterm(comp_dts thy(d,ts))));
  1212  val _=writeln("### insert_ppc: pts= "^
  1190  val _=writeln("### insert_ppc: pts= "^
  1213 (strs2str' o map (Sign.string_of_term (sign_of thy))) pts);
  1191 (strs2str' o map (Syntax.string_of_term (thy2ctxt' thy))) pts);
  1214 
  1192 
  1215 
  1193 
  1216  val sel = "#Given"; val Add_Given' ct = m;
  1194  val sel = "#Given"; val Add_Given' ct = m;
  1217 
  1195 
  1218  val sel = "#Find"; val Add_Find' (ct,_) = m; 
  1196  val sel = "#Find"; val Add_Find' (ct,_) = m; 
  1865 	    then ("re\\(gi union fi)",re\\(gi union fi))
  1843 	    then ("re\\(gi union fi)",re\\(gi union fi))
  1866 	  else ("ok",[]) end;*)
  1844 	  else ("ok",[]) end;*)
  1867 fun chk_vars ctppc = 
  1845 fun chk_vars ctppc = 
  1868   let val {Given=gi,Where=wh,Find=fi,With=wi,Relate=re} = 
  1846   let val {Given=gi,Where=wh,Find=fi,With=wi,Relate=re} = 
  1869           appc flat (mappc (vars o term_of) ctppc)
  1847           appc flat (mappc (vars o term_of) ctppc)
  1870   in let val chked = subtract op = gi wh
  1848       val chked = subtract op = gi wh
  1871              if chked <> [] then ("wh\\gi", chked)
  1849   in if chked <> [] then ("wh\\gi", chked)
  1872      else let val chked = subtract op = (union op = gi fi) re
  1850      else let val chked = subtract op = (union op = gi fi) re
  1873                   if chked  <> []
  1851           in if chked  <> []
  1874 	    then ("re\\(gi union fi)", chked)
  1852 	     then ("re\\(gi union fi)", chked)
  1875 	  else ("ok", []) end;
  1853 	     else ("ok", []) 
       
  1854           end
       
  1855   end;
  1876 
  1856 
  1877 (* check a new pbltype: variables (Free) unbound by given, find*) 
  1857 (* check a new pbltype: variables (Free) unbound by given, find*) 
  1878 fun unbound_ppc ctppc =
  1858 fun unbound_ppc ctppc =
  1879   let val {Given=gi,Find=fi,Relate=re,...} = 
  1859   let val {Given=gi,Find=fi,Relate=re,...} = 
  1880     appc flat (mappc (vars o term_of) ctppc)
  1860     appc flat (mappc (vars o term_of) ctppc)