test/Tools/isac/Minisubpbl/150a-add-given-Maximum.sml
author wneuper <Walther.Neuper@jku.at>
Sat, 25 Nov 2023 15:33:14 +0100
changeset 60767 466f0a5bfb73
parent 60766 2e0603ca18a4
child 60768 14da2230d5c3
permissions -rw-r--r--
followup 4: cleanup new code
Walther@60578
     1
(* Title:  "Minisubpbl/150a-add-given-Maximum.sml"
Walther@60578
     2
   Author: Walther Neuper 1105
Walther@60578
     3
   (c) copyright due to lincense terms.
Walther@60578
     4
Walther@60729
     5
COMPARE Specify/specify.sml --- specify-phase: low level functions ---
Walther@60729
     6
Walther@60705
     7
ATTENTION: the file creates buffer overflow if copied in one piece !
Walther@60705
     8
Walther@60659
     9
Note: This test --- steps into me --- more than once, to a somewhat extreme extent;
Walther@60578
    10
  in order not to get lost while working in Test_Some etc, 
Walther@60578
    11
  re-introduce  ML (*--- step into XXXXX ---*) and Co.
Walther@60578
    12
  and use Sidekick for orientation.
Walther@60659
    13
  Nesting is indicated by  /---   //--   ///-  at the left margin of the comments.
Walther@60578
    14
*)
Walther@60578
    15
Walther@60763
    16
open Model_Def
Walther@60728
    17
open ME_Misc
Walther@60733
    18
open Pre_Conds;
Walther@60578
    19
Walther@60578
    20
val (_(*example text*),
Walther@60578
    21
  (model as ("Constants [r = (7::real)]" :: "Maximum A" :: "AdditionalValues [u, v]" :: 
Walther@60578
    22
     "Extremum (A = 2 * u * v - u \<up> 2)" :: 
Walther@60578
    23
     "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]" :: 
Walther@60578
    24
     "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]" :: 
Walther@60728
    25
     "SideConditions [(u::real) / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>]" ::
Walther@60728
    26
(*---------------------------------------------,(v::real) / 2 = r * cos \<alpha>]" --- ERROR in example*)
Walther@60578
    27
     "FunctionVariable a" :: "FunctionVariable b" :: "FunctionVariable \<alpha>" :: 
Walther@60578
    28
     "Domain {0 <..< r}" :: "Domain {0 <..< r}" :: "Domain {0 <..< \<pi> / 2}" ::
Walther@60578
    29
     "ErrorBound (\<epsilon> = (0::real))" :: []), 
Walther@60578
    30
   refs as ("Diff_App", 
Walther@60578
    31
     ["univariate_calculus", "Optimisation"],
Walther@60578
    32
     ["Optimisation", "by_univariate_calculus"])))
Walther@60588
    33
  = Store.get (Know_Store.get_expls @{theory}) ["Diff_App-No.123a"] ["Diff_App-No.123a"];
Walther@60578
    34
Walther@60578
    35
val c = [];
Walther@60728
    36
val return_init_calc = 
Walther@60728
    37
 Test_Code.init_calc @{context} [(model, refs)]; (*val Model_Problem = nxt;*)
Walther@60728
    38
(*/------------------- step into init_calc -------------------------------------------------\\*)
Walther@60728
    39
"~~~~~ fun init_calc , args:"; val (ctxt, [(model, refs as (thy_id, _, _))]) =
Walther@60728
    40
  (@{context}, [(model, refs)]);
Walther@60728
    41
    val thy = thy_id |> ThyC.get_theory ctxt
Walther@60728
    42
    val ((pt, p), tacis) = Step_Specify.initialise' thy (model, refs)
Walther@60728
    43
	  val tac = case tacis of [] => Tactic.Empty_Tac | _ => (#1 o hd) tacis
Walther@60728
    44
	  val f = 
Walther@60728
    45
           TESTg_form ctxt (pt,p);
Walther@60728
    46
"~~~~~ fun TESTg_form , args:"; val (ctxt, ptp) = (ctxt, (pt,p));
Walther@60728
    47
    val (form, _, _) =
Walther@60728
    48
   ME_Misc.pt_extract ctxt ptp;
Walther@60728
    49
"~~~~~ fun pt_extract , args:"; val (ctxt, (pt, (p, p_ as Pbl(*Frm,Pbl*)))) = (ctxt, ptp);
Walther@60728
    50
        val ppobj = Ctree.get_obj I pt p
Walther@60728
    51
        val f = if Ctree.is_pblobj ppobj then pt_model ppobj p_ else Ctree.get_obj pt_form pt p;
Walther@60728
    52
            (*if*) Ctree.is_pblobj ppobj (*then*);
Walther@60728
    53
           pt_model ppobj p_ ;
Walther@60728
    54
"~~~~~ fun pt_model , args:"; val ((Ctree.PblObj {probl, spec, origin = (_, spec', hdl), ctxt, ...}), Pbl_) =
Walther@60728
    55
  (ppobj, p_);
Walther@60728
    56
      val (_, pI, _) = Ctree.get_somespec' spec spec';
Walther@60728
    57
(*    val where_ = if pI = Problem.id_empty then []*)
Walther@60728
    58
               (*if*) pI = Problem.id_empty (*else*);
Walther@60728
    59
	          val {where_rls, where_, model, ...} = Problem.from_store ctxt pI
Walther@60728
    60
	          val (_, where_) = 
Walther@60741
    61
 Pre_Conds.check ctxt where_rls where_
Walther@60728
    62
              (model, I_Model.OLD_to_TEST probl);
Walther@60741
    63
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
    64
  (ctxt, where_rls, where_, (model, I_Model.OLD_to_TEST probl));
Walther@60758
    65
      val (env_model, (env_subst, env_eval)) = 
Walther@60758
    66
           make_environments model_patt i_model;
Walther@60758
    67
"~~~~~ fun make_environments , args:"; val (_, []) = (model_patt, i_model);
Walther@60728
    68
(*\------------------- step into init_calc -------------------------------------------------//*)
Walther@60763
    69
val (p,_,f,nxt,_,pt) = return_init_calc;   val Model_Problem = nxt
Walther@60763
    70
val (p, _, f, nxt, _, pt) = me nxt p c pt; val Add_Given "Constants [r = 7]" = nxt
Walther@60763
    71
val return_me_add_find_Constants =
Walther@60763
    72
           me nxt p c pt; val Add_Find "Maximum A" = #4 return_me_add_find_Constants;
Walther@60728
    73
(*/------------------- step into me_add_find_Constants -------------------------------------\\*)
Walther@60728
    74
"~~~~~ fun me , args:"; val (tac as Add_Given "Constants [r = 7]", p, _(*NEW remove*), pt) =
Walther@60728
    75
  (nxt, p, c, pt);
Walther@60728
    76
      val ctxt = Ctree.get_ctxt pt p
Walther@60728
    77
(*+*)val PblObj {probl = (1, [1, 2, 3], false, "#Given", Inc 
Walther@60728
    78
    ((Const ("Input_Descript.Constants", _), []), _)) :: _, ...}  = get_obj I pt (fst p)
Walther@60728
    79
(*-------------------------------------------^^--*)
Walther@60728
    80
val return_step_by_tactic = (*case*) 
Walther@60728
    81
      Step.by_tactic tac (pt, p) (*of*);
Walther@60728
    82
(*//------------------ step into Step.by_tactic --------------------------------------------\\*)
Walther@60728
    83
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60728
    84
val Applicable.Yes tac' =
Walther@60741
    85
    (*case*) Specify_Step.check tac (pt, p) (*of*);
Walther@60728
    86
	    (*if*) Tactic.for_specify' tac' (*then*);
Walther@60763
    87
Walther@60763
    88
(** )val return_step_by_tactic =( **)
Walther@60763
    89
(**)val return_step_specify_by_tactic =(**)
Walther@60728
    90
Step_Specify.by_tactic tac' ptp;
Walther@60763
    91
(*///----------------- step into Step_Specify.by_tactic ------------------------------------\\*)
Walther@60728
    92
"~~~~~ fun by_tactic , args:"; val ((Tactic.Add_Given' (ct, _)), (pt, p)) = (tac', ptp);
Walther@60728
    93
Walther@60763
    94
(** )val calling_code =( **)
Walther@60763
    95
(**)val return_by_Add_ =(**)
Walther@60728
    96
   Specify.by_Add_ "#Given" ct (pt, p);
Walther@60763
    97
(*////---------------- step by_Add_ --------------------------------------------------------\\*)
Walther@60728
    98
"~~~~~ fun by_Add_ , args:"; val (m_field, ct, (pt, pos as (_, p_))) = ("#Given", ct, (pt, p));
Walther@60728
    99
    val (met, oris, (_, pI', mI'), pbl, (_, pI, mI), ctxt) = SpecificationC.get_data (pt, pos);
Walther@60763
   100
Walther@60763
   101
val false =
Walther@60728
   102
       (*if*) p_ = Pos.Met (*else*);
Walther@60763
   103
val (i_model, m_patt) =
Walther@60728
   104
         (pbl,
Walther@60728
   105
           (if pI = Problem.id_empty then pI' else pI) |> Problem.from_store ctxt |> #model)
Walther@60728
   106
val I_Model.Add i_single =
Walther@60728
   107
      (*case*) I_Model.check_single ctxt m_field oris i_model m_patt ct (*of*);
Walther@60728
   108
Walther@60763
   109
(** )val i_model' =( **)
Walther@60763
   110
(**)val return_add_single =(**)
Walther@60728
   111
   I_Model.add_single (Proof_Context.theory_of ctxt) i_single i_model;
Walther@60763
   112
(*/////--------------- step add_single -----------------------------------------------------\\*)
Walther@60728
   113
"~~~~~ fun add_single , args:"; val (thy, itm, model) =
Walther@60728
   114
  ((Proof_Context.theory_of ctxt), i_single, i_model);
Walther@60728
   115
    fun eq_untouched d (0, _, _, _, itm_) = (d = I_Model.descriptor itm_)
Walther@60728
   116
      | eq_untouched _ _ = false
Walther@60728
   117
    val model' = case I_Model.seek_ppc (#1 itm) model of
Walther@60728
   118
      SOME _ => overwrite_ppc thy itm model (*itm updated in is_notyet_input WN.11.03*)
Walther@60763
   119
(*\\\\\--------------- step add_single -----------------------------------------------------//*)
Walther@60763
   120
(*|||||--------------- step by_Add_ ----------------------------------------------------------*)
Walther@60763
   121
            val i_model' = return_add_single
Walther@60763
   122
(*+++*)val "[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,false ,#Find ,Inc Maximum , pen2str), \n(3 ,[1, 2, 3] ,false ,#Find ,Inc AdditionalValues [] , pen2str), \n(4 ,[1, 2, 3] ,false ,#Relate ,Inc Extremum , pen2str), \n(5 ,[1, 2] ,false ,#Relate ,Inc SideConditions [] , pen2str)]"
Walther@60763
   123
 = i_model' |> I_Model.to_string ctxt
Walther@60763
   124
            val tac' = I_Model.make_tactic m_field (ct, i_model')
Walther@60763
   125
	          val  (_, _, _, pt') =  Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, pos)
Walther@60763
   126
val return_by_Add_step =
Walther@60763
   127
            ("ok", ([(Tactic.input_from_T ctxt tac', tac', (pos, (Istate_Def.Uistate, ctxt)))],
Walther@60763
   128
              [], (pt', pos)))
Walther@60763
   129
(*+++*)val {probl, ...} = Calc.specify_data (pt', pos);
Walther@60763
   130
(*+++*)val "[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,false ,#Find ,Inc Maximum , pen2str), \n(3 ,[1, 2, 3] ,false ,#Find ,Inc AdditionalValues [] , pen2str), \n(4 ,[1, 2, 3] ,false ,#Relate ,Inc Extremum , pen2str), \n(5 ,[1, 2] ,false ,#Relate ,Inc SideConditions [] , pen2str)]"
Walther@60763
   131
 = probl |> I_Model.to_string ctxt
Walther@60763
   132
(*\\\\---------------- step into by_Add_ ---------------------------------------------------//*)
Walther@60763
   133
val return_by_tactic_step = return_by_Add_
Walther@60763
   134
(*\\\----------------- step into Step_Specify.by_tactic ------------------------------------//*)
Walther@60763
   135
(*vvv--- this means, the return value of *)
Walther@60763
   136
val return_step_by_tactic_STEP = return_step_specify_by_tactic
Walther@60728
   137
(*\\------------------ step into Step.by_tactic --------------------------------------------//*)
Walther@60728
   138
val ("ok", (_, _, ptp)) = return_step_by_tactic;
Walther@60728
   139
Walther@60763
   140
(*+++*)val (pt, p) = ptp
Walther@60763
   141
(*+++*)val {probl, ...} = Calc.specify_data (pt, p);
Walther@60763
   142
(*+++*)val "[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,false ,#Find ,Inc Maximum , pen2str), \n(3 ,[1, 2, 3] ,false ,#Find ,Inc AdditionalValues [] , pen2str), \n(4 ,[1, 2, 3] ,false ,#Relate ,Inc Extremum , pen2str), \n(5 ,[1, 2] ,false ,#Relate ,Inc SideConditions [] , pen2str)]"
Walther@60763
   143
 = probl |> I_Model.to_string ctxt;
Walther@60763
   144
Walther@60763
   145
      val (pt, p) = ptp; (*case*)
Walther@60728
   146
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60728
   147
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) =
Walther@60728
   148
  (p, ((pt, Pos.e_pos'), []));
Walther@60763
   149
val false =
Walther@60728
   150
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60728
   151
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60728
   152
val _ =
Walther@60728
   153
      (*case*) tacis (*of*);
Walther@60763
   154
val false =
Walther@60728
   155
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60728
   156
Walther@60763
   157
Walther@60763
   158
val ("ok", ([(Add_Find "Maximum A", _, _)], [], _)) =
Walther@60728
   159
           switch_specify_solve p_ (pt, ip);
Walther@60728
   160
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60728
   161
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60728
   162
Walther@60763
   163
val ("ok", ([(Add_Find "Maximum A", _, _)], [], _)) =
Walther@60728
   164
           specify_do_next (pt, input_pos);
Walther@60728
   165
"~~~~~ fun specify_do_next , args:"; val (ptp as (pt, (p, p_))) = (pt, input_pos);
Walther@60728
   166
    val (_, (p_', tac)) =
Walther@60728
   167
   Specify.find_next_step ptp;
Walther@60728
   168
"~~~~~ fun find_next_step , args:"; val (pt, pos as (_, p_)) = (ptp);
Walther@60728
   169
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60728
   170
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60728
   171
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60763
   172
(*+*)val "[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,false ,#Find ,Inc Maximum , pen2str), \n(3 ,[1, 2, 3] ,false ,#Find ,Inc AdditionalValues [] , pen2str), \n(4 ,[1, 2, 3] ,false ,#Relate ,Inc Extremum , pen2str), \n(5 ,[1, 2] ,false ,#Relate ,Inc SideConditions [] , pen2str)]"
Walther@60763
   173
 = pbl|> I_Model.to_string ctxt
Walther@60728
   174
Walther@60763
   175
val false =
Walther@60728
   176
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*); 
Walther@60763
   177
val true =
Walther@60728
   178
        (*if*) p_ = Pos.Pbl (*then*); 
Walther@60728
   179
Walther@60763
   180
(** )val ("dummy", (Pbl, Add_Find "Maximum A")) =( **)
Walther@60763
   181
(**)val return_for_problem as ("dummy", (Pbl, Add_Find "Maximum A"))=(**)
Walther@60763
   182
           for_problem ctxt oris (o_refs, refs) (pbl, I_Model.OLD_to_TEST met);
Walther@60763
   183
(*//------------------ step into for_problem -----------------------------------------------\\*)
Walther@60728
   184
"~~~~~ fun for_problem , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met)) =
Walther@60728
   185
  (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60728
   186
    val cpI = if pI = Problem.id_empty then pI' else pI;
Walther@60728
   187
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60728
   188
    val {model = pbt, where_rls, where_, ...} = Problem.from_store ctxt cpI;
Walther@60728
   189
    val {model = mpc, ...} = MethodC.from_store ctxt cmI
Walther@60728
   190
Walther@60763
   191
(** )val (preok, _) =( **)
Walther@60763
   192
(**)val return_check =(**)
Walther@60741
   193
Pre_Conds.check ctxt where_rls where_ (pbt, I_Model.OLD_to_TEST pbl);
Walther@60763
   194
(*///----------------- step into Pre_Conds.check -------------------------------------------\\*)
Walther@60741
   195
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
   196
  (ctxt, where_rls, where_, (pbt, I_Model.OLD_to_TEST pbl));
Walther@60728
   197
Walther@60763
   198
(** )val (_, (env_subst, env_eval)) =( **)
Walther@60763
   199
(**)val return_make_environments =(**)
Walther@60763
   200
Pre_Conds.make_environments model_patt i_model;
Walther@60763
   201
(*////---------------- step into make_environments -----------------------------------------\\*)
Walther@60763
   202
"~~~~~ fun make_environments , args:"; val (model_patt, i_model) = (model_patt, i_model);
Walther@60763
   203
    val equal_descr_pairs = map (get_equal_descr i_model) model_patt
Walther@60763
   204
      |> flat
Walther@60763
   205
Walther@60728
   206
    val env_model = make_env_model equal_descr_pairs
Walther@60763
   207
(** )val env_model =( **)
Walther@60763
   208
(**)val return_make_env_model =(**)
Walther@60763
   209
  make_env_model equal_descr_pairs;
Walther@60763
   210
(*/////--------------- step into make_env_model --------------------------------------------\\*)
Walther@60763
   211
"~~~~~ fun make_env_model , args:"; val (equal_descr_pairs) = (equal_descr_pairs);
Walther@60763
   212
val return_make_env_model_step =
Walther@60763
   213
  map (fn ((_, (_, id)), (_, _, _, _, (feedb, _)))
Walther@60763
   214
        => (mk_env_model id feedb)) equal_descr_pairs
Walther@60763
   215
  |> flat
Walther@60763
   216
(*map:*)val ((_, (_, id)), (_, _, _, _, (feedb, _))) = (nth 2 equal_descr_pairs);
Walther@60763
   217
Walther@60763
   218
(*///// /------------- step into mk_env_model ----------------------------------------------\\*)
Walther@60763
   219
"~~~~~ fun mk_env_model , args:"; val (_, (Model_Def.Inc_TEST (_, []))) = (id, feedb);
Walther@60763
   220
(*+*)val (patt, imod) = nth 2 equal_descr_pairs
Walther@60763
   221
(*+*)val "(#Find, (Maximum, maxx))" = patt |> Model_Pattern.pat2str ctxt
Walther@60763
   222
(*+*)val "(2, [1, 2, 3], false ,#Find, (Inc_TEST Maximum __, Position.T))" = imod |> I_Model.single_to_string_TEST ctxt
Walther@60763
   223
Walther@60763
   224
val return_mk_env_model_2_step = []
Walther@60763
   225
(*\\\\\ \------------- step into mk_env_model ----------------------------------------------//*)
Walther@60763
   226
(*\\\\\--------------- step into make_env_model --------------------------------------------//*)
Walther@60763
   227
val env_model = return_make_env_model;
Walther@60763
   228
Walther@60763
   229
(*||||---------------- contine.. make_environments -------------------------------------------*)
Walther@60728
   230
    val equal_givens = filter (fn ((m_field, _), _) => m_field = "#Given") equal_descr_pairs
Walther@60728
   231
Walther@60763
   232
(** )val subst_eval_list =( **)
Walther@60763
   233
(**)val return_make_envs_preconds =(**)
Walther@60763
   234
  make_envs_preconds equal_givens;
Walther@60763
   235
(*/////--------------- step into make_envs_preconds ----------------------------------------\\*)
Walther@60728
   236
"~~~~~ fun make_envs_preconds , args:"; val (equal_givens) = (equal_givens);
Walther@60763
   237
val return_make_envs_preconds_step = 
Walther@60763
   238
  map (fn ((_, (_, id)), (_, _, _, _, (feedb, _))) => discern_feedback id feedb) equal_givens
Walther@60763
   239
  |> flat
Walther@60728
   240
Walther@60763
   241
Walther@60763
   242
val ((_, (_, id)), (_, _, _, _, (feedb, _))) = nth 1 equal_givens
Walther@60763
   243
(*\\\\\--------------- step into make_envs_preconds ----------------------------------------//*)
Walther@60763
   244
    val subst_eval_list = return_make_envs_preconds;
Walther@60763
   245
    val (env_subst, env_eval) = split_list subst_eval_list
Walther@60763
   246
Walther@60763
   247
val return_make_environments_step = (env_model, (env_subst, env_eval));
Walther@60763
   248
(*+*)if return_make_environments_step = return_make_environments
Walther@60763
   249
  then () else error "return_make_environments_step <> return_make_environments";
Walther@60763
   250
(*\\\\---------------- step into make_environments -----------------------------------------//*)
Walther@60763
   251
(*|||----------------- contine.. Pre_Conds.check ---------------------------------------------*)
Walther@60763
   252
      val (env_model, (env_subst, env_eval)) = return_make_environments
Walther@60763
   253
      val pres_subst = map (TermC.subst_atomic_all env_subst) where_;
Walther@60763
   254
      val pres_subst_other = map (TermC.subst_atomic_all env_model) (map #2 pres_subst);
Walther@60763
   255
      val full_subst = if env_eval = [] then pres_subst_other
Walther@60763
   256
        else map (TermC.subst_atomic_all env_eval) (map #2 pres_subst_other)
Walther@60763
   257
      val evals = map (eval ctxt where_rls) full_subst
Walther@60763
   258
    (*in*)
Walther@60763
   259
val return_make_environments_step = (foldl and_ (true, map fst evals), pres_subst_other)
Walther@60763
   260
(*\\\----------------- step into Pre_Conds.check -------------------------------------------//*)
Walther@60763
   261
(*||------------------ contine.. for_problem -------------------------------------------------*)
Walther@60763
   262
    val (preok, _) = return_check;
Walther@60763
   263
  (*in*)
Walther@60763
   264
val false =
Walther@60763
   265
    (*if*) dI' = ThyC.id_empty andalso dI = ThyC.id_empty (*else*);
Walther@60763
   266
val false =
Walther@60763
   267
      (*if*) pI' = Problem.id_empty andalso pI = Problem.id_empty (*else*);
Walther@60763
   268
val NONE =
Walther@60763
   269
      (*case*) find_first (fn (_, _, _, _, feedb) => I_Model.is_error feedb) pbl (*of*);
Walther@60763
   270
Walther@60763
   271
val SOME (fd, ct' as "Maximum A") = (*case*)
Walther@60763
   272
           item_to_add ctxt oris (I_Model.OLD_to_TEST pbl) (*of*);
Walther@60763
   273
"~~~~~ fun item_to_add , args:"; val (ctxt, o_model, i_model) = (ctxt, oris, (I_Model.OLD_to_TEST pbl));
Walther@60763
   274
    val max_vnt = last_elem (*this decides, for which variant initially help is given*)
Walther@60763
   275
      (Model_Def.max_variants o_model i_model)
Walther@60763
   276
    val o_vnts = filter (fn (_, vnts, _, _, _) => member op= vnts max_vnt) o_model
Walther@60763
   277
    val i_to_select = i_model
Walther@60763
   278
      |> filter_out (fn (_, vnts, _, _, (I_Model.Cor_TEST _, _)) => member op= vnts max_vnt | _ => false)
Walther@60763
   279
      |> select_inc_lists
Walther@60763
   280
      |> hd
Walther@60763
   281
  (*in*)
Walther@60763
   282
Walther@60763
   283
val SOME (_, _, _, m_field, (feedb, _)) = (*case*)
Walther@60763
   284
   I_Model.fill_from_o o_vnts i_to_select (*of*);
Walther@60763
   285
(*+*)val "Cor_TEST Maximum A , pen2str" = feedb |> I_Model.feedback_TEST_to_string ctxt;
Walther@60763
   286
Walther@60763
   287
"~~~~~ fun fill_from_o , args:"; val (o_model, (i, vnts, bool, m_field, (feedb, pos))) =
Walther@60763
   288
  (o_vnts, i_to_select);
Walther@60763
   289
    val (m_field, all_value as [Free ("A", _)]) =
Walther@60767
   290
      case find_first (fn (_, _, _, descr', _) => Model_Def.descriptor_exists descr' feedb) o_model of
Walther@60763
   291
        SOME (_, _, m_field, _, ts) =>  (m_field, ts)
Walther@60767
   292
    val descr = Model_Def.get_descr feedb (*i_single has been filtered appropriately*)
Walther@60763
   293
  (*in*)
Walther@60763
   294
val false =
Walther@60766
   295
    (*if*) Model_Def.is_list_descr descr (*else*);
Walther@60763
   296
val return_fill_from_o_STEP = SOME (i, vnts, bool, m_field,
Walther@60763
   297
      (Inc_TEST (descr, all_value), pos))
Walther@60728
   298
(*\------------------- step into me_add_find_Constants -------------------------------------//*)
Walther@60728
   299
val (p,_,f,nxt,_,pt) = return_me_add_find_Constants;
Walther@60763
   300
                                      val Add_Find "Maximum A" = nxt
Walther@60728
   301
Walther@60763
   302
(** )val (p,_,f,nxt,_,pt) =( **)
Walther@60763
   303
(**)val return_me_Add_Find_Maximum =(**)
Walther@60763
   304
       me nxt p c pt;  val Add_Find "AdditionalValues [u]" = #4 return_me_Add_Find_Maximum;
Walther@60763
   305
(*/------------------- step into me_Add_Find_Maximum ---------------------------------------\\*)
Walther@60763
   306
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt, p, c, pt);
Walther@60763
   307
      val ctxt = Ctree.get_ctxt pt p
Walther@60763
   308
      val (pt, p) = 
Walther@60763
   309
  	    case Step.by_tactic tac (pt, p) of
Walther@60763
   310
  		    ("ok", (_, _, ptp)) => ptp;
Walther@60763
   311
Walther@60763
   312
      (*case*)
Walther@60763
   313
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60763
   314
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) =
Walther@60763
   315
  (p, ((pt, Pos.e_pos'), []));
Walther@60763
   316
val false =
Walther@60763
   317
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60763
   318
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60763
   319
    (*in*)
Walther@60763
   320
val [] =
Walther@60763
   321
      (*case*) tacis (*of*);
Walther@60763
   322
val false =
Walther@60763
   323
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60763
   324
Walther@60763
   325
           switch_specify_solve p_ (pt, ip);
Walther@60763
   326
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60763
   327
val true =
Walther@60763
   328
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60763
   329
Walther@60763
   330
           specify_do_next (pt, input_pos);
Walther@60763
   331
"~~~~~ fun specify_do_next , args:"; val (ptp as (pt, (p, p_))) = (pt, input_pos);
Walther@60763
   332
Walther@60763
   333
(**)val (_, (p_', tac as Add_Find "AdditionalValues [u]")) =(**)
Walther@60763
   334
   Specify.find_next_step ptp;
Walther@60763
   335
"~~~~~ fun find_next_step , args:"; val (pt, pos as (_, p_)) = (ptp);
Walther@60763
   336
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60763
   337
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60763
   338
    val ctxt = Ctree.get_ctxt pt pos
Walther@60763
   339
  (*in*)
Walther@60763
   340
val false =
Walther@60763
   341
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
Walther@60763
   342
val true =
Walther@60763
   343
        (*if*) p_ = Pos.Pbl (*then*);
Walther@60763
   344
Walther@60763
   345
(**)val return_find_next_step_STEP as ("dummy", (Pbl, Add_Find "AdditionalValues [u]")) =(**)
Walther@60763
   346
           for_problem ctxt oris (o_refs, refs) (pbl, I_Model.OLD_to_TEST met);
Walther@60763
   347
"~~~~~ fun for_problem , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met)) =
Walther@60763
   348
  (ctxt, oris, (o_refs, refs), (pbl, I_Model.OLD_to_TEST met));
Walther@60763
   349
    val cpI = if pI = Problem.id_empty then pI' else pI;
Walther@60763
   350
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60763
   351
    val {model = pbt, where_rls, where_, ...} = Problem.from_store ctxt cpI;
Walther@60763
   352
    val {model = mpc, ...} = MethodC.from_store ctxt cmI
Walther@60763
   353
    val (preok, _) = Pre_Conds.check ctxt where_rls where_ (pbt, I_Model.OLD_to_TEST pbl);
Walther@60763
   354
  (*in*)
Walther@60763
   355
val false =
Walther@60763
   356
    (*if*) dI' = ThyC.id_empty andalso dI = ThyC.id_empty (*else*);
Walther@60763
   357
val false =
Walther@60763
   358
      (*if*) pI' = Problem.id_empty andalso pI = Problem.id_empty (*else*);
Walther@60763
   359
val NONE =
Walther@60763
   360
      (*case*) find_first (fn (_, _, _, _, feedb) => I_Model.is_error feedb) pbl (*of*);
Walther@60763
   361
Walther@60763
   362
(**)val SOME (fd, ct' as "AdditionalValues [u]") = (*case*)(**)
Walther@60763
   363
           item_to_add ctxt oris (I_Model.OLD_to_TEST pbl) (*of*);
Walther@60763
   364
"~~~~~ fun item_to_add , args:"; val (ctxt, o_model, i_model) =
Walther@60763
   365
  (ctxt, oris, (I_Model.OLD_to_TEST pbl));
Walther@60763
   366
    val max_vnt = last_elem (*this decides, for which variant initially help is given*)
Walther@60763
   367
      (Model_Def.max_variants o_model i_model)
Walther@60763
   368
    val o_vnts = filter (fn (_, vnts, _, _, _) => member op= vnts max_vnt) o_model
Walther@60763
   369
    val i_to_select = i_model
Walther@60763
   370
      |> filter_out (fn (_, vnts, _, _, (I_Model.Cor_TEST _, _)) => member op= vnts max_vnt | _ => false)
Walther@60763
   371
      |> select_inc_lists
Walther@60763
   372
(*ERROR*)val "[\n(3, [1, 2, 3], false ,#Find, (Inc_TEST AdditionalValues [] [__, __], Position.T)), \n(4, [1, 2, 3], false ,#Relate, (Inc_TEST Extremum (__=__), Position.T)), \n(5, [1, 2], false ,#Relate, (Inc_TEST SideConditions [] [__=__, __=__], Position.T))]"
Walther@60763
   373
 = i_to_select |> I_Model.to_string_TEST ctxt(*ERROR*)
Walther@60763
   374
  (*in*)
Walther@60763
   375
val false =
Walther@60763
   376
    (*if*) i_to_select = []
Walther@60763
   377
Walther@60763
   378
val SOME (_, _, _, m_field, (feedb, _)) = (*case*)
Walther@60763
   379
   I_Model.fill_from_o o_vnts (hd i_to_select) (*of*);
Walther@60763
   380
"~~~~~ fun fill_from_o , args:";
Walther@60763
   381
(*==================== see test/../i-model.sml --- fun item_to_add ===========================*)
Walther@60763
   382
(*\------------------- step into me_Add_Find_Maximum ---------------------------------------//*)
Walther@60763
   383
val (p,_,f,nxt,_,pt) = return_me_Add_Find_Maximum; 
Walther@60763
   384
                                      val Add_Find "AdditionalValues [u]" = nxt
Walther@60763
   385
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Find "AdditionalValues [u, v]" = nxt;(*ERROR after repairing item_to_add, investigate in testcode above*)
Walther@60578
   386
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Relation "Extremum (A = 2 * u * v - u \<up> 2)" = nxt;
Walther@60578
   387
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Relation "SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]" = nxt;
Walther@60763
   388
Walther@60763
   389
val return_me_Add_Relation_SideConditions as (_, _, _, Specify_Theory "Diff_App", _, _)
Walther@60705
   390
                     = me nxt p c pt;
Walther@60705
   391
(*/------------------- step into me Add_Relation_SideConditions ----------------------------\\*)
Walther@60705
   392
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60728
   393
      val ctxt = Ctree.get_ctxt pt p;
Walther@60728
   394
(**)  val (pt, p) = (**) 
Walther@60728
   395
  	    (**)case(**) Step.by_tactic tac (pt, p) (**)of(**)
Walther@60728
   396
(**) 		    ("ok", (_, _, ptp)) => ptp (**) ;
Walther@60728
   397
Walther@60728
   398
   (*case*)
Walther@60705
   399
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60705
   400
(*//------------------ step into do_next ---------------------------------------------------\\*)
Walther@60705
   401
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
Walther@60705
   402
  = (p, ((pt, Pos.e_pos'), [])) (*of*);
Walther@60705
   403
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60705
   404
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60705
   405
      (*case*) tacis (*of*);
Walther@60705
   406
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60705
   407
Walther@60705
   408
      Step.switch_specify_solve p_ (pt, ip);
Walther@60705
   409
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60705
   410
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60763
   411
Walther@60705
   412
      Step.specify_do_next (pt, input_pos);
Walther@60705
   413
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = (pt, input_pos);
Walther@60728
   414
    val (_, (p_', tac as Specify_Theory "Diff_App")) =
Walther@60728
   415
   Specify.find_next_step ptp;
Walther@60705
   416
"~~~~~ fun find_next_step , args:"; val (pt, pos as (_, p_)) = (ptp);
Walther@60705
   417
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60705
   418
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60705
   419
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60705
   420
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
Walther@60705
   421
        (*if*) p_ = Pos.Pbl (*then*);
Walther@60705
   422
Walther@60763
   423
(** )val ("dummy", (Pbl, tac as Specify_Theory "Diff_App")) =( **)
Walther@60763
   424
(**)val return_for_problem =(**)
Walther@60763
   425
  for_problem ctxt oris (o_refs, refs) (pbl, I_Model.OLD_to_TEST met);
Walther@60763
   426
(*///// /------------- step into for_problem -----------------------------------------------\\*)
Walther@60705
   427
"~~~~~ fun for_problem , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met)) =
Walther@60705
   428
  (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60705
   429
    val cpI = if pI = Problem.id_empty then pI' else pI;
Walther@60705
   430
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60705
   431
    val {model = pbt, where_rls, where_, ...} = Problem.from_store ctxt cpI;
Walther@60705
   432
    val {model = mpc, ...} = MethodC.from_store ctxt cmI
Walther@60705
   433
Walther@60705
   434
(*+*)val [Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60763
   435
  Free ("fixes", _)] = where_;
Walther@60728
   436
Walther@60763
   437
(** )val (preok, _) =( **)
Walther@60763
   438
(**)return_check =(**)
Walther@60741
   439
 Pre_Conds.check ctxt where_rls where_ (pbt, I_Model.OLD_to_TEST pbl);
Walther@60763
   440
(*///// //------------ step into check -------------------------------------------------\\*)
Walther@60741
   441
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
   442
  (ctxt, where_rls, where_, (pbt, I_Model.OLD_to_TEST pbl));
Walther@60763
   443
(*+*)val "[0 < fixes]" = pres |> UnparseC.terms ctxt
Walther@60728
   444
(*+*)val "[\"(#Given, (Constants, fixes))\", \"(#Find, (Maximum, maxx))\", \"(#Find, (AdditionalValues, vals))\", \"(#Relate, (Extremum, extr))\", \"(#Relate, (SideConditions, sideconds))\"]"
Walther@60763
   445
(*+*)  = model_patt |> Model_Pattern.to_string ctxt
Walther@60733
   446
(*+*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]"
Walther@60763
   447
 = i_model |> I_Model.to_string_TEST ctxt
Walther@60728
   448
Walther@60758
   449
val return_make_environments as (_, (env_subst, env_eval)) =
Walther@60758
   450
           Pre_Conds.make_environments model_patt i_model
Walther@60728
   451
Walther@60728
   452
(*+*)val [(Free ("fixes", T1), Free ("r", T2))] = env_subst (*?!? Const*)
Walther@60728
   453
(*+*)val Type ("Real.real", []) = T1
Walther@60728
   454
(*+*)val Type ("Real.real", []) = T2
Walther@60728
   455
Walther@60728
   456
(*+*)val [(Free ("r", T2), Const ("Num.numeral_class.numeral", _) $ _)] = env_eval
Walther@60728
   457
(*+*)val Type ("Real.real", []) = T2
Walther@60728
   458
Walther@60758
   459
val (_, (env_subst, env_eval)) = return_make_environments;
Walther@60741
   460
(*|||----------------- contine check -----------------------------------------------------*)
Walther@60728
   461
      val pres_subst = map (TermC.subst_atomic_all env_subst) pres;
Walther@60728
   462
(*+*)val [(true, Const ("Orderings.ord_class.less", _) $
Walther@60728
   463
  Const ("Groups.zero_class.zero", _) $ Free ("r", _))] = pres_subst
Walther@60728
   464
Walther@60728
   465
      val full_subst = map (fn (bool, t) => (bool, subst_atomic env_eval t)) pres_subst
Walther@60728
   466
(*+*)val [(true,
Walther@60728
   467
     Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60728
   468
       (Const ("Num.numeral_class.numeral", _) $ _))] = full_subst
Walther@60728
   469
Walther@60728
   470
      val evals = map (eval ctxt where_rls) full_subst
Walther@60763
   471
val return_check_STEP = (foldl and_ (true, map fst evals), pres_subst)
Walther@60763
   472
(*\\\\\ \\------------ step into check -------------------------------------------------\\*)
Walther@60763
   473
    val (preok as true, _) = return_check
Walther@60728
   474
Walther@60763
   475
(*||||| |------------- contine.. for_problem -------------------------------------------------*)
Walther@60763
   476
val false =
Walther@60763
   477
    (*if*) dI' = ThyC.id_empty andalso dI = ThyC.id_empty (*else*);
Walther@60763
   478
val false =
Walther@60763
   479
      (*if*) pI' = Problem.id_empty andalso pI = Problem.id_empty (*else*);
Walther@60763
   480
val NONE =
Walther@60763
   481
      (*case*) find_first (fn (_, _, _, _, feedb) => I_Model.is_error feedb) pbl (*of*);
Walther@60763
   482
Walther@60763
   483
  (*case*) item_to_add ctxt oris (I_Model.OLD_to_TEST pbl) (*of*);
Walther@60763
   484
"~~~~~ fun item_to_add , args:"; val (ctxt, o_model, i_model) = (ctxt, oris, (I_Model.OLD_to_TEST pbl));
Walther@60763
   485
Walther@60763
   486
(*+*)val "[\n(1, [\"1\", \"2\", \"3\"], #Given, Constants, [\"[r = 7]\"]), \n(2, [\"1\", \"2\", \"3\"], #Find, Maximum, [\"A\"]), \n(3, [\"1\", \"2\", \"3\"], #Find, AdditionalValues, [\"[u]\", \"[v]\"]), \n(4, [\"1\", \"2\", \"3\"], #Relate, Extremum, [\"A = 2 * u * v - u \<up> 2\"]), \n(5, [\"1\", \"2\"], #Relate, SideConditions, [\"[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\"]), \n(6, [\"3\"], #Relate, SideConditions, [\"[u / 2 = r * sin \<alpha>]\", \"[2 / v = r * cos \<alpha>]\"]), \n(7, [\"1\"], #undef, FunctionVariable, [\"a\"]), \n(8, [\"2\"], #undef, FunctionVariable, [\"b\"]), \n(9, [\"3\"], #undef, FunctionVariable, [\"\<alpha>\"]), \n(10, [\"1\", \"2\"], #undef, Input_Descript.Domain, [\"{0<..<r}\"]), \n(11, [\"3\"], #undef, Input_Descript.Domain, [\"{0<..<\<pi> / 2}\"]), \n(12, [\"1\", \"2\", \"3\"], #undef, ErrorBound, [\"\<epsilon> = 0\"])]"
Walther@60763
   487
 = o_model |> O_Model.to_string ctxt
Walther@60763
   488
(*+*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]"
Walther@60763
   489
 = i_model |> I_Model.to_string_TEST ctxt
Walther@60763
   490
Walther@60763
   491
    val max_vnt as 1= last_elem (*this decides, for which variant initially help is given*)
Walther@60763
   492
      (Model_Def.max_variants o_model i_model)
Walther@60763
   493
    val o_vnts = filter (fn (_, vnts, _, _, _) => member op= vnts max_vnt) o_model
Walther@60763
   494
(*+*)val "[\n(1, [\"1\", \"2\", \"3\"], #Given, Constants, [\"[r = 7]\"]), \n(2, [\"1\", \"2\", \"3\"], #Find, Maximum, [\"A\"]), \n(3, [\"1\", \"2\", \"3\"], #Find, AdditionalValues, [\"[u]\", \"[v]\"]), \n(4, [\"1\", \"2\", \"3\"], #Relate, Extremum, [\"A = 2 * u * v - u \<up> 2\"]), \n(5, [\"1\", \"2\"], #Relate, SideConditions, [\"[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\"]), \n(7, [\"1\"], #undef, FunctionVariable, [\"a\"]), \n(10, [\"1\", \"2\"], #undef, Input_Descript.Domain, [\"{0<..<r}\"]), \n(12, [\"1\", \"2\", \"3\"], #undef, ErrorBound, [\"\<epsilon> = 0\"])]"
Walther@60763
   495
 = o_vnts |> O_Model.to_string ctxt
Walther@60763
   496
Walther@60763
   497
    val i_to_select = i_model
Walther@60763
   498
      |> filter_out (fn (_, vnts, _, _, (I_Model.Cor_TEST _, _)) => member op= vnts max_vnt | _ => false)
Walther@60763
   499
      |> select_inc_lists
Walther@60763
   500
val true =
Walther@60763
   501
    (*if*) i_to_select = [] (*then*);
Walther@60763
   502
Walther@60763
   503
val return_for_problem_STEP = NONE
Walther@60763
   504
(*\\\\\ \------------- step into for_problem -----------------------------------------------//*)
Walther@60763
   505
val calling_code = return_for_problem;
Walther@60763
   506
(*-------------------- stopped after ERROR found ---------------------------------------------*)
Walther@60763
   507
Walther@60728
   508
(*\\------------------ step into do_next ---------------------------------------------------\\*)
Walther@60728
   509
(*\------------------- step into me_Add_Relation_SideConditions ----------------------------//*)
Walther@60705
   510
val (p, _, f, nxt, _, pt) = return_me_Add_Relation_SideConditions
Walther@60705
   511
                                      val Specify_Theory "Diff_App" = nxt;
Walther@60705
   512
Walther@60659
   513
val return_me_Specify_Theory
Walther@60659
   514
                     = me nxt p c pt; val Specify_Problem ["univariate_calculus", "Optimisation"] = #4 return_me_Specify_Theory;
Walther@60763
   515
(*/------------------- step into me_Specify_Theory -----------------------------------------\\*)
Walther@60763
   516
"~~~~~ fun me , args:"; val (tac as Specify_Theory "Diff_App", p, _, pt) = (nxt, p, c, pt);
Walther@60728
   517
      val ctxt = Ctree.get_ctxt pt p;
Walther@60728
   518
(*      val (pt, p) = *)
Walther@60728
   519
  	    (*case*) Step.by_tactic tac (pt, p) (*of*);
Walther@60728
   520
(*		    ("ok", (_, _, ptp)) => ptp *)
Walther@60728
   521
val return_Step_by_tactic =
Walther@60728
   522
      Step.by_tactic tac (pt, p);
Walther@60728
   523
(*//------------------ step into Step_by_tactic --------------------------------------------\\*)
Walther@60728
   524
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60741
   525
    (*case*) Specify_Step.check tac (pt, p) (*of*);
Walther@60728
   526
Walther@60728
   527
(*||------------------ contine Step_by_tactic ------------------------------------------------*)
Walther@60728
   528
(*\\------------------ step into Step_by_tactic --------------------------------------------//*)
Walther@60728
   529
Walther@60728
   530
val ("ok", (_, _, ptp)) = return_Step_by_tactic;
Walther@60728
   531
(*|------------------- continue me Specify_Theory --------------------------------------------*)
Walther@60578
   532
Walther@60578
   533
val ("ok", (ts as (_, _, _) :: _, _, _)) =
Walther@60578
   534
    (*case*)
Walther@60578
   535
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60578
   536
(*//------------------ step into do_next ---------------------------------------------------\\*)
Walther@60578
   537
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
Walther@60578
   538
  = (p, ((pt, Pos.e_pos'), [])) (*of*);
Walther@60578
   539
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60578
   540
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60578
   541
val _ =
Walther@60578
   542
      (*case*) tacis (*of*);
Walther@60578
   543
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60578
   544
Walther@60578
   545
      Step.switch_specify_solve p_ (pt, ip);
Walther@60578
   546
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   547
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   548
Walther@60578
   549
      Step.specify_do_next (pt, input_pos);
Walther@60578
   550
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = (pt, input_pos);
Walther@60578
   551
    val (_, (p_', tac)) = Specify.find_next_step ptp
Walther@60578
   552
    val ist_ctxt =  Ctree.get_loc pt (p, p_);
Walther@60578
   553
    (*case*) tac (*of*);
Walther@60578
   554
Walther@60728
   555
Step_Specify.by_tactic_input tac (pt, (p, p_'));
Walther@60728
   556
(*+*)val Specify_Theory "Diff_App" = tac;
Walther@60728
   557
"~~~~~ fun by_tactic_input , args:"; val ((Tactic.Specify_Theory dI), (pt, pos as (_, Pbl)))
Walther@60578
   558
  = (tac, (pt, (p, p_')));
Walther@60578
   559
      val (oris, dI, dI', pI', probl, ctxt) = case get_obj I pt p of
Walther@60578
   560
        PblObj {origin = (oris, (dI,_,_),_), spec = (dI',pI',_), probl, ctxt, ...} =>
Walther@60578
   561
          (oris, dI, dI', pI', probl, ctxt)
Walther@60676
   562
	    val thy = ThyC.get_theory ctxt (if dI' = ThyC.id_empty then dI else dI');
Walther@60585
   563
      val {model, where_, where_rls,...} = Problem.from_store (Ctree.get_ctxt pt pos) pI
Walther@60659
   564
(*\\------------------ step into do_next ---------------------------------------------------//*)
Walther@60763
   565
(*\------------------- step into me_Specify_Theory -----------------------------------------//*)
Walther@60659
   566
val (p,_,f,nxt,_,pt) = return_me_Specify_Theory;
Walther@60578
   567
Walther@60659
   568
val return_me_Specify_Problem (* keep for continuing me *)
Walther@60659
   569
                     = me nxt p c pt; val Specify_Method ["Optimisation", "by_univariate_calculus"] = #4 return_me_Specify_Problem;
Walther@60763
   570
(*/------------------- step into me_Specify_Problem ----------------------------------------\\*)
Walther@60659
   571
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60578
   572
      val ctxt = Ctree.get_ctxt pt p
Walther@60578
   573
Walther@60659
   574
(** )  val ("ok", (_, _, ptp as (pt, p))) =( **)
Walther@60659
   575
(**)    val return_by_tactic =(**) (*case*)
Walther@60578
   576
      Step.by_tactic tac (pt, p) (*of*);
Walther@60659
   577
(*//------------------ step into by_tactic -------------------------------------------------\\*)
Walther@60578
   578
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60578
   579
Walther@60578
   580
    (*case*)
Walther@60578
   581
      Step.check tac (pt, p) (*of*);
Walther@60578
   582
"~~~~~ fun check , args:"; val (tac, (ctree, pos)) = (tac, (pt, p));
Walther@60578
   583
  (*if*) Tactic.for_specify tac (*then*);
Walther@60578
   584
Walther@60578
   585
Specify_Step.check tac (ctree, pos);
Walther@60578
   586
"~~~~~ fun check , args:"; val ((Tactic.Specify_Problem pID), (pt, pos as (p, _)))
Walther@60578
   587
  = (tac, (ctree, pos));
Walther@60578
   588
		    val (oris, dI, pI, dI', pI', itms) = case Ctree.get_obj I pt p of
Walther@60578
   589
		      Ctree.PblObj {origin = (oris, (dI, pI, _), _), spec = (dI', pI', _), probl = itms, ...}
Walther@60578
   590
		        => (oris, dI, pI, dI', pI', itms)
Walther@60676
   591
	      val thy = ThyC.get_theory ctxt (if dI' = ThyC.id_empty then dI else dI');
Walther@60659
   592
(*\\------------------ step into by_tactic -------------------------------------------------//*)
Walther@60659
   593
val ("ok", (_, _, ptp as (pt, p))) = return_by_tactic (* kept for continuing me *);
Walther@60578
   594
Walther@60578
   595
      (*case*)
Walther@60578
   596
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60578
   597
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) = (p, ((pt, Pos.e_pos'), []));
Walther@60578
   598
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60578
   599
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60578
   600
val _ =
Walther@60578
   601
      (*case*) tacis (*of*);
Walther@60578
   602
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60578
   603
Walther@60578
   604
      Step.switch_specify_solve p_ (pt, ip);
Walther@60578
   605
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   606
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   607
Walther@60578
   608
      Step.specify_do_next (pt, input_pos);
Walther@60578
   609
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = ((pt, input_pos));
Walther@60578
   610
    val (_, (p_', tac)) = Specify.find_next_step ptp
Walther@60578
   611
    val ist_ctxt =  Ctree.get_loc pt (p, p_)
Walther@60578
   612
val _ =
Walther@60578
   613
    (*case*) tac (*of*);
Walther@60578
   614
Walther@60578
   615
Step_Specify.by_tactic_input tac (pt, (p, p_'));
Walther@60578
   616
"~~~~~ fun by_tactic_input , args:"; val ((Tactic.Specify_Method id), (pt, pos))
Walther@60578
   617
  = (tac, (pt, (p, p_')));
Walther@60578
   618
Walther@60760
   619
(**)val return_complete_for =(**)
Walther@60760
   620
(** )  val (o_model, ctxt, i_model) =( **)
Walther@60578
   621
Specify_Step.complete_for id (pt, pos);
Walther@60760
   622
(*//------------------ step into complete_for ----------------------------------------------\\*)
Walther@60578
   623
"~~~~~ fun complete_for , args:"; val (mID, (ctree, pos)) = (id, (pt, pos));
Walther@60763
   624
Walther@60763
   625
(*+*)val ["Optimisation", "by_univariate_calculus"] = mID
Walther@60763
   626
(*OLD*  )
Walther@60763
   627
    val {origin = (o_model, _, _), probl = i_prob, ctxt,
Walther@60763
   628
       ...} = Calc.specify_data (ctree, pos);
Walther@60763
   629
    val {model = m_patt, where_, where_rls, ...} = MethodC.from_store ctxt mID
Walther@60763
   630
    val {origin = (root_model, _, _), ...} = Calc.specify_data (ctree, ([], Pos.Und))
Walther@60763
   631
    val (o_model', ctxt') = O_Model.complete_for m_patt root_model (o_model, ctxt)
Walther@60763
   632
( *---*)
Walther@60763
   633
    val {origin = (o_model, o_refs, _), spec = refs, probl = i_prob, meth = met_imod, ctxt,
Walther@60578
   634
       ...} = Calc.specify_data (ctree, pos);
Walther@60578
   635
    val ctxt = Ctree.get_ctxt ctree pos
Walther@60578
   636
    val (dI, _, _) = References.select_input o_refs refs;
Walther@60586
   637
    val {model = m_patt, where_, where_rls, ...} = MethodC.from_store ctxt mID
Walther@60578
   638
    val {origin = (root_model, _, _), ...} = Calc.specify_data (ctree, ([], Pos.Und))
Walther@60578
   639
    val (o_model', ctxt') = O_Model.complete_for m_patt root_model (o_model, ctxt)
Walther@60763
   640
(*NEW*)
Walther@60760
   641
Walther@60760
   642
(**)val return_match_itms_oris = (**)
Walther@60760
   643
(** )val (_, (i_model, _)) = ( **)
Walther@60763
   644
(*OLD* )
Walther@60763
   645
   M_Match.match_itms_oris ctxt i_prob (m_patt, where_, where_rls) o_model';
Walther@60763
   646
( *---*)
Walther@60763
   647
     M_Match.match_itms_oris ctxt o_model' (I_Model.OLD_to_TEST i_prob, I_Model.OLD_to_TEST i_prob)
Walther@60760
   648
              (m_patt, where_, where_rls);
Walther@60763
   649
(*NEW*)
Walther@60763
   650
(*//################## @ {context} within fun match_itms_oris -----------------------------\\*)
Walther@60760
   651
(*///----------------- step into match_itms_oris -------------------------------------------\\*)
Walther@60760
   652
"~~~~~ fun match_itms_oris, args:"; val (ctxt, o_model, (pbl_imod, met_imod), (m_patt, where_, where_rls)) =
Walther@60760
   653
  (ctxt, o_model', (I_Model.OLD_to_TEST i_prob, I_Model.OLD_to_TEST i_prob), (m_patt, where_, where_rls));
Walther@60760
   654
Walther@60760
   655
(**)val return_fill_method =(**)
Walther@60760
   656
(** )val met_imod =( **)
Walther@60760
   657
           fill_method o_model (pbl_imod, met_imod) m_patt;
Walther@60760
   658
(*////--------------- step into fill_method -----------------------------------------------\\*)
Walther@60760
   659
"~~~~~ fun fill_method , args:"; val (o_model, (pbl_imod, met_imod), met_patt) =
Walther@60760
   660
  (o_model, (pbl_imod, met_imod), m_patt);
Walther@60760
   661
Walther@60763
   662
(*+*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]"
Walther@60763
   663
 = pbl_imod |> I_Model.to_string_TEST ctxt
Walther@60763
   664
(*+*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]"
Walther@60763
   665
 = met_imod |> I_Model.to_string_TEST ctxt
Walther@60763
   666
Walther@60763
   667
(**)val return_max_variants =(**)
Walther@60763
   668
(** )val pbl_max_vnts as [2, 1] =( **)
Walther@60763
   669
 Model_Def.max_variants o_model pbl_imod;
Walther@60763
   670
(*//------------------ step into max_variants ----------------------------------------------\\*)
Walther@60763
   671
"~~~~~ fun max_variants , args:"; val (o_model, i_model) = (o_model, pbl_imod);
Walther@60763
   672
      val all_variants as [1, 2, 3] =
Walther@60763
   673
          map (fn (_, variants, _, _, _) => variants) i_model
Walther@60763
   674
          |> flat
Walther@60763
   675
          |> distinct op =
Walther@60763
   676
      val variants_separated = map (filter_variants' i_model) all_variants
Walther@60763
   677
(*+*)val ["[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]",
Walther@60763
   678
          "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]",
Walther@60763
   679
          "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T))]"]
Walther@60763
   680
 = variants_separated |> map (I_Model.to_string_TEST ctxt)
Walther@60763
   681
Walther@60763
   682
      val sums_corr as [5, 5, 4] = map (cnt_corrects) variants_separated
Walther@60763
   683
      (*----------------#--#--#*)
Walther@60763
   684
      (*---------------------^-------^-------^*)
Walther@60763
   685
      val sum_variant_s as [(5, 1), (5, 2), (4, 3)] = arrange_args sums_corr (1, all_variants)
Walther@60763
   686
      val max_first as [(5, 2), (5, 1), (4, 3)] = rev (sort (fn ((i, _), (j, _)) => int_ord (i, j)) sum_variant_s)
Walther@60763
   687
      (*----------------##====--##====--//////---------^^^^*)
Walther@60763
   688
      (*------------^--^-#-------#*)
Walther@60763
   689
      val maxes as [2, 1] = filter (fn (cnt, _) => curry op = (fst (hd max_first)) cnt) max_first
Walther@60763
   690
        |> map snd
Walther@60763
   691
val return_max_variants = maxes
Walther@60763
   692
(*\\------------------ step into max_variants ----------------------------------------------//*)
Walther@60763
   693
val pbl_max_vnts as [2, 1] = return_max_variants;
Walther@60760
   694
Walther@60760
   695
    (*probably pbl/met_imod = [], so take met_patt; if empty return Sup*)
Walther@60760
   696
    val i_from_met = map (fn (_, (descr, _)) => (*order from met_patt*)
Walther@60760
   697
      Pre_Conds.get_descr_vnt descr pbl_max_vnts met_imod) met_patt (*\<longrightarrow> right order for args*)
Walther@60760
   698
(*+MET: Sup..*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T)), \n(0, [], false ,i_model_empty, (Sup_TEST FunctionVariable, Position.T)), \n(0, [], false ,i_model_empty, (Sup_TEST Input_Descript.Domain, Position.T)), \n(0, [], false ,i_model_empty, (Sup_TEST ErrorBound, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T))]"
Walther@60763
   699
  = i_from_met |> I_Model.to_string_TEST ctxt
Walther@60760
   700
Walther@60760
   701
    val met_max_vnts as [2, 1] = Model_Def.max_variants o_model i_from_met;
Walther@60760
   702
    val max_vnt as 2 = hd (inter op= pbl_max_vnts met_max_vnts);
Walther@60760
   703
    (*add items from pbl_imod (without overwriting existing items in met_imod)*)
Walther@60760
   704
Walther@60763
   705
val return_add_other = map (
Walther@60760
   706
           add_other max_vnt pbl_imod) i_from_met;
Walther@60763
   707
(*+*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST FunctionVariable, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST Input_Descript.Domain, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST ErrorBound, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T))]"
Walther@60763
   708
  = return_add_other |> I_Model.to_string_TEST ctxt;
Walther@60760
   709
(*/////-------------- step into add_other -------------------------------------------------\\*)
Walther@60760
   710
"~~~~~ fun add_other_5 , args:"; val (max_vnt, i1_model, (i2, _, bool2, m_field2, (Sup_TEST (descr2, ts2), pos2))) =
Walther@60760
   711
  (max_vnt, pbl_imod, nth 5 i_from_met);
Walther@60763
   712
Walther@60760
   713
(*+*)val Const ("Input_Descript.FunctionVariable", _) = descr2;
Walther@60760
   714
Walther@60760
   715
val (_, vnts1, _, _, (feedb1, _)) = (i2, [], bool2, m_field2, (Sup_TEST (descr2, ts2), pos2))
Walther@60760
   716
val SOME (descr1 as (Const ("Input_Descript.FunctionVariable", _)) ) =
Walther@60767
   717
      get_dscr_opt feedb1
Walther@60760
   718
val true =
Walther@60760
   719
        descr1 = descr2
Walther@60760
   720
val true =
Walther@60760
   721
          Model_Def.member_vnt vnts1 max_vnt
Walther@60760
   722
val NONE =
Walther@60767
   723
    find_first (fn (_, vnts1, _, _, (feedb1, _)) => case get_dscr_opt feedb1 of
Walther@60760
   724
          NONE => false
Walther@60760
   725
        | SOME descr1 => descr1 = descr2 andalso Model_Def.member_vnt vnts1 max_vnt) i1_model
Walther@60760
   726
Walther@60760
   727
val return_add_other_1 = (i2, [max_vnt], bool2, m_field2, (Sup_TEST (descr2, ts2), pos2))
Walther@60760
   728
val check as true = return_add_other_1 = nth 5 return_add_other
Walther@60760
   729
(*\\\\\-------------- step into add_other -------------------------------------------------//*)
Walther@60760
   730
    val i_from_pbl = return_add_other
Walther@60760
   731
(*\\\\---------------- step into fill_method -----------------------------------------------//*)
Walther@60760
   732
val return_fill_method_step = filter (fn (_, vnts', _, _, _) => member op = vnts' max_vnt) i_from_met
Walther@60760
   733
Walther@60760
   734
(*+MET: dropped ALL DUE TO is_empty_single_TEST*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T))]" =
Walther@60763
   735
  return_fill_method_step |> I_Model.to_string_TEST ctxt
Walther@60760
   736
(*+*)val                                             "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST FunctionVariable, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST Input_Descript.Domain, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST ErrorBound, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T))]"
Walther@60763
   737
 = return_fill_method |> I_Model.to_string_TEST ctxt;
Walther@60760
   738
return_fill_method_step = return_fill_method; (*latter is correct, did not investigate further*)
Walther@60760
   739
(*\\\----------------- step into match_itms_oris -------------------------------------------//*)
Walther@60763
   740
(*\\################# @ {context} within fun match_itms_oris ------------------------------//*)
Walther@60760
   741
val (_, (i_model, _)) = return_match_itms_oris;
Walther@60760
   742
Walther@60760
   743
(*||------------------ continue. complete_for ------------------------------------------------*)
Walther@60760
   744
      val (o_model, ctxt, i_model) = return_complete_for
Walther@60763
   745
(*+isa*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST FunctionVariable, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST Input_Descript.Domain, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST ErrorBound, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T))]"
Walther@60763
   746
 = i_model |> I_Model.to_string_TEST ctxt(*+isa*)
Walther@60760
   747
(*+isa2:MET.Mis* ) val "[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,true ,#Find ,Cor Maximum A , pen2str), \n(3 ,[1, 2, 3] ,true ,#Find ,Cor AdditionalValues [u, v] , pen2str), \n(4 ,[1, 2, 3] ,true ,#Relate ,Cor Extremum (A = 2 * u * v - u \<up> 2) , pen2str), \n(5 ,[1, 2] ,true ,#Relate ,Cor SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str), \n(7 ,[1] ,false ,#Given ,Mis FunctionVariable funvar), \n(10 ,[1, 2] ,false ,#Given ,Mis Input_Descript.Domain doma), \n(12 ,[1, 2, 3] ,false ,#Given ,Mis ErrorBound err)]" =
Walther@60763
   748
  i_model |> I_Model.to_string ctxt ( *+isa2*)
Walther@60760
   749
(*\\------------------ step into complete_for ----------------------------------------------//*)
Walther@60760
   750
      val (o_model, ctxt, i_model) = return_complete_for
Walther@60760
   751
Walther@60760
   752
(*|------------------- continue. complete_for ------------------------------------------------*)
Walther@60760
   753
val return_complete_for_step = (o_model', ctxt', i_model)
Walther@60760
   754
Walther@60760
   755
val (o_model'_step, i_model_step) = (#1 return_complete_for_step, #3 return_complete_for_step)
Walther@60760
   756
val (o_model', i_model) = (#1 return_complete_for, #3 return_complete_for)
Walther@60760
   757
;
Walther@60763
   758
(*+*)if (o_model'_step, i_model_step) = (o_model', i_model)
Walther@60763
   759
(*+*)then () else error "return_complete_for_step <> return_complete_for";
Walther@60659
   760
(*\------------------- step into me Specify_Problem ----------------------------------------//*)
Walther@60659
   761
val (p,_,f,nxt,_,pt) = return_me_Specify_Problem
Walther@60578
   762
Walther@60760
   763
val return_me_Specify_Method
Walther@60763
   764
                     = me nxt p c pt; val Add_Given "FunctionVariable a" = #4 return_me_Specify_Method;
Walther@60760
   765
(*/------------------- step into me_Specify_Method -----------------------------------------\\*)
Walther@60659
   766
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60760
   767
Walther@60763
   768
(*+*)val "[]" =(*+*) get_obj g_met pt (fst p) |> I_Model.to_string ctxt
Walther@60760
   769
Walther@60578
   770
      val ctxt = Ctree.get_ctxt pt p
Walther@60578
   771
      val (pt, p) = 
Walther@60578
   772
  	    case Step.by_tactic tac (pt, p) of
Walther@60578
   773
  		    ("ok", (_, _, ptp)) => ptp;
Walther@60578
   774
Walther@60760
   775
(*quick step into --> me_Specify_Method*)
Walther@60760
   776
(*+*)val Specify_Method ["Optimisation", "by_univariate_calculus"] = tac;
Walther@60760
   777
(*    Step.by_tactic*)
Walther@60760
   778
"~~~~~ fun by_tactic , args:"; val () = ();
Walther@60760
   779
(*    Step.check*)
Walther@60760
   780
"~~~~~ fun check , args:"; val () = ();
Walther@60760
   781
(*Specify_Step.check (Tactic.Specify_Method*)
Walther@60760
   782
"~~~~~ fun check , args:"; val () = ();
Walther@60760
   783
(*Specify_Step.complete_for*)
Walther@60760
   784
"~~~~~ fun complete_for , args:"; val () = ();
Walther@60760
   785
(* M_Match.match_itms_oris*)
Walther@60760
   786
"~~~~~ fun match_itms_oris , args:"; val () = ();
Walther@60760
   787
Walther@60763
   788
(*+isa*)val"[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,true ,#Find ,Cor Maximum A , pen2str), \n(4 ,[1, 2, 3] ,true ,#Relate ,Cor Extremum (A = 2 * u * v - u \<up> 2) , pen2str), \n(5 ,[1, 2] ,true ,#Relate ,Cor SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str), \n(0 ,[2] ,false ,i_model_empty ,Sup FunctionVariable), \n(0 ,[2] ,false ,i_model_empty ,Sup Input_Descript.Domain), \n(0 ,[2] ,false ,i_model_empty ,Sup ErrorBound), \n(3 ,[1, 2, 3] ,true ,#Find ,Cor AdditionalValues [u, v] , pen2str)]"
Walther@60763
   789
 = get_obj g_met pt (fst p) |> I_Model.to_string ctxt;
Walther@60763
   790
Walther@60578
   791
         (*case*)
Walther@60578
   792
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60760
   793
(*//------------------ step into Step.do_next ----------------------------------------------\\*)
Walther@60578
   794
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) = (p, ((pt, Pos.e_pos'), []));
Walther@60578
   795
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60578
   796
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60578
   797
val _ =
Walther@60578
   798
      (*case*) tacis (*of*);
Walther@60578
   799
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60578
   800
Walther@60578
   801
      Step.switch_specify_solve p_ (pt, ip);
Walther@60760
   802
(*///----------------- step into Step.switch_specify_solve ---------------------------------\\*)
Walther@60578
   803
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   804
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   805
Walther@60578
   806
      Step.specify_do_next (pt, input_pos);
Walther@60760
   807
(*////---------------- step into Step.specify_do_next --------------------------------------\\*)
Walther@60578
   808
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = (pt, input_pos);
Walther@60578
   809
Walther@60578
   810
    val (_, (p_', tac)) =
Walther@60578
   811
   Specify.find_next_step ptp;
Walther@60763
   812
(*/////--------------- step into find_next_step --------------------------------------------\\*)
Walther@60578
   813
"~~~~~ fun find_next_step , args:"; val ((pt, pos as (_, p_))) = (ptp);
Walther@60578
   814
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60578
   815
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60578
   816
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60578
   817
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
Walther@60578
   818
        (*if*) p_ = Pos.Pbl (*else*);
Walther@60578
   819
Walther@60763
   820
(*+isa*)val     "[\n(1 ,[1, 2, 3] ,true ,#Given ,Cor Constants [r = 7] , pen2str), \n(2 ,[1, 2, 3] ,true ,#Find ,Cor Maximum A , pen2str), \n(4 ,[1, 2, 3] ,true ,#Relate ,Cor Extremum (A = 2 * u * v - u \<up> 2) , pen2str), \n(5 ,[1, 2] ,true ,#Relate ,Cor SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str), \n(0 ,[2] ,false ,i_model_empty ,Sup FunctionVariable), \n(0 ,[2] ,false ,i_model_empty ,Sup Input_Descript.Domain), \n(0 ,[2] ,false ,i_model_empty ,Sup ErrorBound), \n(3 ,[1, 2, 3] ,true ,#Find ,Cor AdditionalValues [u, v] , pen2str)]"
Walther@60763
   821
 = met |> I_Model.to_string ctxt;
Walther@60760
   822
Walther@60763
   823
(**)val ("dummy", (Met, Add_Given "FunctionVariable a")) =(**)
Walther@60578
   824
   Specify.for_method ctxt oris (o_refs, refs) (pbl, met);
Walther@60760
   825
(*///// /------------- step into Step.for_method -------------------------------------------\\*)
Walther@60730
   826
"~~~~~ fun for_method , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (_, met))
Walther@60578
   827
  = (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60578
   828
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60730
   829
    val {model, where_rls, where_, ...} = MethodC.from_store ctxt cmI;    (*..MethodC ?*)
Walther@60741
   830
    val (preok, _) = Pre_Conds.check ctxt where_rls where_ (model, I_Model.OLD_to_TEST met);
Walther@60578
   831
val NONE =
Walther@60578
   832
    (*case*) find_first (I_Model.is_error o #5) met (*of*);
Walther@60578
   833
Walther@60763
   834
(** )SOME (fd, ct') =( **)
Walther@60763
   835
(**)val return_item_to_add =(**)
Walther@60578
   836
      (*case*)
Walther@60763
   837
   Specify.item_to_add  ctxt oris (I_Model.OLD_to_TEST met) (*of*);
Walther@60763
   838
(*///// //------------ step into item_to_add -----------------------------------------------\\*)
Walther@60763
   839
"~~~~~ fun item_to_add , args:"; val (ctxt, o_model, i_model) = (ctxt, oris, I_Model.OLD_to_TEST met);
Walther@60763
   840
(*+*)val "[\n(1, [\"1\", \"2\", \"3\"], #Given, Constants, [\"[r = 7]\"]), \n(2, [\"1\", \"2\", \"3\"], #Given, Maximum, [\"A\"]), \n(3, [\"1\", \"2\", \"3\"], #Find, AdditionalValues, [\"[u]\", \"[v]\"]), \n(4, [\"1\", \"2\", \"3\"], #Given, Extremum, [\"A = 2 * u * v - u \<up> 2\"]), \n(5, [\"1\", \"2\"], #Given, SideConditions, [\"[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\"]), \n(6, [\"3\"], #Given, SideConditions, [\"[u / 2 = r * sin \<alpha>]\", \"[2 / v = r * cos \<alpha>]\"]), \n(7, [\"1\"], #Given, FunctionVariable, [\"a\"]), \n(8, [\"2\"], #Given, FunctionVariable, [\"b\"]), \n(9, [\"3\"], #Given, FunctionVariable, [\"\<alpha>\"]), \n(10, [\"1\", \"2\"], #Given, Input_Descript.Domain, [\"{0<..<r}\"]), \n(11, [\"3\"], #Given, Input_Descript.Domain, [\"{0<..<\<pi> / 2}\"]), \n(12, [\"1\", \"2\", \"3\"], #Given, ErrorBound, [\"\<epsilon> = 0\"])]"
Walther@60763
   841
 = oris |> O_Model.to_string ctxt
Walther@60763
   842
(*+*)val "[\n(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] , pen2str, Position.T)), \n(2, [1, 2, 3], true ,#Find, (Cor_TEST Maximum A , pen2str, Position.T)), \n(4, [1, 2, 3], true ,#Relate, (Cor_TEST Extremum (A = 2 * u * v - u \<up> 2) , pen2str, Position.T)), \n(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST FunctionVariable, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST Input_Descript.Domain, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST ErrorBound, Position.T)), \n(3, [1, 2, 3], true ,#Find, (Cor_TEST AdditionalValues [u, v] , pen2str, Position.T))]"
Walther@60763
   843
 = i_model |> I_Model.to_string_TEST ctxt
Walther@60763
   844
Walther@60763
   845
    val max_vnt = last_elem (*this decides, for which variant initially help is given*)
Walther@60763
   846
      (Model_Def.max_variants o_model i_model)
Walther@60763
   847
    val o_vnts = filter (fn (_, vnts, _, _, _) => member op= vnts max_vnt) o_model
Walther@60763
   848
    val i_to_select = i_model
Walther@60763
   849
      |> filter_out (fn (_, vnts, _, _, (I_Model.Cor_TEST _, _)) => member op= vnts max_vnt | _ => false)
Walther@60763
   850
      |> select_inc_lists
Walther@60763
   851
(*+*)val "[\n(0, [2], false ,i_model_empty, (Sup_TEST FunctionVariable, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST Input_Descript.Domain, Position.T)), \n(0, [2], false ,i_model_empty, (Sup_TEST ErrorBound, Position.T))]"
Walther@60763
   852
 = i_to_select |> I_Model.to_string_TEST ctxt
Walther@60763
   853
Walther@60763
   854
val false =
Walther@60763
   855
    (*if*) i_to_select = [] (*else*);
Walther@60763
   856
Walther@60763
   857
(** )val SOME (_, _, _, m_field, (feedb, _)) =( **)
Walther@60763
   858
(**)val return_fill_from_o = (**)
Walther@60763
   859
      (*case*) I_Model.fill_from_o o_vnts (hd i_to_select) (*of*);
Walther@60763
   860
(*///// ///----------- step into fill_from_o -----------------------------------------------\\*)
Walther@60763
   861
"~~~~~ fun fill_from_o , args:"; val (o_model, (i, vnts, bool, _, (feedb, pos))) =
Walther@60763
   862
  (o_vnts, (hd i_to_select));
Walther@60763
   863
    val (m_field, all_value) =
Walther@60767
   864
      case find_first (fn (_, _, _, descr', _) => Model_Def.descriptor_exists descr' feedb) o_model of
Walther@60763
   865
        SOME (_, _, m_field, _, ts) =>  (m_field, ts)
Walther@60767
   866
    val descr = Model_Def.get_descr feedb (*i_single has been filtered appropriately*)
Walther@60763
   867
val false =
Walther@60766
   868
    (*if*) Model_Def.is_list_descr descr (*else*);
Walther@60763
   869
val return_fill_from_o_STEP = SOME (i, vnts, bool, m_field, (Cor_TEST (descr, all_value), pos))
Walther@60763
   870
(*-------------------- stopped after ERROR found ---------------------------------------------*)
Walther@60763
   871
(*\\\\\ \\\----------- step into fill_from_o -----------------------------------------------//*)
Walther@60763
   872
val SOME (_, _, _, m_field, (feedb, _)) = return_fill_from_o
Walther@60763
   873
Walther@60763
   874
(*||||| ||------------ step into item_to_add -----------------------------------------------//*)
Walther@60763
   875
(*\\\\\ \\\----------- step into item_to_add -----------------------------------------------//*)
Walther@60763
   876
val return_item_to_add_STEP as SOME ("#Given", "FunctionVariable a") =
Walther@60763
   877
  SOME (m_field, feedb |> I_Model.feedb_args_to_string ctxt)
Walther@60763
   878
(*\\\\\ \\------------ step into item_to_add -----------------------------------------------//*)
Walther@60763
   879
val SOME (fd, ct') = return_item_to_add;
Walther@60763
   880
(*||||| |------------- contine.. Step.for_method ---------------------------------------------*)
Walther@60763
   881
val return_for_method_STEP = ("dummy", (Pos.Met, P_Model.mk_additem fd ct'))
Walther@60763
   882
Walther@60763
   883
(*\\\\\ \------------- step into Step.for_method -------------------------------------------//*)
Walther@60760
   884
(*\------------------- step into me_Specify_Method -----------------------------------------//*)
Walther@60578
   885
Walther@60763
   886
val (p,_,f,nxt,_,pt) = return_me_Specify_Method;
Walther@60763
   887
                                      val Add_Given "FunctionVariable a" = nxt;
Walther@60766
   888
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Given "Input_Descript.Domain {0<..<r}" = nxt
Walther@60578
   889
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Given "ErrorBound (\<epsilon> = 0)" = nxt;
Walther@60763
   890
(*ErRoR type_of: type mismatch in application, bool, bool list, (#) [r = 7] --> 200a-start-method
Walther@60763
   891
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Apply_Method xxx = nxt
Walther@60763
   892
*)