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