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