test/Tools/isac/Specify/i-model.sml
author wneuper <Walther.Neuper@jku.at>
Tue, 20 Jun 2023 06:26:18 +0200
changeset 60714 94242a19b04c
parent 60710 21ae85b023bb
child 60716 a6a9dd158e69
permissions -rw-r--r--
prepare 4: narrow I_Model.T -- _TEST
walther@59957
     1
(* Title:  "Specify/i-model.sml"
walther@59957
     2
   Author: Walther Neuper
walther@59957
     3
   (c) due to copyright terms
walther@59957
     4
*)
walther@59957
     5
walther@59957
     6
"-----------------------------------------------------------------------------------------------";
walther@59957
     7
"table of contents -----------------------------------------------------------------------------";
walther@59957
     8
"-----------------------------------------------------------------------------------------------";
walther@59957
     9
"----------- investigate fun add_single in I_Model ---------------------------------------------";
Walther@60690
    10
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60705
    11
"----------- exercise preparing I_Model.is_complete --------------------------------------------";
Walther@60705
    12
"----------- build I_Model.is_complete_OLD -----------------------------------------------------";
walther@59957
    13
"-----------------------------------------------------------------------------------------------";
walther@59957
    14
"-----------------------------------------------------------------------------------------------";
walther@59957
    15
"-----------------------------------------------------------------------------------------------";
walther@59957
    16
walther@59957
    17
open I_Model;
Walther@60705
    18
open Test_Code;
Walther@60705
    19
open Tactic;
Walther@60705
    20
open Pos;
walther@59957
    21
"----------- investigate fun add_single in I_Model -------------------------------------------";
walther@59957
    22
"----------- investigate fun add_single in I_Model -------------------------------------------";
walther@59957
    23
"----------- investigate fun add_single in I_Model -------------------------------------------";
walther@59997
    24
val f_model = ["Traegerlaenge L", "Streckenlast q_0", "Biegelinie y",
walther@59957
    25
	"Randbedingungen [y 0 = (0::real), y L = 0, M_b 0 = 0, M_b L = 0]",
walther@59957
    26
	"FunktionsVariable x", "GleichungsVariablen [c, c_2, c_3, c_4]",
walther@59957
    27
  "AbleitungBiegelinie dy"];
walther@59957
    28
val f_spec = ("Biegelinie", ["Biegelinien"], ["IntegrierenUndKonstanteBestimmen2"]);
Walther@60571
    29
(*[], Pbl*)val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context} [(f_model, f_spec)]; (*\<rightarrow>Model_Problem*)
walther@59957
    30
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*\<rightarrow>Add_Given "Traegerlaenge L"*)
walther@59957
    31
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "Streckenlast q_0"*)
walther@59957
    32
Walther@60676
    33
(*[], Pbl*)val return_me_Add_Given =
Walther@60676
    34
           me nxt p [] pt; (*\<rightarrow>Add_Find "Biegelinie y"*)
Walther@60676
    35
(*/------------------- step into me Add_Given ----------------------------------------------\\*)
walther@59957
    36
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt, p, [], pt);
walther@59957
    37
Walther@60676
    38
val ("ok", (_, _, ptp)) = (*case*)
walther@59957
    39
      Step.by_tactic tac (pt, p) (*of*);
walther@59957
    40
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60676
    41
walther@59957
    42
  val Applicable.Yes tac' = (*case*)
walther@59957
    43
      Step.check tac (pt, p) (*of*);
walther@59957
    44
	    (*if*) Tactic.for_specify' tac' (*then*);
walther@59957
    45
walther@59957
    46
Step_Specify.by_tactic tac' ptp;
walther@59957
    47
"~~~~~ fun by_tactic , args:"; val ((Tactic.Add_Given' (ct, _)), (pt, p)) = (tac', ptp);
walther@59957
    48
Walther@60676
    49
val ("ok", ([(Add_Given "Streckenlast q_0", _, _)], [], _)) = (*case*)
walther@60016
    50
   Specify.by_Add_ "#Given" ct (pt, p);
Walther@60676
    51
"~~~~~ fun by_Add_ , args:"; val (m_field, ct, (pt, pos as (_, p_))) =
walther@59957
    52
  ("#Given", ct, (pt, p));
Walther@60676
    53
    val (met, oris, (_, pI', mI'), pbl, (_, pI, mI), ctxt) = SpecificationC.get_data (pt, pos)
Walther@60676
    54
    val (i_model, m_patt) =
Walther@60676
    55
       if p_ = Pos.Met then
Walther@60676
    56
         (met,
Walther@60676
    57
           (if mI = MethodC.id_empty then mI' else mI) |> MethodC.from_store ctxt |> #model)
Walther@60676
    58
       else
Walther@60676
    59
         (pbl,
Walther@60676
    60
           (if pI = Problem.id_empty then pI' else pI) |> Problem.from_store ctxt |> #model)
Walther@60676
    61
;
Walther@60655
    62
(*+*)if O_Model.to_string @{context} oris = "[\n" ^
walther@59997
    63
  "(1, [\"1\"], #Given, Traegerlaenge, [\"L\"]), \n" ^
walther@59997
    64
  "(2, [\"1\"], #Given, Streckenlast, [\"q_0\"]), \n" ^
walther@59997
    65
  "(3, [\"1\"], #Find, Biegelinie, [\"y\"]), \n" ^
walther@59997
    66
  "(4, [\"1\"], #Relate, Randbedingungen, [\"[y 0 = 0]\", \"[y L = 0]\", \"[M_b 0 = 0]\", \"[M_b L = 0]\"]), \n" ^
walther@59997
    67
  "(5, [\"1\"], #undef, FunktionsVariable, [\"x\"]), \n" ^
walther@59997
    68
  "(6, [\"1\"], #undef, GleichungsVariablen, [\"[c]\", \"[c_2]\", \"[c_3]\", \"[c_4]\"]), \n" ^
walther@59997
    69
  "(7, [\"1\"], #undef, AbleitungBiegelinie, [\"dy\"])]"
walther@59957
    70
(*+*)then () else error "INITIAL O_Model CHANGED";
walther@59957
    71
(*+*)if I_Model.to_string ctxt pbl = "[\n" ^
walther@59997
    72
  "(0 ,[] ,false ,#Given ,Inc Streckenlast ,(??.empty, [])), \n" ^
walther@59997
    73
  "(0 ,[] ,false ,#Find ,Inc Biegelinie ,(??.empty, [])), \n" ^
walther@59997
    74
  "(0 ,[] ,false ,#Relate ,Inc Randbedingungen [] ,(??.empty, [])), \n" ^
walther@59957
    75
  "(1 ,[1] ,true ,#Given ,Cor Traegerlaenge L ,(l_l, [L]))]"
walther@59957
    76
(*+*)then () else error "INITIAL I_Model CHANGED";
walther@59957
    77
Walther@60676
    78
val return_check_single = (*case*)
Walther@60676
    79
   I_Model.check_single ctxt m_field oris i_model m_patt ct (*of*);
Walther@60676
    80
(*//------------------ step into check_single ----------------------------------------------\\*)
Walther@60676
    81
"~~~~~ fun check_single , args <>[]:"; val (ctxt, m_field, o_model, i_model, m_patt, str)
Walther@60676
    82
  = (ctxt, m_field, oris, i_model, m_patt, ct);
Walther@60676
    83
      val (t as (descriptor $ _)) = Syntax.read_term ctxt str
Walther@60676
    84
        handle ERROR msg => error (msg (*^ Position.here pp*))
Walther@60676
    85
val SOME m_field' =
Walther@60676
    86
        (*case*) Model_Pattern.get_field descriptor m_patt (*of*);
Walther@60676
    87
          (*if*) m_field <> m_field' (*else*);
Walther@60676
    88
walther@59957
    89
(**)val ("", ori', all) =(**)
Walther@60469
    90
          (*case*) O_Model.contains ctxt m_field o_model t (*of*);
walther@59957
    91
Walther@60655
    92
(*+*)O_Model.single_to_string @{context} ori';
walther@59957
    93
(*+*)val [Free ("q_0", _)] = all;
walther@59957
    94
walther@59957
    95
(**)val ("", itm) =(**)
walther@59957
    96
 (*case*) is_notyet_input ctxt i_model all ori' m_patt (*of*);
walther@59957
    97
Walther@60676
    98
(*+*)val (2, [1], true, "#Given", Cor ((Const (\<^const_name>\<open>Streckenlast\<close>, _), [Free ("q_0", _)]), (Free ("q_q", _), [Free ("q_0", _)]))) = itm
Walther@60676
    99
(*\\------------------ step into check_single ----------------------------------------------//*)
Walther@60676
   100
val return_check_single = Add itm;
walther@59957
   101
Walther@60676
   102
"~~~~~ from fun check_single \<longrightarrow>fun by_Add_ , return:"; val (I_Model.Add i_single) = (return_check_single);
Walther@60676
   103
	          val i_model' = I_Model.add_single (Proof_Context.theory_of ctxt) i_single i_model
Walther@60676
   104
            val tac' = I_Model.make_tactic m_field (ct, i_model')
Walther@60676
   105
;
Walther@60676
   106
(*+*)if I_Model.to_string ctxt i_model' = "[\n" ^
walther@59997
   107
  "(0 ,[] ,false ,#Find ,Inc Biegelinie ,(??.empty, [])), \n" ^
walther@59997
   108
  "(0 ,[] ,false ,#Relate ,Inc Randbedingungen [] ,(??.empty, [])), \n" ^
walther@59997
   109
  "(1 ,[1] ,true ,#Given ,Cor Traegerlaenge L ,(l_l, [L])), \n" ^
walther@59957
   110
  "(2 ,[1] ,true ,#Given ,Cor Streckenlast q_0 ,(q_q, [q_0]))]"
walther@59957
   111
(*+*)then () else error "FINAL I_Model CHANGED";
walther@59957
   112
Walther@60676
   113
	          val  (_, _, _, pt') =  Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59957
   114
Walther@60676
   115
val return_by_Add_ = ("ok", ([(Tactic.input_from_T ctxt tac', tac', (pos, (Istate_Def.Uistate, ctxt)))],
Walther@60676
   116
              [], (pt', pos)));
Walther@60676
   117
(*-------------------- stop into me Add_Given ------------------------------------------------*)
Walther@60676
   118
(*\------------------- step into me Add_Given ----------------------------------------------//*)
Walther@60676
   119
                                val (p,_,f,nxt,_,pt) = return_me_Add_Given
walther@59957
   120
Walther@60676
   121
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*\<rightarrow>Add_Relation "Randbedingungen [y 0 = 0]"*)
walther@59957
   122
walther@59957
   123
(* final test ...*)
walther@59957
   124
if p = ([], Pbl) then
walther@59957
   125
  case nxt of Add_Relation "Randbedingungen [y 0 = 0]" => () | _ => error "investigate fun add_single CHANGED 1"
walther@59957
   126
else error "investigate fun add_single CHANGED 2"
Walther@60690
   127
Walther@60690
   128
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60690
   129
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60690
   130
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60690
   131
(*/---------------------------------------- mimic input from PIDE -----------------------------\*)
Walther@60690
   132
Walther@60690
   133
(* Test_Example "Diff_App-No.123a" (*complete Model, empty References*) *)
Walther@60690
   134
val in_refs as (thy_id, probl_id, meth_id) = ("__", "__/__", "__/__")
Walther@60690
   135
val thy = @{theory}
Walther@60690
   136
val model_input = (*type Position.T is hidden, thus redefinition*)
Walther@60690
   137
 [("#Given", [("Constants [r = 7]", Position.none)]),
Walther@60690
   138
  ("#Where", [("0 < r", Position.none)]),
Walther@60690
   139
  ("#Find",
Walther@60690
   140
   [("Maximum A", Position.none), ("AdditionalValues [u, v]", Position.none)]),
Walther@60690
   141
  ("#Relate",
Walther@60690
   142
   [("Extremum (A = 2 * u * v - u \<up> 2)", Position.none),
Walther@60690
   143
    ("SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]", Position.none)])]
Walther@60690
   144
: (Model_Pattern.m_field * (string * Position.T) list) list
Walther@60690
   145
val example_id = "Diff_App-No.123a";
Walther@60690
   146
(*----------------------------------------- init state -----------------------------------------*)
Walther@60704
   147
set_data CTbasic_TEST.EmptyPtree @{theory Calculation};
Walther@60690
   148
(*\---------------------------------------- mimic input from PIDE -----------------------------/*)
Walther@60690
   149
Walther@60704
   150
val CTbasic_TEST.EmptyPtree =
Walther@60694
   151
              (*case*) the_data @{theory Calculation} (*of*);
Walther@60690
   152
Walther@60690
   153
(* Calculation..*)
Walther@60704
   154
"~~~~~ fun init_ctree , args:"; val (thy, example_id) = (thy, example_id);
Walther@60690
   155
      val example_id' = References_Def.explode_id example_id
Walther@60690
   156
      val (_, (formalise as (model, refs as (thy_id, probl_id, meth_id)))) =
Walther@60690
   157
        Store.get (Know_Store.get_expls @{theory}) example_id' example_id' 
Walther@60690
   158
      val {model = model_patt, ...} = Problem.from_store (Proof_Context.init_global thy) probl_id
Walther@60690
   159
      val (o_model, ctxt) = O_Model.init thy model model_patt
Walther@60690
   160
;
Walther@60690
   161
(*+*)o_model: O_Model.T; (* |> O_Model.to_string @{context}*)
Walther@60690
   162
(*+*)val ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"]) =
Walther@60695
   163
(*+*)  refs       
Walther@60690
   164
Walther@60694
   165
      val empty_i_model =
Walther@60702
   166
   I_Model.init_TEST o_model model_patt;
Walther@60694
   167
"~~~~~ fun init_TEST , args:"; val (ctxt, model_patt) = (ctxt, model_patt);
Walther@60694
   168
;
Walther@60714
   169
(*+*)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@60714
   170
(*+*)  = I_Model.to_string_TEST @{context} empty_i_model;
Walther@60705
   171
Walther@60705
   172
Walther@60705
   173
"----------- exercise preparing I_Model.is_complete --------------------------------------------";
Walther@60705
   174
"----------- exercise preparing I_Model.is_complete --------------------------------------------";
Walther@60705
   175
"----------- exercise preparing I_Model.is_complete --------------------------------------------";
Walther@60705
   176
fun check str = if str = "true" then true else false
Walther@60705
   177
fun complete str = if str = "true" then true else false
Walther@60705
   178
Walther@60705
   179
val i_model_envs_v = [("i_model_envs-1", 11), ("i_model_envs-2", 12), ("i_model_envs-3", 13)]
Walther@60705
   180
Walther@60705
   181
val result_all_variants =
Walther@60705
   182
  map (fn (a, variant) => if check a andalso complete a then SOME [variant] else NONE) i_model_envs_v;
Walther@60705
   183
(*----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
Walther@60705
   184
;
Walther@60705
   185
val [NONE, NONE, NONE] = result_all_variants: int list option list
Walther@60705
   186
Walther@60705
   187
(*+*)val true = forall is_none result_all_variants
Walther@60705
   188
Walther@60705
   189
val variants_complete =
Walther@60705
   190
  if forall is_none result_all_variants
Walther@60705
   191
  then NONE
Walther@60705
   192
  else SOME (map (fn x => if is_some x then [the x] else []) result_all_variants |> flat |> flat)
Walther@60705
   193
;
Walther@60705
   194
val NONE = variants_complete: int list option
Walther@60705
   195
Walther@60705
   196
Walther@60705
   197
(*more significant result ..*)
Walther@60705
   198
val result_all_variants = [SOME [11], NONE, SOME [13]]: int list option list
Walther@60705
   199
(*
Walther@60705
   200
in case the result is null, no I_Model is_complete,
Walther@60705
   201
in case the result contains more than 1 variant, this might determine the decision for MethodC.
Walther@60705
   202
*)
Walther@60705
   203
val variants_complete =
Walther@60705
   204
  if forall is_none result_all_variants
Walther@60705
   205
  then NONE
Walther@60705
   206
  else SOME (map (fn x => if is_some x then [the x] else []) result_all_variants |> flat |> flat)
Walther@60705
   207
;
Walther@60705
   208
val SOME [11, 13] = variants_complete: int list option;
Walther@60705
   209
Walther@60714
   210
(*/----- reactivate with CS "remove sep_variants_envs"-----\* )
Walther@60705
   211
"----------- build I_Model.is_complete_OLD -----------------------------------------------------";
Walther@60705
   212
"----------- build I_Model.is_complete_OLD -----------------------------------------------------";
Walther@60705
   213
"----------- build I_Model.is_complete_OLD -----------------------------------------------------";
Walther@60705
   214
(*see Outer_Syntax:    val (model, where_) = Model_Pattern.parse_pos_empty ctxt model_input*)
Walther@60705
   215
open I_Model
Walther@60705
   216
open Pre_Conds;
Walther@60705
   217
(*//------------------ test data setup -----------------------------------------------------\\*)
Walther@60705
   218
(*
Walther@60705
   219
*****************************************************************************************
Walther@60705
   220
***** WE FIRST MAINTAIN THE ERROR, THAT ITEMS WITH TYPE list ARE STORED AS isalist, *****
Walther@60705
   221
***** NOT AS term list (NECESSARY TO DETECT INCOMPLETE INPUT OF lists)              *****
Walther@60705
   222
*****************************************************************************************
Walther@60705
   223
  The ERROR occurred somewhere since introducing structure or since transition to PIDE.
Walther@60705
   224
*****************************************************************************************
Walther@60705
   225
  We complete the two single_TEST "1" and "5" below and replace them in  empty_input;
Walther@60705
   226
  we add "6" as variant of "5" to the empty input.
Walther@60705
   227
  later we shall replace empty_input by partial input "AdditionalValues [v]" (u missing).
Walther@60705
   228
  The test intermediatly pairs (feedback_TEST, Position.T) in I_Model.T_TEST 
Walther@60705
   229
  and leaves the rest as is.
Walther@60705
   230
Walther@60705
   231
I_Model.is_complete_OLD: because PIDE gets instantiated Pre_Conds by Template.show,
Walther@60705
   232
  I_Model.is_complete_TEST NO instantiation (done in Template.show):
Walther@60705
   233
  it serves to maintain the OLD test/*
Walther@60705
   234
*)
Walther@60705
   235
val thy = @{theory Calculation}
Walther@60705
   236
Walther@60705
   237
            val state =
Walther@60705
   238
              case the_data thy of
Walther@60705
   239
                  CTbasic_TEST.EmptyPtree => Preliminary.init_ctree thy example_id
Walther@60705
   240
                | _(*state (*FOR TEST*)*) => (**)the_data thy(**)
Walther@60705
   241
                  (*let*)
Walther@60705
   242
                    val {origin = (o_model, o_ref, _), spec = spec_ref, probl, meth, ctxt, ...} =
Walther@60705
   243
                      CTbasic_TEST.get_obj I state [(*Pos will become variable*)] |> CTbasic_TEST.rep_specify_data
Walther@60705
   244
;
Walther@60705
   245
probl: Model_Def.i_model_TEST 
Walther@60705
   246
(*[(1, [1, 2, 3], false, "#Given", (Inp_TEST (Const ("Input_Descript.Constants", "bool list \<Rightarrow> nam"), "[__=__, __=__]"), {})),
Walther@60705
   247
   (2, [1, 2, 3], false, "#Find", (Inp_TEST (Const ("Input_Descript.Maximum", "real \<Rightarrow> toreal"), "__"), {})),
Walther@60705
   248
   (3, [1, 2, 3], false, "#Find", (Inp_TEST (Const ("Input_Descript.AdditionalValues", "real list \<Rightarrow> toreall"), "[__, __]"), {})),
Walther@60705
   249
   (4, [1, 2, 3], false, "#Relate", (Inp_TEST (Const ("Input_Descript.Extremum", "bool \<Rightarrow> toreal"), "__"), {})),
Walther@60705
   250
   (5, [1, 2], false, "#Relate", (Inp_TEST (Const ("Input_Descript.SideConditions", "bool list \<Rightarrow> una"), "[__=__, __=__]"), {}))]*)
Walther@60705
   251
;
Walther@60705
   252
val probl_POS = (*from above, #1 and #5,6 replaced by complete items for building code.test*)
Walther@60705
   253
  (1, [1,2,3], true, "#Given",
Walther@60705
   254
    (Cor_TEST ((@{term "Constants"}, [@{term "[r = (7::real)]"(*should be "r = (7::real)"*)}]),
Walther@60705
   255
      (@{term "fixes::bool list"}, [@{term "[r = (7::real)]"}])), Position.none )) ::
Walther@60705
   256
  nth 2 probl :: nth 3 probl :: nth 4 probl ::
Walther@60705
   257
  (5, [1,2], true, "#Relate",
Walther@60705
   258
    (Cor_TEST ((@{term "SideConditions"}, [@{term "[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]"}]),
Walther@60705
   259
      (@{term "sideconds::bool list"}, [TermC.empty])), Position.none )) ::
Walther@60705
   260
  (6, [3], true, "#Relate",
Walther@60705
   261
    (Cor_TEST ((@{term "SideConditions"}, [@{term "[2 * u = r * sin \<alpha>, 2 * v = r * cos \<alpha>]"}]),
Walther@60705
   262
      (@{term "sideconds::bool list"}, [TermC.empty])), Position.none ))
Walther@60705
   263
  :: [];
Walther@60705
   264
Walther@60705
   265
val {model = model_patt, where_rls, where_ = where_OLD, ...} = (*from_store without Position.T-vv*)
Walther@60705
   266
  Problem.from_store ctxt (References.explode_id "univariate_calculus/Optimisation")
Walther@60705
   267
;
Walther@60705
   268
val [Const ("Orderings.ord_class.less", _(*"real \<Rightarrow> real \<Rightarrow> bool"*)) $
Walther@60705
   269
  Const ("Groups.zero_class.zero", _(*"real"*)) $ Free ("fixes", _(*"real"*))] = where_OLD
Walther@60705
   270
(*design-ERROR: "fixes" is used twice, as variable ------^^^^^^^^^^^^^^^^^^^^^^^^^^^ in pre-condition
Walther@60705
   271
  AND as "id" in Subst.T [("fixes", [0 < x])] *);
Walther@60705
   272
(model_patt |> Model_Pattern.to_string ctxt) =
Walther@60705
   273
 "[\"(#Given, (Constants, fixes))\", " ^
Walther@60705
   274
  "\"(#Find, (Maximum, maxx))\", " ^
Walther@60705
   275
  "\"(#Find, (AdditionalValues, vals))\", " ^
Walther@60705
   276
  "\"(#Relate, (Extremum, extr))\", " ^
Walther@60705
   277
  "\"(#Relate, (SideConditions, sideconds))\"]";
Walther@60705
   278
val "[0 < fixes]" = (where_OLD |> UnparseC.terms @{context})
Walther@60705
   279
(*\\------------------ test data setup -----------------------------------------------------//*)
Walther@60705
   280
Walther@60705
   281
(*/------------------- test on OLD algorithm (with I_Model.T_TEST) --------------------------\*)
Walther@60705
   282
;
Walther@60705
   283
Walther@60705
   284
   I_Model.is_complete_OLD ctxt model_patt where_rls where_OLD probl_POS;
Walther@60705
   285
(*//------------------ step into is_complete_OLD -------------------------------------------\\*)
Walther@60705
   286
"~~~~~ fun is_complete_OLD , args:"; val (ctxt, model_patt, where_rls, pres, i_model) =
Walther@60705
   287
  (ctxt, model_patt, where_rls, where_OLD,
Walther@60705
   288
    (** )filter (fn (_, _, _, m_field, _) => m_field = "#Given")( **) probl_POS);
Walther@60705
   289
    (*for Pre_Conds.eval we only need ------------------^^^^^^^^, -UNCOMMENT EITHER HER OR THERE-*)
Walther@60705
   290
Walther@60705
   291
(*+*)val [Const ("Orderings.ord_class.less", _(*"real \<Rightarrow> real \<Rightarrow> bool"*)) $
Walther@60705
   292
  Const ("Groups.zero_class.zero", _(*"real"*)) $ Free ("fixes", xxx(*"real"*))] = pres;
Walther@60705
   293
(*+*) if I_Model.to_string_TEST @{context} i_model = "[\n" ^
Walther@60705
   294
  "(1, [1, 2, 3], true ,#Given, (Cor_TEST Constants [r = 7] ,(fixes, [[r = 7]]), Position.T)), \n" ^
Walther@60705
   295
  "(2, [1, 2, 3], false ,#Find, (Inp_TEST Maximum __, Position.T)), \n" ^
Walther@60705
   296
  "(3, [1, 2, 3], false ,#Find, (Inp_TEST AdditionalValues [__, __], Position.T)), \n" ^
Walther@60705
   297
  "(4, [1, 2, 3], false ,#Relate, (Inp_TEST Extremum __, Position.T)), \n" ^
Walther@60705
   298
  "(5, [1, 2], true ,#Relate, (Cor_TEST SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] ,(sideconds, [??.empty]), Position.T)), \n" ^
Walther@60705
   299
  "(6, [3], true ,#Relate, (Cor_TEST SideConditions\n [(2::'a) * u = r * sin \<alpha>, (2::'a) * v = r * cos \<alpha>] ,(sideconds, [??.empty]), Position.T))]"
Walther@60705
   300
  then () else raise error "I_Model.to_string_TEST i_model CHANGED";
Walther@60705
   301
Walther@60710
   302
    val no_model_items = length model_patt
Walther@60710
   303
(*+*)val 5 = no_model_items;
Walther@60705
   304
           sep_variants_envs model_patt i_model;
Walther@60710
   305
Walther@60705
   306
(*///----------------- step into sep_variants_envs ----------------------------------------\\\*)
Walther@60705
   307
(*+*)sep_variants_envs: Model_Pattern.T -> I_Model.T_TEST ->
Walther@60705
   308
    ((I_Model.T_TEST * Pre_Conds.env_subst * Pre_Conds.env_eval) * variant) list;
Walther@60705
   309
"~~~~~ fun sep_variants_envs , args:"; val (model_patt, i_model) = (model_patt, i_model);
Walther@60705
   310
    val equal_descr_pairs =
Walther@60705
   311
      map (get_equal_descr i_model) model_patt
Walther@60705
   312
      |> flat
Walther@60705
   313
(*+*)val
Walther@60705
   314
   [(("#Given", (Const ("Input_Descript.Constants", _), Free ("fixes", _))),
Walther@60705
   315
     (1, [1, 2, 3], true, "#Given", _)),
Walther@60705
   316
(*"#Given"^^^^ would be appropriate for pre-conditions, but kept to build code:...*)
Walther@60705
   317
    (("#Relate", (Const ("Input_Descript.SideConditions", _), Free ("sideconds", _))),
Walther@60705
   318
     (5, [1, 2], true, "#Relate", _)),
Walther@60705
   319
    (("#Relate", (Const ("Input_Descript.SideConditions", _), Free ("sideconds", _))),
Walther@60705
   320
     (6, [3], true, "#Relate", _) )] = equal_descr_pairs
Walther@60705
   321
Walther@60705
   322
    val all_variants =
Walther@60705
   323
        map (fn (_, (_, variants, _, _, _)) => variants) equal_descr_pairs
Walther@60705
   324
        |> flat
Walther@60705
   325
        |> distinct op =
Walther@60705
   326
    val variants_separated = map (filter_variants equal_descr_pairs) all_variants
Walther@60705
   327
(*+*)val
Walther@60705
   328
  [
Walther@60705
   329
   [(("#Given", (Const ("Input_Descript.Constants", _), Free ("fixes", _(*"bool list"*)))),
Walther@60710
   330
     (1, [1(*#*), 2, 3], true, "#Given", (Cor_TEST ((Const ("Input_Descript.Constants", _),
Walther@60705
   331
       [_ $ (Const ("HOL.eq", _) $ Free ("r", _) $ _) $ _]), _(*eliminate*)), _))),
Walther@60705
   332
    (("#Relate", (Const ("Input_Descript.SideConditions", _), Free ("sideconds", _))),
Walther@60710
   333
     (5, [1(*#*), 2], true, "#Relate", (Cor_TEST ((Const ("Input_Descript.SideConditions", _),
Walther@60705
   334
         [_ $ (_ $ (_ $ (_ $ (_ $ Free ("u", _) $ _) $ _) $ _) $ _) $ _]), _(*eliminate*)), _)))],
Walther@60705
   335
   [(("#Given", (Const ("Input_Descript.Constants", _), Free ("fixes", _(*"bool list"*)))),
Walther@60710
   336
     (1, [1, 2(*#*), 3], true, "#Given", (Cor_TEST ((Const ("Input_Descript.Constants", _),
Walther@60705
   337
         [_ $ (_ $ Free ("r", _) $ _) $ _]), _(*eliminate*)), _))),
Walther@60705
   338
    (("#Relate", (Const ("Input_Descript.SideConditions", _), Free ("sideconds", _))),
Walther@60710
   339
     (5, [1, 2(*#*)], true, "#Relate", (Cor_TEST ((Const ("Input_Descript.SideConditions", _),
Walther@60705
   340
         [_ $ (_ $ (_ $ (_ $ (_ $ Free ("u", _) $ _) $ _) $ _) $ _) $ _]), _(*eliminate*)), _)))],
Walther@60705
   341
   [(("#Given", (Const ("Input_Descript.Constants", _), Free ("fixes", _(*"bool list"*)))),
Walther@60710
   342
     (1, [1, 2, 3(*#*)], true, "#Given", (Cor_TEST ((Const ("Input_Descript.Constants", _),
Walther@60705
   343
       [_ $ (Const ("HOL.eq", _) $ Free ("r", _) $ _) $ _]), _(*eliminate*)), _))),
Walther@60705
   344
    (("#Relate", (Const ("Input_Descript.SideConditions", _), Free ("sideconds", _))),
Walther@60710
   345
     (6, [3(*#*)], true, "#Relate", (Cor_TEST ((Const ("Input_Descript.SideConditions", _),
Walther@60705
   346
       [_ $ (_ $ _ $ (_ $ _ $ (Const ("Transcendental.sin", _) $ Free ("\<alpha>", _)))) $ _]), _), _)))]]
Walther@60710
   347
(*+*) = variants_separated (*#*):
Walther@60705
   348
   (Model_Pattern.single * single_TEST) list list
Walther@60705
   349
Walther@60710
   350
    val i_models = map (map snd) variants_separated; (*drop Model_Pattern.T from pair*)
Walther@60705
   351
(*+*)i_models: I_Model.T_TEST list;
Walther@60705
   352
Walther@60705
   353
    val envs_subst = map mk_env_subst variants_separated;
Walther@60705
   354
(*+*)envs_subst: Pre_Conds.env_subst list;
Walther@60705
   355
Walther@60705
   356
    val envs_eval =  map mk_env_eval variants_separated;
Walther@60705
   357
(*+*)envs_eval: Pre_Conds.env_subst list;
Walther@60705
   358
Walther@60705
   359
val return_sep_variants_envs = arrange_args2 i_models envs_subst envs_eval (1, all_variants);
Walther@60705
   360
Walther@60705
   361
(*+*)return_sep_variants_envs:
Walther@60705
   362
   ((I_Model.T_TEST * Pre_Conds.env_subst * Pre_Conds.env_eval) * variant) list;
Walther@60705
   363
(*\\\----------------- step into sep_variants_envs ----------------------------------------///*)
Walther@60705
   364
Walther@60705
   365
(*||------------------ continuing is_complete_OLD --------------------------------------------*)
Walther@60705
   366
(*+*)val [[(Free ("fixes", _), Free ("r", _))], (*.. vor 3 variants*)
Walther@60705
   367
     [(Free ("fixes", _), Free ("r", _))], 
Walther@60705
   368
     [(Free ("fixes", _), Free ("r", _))]] = envs_subst;
Walther@60705
   369
Walther@60705
   370
(*taken from local environment -----------------------vvvvvvvvvv, ----vvvvvvvvv*)
Walther@60705
   371
           check_variant_envs ctxt where_rls pres (hd envs_subst) (hd envs_eval);
Walther@60705
   372
(*+*)val (true,
Walther@60705
   373
       [(true, Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60705
   374
         Free ("r", _))])
Walther@60705
   375
        = check_variant_envs ctxt where_rls pres (hd envs_subst) (hd envs_eval);;
Walther@60705
   376
(*///----------------- step into check_variant_envs --------------------------------------\\\*)
Walther@60705
   377
(*these come in variants..*)
Walther@60705
   378
val variant_envs as ((_, env_subst, env_eval), _) = hd return_sep_variants_envs;
Walther@60705
   379
(*args of is_complete_OLD -------------------vvvv--vvvvvvvvv--vvvv*)
Walther@60705
   380
"~~~~~ fun check_variant_envs , args:"; val (ctxt, where_rls, pres, env_subst, env_eval) =
Walther@60705
   381
  (ctxt, where_rls, pres, hd envs_subst, hd envs_eval);
Walther@60705
   382
Walther@60705
   383
(*+*)val [Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60705
   384
      Free ("fixes", _)] = pres
Walther@60705
   385
(*+*)val [(Free ("fixes", _),  Free ("r", _))] = env_subst 
Walther@60705
   386
(*+*)val [(Free ("r", _), Const ("Num.numeral_class.numeral", _) $ _ )] = env_eval (*env2*)
Walther@60705
   387
Walther@60705
   388
    val pres_subst = map (TermC.subst_atomic_all env_subst) pres;
Walther@60705
   389
(*+*)val [(true, Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60705
   390
      Free ("r", _))] = pres_subst
Walther@60705
   391
Walther@60705
   392
    val full_subst = map (fn (bool, t) => (bool, subst_atomic env_eval t)) pres_subst
Walther@60705
   393
(*+*)val [(true, Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60705
   394
       (Const ("Num.numeral_class.numeral", _) $ _ ))] = full_subst
Walther@60705
   395
Walther@60705
   396
    val evals = map (eval ctxt where_rls) full_subst
Walther@60705
   397
(*+*)val [(true,
Walther@60705
   398
     Const ("Orderings.ord_class.less", _) $ Const ("Groups.zero_class.zero", _) $
Walther@60705
   399
       (Const ("Num.numeral_class.numeral", _) $ _ ))] = evals
Walther@60705
   400
Walther@60705
   401
(*-------------- fixpoint of foldl -----vvvv*)
Walther@60705
   402
val return_check_variant = (foldl and_ (true, map fst evals), pres_subst)
Walther@60705
   403
(*+*)val (true, [(true, Const ("Orderings.ord_class.less", _) $
Walther@60705
   404
        Const ("Groups.zero_class.zero", _) $ Free ("r", _))]) = return_check_variant
Walther@60705
   405
(*\\\----------------- step into check_variant_envs --------------------------------------///*)
Walther@60705
   406
Walther@60705
   407
(*||------------------ continuing is_complete_OLD --------------------------------------------*)
Walther@60705
   408
(*+*)val false = is_complete_variant no_model_items i_model
Walther@60705
   409
Walther@60705
   410
    val variants_envs = sep_variants_envs model_patt i_model;
Walther@60705
   411
(*+*)variants_envs: ((I_Model.T_TEST * Pre_Conds.env_subst * Pre_Conds.env_eval) * variant) list;
Walther@60705
   412
Walther@60705
   413
    val result_all_variants = map
Walther@60705
   414
      (fn ((i_model, env_subst, env_eval), variant) =>
Walther@60705
   415
        if fst (check_variant_envs ctxt where_rls pres env_subst env_eval)
Walther@60705
   416
          andalso is_complete_variant no_model_items i_model
Walther@60705
   417
        then SOME [variant] else NONE) variants_envs;
Walther@60705
   418
(*+*)result_all_variants: variant list option list;
Walther@60705
   419
(*+*)val [NONE, NONE, NONE] = result_all_variants
Walther@60705
   420
Walther@60705
   421
    val variants_complete =
Walther@60705
   422
      if forall is_none result_all_variants
Walther@60705
   423
      then NONE
Walther@60705
   424
      else SOME (map (fn x => if is_some x then [the x] else []) result_all_variants |> flat |> flat);
Walther@60705
   425
(*+*)variants_complete: variant list option;
Walther@60705
   426
Walther@60705
   427
val return_is_complete_OLD = variants_complete;
Walther@60705
   428
(*\\------------------ step into into is_complete_OLD --------------------------------------//*)
Walther@60705
   429
(*\------------------- test on OLD algorithm (with I_Model.T_TEST) --------------------------/*)
Walther@60714
   430
( *\----- reactivate with CS "remove sep_variants_envs"-----/*)