src/Tools/isac/ME/mstools.sml
branchisac-update-Isa09-2
changeset 37924 6c53fe2519e5
parent 37923 4afbcd008799
child 37928 dfec2cf32f77
equal deleted inserted replaced
37923:4afbcd008799 37924:6c53fe2519e5
     5    author: Walther Neuper
     5    author: Walther Neuper
     6    (c) due to copyright terms
     6    (c) due to copyright terms
     7 
     7 
     8 use"ME/mstools.sml" (*re-evaluate sml/ from scratch!*);
     8 use"ME/mstools.sml" (*re-evaluate sml/ from scratch!*);
     9 use"mstools.sml";
     9 use"mstools.sml";
       
    10 12345678901234567890123456789012345678901234567890123456789012345678901234567890
       
    11         10        20        30        40        50        60        70        80
    10 *)
    12 *)
    11 
    13 
    12 signature SPECIFY_TOOLS =
    14 signature SPECIFY_TOOLS =
    13   sig
    15   sig
    14     type envv
    16     type envv
    21         | Superfl of string
    23         | Superfl of string
    22         | SyntaxE of string
    24         | SyntaxE of string
    23         | TypeE of string
    25         | TypeE of string
    24     val item2str : item -> string
    26     val item2str : item -> string
    25     type itm
    27     type itm
    26     val itm2str : Theory.theory -> itm -> string
    28     val itm2str_ : Proof.context -> itm -> string
    27     datatype
    29     datatype
    28       itm_ =
    30       itm_ =
    29           Cor of (Term.term * Term.term list) * (Term.term * Term.term list)
    31           Cor of (term * term list) * (term * term list)
    30         | Inc of (Term.term * Term.term list) * (Term.term * Term.term list)
    32         | Inc of (term * term list) * (term * term list)
    31         | Mis of Term.term * Term.term
    33         | Mis of term * term
    32         | Par of cterm'
    34         | Par of cterm'
    33         | Sup of Term.term * Term.term list
    35         | Sup of term * term list
    34         | Syn of cterm'
    36         | Syn of cterm'
    35         | Typ of cterm'
    37         | Typ of cterm'
    36     val itm_2str : itm_ -> string
    38     val itm_2str : itm_ -> string
    37     val itm__2str : Theory.theory -> itm_ -> string
    39     val itm_2str_ : Proof.context -> itm_ -> string
    38     val itms2str : Theory.theory -> itm list -> string
    40     val itms2str_ : Proof.context -> itm list -> string
    39     type 'a ppc
    41     type 'a ppc
    40     val ppc2str :
    42     val ppc2str :
    41        {Find: string list, With: string list, Given: string list,
    43        {Find: string list, With: string list, Given: string list,
    42          Where: string list, Relate: string list} -> string
    44          Where: string list, Relate: string list} -> string
    43     datatype
    45     datatype
    45           Matches of pblID * item ppc
    47           Matches of pblID * item ppc
    46         | NoMatch of pblID * item ppc
    48         | NoMatch of pblID * item ppc
    47     val match2str : match -> string
    49     val match2str : match -> string
    48     datatype
    50     datatype
    49       match_ =
    51       match_ =
    50           Match_ of pblID * (itm list * (bool * Term.term) list)
    52           Match_ of pblID * (itm list * (bool * term) list)
    51         | NoMatch_
    53         | NoMatch_
    52     val matchs2str : match list -> string
    54     val matchs2str : match list -> string
    53     type ori
    55     type ori
    54     val ori2str : ori -> string
    56     val ori2str : ori -> string
    55     val oris2str : ori list -> string
    57     val oris2str : ori list -> string
    56     type preori
    58     type preori
    57     val preori2str : preori -> string
    59     val preori2str : preori -> string
    58     val preoris2str : preori list -> string
    60     val preoris2str : preori list -> string
    59     type penv
    61     type penv
    60     (* val penv2str : Theory.theory -> penv -> string *)
    62     (* val penv2str_ : Proof.context -> penv -> string *)
    61     type vats
    63     type vats
    62     (*----------------------------------------------------------------------*)
    64     (*----------------------------------------------------------------------*)
    63     val all_ts_in : itm_ list -> Term.term list
    65     val all_ts_in : itm_ list -> term list
    64     val check_preconds :
    66     val check_preconds :
    65        'a ->
    67        'a ->
    66        rls ->
    68        rls ->
    67        Term.term list -> itm list -> (bool * Term.term) list
    69        term list -> itm list -> (bool * term) list
    68     val check_preconds' :
    70     val check_preconds' :
    69        rls ->
    71        rls ->
    70        Term.term list ->
    72        term list ->
    71        itm list -> 'a -> (bool * Term.term) list
    73        itm list -> 'a -> (bool * term) list
    72    (* val chkpre2item : rls -> Term.term -> bool * item  *)
    74    (* val chkpre2item : rls -> term -> bool * item  *)
    73     val pres2str : (bool * Term.term) list -> string
    75     val pres2str : (bool * term) list -> string
    74    (* val evalprecond : rls -> Term.term -> bool * Term.term  *)
    76    (* val evalprecond : rls -> term -> bool * term  *)
    75    (* val cnt : itm list -> int -> int * int *)
    77    (* val cnt : itm list -> int -> int * int *)
    76     val comp_dts : Theory.theory -> Term.term * Term.term list -> Thm.cterm
    78     val comp_dts : theory -> term * term list -> term
    77     val comp_dts' : Term.term * Term.term list -> Term.term
    79     val comp_dts' : term * term list -> term
    78     val comp_dts'' : Term.term * Term.term list -> string
    80     val comp_dts'' : term * term list -> string
    79     val comp_ts : Term.term * Term.term list -> Term.term
    81     val comp_ts : term * term list -> term
    80     val d_in : itm_ -> Term.term
    82     val d_in : itm_ -> term
    81     val de_item : item -> cterm'
    83     val de_item : item -> cterm'
    82     val dest_list : Term.term * Term.term list -> Term.term list (* for testing *)
    84     val dest_list : term * term list -> term list (* for testing *)
    83     val dest_list' : Term.term -> Term.term list
    85     val dest_list' : term -> term list
    84     val dts2str : Term.term * Term.term list -> string
    86     val dts2str : term * term list -> string
    85     val e_itm : itm
    87     val e_itm : itm
    86   (*  val e_listBool : Term.term  *)
    88   (*  val e_listBool : term  *)
    87   (*  val e_listReal : Term.term  *)
    89   (*  val e_listReal : term  *)
    88     val e_ori : ori
    90     val e_ori : ori
    89     val e_ori_ : ori
    91     val e_ori_ : ori
    90     val empty_ppc : item ppc
    92     val empty_ppc : item ppc
    91    (* val empty_ppc_ct' : cterm' ppc *)
    93    (* val empty_ppc_ct' : cterm' ppc *)
    92    (* val getval : Term.term * Term.term list -> Term.term * Term.term *)
    94    (* val getval : term * term list -> term * term *)
    93    (*val head_precond :
    95    (*val head_precond :
    94        domID * pblID * 'a ->
    96        domID * pblID * 'a ->
    95        Term.term Library.option ->
    97        term option ->
    96        rls ->
    98        rls ->
    97        Term.term list ->
    99        term list ->
    98        itm list -> 'b -> Term.term * (bool * Term.term) list*)
   100        itm list -> 'b -> term * (bool * term) list*)
    99    (* val init_item : string -> item *)
   101    (* val init_item : string -> item *)
   100    (* val is_matches : match -> bool *)
   102    (* val is_matches : match -> bool *)
   101    (* val is_matches_ : match_ -> bool *)
   103    (* val is_matches_ : match_ -> bool *)
   102     val is_var : Term.term -> bool
   104     val is_var : term -> bool
   103    (* val item_ppc :
   105    (* val item_ppc :
   104        string ppc -> item ppc  *)
   106        string ppc -> item ppc  *)
   105     val itemppc2str : item ppc -> string
   107     val itemppc2str : item ppc -> string
   106     val linefeed : string -> string
       
   107    (* val matches_pblID : match -> pblID *)
   108    (* val matches_pblID : match -> pblID *)
   108     val max2 : ('a * int) list -> 'a * int
   109     val max2 : ('a * int) list -> 'a * int
   109     val max_vt : itm list -> int
   110     val max_vt : itm list -> int
   110     val mk_e : itm_ -> (Term.term * Term.term) list
   111     val mk_e : itm_ -> (term * term) list
   111     val mk_en : int -> itm -> (Term.term * Term.term) list
   112     val mk_en : int -> itm -> (term * term) list
   112     val mk_env : itm list -> (Term.term * Term.term) list
   113     val mk_env : itm list -> (term * term) list
   113     val mkval : 'a -> Term.term list -> Term.term
   114     val mkval : 'a -> term list -> term
   114     val mkval' : Term.term list -> Term.term
   115     val mkval' : term list -> term
   115    (* val pblID_of_match : match -> pblID *)
   116    (* val pblID_of_match : match -> pblID *)
   116     val pbl_ids : Theory.theory -> Term.term -> Term.term -> Term.term list
   117     val pbl_ids : Proof.context -> term -> term -> term list
   117     val pbl_ids' : 'a -> Term.term -> Term.term list -> Term.term list
   118     val pbl_ids' : 'a -> term -> term list -> term list
   118    (* val pen2str : Theory.theory -> Term.term * Term.term list -> string *)
   119    (* val pen2str : theory -> term * term list -> string *)
   119     val penvval_in : itm_ -> Term.term list
   120     val penvval_in : itm_ -> term list
   120     val refined : match list -> pblID
   121     val refined : match list -> pblID
   121     val refined_ :
   122     val refined_ :
   122        match_ list -> match_ Library.option
   123        match_ list -> match_ option
   123   (*  val refined_IDitms :
   124   (*  val refined_IDitms :
   124        match list -> match Library.option  *)
   125        match list -> match option  *)
   125     val split_dts : 'a -> Term.term -> Term.term * Term.term list
   126     val split_dts : 'a -> term -> term * term list
   126     val split_dts' : Term.term * Term.term -> Term.term list
   127     val split_dts' : term * term -> term list
   127   (*  val take_apart : Term.term -> Term.term list  *)
   128   (*  val take_apart : term -> term list  *)
   128   (*  val take_apart_inv : Term.term list -> Term.term *)
   129   (*  val take_apart_inv : term list -> term *)
   129     val ts_in : itm_ -> Term.term list
   130     val ts_in : itm_ -> term list
   130    (* val unique : Term.term  *)
   131    (* val unique : term  *)
   131     val untouched : itm list -> bool
   132     val untouched : itm list -> bool
   132     val upd :
   133     val upd :
   133        Theory.theory ->
   134        Proof.context ->
   134        (''a * (''b * Term.term list) list) list ->
   135        (''a * (''b * term list) list) list ->
   135        Term.term ->
   136        term ->
   136        ''b * Term.term -> ''a -> ''a * (''b * Term.term list) list
   137        ''b * term -> ''a -> ''a * (''b * term list) list
   137     val upd_envv :
   138     val upd_envv :
   138        Theory.theory ->
   139        Proof.context ->
   139        envv ->
   140        envv ->
   140        vats ->
   141        vats ->
   141        Term.term -> Term.term -> Term.term -> envv
   142        term -> term -> term -> envv
   142     val upd_penv :
   143     val upd_penv :
   143        Theory.theory ->
   144        Proof.context ->
   144        (''a * Term.term list) list ->
   145        (''a * term list) list ->
   145        Term.term -> ''a * Term.term -> (''a * Term.term list) list
   146        term -> ''a * term -> (''a * term list) list
   146    (* val upds_envv :
   147    (* val upds_envv :
   147        Theory.theory ->
   148        Proof.context ->
   148        envv ->
   149        envv ->
   149        (vats * Term.term * Term.term * Term.term) list ->
   150        (vats * term * term * term) list ->
   150        envv                         *)
   151        envv                         *)
   151     val vts_cnt : int list -> itm list -> (int * int) list
   152     val vts_cnt : int list -> itm list -> (int * int) list
   152     val vts_in : itm list -> int list
   153     val vts_in : itm list -> int list
   153    (* val w_itms2str : Theory.theory -> itm list -> unit *)
   154    (* val w_itms2str_ : Proof.context -> itm list -> unit *)
   154   end
   155   end
   155 
   156 
   156 (*----------------------------------------------------------*)
   157 (*----------------------------------------------------------*)
   157 structure SpecifyTools : SPECIFY_TOOLS =
   158 structure SpecifyTools : SPECIFY_TOOLS =
   158 struct
   159 struct
   159 (*----------------------------------------------------------*)
   160 (*----------------------------------------------------------*)
   160 val e_listReal = (term_of o the o (parse Script.thy)) "[]::(real list)";
   161 val e_listReal = (term_of o the o (parse (theory "Script"))) "[]::(real list)";
   161 val e_listBool = (term_of o the o (parse Script.thy)) "[]::(bool list)";
   162 val e_listBool = (term_of o the o (parse (theory "Script"))) "[]::(bool list)";
   162 
   163 
   163 (*.take list-term apart w.r.t. handling elementwise input.*)
   164 (*.take list-term apart w.r.t. handling elementwise input.*)
   164 fun take_apart t =
   165 fun take_apart t =
   165     let val elems = isalist2list t
   166     let val elems = isalist2list t
   166     in map ((list2isalist (type_of (hd elems))) o single) elems end;
   167     in map ((list2isalist (type_of (hd elems))) o single) elems end;
   195     else (hd ts);
   196     else (hd ts);
   196 (*.revert split_.
   197 (*.revert split_.
   197  WN050903 we do NOT know which is from subtheory, description or term;
   198  WN050903 we do NOT know which is from subtheory, description or term;
   198  typecheck thus may lead to TYPE-error 'unknown constant';
   199  typecheck thus may lead to TYPE-error 'unknown constant';
   199  solution: typecheck with Isac.thy; i.e. arg 'thy' superfluous*)
   200  solution: typecheck with Isac.thy; i.e. arg 'thy' superfluous*)
   200 fun comp_dts thy (d,[]) = 
   201 (*fun comp_dts thy (d,[]) = 
   201     cterm_of ((sign_of o assoc_thy) "Isac.thy")
   202     cterm_of (*(sign_of o assoc_thy) "Isac.thy"*)
       
   203 	     (theory "Isac")
   202 	     (*comp_dts:FIXXME stay with term for efficiency !!!*)
   204 	     (*comp_dts:FIXXME stay with term for efficiency !!!*)
   203 	     (if is_reall_dsc d then (d $ e_listReal)
   205 	     (if is_reall_dsc d then (d $ e_listReal)
   204 	      else if is_booll_dsc d then (d $ e_listBool)
   206 	      else if is_booll_dsc d then (d $ e_listBool)
   205 	      else d)
   207 	      else d)
   206   | comp_dts thy (d,ts) =
   208   | comp_dts thy (d,ts) =
   207     (cterm_of ((sign_of o assoc_thy) "Isac.thy")
   209     (cterm_of (*(sign_of o assoc_thy) "Isac.thy"*)
       
   210 	      (theory "Isac")
   208 	      (*comp_dts:FIXXME stay with term for efficiency !!*)
   211 	      (*comp_dts:FIXXME stay with term for efficiency !!*)
   209 	      (d $ (comp_ts (d, ts)))
   212 	      (d $ (comp_ts (d, ts)))
   210        handle _ => raise error ("comp_dts: "^(term2str d)^
   213        handle _ => raise error ("comp_dts: "^(term2str d)^
   211 				" $ "^(term2str (hd ts)))); 
   214 				" $ "^(term2str (hd ts))));*)
       
   215 fun comp_dts thy (d,[]) = 
       
   216 	     (if is_reall_dsc d then (d $ e_listReal)
       
   217 	      else if is_booll_dsc d then (d $ e_listBool)
       
   218 	      else d)
       
   219   | comp_dts thy (d,ts) =
       
   220 	      (d $ (comp_ts (d, ts)))
       
   221        handle _ => raise error ("comp_dts: "^(term2str d)^
       
   222 				" $ "^(term2str (hd ts))); 
   212 (*25.8.03*)
   223 (*25.8.03*)
   213 fun comp_dts' (d,[]) = 
   224 fun comp_dts' (d,[]) = 
   214     if is_reall_dsc d then (d $ e_listReal)
   225     if is_reall_dsc d then (d $ e_listReal)
   215     else if is_booll_dsc d then (d $ e_listBool)
   226     else if is_booll_dsc d then (d $ e_listBool)
   216     else d
   227     else d
   363            but [#0, epsilon] only outcommented for eventual reconsideration  
   374            but [#0, epsilon] only outcommented for eventual reconsideration  
   364 *)
   375 *)
   365 type penv = (term          (*err_*)
   376 type penv = (term          (*err_*)
   366 	     * (term list) (*[#0, epsilon] 9.5.03 outcommented*)
   377 	     * (term list) (*[#0, epsilon] 9.5.03 outcommented*)
   367 	     ) list;
   378 	     ) list;
   368 fun pen2str thy (t, ts) =
   379 fun pen2str ctxt (t, ts) =
   369     pair2str(Syntax.string_of_term GOON (sign_of thy) t,
   380     pair2str(Syntax.string_of_term ctxt t,
   370 	     (strs2str' o map (Sign.string_of_term (sign_of thy))) ts);
   381 	     (strs2str' o map (Syntax.string_of_term ctxt)) ts);
   371 fun penv2str thy (penv:penv) = (strs2str' o (map (pen2str thy))) penv;
   382 fun penv2str_ thy (penv:penv) = (strs2str' o (map (pen2str thy))) penv;
   372 
   383 
   373 (*
   384 (*
   374   9.5.03: still unused, but left for eventual future development*)
   385   9.5.03: still unused, but left for eventual future development*)
   375 type envv = (int * penv) list; (*over variants*)
   386 type envv = (int * penv) list; (*over variants*)
   376 
   387 
   386 
   397 
   387 (*. get the constant value from a penv .*)
   398 (*. get the constant value from a penv .*)
   388 fun getval (id, values) = 
   399 fun getval (id, values) = 
   389     case values of
   400     case values of
   390 	[] => raise error ("penv_value: no values in '"^
   401 	[] => raise error ("penv_value: no values in '"^
   391 			   (Sign.string_of_term (sign_of Tools.thy) id))
   402 			   (Syntax.string_of_term (thy2ctxt "Tools") id))
   392       | [v] => (id, v)
   403       | [v] => (id, v)
   393       | (v1::v2::_) => (case v1 of 
   404       | (v1::v2::_) => (case v1 of 
   394 			     Const ("Script.Arbfix",_) => (id, v2)
   405 			     Const ("Script.Arbfix",_) => (id, v2)
   395 			   | _ => (id, v1));
   406 			   | _ => (id, v1));
   396 (*
   407 (*
   533   | mk_e (Typ _) = [] 
   544   | mk_e (Typ _) = [] 
   534   | mk_e (Inc (_, iv)) = [getval iv]
   545   | mk_e (Inc (_, iv)) = [getval iv]
   535   | mk_e (Sup _) = []
   546   | mk_e (Sup _) = []
   536   | mk_e (Mis _) = [];
   547   | mk_e (Mis _) = [];
   537 fun mk_en vt ((i,vts,b,f,itm_):itm) =
   548 fun mk_en vt ((i,vts,b,f,itm_):itm) =
   538     if vt mem vts then mk_e itm_ else [];
   549     if member op = vts vt then mk_e itm_ else [];
   539 (*. extract the environment from an item list; 
   550 (*. extract the environment from an item list; 
   540     takes the variant with most items .*)
   551     takes the variant with most items .*)
   541 fun mk_env itms = 
   552 fun mk_env itms = 
   542     let val vt = max_vt itms
   553     let val vt = max_vt itms
   543     in (flat o (map (mk_en vt))) itms end;
   554     in (flat o (map (mk_en vt))) itms end;
   578 val preoris2str = (strs2str' o (map (linefeed o preori2str)));
   589 val preoris2str = (strs2str' o (map (linefeed o preori2str)));
   579 
   590 
   580 (*. given the input value (from split_dts)
   591 (*. given the input value (from split_dts)
   581     make the value in a problem-env according to description-type .*)
   592     make the value in a problem-env according to description-type .*)
   582 (*28.8.01: .nam and .una impl. properly, others copied .. TODO*)
   593 (*28.8.01: .nam and .una impl. properly, others copied .. TODO*)
   583 (*9.5.03 penv-concept postponed *)
   594 fun pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.nam",_)]))) v =
   584 fun pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.nam",_)]))) v =
       
   585     if is_list v 
   595     if is_list v 
   586     then [v]         (*eg. [r=Arbfix]*)
   596     then [v]         (*eg. [r=Arbfix]*)
   587     else (case v of  (*eg. eps=#0*)
   597     else (case v of  (*eg. eps=#0*)
   588 	      (Const ("op =",_) $ l $ r) => [r,l]
   598 	      (Const ("op =",_) $ l $ r) => [r,l]
   589 	    | _ => raise error ("pbl_ids Tools.nam: no equality "
   599 	    | _ => raise error ("pbl_ids Tools.nam: no equality "
   590 				^(Sign.string_of_term (sign_of thy) v)))
   600 				^(Syntax.string_of_term ctxt v)))
   591   | pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.una",_)]))) v = [v]
   601   | pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.una",_)]))) v = [v]
   592   | pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.unl",_)]))) v = [v]
   602   | pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.unl",_)]))) v = [v]
   593   | pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.str",_)]))) v = [v]
   603   | pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.str",_)]))) v = [v]
   594   | pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.toreal",_)]))) v = [v] 
   604   | pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.toreal",_)]))) v = [v] 
   595   | pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.toreall",_)])))v = [v] 
   605   | pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.toreall",_)])))v = [v] 
   596   | pbl_ids thy (Const(_,Type("fun",[_,Type("Tools.unknown",_)])))v = [v] 
   606   | pbl_ids ctxt (Const(_,Type("fun",[_,Type("Tools.unknown",_)])))v = [v] 
   597   | pbl_ids thy _ v = raise error ("pbl_ids: not implemented for "
   607   | pbl_ids ctxt _ v = raise error ("pbl_ids: not implemented for "
   598 				    ^(Sign.string_of_term (sign_of thy) v));
   608 				    ^(Syntax.string_of_term ctxt v));
   599 (*
   609 (*
   600 val t as t1 $ t2 = str2term "antiDerivativeName M_b";
   610 val t as t1 $ t2 = str2term "antiDerivativeName M_b";
   601 pbl_ids thy t1 t2;
   611 pbl_ids ctxt t1 t2;
   602 
   612 
   603   val t = (term_of o the o (parse thy)) "fixedValues [r=Arbfix]";
   613   val t = (term_of o the o (parse thy)) "fixedValues [r=Arbfix]";
   604   val (d,argl) = strip_comb t;
   614   val (d,argl) = strip_comb t;
   605   is_dsc d;                      (*see split_dts*)
   615   is_dsc d;                      (*see split_dts*)
   606   dest_list (d,argl);
   616   dest_list (d,argl);
   607   val (_ $ v) = t;
   617   val (_ $ v) = t;
   608   is_list v;
   618   is_list v;
   609   pbl_ids thy d v;
   619   pbl_ids ctxt d v;
   610 [Const ("List.list.Cons","[bool, bool List.list] => bool List.list") $
   620 [Const ("List.list.Cons","[bool, bool List.list] => bool List.list") $
   611        (Const # $ Free # $ Const (#,#)) $ Const ("List.list.Nil","bool List..
   621        (Const # $ Free # $ Const (#,#)) $ Const ("List.list.Nil","bool List..
   612 
   622 
   613   val (dsc,vl) = (split_dts o term_of o the o (parse thy)) "solveFor x";
   623   val (dsc,vl) = (split_dts o term_of o the o (parse thy)) "solveFor x";
   614 val dsc = Const ("Descript.solveFor","RealDef.real => Tools.una") : term
   624 val dsc = Const ("Descript.solveFor","RealDef.real => Tools.una") : term
   615 val vl = Free ("x","RealDef.real") : term 
   625 val vl = Free ("x","RealDef.real") : term 
   616 
   626 
   617   val (dsc,id) = (split_did o term_of o the o (parse thy)) "solveFor v_";
   627   val (dsc,id) = (split_did o term_of o the o (parse thy)) "solveFor v_";
   618   pbl_ids thy dsc vl;
   628   pbl_ids ctxt dsc vl;
   619 val it = [Free ("x","RealDef.real")] : term list
   629 val it = [Free ("x","RealDef.real")] : term list
   620    
   630    
   621   val (dsc,vl) = (split_dts o term_of o the o(parse thy))
   631   val (dsc,vl) = (split_dts o term_of o the o(parse thy))
   622 		       "errorBound (eps=#0)";
   632 		       "errorBound (eps=#0)";
   623   val (dsc,id) = (split_did o term_of o the o(parse thy)) "errorBound err_";
   633   val (dsc,id) = (split_did o term_of o the o(parse thy)) "errorBound err_";
   624   pbl_ids thy dsc vl;
   634   pbl_ids ctxt dsc vl;
   625 val it = [Free ("#0","RealDef.real"),Free ("eps","RealDef.real")] : term list     *)
   635 val it = [Free ("#0","RealDef.real"),Free ("eps","RealDef.real")] : term list     *)
   626 
   636 
   627 (*. given an already input itm, ((14.9.01: no difference to pbl_ids jet!!))
   637 (*. given an already input itm, ((14.9.01: no difference to pbl_ids jet!!))
   628     make the value in a problem-env according to description-type .*)
   638     make the value in a problem-env according to description-type .*)
   629 (*28.8.01: .nam and .una impl. properly, others copied .. TODO*)
   639 (*28.8.01: .nam and .una impl. properly, others copied .. TODO*)
   631     (case vs of 
   641     (case vs of 
   632 	 [] => raise error ("pbl_ids' Tools.nam called with []")
   642 	 [] => raise error ("pbl_ids' Tools.nam called with []")
   633        | [t] => (case t of  (*eg. eps=#0*)
   643        | [t] => (case t of  (*eg. eps=#0*)
   634 		     (Const ("op =",_) $ l $ r) => [r,l]
   644 		     (Const ("op =",_) $ l $ r) => [r,l]
   635 		   | _ => raise error ("pbl_ids' Tools.nam: no equality "
   645 		   | _ => raise error ("pbl_ids' Tools.nam: no equality "
   636 				       ^(Sign.string_of_term (sign_of thy) t)))
   646 				       ^(Syntax.string_of_term (ctxt_Isac"")t)))
   637        | vs' => vs (*14.9.01: ???TODO *))
   647        | vs' => vs (*14.9.01: ???TODO *))
   638   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.una",_)]))) vs = vs
   648   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.una",_)]))) vs = vs
   639   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.unl",_)]))) vs = vs
   649   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.unl",_)]))) vs = vs
   640   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.str",_)]))) vs = vs
   650   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.str",_)]))) vs = vs
   641   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.toreal",_)]))) vs = vs 
   651   | pbl_ids' (Const(_,Type("fun",[_,Type("Tools.toreal",_)]))) vs = vs 
   648 fun pbl_ids' thy d vs = [comp_ts (d, vs)];
   658 fun pbl_ids' thy d vs = [comp_ts (d, vs)];
   649 
   659 
   650 
   660 
   651 (*14.9.01: not used after putting values for penv into itm_
   661 (*14.9.01: not used after putting values for penv into itm_
   652   WN.5.5.03: used in upd .. upd_envv*)
   662   WN.5.5.03: used in upd .. upd_envv*)
   653 fun upd_penv thy penv dsc (id, vl) =
   663 fun upd_penv ctxt penv dsc (id, vl) =
   654 (writeln"### upd_penv used !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
   664 (writeln"### upd_penv used !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
   655  writeln"### upd_penv used !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
   665  writeln"### upd_penv used !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
   656  writeln"### upd_penv used !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
   666  writeln"### upd_penv used !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
   657   overwrite (penv, (id, pbl_ids thy dsc vl))
   667   overwrite (penv, (id, pbl_ids ctxt dsc vl))
   658 );
   668 );
   659 (* 
   669 (* 
   660   val penv = [];
   670   val penv = [];
   661   val (dsc,vl) = (split_did o term_of o the o (parse thy)) "solveFor x";
   671   val (dsc,vl) = (split_did o term_of o the o (parse thy)) "solveFor x";
   662   val (dsc,id) = (split_did o term_of o the o (parse thy)) "solveFor v_";
   672   val (dsc,id) = (split_did o term_of o the o (parse thy)) "solveFor v_";
   676 *)
   686 *)
   677 
   687 
   678 (*WN.9.5.03: not reconsidered; looks strange !!!*)
   688 (*WN.9.5.03: not reconsidered; looks strange !!!*)
   679 fun upd thy envv dsc (id, vl) i =
   689 fun upd thy envv dsc (id, vl) i =
   680     let val penv = case assoc (envv, i) of
   690     let val penv = case assoc (envv, i) of
   681 		       Some e => e
   691 		       SOME e => e
   682 		     | None => [];
   692 		     | NONE => [];
   683         val penv' = upd_penv thy penv dsc (id, vl);
   693         val penv' = upd_penv thy penv dsc (id, vl);
   684     in (i, penv') end;
   694     in (i, penv') end;
   685 (*
   695 (*
   686   val i = 2;
   696   val i = 2;
   687   val envv = [(1,[]:penv),(2,[]:penv),(3,[]:penv)]:envv;
   697   val envv = [(1,[]:penv),(2,[]:penv),(3,[]:penv)]:envv;
   697     let val vats = if length vats = 0 
   707     let val vats = if length vats = 0 
   698 		   then (*unknown id to _all_ variants*)
   708 		   then (*unknown id to _all_ variants*)
   699 		       if length envv = 0 then [1]
   709 		       if length envv = 0 then [1]
   700 		       else (intsto o length) envv 
   710 		       else (intsto o length) envv 
   701 		   else vats
   711 		   else vats
   702 	fun isin vats (i,_) = i mem vats;
   712 	fun isin vats (i,_) = member op = vats i;
   703 	val envs_notin_vat = filter_out (isin vats) envv;
   713 	val envs_notin_vat = filter_out (isin vats) envv;
   704     in ((map (upd thy envv dsc (id, vl)) vats) @ envs_notin_vat):envv end;
   714     in ((map (upd thy envv dsc (id, vl)) vats) @ envs_notin_vat):envv end;
   705 (*
   715 (*
   706   val envv = [(1,[]:penv),(2,[]:penv),(3,[]:penv)]:envv;
   716   val envv = [(1,[]:penv),(2,[]:penv),(3,[]:penv)]:envv;
   707  
   717  
   775   | TypeE   of string (**)
   785   | TypeE   of string (**)
   776   | False   of cterm' (*WN050618 notexistent in itm_: only used in Where*)
   786   | False   of cterm' (*WN050618 notexistent in itm_: only used in Where*)
   777   | Incompl of cterm' (**)
   787   | Incompl of cterm' (**)
   778   | Superfl of string (**)
   788   | Superfl of string (**)
   779   | Missing of cterm';
   789   | Missing of cterm';
   780 fun item2str (Correct  s) ="Correct "^s
   790 fun item2str (Correct  s) ="Correct " ^ s
   781   | item2str (SyntaxE  s) ="SyntaxE "^s
   791   | item2str (SyntaxE  s) ="SyntaxE " ^ s
   782   | item2str (TypeE    s) ="TypeE "^s
   792   | item2str (TypeE    s) ="TypeE " ^ s
   783   | item2str (False    s) ="False "^s
   793   | item2str (False    s) ="False " ^ s
   784   | item2str (Incompl  s) ="Incompl "^s
   794   | item2str (Incompl  s) ="Incompl " ^ s
   785   | item2str (Superfl  s) ="Superfl "^s
   795   | item2str (Superfl  s) ="Superfl " ^ s
   786   | item2str (Missing  s) ="Missing "^s;
   796   | item2str (Missing  s) ="Missing " ^ s;
   787 (*make string for error-msgs*)
   797 (*make string for error-msgs*)
   788 fun itm__2str thy (Cor ((d,ts), penv)) = 
   798 fun itm_2str_ ctxt (Cor ((d,ts), penv)) = 
   789     "Cor " ^ string_of_cterm (comp_dts thy(d,ts)) ^" ,"^ pen2str thy penv
   799     "Cor " ^ Syntax.string_of_term ctxt (comp_dts ctxt (d,ts)) ^ " ,"
   790   | itm__2str thy (Syn c)      = "Syn "^c
   800     ^ pen2str ctxt penv
   791   | itm__2str thy (Typ c)      = "Typ "^c
   801   | itm_2str_ ctxt (Syn c)      = "Syn " ^ c
   792   | itm__2str thy (Inc ((d,ts), penv)) = 
   802   | itm_2str_ ctxt (Typ c)      = "Typ " ^ c
   793     "Inc " ^ string_of_cterm (comp_dts thy(d,ts)) ^" ,"^ pen2str thy penv
   803   | itm_2str_ ctxt (Inc ((d,ts), penv)) = 
   794   | itm__2str thy (Sup (d,ts)) = "Sup "^(string_of_cterm (comp_dts thy(d,ts)))
   804     "Inc " ^ Syntax.string_of_term ctxt (comp_dts ctxt (d,ts)) ^ " ,"
   795   | itm__2str thy (Mis (d,pid))= 
   805     ^ pen2str ctxt penv
   796     "Mis "^ Sign.string_of_term (sign_of thy) d ^
   806   | itm_2str_ ctxt (Sup (d,ts)) = 
   797     " "^ Sign.string_of_term (sign_of thy) pid
   807     "Sup " ^ Syntax.string_of_term ctxt (comp_dts ctxt (d,ts))
   798   | itm__2str thy (Par s) = "Trm "^s;
   808   | itm_2str_ ctxt (Mis (d,pid))= 
   799 fun itm_2str t = itm__2str (assoc_thy "Isac.thy") t;
   809     "Mis "^ Syntax.string_of_term ctxt d ^
   800 fun itm2str thy ((i,is,b,s,itm_):itm) = 
   810     " "^ Syntax.string_of_term ctxt pid
       
   811   | itm_2str_ ctxt (Par s) = "Trm "^s;
       
   812 fun itm_2str t = itm_2str_ (thy2ctxt "Isac") t;
       
   813 fun itm2str_ ctxt ((i,is,b,s,itm_):itm) = 
   801     "("^(string_of_int i)^" ,"^(ints2str' is)^" ,"^(bool2str b)^" ,"^
   814     "("^(string_of_int i)^" ,"^(ints2str' is)^" ,"^(bool2str b)^" ,"^
   802     s^" ,"^(itm__2str thy itm_)^")";
   815     s^" ,"^(itm_2str_ ctxt itm_)^")";
   803 val linefeed = (curry op^) "\n";
   816 fun itms2str_ ctxt itms = strs2str' (map (linefeed o (itm2str_ ctxt)) itms);
   804 fun itms2str thy itms = strs2str' (map (linefeed o (itm2str thy)) itms);
   817 fun w_itms2str_ ctxt itms = writeln (itms2str_ ctxt itms);
   805 fun w_itms2str thy itms = writeln (itms2str thy itms);
       
   806 
   818 
   807 fun init_item str = SyntaxE str;
   819 fun init_item str = SyntaxE str;
   808 
   820 
   809 
   821 
   810 
   822 
   894   | ts_in (Inc ((_,ts),_)) = ts
   906   | ts_in (Inc ((_,ts),_)) = ts
   895   | ts_in (Sup (_,ts)) = ts
   907   | ts_in (Sup (_,ts)) = ts
   896   | ts_in (Mis _) = [];
   908   | ts_in (Mis _) = [];
   897 (*WN050629 unused*)
   909 (*WN050629 unused*)
   898 fun all_ts_in itm_s = (flat o (map ts_in)) itm_s;
   910 fun all_ts_in itm_s = (flat o (map ts_in)) itm_s;
   899 val unique = (term_of o the o (parse Real.thy)) "UnIqE_tErM";
   911 val unique = (term_of o the o (parse (theory "Real"))) "UnIqE_tErM";
   900 fun d_in (Cor ((d,_),_)) = d
   912 fun d_in (Cor ((d,_),_)) = d
   901   | d_in (Syn  (c)) = (writeln("*** d_in: Syn ("^c^")"); unique)
   913   | d_in (Syn  (c)) = (writeln("*** d_in: Syn ("^c^")"); unique)
   902   | d_in (Typ  (c)) = (writeln("*** d_in: Typ ("^c^")"); unique)
   914   | d_in (Typ  (c)) = (writeln("*** d_in: Typ ("^c^")"); unique)
   903   | d_in (Inc ((d,_),_)) = d
   915   | d_in (Inc ((d,_),_)) = d
   904   | d_in (Sup (d,_)) = d
   916   | d_in (Sup (d,_)) = d
   916 
   928 
   917 (*. check a predicate labelled with indication of incomplete substitution;
   929 (*. check a predicate labelled with indication of incomplete substitution;
   918 rls ->    (*for eval_true*)
   930 rls ->    (*for eval_true*)
   919 bool * 	  (*have _all_ variables(Free) from the model-pattern 
   931 bool * 	  (*have _all_ variables(Free) from the model-pattern 
   920             been substituted by a value from the pattern's environment ?*)
   932             been substituted by a value from the pattern's environment ?*)
   921 Term.term (*the precondition*)
   933 term (*the precondition*)
   922 ->
   934 ->
   923 bool * 	  (*has the precondition evaluated to true*)
   935 bool * 	  (*has the precondition evaluated to true*)
   924 Term.term (*the precondition (for map)*)
   936 term (*the precondition (for map)*)
   925 .*)
   937 .*)
   926 fun evalprecond prls (false, pre) = 
   938 fun evalprecond prls (false, pre) = 
   927   (*NOT ALL Free's have been substituted, eg. because of incomplete model*)
   939   (*NOT ALL Free's have been substituted, eg. because of incomplete model*)
   928     (false, pre)
   940     (false, pre)
   929   | evalprecond prls (true, pre) =
   941   | evalprecond prls (true, pre) =
   967       fun vt_and_dsc d' ((i,v,f,d,ts):ori) =
   979       fun vt_and_dsc d' ((i,v,f,d,ts):ori) =
   968 	  vt mem v andalso d'= d
   980 	  vt mem v andalso d'= d
   969       fun cpy its [] (f, (d, id)) = 
   981       fun cpy its [] (f, (d, id)) = 
   970 	  if length its = 0        (*no dsc found in pbl*)
   982 	  if length its = 0        (*no dsc found in pbl*)
   971 	  then case find_first (vt_and_dsc d) oris
   983 	  then case find_first (vt_and_dsc d) oris
   972 		of Some (i,v,_,_,ts) => 
   984 		of SOME (i,v,_,_,ts) => 
   973 		   [(i,v,true,f, Cor ((d,ts), (id,pbl_ids' thy d ts)))]
   985 		   [(i,v,true,f, Cor ((d,ts), (id,pbl_ids' thy d ts)))]
   974 		 | None => [(0,[],false,f,Mis (d, id))]
   986 		 | NONE => [(0,[],false,f,Mis (d, id))]
   975 	  else its	       
   987 	  else its	       
   976 	| cpy its ((it as (i, vs, b, f, itm_))::itms) (pb as (x, (d, id))) =
   988 	| cpy its ((it as (i, vs, b, f, itm_))::itms) (pb as (x, (d, id))) =
   977 	  if d = d_in itm_ andalso i<>0 (*already touched by user*)
   989 	  if d = d_in itm_ andalso i<>0 (*already touched by user*)
   978 	  then cpy (its @ [it]) itms pb else cpy its itms pb;	  
   990 	  then cpy (its @ [it]) itms pb else cpy its itms pb;	  
   979   in ((flat o (map (cpy [] pbl))) met):itm list end;
   991   in ((flat o (map (cpy [] pbl))) met):itm list end;
  1016 (* val (pbl, met) = (itms, pbt);
  1028 (* val (pbl, met) = (itms, pbt);
  1017    *)
  1029    *)
  1018 fun copy_pbl (pbl:itm list) met oris =
  1030 fun copy_pbl (pbl:itm list) met oris =
  1019   let fun eqdsc_pbt_itm ((_,(d,_))) ((_,_,_,_,itm_):itm) = d = d_in itm_;
  1031   let fun eqdsc_pbt_itm ((_,(d,_))) ((_,_,_,_,itm_):itm) = d = d_in itm_;
  1020       fun notmem pbl pbt1 = case find_first (eqdsc_pbt_itm pbt1) pbl of
  1032       fun notmem pbl pbt1 = case find_first (eqdsc_pbt_itm pbt1) pbl of
  1021 				Some _ => false | None => true;
  1033 				SOME _ => false | NONE => true;
  1022  (*1*)val mis = ((map (cons2 (fst, fst o snd))) o (filter (notmem pbl))) met;
  1034  (*1*)val mis = ((map (cons2 (fst, fst o snd))) o (filter (notmem pbl))) met;
  1023 
  1035 
  1024       fun eqdsc_ori d ((_,_,_,d',_):ori) = d = d';
  1036       fun eqdsc_ori d ((_,_,_,d',_):ori) = d = d';
  1025       fun ori2itmMis f ((i,v,_,d,ts):ori) = (i,v,false,f,Mis (d,ts)):itm;
  1037       fun ori2itmMis f ((i,v,_,d,ts):ori) = (i,v,false,f,Mis (d,ts)):itm;
  1026       fun oris2itms oris mis1 = ((map (ori2itmMis (fst mis1)))
  1038       fun oris2itms oris mis1 = ((map (ori2itmMis (fst mis1)))