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