test/Tools/isac/Minisubpbl/150-add-given.sml
author Walther Neuper <walther.neuper@jku.at>
Sat, 16 May 2020 16:23:24 +0200
changeset 59988 9a6aa40d1962
parent 59981 dc34eff67648
child 59990 ca6f741c0ca3
permissions -rw-r--r--
shift code from Specification to I_Model, rename ids
walther@59839
     1
(* Title:  "Minisubpbl/150-add-given.sml"
neuper@41986
     2
   Author: Walther Neuper 1105
neuper@41986
     3
   (c) copyright due to lincense terms.
neuper@41986
     4
*)
neuper@41986
     5
neuper@41986
     6
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
neuper@41986
     7
val (dI',pI',mI') =
neuper@41986
     8
  ("Test", ["sqroot-test","univariate","equation","test"],
neuper@41986
     9
   ["Test","squ-equ-test-subpbl1"]);
neuper@41986
    10
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))]; (*nxt = ("Model_Problem"*)
neuper@52070
    11
(*for resuming after stepping into code*)
neuper@52070
    12
val (p''',f''',nxt''',pt''') = (p,f,nxt,pt);
neuper@52070
    13
walther@59839
    14
"~~~~~ fun me , args:"; val (tac, (p:pos'), (_:NEW), (pt:ctree)) = (nxt, p, [], pt);
neuper@52070
    15
    val (pt, p) = 
wneuper@59426
    16
      (*ERROR nxt_add: types or dsc DO NOT MATCH BETWEEN fmz --- pbt ... see 100-init-rootpbl.sml*)
walther@59804
    17
	    case Step.by_tactic tac (pt,p) of
neuper@52070
    18
		    ("ok", (_, _, ptp)) => ptp;
walther@59839
    19
walther@59839
    20
    (*case*)
walther@59839
    21
      Step.do_next p ((pt, Pos.e_pos'), []) (*of*);
walther@59981
    22
"~~~~~ fun do_next , args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):Calc.state_pre)) =
neuper@52070
    23
  (p, ((pt, e_pos'),[]));
walther@59839
    24
    val pIopt = get_pblID (pt,ip);
walther@59839
    25
    (*if*) ip = ([],Res); (* = false*)
walther@59839
    26
      val _ = (*case*) tacis (*of*);
walther@59839
    27
      val SOME _ = (*case*) pIopt (*of*);
neuper@52070
    28
walther@59839
    29
   val (_, ([(Add_Given "equality (x + 1 = 2)", _, _)], _, _)) =
walther@59839
    30
           switch_specify_solve p_ (pt, ip);
walther@59839
    31
"~~~~~ fun switch_specify_solve , args:"; val (ptp as (pt, pos as (p,p_))) = (pt, ip);
neuper@52070
    32
val pblobj as (PblObj{meth,origin=origin as (oris,(dI',pI',mI'),_),
neuper@52070
    33
			  probl,spec=(dI,pI,mI), ...}) = get_obj I pt p;
neuper@52070
    34
just_created_ pblobj (*by Subproblem*) andalso origin <> e_origin; (* = false*)
walther@59903
    35
        val cpI = if pI = Problem.id_empty then pI' else pI;
walther@59903
    36
		    val cmI = if mI = Method.id_empty then mI' else mI;
walther@59970
    37
		    val {ppc, prls, where_, ...} = Problem.from_store cpI;
walther@59965
    38
		    val pre = Pre_Conds.check' "thy 100820" prls where_ probl;
neuper@52070
    39
		    val pb = foldl and_ (true, map fst pre);
neuper@52070
    40
neuper@52070
    41
(*    val (_,tac) = nxt_spec p_ pb oris (dI',pI',mI') (probl, meth) 
walther@59970
    42
			    (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI);
neuper@52070
    43
ERROR: val tac = Add_Given "equality (<markup> + <markup> = <markup>)"*)
walther@59976
    44
"~~~~~ fun nxt_spec, args:"; val (Pbl, preok, (oris : O_Model.T), ((dI', pI', mI') : References.T),
walther@59976
    45
  ((pbl : I_Model.T), (met : I_Model.T)), (pbt, mpc), ((dI, pI, mI) : References.T)) = 
neuper@52070
    46
  (p_, pb, oris, (dI',pI',mI'), (probl, meth), 
walther@59970
    47
			    (ppc, (#ppc o Method.from_store) cmI), (dI, pI, mI));
neuper@52070
    48
walther@59879
    49
dI' = ThyC.id_empty andalso dI = ThyC.id_empty; (* = false*)
walther@59903
    50
pI' = Problem.id_empty andalso pI = Problem.id_empty; (* = false*)
walther@59988
    51
find_first (I_Model.is_error o #5) (pbl:I_Model.T); (* = NONE*)
neuper@52070
    52
walther@59881
    53
(* nxt_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl; 
neuper@52070
    54
= SOME ("#Given", "equality (<markup> + <markup> = <markup>)") *)
neuper@52070
    55
"~~~~~ fun nxt_add, args:"; val (thy, oris, pbt, itms) =
walther@59881
    56
  ((ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)), oris, pbt, pbl);
neuper@52070
    57
local infix mem;
neuper@52070
    58
fun x mem [] = false
neuper@52070
    59
  | x mem (y :: ys) = x = y orelse x mem ys;
neuper@52070
    60
in 
walther@59943
    61
    fun testr_vt v ori = (curry (op mem) v) (#2 (ori:O_Model.single))
neuper@52070
    62
      andalso (#3 ori) <>"#undef";
walther@59943
    63
    fun testi_vt v itm = (curry (op mem) v) (#2 (itm:I_Model.single));
walther@59943
    64
    fun test_id ids r = curry (op mem) (#1 (r:O_Model.single)) ids;
walther@59943
    65
    fun test_subset (itm:I_Model.single) ((_,_,_,d,ts):O_Model.single) = 
walther@59945
    66
	(I_Model.d_in (#5 itm)) = d andalso subset op = (I_Model.ts_in (#5 itm), ts);
walther@59945
    67
    fun false_and_not_Sup((i,v,false,f,I_Model.Sup _):I_Model.single) = false
neuper@52070
    68
      | false_and_not_Sup (i,v,false,f, _) = true
neuper@52070
    69
      | false_and_not_Sup  _ = false;
neuper@52070
    70
end
walther@59945
    71
    val v = if itms = [] then 1 else I_Model.max_vt itms;
neuper@52070
    72
    val vors = if v = 0 then oris else filter (testr_vt v) oris;(*oris..vat*)
neuper@52070
    73
    val vits = if v = 0 then itms (*because of dsc without dat*)
neuper@52070
    74
	       else filter (testi_vt v) itms;                   (*itms..vat*)
neuper@52070
    75
    val icl = filter false_and_not_Sup vits; (* incomplete *)
neuper@52070
    76
icl = []; (* = false*)
neuper@52070
    77
val SOME ori = find_first (test_subset (hd icl)) vors;
neuper@52070
    78
neuper@52070
    79
(* SOME (geti_ct thy ori (hd icl))
neuper@52070
    80
ERROR: SOME (geti_ct thy ori (hd icl))*)
walther@59943
    81
"~~~~~ fun geti_ct, args:"; val (thy, ((_, _, _, d, ts) : O_Model.single), ((_, _, _, fd, itm_) : I_Model.single)) =
neuper@52070
    82
  (thy, ori, (hd icl));
neuper@52070
    83
"~~~~~ to  return val:"; val xxx = 
neuper@52070
    84
  ( fd, 
walther@59953
    85
    ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, subtract op = (I_Model.ts_in itm_) ts) : TermC.as_string
neuper@52070
    86
  );
neuper@52070
    87
if xxx = ("#Given", "equality (x + 1 = 2)") then () else error "";
neuper@52070
    88
neuper@52070
    89
(* resuming after stepping into code*)
neuper@52070
    90
val (p,f,nxt,pt) = (p''',f''',nxt''',pt''');
neuper@52070
    91
neuper@41986
    92
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = (_,Add_Given "equality (x + 1 = 2)*)
neuper@41986
    93
val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = (_,Add_Given "solveFor x"*)
walther@59749
    94
case nxt of (Add_Given "solveFor x") => ()
walther@59839
    95
| _ => error "minisubpbl: Add_Given is broken in root-problem";