test/Tools/isac/Specify/pre-conditions.sml
author wneuper <Walther.Neuper@jku.at>
Sun, 10 Dec 2023 17:35:07 +0100
changeset 60777 df8636ffd6f8
parent 60771 1b072aab8f4e
child 60779 fabe6923e819
permissions -rw-r--r--
PIDE turn 14: ALL src/* (except Ctree) with I_Model.T_POS exclusively
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@60746
    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@60771
    26
                  CTbasic_POS.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@60771
    30
                      CTbasic_POS.get_obj I state [(*Pos will become variable*)] |> CTbasic_POS.rep_specify_data
Walther@60705
    31
;
Walther@60771
    32
(*+*)if (probl |> I_Model.to_string_POS @{context}) = "[\n" ^
Walther@60771
    33
  "(1, [1, 2, 3], false ,#Given, (Inc_POS Constants [] [__=__, __=__], Position.T)), \n" ^
Walther@60771
    34
  "(2, [1, 2, 3], false ,#Find, (Inc_POS Maximum __, Position.T)), \n" ^
Walther@60771
    35
  "(3, [1, 2, 3], false ,#Find, (Inc_POS AdditionalValues [] [__, __], Position.T)), \n" ^
Walther@60771
    36
  "(4, [1, 2, 3], false ,#Relate, (Inc_POS Extremum (__=__), Position.T)), \n" ^
Walther@60771
    37
  "(5, [1, 2], false ,#Relate, (Inc_POS 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@60771
    43
    (Cor_POS ((@{term "Constants"}, [@{term "[r = (7::real)]"(*should be "r = (7::real)"*)}])), Position.none )) ::
Walther@60705
    44
  nth 2 probl :: nth 3 probl :: nth 4 probl ::
Walther@60705
    45
  (5, [1,2], true, "#Relate",
Walther@60771
    46
    (Cor_POS ((@{term "SideConditions"}, [@{term "[(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]"}])), Position.none ))
Walther@60771
    47
  :: [] : I_Model.T_POS;
Walther@60777
    48
val probl_OLD = probl
Walther@60705
    49
Walther@60705
    50
val {model = model_patt, where_rls, where_ = where_OLD, ...} = (*from_store without Position.T-vv*)
Walther@60705
    51
  Problem.from_store ctxt (References.explode_id "univariate_calculus/Optimisation")
Walther@60705
    52
;
Walther@60732
    53
if (model_patt |> Model_Pattern.to_string ctxt) =
Walther@60705
    54
 "[\"(#Given, (Constants, fixes))\", " ^
Walther@60705
    55
  "\"(#Find, (Maximum, maxx))\", " ^
Walther@60705
    56
  "\"(#Find, (AdditionalValues, vals))\", " ^
Walther@60705
    57
  "\"(#Relate, (Extremum, extr))\", " ^
Walther@60732
    58
  "\"(#Relate, (SideConditions, sideconds))\"]"
Walther@60732
    59
then () else error "i_model FROM state CHANGED";
Walther@60705
    60
val "[0 < fixes]" = (where_OLD |> UnparseC.terms @{context})
Walther@60705
    61
Walther@60758
    62
(*prepare check input with Position.T-------------------------------------------------------------*)
Walther@60705
    63
val where_POS = [(@{term "0 < (r::real)"}, Position.none)];
Walther@60705
    64
(*\\------------------ test data setup -----------------------------------------------------//*)
Walther@60705
    65
Walther@60732
    66
(*//------------------ build new code (with Position.T) ------------------------------------\\*)
Walther@60732
    67
 Pre_Conds.check_pos ctxt where_rls where_POS (model_patt, probl);
Walther@60732
    68
"~~~~~ fun check_pos , args:"; val (ctxt, where_rls, where_POS, (model_patt, i_model)) =
Walther@60758
    69
  (ctxt, where_rls, where_POS, (model_patt, probl_POS));
Walther@60705
    70
Walther@60732
    71
(*+*)val [(prec, _)] = where_POS;
Walther@60732
    72
(*+*)val "0 < r" = prec |> UnparseC.term @{context} (* 1st substitution already done*)
Walther@60732
    73
Walther@60771
    74
(*+*)val ((1, [1, 2, 3], false, "#Given", (Inc_POS _, _)) :: _) = probl
Walther@60732
    75
(*+*)val 5 = length probl;
Walther@60771
    76
(*!!!*)val ((1, [1, 2, 3], true, "#Given", (Cor_POS _, _)) :: _) = probl_POS
Walther@60732
    77
(*!!!*)val 5 = length probl_POS; (*thus subst_atomic_all \<longrightarrow> false, replaces for test -------vvvv*)
Walther@60732
    78
Walther@60732
    79
Walther@60758
    80
      val (env_model, (env_subst, env_eval)) = make_environments model_patt 
Walther@60758
    81
        ((*filter (fn (_, _, _, m_field ,_) => m_field = "#Given")*) i_model)
Walther@60758
    82
;
Walther@60771
    83
(*+*)(probl_POS |> I_Model.to_string_POS @{context}) = "[\n" ^
Walther@60771
    84
  "(1, [1, 2, 3], true ,#Given, (Cor_POS Constants [r = 7] , pen2str, Position.T)), \n" ^
Walther@60758
    85
(*--------------------------------------------------^^^^^^^--- FROM test data setup -----------*)
Walther@60771
    86
  "(2, [1, 2, 3], false ,#Find, (Inc_POS Maximum __, Position.T)), \n" ^
Walther@60771
    87
  "(3, [1, 2, 3], false ,#Find, (Inc_POS AdditionalValues [] [__, __], Position.T)), \n" ^
Walther@60771
    88
  "(4, [1, 2, 3], false ,#Relate, (Inc_POS Extremum (__=__), Position.T)), \n" ^
Walther@60758
    89
(*------------------------------------------------------vvvvvvv--- FROM test data setup -------*)
Walther@60771
    90
  "(5, [1, 2], true ,#Relate, (Cor_POS SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2] , pen2str, Position.T))]"
Walther@60758
    91
;
Walther@60766
    92
(*+*)val "[\"\n(fixes, [r = 7])\", \"\n(sideconds, [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2])\"]"
Walther@60766
    93
 = env_model |> Subst.to_string ctxt
Walther@60732
    94
(*+*)val "[\"\n(fixes, r)\"]" = env_subst |> Subst.to_string @{context}
Walther@60732
    95
(*+*)val "[\"\n(r, 7)\"]" = env_eval |> Subst.to_string @{context}
Walther@60732
    96
Walther@60732
    97
      val full_subst = if env_eval = []
Walther@60732
    98
        then map (fn (t, pos) => ((true, t), pos)) where_POS
Walther@60732
    99
        else map (fn (t, pos) => (TermC.subst_atomic_all env_eval t, pos)) where_POS;
Walther@60732
   100
Walther@60732
   101
(*+*)val [((true, precond), pos)] = full_subst;
Walther@60732
   102
(*+*)val "0 < 7" = precond |> UnparseC.term @{context}
Walther@60732
   103
Walther@60732
   104
      val evals = map (fn ((bool_t), pos) => (eval ctxt where_rls bool_t, pos)) full_subst;
Walther@60732
   105
Walther@60732
   106
(*+*)val (true, precond) =                    eval ctxt where_rls (true, precond)
Walther@60732
   107
(*+*)val "0 < 7" = precond |> UnparseC.term @{context}
Walther@60732
   108
(*+*)val [((true, precond), pos)] = evals
Walther@60732
   109
(*+*)val "0 < 7" = precond |> UnparseC.term @{context}
Walther@60732
   110
Walther@60732
   111
      val display = map (fn ((t, pos), ((bool, _), _)) => (bool, (t, pos))) (where_POS ~~ evals)
Walther@60732
   112
(*
Walther@60732
   113
  NOTE ON IMPROVEMENT: one could do all subst + eval without Position.T and by ------ ^^^
Walther@60732
   114
  finally pair with bool (! the sequence of list items is NOT changed)
Walther@60732
   115
*)
Walther@60732
   116
(*+*)val [(true, (precond, pos))] = display
Walther@60732
   117
(*+*)val "0 < r" = precond |> UnparseC.term @{context}
Walther@60732
   118
Walther@60732
   119
val return_check_pos =
Walther@60732
   120
      (foldl and_ (true, map (fn ((bool, _: term), _: Position.T) => bool) evals), display)
Walther@60732
   121
:
Walther@60741
   122
checked_pos
Walther@60705
   123
Walther@60705
   124
(* final test ... ----------------------------------------------------------------------------*)
Walther@60732
   125
val (true, [(true, (Const ("Orderings.ord_class.less", _) $ 
Walther@60732
   126
    Const ("Groups.zero_class.zero", _) $ Free ("r", _), _))]) = return_check_pos
Walther@60705
   127
(*\\------------------ build new code (with Position.T) ------------------------------------//*)