src/Tools/isac/Specify/i-model.sml
changeset 60772 ac0317936138
parent 60771 1b072aab8f4e
child 60773 439e23525491
equal deleted inserted replaced
60771:1b072aab8f4e 60772:ac0317936138
    39   val single_to_string_POS': single_POS -> string
    39   val single_to_string_POS': single_POS -> string
    40   val to_string: Proof.context -> T -> string
    40   val to_string: Proof.context -> T -> string
    41   val to_string_POS: Proof.context -> T_POS -> string
    41   val to_string_POS: Proof.context -> T_POS -> string
    42 
    42 
    43   val feedback_OLD_to_POS: feedback -> feedback_POS
    43   val feedback_OLD_to_POS: feedback -> feedback_POS
    44 
    44   val feedback_POS_to_OLD: feedback_POS -> feedback
    45   datatype add_single = Add of single | Err of string
    45   val OLD_to_POS_single: single -> single_POS
       
    46   val TEST_to_OLD_single: single_POS -> single
       
    47 
       
    48   datatype add_single = Add of single_POS | Err of string
    46   val init: Model_Pattern.T -> T
    49   val init: Model_Pattern.T -> T
    47   val init_POS: Proof.context -> O_Model.T -> Model_Pattern.T -> T_POS
    50   val init_POS: Proof.context -> O_Model.T -> Model_Pattern.T -> T_POS
    48   val check_single: Proof.context -> m_field -> O_Model.T -> T -> Model_Pattern.T ->
    51   val check_single: Proof.context -> m_field -> O_Model.T -> T -> Model_Pattern.T ->
    49     TermC.as_string -> add_single
    52     TermC.as_string -> add_single
       
    53   (*probably unused in PIDE, thus-----v----v*)
    50   val add_single: theory -> single -> T -> T
    54   val add_single: theory -> single -> T -> T
    51 
    55 
    52   val make_tactic: m_field -> TermC.as_string * T -> Tactic.T
    56   val make_tactic: m_field -> TermC.as_string * T -> Tactic.T
    53 (*--*)
    57 
    54   val descriptor: feedback -> descriptor
    58   val descriptor: feedback -> descriptor
    55 (*--*)
       
    56   val descriptor_POS: feedback_POS -> descriptor
    59   val descriptor_POS: feedback_POS -> descriptor
    57   val values: feedback -> values option
    60   val values: feedback -> values option
    58   val o_model_values: feedback -> values
    61   val o_model_values: feedback -> values
    59   val values_POS': feedback_POS -> values
    62   val values_POS': feedback_POS -> values
    60   val descr_pairs_to_string: Proof.context -> (Model_Pattern.single * single_POS) list -> string
    63   val descr_pairs_to_string: Proof.context -> (Model_Pattern.single * single_POS) list -> string
    61   val variables: Model_Pattern.T -> Model_Def.i_model_POS -> term list
    64   val variables: Model_Pattern.T -> Model_Def.i_model_POS -> term list
    62   val is_notyet_input : Proof.context -> T -> O_Model.values -> O_Model.single -> Model_Pattern.T
    65   val is_notyet_input: Proof.context -> T_POS -> O_Model.values -> O_Model.single ->
    63     -> message * single
    66     Model_Pattern.T -> message * single_POS
    64   val get_field_term: theory -> O_Model.single -> single -> m_field * TermC.as_string
    67   val get_field_term: theory -> O_Model.single -> single -> m_field * TermC.as_string
    65 
    68 
    66   val fill_from_o: O_Model.T -> single_POS -> single_POS option
    69   val fill_from_o: O_Model.T -> single_POS -> single_POS option
    67 
    70 
    68   val add_other: variant -> T_POS -> single_POS -> single_POS
    71   val add_other: variant -> T_POS -> single_POS -> single_POS
    76 
    79 
    77 (*/----- from isac_test for Minisubpbl*)
    80 (*/----- from isac_test for Minisubpbl*)
    78   val msg: variants -> feedback_POS -> string
    81   val msg: variants -> feedback_POS -> string
    79   val transfer_terms: O_Model.single -> single_POS
    82   val transfer_terms: O_Model.single -> single_POS
    80 
    83 
    81   val eq1: ''a -> 'b * (''a * 'c) -> bool
       
    82   val feedback_to_string: Proof.context -> feedback -> string
    84   val feedback_to_string: Proof.context -> feedback -> string
    83   val feedback_POS_to_string: Proof.context -> feedback_POS -> string
    85   val feedback_POS_to_string: Proof.context -> feedback_POS -> string
    84   val descr_vals_to_string: Proof.context -> descriptor * values -> string
    86   val descr_vals_to_string: Proof.context -> descriptor * values -> string
    85   val feedb_args_to_string: Proof.context -> feedback_POS -> string
    87   val feedb_args_to_string: Proof.context -> feedback_POS -> string
    86 
    88 
    87   val ori_2itm: feedback -> descriptor -> Model_Def.values -> O_Model.single -> single
    89   val ori_2itm: feedback_POS -> descriptor -> Model_Def.values -> O_Model.single -> single_POS
    88   val seek_ppc: int -> T -> single option
    90   val seek_ppc: int -> T -> single option
    89   val overwrite_ppc: theory -> single -> T -> T
    91   val overwrite_ppc: theory -> single -> T -> T
    90 (*\----- from isac_test for Minisubpbl*)
    92 (*\----- from isac_test for Minisubpbl*)
    91 
    93 
    92 \<^isac_test>\<open>
    94 \<^isac_test>\<open>
    93   (**)
    95   (*copy "from isac_test for Minisubpbl" here*)
    94 
    96 
    95 \<close>
    97 \<close>
    96 
    98 
    97 end
    99 end
    98 
   100 
   139   | feedback_OLD_to_POS (Inc ((d, ts), _)) = (Model_Def.Inc_POS (d, ts))
   141   | feedback_OLD_to_POS (Inc ((d, ts), _)) = (Model_Def.Inc_POS (d, ts))
   140   | feedback_OLD_to_POS (Sup (d, ts)) = (Model_Def.Sup_POS (d, ts))
   142   | feedback_OLD_to_POS (Sup (d, ts)) = (Model_Def.Sup_POS (d, ts))
   141   | feedback_OLD_to_POS (Mis (d, pid)) = Model_Def.Syn_POS ((UnparseC.term (ContextC.for_ERROR ()) d) ^ " " ^
   143   | feedback_OLD_to_POS (Mis (d, pid)) = Model_Def.Syn_POS ((UnparseC.term (ContextC.for_ERROR ()) d) ^ " " ^
   142       (UnparseC.term (ContextC.for_ERROR ()) pid))
   144       (UnparseC.term (ContextC.for_ERROR ()) pid))
   143   | feedback_OLD_to_POS (Par s) = (Model_Def.Syn_POS s)
   145   | feedback_OLD_to_POS (Par s) = (Model_Def.Syn_POS s)
   144 fun OLD_to_POS i_old =
   146 fun OLD_to_POS_single (a, b, c, d, e) = (a, b, c, d, (feedback_OLD_to_POS e, Position.none))
   145   map (fn (a, b, c, d, e) => (a, b, c, d, (feedback_OLD_to_POS e, Position.none))) i_old
   147 fun OLD_to_POS i_old = map OLD_to_POS_single i_old
   146 
   148 
   147 fun feedback_POS_to_OLD (Model_Def.Cor_POS (d, ts)) = (Cor ((d, ts), (TermC.empty, [])))
   149 fun feedback_POS_to_OLD (Model_Def.Cor_POS (d, ts)) = (Cor ((d, ts), (TermC.empty, [])))
   148   | feedback_POS_to_OLD (Model_Def.Syn_POS c) = (Syn c)
   150   | feedback_POS_to_OLD (Model_Def.Syn_POS c) = (Syn c)
   149   | feedback_POS_to_OLD (Model_Def.Inc_POS (d, ts)) = (Inc ((d, ts), (TermC.empty, [])))
   151   | feedback_POS_to_OLD (Model_Def.Inc_POS (d, ts)) = (Inc ((d, ts), (TermC.empty, [])))
   150   | feedback_POS_to_OLD (Model_Def.Sup_POS (d, ts)) = (Sup (d, ts))
   152   | feedback_POS_to_OLD (Model_Def.Sup_POS (d, ts)) = (Sup (d, ts))
   151 fun TEST_to_OLD i_model = 
   153 fun TEST_to_OLD_single (a, b, c, d, (e, _)) = (a, b, c, d, feedback_POS_to_OLD e)
   152   map (fn (a, b, c, d, (e, _)) => (a, b, c, d, feedback_POS_to_OLD e)) i_model
   154 fun TEST_to_OLD i_model = map TEST_to_OLD_single i_model
   153 
   155 
   154 type message = string;
   156 type message = string;
   155 
   157 
   156 fun feedback_to_string ctxt (Cor ((d, ts), _)) = 
   158 fun feedback_to_string ctxt (Cor ((d, ts), _)) = 
   157     "Cor " ^ UnparseC.term  ctxt (Input_Descript.join (d, ts)) ^ " , pen2str"
   159     "Cor " ^ UnparseC.term  ctxt (Input_Descript.join (d, ts)) ^ " , pen2str"
   285 
   287 
   286 fun variables model_patt i_model =
   288 fun variables model_patt i_model =
   287   Pre_Conds.environment_POS model_patt i_model
   289   Pre_Conds.environment_POS model_patt i_model
   288   |> map snd
   290   |> map snd
   289 
   291 
       
   292 (*
   290 val unknown_descriptor = Syntax.read_term\<^context> "unknown::'a => unknow";
   293 val unknown_descriptor = Syntax.read_term\<^context> "unknown::'a => unknow";
   291 
   294 *)
   292 (* get a term from O_Model, notyet input in I_Model.
   295 (* get a term from O_Model, notyet input in I_Model.
   293    the term from O_Model is thrown back to a string in order to reuse
   296    the term from O_Model is thrown back to a string in order to reuse
   294    machinery for immediate input by the user. *)
   297    machinery for immediate input by the user. *)
   295 fun get_field_term thy (_, _, _, d, ts) (_, _, _, fd, itm_) =
   298 fun get_field_term thy (_, _, _, d, ts) (_, _, _, fd, itm_) =
   296   (fd, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, subtract op = (o_model_values itm_) ts))
   299   (fd, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, subtract op = (o_model_values itm_) ts))
   297 
   300 
   298 (*update the itm_ already input, all..from ori*)
   301 (*update the itm_ already input, all..from ori*)
   299 fun ori_2itm itm_ pid all (id, vt, fd, d, ts) = 
   302 fun ori_2itm (feedb:feedback_POS) _ all (id, vt, fd, d, ts) = 
   300   let 
   303   let 
   301     val ts' = union op = (o_model_values itm_) ts;
   304     val ts' = union op = (values_POS' feedb) ts;
   302     val pval = [Input_Descript.join'''' (d, ts')]
       
   303 	  (*WN.9.5.03: FIXXXME [#0, epsilon] here would upd_penv be called for [#0, epsilon] etc*)
       
   304     val complete = if eq_set op = (ts', all) then true else false
   305     val complete = if eq_set op = (ts', all) then true else false
   305   in
   306   in
   306     case itm_ of
   307     case feedb of
   307       (Cor _) => 
   308       Cor_POS _ => if fd = "#undef"
   308         (if fd = "#undef" then (id, vt, complete, fd, Sup (d, ts')) 
   309       then (id, vt, complete, fd, (Sup_POS (d, ts'), Position.none))
   309 	       else (id, vt, complete, fd, Cor ((d, ts'), (pid, pval))))
   310 	    else (id, vt, complete, fd, (Cor_POS (d, ts'), Position.none))
   310     | (Syn c) => raise ERROR ("ori_2itm wants to overwrite " ^ c)
   311     | Inc_POS _ => if complete
   311     | (Typ c) => raise ERROR ("ori_2itm wants to overwrite " ^ c)
   312   	  then (id, vt, true,  fd, (Cor_POS (d, ts'), Position.none))
   312     | (Inc _) =>
   313   	  else (id, vt, false, fd, (Inc_POS (d, ts'), Position.none))
   313       if complete
   314     | Sup_POS (d, ts') =>
   314   	  then (id, vt, true, fd, Cor ((d, ts'), (pid, pval)))
   315   	  (id, vt, complete, fd, (Sup_POS (d, ts'), Position.none))
   315   	  else (id, vt, false, fd, Inc ((d, ts'), (pid, pval)))
   316     | i => raise ERROR ("ori_2itm: uncovered case of " ^ feedback_POS_to_string (ContextC.for_ERROR ()) i)
   316     | (Sup (d,ts')) => (*4.9.01 lost env*)
       
   317   	  (*if fd = "#undef" then*) (id,vt,complete,fd,Sup(d,ts'))
       
   318   	  (*else (id,vt,complete,fd,Cor((d,ts'),e))*)
       
   319       (* 28.1.00: not completely clear ---^^^ etc.*)
       
   320     | (Mis _) => (* 4.9.01: Mis just copied *)
       
   321        if complete
       
   322   		 then (id, vt, true, fd, Cor ((d,ts'), (pid, pval)))
       
   323   		 else (id, vt, false, fd, Inc ((d,ts'), (pid, pval)))
       
   324     | i => raise ERROR ("ori_2itm: uncovered case of " ^ feedback_to_string (ContextC.for_ERROR ()) i)
       
   325   end
   317   end
   326 
   318 
   327 
   319 
   328 (** find next step **)
   320 (** find next step **)
   329 
   321 
   330 fun eq1 d (_, (d', _)) = (d = d')
   322 (*old code kept for test/*)
   331 fun eq3 f d (_, _, _, f', itm_) = f = f' andalso d = (descriptor itm_) 
       
   332 
       
   333 fun is_notyet_input ctxt itms all (i, v, f, d, ts) pbt =
   323 fun is_notyet_input ctxt itms all (i, v, f, d, ts) pbt =
   334   case find_first (eq1 d) pbt of
   324   case find_first (fn (_, (d', _)) => d = d') pbt of
   335     SOME (_, (_, pid)) =>
   325     SOME (_, (_, pid)) =>
   336       (case find_first (eq3 f d) itms of
   326       (case find_first (fn (_, _, _, f', (feedb, _)) =>
   337         SOME (_, _, _, _, itm_) =>
   327           f = f' andalso d = (descriptor_POS feedb)) itms of
   338           let val ts' = inter op = (o_model_values itm_) ts
   328         SOME (_, _, _, _, (feedb, _)) =>
   339           in 
   329           let val ts' = inter op = (values_POS' feedb) ts
       
   330           in
   340             if subset op = (ts, ts') 
   331             if subset op = (ts, ts') 
   341             then (((strs2str' o map (UnparseC.term ctxt)) ts') ^ " already input", empty_single)
   332             then (((strs2str' o map (UnparseC.term ctxt)) ts') ^ " already input", empty_single_POS)
   342 	          else ("", ori_2itm itm_ pid all (i, v, f, d, subtract op = ts' ts))
   333 	          else ("", ori_2itm feedb pid all (i, v, f, d, subtract op = ts' ts))
   343 	          end
   334 	        end
   344 	    | NONE => ("", ori_2itm (Inc ((TermC.empty, []), (pid, []))) pid all (i, v, f, d, ts)))
   335 	    | NONE => ("", ori_2itm (Inc_POS (TermC.empty, [])) pid all (i, v, f, d, ts)))
   345   | NONE => ("", ori_2itm (Sup (d, ts)) TermC.empty all (i, v, f, d, ts))
   336   | NONE => ("", ori_2itm (Sup_POS (d, ts)) TermC.empty all (i, v, f, d, ts))
   346 
   337 
   347 datatype add_single =
   338 datatype add_single =
   348 	Add of single   (* return-value of check_single *)
   339 	Add of single_POS   (* return-value of check_single *)
   349 | Err of string   (* error-message                *)
   340 | Err of string   (* error-message                *)
   350 
   341 
   351 (*
   342 (*
   352   Create feedback for input of TermC.as_string to m_field;
   343   Create feedback for input of TermC.as_string to m_field;
   353   check w.r.t. O_Model.T and Model_Pattern.T.
   344   check w.r.t. O_Model.T and Model_Pattern.T.
   363       val t = Syntax.read_term ctxt ct
   354       val t = Syntax.read_term ctxt ct
   364         handle ERROR msg => error (msg (*^ Position.here pos*))
   355         handle ERROR msg => error (msg (*^ Position.here pos*))
   365     (*\------------ replace by ParseC.term_position -----------/*)
   356     (*\------------ replace by ParseC.term_position -----------/*)
   366         (*NONE => Add (i, [], false, m_field, Syn ct)*)
   357         (*NONE => Add (i, [], false, m_field, Syn ct)*)
   367       val (d, ts) = Input_Descript.split t
   358       val (d, ts) = Input_Descript.split t
   368     in 
   359     in
   369       if d = TermC.empty then
   360       (*if d = TermC.empty then .. *)
   370         Add (i, [], false, m_field, Mis (unknown_descriptor, hd ts)) 
   361         (case find_first (fn (_, (d', _)) => d = d') m_patt of
   371       else
   362           NONE => Add (i, [], true, m_field, (Sup_POS (d,ts), Position.none))
   372         (case find_first (eq1 d) m_patt of
       
   373           NONE => Add (i, [], true, m_field, Sup (d,ts))
       
   374         | SOME (f, (_, id)) =>
   363         | SOME (f, (_, id)) =>
   375             let
   364           case find_first (fn (i, _, _, _, feedb) => d = (descriptor feedb) andalso i <> 0) i_model of
   376               fun eq2 d (i, _, _, _, itm_) = d = (descriptor itm_) andalso i <> 0
   365             NONE =>
   377             in
   366               Add (i, [], true, f, (Cor_POS (d, ts), Position.none))
   378               case find_first (eq2 d) i_model of
   367           | SOME (i', _, _, _, itm_) => 
   379                 NONE => Add (i, [], true, f,Cor ((d, ts), (id, [Input_Descript.join'''' (d, ts)])))
   368             if Input_Descript.for_list d then 
   380               | SOME (i', _, _, _, itm_) => 
   369               let
   381                   if Input_Descript.for_list d then 
   370                 val in_itm = o_model_values itm_
   382                     let
   371                 val ts' = union op = ts in_itm
   383                       val in_itm = o_model_values itm_
   372                 val i'' = if in_itm = [] then i else i'
   384                       val ts' = union op = ts in_itm
   373               in Add (i'', [], true, f, (Cor_POS (d, ts'), Position.none)) end
   385                       val i'' = if in_itm = [] then i else i'
   374             else Add (i', [], true, f, (Cor_POS (d, ts), Position.none)))
   386                     in Add (i'', [], true, f, Cor ((d, ts'), (id, [Input_Descript.join'''' (d, ts')])))end
       
   387                   else Add (i', [], true, f, Cor ((d, ts), (id, [Input_Descript.join'''' (d, ts)])))
       
   388             end)
       
   389     end
   375     end
   390     (*will come directly from PIDE ----------------------vvvvvvvvvvv*)
   376     (*will come directly from PIDE ----------------------vvvvvvvvvvv*)
   391   | check_single ctxt m_field o_model i_model m_patt (str(*, pos*)) =
   377   | check_single ctxt m_field o_model i_model m_patt (str(*, pos*)) =
   392     let
   378     let
   393       val (t as (descriptor $ _)) = Syntax.read_term ctxt str
   379       val (t as (descriptor $ _)) = Syntax.read_term ctxt str
   402             Err ("ERROR I_Model.check_single: \"" ^ UnparseC.term ctxt t ^ "\"" ^
   388             Err ("ERROR I_Model.check_single: \"" ^ UnparseC.term ctxt t ^ "\"" ^
   403              "\" not for field \"" ^ m_field ^ "\"")
   389              "\" not for field \"" ^ m_field ^ "\"")
   404           else
   390           else
   405             case O_Model.contains ctxt m_field o_model t of
   391             case O_Model.contains ctxt m_field o_model t of
   406               ("", ori', all) => 
   392               ("", ori', all) => 
   407                 (case is_notyet_input ctxt i_model all ori' m_patt of
   393                 (case is_notyet_input ctxt (OLD_to_POS i_model) all ori' m_patt of
   408                    ("", itm) => Add itm
   394                    ("", itm) => Add itm
   409                  | (msg, _) => Err ("ERROR I_Model.check_single: is_notyet_input: " ^ msg))
   395                  | (msg, _) => Err ("ERROR I_Model.check_single: is_notyet_input: " ^ msg))
   410             | (msg, _, _) => Err ("ERROR I_Model.check_single: contains: " ^ msg)
   396             | (msg, _, _) => Err ("ERROR I_Model.check_single: contains: " ^ msg)
   411     end
   397     end
   412      
   398      
   484       case find_first (fn (_, _, _, descr', _) => Model_Def.descriptor_exists descr' feedb) o_model of
   470       case find_first (fn (_, _, _, descr', _) => Model_Def.descriptor_exists descr' feedb) o_model of
   485         SOME (_, _, m_field, _, ts) =>  (m_field, ts)
   471         SOME (_, _, m_field, _, ts) =>  (m_field, ts)
   486       | NONE => raise ERROR "I_Model.fill_from_o does NOT find a descriptor in O_Model"
   472       | NONE => raise ERROR "I_Model.fill_from_o does NOT find a descriptor in O_Model"
   487     val descr = Model_Def.get_descr feedb (*i_single has been filtered appropriately*)
   473     val descr = Model_Def.get_descr feedb (*i_single has been filtered appropriately*)
   488   in
   474   in
   489 (*---------------vvvvvvvvvvvvv MV if TermC-is_list all_value-----*)
   475 (*---------------vvvvvvvvvvvvv MV if TermC.is_list all_value-----*)
   490     if Model_Def.is_list_descr descr
   476     if Model_Def.is_list_descr descr
   491     then
   477     then
   492       let
   478       let
   493         val already_input = feedb |> values_POS'
   479         val already_input = feedb |> values_POS'
   494         val miss = subtract op= already_input all_values (*"[[c], [c_2], [c_3], [c_4]]"*)
   480         val miss = subtract op= already_input all_values (*"[[c], [c_2], [c_3], [c_4]]"*)
   510     (case find_first (fn (_, vnts1, _, _, (feedb1, _)) => case Model_Def.get_dscr_opt feedb1 of
   496     (case find_first (fn (_, vnts1, _, _, (feedb1, _)) => case Model_Def.get_dscr_opt feedb1 of
   511           NONE => false
   497           NONE => false
   512         | SOME descr1 => descr1 = descr2 andalso Model_Def.member_vnt vnts1 max_vnt) i1_model of
   498         | SOME descr1 => descr1 = descr2 andalso Model_Def.member_vnt vnts1 max_vnt) i1_model of
   513       NONE =>
   499       NONE =>
   514         (i2, [max_vnt], bool2, m_field2, (Sup_POS (descr2, ts2), pos2)) (*the present in i2_model*)
   500         (i2, [max_vnt], bool2, m_field2, (Sup_POS (descr2, ts2), pos2)) (*the present in i2_model*)
   515     | SOME i1_single => i1_single)                      (*shift the item from i1_model to i2_model*)
   501     | SOME i1_single => i1_single)                     (*shift the item from i1_model to i2_model*)
   516   | add_other _ _ i2_single = i2_single                     (*keep all the other items in i2_model*)
   502   | add_other _ _ i2_single = i2_single                    (*keep all the other items in i2_model*)
   517 
   503 
   518 (*fill method from items already input*)
   504 (*fill method from items already input*)
   519 fun fill_method o_model (pbl_imod, met_imod) met_patt =
   505 fun fill_method o_model (pbl_imod, met_imod) met_patt =
   520   let
   506   let
   521     val pbl_max_vnts = Model_Def.max_variants o_model pbl_imod
   507     val pbl_max_vnts = Model_Def.max_variants o_model pbl_imod