test/Tools/isac/Specify/m-match.sml
author wneuper <Walther.Neuper@jku.at>
Fri, 01 Dec 2023 05:51:18 +0100
changeset 60770 365758b39d90
parent 60769 0df0759fed26
child 60771 1b072aab8f4e
permissions -rw-r--r--
prepare 16: adapt Refine to variants
walther@60324
     1
(* Title:  "Specify/m-match.sml"
walther@59968
     2
   Author: Walther Neuper
walther@59968
     3
   (c) due to copyright terms
walther@59968
     4
*)
walther@59968
     5
walther@59968
     6
"-----------------------------------------------------------------------------------------------";
walther@59968
     7
"table of contents -----------------------------------------------------------------------------";
walther@59968
     8
"-----------------------------------------------------------------------------------------------";
Walther@60768
     9
"----------- fun by_o_model --------------------------------------------------------------------";
Walther@60769
    10
"----------- fun by_formalise ---------------------------------------------------------------------";
Walther@60469
    11
"----------- M_Match.arguments, is_cp, O_Model.copy_name +with EqSystem (!) --------------------";
walther@59968
    12
"-----------------------------------------------------------------------------------------------";
walther@59968
    13
"-----------------------------------------------------------------------------------------------";
walther@59968
    14
"-----------------------------------------------------------------------------------------------";
walther@59968
    15
walther@59984
    16
open M_Match;
Walther@60768
    17
(*** ------- fun by_o_model ----------------------------------------------------------------- ***)
Walther@60768
    18
"----------- fun by_o_model --------------------------------------------------------------------";
Walther@60768
    19
"----------- fun by_o_model --------------------------------------------------------------------";
Walther@60768
    20
(*//------------------ setup test data for fun by_o_model 1 --------------------------------\\*)
Walther@60768
    21
val fmz = ["equality (sqrt(9+4*x)=sqrt x + sqrt(5+x))",
Walther@60768
    22
	      "solveFor x", "errorBound (eps=0)", "solutions L"];
Walther@60768
    23
val pbt as {model,...} = Problem.from_store @{context} ["univariate", "equation"];
Walther@60768
    24
val (o_model, ctxt) = O_Model.init @{theory} fmz model
Walther@60768
    25
Walther@60768
    26
val py1 = Problem.from_store @{context} ["equation"];
Walther@60768
    27
val py2 = Problem.from_store @{context} ["univariate", "equation"];
Walther@60768
    28
val py3 = Problem.from_store @{context} ["sq", "rootX", "univariate", "equation"];
Walther@60768
    29
Walther@60768
    30
val return_1 as true = by_o_model ctxt o_model (#model py1, #where_ py1, #where_rls py1)
Walther@60768
    31
val return_2 as true = by_o_model ctxt o_model (#model py2, #where_ py2, #where_rls py2)
Walther@60768
    32
val return_1 as true = by_o_model ctxt o_model (#model py3, #where_ py3, #where_rls py3);
Walther@60768
    33
(*\\------------------ setup test data for fun by_o_model 1 --------------------------------//*)
Walther@60768
    34
Walther@60768
    35
"~~~~~ fun by_o_model , args:"; val (ctxt, o_model, (model_patt, where_, where_rls))
Walther@60768
    36
  = (ctxt, o_model, (#model py3, #where_ py3, #where_rls py3));
Walther@60768
    37
Walther@60768
    38
          (data_by_o ctxt o_model (model_patt, where_, where_rls));
Walther@60768
    39
"~~~~~ fun data_by_o , args:"; val (ctxt, o_model, (model_patt, where_, where_rls)) =
Walther@60768
    40
  (ctxt, o_model, (model_patt, where_, where_rls));
Walther@60768
    41
    val o_model_vnt = o_model
Walther@60768
    42
      |> map (fn o_single as (_, variants, _, _, _)
Walther@60768
    43
        => if member_swap op = 1 (*variant 1 is mandatory*) variants then [o_single] else [])
Walther@60768
    44
      |> flat
Walther@60770
    45
    val is_complete as true = map (fn (_, (descr, _)) => contains_o descr o_model_vnt) model_patt
Walther@60768
    46
      |> curry (foldl and_) true
Walther@60768
    47
    val i_model = (*in order to match sig of Pre_Conds.check*)
Walther@60768
    48
      map (fn (a, b, c, d, e) => (a, b, true, c, (I_Model.Cor_TEST (d, e), Position.none))) o_model_vnt
Walther@60768
    49
(*+*)val "[\n(1, [1], true ,#Given, (Cor_TEST equality (sqrt (9 + 4 * x) = sqrt x + sqrt (5 + x)) , pen2str, Position.T)), \n(2, [1], true ,#Given, (Cor_TEST solveFor x , pen2str, Position.T)), \n(3, [1], true ,#undef, (Cor_TEST errorBound (eps = (0::'a)) , pen2str, Position.T)), \n(4, [1], true ,#Find, (Cor_TEST solutions L , pen2str, Position.T))]"
Walther@60768
    50
 = i_model |> I_Model.to_string_TEST ctxt
Walther@60768
    51
Walther@60768
    52
    val (pre_conds_check, pre_conds) = Pre_Conds.check ctxt where_rls where_ (model_patt, i_model)
Walther@60768
    53
val return_data_by_o_STEP = (is_complete andalso pre_conds_check, (i_model, pre_conds))
Walther@60768
    54
Walther@60768
    55
val return_by_o_model as true = (data_by_o ctxt o_model (model_patt, where_, where_rls)) |> #1;
Walther@60768
    56
Walther@60768
    57
Walther@60769
    58
(*** ------- fun by_formalise ------------------------------------------------------------------ ***)
Walther@60769
    59
"----------- fun by_formalise ---------------------------------------------------------------------";
Walther@60769
    60
"----------- fun by_formalise ---------------------------------------------------------------------";
walther@59996
    61
val fmz = ["equality (sqrt(9+4*x)=sqrt x + sqrt(5+x))",
walther@59997
    62
	      "solveFor x", "errorBound (eps=0)", "solutions L"];
Walther@60586
    63
val pbt as {thy = thy, where_ = where_, model = model,...} =
Walther@60559
    64
    Problem.from_store @{context} ["univariate", "equation"];
Walther@60769
    65
val xxx = M_Match.by_formalise fmz pbt;
walther@59996
    66
Walther@60768
    67
val Matches'
Walther@60768
    68
   {Find = [Correct "solutions L"], 
walther@59996
    69
    Given = [
Walther@60768
    70
      Correct "equality (sqrt (9 + 4 * x) = sqrt x + sqrt (5 + x))", 
Walther@60768
    71
      Correct "solveFor x", 
Walther@60768
    72
      Correct "errorBound (eps = (0::'a))"], 
Walther@60768
    73
    Relate = [], 
Walther@60768
    74
    Where = [Correct "matches (?a = ?b) (sqrt (9 + 4 * x) = sqrt x + sqrt (5 + x))"], 
Walther@60768
    75
    With = []} = xxx;
walther@59996
    76
walther@59996
    77
Walther@60768
    78
(*** ------- M_Match.arguments, is_cp, O_Model.copy_name +with EqSystem (!) ----------------- ***)
Walther@60768
    79
"----------- M_Match.arguments, is_cp, O_Model.copy_name +with EqSystem (!) --------------------";
Walther@60475
    80
"----------- M_Match.arguments, is_cp, O_Model.copy_name +with EqSystem (!) --------------------";
walther@60336
    81
val Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
    82
	  (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
    83
		 Free (dI',_) $ 
wenzelm@60309
    84
		 (Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
    85
    (*...copied from LItool.tac_from_prog*)
Walther@60660
    86
    ParseC.parse_test @{context} (
walther@59996
    87
	"SubProblem (EqSystemX, [LINEAR, system], [no_met])         " ^
walther@60242
    88
        "     [BOOL_LIST [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]," ^
walther@59996
    89
        "      REAL_LIST [c, c_2]]");
walther@59996
    90
val ags = isalist2list ags';
walther@59997
    91
val pI = ["LINEAR", "system"];
Walther@60586
    92
val pats = (#model o Problem.from_store @{context}) pI;
walther@59996
    93
"-a1-----------------------------------------------------";
walther@59996
    94
(*M_Match.arguments = fn : theory -> pat list -> term list -> O_Model.T*)
walther@59996
    95
val xxx = M_Match.arguments @{theory "EqSystem"} pats ags;
walther@59996
    96
"-a2-----------------------------------------------------";
walther@59996
    97
case M_Match.arguments @{theory  "Isac_Knowledge"} pats ags of 
walther@60336
    98
    [(1, [1], "#Given", Const (\<^const_name>\<open>Input_Descript.equalities\<close>, _), _),
walther@60336
    99
     (2, [1], "#Given", Const (\<^const_name>\<open>EqSystem.solveForVars\<close>, _),
walther@59996
   100
      [ _ $ Free ("c", _) $ _, _ $ Free ("c_2", _) $ _]),
walther@60336
   101
     (3, [1], "#Find", Const (\<^const_name>\<open>EqSystem.solution\<close>, _), [Free ("ss'''", _)])] 
walther@59996
   102
    =>()
walther@59996
   103
  | _ => error "calchead.sml M_Match.arguments 2 args Nok ----------------";
walther@59996
   104
walther@59996
   105
"-b------------------------------------------------------";
walther@60336
   106
val Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
   107
	  (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   108
		 Free (dI',_) $ 
wenzelm@60309
   109
		 (Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   110
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   111
    ParseC.parse_test @{context} (
walther@59996
   112
	"SubProblem (EqSystemX, [LINEAR, system], [no_met])         " ^
walther@60242
   113
        "     [BOOL_LIST [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]," ^
walther@59996
   114
        "      REAL_LIST [c, c_2], BOOL_LIST ss''']");
walther@59996
   115
val ags = isalist2list ags';
walther@59997
   116
val pI = ["LINEAR", "system"];
Walther@60586
   117
val pats = (#model o Problem.from_store @{context}) pI;
walther@59996
   118
"-b1-----------------------------------------------------";
walther@59996
   119
val xxx = M_Match.arguments @{theory  "Isac_Knowledge"} pats ags;
walther@59996
   120
"-b2-----------------------------------------------------";
walther@59996
   121
case M_Match.arguments @{theory "EqSystem"} pats ags of 
walther@60336
   122
    [(1, [1], "#Given", Const (\<^const_name>\<open>Input_Descript.equalities\<close>, _), _),
walther@60336
   123
     (2, [1], "#Given", Const (\<^const_name>\<open>EqSystem.solveForVars\<close>, _),
walther@59996
   124
         [_ $ Free ("c", _) $ _,
walther@59996
   125
          _ $ Free ("c_2", _) $ _]),
walther@60336
   126
     (3, [1], "#Find", Const (\<^const_name>\<open>EqSystem.solution\<close>, _), [Free ("ss'''", _)])]
walther@59996
   127
    (*         type of Find:            [Free ("ss'''", "bool List.list")]*)
walther@59996
   128
    =>()
walther@59996
   129
  | _ => error "calchead.sml M_Match.arguments copy-named dropped --------";
walther@59996
   130
walther@59996
   131
"-c---ERROR case: stac is missing #Given equalities e_s--";
walther@60336
   132
val stac as Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
   133
	 (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   134
		Free (dI',_) $ 
wenzelm@60309
   135
		(Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   136
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   137
    ParseC.parse_test @{context} (
walther@59996
   138
	"SubProblem (EqSystemX, [LINEAR, system], [no_met]) " ^
walther@59996
   139
        "     [REAL_LIST [c, c_2]]");
walther@59996
   140
val ags = isalist2list ags'; 
walther@59997
   141
val pI = ["LINEAR", "system"];
Walther@60586
   142
val pats = (#model o Problem.from_store @{context}) pI;
walther@59996
   143
(*============ inhibit exn AK110726 ==============================================
walther@59996
   144
val xxx - M_Match.arguments (theory "EqSystem") pats ags;
walther@59996
   145
============ inhibit exn AK110726 ==============================================*)
walther@59996
   146
"-c1-----------------------------------------------------";
walther@59996
   147
"--------------------------step through code M_Match.arguments---";
walther@59996
   148
val (thy, pbt: Model_Pattern.T, ags) = (@{theory "EqSystem"}, pats, ags);
walther@59996
   149
fun flattup (i,(var,bool,str,itm_)) = (i,var,bool,str,itm_);
walther@59996
   150
	val pbt' = filter_out O_Model.is_copy_named pbt; (*=equalities, solveForVars*)
walther@59996
   151
	val cy = filter O_Model.is_copy_named pbt;       (*=solution*)
walther@59996
   152
(*============ inhibit exn AK110726 ==============================================
walther@59996
   153
	val oris' - O_Model.matc thy pbt' ags [];
walther@59996
   154
============ inhibit exn AK110726 ==============================================*)
walther@59996
   155
"-------------------------------step through code O_Model.matc---";
walther@59996
   156
val (thy, (p as (s,(d,t)))::pbt, a::ags, oris) = (thy, pbt', ags, []);
Walther@60475
   157
(O_Model.is_copy_named' o free2str) t;
walther@59996
   158
"---if False:...";
walther@59996
   159
(*============ inhibit exn AK110726 ==============================================
walther@59996
   160
val opt - mtc thy p a;
walther@59996
   161
============ inhibit exn AK110726 ==============================================*)
walther@59996
   162
"--------------------------------step through code mtc---";
walther@59996
   163
val (thy, (str, (dsc, _)): Model_Pattern.single, ty $ var) = (thy, p, a);
walther@59996
   164
Thm.global_cterm_of;
walther@59996
   165
val ttt = (dsc $ var);
walther@59996
   166
(*============ inhibit exn AK110726 ==============================================
walther@59996
   167
Thm.global_cterm_of thy (dsc $ var);
walther@59996
   168
============ inhibit exn AK110726 ==============================================*)
walther@59996
   169
walther@59996
   170
"-------------------------------------step through end---";
Walther@60473
   171
"--------- M_Match.arguments, is_cp, O_Model.copy_name +with EqSystem (!)--";
walther@60336
   172
val Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
   173
	  (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   174
		 Free (dI',_) $ 
wenzelm@60309
   175
		 (Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   176
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   177
    ParseC.parse_test @{context} (
walther@59996
   178
	"SubProblem (EqSystemX, [LINEAR, system], [no_met])         " ^
walther@60242
   179
        "     [BOOL_LIST [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]," ^
walther@59996
   180
        "      REAL_LIST [c, c_2]]");
walther@59996
   181
val ags = isalist2list ags';
walther@59997
   182
val pI = ["LINEAR", "system"];
Walther@60586
   183
val pats = (#model o Problem.from_store @{context}) pI;
walther@59996
   184
"-a1-----------------------------------------------------";
walther@59996
   185
(*M_Match.arguments = fn : theory -> pat list -> term list -> O_Model.T*)
walther@59996
   186
val xxx = M_Match.arguments @{theory "EqSystem"} pats ags;
walther@59996
   187
"-a2-----------------------------------------------------";
walther@59996
   188
case M_Match.arguments @{theory  "Isac_Knowledge"} pats ags of 
walther@60336
   189
    [(1, [1], "#Given", Const (\<^const_name>\<open>Input_Descript.equalities\<close>, _), _),
walther@60336
   190
     (2, [1], "#Given", Const (\<^const_name>\<open>EqSystem.solveForVars\<close>, _),
walther@59996
   191
      [ _ $ Free ("c", _) $ _, _ $ Free ("c_2", _) $ _]),
walther@60336
   192
     (3, [1], "#Find", Const (\<^const_name>\<open>EqSystem.solution\<close>, _), [Free ("ss'''", _)])] 
walther@59996
   193
    =>()
walther@59996
   194
  | _ => error "calchead.sml M_Match.arguments 2 args Nok ----------------";
walther@59996
   195
walther@59996
   196
"-b------------------------------------------------------";
walther@60336
   197
val Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
   198
	  (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   199
		 Free (dI',_) $ 
wenzelm@60309
   200
		 (Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   201
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   202
    ParseC.parse_test @{context} (
walther@59996
   203
	"SubProblem (EqSystemX, [LINEAR, system], [no_met])         " ^
walther@60242
   204
        "     [BOOL_LIST [c_2 = 0, L * c + c_2 = q_0 * L \<up> 2 / 2]," ^
walther@59996
   205
        "      REAL_LIST [c, c_2], BOOL_LIST ss''']");
walther@59996
   206
val ags = isalist2list ags';
walther@59997
   207
val pI = ["LINEAR", "system"];
Walther@60586
   208
val pats = (#model o Problem.from_store @{context}) pI;
walther@59996
   209
"-b1-----------------------------------------------------";
walther@59996
   210
val xxx = M_Match.arguments @{theory  "Isac_Knowledge"} pats ags;
walther@59996
   211
"-b2-----------------------------------------------------";
walther@59996
   212
case M_Match.arguments @{theory "EqSystem"} pats ags of 
walther@60336
   213
    [(1, [1], "#Given", Const (\<^const_name>\<open>Input_Descript.equalities\<close>, _), _),
walther@60336
   214
     (2, [1], "#Given", Const (\<^const_name>\<open>EqSystem.solveForVars\<close>, _),
walther@59996
   215
         [_ $ Free ("c", _) $ _,
walther@59996
   216
          _ $ Free ("c_2", _) $ _]),
walther@60336
   217
     (3, [1], "#Find", Const (\<^const_name>\<open>EqSystem.solution\<close>, _), [Free ("ss'''", _)])]
walther@59996
   218
    (*         type of Find:            [Free ("ss'''", "bool List.list")]*)
walther@59996
   219
    =>()
walther@59996
   220
  | _ => error "calchead.sml M_Match.arguments copy-named dropped --------";
walther@59996
   221
walther@59996
   222
"-c---ERROR case: stac is missing #Given equalities e_s--";
walther@60336
   223
val stac as Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
   224
	 (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   225
		Free (dI',_) $ 
wenzelm@60309
   226
		(Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   227
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   228
    ParseC.parse_test @{context} (
walther@59996
   229
	"SubProblem (EqSystemX, [LINEAR, system], [no_met]) " ^
walther@59996
   230
        "     [REAL_LIST [c, c_2]]");
walther@59996
   231
val ags = isalist2list ags'; 
walther@59997
   232
val pI = ["LINEAR", "system"];
Walther@60586
   233
val pats = (#model o Problem.from_store @{context}) pI;
walther@59996
   234
(*============ inhibit exn AK110726 ==============================================
walther@59996
   235
val xxx - M_Match.arguments (theory "EqSystem") pats ags;
walther@59996
   236
-------------------------------------------------------------------*)
walther@59996
   237
"-c1-----------------------------------------------------";
walther@59996
   238
"--------------------------step through code M_Match.arguments---";
walther@59996
   239
val (thy, pbt: Model_Pattern.T, ags) = (@{theory "EqSystem"}, pats, ags);
walther@59996
   240
fun flattup (i,(var,bool,str,itm_)) = (i,var,bool,str,itm_);
walther@59996
   241
	val pbt' = filter_out O_Model.is_copy_named pbt; (*=equalities, solveForVars*)
walther@59996
   242
	val cy = filter O_Model.is_copy_named pbt;       (*=solution*)
walther@59996
   243
(*============ inhibit exn AK110726 ==============================================
walther@59996
   244
	val oris' - O_Model.matc thy pbt' ags [];
walther@59996
   245
-------------------------------------------------------------------*)
walther@59996
   246
"-------------------------------step through code O_Model.matc---";
walther@59996
   247
val (thy, (p as (s,(d,t)))::pbt, a::ags, oris) = (thy, pbt', ags, []);
Walther@60475
   248
(O_Model.is_copy_named' o free2str) t;
walther@59996
   249
"---if False:...";
walther@59996
   250
(*============ inhibit exn AK110726 ==============================================
walther@59996
   251
val opt - mtc thy p a;
walther@59996
   252
-------------------------------------------------------------------*)
walther@59996
   253
"--------------------------------step through code mtc---";
walther@59996
   254
val (thy, (str, (dsc, _)): Model_Pattern.single, ty $ var) = (thy, p, a);
walther@59996
   255
Thm.global_cterm_of;
walther@59996
   256
val ttt = (dsc $ var);
walther@59996
   257
(*============ inhibit exn AK110726 ==============================================
walther@59996
   258
Thm.global_cterm_of thy (dsc $ var);
walther@59996
   259
-------------------------------------------------------------------*)
walther@59996
   260
"-------------------------------------step through end---";
walther@59996
   261
walther@59996
   262
case ((M_Match.arguments @{theory "EqSystem"} pats ags)
walther@59996
   263
      handle ERROR _ => []) of (*why not TYPE ?WN100920*)
Walther@60559
   264
    [] => M_Match.arguments_msg @{context} pI stac ags
walther@59996
   265
  | _ => error "calchead.sml M_Match.arguments 1st arg missing --------";
walther@59996
   266
walther@59996
   267
"-d------------------------------------------------------";
walther@60336
   268
val stac as Const (\<^const_name>\<open>SubProblem\<close>,_) $
wenzelm@60309
   269
	 (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   270
		Free (dI',_) $ 
wenzelm@60309
   271
		(Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   272
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   273
   ParseC.parse_test @{context} (
walther@59996
   274
	"SubProblem (TestX,[univariate,equation,test]," ^
walther@59996
   275
        "             [no_met]) [BOOL (x+1=2), REAL x]");
walther@59996
   276
val AGS = isalist2list ags';
walther@59997
   277
val pI = ["univariate", "equation", "test"];
walther@59996
   278
walther@59996
   279
walther@59996
   280
case ((M_Match.arguments @{theory "EqSystem"} pats ags)
walther@59996
   281
      handle ERROR _ => []) of (*why not TYPE ?WN100920*)
Walther@60559
   282
    [] => M_Match.arguments_msg @{context} pI stac ags
walther@59996
   283
  | _ => error "calchead.sml M_Match.arguments 1st arg missing --------";
walther@59996
   284
walther@59996
   285
"-d------------------------------------------------------";
walther@60336
   286
val stac as Const (\<^const_name>\<open>SubProblem\<close>, _) $
wenzelm@60309
   287
	 (Const (\<^const_name>\<open>Pair\<close>,_) $
walther@59996
   288
		Free (dI',_) $ 
wenzelm@60309
   289
		(Const (\<^const_name>\<open>Pair\<close>,_) $ pI' $ mI')) $ ags' =
walther@59996
   290
    (*...copied from LItool.tac_from_prog*)
Walther@60660
   291
    ParseC.parse_test @{context} (
walther@59996
   292
	"SubProblem (TestX,[univariate,equation,test]," ^
walther@59996
   293
        "             [no_met]) [BOOL (x+1=2), REAL x]");
walther@59996
   294
val AGS = isalist2list ags';
walther@59997
   295
val pI = ["univariate", "equation", "test"];
Walther@60586
   296
val PATS = (#model o Problem.from_store @{context}) pI;
walther@59996
   297
"-d1-----------------------------------------------------";
walther@59996
   298
"--------------------------step through code M_Match.arguments---";
walther@59996
   299
val (thy, pbt: Model_Pattern.T, ags) = (@{theory "Test"}, PATS, AGS);
walther@59996
   300
fun flattup (i,(var,bool,str,itm_)) = (i,var,bool,str,itm_);
walther@59996
   301
	val pbt' = filter_out O_Model.is_copy_named pbt; 
walther@59996
   302
	val cy = filter O_Model.is_copy_named pbt;       
walther@59996
   303
	val oris' = M_Match.matc thy pbt' ags [];
walther@59996
   304
"-------------------------------step through code O_Model.matc---";
walther@59996
   305
val (thy, (p as (s,(d,t)))::pbt, a::ags, oris) = (thy, pbt', ags, []);
Walther@60475
   306
(O_Model.is_copy_named' o free2str) t;
walther@59996
   307
"---if False:...";
walther@59996
   308
val opt = mtc thy p a;
walther@59996
   309
"--------------------------------step through code mtc---";
walther@59996
   310
val (thy, (str, (dsc, _)): Model_Pattern.single, ty $ var) = (thy, p, a);
walther@59996
   311
val ttt = (dsc $ var);
walther@59996
   312
Thm.global_cterm_of thy (dsc $ var);
walther@59996
   313
val ori = ((([1], str, dsc, (*[var]*) Input_Descript.split' (dsc, var))): O_Model.preori);
walther@59996
   314
walther@59996
   315
"-d2-----------------------------------------------------";
walther@59996
   316
pbt = [];  (*false*)
walther@59996
   317
"-------------------------------step through code O_Model.matc---";
walther@59996
   318
val (thy, (p as (s,(d,t)))::pbt, a::ags, oris) = (thy, pbt, ags, oris @ [ori]);
Walther@60475
   319
(O_Model.is_copy_named' o free2str) t;
walther@59996
   320
"---if False:...";
walther@59996
   321
val opt = mtc thy p a;
walther@59996
   322
"--------------------------------step through code mtc---";
walther@59996
   323
val (thy, (str, (dsc, _)):Model_Pattern.single, ty $ var) = (thy, p, a);
walther@59996
   324
val ttt = (dsc $ var);
walther@59996
   325
Thm.global_cterm_of thy (dsc $ var);
walther@59996
   326
val ori = ((([1], str, dsc, (*[var]*) Input_Descript.split' (dsc, var))): O_Model.preori);
walther@59996
   327
"-d3-----------------------------------------------------";
walther@59996
   328
pbt = [];  (*true, base case*)
walther@59996
   329
"-----------------continue step through code M_Match.arguments---";
Walther@60473
   330
	val oris' = oris @ [ori]; (*result 2 oris, O_Model.copy_name added later*)
Walther@60473
   331
"--------------------------------step through O_Model.copy_name----";
walther@59996
   332
val (pbt, oris, p as (field, (dsc, t)):Model_Pattern.single) = (pbt', oris', hd cy);
walther@59996
   333
(*t = "v_v'i'" : term             OLD: t = "v_i_"*)
walther@59996
   334
"--------------------------------------------------------";
walther@59996
   335
fun is_copy_named_generating_idstr str =
Walther@60475
   336
    if O_Model.is_copy_named' str
walther@59996
   337
    then case (rev o Symbol.explode) str of
walther@59996
   338
      (*"_"::"_"::"_"::_ => false*)
walther@59996
   339
	"'"::"'"::"'"::_ => false
walther@59996
   340
      | _ => true
walther@59996
   341
    else false;
walther@59996
   342
fun is_copy_named_generating (_, (_, t)) = 
walther@59996
   343
    (is_copy_named_generating_idstr o free2str) t;
walther@59996
   344
"--------------------------------------------------------";
walther@59996
   345
is_copy_named_generating p (*true*);
walther@59996
   346
           fun sel (_,_,d,ts) = Input_Descript.join'''' (d, ts);
Walther@60605
   347
	   val cy' = (String.concat o (drop_last_n 3) o Symbol.explode o free2str) t;
walther@59996
   348
               (*"v_v"             OLD: "v_"*)
walther@59996
   349
	   val ext = (last_elem o drop_last o Symbol.explode o free2str) t;
walther@59996
   350
               (*"i"               OLD: "i"*)
walther@59996
   351
	   val vars' = map (free2str o snd o snd) pbt(*cpy-nam filtered_out*);
walther@59996
   352
               (*["e_e", "v_v"]    OLD: ["e_", "v_"]*)
walther@59996
   353
	   val vals = map sel oris;
walther@59996
   354
               (*[x+1=2, x]        OLD: [x+1=2, x] : term list*)
walther@59996
   355
vars' ~~ vals;
walther@59996
   356
(*[("e_e", [x+1=2), ("v_v", x)]    OLD: [("e_", [x+1=2), ("v_", x)]*)
walther@59996
   357
(LibraryC.assoc (vars'~~vals, cy'));
walther@59996
   358
(*SOME (Free ("x", "Real.real")) : term option*)
walther@59996
   359
	   val cy_ext = (free2str o the) (LibraryC.assoc (vars'~~vals, cy'))^"_"^ext;
walther@59996
   360
               (*x_i*)
walther@59996
   361
"-----------------continue step through code M_Match.arguments---";
Walther@60473
   362
	val cy' = map (O_Model.copy_name pbt' oris') cy;
walther@59996
   363
               (*[([1], "#Find", "solutions, [x_i"] (*as terms*) )]*)
walther@59996
   364
"-------------------------------------step through end---";
walther@59996
   365
walther@59996
   366
case M_Match.arguments thy PATS AGS of
walther@60336
   367
[(1, [1], "#Given", Const (\<^const_name>\<open>Input_Descript.equality\<close>, _),
walther@60336
   368
  [Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (Const (\<^const_name>\<open>plus_class.plus\<close>, _) $
walther@60324
   369
		Free ("x", _) $ _(*1*)) $ _(*1*)]),
walther@60336
   370
 (2, [1], "#Given", Const (\<^const_name>\<open>Input_Descript.solveFor\<close>, _), [Free ("x", _)]),
walther@60336
   371
 (3, [1], "#Find", Const (\<^const_name>\<open>Input_Descript.solutions\<close>, _), [Free ("x_i", _)])]
walther@59996
   372
    => ()
walther@59996
   373
  | _ => error "calchead.sml M_Match.arguments [univariate,equation,test]--";