src/Tools/isac/Specify/p-spec.sml
author wneuper <Walther.Neuper@jku.at>
Mon, 11 Dec 2023 17:26:30 +0100
changeset 60782 e797d1bdfe37
parent 60776 c2e6848d3dce
permissions -rw-r--r--
eliminate the intermediate *_POS
     1 (* Title:  Specify/p-spec.sml
     2    Author: Walther Neuper
     3    (c) due to copyright terms
     4 
     5 Major parts will be dropped at switch to Isabelle/PIDE.
     6 Thus the switch to I_Model.T is prepared quick and dirty.
     7 *)
     8 
     9 signature PRESENTATION_SPECIFICATION =
    10 sig
    11   type record
    12 (*/------- rename -------\*)
    13   datatype p_model =
    14       Find of TermC.as_string list
    15     | Given of TermC.as_string list
    16     | Relate of TermC.as_string list
    17 
    18   val appl_add': ThyC.id -> O_Model.T -> I_Model.T -> Model_Pattern.T ->
    19     string * TermC.as_string -> I_Model.single
    20   val appl_adds: ThyC.id -> O_Model.T -> I_Model.T -> Model_Pattern.T ->
    21     (Model_Def.m_field * TermC.as_string) list -> I_Model.T
    22   val eq7: ''a * ''b -> ''a * (''b * 'c) -> bool
    23   val fstr2itm_: theory -> Model_Pattern.T -> Model_Def.m_field * string ->
    24     int list * bool * Model_Def.m_field * (I_Model.feedback * Position.T)
    25   val imodel2fstr: p_model list -> (string * TermC.as_string) list
    26   val is_e_ts: term list -> bool
    27   val itms2fstr: Proof.context -> I_Model.single -> string * string
    28   val par2fstr: I_Model.single -> string * TermC.as_string
    29   val unknown_expl: ThyC.id -> Model_Pattern.T -> (Model_Def.m_field * string) list -> I_Model.T
    30 (*\----- from isac_test for Minisubpbl*)
    31 
    32 \<^isac_test>\<open>
    33 (**)
    34 \<close>
    35 (*\------- rename -------/*)
    36 end
    37 
    38 (**)
    39 structure P_Spec(**): PRESENTATION_SPECIFICATION(**) =
    40 struct
    41 (**)
    42 
    43   type record = {thy_id: ThyC.id, pbl_id: Problem.id,           (* headline of Problem *)
    44     givens: TermC.as_string list, wheres: TermC.as_string list, (* Model.T             *)
    45       find: TermC.as_string, relates: TermC.as_string list,
    46     rthy_id: ThyC.id, rpbl_id: Problem.id, rmet_id: MethodC.id}  (* References.T        *)
    47 
    48 fun flattup2 (a, (b ,c, d, e)) = (a, b, c, d, e)
    49 
    50 (** handle an input P_Specific'action **)
    51 
    52 datatype p_model = 
    53   Given of TermC.as_string list
    54 (*Where is still not input*) 
    55 | Find  of TermC.as_string list
    56 | Relate  of TermC.as_string list
    57 
    58 fun is_e_ts [] = true
    59   | is_e_ts [Const (\<^const_name>\<open>Nil\<close>, _)] = true
    60   | is_e_ts _ = false;
    61 
    62 fun appl_add' dI oris (model: I_Model.T) pbt (sel, ct) = 
    63   let 
    64      val ctxt = Know_Store.get_via_last_thy dI |> Proof_Context.init_global;
    65   in
    66     (*/------------ replace by ParseC.term_position ------------------\*)
    67     case ParseC.term_opt ctxt ct of
    68     (*\------------ replace by ParseC.term_position ------------------/*)
    69 	    NONE => (0, [], false, sel, (I_Model.Syn ct, Position.none))
    70 	  | SOME t =>
    71 	    (case O_Model.contains ctxt sel oris t of
    72         ("", ori', all) =>
    73           (case I_Model.is_notyet_input ctxt model all ori' pbt of
    74             ("", itm)  => itm
    75           | (msg,_) => raise ERROR ("P_Spec.appl_add': " ^ msg))
    76       | (_, (i, v, _, d, ts), _) =>
    77         if is_e_ts ts
    78         then (i, v, false, sel, (I_Model.Inc (d, ts), Position.none))
    79         else (i, v, false, sel, (I_Model.Sup (d, ts), Position.none)))
    80    end
    81 
    82 (* generate preliminary itm_ from a string (with field "#Given" etc.) *)
    83 fun eq7 (f, d) (f', (d', _)) = f = f' andalso d = d';
    84 fun fstr2itm_ thy pbt (f, str) =
    85   let
    86     (*/------------ replace by ParseC.term_position ? ------------\*)
    87     val topt = ParseC.term_opt (Proof_Context.init_global thy) str
    88     (*\------------ replace by ParseC.term_position ? ------------/*)
    89   in
    90     case topt of
    91       NONE => ([], false, f, (I_Model.Syn str, Position.none))
    92     | SOME ct => 
    93 	    let
    94 	      val (d, ts) = Input_Descript.split ct
    95 	      val popt = find_first (eq7 (f, d)) pbt
    96 	    in
    97 	      case popt of
    98 	        NONE => ([1](*??*), true(*??*), f, (I_Model.Sup (d, ts), Position.none))
    99 	      | SOME (f, (d, id)) => ([1], true, f, (I_Model.Cor (d, ts), Position.none))
   100 	    end
   101   end
   102 
   103 (*.input into empty PblObj, i.e. empty fmz+origin (unknown example).*)
   104 fun unknown_expl dI pbt selcts =
   105   let
   106     val thy = Know_Store.get_via_last_thy dI
   107     val its_ = map (fstr2itm_ thy pbt) selcts
   108     val its = O_Model.add_enumerate its_ 
   109   in map flattup2 its end
   110 
   111 fun eq_dsc ((_, _, _, _, (itm_, _)), (_, _, _, _, (iitm_, _))) =
   112   (I_Model.descriptor itm_ = I_Model.descriptor iitm_)
   113 fun add itm (itms: I_Model.T) = if member eq_dsc itms itm then itms else itms @ [itm] (* @ new itm *)
   114 fun appl_adds dI [] _ pbt selcts = unknown_expl dI pbt selcts
   115     (*already present itms in model are being overwritten*)
   116   | appl_adds _ _ (model: I_Model.T) _ [] = model
   117   | appl_adds dI oris (model: I_Model.T) pbt (selct :: ss) =
   118     let val itm = appl_add' dI oris model pbt selct;
   119     in appl_adds dI oris (add itm model) pbt ss end
   120 
   121 fun par2fstr (_, _, _, f, (I_Model.Syn s, _)) = (f, s)
   122   | par2fstr itm = raise ERROR ("par2fstr: called with " ^
   123     I_Model.single_to_string (ContextC.for_ERROR ()) itm)
   124 
   125 fun itms2fstr _ (_, _, _, f, (I_Model.Cor (d, ts), _)) = (f, Input_Descript.join''' (d, ts))
   126   | itms2fstr _ (_, _, _, f, (I_Model.Syn str, _)) = (f, str)
   127   | itms2fstr _ (_, _, _, f, (I_Model.Inc (d, ts), _)) = (f, Input_Descript.join''' (d,ts))
   128   | itms2fstr _ (_, _, _, f, (I_Model.Sup (d, ts), _)) = (f, Input_Descript.join''' (d, ts))
   129 
   130 fun imodel2fstr iitems = 
   131   let 
   132     fun xxx is [] = is
   133 	    | xxx is ((Given strs)::iis) = xxx (is @ (map (pair "#Given") strs)) iis
   134 	    | xxx is ((Find strs)::iis) = xxx (is @ (map (pair "#Find") strs)) iis
   135 	    | xxx is ((Relate strs)::iis) = xxx (is @ (map (pair "#Relate") strs)) iis
   136   in xxx [] iitems end;
   137 
   138 
   139 (**)end (**)