test/Tools/isac/Minisubpbl/150a-add-given-Maximum.sml
author wneuper <Walther.Neuper@jku.at>
Wed, 20 Sep 2023 11:30:50 +0200
changeset 60750 d4f6bfc1eb70
parent 60748 d9bae125ba2a
child 60754 bac1b22385e4
permissions -rw-r--r--
prepare 6: I_Model.T(*_TEST*) towards final shape
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@60728
    16
open Ctree;
Walther@60728
    17
open Pos;
Walther@60728
    18
open TermC;
Walther@60728
    19
open Istate;
Walther@60728
    20
open Tactic;
Walther@60728
    21
open I_Model;
Walther@60728
    22
open P_Model
Walther@60728
    23
open Rewrite;
Walther@60728
    24
open Step;
Walther@60728
    25
open LItool;
Walther@60728
    26
open LI;
Walther@60578
    27
open Test_Code
Walther@60705
    28
open Specify
Walther@60728
    29
open ME_Misc
Walther@60733
    30
open Pre_Conds;
Walther@60578
    31
Walther@60578
    32
val (_(*example text*),
Walther@60578
    33
  (model as ("Constants [r = (7::real)]" :: "Maximum A" :: "AdditionalValues [u, v]" :: 
Walther@60578
    34
     "Extremum (A = 2 * u * v - u \<up> 2)" :: 
Walther@60578
    35
     "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]" :: 
Walther@60578
    36
     "SideConditions [((u::real) / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]" :: 
Walther@60728
    37
     "SideConditions [(u::real) / 2 = r * sin \<alpha>, 2 / v = r * cos \<alpha>]" ::
Walther@60728
    38
(*---------------------------------------------,(v::real) / 2 = r * cos \<alpha>]" --- ERROR in example*)
Walther@60578
    39
     "FunctionVariable a" :: "FunctionVariable b" :: "FunctionVariable \<alpha>" :: 
Walther@60578
    40
     "Domain {0 <..< r}" :: "Domain {0 <..< r}" :: "Domain {0 <..< \<pi> / 2}" ::
Walther@60578
    41
     "ErrorBound (\<epsilon> = (0::real))" :: []), 
Walther@60578
    42
   refs as ("Diff_App", 
Walther@60578
    43
     ["univariate_calculus", "Optimisation"],
Walther@60578
    44
     ["Optimisation", "by_univariate_calculus"])))
Walther@60588
    45
  = Store.get (Know_Store.get_expls @{theory}) ["Diff_App-No.123a"] ["Diff_App-No.123a"];
Walther@60578
    46
Walther@60578
    47
val c = [];
Walther@60728
    48
val return_init_calc = 
Walther@60728
    49
 Test_Code.init_calc @{context} [(model, refs)]; (*val Model_Problem = nxt;*)
Walther@60728
    50
(*/------------------- step into init_calc -------------------------------------------------\\*)
Walther@60728
    51
"~~~~~ fun init_calc , args:"; val (ctxt, [(model, refs as (thy_id, _, _))]) =
Walther@60728
    52
  (@{context}, [(model, refs)]);
Walther@60728
    53
    val thy = thy_id |> ThyC.get_theory ctxt
Walther@60728
    54
    val ((pt, p), tacis) = Step_Specify.initialise' thy (model, refs)
Walther@60728
    55
	  val tac = case tacis of [] => Tactic.Empty_Tac | _ => (#1 o hd) tacis
Walther@60728
    56
	  val f = 
Walther@60728
    57
           TESTg_form ctxt (pt,p);
Walther@60728
    58
"~~~~~ fun TESTg_form , args:"; val (ctxt, ptp) = (ctxt, (pt,p));
Walther@60728
    59
    val (form, _, _) =
Walther@60728
    60
   ME_Misc.pt_extract ctxt ptp;
Walther@60728
    61
"~~~~~ fun pt_extract , args:"; val (ctxt, (pt, (p, p_ as Pbl(*Frm,Pbl*)))) = (ctxt, ptp);
Walther@60728
    62
        val ppobj = Ctree.get_obj I pt p
Walther@60728
    63
        val f = if Ctree.is_pblobj ppobj then pt_model ppobj p_ else Ctree.get_obj pt_form pt p;
Walther@60728
    64
            (*if*) Ctree.is_pblobj ppobj (*then*);
Walther@60728
    65
           pt_model ppobj p_ ;
Walther@60728
    66
"~~~~~ fun pt_model , args:"; val ((Ctree.PblObj {probl, spec, origin = (_, spec', hdl), ctxt, ...}), Pbl_) =
Walther@60728
    67
  (ppobj, p_);
Walther@60728
    68
      val (_, pI, _) = Ctree.get_somespec' spec spec';
Walther@60728
    69
(*    val where_ = if pI = Problem.id_empty then []*)
Walther@60728
    70
               (*if*) pI = Problem.id_empty (*else*);
Walther@60728
    71
	          val {where_rls, where_, model, ...} = Problem.from_store ctxt pI
Walther@60728
    72
	          val (_, where_) = 
Walther@60741
    73
 Pre_Conds.check ctxt where_rls where_
Walther@60728
    74
              (model, I_Model.OLD_to_TEST probl);
Walther@60741
    75
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
    76
  (ctxt, where_rls, where_, (model, I_Model.OLD_to_TEST probl));
Walther@60728
    77
      val (_, _, (env_subst, env_eval)) =
Walther@60728
    78
           of_max_variant model_patt i_model;
Walther@60728
    79
"~~~~~ fun of_max_variant , args:"; val (_, []) = (model_patt, i_model);
Walther@60728
    80
(*\------------------- step into init_calc -------------------------------------------------//*)
Walther@60728
    81
val (p,_,f,nxt,_,pt) = return_init_calc;
Walther@60578
    82
Walther@60728
    83
(*+*)val PblObj {ctxt, probl, ...} = get_obj I pt [];
Walther@60659
    84
(*+*)Proof_Context.theory_of ctxt (*= {Pure, .., Diff_App}*);
Walther@60659
    85
(*+*)val Free ("r", Type ("Real.real", [])) = Syntax.read_term ctxt "r"
Walther@60728
    86
(*+*)val [] = probl
Walther@60578
    87
Walther@60659
    88
val return_me_Model_Problem = 
Walther@60659
    89
           me nxt p c pt; val Add_Given "Constants [r = 7]" = #4 return_me_Model_Problem;
Walther@60659
    90
(*/------------------- step into me Model_Problem ------------------------------------------\\*)
Walther@60578
    91
"~~~~~ fun me , args:"; val (tac, (p:Pos.pos'), (_:Test_Code.NEW), (pt:Ctree.ctree)) = (nxt, p, c, pt);
Walther@60728
    92
      val ctxt = Ctree.get_ctxt pt p
Walther@60728
    93
val return_by_tactic = case
Walther@60728
    94
      Step.by_tactic tac (pt,p) of
Walther@60578
    95
		    ("ok", (_, _, ptp)) => ptp;
Walther@60578
    96
Walther@60728
    97
(*//------------------ step into by_tactic -------------------------------------------------\\*)
Walther@60728
    98
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
Walther@60728
    99
val Applicable.Yes tac' = (*case*)
Walther@60728
   100
      Step.check tac (pt, p) (*of*);
Walther@60728
   101
(*+*)val Model_Problem' _ = tac';
Walther@60728
   102
"~~~~~ fun check , args:"; val (tac, (ctree, pos)) = (tac, (pt, p));
Walther@60728
   103
  (*if*) Tactic.for_specify tac (*then*);
Walther@60728
   104
Walther@60728
   105
Specify_Step.check tac (ctree, pos);
Walther@60728
   106
"~~~~~ fun check , args:"; val (Tactic.Model_Problem, (pt, pos as (p, _))) =
Walther@60728
   107
  (tac, (ctree, pos));
Walther@60728
   108
        val (o_model, pI', ctxt) = case Ctree.get_obj I pt p of
Walther@60728
   109
          Ctree.PblObj {origin = (o_model, (_, pI', _), _), ctxt, ...} => (o_model, pI', ctxt)
Walther@60728
   110
	      val {model = model_patt, ...} = Problem.from_store (Ctree.get_ctxt pt pos) pI'
Walther@60728
   111
	      val pbl = I_Model.init_TEST o_model model_patt;
Walther@60728
   112
Walther@60728
   113
val return_check =
Walther@60728
   114
    Applicable.Yes (Tactic.Model_Problem' (pI', I_Model.TEST_to_OLD pbl, []));
Walther@60728
   115
(*\\------------------ step into by_tactic -------------------------------------------------//*)
Walther@60728
   116
val (pt, p) = return_by_tactic;
Walther@60728
   117
Walther@60659
   118
val return_do_next = (*case*)
Walther@60578
   119
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60578
   120
(*//------------------ step into do_next ---------------------------------------------------\\*)
Walther@60578
   121
"~~~~~ fun do_next , args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):Calc.state_pre)) =
Walther@60578
   122
  (p, ((pt, e_pos'),[]));
Walther@60578
   123
    val pIopt = get_pblID (pt,ip);
Walther@60578
   124
    (*if*) ip = ([],Res); (* = false*)
Walther@60578
   125
      val _ = (*case*) tacis (*of*);
Walther@60578
   126
      val SOME _ = (*case*) pIopt (*of*);
Walther@60578
   127
Walther@60578
   128
    val ("ok", ([(Add_Given "Constants [r = 7]", _, _)], [], _)) =
Walther@60578
   129
      Step.switch_specify_solve p_ (pt, ip);
Walther@60578
   130
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   131
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   132
Walther@60578
   133
    val ("ok", ([(Add_Given "Constants [r = 7]", _, _)], [], _)) =
Walther@60578
   134
      Step.specify_do_next (pt, input_pos);
Walther@60659
   135
(*///----------------- step into specify_do_next -------------------------------------------\\*)
Walther@60578
   136
"~~~~~ fun specify_do_next , args:"; val (ptp as (pt, (p, p_))) = (pt, input_pos);
Walther@60578
   137
Walther@60659
   138
(*  val (_, (p_', tac)) =*)
Walther@60659
   139
val return_find_next_step = (*keep for continuing specify_do_next*)
Walther@60578
   140
   Specify.find_next_step ptp;
Walther@60659
   141
(*////---------------- step into find_next_step --------------------------------------------\\*)
Walther@60578
   142
"~~~~~ fun find_next_step , args:"; val ((pt, pos as (_, p_))) = (ptp);
Walther@60578
   143
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60578
   144
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60578
   145
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60578
   146
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
Walther@60578
   147
        (*if*) p_ = Pos.Pbl (*then*);
Walther@60578
   148
Walther@60578
   149
   Specify.for_problem ctxt oris (o_refs, refs) (pbl, met);
Walther@60728
   150
(*/////--------------- step into for_problem -----------------------------------------------\\*)
Walther@60578
   151
"~~~~~ fun for_problem , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met))
Walther@60578
   152
  = (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60578
   153
    val cdI = if dI = ThyC.id_empty then dI' else dI;
Walther@60578
   154
    val cpI = if pI = Problem.id_empty then pI' else pI;
Walther@60578
   155
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60585
   156
    val {model = pbt, where_rls, where_, ...} = Problem.from_store ctxt cpI;
Walther@60728
   157
    val {model = mpc, ...} = MethodC.from_store ctxt cmI;
Walther@60728
   158
Walther@60728
   159
    val return_check_OLD =
Walther@60741
   160
           check ctxt where_rls where_ (pbt, I_Model.OLD_to_TEST pbl);
Walther@60741
   161
(*//////-------------- step into check -------------------------------------------------\\*)
Walther@60741
   162
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
   163
  (ctxt, where_rls, where_, (pbt, I_Model.OLD_to_TEST pbl));
Walther@60728
   164
      val return_of_max_variant =
Walther@60728
   165
           of_max_variant model_patt i_model;
Walther@60728
   166
(*///// //------------ step into of_max_variant --------------------------------------------\\*)
Walther@60728
   167
"~~~~~ fun of_max_variant , args:"; val (model_patt, i_model) =
Walther@60728
   168
  (model_patt, i_model);
Walther@60728
   169
Walther@60733
   170
(*+*)val "[\n(1, [1, 2, 3], false ,#Given, (Inc_TEST Constants [] [__=__, __=__], Position.T)), \n(2, [1, 2, 3], false ,#Find, (Inc_TEST Maximum __, Position.T)), \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@60733
   171
 = i_model |> I_Model.to_string_TEST @{context}
Walther@60728
   172
    val all_variants =
Walther@60728
   173
        map (fn (_, variants, _, _, _) => variants) i_model
Walther@60728
   174
        |> flat
Walther@60728
   175
        |> distinct op =
Walther@60728
   176
    val variants_separated = map (filter_variants' i_model) all_variants
Walther@60748
   177
    val sums_corr = map (Model_Def.cnt_corrects) variants_separated
Walther@60748
   178
    val sum_variant_s = Model_Def.arrange_args sums_corr (1, all_variants)
Walther@60728
   179
(*+*)val [(0, 1), (0, 2), (0, 3)] = sum_variant_s
Walther@60728
   180
    val (_, max_variant) = hd (*..crude decision, up to improvement *)
Walther@60728
   181
      (sort (fn ((i, _), (j, _)) => int_ord (i, j)) sum_variant_s)
Walther@60728
   182
    val i_model_max =
Walther@60728
   183
      filter (fn (_, variants, _ , _ ,_) => member (op =) variants max_variant) i_model
Walther@60728
   184
    val equal_descr_pairs = map (get_equal_descr i_model) model_patt |> flat
Walther@60728
   185
(*for building make_env_s -------------------------------------------------------------------\*)
Walther@60728
   186
(*!!!*) val ("#Given", (descr, term), pos) =
Walther@60728
   187
  Model_Pattern.split_descriptor ctxt ("#Given", @{term "Constants [r = (7::real)]"}, Position.none)
Walther@60728
   188
(*!!!*) val patt = equal_descr_pairs |> hd |> #1
Walther@60728
   189
(*!!!*)val equal_descr_pairs =
Walther@60728
   190
  (patt,
Walther@60750
   191
  (1, [1, 2, 3], true, "#Given", (Cor_TEST ((descr, (*!*)TermC.isalist2list(*!*) term)), pos)))
Walther@60728
   192
  :: tl equal_descr_pairs
Walther@60728
   193
(*for building make_env_s -------------------------------------------------------------------/*)
Walther@60728
   194
Walther@60728
   195
    val env_model = make_env_model equal_descr_pairs;
Walther@60728
   196
(*///// ///----------- step into make_env_model --------------------------------------------\\*)
Walther@60728
   197
"~~~~~ fun make_env_model , args:"; val (equal_descr_pairs) = (equal_descr_pairs);
Walther@60728
   198
Walther@60728
   199
val xxx = (fn ((_, (_, id)), (_, _, _, _, (feedb, _)))
Walther@60728
   200
       => (mk_env_model id feedb));
Walther@60728
   201
val ((_, (_, id)), (_, _, _, _, (feedb, _))) = nth 4 equal_descr_pairs;
Walther@60728
   202
(*\\\\\ \\\----------- step into make_env_model --------------------------------------------//*)
Walther@60728
   203
(*||||| ||------------ contine of_max_variant ------------------------------------------------*)
Walther@60728
   204
Walther@60728
   205
    val equal_givens = filter (fn ((m_field, _), _) => m_field = "#Given") equal_descr_pairs
Walther@60728
   206
    val subst_eval_list = make_envs_preconds equal_givens
Walther@60728
   207
val return_make_envs_preconds =
Walther@60728
   208
           make_envs_preconds equal_givens;
Walther@60728
   209
(*///// ///----------- step into make_envs_preconds ----------------------------------------\\*)
Walther@60728
   210
"~~~~~ fun make_envs_preconds , args:"; val (equal_givens) = (equal_givens);
Walther@60728
   211
val xxx = (fn ((_, (_, id)), (_, _, _, _, (feedb, _))) => discern_feedback id feedb)
Walther@60728
   212
;
Walther@60728
   213
xxx: (Model_Pattern.single * I_Model.single_TEST) -> ((term * term) * (term * term)) list;
Walther@60728
   214
val return_discern_feedback =
Walther@60728
   215
           discern_feedback id feedb;
Walther@60728
   216
(*nth 1 equal_descr_pairs* )
Walther@60728
   217
"~~~~~ fun discern_feedback , args:"; val (id, (Model_Def.Cor_TEST ((descr, ts), _))) = (id, feedb);
Walther@60728
   218
( *nth 2 equal_descr_pairs*)
Walther@60750
   219
"~~~~~ fun discern_feedback , args:"; val (id, (Model_Def.Inc_TEST ((descr, ts)))) = (id, feedb);
Walther@60728
   220
Walther@60728
   221
(*nth 1 equal_descr_pairs* )
Walther@60728
   222
(*+*)val [((Const ("fixes", typ1), Free ("r", typ2)),
Walther@60728
   223
           (Free ("r", typ3), value))] = return_discern_feedback
Walther@60728
   224
(*+*)val true = typ1 = typ2
Walther@60728
   225
(*+*)val true = typ3 = HOLogic.realT
Walther@60728
   226
(*+*)val "7" = UnparseC.term @{context} value
Walther@60728
   227
( *nth 2 equal_descr_pairs*)
Walther@60728
   228
(*+*)val [] = return_discern_feedback
Walther@60728
   229
Walther@60728
   230
val return_discern_typ =
Walther@60728
   231
           discern_typ id (descr, ts);
Walther@60728
   232
"~~~~~ fun discern_typ , args:"; val (id, (descr, ts)) = (id, (descr, ts));
Walther@60728
   233
(*nth 1 equal_descr_pairs* )
Walther@60728
   234
(*+*)val [((Const ("fixes", typ1), Free ("r", typ2)),
Walther@60728
   235
           (Free ("r", typ3), value))] = return_discern_typ
Walther@60728
   236
(*+*)val true = typ1 = typ2
Walther@60728
   237
(*+*)val true = typ3 = HOLogic.realT
Walther@60728
   238
(*+*)val "7" = UnparseC.term @{context} value
Walther@60728
   239
( *nth 2 equal_descr_pairs*)
Walther@60728
   240
(*+*)val [] = return_discern_typ;
Walther@60728
   241
(**)
Walther@60741
   242
           switch_type id ts;
Walther@60741
   243
"~~~~~ fun switch_type , args:"; val (Const (descr_string, _), ts) = (descr, ts);
Walther@60728
   244
Walther@60728
   245
(*nth 1 equal_descr_pairs* )
Walther@60728
   246
val return_switch_type_TEST = Const (descr_string, ts |> hd |> TermC.lhs |> type_of)
Walther@60728
   247
Walther@60728
   248
(*+*)val Const ("Input_Descript.Constants", typ) = return_switch_type_TEST
Walther@60728
   249
(*+*)val Type ("Real.real", []) = typ
Walther@60728
   250
( *nth 2 equal_descr_pairs*)
Walther@60728
   251
(*+*)val return_switch_type_TEST = descr
Walther@60728
   252
(**)
Walther@60728
   253
(*\\\\\ \\\----------- step into make_envs_preconds ----------------------------------------//*)
Walther@60728
   254
(*||||| ||------------ contine of_max_variant ------------------------------------------------*)
Walther@60728
   255
    val subst_eval_list = make_envs_preconds equal_givens
Walther@60728
   256
    val (env_subst, env_eval) = split_list subst_eval_list
Walther@60728
   257
val return_of_max_variant = (i_model_max, env_model, (env_subst, env_eval)); (*GOON*)
Walther@60728
   258
(*\\\\\ \\------------ step into of_max_variant --------------------------------------------//*)
Walther@60728
   259
      val (i_model_max, env_model, (env_subst, env_eval)) = return_of_max_variant
Walther@60728
   260
(*!!!/----- we had a helpful argument for constructing env_model and (env_subst, env_eval)---\*)
Walther@60728
   261
      val (i_max_variant, env_model, (env_subst, env_eval)) = (i_model_max, [], ([], []))
Walther@60728
   262
(*!!!\----- we had a helpful argument for constructing env_model and (env_subst, env_eval)---/*) 
Walther@60741
   263
(*||||||-------------- contine check -----------------------------------------------------*)
Walther@60728
   264
      val pres_subst = map (TermC.subst_atomic_all env_subst) pres;
Walther@60728
   265
      val pres_subst_other = map (TermC.subst_atomic_all env_model) (map #2 pres_subst);
Walther@60728
   266
      val full_subst = if env_eval = [] then pres_subst_other
Walther@60728
   267
        else map (TermC.subst_atomic_all env_eval) (map #2 pres_subst_other)
Walther@60728
   268
      val evals = map (eval ctxt where_rls) full_subst
Walther@60728
   269
val return_ = (i_model_max, env_subst, env_eval)
Walther@60741
   270
(*\\\\\\\------------- step into check -------------------------------------------------//*)
Walther@60728
   271
val (preok, _) = return_check_OLD;
Walther@60728
   272
Walther@60728
   273
(*|||||--------------- contine for_problem ---------------------------------------------------*)
Walther@60578
   274
    (*if*) dI' = ThyC.id_empty andalso dI = ThyC.id_empty (*else*);
Walther@60578
   275
      (*if*) pI' = Problem.id_empty andalso pI = Problem.id_empty (*else*);
Walther@60728
   276
val NONE =
Walther@60728
   277
     (*case*) find_first (I_Model.is_error o #5) pbl (*of*);
Walther@60578
   278
Walther@60578
   279
        (*case*)
Walther@60676
   280
   Specify.item_to_add (ThyC.get_theory ctxt
Walther@60578
   281
            (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl (*of*);
Walther@60578
   282
"~~~~~ fun item_to_add , args:"; val (thy, oris, _, itms)
Walther@60676
   283
  = ((ThyC.get_theory ctxt (if dI = ThyC.id_empty then dI' else dI)), oris, pbt, pbl);
Walther@60578
   284
      fun false_and_not_Sup (_, _, false, _, I_Model.Sup _) = false
Walther@60578
   285
        | false_and_not_Sup (_, _, false, _, _) = true
Walther@60578
   286
        | false_and_not_Sup _ = false
Walther@60728
   287
Walther@60705
   288
      val v = if itms = [] then 1 else Pre_Conds.max_variant itms
Walther@60728
   289
      val vors = if v = 0 then oris
Walther@60728
   290
        else filter ((fn variant =>
Walther@60728
   291
            fn (_, variants, m_field, _, _) => member op= variants variant andalso m_field <> "#undef")
Walther@60728
   292
          v) oris
Walther@60728
   293
Walther@60728
   294
(*+*)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]\"])]"
Walther@60728
   295
(*+*)  = vors |> O_Model.to_string @{context}
Walther@60728
   296
Walther@60728
   297
      val vits = if v = 0 then itms               (* because of dsc without dat *)
Walther@60728
   298
  	    else filter ((fn variant =>
Walther@60728
   299
            fn (_, variants, _, _, _) => member op= variants variant)
Walther@60728
   300
          v) itms;                                (* itms..vat *)
Walther@60728
   301
Walther@60728
   302
      val icl = filter false_and_not_Sup vits;    (* incomplete *)
Walther@60728
   303
Walther@60578
   304
      (*if*) icl = [] (*else*);
Walther@60739
   305
(*+*)val "[\n(1 ,[1, 2, 3] ,false ,#Given ,Inc Constants [] , 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@60739
   306
 = icl |> I_Model.to_string @{context}
Walther@60739
   307
(*+*)val "(1 ,[1, 2, 3] ,false ,#Given ,Inc Constants [] , pen2str)"
Walther@60739
   308
 = hd icl |> I_Model.single_to_string @{context}
Walther@60728
   309
Walther@60728
   310
(*++*)val feedback = (fn (_, _, _, _, feedback) => feedback) (hd icl)
Walther@60728
   311
(*++*)val Const ("Input_Descript.Constants", _) = I_Model.descriptor feedback
Walther@60728
   312
(*++*)val [] = I_Model.o_model_values feedback
Walther@60728
   313
Walther@60728
   314
(*+*)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]\"])]"
Walther@60728
   315
(*+*)  = vors |> O_Model.to_string @{context}
Walther@60728
   316
Walther@60578
   317
val SOME ori =
Walther@60728
   318
        (*case*) find_first ((fn (_, _, _, _, feedback) => fn (_, _, _, d, ts) =>
Walther@60728
   319
           d = I_Model.descriptor feedback andalso subset op = (I_Model.o_model_values feedback, ts))
Walther@60728
   320
         (hd icl)) vors (*of*);
Walther@60728
   321
Walther@60728
   322
(*+*)val "(1, [\"1\", \"2\", \"3\"], #Given, Constants, [\"[r = 7]\"])" =
Walther@60728
   323
(*+*)  ori |> O_Model.single_to_string @{context}
Walther@60728
   324
(*\\\\\--------------- step into for_problem -----------------------------------------------//*)
Walther@60659
   325
(*\\\\---------------- step into find_next_step --------------------------------------------//*)
Walther@60659
   326
(*|||----------------- continuing specify_do_next --------------------------------------------*)
Walther@60659
   327
val (_, (p_', tac)) = return_find_next_step (*kept for continuing specify_do_next*)
Walther@60659
   328
Walther@60659
   329
    val ist_ctxt =  Ctree.get_loc pt (p, p_)
Walther@60659
   330
(*+*)val Add_Given "Constants [r = 7]" = tac
Walther@60659
   331
val _ =
Walther@60659
   332
    (*case*) tac (*of*);
Walther@60659
   333
Walther@60659
   334
Step_Specify.by_tactic_input tac (pt, (p, p_'));
Walther@60659
   335
"~~~~~ fun by_tactic_input , args:"; val ((Tactic.Add_Given ct), ptp) =
Walther@60659
   336
  (tac, (pt, (p, p_')));
Walther@60659
   337
Walther@60659
   338
   Specify.by_Add_ "#Given" ct ptp;
Walther@60659
   339
"~~~~~ fun by_Add_ , args:"; val (m_field, ct ,(pt, pos as (_, p_))) =
Walther@60659
   340
  ("#Given", ct, ptp);
Walther@60659
   341
    val (met, oris, (_, pI', mI'), pbl, (_, pI, mI), ctxt) = SpecificationC.get_data (pt, pos)
Walther@60659
   342
    val (i_model, m_patt) =
Walther@60659
   343
       if p_ = Pos.Met then
Walther@60659
   344
         (met,
Walther@60659
   345
           (if mI = MethodC.id_empty then mI' else mI) |> MethodC.from_store ctxt |> #model)
Walther@60659
   346
       else
Walther@60659
   347
         (pbl,
Walther@60659
   348
           (if pI = Problem.id_empty then pI' else pI) |> Problem.from_store ctxt |> #model);
Walther@60728
   349
Walther@60659
   350
      (*case*)
Walther@60659
   351
   I_Model.check_single ctxt m_field oris i_model m_patt ct (*of*);
Walther@60659
   352
"~~~~~ fun check_single , args:"; val (ctxt, m_field, o_model, i_model, m_patt, (str(*, pos*))) =
Walther@60659
   353
  (ctxt, m_field, oris, i_model, m_patt, ct);
Walther@60728
   354
        val (t as (descriptor $ _)) = Syntax.read_term ctxt str
Walther@60659
   355
Walther@60675
   356
(*+*)val "Constants [r = 7]" = UnparseC.term @{context} t;
Walther@60659
   357
Walther@60728
   358
        val SOME m_field' =
Walther@60728
   359
          (*case*) Model_Pattern.get_field descriptor m_patt (*of*);
Walther@60728
   360
           (*if*) m_field <> m_field' (*else*);
Walther@60659
   361
Walther@60659
   362
(*+*)val "#Given" = m_field; val "#Given" = m_field'
Walther@60659
   363
Walther@60728
   364
val ("", ori', all) =
Walther@60728
   365
          (*case*) O_Model.contains ctxt m_field o_model t (*of*);
Walther@60659
   366
Walther@60659
   367
(*+*)val (_, _, _, _, vals) = hd o_model;
Walther@60675
   368
(*+*)val "Constants [r = 7]" = UnparseC.term @{context} (@{term Constants} $ (hd vals));
Walther@60728
   369
(*+*)if "[\n(1, [\"1\", \"2\", \"3\"], #Given, Constants, [\"[r = 7]\"]), " ^ 
Walther@60728
   370
(*+*)    "\n(2, [\"1\", \"2\", \"3\"], #Find, Maximum, [\"A\"]), " ^ 
Walther@60728
   371
(*+*)    "\n(3, [\"1\", \"2\", \"3\"], #Find, AdditionalValues, [\"[u]\", \"[v]\"]), " ^ 
Walther@60728
   372
(*+*)    "\n(4, [\"1\", \"2\", \"3\"], #Relate, Extremum, [\"A = 2 * u * v - u \<up> 2\"]), " ^ 
Walther@60728
   373
(*+*)    "\n(5, [\"1\", \"2\"], #Relate, SideConditions, [\"[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]\"]), " ^ 
Walther@60728
   374
(*+*)    "\n(6, [\"3\"], #Relate, SideConditions, [\"[u / 2 = r * sin \<alpha>]\", \"[2 / v = r * cos \<alpha>]\"]), " ^ 
Walther@60728
   375
(*+*)    "\n(7, [\"1\"], #undef, FunctionVariable, [\"a\"]), " ^ 
Walther@60728
   376
(*+*)    "\n(8, [\"2\"], #undef, FunctionVariable, [\"b\"]), \n(9, [\"3\"], #undef, FunctionVariable, [\"\<alpha>\"]), " ^ 
Walther@60728
   377
(*+*)    "\n(10, [\"1\", \"2\"], #undef, Input_Descript.Domain, [\"{0<..<r}\"]), " ^ 
Walther@60728
   378
(*+*)    "\n(11, [\"3\"], #undef, Input_Descript.Domain, [\"{0<..<\<pi> / 2}\"]), " ^ 
Walther@60728
   379
(*+*)    "\n(12, [\"1\", \"2\", \"3\"], #undef, ErrorBound, [\"\<epsilon> = 0\"])]"
Walther@60728
   380
(*+*)= O_Model.to_string @{context} o_model then () else error "o_model CHANGED";
Walther@60578
   381
Walther@60728
   382
  (*case*) is_notyet_input ctxt i_model all ori' m_patt (*of*);
Walther@60728
   383
"~~~~~ fun is_notyet_input , args:"; val (ctxt, itms, all, (i, v, f, d, ts), pbt) =
Walther@60728
   384
  (ctxt, i_model, all, ori', m_patt);
Walther@60728
   385
val SOME (_, (_, pid)) =
Walther@60728
   386
  (*case*) find_first (eq1 d) pbt (*of*);
Walther@60728
   387
(*local*)fun eq3 f d (_, _, _, f', itm_) = f = f' andalso d = (I_Model.descriptor itm_);(*local*)
Walther@60728
   388
val SOME (_, _, _, _, itm_) =
Walther@60728
   389
    (*case*) find_first (eq3 f d) itms (*of*);
Walther@60728
   390
val ts' = inter op = (o_model_values itm_) ts;
Walther@60728
   391
            (*if*) subset op = (ts, ts') (*else*);
Walther@60728
   392
val return_is_notyet_input = ("", 
Walther@60728
   393
           ori_2itm itm_ pid all (i, v, f, d, subtract op = ts' ts));
Walther@60728
   394
"~~~~~ fun ori_2itm , args:"; val (itm_, pid, all, (id, vt, fd, d, ts)) =
Walther@60728
   395
  (itm_, pid, all, (i, v, f, d, subtract op = ts' ts));
Walther@60728
   396
    val ts' = union op = (o_model_values itm_) ts;
Walther@60728
   397
    val pval = [Input_Descript.join'''' (d, ts')]
Walther@60728
   398
    val complete = if eq_set op = (ts', all) then true else false
Walther@60728
   399
Walther@60739
   400
(*+*)val "Inc Constants [] , pen2str" = itm_ |> I_Model.feedback_to_string @{context}
Walther@60728
   401
(*\\\----------------- step into specify_do_next -------------------------------------------//*)
Walther@60728
   402
(*\\------------------ step into do_next ---------------------------------------------------//*)
Walther@60728
   403
val ("ok", (ts as (_, _, _) :: _, _, (pt, p))) = return_do_next
Walther@60728
   404
Walther@60728
   405
(*|------------------- continue with me_Model_Problem ----------------------------------------*)
Walther@60659
   406
Walther@60578
   407
val tacis as (_::_) =
Walther@60578
   408
        (*case*) ts (*of*);
Walther@60578
   409
          val (tac, _, _) = last_elem tacis
Walther@60578
   410
Walther@60728
   411
val return_Model_Problem = (p, [] : NEW, TESTg_form ctxt (pt, p), tac, Celem.Sundef, pt);
Walther@60728
   412
(*//------------------ step into TESTg_form ------------------------------------------------\\*)
Walther@60578
   413
"~~~~~ fun TESTg_form , args:"; val (ctxt, ptp) = (ctxt, (pt, p));
Walther@60728
   414
Walther@60728
   415
    val (form, _, _) =
Walther@60728
   416
   ME_Misc.pt_extract ctxt ptp;
Walther@60728
   417
"~~~~~ fun pt_extract , args:"; val (ctxt, (pt, (p, p_(*Frm,Pbl*)))) = (ctxt, ptp);
Walther@60728
   418
        val ppobj = Ctree.get_obj I pt p
Walther@60728
   419
        val f = if Ctree.is_pblobj ppobj then pt_model ppobj p_ else Ctree.get_obj pt_form pt p;
Walther@60728
   420
          (*if*) Ctree.is_pblobj ppobj (*then*);
Walther@60728
   421
Walther@60728
   422
           pt_model ppobj p_;
Walther@60728
   423
"~~~~~ fun pt_model , args:"; val ((Ctree.PblObj {probl, spec, origin = (_, spec', hdl), ctxt, ...}), 
Walther@60728
   424
  Pbl(*Frm,Pbl*)) = (ppobj, p_);
Walther@60728
   425
      val (_, pI, _) = Ctree.get_somespec' spec spec';
Walther@60728
   426
                 (*if*) pI = Problem.id_empty (*else*); 
Walther@60728
   427
(*    val where_ = if pI = Problem.id_empty then []*)
Walther@60728
   428
(*      else                                       *)
Walther@60728
   429
(*        let                                      *)
Walther@60728
   430
	          val {where_rls, where_, model, ...} = Problem.from_store ctxt pI
Walther@60741
   431
	          val (_, where_) = (*Pre_Conds.*)check ctxt where_rls where_ (model, I_Model.OLD_to_TEST probl)
Walther@60728
   432
(*        in where_ end                           *)
Walther@60728
   433
	    val allcorrect = I_Model.is_complete probl andalso foldl and_ (true, (map #1 where_))
Walther@60728
   434
val return_pt_model = Ctree.ModSpec (allcorrect, Pos.Pbl, hdl, probl, where_, spec)
Walther@60728
   435
Walther@60728
   436
(*|------------------- continue with TESTg_form ----------------------------------------------*)
Walther@60728
   437
val Ctree.ModSpec (spec as (_, p_, _, gfr, where_, _)) =
Walther@60578
   438
    (*case*) form (*of*);
Walther@60578
   439
    Test_Out.PpcKF (  (Test_Out.Problem [],
Walther@60586
   440
 			P_Model.from (Proof_Context.theory_of ctxt) gfr where_));
Walther@60578
   441
Walther@60586
   442
   P_Model.from (Proof_Context.theory_of ctxt) gfr where_;
Walther@60586
   443
"~~~~~ fun from , args:"; val (thy, itms, where_) = ((Proof_Context.theory_of ctxt), gfr, where_);
Walther@60586
   444
    fun coll model [] = model
Walther@60586
   445
      | coll model ((_, _, _, field, itm_) :: itms) =
Walther@60586
   446
        coll (add_sel_ppc thy field model (item_from_feedback thy itm_)) itms;
Walther@60578
   447
Walther@60578
   448
 val gfr = coll P_Model.empty itms;
Walther@60586
   449
"~~~~~ fun coll , args:"; val (model, ((aaa, bbb_,ccc_, field, itm_) :: itms))
Walther@60578
   450
  = (P_Model.empty, itms);
Walther@60578
   451
Walther@60578
   452
(*+*)val 4 = length itms;
Walther@60578
   453
(*+*)val itm = nth 1 itms;
Walther@60578
   454
Walther@60578
   455
           coll P_Model.empty [itm];
Walther@60586
   456
"~~~~~ fun coll , iterate:"; val (model, ((aaa, bbb_,ccc_, field, itm_) :: []))
Walther@60578
   457
  = (P_Model.empty, [itm]);
Walther@60578
   458
Walther@60586
   459
          (add_sel_ppc thy field model (item_from_feedback thy itm_));
Walther@60578
   460
"~~~~~ fun add_sel_ppc , args:"; val ((_: theory), sel, {Given = gi, Where = wh, Find = fi, With = wi, Relate = re}, x )
Walther@60586
   461
  = (thy, field, model, (item_from_feedback thy itm_));
Walther@60578
   462
Walther@60578
   463
   P_Model.item_from_feedback thy itm_;
Walther@60578
   464
"~~~~~ fun item_from_feedback , args:"; val (thy, (I_Model.Inc ((d, ts), _))) = (thy, itm_);
Walther@60728
   465
   P_Model.Incompl (UnparseC.term_in_thy thy (Input_Descript.join (d, ts)));
Walther@60728
   466
(*\\------------------ step into TESTg_form ------------------------------------------------//*)
Walther@60728
   467
(*\------------------- step into me Model_Problem ------------------------------------------//*)
Walther@60659
   468
val (p, _, f, nxt, _, pt) = return_me_Model_Problem
Walther@60728
   469
Walther@60728
   470
(*-------------------- contine me's ----------------------------------------------------------*)
Walther@60728
   471
val return_me_add_find_Constants = me nxt p c pt;
Walther@60728
   472
                                      val Add_Find "Maximum A" = #4 return_me_add_find_Constants;
Walther@60728
   473
(*/------------------- step into me_add_find_Constants -------------------------------------\\*)
Walther@60728
   474
"~~~~~ fun me , args:"; val (tac as Add_Given "Constants [r = 7]", p, _(*NEW remove*), pt) =
Walther@60728
   475
  (nxt, p, c, pt);
Walther@60728
   476
      val ctxt = Ctree.get_ctxt pt p
Walther@60728
   477
(*+*)val PblObj {probl = (1, [1, 2, 3], false, "#Given", Inc 
Walther@60728
   478
    ((Const ("Input_Descript.Constants", _), []), _)) :: _, ...}  = get_obj I pt (fst p)
Walther@60728
   479
(*-------------------------------------------^^--*)
Walther@60728
   480
val return_step_by_tactic = (*case*) 
Walther@60728
   481
      Step.by_tactic tac (pt, p) (*of*);
Walther@60728
   482
(*//------------------ step into Step.by_tactic --------------------------------------------\\*)
Walther@60728
   483
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60728
   484
val Applicable.Yes tac' =
Walther@60741
   485
    (*case*) Specify_Step.check tac (pt, p) (*of*);
Walther@60728
   486
	    (*if*) Tactic.for_specify' tac' (*then*);
Walther@60728
   487
Step_Specify.by_tactic tac' ptp;
Walther@60728
   488
"~~~~~ fun by_tactic , args:"; val ((Tactic.Add_Given' (ct, _)), (pt, p)) = (tac', ptp);
Walther@60728
   489
Walther@60728
   490
   Specify.by_Add_ "#Given" ct (pt, p);
Walther@60728
   491
"~~~~~ fun by_Add_ , args:"; val (m_field, ct, (pt, pos as (_, p_))) = ("#Given", ct, (pt, p));
Walther@60728
   492
    val (met, oris, (_, pI', mI'), pbl, (_, pI, mI), ctxt) = SpecificationC.get_data (pt, pos);
Walther@60728
   493
(*  val (i_model, m_patt) =*)
Walther@60728
   494
       (*if*) p_ = Pos.Met (*else*);
Walther@60728
   495
val return_by_Add_ =
Walther@60728
   496
         (pbl,
Walther@60728
   497
           (if pI = Problem.id_empty then pI' else pI) |> Problem.from_store ctxt |> #model)
Walther@60728
   498
val I_Model.Add i_single =
Walther@60728
   499
      (*case*) I_Model.check_single ctxt m_field oris i_model m_patt ct (*of*);
Walther@60728
   500
Walther@60728
   501
	          val i_model' =
Walther@60728
   502
   I_Model.add_single (Proof_Context.theory_of ctxt) i_single i_model;
Walther@60728
   503
"~~~~~ fun add_single , args:"; val (thy, itm, model) =
Walther@60728
   504
  ((Proof_Context.theory_of ctxt), i_single, i_model);
Walther@60728
   505
    fun eq_untouched d (0, _, _, _, itm_) = (d = I_Model.descriptor itm_)
Walther@60728
   506
      | eq_untouched _ _ = false
Walther@60728
   507
    val model' = case I_Model.seek_ppc (#1 itm) model of
Walther@60728
   508
      SOME _ => overwrite_ppc thy itm model (*itm updated in is_notyet_input WN.11.03*)
Walther@60728
   509
Walther@60728
   510
(*||------------------ contine Step.by_tactic ------------------------------------------------*)
Walther@60728
   511
(*\\------------------ step into Step.by_tactic --------------------------------------------//*)
Walther@60728
   512
val ("ok", (_, _, ptp)) = return_step_by_tactic;
Walther@60728
   513
Walther@60728
   514
      val (pt, p) = ptp;
Walther@60728
   515
        (*case*) 
Walther@60728
   516
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60728
   517
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) =
Walther@60728
   518
  (p, ((pt, Pos.e_pos'), []));
Walther@60728
   519
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60728
   520
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60728
   521
val _ =
Walther@60728
   522
      (*case*) tacis (*of*);
Walther@60728
   523
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60728
   524
Walther@60728
   525
           switch_specify_solve p_ (pt, ip);
Walther@60728
   526
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60728
   527
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60728
   528
Walther@60728
   529
           specify_do_next (pt, input_pos);
Walther@60728
   530
"~~~~~ fun specify_do_next , args:"; val (ptp as (pt, (p, p_))) = (pt, input_pos);
Walther@60728
   531
    val (_, (p_', tac)) =
Walther@60728
   532
   Specify.find_next_step ptp;
Walther@60728
   533
"~~~~~ fun find_next_step , args:"; val (pt, pos as (_, p_)) = (ptp);
Walther@60728
   534
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60728
   535
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60728
   536
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60728
   537
Walther@60728
   538
(*+*)val (1, [1, 2, 3], true, "#Given", Cor ((Const ("Input_Descript.Constants", _), ts ), _)) :: _
Walther@60728
   539
  = pbl
Walther@60728
   540
(*+*)val "[[r = 7]]" = UnparseC.terms @{context} ts;
Walther@60728
   541
(*-----ML-^------^-HOL*)
Walther@60728
   542
Walther@60728
   543
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*); 
Walther@60728
   544
        (*if*) p_ = Pos.Pbl (*then*); 
Walther@60728
   545
Walther@60728
   546
           for_problem ctxt oris (o_refs, refs) (pbl, met);
Walther@60728
   547
"~~~~~ fun for_problem , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met)) =
Walther@60728
   548
  (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60728
   549
    val cpI = if pI = Problem.id_empty then pI' else pI;
Walther@60728
   550
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60728
   551
    val {model = pbt, where_rls, where_, ...} = Problem.from_store ctxt cpI;
Walther@60728
   552
    val {model = mpc, ...} = MethodC.from_store ctxt cmI
Walther@60728
   553
Walther@60728
   554
    val (preok, _) =
Walther@60741
   555
Pre_Conds.check ctxt where_rls where_ (pbt, I_Model.OLD_to_TEST pbl);
Walther@60741
   556
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
   557
  (ctxt, where_rls, where_, (pbt, I_Model.OLD_to_TEST pbl));
Walther@60728
   558
Walther@60728
   559
      val (_, _, (env_subst, env_eval)) = of_max_variant model_patt i_model;
Walther@60728
   560
"~~~~~ fun of_max_variant , args:"; val (model_patt, i_model) = (model_patt, i_model);
Walther@60728
   561
    val all_variants =
Walther@60728
   562
        map (fn (_, variants, _, _, _) => variants) i_model
Walther@60728
   563
        |> flat
Walther@60728
   564
        |> distinct op =
Walther@60728
   565
    val variants_separated = map (filter_variants' i_model) all_variants
Walther@60748
   566
    val sums_corr = map (Model_Def.cnt_corrects) variants_separated
Walther@60748
   567
    val sum_variant_s = Model_Def.arrange_args sums_corr (1, all_variants)
Walther@60728
   568
    val (_, max_variant) = hd (*..crude decision, up to improvement *)
Walther@60728
   569
      (sort (fn ((i, _), (j, _)) => int_ord (i, j)) sum_variant_s)
Walther@60728
   570
    val i_model_max =
Walther@60728
   571
      filter (fn (_, variants, _ , _ ,_) => member (op =) variants max_variant) i_model
Walther@60728
   572
    val equal_descr_pairs = map (get_equal_descr i_model) model_patt |> flat
Walther@60728
   573
    val env_model = make_env_model equal_descr_pairs
Walther@60728
   574
    val equal_givens = filter (fn ((m_field, _), _) => m_field = "#Given") equal_descr_pairs
Walther@60728
   575
Walther@60728
   576
    val subst_eval_list =
Walther@60728
   577
           make_envs_preconds equal_givens;
Walther@60728
   578
"~~~~~ fun make_envs_preconds , args:"; val (equal_givens) = (equal_givens);
Walther@60728
   579
val xxx = (fn ((_, (_, id)), (_, _, _, _, (feedb, _))) =>
Walther@60728
   580
           discern_feedback id feedb)
Walther@60728
   581
val           ((_, (_, id)), (_, _, _, _, (feedb, _))) = nth 1 equal_givens;
Walther@60750
   582
"~~~~~ fun discern_feedback , args:"; val (id, (Model_Def.Cor_TEST ((descr, ts)))) = (id, feedb);
Walther@60728
   583
Walther@60728
   584
           discern_typ id (descr, ts);
Walther@60728
   585
"~~~~~ fun discern_typ , args:"; val (id, (descr, ts)) = (id, (descr, ts));
Walther@60728
   586
(*|------------------- contine me_add_find_Constants -----------------------------------------*)
Walther@60728
   587
(*\------------------- step into me_add_find_Constants -------------------------------------//*)
Walther@60728
   588
val (p,_,f,nxt,_,pt) = return_me_add_find_Constants;
Walther@60728
   589
(*/########################## before destroying elementwise input of lists ##################\* )
Walther@60578
   590
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Find "AdditionalValues [u]" = nxt;
Walther@60578
   591
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Find "AdditionalValues [v]" = nxt;
Walther@60728
   592
( *\########################## before destroying elementwise input of lists ##################/*)
Walther@60728
   593
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Find "AdditionalValues [u, v]" = nxt;
Walther@60728
   594
Walther@60578
   595
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Relation "Extremum (A = 2 * u * v - u \<up> 2)" = nxt;
Walther@60578
   596
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@60705
   597
val return_me_Add_Relation_SideConditions
Walther@60705
   598
                     = me nxt p c pt;
Walther@60728
   599
(*+*)val (_, _, _, Specify_Theory "Diff_App", _, _) = return_me_Add_Relation_SideConditions; (*###############*)
Walther@60705
   600
(*/------------------- step into me Add_Relation_SideConditions ----------------------------\\*)
Walther@60705
   601
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60728
   602
      val ctxt = Ctree.get_ctxt pt p;
Walther@60728
   603
(**)  val (pt, p) = (**) 
Walther@60728
   604
  	    (**)case(**) Step.by_tactic tac (pt, p) (**)of(**)
Walther@60728
   605
(**) 		    ("ok", (_, _, ptp)) => ptp (**) ;
Walther@60728
   606
Walther@60728
   607
   (*case*)
Walther@60705
   608
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60705
   609
(*//------------------ step into do_next ---------------------------------------------------\\*)
Walther@60705
   610
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
Walther@60705
   611
  = (p, ((pt, Pos.e_pos'), [])) (*of*);
Walther@60705
   612
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60705
   613
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60705
   614
      (*case*) tacis (*of*);
Walther@60705
   615
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60705
   616
Walther@60705
   617
      Step.switch_specify_solve p_ (pt, ip);
Walther@60705
   618
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60705
   619
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60705
   620
      Step.specify_do_next (pt, input_pos);
Walther@60705
   621
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = (pt, input_pos);
Walther@60728
   622
(*isa------ERROR: Refine_Problem INSTEAD 
Walther@60728
   623
            isa2: Specify_Theory "Diff_App"*)
Walther@60728
   624
    val (_, (p_', tac as Specify_Theory "Diff_App")) =
Walther@60728
   625
(*ERROR------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
Walther@60728
   626
   Specify.find_next_step ptp;
Walther@60705
   627
"~~~~~ fun find_next_step , args:"; val (pt, pos as (_, p_)) = (ptp);
Walther@60705
   628
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60705
   629
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60705
   630
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60705
   631
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
Walther@60705
   632
        (*if*) p_ = Pos.Pbl (*then*);
Walther@60705
   633
Walther@60728
   634
val ("dummy", (Pbl, tac as Specify_Theory "Diff_App")) =
Walther@60728
   635
(*ERROR------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
Walther@60728
   636
          for_problem ctxt oris (o_refs, refs) (pbl, met);
Walther@60705
   637
"~~~~~ fun for_problem , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (pbl, met)) =
Walther@60705
   638
  (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60705
   639
    val cpI = if pI = Problem.id_empty then pI' else pI;
Walther@60705
   640
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60705
   641
    val {model = pbt, where_rls, where_, ...} = Problem.from_store ctxt cpI;
Walther@60705
   642
    val {model = mpc, ...} = MethodC.from_store ctxt cmI
Walther@60705
   643
Walther@60705
   644
(*+*)val [Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60705
   645
  Free ("fixes", _)] = where_
Walther@60728
   646
Walther@60728
   647
    val (preok, _) =
Walther@60741
   648
 Pre_Conds.check ctxt where_rls where_ (pbt, I_Model.OLD_to_TEST pbl);
Walther@60741
   649
(*///----------------- step into check -------------------------------------------------\\*)
Walther@60741
   650
"~~~~~ fun check , args:"; val (ctxt, where_rls, pres, (model_patt, i_model)) =
Walther@60728
   651
  (ctxt, where_rls, where_, (pbt, I_Model.OLD_to_TEST pbl));
Walther@60728
   652
(*+*)val "[0 < fixes]" = pres |> UnparseC.terms @{context}
Walther@60728
   653
(*+*)val "[\"(#Given, (Constants, fixes))\", \"(#Find, (Maximum, maxx))\", \"(#Find, (AdditionalValues, vals))\", \"(#Relate, (Extremum, extr))\", \"(#Relate, (SideConditions, sideconds))\"]"
Walther@60728
   654
(*+*)  = model_patt |> Model_Pattern.to_string @{context}
Walther@60733
   655
(*+*)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@60733
   656
 = i_model |> I_Model.to_string_TEST @{context}
Walther@60728
   657
Walther@60728
   658
val return_of_max_variant as (_, _, (env_subst, env_eval)) =
Walther@60728
   659
           of_max_variant model_patt i_model
Walther@60728
   660
Walther@60728
   661
(*+*)val [(Free ("fixes", T1), Free ("r", T2))] = env_subst (*?!? Const*)
Walther@60728
   662
(*+*)val Type ("Real.real", []) = T1
Walther@60728
   663
(*+*)val Type ("Real.real", []) = T2
Walther@60728
   664
Walther@60728
   665
(*+*)val [(Free ("r", T2), Const ("Num.numeral_class.numeral", _) $ _)] = env_eval
Walther@60728
   666
(*+*)val Type ("Real.real", []) = T2
Walther@60728
   667
Walther@60728
   668
val (_, _, (env_subst, env_eval)) = return_of_max_variant;
Walther@60741
   669
(*|||----------------- contine check -----------------------------------------------------*)
Walther@60728
   670
      val pres_subst = map (TermC.subst_atomic_all env_subst) pres;
Walther@60728
   671
Walther@60741
   672
(*|||----------------- contine check -----------------------------------------------------*)
Walther@60728
   673
(*+*)val [(true, Const ("Orderings.ord_class.less", _) $
Walther@60728
   674
  Const ("Groups.zero_class.zero", _) $ Free ("r", _))] = pres_subst
Walther@60728
   675
Walther@60728
   676
      val full_subst = map (fn (bool, t) => (bool, subst_atomic env_eval t)) pres_subst
Walther@60728
   677
(*+*)val [(true,
Walther@60728
   678
     Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60728
   679
       (Const ("Num.numeral_class.numeral", _) $ _))] = full_subst
Walther@60728
   680
Walther@60728
   681
      val evals = map (eval ctxt where_rls) full_subst
Walther@60728
   682
val return_check_OLD = (foldl and_ (true, map fst evals), pres_subst)
Walther@60741
   683
(*\\\----------------- step into check -------------------------------------------------\\*)
Walther@60728
   684
Walther@60728
   685
    val (preok as true, _) = return_check_OLD
Walther@60728
   686
(*+---------------^^^^*)
Walther@60728
   687
(*\\------------------ step into do_next ---------------------------------------------------\\*)
Walther@60728
   688
(*\------------------- step into me_Add_Relation_SideConditions ----------------------------//*)
Walther@60705
   689
val (p, _, f, nxt, _, pt) = return_me_Add_Relation_SideConditions
Walther@60705
   690
                                      val Specify_Theory "Diff_App" = nxt;
Walther@60705
   691
Walther@60659
   692
val return_me_Specify_Theory
Walther@60659
   693
                     = me nxt p c pt; val Specify_Problem ["univariate_calculus", "Optimisation"] = #4 return_me_Specify_Theory;
Walther@60659
   694
(*/------------------- step into me Specify_Theory -----------------------------------------\\*)
Walther@60578
   695
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60728
   696
      val ctxt = Ctree.get_ctxt pt p;
Walther@60728
   697
(*      val (pt, p) = *)
Walther@60728
   698
  	    (*case*) Step.by_tactic tac (pt, p) (*of*);
Walther@60728
   699
(*		    ("ok", (_, _, ptp)) => ptp *)
Walther@60728
   700
val return_Step_by_tactic =
Walther@60728
   701
      Step.by_tactic tac (pt, p);
Walther@60728
   702
(*//------------------ step into Step_by_tactic --------------------------------------------\\*)
Walther@60728
   703
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60741
   704
    (*case*) Specify_Step.check tac (pt, p) (*of*);
Walther@60728
   705
Walther@60728
   706
(*||------------------ contine Step_by_tactic ------------------------------------------------*)
Walther@60728
   707
(*\\------------------ step into Step_by_tactic --------------------------------------------//*)
Walther@60728
   708
Walther@60728
   709
val ("ok", (_, _, ptp)) = return_Step_by_tactic;
Walther@60728
   710
(*|------------------- continue me Specify_Theory --------------------------------------------*)
Walther@60578
   711
Walther@60578
   712
val ("ok", (ts as (_, _, _) :: _, _, _)) =
Walther@60578
   713
    (*case*)
Walther@60578
   714
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60578
   715
(*//------------------ step into do_next ---------------------------------------------------\\*)
Walther@60578
   716
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
Walther@60578
   717
  = (p, ((pt, Pos.e_pos'), [])) (*of*);
Walther@60578
   718
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60578
   719
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60578
   720
val _ =
Walther@60578
   721
      (*case*) tacis (*of*);
Walther@60578
   722
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60578
   723
Walther@60578
   724
      Step.switch_specify_solve p_ (pt, ip);
Walther@60578
   725
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   726
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   727
Walther@60578
   728
      Step.specify_do_next (pt, input_pos);
Walther@60578
   729
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = (pt, input_pos);
Walther@60578
   730
    val (_, (p_', tac)) = Specify.find_next_step ptp
Walther@60578
   731
    val ist_ctxt =  Ctree.get_loc pt (p, p_);
Walther@60578
   732
    (*case*) tac (*of*);
Walther@60578
   733
Walther@60728
   734
Step_Specify.by_tactic_input tac (pt, (p, p_'));
Walther@60728
   735
(*+*)val Specify_Theory "Diff_App" = tac;
Walther@60728
   736
"~~~~~ fun by_tactic_input , args:"; val ((Tactic.Specify_Theory dI), (pt, pos as (_, Pbl)))
Walther@60578
   737
  = (tac, (pt, (p, p_')));
Walther@60578
   738
      val (oris, dI, dI', pI', probl, ctxt) = case get_obj I pt p of
Walther@60578
   739
        PblObj {origin = (oris, (dI,_,_),_), spec = (dI',pI',_), probl, ctxt, ...} =>
Walther@60578
   740
          (oris, dI, dI', pI', probl, ctxt)
Walther@60676
   741
	    val thy = ThyC.get_theory ctxt (if dI' = ThyC.id_empty then dI else dI');
Walther@60585
   742
      val {model, where_, where_rls,...} = Problem.from_store (Ctree.get_ctxt pt pos) pI
Walther@60659
   743
(*\\------------------ step into do_next ---------------------------------------------------//*)
Walther@60659
   744
(*\------------------- step into me Specify_Theory -----------------------------------------//*)
Walther@60659
   745
val (p,_,f,nxt,_,pt) = return_me_Specify_Theory;
Walther@60578
   746
Walther@60659
   747
val return_me_Specify_Problem (* keep for continuing me *)
Walther@60659
   748
                     = me nxt p c pt; val Specify_Method ["Optimisation", "by_univariate_calculus"] = #4 return_me_Specify_Problem;
Walther@60659
   749
(*/------------------- step into me Specify_Problem ----------------------------------------\\*)
Walther@60659
   750
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60578
   751
      val ctxt = Ctree.get_ctxt pt p
Walther@60578
   752
Walther@60659
   753
(** )  val ("ok", (_, _, ptp as (pt, p))) =( **)
Walther@60659
   754
(**)    val return_by_tactic =(**) (*case*)
Walther@60578
   755
      Step.by_tactic tac (pt, p) (*of*);
Walther@60659
   756
(*//------------------ step into by_tactic -------------------------------------------------\\*)
Walther@60578
   757
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60578
   758
Walther@60578
   759
    (*case*)
Walther@60578
   760
      Step.check tac (pt, p) (*of*);
Walther@60578
   761
"~~~~~ fun check , args:"; val (tac, (ctree, pos)) = (tac, (pt, p));
Walther@60578
   762
  (*if*) Tactic.for_specify tac (*then*);
Walther@60578
   763
Walther@60578
   764
Specify_Step.check tac (ctree, pos);
Walther@60578
   765
"~~~~~ fun check , args:"; val ((Tactic.Specify_Problem pID), (pt, pos as (p, _)))
Walther@60578
   766
  = (tac, (ctree, pos));
Walther@60578
   767
		    val (oris, dI, pI, dI', pI', itms) = case Ctree.get_obj I pt p of
Walther@60578
   768
		      Ctree.PblObj {origin = (oris, (dI, pI, _), _), spec = (dI', pI', _), probl = itms, ...}
Walther@60578
   769
		        => (oris, dI, pI, dI', pI', itms)
Walther@60676
   770
	      val thy = ThyC.get_theory ctxt (if dI' = ThyC.id_empty then dI else dI');
Walther@60659
   771
(*\\------------------ step into by_tactic -------------------------------------------------//*)
Walther@60659
   772
val ("ok", (_, _, ptp as (pt, p))) = return_by_tactic (* kept for continuing me *);
Walther@60578
   773
Walther@60578
   774
      (*case*)
Walther@60578
   775
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60578
   776
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) = (p, ((pt, Pos.e_pos'), []));
Walther@60578
   777
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60578
   778
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60578
   779
val _ =
Walther@60578
   780
      (*case*) tacis (*of*);
Walther@60578
   781
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60578
   782
Walther@60578
   783
      Step.switch_specify_solve p_ (pt, ip);
Walther@60578
   784
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   785
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   786
Walther@60578
   787
      Step.specify_do_next (pt, input_pos);
Walther@60578
   788
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = ((pt, input_pos));
Walther@60578
   789
    val (_, (p_', tac)) = Specify.find_next_step ptp
Walther@60578
   790
    val ist_ctxt =  Ctree.get_loc pt (p, p_)
Walther@60578
   791
val _ =
Walther@60578
   792
    (*case*) tac (*of*);
Walther@60578
   793
Walther@60578
   794
Step_Specify.by_tactic_input tac (pt, (p, p_'));
Walther@60578
   795
"~~~~~ fun by_tactic_input , args:"; val ((Tactic.Specify_Method id), (pt, pos))
Walther@60578
   796
  = (tac, (pt, (p, p_')));
Walther@60578
   797
Walther@60578
   798
      val (o_model, ctxt, i_model) =
Walther@60578
   799
Specify_Step.complete_for id (pt, pos);
Walther@60578
   800
"~~~~~ fun complete_for , args:"; val (mID, (ctree, pos)) = (id, (pt, pos));
Walther@60578
   801
    val {origin = (o_model, o_refs, _), spec = refs, probl = i_prob, ctxt,
Walther@60578
   802
       ...} = Calc.specify_data (ctree, pos);
Walther@60578
   803
    val ctxt = Ctree.get_ctxt ctree pos
Walther@60578
   804
    val (dI, _, _) = References.select_input o_refs refs;
Walther@60586
   805
    val {model = m_patt, where_, where_rls, ...} = MethodC.from_store ctxt mID
Walther@60578
   806
    val {origin = (root_model, _, _), ...} = Calc.specify_data (ctree, ([], Pos.Und))
Walther@60578
   807
    val (o_model', ctxt') = O_Model.complete_for m_patt root_model (o_model, ctxt)
Walther@60676
   808
    val thy = ThyC.get_theory ctxt dI
Walther@60590
   809
    val (_, (i_model, _)) = M_Match.match_itms_oris ctxt i_prob (m_patt, where_, where_rls) o_model';
Walther@60659
   810
(*\------------------- step into me Specify_Problem ----------------------------------------//*)
Walther@60659
   811
val (p,_,f,nxt,_,pt) = return_me_Specify_Problem
Walther@60578
   812
Walther@60659
   813
val return_me_Add_Given_FunctionVariable
Walther@60659
   814
                     = me nxt p c pt; val Add_Given "FunctionVariable a" = #4 return_me_Add_Given_FunctionVariable;
Walther@60659
   815
(*/------------------- step into me Specify_Method -----------------------------------------\\*)
Walther@60659
   816
"~~~~~ fun me , args:"; val (tac, p, _, pt) = (nxt, p, c, pt);
Walther@60578
   817
      val ctxt = Ctree.get_ctxt pt p
Walther@60578
   818
      val (pt, p) = 
Walther@60578
   819
  	    (*Step.by_tactic is here for testing by me; do_next would suffice in me*)
Walther@60578
   820
  	    case Step.by_tactic tac (pt, p) of
Walther@60578
   821
  		    ("ok", (_, _, ptp)) => ptp;
Walther@60578
   822
Walther@60578
   823
         (*case*)
Walther@60578
   824
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60578
   825
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis)) = (p, ((pt, Pos.e_pos'), []));
Walther@60578
   826
  (*if*) Pos.on_calc_end ip (*else*);
Walther@60578
   827
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60578
   828
val _ =
Walther@60578
   829
      (*case*) tacis (*of*);
Walther@60578
   830
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60578
   831
Walther@60578
   832
      Step.switch_specify_solve p_ (pt, ip);
Walther@60578
   833
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60578
   834
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60578
   835
Walther@60578
   836
      Step.specify_do_next (pt, input_pos);
Walther@60578
   837
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = (pt, input_pos);
Walther@60578
   838
Walther@60578
   839
    val (_, (p_', tac)) =
Walther@60578
   840
   Specify.find_next_step ptp;
Walther@60578
   841
"~~~~~ fun find_next_step , args:"; val ((pt, pos as (_, p_))) = (ptp);
Walther@60578
   842
    val {meth = met, origin = origin as (oris, o_refs as (_, pI', mI'), _), probl = pbl,
Walther@60578
   843
      spec = refs, ...} = Calc.specify_data (pt, pos);
Walther@60578
   844
    val ctxt = Ctree.get_ctxt pt pos;
Walther@60578
   845
      (*if*) Ctree.just_created (pt, pos) andalso origin <> Ctree.e_origin (*else*);
Walther@60578
   846
        (*if*) p_ = Pos.Pbl (*else*);
Walther@60578
   847
Walther@60578
   848
   Specify.for_method ctxt oris (o_refs, refs) (pbl, met);
Walther@60730
   849
"~~~~~ fun for_method , args:"; val (ctxt, oris, ((dI', pI', mI'), (dI, pI, mI)), (_, met))
Walther@60578
   850
  = (ctxt, oris, (o_refs, refs), (pbl, met));
Walther@60578
   851
    val cmI = if mI = MethodC.id_empty then mI' else mI;
Walther@60730
   852
    val {model, where_rls, where_, ...} = MethodC.from_store ctxt cmI;    (*..MethodC ?*)
Walther@60741
   853
    val (preok, _) = Pre_Conds.check ctxt where_rls where_ (model, I_Model.OLD_to_TEST met);
Walther@60578
   854
val NONE =
Walther@60578
   855
    (*case*) find_first (I_Model.is_error o #5) met (*of*);
Walther@60578
   856
Walther@60578
   857
      (*case*)
Walther@60676
   858
   Specify.item_to_add (ThyC.get_theory ctxt 
Walther@60578
   859
     (if dI = ThyC.id_empty then dI' else dI)) oris mpc met (*of*);
Walther@60578
   860
"~~~~~ fun item_to_add , args:"; val (thy, oris, _, itms)
Walther@60676
   861
  = ((ThyC.get_theory ctxt (if dI = ThyC.id_empty then dI' else dI)), oris, mpc, met);
Walther@60659
   862
(*\------------------- step into me Specify_Method -----------------------------------------//*)
Walther@60659
   863
val (p,_,f,nxt,_,pt) = return_me_Add_Given_FunctionVariable
Walther@60578
   864
Walther@60659
   865
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Given "Input_Descript.Domain {0<..<r}" = nxt;
Walther@60578
   866
val (p,_,f,nxt,_,pt) = me nxt p c pt; val Add_Given "ErrorBound (\<epsilon> = 0)" = nxt;
Walther@60728
   867
Walther@60728
   868
(* ------------------- step into UNTIL A PROGRAM IS REQUIRED (not yet impl. ---------------- )*)
Walther@60728
   869
(*/------------------- step into me_Add_Given_ErrorBound------------------------------------\\*)
Walther@60728
   870
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt, p, c, pt);
Walther@60728
   871
      val ctxt = Ctree.get_ctxt pt p
Walther@60728
   872
      val (pt, p) = 
Walther@60728
   873
  	    (*Step.by_tactic is here for testing by me; do_next would suffice in me*)
Walther@60728
   874
  	    case Step.by_tactic tac (pt, p) of
Walther@60728
   875
  		    ("ok", (_, _, ptp)) => ptp;
Walther@60728
   876
(*ERROR due to missing program in creating the environment from formal args* )
Walther@60728
   877
      (*case*)
Walther@60728
   878
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
Walther@60728
   879
( *ERROR*)
Walther@60728
   880
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis) ) =
Walther@60728
   881
  (p, ((pt, Pos.e_pos'), []));
Walther@60728
   882
  (*if*) Pos.on_calc_end ip (*else*); 
Walther@60728
   883
      val (_, probl_id, _) = Calc.references (pt, p);
Walther@60728
   884
val _ =
Walther@60728
   885
      (*case*) tacis (*of*);
Walther@60728
   886
        (*if*) probl_id = Problem.id_empty (*else*);
Walther@60728
   887
Walther@60728
   888
(*ERROR due to missing program in creating the environment from formal args* )
Walther@60728
   889
           switch_specify_solve p_ (pt, ip);
Walther@60728
   890
( *ERROR*)
Walther@60728
   891
"~~~~~ fun switch_specify_solve , args:"; val (state_pos, (pt, input_pos)) = (p_, (pt, ip));
Walther@60728
   892
      (*if*) Pos.on_specification ([], state_pos) (*then*);
Walther@60728
   893
Walther@60728
   894
(*ERROR due to missing program in creating the environment from formal args* )
Walther@60728
   895
           specify_do_next (pt, input_pos)
Walther@60728
   896
( *ERROR*)
Walther@60728
   897
"~~~~~ fun specify_do_next , args:"; val ((ptp as (pt, (p, p_)))) = ((pt, input_pos));
Walther@60728
   898
    val (_, (p_', tac as Apply_Method ["Optimisation", "by_univariate_calculus"])) =
Walther@60728
   899
    (*-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not yet impl.*)
Walther@60728
   900
      Specify.find_next_step ptp
Walther@60728
   901
    val ist_ctxt =  Ctree.get_loc pt (p, p_)
Walther@60728
   902
Walther@60728
   903
val Tactic.Apply_Method (mI as ["Optimisation", "by_univariate_calculus"]) =
Walther@60728
   904
        (*case*) tac (*of*);
Walther@60728
   905
(*ERROR due to missing program in creating the environment from formal args* )
Walther@60728
   906
  	    LI.by_tactic (Tactic.Apply_Method' (mI, NONE, Istate.empty, ContextC.empty))
Walther@60728
   907
  	      ist_ctxt (pt, (p, p_'))
Walther@60728
   908
( *ERROR*)
Walther@60728
   909
"~~~~~ fun by_tactic , args:"; val ((Tactic.Apply_Method' (mI, _, _, _)), (_, ctxt), (pt, pos as (p, _))) =
Walther@60728
   910
  ((Tactic.Apply_Method' (mI, NONE, Istate.empty, ContextC.empty)), ist_ctxt, (pt, (p, p_')));
Walther@60728
   911
      val (itms, oris, probl) = case get_obj I pt p of
Walther@60728
   912
          PblObj {meth = itms, origin = (oris, _, _), probl, ...} => (itms, oris, probl)
Walther@60728
   913
      val {model, ...} = MethodC.from_store ctxt mI;
Walther@60728
   914
      (*if*) itms <> [] (*then*);
Walther@60728
   915
      val itms = I_Model.complete oris probl [] model
Walther@60728
   916
Walther@60739
   917
(*+*)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] ,true ,#Given ,Cor FunctionVariable a , pen2str), \n(10 ,[1, 2] ,true ,#Given ,Cor Input_Descript.Domain {0<..<r} , pen2str), \n(12 ,[1, 2, 3] ,true ,#Given ,Cor ErrorBound (\<epsilon> = 0) , pen2str)]"
Walther@60728
   918
 = itms |> I_Model.to_string @{context}
Walther@60728
   919
(*+*)val 8 = length itms
Walther@60728
   920
(*+*)val 8 = length model
Walther@60728
   921
(*\------------------- step into me_Add_Given_ErrorBound------------------------------------//*)
Walther@60728
   922