test/Tools/isac/Specify/i-model.sml
author wneuper <Walther.Neuper@jku.at>
Sun, 19 Feb 2023 10:29:58 +0100
changeset 60690 b7f19579bc25
parent 60676 8c37f1009457
child 60694 3ef9d9a83096
permissions -rw-r--r--
PIDE turn 3: hints for input format of terms in Model
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@59957
    11
"-----------------------------------------------------------------------------------------------";
walther@59957
    12
"-----------------------------------------------------------------------------------------------";
walther@59957
    13
"-----------------------------------------------------------------------------------------------";
walther@59957
    14
walther@59957
    15
open I_Model;
walther@59957
    16
"----------- investigate fun add_single in I_Model -------------------------------------------";
walther@59957
    17
"----------- investigate fun add_single in I_Model -------------------------------------------";
walther@59957
    18
"----------- investigate fun add_single in I_Model -------------------------------------------";
walther@59997
    19
val f_model = ["Traegerlaenge L", "Streckenlast q_0", "Biegelinie y",
walther@59957
    20
	"Randbedingungen [y 0 = (0::real), y L = 0, M_b 0 = 0, M_b L = 0]",
walther@59957
    21
	"FunktionsVariable x", "GleichungsVariablen [c, c_2, c_3, c_4]",
walther@59957
    22
  "AbleitungBiegelinie dy"];
walther@59957
    23
val f_spec = ("Biegelinie", ["Biegelinien"], ["IntegrierenUndKonstanteBestimmen2"]);
Walther@60571
    24
(*[], Pbl*)val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context} [(f_model, f_spec)]; (*\<rightarrow>Model_Problem*)
walther@59957
    25
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*\<rightarrow>Add_Given "Traegerlaenge L"*)
walther@59957
    26
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "Streckenlast q_0"*)
walther@59957
    27
Walther@60676
    28
(*[], Pbl*)val return_me_Add_Given =
Walther@60676
    29
           me nxt p [] pt; (*\<rightarrow>Add_Find "Biegelinie y"*)
Walther@60676
    30
(*/------------------- step into me Add_Given ----------------------------------------------\\*)
walther@59957
    31
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt, p, [], pt);
walther@59957
    32
Walther@60676
    33
val ("ok", (_, _, ptp)) = (*case*)
walther@59957
    34
      Step.by_tactic tac (pt, p) (*of*);
walther@59957
    35
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, p));
Walther@60676
    36
walther@59957
    37
  val Applicable.Yes tac' = (*case*)
walther@59957
    38
      Step.check tac (pt, p) (*of*);
walther@59957
    39
	    (*if*) Tactic.for_specify' tac' (*then*);
walther@59957
    40
walther@59957
    41
Step_Specify.by_tactic tac' ptp;
walther@59957
    42
"~~~~~ fun by_tactic , args:"; val ((Tactic.Add_Given' (ct, _)), (pt, p)) = (tac', ptp);
walther@59957
    43
Walther@60676
    44
val ("ok", ([(Add_Given "Streckenlast q_0", _, _)], [], _)) = (*case*)
walther@60016
    45
   Specify.by_Add_ "#Given" ct (pt, p);
Walther@60676
    46
"~~~~~ fun by_Add_ , args:"; val (m_field, ct, (pt, pos as (_, p_))) =
walther@59957
    47
  ("#Given", ct, (pt, p));
Walther@60676
    48
    val (met, oris, (_, pI', mI'), pbl, (_, pI, mI), ctxt) = SpecificationC.get_data (pt, pos)
Walther@60676
    49
    val (i_model, m_patt) =
Walther@60676
    50
       if p_ = Pos.Met then
Walther@60676
    51
         (met,
Walther@60676
    52
           (if mI = MethodC.id_empty then mI' else mI) |> MethodC.from_store ctxt |> #model)
Walther@60676
    53
       else
Walther@60676
    54
         (pbl,
Walther@60676
    55
           (if pI = Problem.id_empty then pI' else pI) |> Problem.from_store ctxt |> #model)
Walther@60676
    56
;
Walther@60655
    57
(*+*)if O_Model.to_string @{context} oris = "[\n" ^
walther@59997
    58
  "(1, [\"1\"], #Given, Traegerlaenge, [\"L\"]), \n" ^
walther@59997
    59
  "(2, [\"1\"], #Given, Streckenlast, [\"q_0\"]), \n" ^
walther@59997
    60
  "(3, [\"1\"], #Find, Biegelinie, [\"y\"]), \n" ^
walther@59997
    61
  "(4, [\"1\"], #Relate, Randbedingungen, [\"[y 0 = 0]\", \"[y L = 0]\", \"[M_b 0 = 0]\", \"[M_b L = 0]\"]), \n" ^
walther@59997
    62
  "(5, [\"1\"], #undef, FunktionsVariable, [\"x\"]), \n" ^
walther@59997
    63
  "(6, [\"1\"], #undef, GleichungsVariablen, [\"[c]\", \"[c_2]\", \"[c_3]\", \"[c_4]\"]), \n" ^
walther@59997
    64
  "(7, [\"1\"], #undef, AbleitungBiegelinie, [\"dy\"])]"
walther@59957
    65
(*+*)then () else error "INITIAL O_Model CHANGED";
walther@59957
    66
(*+*)if I_Model.to_string ctxt pbl = "[\n" ^
walther@59997
    67
  "(0 ,[] ,false ,#Given ,Inc Streckenlast ,(??.empty, [])), \n" ^
walther@59997
    68
  "(0 ,[] ,false ,#Find ,Inc Biegelinie ,(??.empty, [])), \n" ^
walther@59997
    69
  "(0 ,[] ,false ,#Relate ,Inc Randbedingungen [] ,(??.empty, [])), \n" ^
walther@59957
    70
  "(1 ,[1] ,true ,#Given ,Cor Traegerlaenge L ,(l_l, [L]))]"
walther@59957
    71
(*+*)then () else error "INITIAL I_Model CHANGED";
walther@59957
    72
Walther@60676
    73
val return_check_single = (*case*)
Walther@60676
    74
   I_Model.check_single ctxt m_field oris i_model m_patt ct (*of*);
Walther@60676
    75
(*//------------------ step into check_single ----------------------------------------------\\*)
Walther@60676
    76
"~~~~~ fun check_single , args <>[]:"; val (ctxt, m_field, o_model, i_model, m_patt, str)
Walther@60676
    77
  = (ctxt, m_field, oris, i_model, m_patt, ct);
Walther@60676
    78
      val (t as (descriptor $ _)) = Syntax.read_term ctxt str
Walther@60676
    79
        handle ERROR msg => error (msg (*^ Position.here pp*))
Walther@60676
    80
val SOME m_field' =
Walther@60676
    81
        (*case*) Model_Pattern.get_field descriptor m_patt (*of*);
Walther@60676
    82
          (*if*) m_field <> m_field' (*else*);
Walther@60676
    83
walther@59957
    84
(**)val ("", ori', all) =(**)
Walther@60469
    85
          (*case*) O_Model.contains ctxt m_field o_model t (*of*);
walther@59957
    86
Walther@60655
    87
(*+*)O_Model.single_to_string @{context} ori';
walther@59957
    88
(*+*)val [Free ("q_0", _)] = all;
walther@59957
    89
walther@59957
    90
(**)val ("", itm) =(**)
walther@59957
    91
 (*case*) is_notyet_input ctxt i_model all ori' m_patt (*of*);
walther@59957
    92
Walther@60676
    93
(*+*)val (2, [1], true, "#Given", Cor ((Const (\<^const_name>\<open>Streckenlast\<close>, _), [Free ("q_0", _)]), (Free ("q_q", _), [Free ("q_0", _)]))) = itm
Walther@60676
    94
(*\\------------------ step into check_single ----------------------------------------------//*)
Walther@60676
    95
val return_check_single = Add itm;
walther@59957
    96
Walther@60676
    97
"~~~~~ from fun check_single \<longrightarrow>fun by_Add_ , return:"; val (I_Model.Add i_single) = (return_check_single);
Walther@60676
    98
	          val i_model' = I_Model.add_single (Proof_Context.theory_of ctxt) i_single i_model
Walther@60676
    99
            val tac' = I_Model.make_tactic m_field (ct, i_model')
Walther@60676
   100
;
Walther@60676
   101
(*+*)if I_Model.to_string ctxt i_model' = "[\n" ^
walther@59997
   102
  "(0 ,[] ,false ,#Find ,Inc Biegelinie ,(??.empty, [])), \n" ^
walther@59997
   103
  "(0 ,[] ,false ,#Relate ,Inc Randbedingungen [] ,(??.empty, [])), \n" ^
walther@59997
   104
  "(1 ,[1] ,true ,#Given ,Cor Traegerlaenge L ,(l_l, [L])), \n" ^
walther@59957
   105
  "(2 ,[1] ,true ,#Given ,Cor Streckenlast q_0 ,(q_q, [q_0]))]"
walther@59957
   106
(*+*)then () else error "FINAL I_Model CHANGED";
walther@59957
   107
Walther@60676
   108
	          val  (_, _, _, pt') =  Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59957
   109
Walther@60676
   110
val return_by_Add_ = ("ok", ([(Tactic.input_from_T ctxt tac', tac', (pos, (Istate_Def.Uistate, ctxt)))],
Walther@60676
   111
              [], (pt', pos)));
Walther@60676
   112
(*-------------------- stop into me Add_Given ------------------------------------------------*)
Walther@60676
   113
(*\------------------- step into me Add_Given ----------------------------------------------//*)
Walther@60676
   114
                                val (p,_,f,nxt,_,pt) = return_me_Add_Given
walther@59957
   115
Walther@60676
   116
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*\<rightarrow>Add_Relation "Randbedingungen [y 0 = 0]"*)
walther@59957
   117
walther@59957
   118
(* final test ...*)
walther@59957
   119
if p = ([], Pbl) then
walther@59957
   120
  case nxt of Add_Relation "Randbedingungen [y 0 = 0]" => () | _ => error "investigate fun add_single CHANGED 1"
walther@59957
   121
else error "investigate fun add_single CHANGED 2"
Walther@60690
   122
Walther@60690
   123
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60690
   124
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60690
   125
"----------- build I_Model.init_TEST -----------------------------------------------------------";
Walther@60690
   126
(*/---------------------------------------- mimic input from PIDE -----------------------------\*)
Walther@60690
   127
Walther@60690
   128
(* Test_Example "Diff_App-No.123a" (*complete Model, empty References*) *)
Walther@60690
   129
val in_refs as (thy_id, probl_id, meth_id) = ("__", "__/__", "__/__")
Walther@60690
   130
val thy = @{theory}
Walther@60690
   131
val model_input = (*type Position.T is hidden, thus redefinition*)
Walther@60690
   132
 [("#Given", [("Constants [r = 7]", Position.none)]),
Walther@60690
   133
  ("#Where", [("0 < r", Position.none)]),
Walther@60690
   134
  ("#Find",
Walther@60690
   135
   [("Maximum A", Position.none), ("AdditionalValues [u, v]", Position.none)]),
Walther@60690
   136
  ("#Relate",
Walther@60690
   137
   [("Extremum (A = 2 * u * v - u \<up> 2)", Position.none),
Walther@60690
   138
    ("SideConditions [(u / 2) \<up> 2 + (2 / v) \<up> 2 = r \<up> 2]", Position.none)])]
Walther@60690
   139
: (Model_Pattern.m_field * (string * Position.T) list) list
Walther@60690
   140
val example_id = "Diff_App-No.123a";
Walther@60690
   141
(*----------------------------------------- init state -----------------------------------------*)
Walther@60690
   142
set_data Ctree.EmptyPtree thy;
Walther@60690
   143
(*\---------------------------------------- mimic input from PIDE -----------------------------/*)
Walther@60690
   144
Walther@60690
   145
val Ctree.EmptyPtree =
Walther@60690
   146
              (*case*) the_data thy (*of*);
Walther@60690
   147
Walther@60690
   148
(* Calculation..*)
Walther@60690
   149
"~~~~~ fun init_ctree_TEST , args:"; val (thy, example_id) = (thy, example_id);
Walther@60690
   150
      val example_id' = References_Def.explode_id example_id
Walther@60690
   151
      val (_, (formalise as (model, refs as (thy_id, probl_id, meth_id)))) =
Walther@60690
   152
        Store.get (Know_Store.get_expls @{theory}) example_id' example_id' 
Walther@60690
   153
      val {model = model_patt, ...} = Problem.from_store (Proof_Context.init_global thy) probl_id
Walther@60690
   154
      val (o_model, ctxt) = O_Model.init thy model model_patt
Walther@60690
   155
;
Walther@60690
   156
(*+*)o_model: O_Model.T; (* |> O_Model.to_string @{context}*)
Walther@60690
   157
(*+*)val ("Diff_App", ["univariate_calculus", "Optimisation"], ["Optimisation", "by_univariate_calculus"]) =
Walther@60690
   158
(*+*)  refs
Walther@60690
   159
Walther@60690
   160
      val empty_i_model = I_Model.init_TEST ctxt model_patt;
Walther@60690
   161
Walther@60690
   162
(*+*)if I_Model.to_string @{context} empty_i_model =
Walther@60690
   163
(*+*)  "[\n(0 ,[] ,false ,#Given ,Syn Constants [__=__, __=__]), \n" ^
Walther@60690
   164
(*+*)  "(0 ,[] ,false ,#Find ,Syn Maximum __), \n" ^
Walther@60690
   165
(*+*)  "(0 ,[] ,false ,#Find ,Syn AdditionalValues [__, __]), \n" ^
Walther@60690
   166
(*+*)  "(0 ,[] ,false ,#Relate ,Syn Extremum __), \n" ^
Walther@60690
   167
(*+*)  "(0 ,[] ,false ,#Relate ,Syn SideConditions [__=__, __=__])]"
Walther@60690
   168
(*+*)then () else error "final test of build I_Model.init_TEST FAILED";