test/Tools/isac/Specify/pre-conditions.sml
author wneuper <Walther.Neuper@jku.at>
Thu, 17 Aug 2023 08:01:45 +0200
changeset 60732 18b933a12ab8
parent 60716 a6a9dd158e69
child 60733 4097c1317986
permissions -rw-r--r--
prepare 15: delete old code 1, repair Pre_Conds.check_envs_TEST and check_pos
walther@59996
     1
(* Title:  "Specify/pre-conditions.sml"
walther@59996
     2
   Author: Walther Neuper
walther@59996
     3
   (c) due to copyright terms
walther@59996
     4
*)
walther@59996
     5
walther@59996
     6
"-----------------------------------------------------------------------------------------------";
walther@59996
     7
"table of contents -----------------------------------------------------------------------------";
walther@59996
     8
"-----------------------------------------------------------------------------------------------";
Walther@60732
     9
"----------- build Pre_Conds.check_pos ---------------------------------------------------------";
walther@59996
    10
"-----------------------------------------------------------------------------------------------";
walther@59996
    11
"-----------------------------------------------------------------------------------------------";
walther@59996
    12
"-----------------------------------------------------------------------------------------------";
walther@59996
    13
Walther@60732
    14
"----------- build Pre_Conds.check_pos ---------------------------------------------------------";
Walther@60732
    15
"----------- build Pre_Conds.check_pos ---------------------------------------------------------";
Walther@60732
    16
"----------- build Pre_Conds.check_pos ---------------------------------------------------------";
Walther@60705
    17
(*see Outer_Syntax:    val (model, where_) = Model_Pattern.parse_pos_empty ctxt model_input*)
Walther@60732
    18
open Model_Def;
Walther@60732
    19
open Pre_Conds;
Walther@60705
    20
open I_Model
Walther@60705
    21
(*//------------------ test data setup -----------------------------------------------------\\*)
Walther@60705
    22
val thy = @{theory Calculation}
Walther@60705
    23
Walther@60705
    24
            val state =
Walther@60705
    25
              case the_data thy of
Walther@60705
    26
                  CTbasic_TEST.EmptyPtree => Preliminary.init_ctree thy example_id
Walther@60705
    27
                | _(*state (*FOR TEST*)*) => (**)the_data thy(**)
Walther@60705
    28
                  (*let*)
Walther@60705
    29
                    val {origin = (o_model, o_ref, _), spec = spec_ref, probl, meth, ctxt, ...} =
Walther@60705
    30
                      CTbasic_TEST.get_obj I state [(*Pos will become variable*)] |> CTbasic_TEST.rep_specify_data
Walther@60705
    31
;
Walther@60732
    32
if (probl |> I_Model.to_string_TEST @{context}) = "[\n" ^
Walther@60732
    33
  "(1, [1, 2, 3], false ,#Given, (Inc_TEST Constants [__=__, __=__], Position.T)), \n" ^
Walther@60732
    34
  "(2, [1, 2, 3], false ,#Find, (Inc_TEST Maximum __, Position.T)), \n" ^
Walther@60732
    35
  "(3, [1, 2, 3], false ,#Find, (Inc_TEST AdditionalValues [__, __], Position.T)), \n" ^
Walther@60732
    36
  "(4, [1, 2, 3], false ,#Relate, (Inc_TEST Extremum (__=__), Position.T)), \n" ^
Walther@60732
    37
  "(5, [1, 2], false ,#Relate, (Inc_TEST SideConditions [__=__, __=__], Position.T))]"
Walther@60732
    38
then () else error "probl FROM state CHANGED";
Walther@60732
    39
Walther@60732
    40
(*  probl_POS from above, #1 and #2 replaced by complete items, in order to evaluate to true*)
Walther@60732
    41
val probl_POS =
Walther@60705
    42
  (1, [1,2,3], true, "#Given",
Walther@60705
    43
    (Cor_TEST ((@{term "Constants"}, [@{term "[r = (7::real)]"(*should be "r = (7::real)"*)}]),
Walther@60705
    44
      (@{term "fixes::real"}, [@{term "r::real"}])), Position.none )) ::
Walther@60705
    45
  nth 2 probl :: nth 3 probl :: nth 4 probl ::
Walther@60705
    46
  (5, [1,2], true, "#Relate",
Walther@60705
    47
    (Cor_TEST ((@{term "SideConditions"}, [@{term "[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]"}]),
Walther@60705
    48
      (@{term "sideconds::bool list"}, [TermC.empty])), Position.none ))
Walther@60732
    49
  :: [] : I_Model.T_TEST;
Walther@60732
    50
val probl_OLD = I_Model.TEST_to_OLD probl : I_Model.T;
Walther@60705
    51
Walther@60705
    52
val {model = model_patt, where_rls, where_ = where_OLD, ...} = (*from_store without Position.T-vv*)
Walther@60705
    53
  Problem.from_store ctxt (References.explode_id "univariate_calculus/Optimisation")
Walther@60705
    54
;
Walther@60732
    55
if (model_patt |> Model_Pattern.to_string ctxt) =
Walther@60705
    56
 "[\"(#Given, (Constants, fixes))\", " ^
Walther@60705
    57
  "\"(#Find, (Maximum, maxx))\", " ^
Walther@60705
    58
  "\"(#Find, (AdditionalValues, vals))\", " ^
Walther@60705
    59
  "\"(#Relate, (Extremum, extr))\", " ^
Walther@60732
    60
  "\"(#Relate, (SideConditions, sideconds))\"]"
Walther@60732
    61
then () else error "i_model FROM state CHANGED";
Walther@60705
    62
val "[0 < fixes]" = (where_OLD |> UnparseC.terms @{context})
Walther@60705
    63
Walther@60705
    64
(*prepare check input with Position.T----------------------------------------------------------^^-*)
Walther@60705
    65
val where_POS = [(@{term "0 < (r::real)"}, Position.none)];
Walther@60705
    66
(*\\------------------ test data setup -----------------------------------------------------//*)
Walther@60705
    67
Walther@60732
    68
(*//------------------ build new code (with Position.T) ------------------------------------\\*)
Walther@60732
    69
 Pre_Conds.check_pos ctxt where_rls where_POS (model_patt, probl);
Walther@60732
    70
"~~~~~ fun check_pos , args:"; val (ctxt, where_rls, where_POS, (model_patt, i_model)) =
Walther@60732
    71
  (ctxt, where_rls, where_POS, (model_patt, probl));
Walther@60705
    72
Walther@60732
    73
(*+*)val [(prec, _)] = where_POS;
Walther@60732
    74
(*+*)val "0 < r" = prec |> UnparseC.term @{context} (* 1st substitution already done*)
Walther@60732
    75
Walther@60732
    76
(*+*)val ((1, [1, 2, 3], false, "#Given", (Inc_TEST _, _)) :: _) = probl
Walther@60732
    77
(*+*)val 5 = length probl;
Walther@60732
    78
(*!!!*)val ((1, [1, 2, 3], true, "#Given", (Cor_TEST _, _)) :: _) = probl_POS
Walther@60732
    79
(*!!!*)val 5 = length probl_POS; (*thus subst_atomic_all \<longrightarrow> false, replaces for test -------vvvv*)
Walther@60732
    80
Walther@60732
    81
Walther@60732
    82
      val (_, (** )_( **)env_model(**), ((** )_( **)env_subst(**), env_eval)) = of_max_variant model_patt 
Walther@60732
    83
        (filter (fn (_, _, _, m_field ,_) => m_field = "#Given") probl_POS)
Walther@60732
    84
Walther@60732
    85
(*+*)val "[\"\n(fixes, [[r = 7]])\"]" = env_model |> Subst.to_string @{context}
Walther@60732
    86
(*+*)val "[\"\n(fixes, r)\"]" = env_subst |> Subst.to_string @{context}
Walther@60732
    87
(*+*)val "[\"\n(r, 7)\"]" = env_eval |> Subst.to_string @{context}
Walther@60732
    88
Walther@60732
    89
      val full_subst = if env_eval = []
Walther@60732
    90
        then map (fn (t, pos) => ((true, t), pos)) where_POS
Walther@60732
    91
        else map (fn (t, pos) => (TermC.subst_atomic_all env_eval t, pos)) where_POS;
Walther@60732
    92
Walther@60732
    93
(*+*)val [((true, precond), pos)] = full_subst;
Walther@60732
    94
(*+*)val "0 < 7" = precond |> UnparseC.term @{context}
Walther@60732
    95
Walther@60732
    96
      val evals = map (fn ((bool_t), pos) => (eval ctxt where_rls bool_t, pos)) full_subst;
Walther@60732
    97
Walther@60732
    98
(*+*)val (true, precond) =                    eval ctxt where_rls (true, precond)
Walther@60732
    99
(*+*)val "0 < 7" = precond |> UnparseC.term @{context}
Walther@60732
   100
(*+*)val [((true, precond), pos)] = evals
Walther@60732
   101
(*+*)val "0 < 7" = precond |> UnparseC.term @{context}
Walther@60732
   102
Walther@60732
   103
      val display = map (fn ((t, pos), ((bool, _), _)) => (bool, (t, pos))) (where_POS ~~ evals)
Walther@60732
   104
(*
Walther@60732
   105
  NOTE ON IMPROVEMENT: one could do all subst + eval without Position.T and by ------ ^^^
Walther@60732
   106
  finally pair with bool (! the sequence of list items is NOT changed)
Walther@60732
   107
*)
Walther@60732
   108
(*+*)val [(true, (precond, pos))] = display
Walther@60732
   109
(*+*)val "0 < r" = precond |> UnparseC.term @{context}
Walther@60732
   110
Walther@60732
   111
val return_check_pos =
Walther@60732
   112
      (foldl and_ (true, map (fn ((bool, _: term), _: Position.T) => bool) evals), display)
Walther@60732
   113
:
Walther@60732
   114
checked_TEST
Walther@60705
   115
Walther@60705
   116
(* final test ... ----------------------------------------------------------------------------*)
Walther@60732
   117
val (true, [(true, (Const ("Orderings.ord_class.less", _) $ 
Walther@60732
   118
    Const ("Groups.zero_class.zero", _) $ Free ("r", _), _))]) = return_check_pos
Walther@60705
   119
(*\\------------------ build new code (with Position.T) ------------------------------------//*)