src/Tools/isac/Specify/specification.sml
author wneuper <Walther.Neuper@jku.at>
Mon, 11 Dec 2023 17:26:30 +0100
changeset 60782 e797d1bdfe37
parent 60779 fabe6923e819
permissions -rw-r--r--
eliminate the intermediate *_POS
     1 (* Title:  Specify/specification.sml
     2    Author: Walther Neuper, Mathias Lehnfeld
     3    (c) due to copyright terms
     4 *)
     5 
     6 (* Survey on type fmz_ .. type ori .. type itm (in probl, meth) .. formal args of root-/SubProblem
     7    and relations between respective list elements:                                       #1#
     8                   fmz      =             [ dsc $ v......................................(dsc $ v)..]
     9 root problem on pos = ([], _)            
    10                   fmz_     =             [(dsc, v).......................................(dsc, v)..]
    11                   \<down>                                                                       
    12                   oris     =             [(dsc, v)..(dsc, v),(dsc, v),(dsc, v)...........(dsc, v)..]
    13                   \<down>                       #Given,..,#Relate  #Find     #undef............#undef   \<down>
    14                   \<down>                                                     \<down>                 \<down>       \<down>
    15   Specify_Problem + pbl.model=             [(dsc,id)..(dsc,id),(dsc,id)]  \<down>                 \<down>       \<down>
    16                   \<down>                                                     \<down>                 \<down>       \<down>
    17                   itms     =             [(dsc, v)..(dsc, v),(dsc, v)]  \<down>                 \<down>       \<down>
    18   int.modelling                           +Cor ++++++++++Cor +Cor       \<down>                 \<down>       \<down>
    19                   \<down>                                                     \<down>                 \<down>       \<down>
    20   Specify_Method  + met.model=             [(dsc,id)..(dsc,id),(dsc,id)]  \<down>                 \<down>       \<down>
    21                   \<down>                                                     \<down>                 \<down>       \<down>
    22                   itms     =             [(dsc, v)..(dsc, v),(dsc, v),(dsc, v)..(dsc, v)] \<down>       \<down>
    23   int.modelling                                                       +Cor ++++++Cor      \<down>       \<down>
    24                   form.args=             [ id ..... id      , ///////  id ....... id    ] \<down>       \<down>
    25                   env =                  [(id, v)..(id, v)  , /////// (id, v)....(id, v)] \<down>       \<down>
    26   interpret code env = [(id, v)..(id, v), (id, v)..(id, v)  , /////// (id, v)....(id, v)] \<down>       \<down>
    27     ..extends env       ^^^^^^^^^^^^^^^^   \<down>                           \<down>   \<down>              \<down>       \<down>
    28                                    \<down>       \<down>                           \<down>   \<down>              \<down>       \<down>
    29 SubProblem on pos = ([2], _)       \<down>       \<down>                           \<down>   \<down>              \<down>       \<down>
    30                   form.args=      [id ................................ id ]\<down>              \<down>       \<down>
    31                   \<down>                REAL..BOOL..                            \<down>              \<down>       \<down>
    32                   \<down>                                                        \<down>              \<down>       \<down>
    33                   + met.model=      [(dsc,id).......................(dsc,id)]\<down>              \<down>       \<down>
    34                                     \<down>                               \<down>      \<down>              \<down>       \<down>
    35                   oris     =      [(dsc, v)...................... (dsc,   v) ........... (dsc, v)]\<down>
    36   Specify_Problem, int.modelling, Specify_Method, interpret code as above                 #1#    \<down>
    37                                                                                                   \<down>
    38 SubProblem on pos = ([3, 4], _)                                                                   \<down>
    39                   form.args=              [id ...................... id ]                         \<down>
    40                   \<down>                        REAL..BOOL..                                           \<down>
    41                   + met.model=              [(dsc,id).............(dsc,id)]                         \<down>
    42                   oris     =              [(dsc, v).............(dsc, v)...................(dsc, v)] 
    43   Specify_Problem, int.modelling, Specify_Method, interpret code as above                    #1#
    44 
    45 Notes:
    46 (1) SubProblem implements sub-function calls such, that the arguments(in/output + where_- + post-cond.)
    47     of the functions become concern of interactive modelling.
    48 (2) In Isac-terms, the above concerns the phases of modelling and 
    49     and of specifying (Specify_Problem, Specify_Method),
    50     while stepwise construction of Solution is called solving.
    51     The latter is supported by Lucas-Interpretation of the functions' body.
    52 (3) ori list is determined by fmz_ (in root-pbl) or by args of SubProblem;
    53     it is as complete as possible (this has been different up to now).
    54 (4) itm list is initialised by pbl-model | met-model and completed (Cor) by stepwise user input.
    55 (5) model-pattern of pbl can omit technical items, e.g. boundVariable or functionName,
    56     add them to the model-pattern of met and let this input be done automatically;
    57     respective items must be in fmz.
    58 *)
    59 signature SPECIFICATION =
    60 sig
    61 
    62   type T = Specification_Def.T
    63   val get: Calc.T -> T
    64   val get_data: Calc.T ->
    65     I_Model.T * O_Model.T * References.T * I_Model.T * References.T * Proof.context
    66   val reset: Calc.T -> Calc.T
    67 
    68   val is_complete': I_Model.T -> Pre_Conds.T -> References.T -> bool(*TODO:see I_Model.is_complete*)
    69   val is_complete: Calc.T -> bool                                   (*TODO:see I_Model.is_complete*)
    70 
    71 end
    72 
    73 (**)
    74 structure SpecificationC(**): SPECIFICATION(**) =
    75 struct
    76 (**)
    77 
    78 type T = Specification_Def.T;
    79 
    80 (** is SpecificationC complete? **)
    81 
    82 (* check i_model either for Problem or MethodC *)
    83 (*whether 
    84 (1) singles are all I_Model.Cor 
    85 (2) Pre_Conds are true
    86  * TODO-PIDE:
    87    * replace (1..2) by I_Model.is_complete
    88    * sort out References
    89  *)
    90 fun is_complete' its where_ (dI, pI, mI) = 
    91   foldl and_ (true, map #3 (its: I_Model.T)) andalso 
    92   foldl and_ (true, map #1 (where_: Pre_Conds.T)) andalso 
    93   dI <> ThyC.id_empty andalso pI <> Problem.id_empty andalso mI <> MethodC.id_empty
    94 
    95 fun is_complete (pt, (p, _)) =
    96   let
    97     val (itms, oris, probl, o_spec, spec, ctxt) = case Ctree.get_obj I pt p of
    98        Ctree.PblObj {meth = itms, origin = (oris, o_spec, _), probl, spec, ctxt, ...}
    99        => (itms, oris, probl, o_spec, spec, ctxt)
   100     | _ => raise ERROR "SpecificationC.is_complete only with PblObj"
   101     val (_, pbl_id, met_id) = References.select_input o_spec spec
   102   in
   103     I_Model.s_are_complete ctxt oris (probl, itms) (pbl_id, met_id)
   104   end
   105 
   106 (** handle acces to Ctree **)
   107 
   108 fun get_data (pt, (p, _)) =
   109   case Ctree.get_obj I pt p of
   110     (Ctree.PblObj {meth, origin = (oris, (dI', pI', mI'), _), probl, spec = (dI, pI, mI), ctxt, ...})
   111       => (meth, oris, (dI', pI', mI'), probl, (dI, pI, mI), ctxt)
   112   | _ => raise ERROR "specify_additem: uncovered case of get_obj I pt p";
   113 
   114 (* get a calchead from a PblObj-node in the ctree; preconditions must be calculated *)
   115 fun get (pt, (p, Pos.Pbl)) = 
   116     let
   117 	    val (ospec, hdf', spec, probl, ctxt) = case Ctree.get_obj I pt p of
   118 	      Ctree.PblObj {origin = (_, ospec, hdf'), spec, probl, ctxt, ...} =>
   119 	        (ospec, hdf', spec, probl, ctxt)
   120 	    | _ => raise ERROR "get Pbl: uncovered case get_obj"
   121       val {where_rls, where_, model, ...} =
   122         Problem.from_store ctxt (#2 (References.select_input ospec spec))
   123       val (_, where_) = Pre_Conds.check ctxt where_rls where_ 
   124         (model, probl)
   125     in
   126       (is_complete' probl where_ spec, Pos.Pbl, hdf', probl, where_, spec)
   127     end
   128   | get (pt, (p, Pos.Met)) = 
   129     let
   130 		  val (ospec, hdf', spec, meth, ctxt) = case Ctree.get_obj I pt p of
   131 		    Ctree.PblObj {origin = (_, ospec, hdf'), spec, meth, ctxt, ...} =>
   132 		      (ospec, hdf', spec, meth, ctxt)
   133 		  | _ => raise ERROR "get Met: uncovered case get_obj"
   134       val {where_rls, where_, model, ...} =
   135         MethodC.from_store ctxt (#3 (References.select_input ospec spec))
   136       val (_, where_)  = Pre_Conds.check ctxt where_rls where_ 
   137         (model, meth)
   138     in
   139       (is_complete' meth where_ spec, Pos.Met, hdf', meth, where_, spec)
   140     end
   141   | get _ = raise ERROR "get: uncovered definition"
   142 
   143 (* at the activeFormula set the Specification 
   144    to empty and return a CalcHead;
   145    the 'origin' remains (for reconstructing all that) *)
   146 fun reset (pt, (p,_)) = 
   147   let
   148     val () = case Ctree.get_obj I pt p of
   149       Ctree.PblObj _ => ()
   150     | _ => raise ERROR "reset: uncovered case get_obj"
   151     val pt = Ctree.update_pbl pt p []
   152     val pt = Ctree.update_met pt p []
   153     val pt = Ctree.update_spec pt p References.empty
   154   in (pt, (p, Pos.Pbl)) end
   155 
   156 (**)end(**)