src/Tools/isac/Specify/specification.sml
author Walther Neuper <walther.neuper@jku.at>
Mon, 18 May 2020 14:05:46 +0200
changeset 59993 f43721d157f9
parent 59992 7431c60c4fcc
child 59994 c6546844dd26
permissions -rw-r--r--
delete unused code; + see 2adc8406b746
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@59977
    61
  type T = Specification_Def.T
neuper@37906
    62
walther@59992
    63
(*val reset_calchead: Calc.T -> Calc.T*)
walther@59992
    64
  val reset: Calc.T -> Calc.T
walther@59992
    65
(*val get_ocalhd: Calc.T -> T*)
walther@59992
    66
  val get: Calc.T -> T
walther@59992
    67
(*val get: Calc.T ->
walther@59992
    68
    I_Model.T * O_Model.T * References.T * I_Model.T * References.T * Proof.context*)
walther@59992
    69
  val get_data: Calc.T ->
walther@59992
    70
    I_Model.T * O_Model.T * References.T * I_Model.T * References.T * Proof.context
walther@59992
    71
walther@59992
    72
(*val ocalhd_complete: I_Model.T -> Pre_Conds.T -> ThyC.id * Problem.id * Method.id -> bool*)
walther@59992
    73
  val complete: I_Model.T -> Pre_Conds.T -> ThyC.id * Problem.id * Method.id -> bool
walther@59992
    74
(*val is_complete_mod: Calc.T -> bool*)
walther@59992
    75
  val is_complete: Calc.T -> bool
neuper@37906
    76
wneuper@59310
    77
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
walther@59981
    78
  (*NONE*)
walther@59886
    79
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59886
    80
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
wneuper@59265
    81
end
neuper@37906
    82
walther@59763
    83
(**)
walther@59992
    84
structure Specification(**): SPECIFICATION(**) =
neuper@37906
    85
struct
walther@59763
    86
(**)
walther@59957
    87
walther@59977
    88
type T = Specification_Def.T;
walther@59977
    89
wneuper@59265
    90
(* is the calchead complete ? *)
walther@59992
    91
fun complete its pre (dI, pI, mI) = 
walther@59939
    92
  foldl and_ (true, map #3 (its: I_Model.T)) andalso 
walther@59963
    93
  foldl and_ (true, map #1 (pre: Pre_Conds.T)) andalso 
walther@59903
    94
  dI <> ThyC.id_empty andalso pI <> Problem.id_empty andalso mI <> Method.id_empty
neuper@37906
    95
walther@59992
    96
(** )
walther@59957
    97
fun make m_field (term_as_string, i_model) =
walther@59957
    98
  case m_field of
walther@59957
    99
    "#Given" => Tactic.Add_Given' (term_as_string, i_model)
walther@59957
   100
  | "#Find" => Tactic.Add_Find' (term_as_string, i_model)
walther@59957
   101
  | "#Relate" => Tactic.Add_Relation'(term_as_string, i_model)
walther@59957
   102
  | str => raise ERROR ("specify_additem Frm, Pbl: uncovered case with " ^ str);
walther@59992
   103
( **)
walther@59992
   104
walther@59992
   105
fun get_data (pt, (p, _)) =
walther@59957
   106
  case Ctree.get_obj I pt p of
walther@59957
   107
    (Ctree.PblObj {meth, origin = (oris, (dI', pI', mI'), _), probl, spec = (dI, pI, mI), ctxt, ...})
walther@59985
   108
      => (meth, oris, (dI', pI', mI'), probl, (dI, pI, mI), ctxt)
walther@59957
   109
  | _ => raise ERROR "specify_additem: uncovered case of get_obj I pt p";
neuper@41994
   110
walther@59992
   111
fun is_complete (pt, pos as (p, Pos.Pbl)) =
walther@59957
   112
    if (Ctree.is_pblobj o (Ctree.get_obj I pt)) p 
walther@59988
   113
    then (I_Model.is_complete o (Ctree.get_obj Ctree.g_pbl pt)) p
walther@59992
   114
    else raise ERROR ("is_complete: called by PrfObj at " ^ Pos.pos'2str pos)
walther@59992
   115
  | is_complete (pt, pos as (p, Pos.Met)) = 
walther@59957
   116
    if (Ctree.is_pblobj o (Ctree.get_obj I pt)) p 
walther@59988
   117
    then (I_Model.is_complete o (Ctree.get_obj Ctree.g_met pt)) p
walther@59992
   118
    else raise ERROR ("is_complete: called by PrfObj at " ^ Pos.pos'2str pos)
walther@59992
   119
  | is_complete (_, pos) =
walther@59992
   120
    raise ERROR ("is_complete called by " ^ Pos.pos'2str pos ^ " (should be Pbl or Met)")
neuper@37906
   121
wneuper@59265
   122
(* get a calchead from a PblObj-node in the ctree; preconditions must be calculated *)
walther@59992
   123
fun get (pt, (p, Pos.Pbl)) = 
wneuper@59265
   124
    let
walther@59957
   125
	    val (ospec, hdf', spec, probl) = case Ctree.get_obj I pt p of
walther@59957
   126
	      Ctree.PblObj {origin = (_, ospec, hdf'), spec, probl,...} => (ospec, hdf', spec, probl)
walther@59992
   127
	    | _ => raise ERROR "get Pbl: uncovered case get_obj"
walther@59983
   128
      val {prls, where_, ...} = Problem.from_store (#2 (References.select ospec spec))
walther@59965
   129
      val pre = Pre_Conds.check' (ThyC.get_theory "Isac_Knowledge") prls where_ probl
wneuper@59265
   130
    in
walther@59992
   131
      (complete probl pre spec, Pos.Pbl, hdf', probl, pre, spec)
wneuper@59265
   132
    end
walther@59992
   133
  | get (pt, (p, Pos.Met)) = 
wneuper@59265
   134
    let
walther@59957
   135
		  val (ospec, hdf', spec, meth) = case Ctree.get_obj I pt p of
walther@59957
   136
		    Ctree.PblObj {origin = (_, ospec, hdf'), spec, meth, ...} => (ospec, hdf', spec, meth)
walther@59992
   137
		  | _ => raise ERROR "get Met: uncovered case get_obj"
walther@59983
   138
      val {prls, pre, ...} = Method.from_store (#3 (References.select ospec spec))
walther@59965
   139
      val pre = Pre_Conds.check' (ThyC.get_theory "Isac_Knowledge") prls pre meth
wneuper@59265
   140
    in
walther@59992
   141
      (complete meth pre spec, Pos.Met, hdf', meth, pre, spec)
wneuper@59265
   142
    end
walther@59992
   143
  | get _ = raise ERROR "get: uncovered definition"
neuper@37906
   144
walther@59977
   145
(* at the activeFormula set the Specification 
wneuper@59265
   146
   to empty and return a CalcHead;
wneuper@59265
   147
   the 'origin' remains (for reconstructing all that) *)
walther@59992
   148
fun reset (pt, (p,_)) = 
wneuper@59265
   149
  let
walther@59957
   150
    val () = case Ctree.get_obj I pt p of
walther@59957
   151
      Ctree.PblObj _ => ()
walther@59992
   152
    | _ => raise ERROR "reset: uncovered case get_obj"
walther@59957
   153
    val pt = Ctree.update_pbl pt p []
walther@59957
   154
    val pt = Ctree.update_met pt p []
walther@59976
   155
    val pt = Ctree.update_spec pt p References.empty
walther@59957
   156
  in (pt, (p, Pos.Pbl)) end
neuper@37906
   157
walther@59763
   158
(**)end(**)