src/sml/ME/mathengine.sml
author wneuper
Thu, 01 Sep 2005 12:48:54 +0200
branchstart_Take
changeset 360 f01c35e2801c
parent 359 005153b87bca
child 383 a7f31617891e
permissions -rw-r--r--
Biegelinie#Script intermediate, (once more) removed DG
wneuper@339
     1
(* The _functional_ mathematics engine, ie. without a state.
wneuper@339
     2
   Input and output are Isabelle's formulae as strings.
wneuper@339
     3
   (c) Walther Neuper 2000
wneuper@339
     4
   (c) Stefan Rath 2005
wneuper@339
     5
wneuper@339
     6
use"~/proto2/isac/src/sml/ME/mathengine.sml";
wneuper@339
     7
*)
wneuper@339
     8
wneuper@339
     9
signature MATHENGINE =
wneuper@339
    10
  sig
wneuper@339
    11
    type nxt_
wneuper@339
    12
    (* datatype nxt_ = HElpless | Nexts of CalcHead.calcstate *)
wneuper@339
    13
    type NEW
wneuper@339
    14
    type lOc_
wneuper@339
    15
    (*datatype
wneuper@339
    16
      lOc_ =
wneuper@339
    17
          ERror of string
wneuper@339
    18
        | UNsafe of CalcHead.calcstate'
wneuper@339
    19
        | Updated of CalcHead.calcstate' *)
wneuper@339
    20
wneuper@339
    21
    val CalcTreeTEST :
wneuper@339
    22
       fmz list ->
wneuper@339
    23
       pos' * NEW * mout * (string * tac) * safe * ptree
wneuper@339
    24
wneuper@339
    25
    val TESTg_form : ptree * (int list * pos_) -> mout
wneuper@339
    26
    val autocalc :
wneuper@339
    27
       pos' list ->
wneuper@339
    28
       pos' ->
wneuper@339
    29
       (ptree * pos') * taci list ->
wneuper@339
    30
       auto -> string * pos' list * (ptree * pos')
wneuper@339
    31
    val detailstep : ptree -> pos' -> string * ptree * pos'
wneuper@339
    32
   (* val e_tac_ : tac_ *)
wneuper@339
    33
   (* val get_pblID : ptree * pos' -> pblID Library.option *)
wneuper@339
    34
wneuper@339
    35
   (* val loc_solve_ :
wneuper@339
    36
       string * tac_ -> ptree * (int list * pos_) -> lOc_ *)
wneuper@339
    37
   (* val loc_specify_ : tac_ -> ptree * pos' -> lOc_ *)
wneuper@339
    38
    val locatetac :     (*tests only*)
wneuper@339
    39
       tac ->
wneuper@339
    40
       ptree * (posel list * pos_) ->
wneuper@339
    41
       string * (taci list * pos' list * (ptree * (posel list * pos_)))
wneuper@339
    42
    val me :
wneuper@339
    43
       tac'_ ->
wneuper@339
    44
       pos' ->
wneuper@339
    45
       NEW ->
wneuper@339
    46
       ptree -> pos' * NEW * mout * tac'_ * safe * ptree
wneuper@339
    47
wneuper@339
    48
    val nxt_specify_ : ptree * (int list * pos_) -> CalcHead.calcstate'
wneuper@339
    49
    val step : pos' -> CalcHead.calcstate -> string * CalcHead.calcstate'
wneuper@339
    50
    val trymatch : pblID -> ptree -> int list * 'a -> ptform
wneuper@339
    51
    val tryrefine : pblID -> ptree -> int list * 'a -> ptform
wneuper@339
    52
  end
wneuper@339
    53
wneuper@339
    54
wneuper@339
    55
wneuper@339
    56
(*
wneuper@339
    57
structure mathengine : MATHENGINE =
wneuper@339
    58
struct
wneuper@339
    59
*)
wneuper@339
    60
fun get_pblID (pt, (p,_):pos') =
wneuper@339
    61
    let val p' = par_pblobj pt p
wneuper@339
    62
	val (_,pI,_) = get_obj g_spec pt p'
wneuper@339
    63
	val (_,(_,oI,_),_) = get_obj g_origin pt p'
wneuper@339
    64
    in if pI <> e_pblID then Some pI
wneuper@339
    65
       else if oI <> e_pblID then Some oI
wneuper@339
    66
       else None end;
wneuper@339
    67
(*fun get_pblID (pt, (p,_):pos') =
wneuper@339
    68
    ((snd3 o (get_obj g_spec pt)) (par_pblobj pt p));*)
wneuper@339
    69
wneuper@339
    70
wneuper@339
    71
(*----------------------vvv--------------------dummies for test*)
wneuper@339
    72
val e_tac_ = Tac_ (Pure.thy,"","","");
wneuper@339
    73
datatype lOc_ =
wneuper@339
    74
  ERror of string         (*after loc_specify, loc_solve*)
wneuper@339
    75
| UNsafe of calcstate'    (*after loc_specify, loc_solve*)
wneuper@339
    76
| Updated of calcstate';   (*after loc_specify, loc_solve*)
wneuper@339
    77
fun loc_specify_ m (pt,pos) =
wneuper@339
    78
(* val pos = ip;
wneuper@339
    79
   *)
wneuper@339
    80
    let val (p,_,f,_,s,pt) = specify m pos [] pt;
wneuper@339
    81
(*      val (_,_,_,_,_,pt')= specify m pos [] pt;
wneuper@339
    82
   *) 
wneuper@339
    83
   in case f of
wneuper@339
    84
	   (Error' (Error_ e)) => ERror e
wneuper@339
    85
	 | _ => Updated ([], [], (pt,p)) end;
wneuper@339
    86
wneuper@339
    87
fun loc_solve_ m (pt,pos) =
wneuper@339
    88
(* val (m, pos) = ((mI,m), ip);
wneuper@339
    89
   val (m,(pt,pos) ) = ((mI,m), ptp);
wneuper@339
    90
   *)  
wneuper@339
    91
    let val (msg, cs') = solve m (pt, pos);
wneuper@339
    92
(* val (tacis,dels,(pt',p')) = cs';
wneuper@339
    93
   (writeln o istate2str) (get_istate pt' p');
wneuper@339
    94
   (term2str o fst) (get_obj g_result pt' (fst p'));
wneuper@339
    95
   *)
wneuper@339
    96
    in case msg of
wneuper@339
    97
	   "ok" => Updated cs' 
wneuper@339
    98
	 | msg => ERror msg 
wneuper@339
    99
    end;
wneuper@339
   100
wneuper@339
   101
datatype nxt_ =
wneuper@339
   102
	 HElpless  (**)
wneuper@339
   103
       | Nexts of calcstate; (**)
wneuper@339
   104
wneuper@339
   105
(*report applicability of tac in tacis; pt is dropped in setNextTactic*)
wneuper@339
   106
fun locatetac _ (ptp as (_,([],Res))) = ("end-of-calculation", ([], [], ptp))
wneuper@339
   107
  | locatetac tac (ptp as (pt, p)) =
wneuper@339
   108
(* val ptp as (pt, p) = (pt, ip);
wneuper@339
   109
   val ptp as (pt, p) = (pt, p);
wneuper@339
   110
   *)
wneuper@339
   111
    let val (mI,m) = mk_tac'_ tac;
wneuper@339
   112
    in case applicable_in p pt m of
wneuper@339
   113
	   Notappl e => ("not-applicable", ([],[],  ptp):calcstate')
wneuper@339
   114
	 | Appl m =>
wneuper@339
   115
(* val Appl m = applicable_in p pt m;
wneuper@339
   116
    *) 
wneuper@339
   117
	   let val x = if mI mem specsteps
wneuper@339
   118
		       then loc_specify_ m ptp else loc_solve_ (mI,m) ptp
wneuper@339
   119
	   in case x of 
wneuper@339
   120
		  ERror e => ("failure", ([], [], ptp))
wneuper@339
   121
		(*FIXXXXXME: loc_specify_, loc_solve_ TOGETHER with dropping meOLD+detail.sml*)
wneuper@339
   122
		| UNsafe cs' => ("unsafe-ok", cs')
wneuper@339
   123
		| Updated (cs' as (_,_,(_,p'))) =>
wneuper@339
   124
		  (*ev.SEVER.tacs like Begin_Trans*)
wneuper@339
   125
		  (if p' = ([],Res) then "end-of-calculation" else "ok", 
wneuper@339
   126
		   cs')(*for -"-  user to ask ? *)
wneuper@339
   127
	   end
wneuper@339
   128
    end;
wneuper@339
   129
wneuper@339
   130
wneuper@339
   131
(*------------------------------------------------------------------
wneuper@339
   132
fun init_detail ptp = e_calcstate;(*15.8.03.MISSING-->solve.sml!?*)
wneuper@339
   133
(*----------------------------------------------------from solve.sml*)
wneuper@339
   134
  | nxt_solv (Detail_Set'(thy', rls, t)) (pt, p) =
wneuper@339
   135
    let (*val rls = the (assoc(!ruleset',rls'))
wneuper@339
   136
	    handle _ => raise error ("solve: '"^rls'^"' not known");*)
wneuper@339
   137
	val thy = assoc_thy thy';
wneuper@339
   138
        val (srls, sc, is) = 
wneuper@339
   139
	    case rls of
wneuper@339
   140
		Rrls {scr=sc as Rfuns {init_state=ii,...},...} => 
wneuper@339
   141
		(e_rls, sc, RrlsState (ii t))
wneuper@339
   142
	      | Rls {srls=srls,scr=sc as Script s,...} => 
wneuper@339
   143
		(srls, sc, ScrState ([(one_scr_arg s,t)], [], 
wneuper@339
   144
			       None, e_term, Sundef, true));
wneuper@339
   145
	val pt = update_tac pt (fst p) (Detail_Set (id_rls rls));
wneuper@339
   146
	val (p,cid,_,pt) = generate1 thy (Begin_Trans' t) is p pt;
wneuper@339
   147
	val nx = (tac_2tac o fst3) (next_tac (thy',srls) (pt,p) sc is);
wneuper@339
   148
	val aopt = applicable_in p pt nx;
wneuper@339
   149
    in case aopt of
wneuper@339
   150
	   Notappl s => raise error ("solve Detail_Set: "^s)
wneuper@339
   151
	 (* val Appl m = aopt;
wneuper@339
   152
	    *)
wneuper@339
   153
	 | Appl m => solve ("discardFIXME",m) p pt end
wneuper@339
   154
------------------------------------------------------------------*)
wneuper@339
   155
wneuper@339
   156
wneuper@339
   157
(*iterated by nxt_me; there (the resulting) ptp dropped
wneuper@339
   158
  may call nxt_solve Apply_Method --- thus evaluated here after solve.sml*)
wneuper@339
   159
fun nxt_specify_ (ptp as (pt, pos as (p,p_))) =
wneuper@339
   160
(* val (ptp as (pt, pos as (p,p_))) = ptp;
wneuper@339
   161
   val (ptp as (pt, pos as (p,p_))) = (pt,ip);
wneuper@339
   162
   *)
wneuper@339
   163
    let val pblobj as (PblObj{meth,origin=origin as (oris,(dI',pI',mI'),_),
wneuper@339
   164
			      probl,spec=(dI,pI,mI),...}) = get_obj I pt p;
wneuper@339
   165
    in if just_created_ pblobj (*by Subproblem*) andalso origin <> e_origin
wneuper@339
   166
       then case mI' of
wneuper@339
   167
	 ["no_met"] => nxt_specif (Refine_Tacitly pI') (pt, (p,Pbl))
wneuper@339
   168
       | _ => nxt_specif (Model_Problem pI') (pt, (p,Pbl))
wneuper@339
   169
       else let val cpI = if pI = e_pblID then pI' else pI;
wneuper@339
   170
		val cmI = if mI = e_metID then mI' else mI;
wneuper@339
   171
		val {ppc,prls,where_,...} = get_pbt cpI;
wneuper@339
   172
		val pre = check_preconds thy prls where_ probl;
wneuper@339
   173
		val pb = foldl and_ (true, map fst pre);
wneuper@357
   174
		(*FIXME.WN0308:    ~~~~~: just check true in itms of pbl/met?*)
wneuper@339
   175
		val (_,tac) =
wneuper@358
   176
		    nxt_spec p_ pb oris (dI',pI',mI') (probl,meth) 
wneuper@339
   177
			     (ppc,(#ppc o get_met) cmI) (dI,pI,mI);
wneuper@339
   178
	    in case tac of
wneuper@339
   179
		   Apply_Method mI => 
wneuper@359
   180
(* val Apply_Method mI = tac;
wneuper@359
   181
   *)
wneuper@339
   182
		   nxt_solv (Apply_Method' (mI, None, e_istate)) e_istate ptp
wneuper@339
   183
		 | _ => nxt_specif tac ptp end
wneuper@339
   184
    end;
wneuper@339
   185
wneuper@339
   186
wneuper@339
   187
(*WN11.9.03--- was only for hide, detail --> dialog ---------
wneuper@339
   188
(*
wneuper@339
   189
val nxt_me = fn
wneuper@339
   190
  : pblID
wneuper@339
   191
    -> (ptree * pos') *             : always the latest ovewriting the others
wneuper@339
   192
       (tac * tac_ * istate) list   : new tacs found PREpended to others
wneuper@339
   193
                                   -"- calcstate (typeinference doesn get it)
wneuper@339
   194
       -> detail * detail -> 
wneuper@339
   195
       hid ->                       : handles packages of tacs (eg. modeling)
wneuper@339
   196
       nxt_                                        
wneuper@339
   197
*)
wneuper@339
   198
fun nxt_me _ _ _ Hmodel = raise error "nxt_me: not impl. for Hmodel"
wneuper@339
   199
  | nxt_me _ _ _ Hspecify = raise error "nxt_me: not impl. for Hspecify"
wneuper@339
   200
  | nxt_me _ _ _ Happly = raise error "nxt_me: not impl. for Happly"
wneuper@339
   201
(* val ((ptp as (_,(_,p_)), tacis), (hi, de)) = ((ptp, []), (hide, detail));
wneuper@339
   202
   *)
wneuper@339
   203
  | nxt_me pI (ptp as (_,([],Res)), tacis) _ _ = Nexts (ptp, tacis)
wneuper@339
   204
  | nxt_me pI ((ptp as (_,(_,p_)), tacis):calcstate) (hi, de) _(*Hundef,Htac*)=
wneuper@339
   205
(* val ((ptp as (_,(_,p_)), tacis), (hi, de)) = ((ptp, []), (hide, detail));
wneuper@339
   206
   val ((ptp as (_,(_,p_)), []   ), (hi, de)) = ((ptp, []), (hide, detail));
wneuper@339
   207
   *)
wneuper@339
   208
    let val x = (if p_ mem [Pbl,Met]
wneuper@339
   209
		 then nxt_specify_ ptp else nxt_solve_ ptp)
wneuper@339
   210
	    handle _ => (ptp, []) (*e.g. by Add_Given "equality"///*)
wneuper@339
   211
    in case x of 
wneuper@339
   212
	   (_,[]) => HElpless
wneuper@339
   213
	 | (cs as (ptp, (tac,_,_)::_)) =>
wneuper@339
   214
	   let val (cs as (ptp, tacis' as (tac,_,_)::_)) =
wneuper@339
   215
		   if is_detail pI tac de then init_detail ptp else cs
wneuper@339
   216
	   in case is_hide pI tac hi of
wneuper@339
   217
		  Show => Nexts (ptp, tacis' @ tacis)
wneuper@339
   218
		| hid => 
wneuper@339
   219
		  nxt_me pI (ptp, tacis' @ tacis) (hi, de) hid
wneuper@339
   220
	   end
wneuper@339
   221
    end;
wneuper@339
   222
------------------------------------------------------------------*)
wneuper@339
   223
wneuper@339
   224
(*.does a step forward; returns tactic used, ctree updated
wneuper@339
   225
arg ip: 
wneuper@339
   226
    calcstate
wneuper@339
   227
.*)
wneuper@339
   228
fun step ((ip as (_,p_)):pos') ((ptp as (pt,p), tacis):calcstate) =
wneuper@339
   229
(* val (ip as (_,p_), (ptp as (pt,p), tacis)) = (get_pos 1 1, get_calc 1);
wneuper@339
   230
   val (ip as (_,p_), (ptp as (pt,p), tacis)) = (ip,cs);
wneuper@339
   231
   val (ip as (_,p_), (ptp as (pt,p), tacis)) = (p, ((pt, e_pos'),[]));
wneuper@339
   232
   *)
wneuper@339
   233
    let val pIopt = get_pblID (pt,ip);
wneuper@339
   234
    in if p = ([],Res) orelse ip = ([],Res)
wneuper@339
   235
       then ("end-of-calculation",(tacis, [], ptp):calcstate') else
wneuper@339
   236
       case tacis of
wneuper@339
   237
	   (_::_) =>
wneuper@339
   238
(* val((tac,_,_)::_) = tacis;
wneuper@339
   239
   *) 
wneuper@339
   240
	   if ip = p 
wneuper@339
   241
	   then let val (pt',c',p') = generate tacis (pt,[],p)
wneuper@339
   242
		in ("ok", (tacis, c', (pt', p'))) end
wneuper@339
   243
	   else (case (if p_ mem [Pbl,Met]
wneuper@339
   244
		       then nxt_specify_ (pt,ip) else nxt_solve_ (pt,ip))
wneuper@339
   245
		      handle _ => ([],[],ptp)(*e.g.by Add_Given "equality///"*)
wneuper@339
   246
		  of cs as ([],_,_) => ("helpless", cs)
wneuper@339
   247
		   | cs => ("ok", cs))
wneuper@339
   248
	 | _ => (case pIopt of
wneuper@339
   249
		     None => ("no-fmz-spec", ([], [], ptp))
wneuper@339
   250
		   | Some pI =>
wneuper@339
   251
(* val Some pI = pIopt; 
wneuper@339
   252
   val cs = (if p_ mem [Pbl,Met] andalso is_none (get_obj g_env pt (fst p))
wneuper@339
   253
	     then nxt_specify_ (pt,ip) else nxt_solve_ (pt,ip))
wneuper@339
   254
       handle _ => ([], ptp);
wneuper@339
   255
   *)
wneuper@339
   256
		     (case (if p_ mem [Pbl,Met]
wneuper@339
   257
			       andalso is_none (get_obj g_env pt (fst p))
wneuper@339
   258
			    (*^^^^^^^^: Apply_Method without init_form*)
wneuper@339
   259
			    then nxt_specify_ (pt,ip) else nxt_solve_ (pt,ip))
wneuper@339
   260
			   handle _ => ([],[],ptp)(*e.g.by Add_Giv"equality/"*)
wneuper@339
   261
		       of cs as ([],_,_) => ("helpless", cs)
wneuper@339
   262
			| cs => ("ok", cs)))
wneuper@339
   263
    end;
wneuper@339
   264
wneuper@339
   265
wneuper@339
   266
wneuper@339
   267
(* is_complete_mod ptp;
wneuper@339
   268
   is_complete_spec ptp;
wneuper@339
   269
   get_obj g_form pt [1];
wneuper@339
   270
   print_depth 11;pt;print_depth 3;
wneuper@339
   271
wneuper@339
   272
   val (str, (_, (pt',p'))) = step ip cs;
wneuper@339
   273
   get_obj g_form pt [1];
wneuper@339
   274
wneuper@339
   275
   val (ip, cs as (ptp as (pt,p),tacis)) = (get_pos cI 1, get_calc cI);
wneuper@339
   276
wneuper@339
   277
   val (c, ip, cs as (ptp as (_,p),tacis)) = ([]:pos' list, pold, get_calc cI);
wneuper@339
   278
   val (Step s) = auto;
wneuper@339
   279
   *) 
wneuper@339
   280
fun autocalc c ip (cs as (ptp as (_,p),tacis)) (Step s) =
wneuper@339
   281
    if s <= 1 
wneuper@339
   282
    then case tacis of
wneuper@339
   283
	     _::_ => (*if ip = p then ("ok", generate tacis ptp)##DONE IN step#
wneuper@339
   284
		     else*) let val (str, (_, c', ptp)) = step ip cs;(*1*)
wneuper@339
   285
			  (*at least does 1 step, ev.1 too much*)
wneuper@339
   286
			  in (str, c@c', ptp) end
wneuper@339
   287
	   | _ => let val (str, (_, c', ptp)) = step ip cs
wneuper@339
   288
		  in (str, c@c', ptp) end
wneuper@339
   289
    else (case tacis of
wneuper@339
   290
	     _::_ => (*if ip = p then
wneuper@339
   291
			 let val ptp as (_, p) = generate tacis ptp
wneuper@339
   292
			 in autocalc p (ptp, []) (Step(s-1-(length tacis))) end
wneuper@339
   293
		     else*) let val (str, (_, c', ptp as (_, p))) = step ip cs;
wneuper@339
   294
			  in if str = "ok" 
wneuper@339
   295
			     then autocalc (c@c') p (ptp,[]) (Step(s-1))
wneuper@339
   296
			     else (str, c@c', ptp) end
wneuper@339
   297
	   | _ => let val (str, (_, c', ptp as (_, p))) = step ip cs;
wneuper@339
   298
		  in if str = "ok" 
wneuper@339
   299
		     then autocalc (c@c') p (ptp, []) (Step (s-1)) 
wneuper@339
   300
		     else (str, c@c', ptp) end)
wneuper@339
   301
(*handles autoord <= 3, autoord > 3 handled by all_/complete_solve*)
wneuper@339
   302
  | autocalc c (pos as (_,p_)) ((pt,_), _(*tacis would help 1x in solve*))auto=
wneuper@339
   303
(* val (pos as (_,p_), ((pt,_), _)) = (get_pos cI 1, get_calc cI);
wneuper@339
   304
   autocalc (get_pos cI 1) (get_calc cI) auto;
wneuper@339
   305
wneuper@339
   306
  val (c:pos' list, (pos as (_,p_)),((pt,_),_),auto) = 
wneuper@339
   307
      ([], pold, get_calc cI, auto);
wneuper@339
   308
   *)
wneuper@339
   309
     if autoord auto > 3 andalso just_created (pt, pos)
wneuper@339
   310
     then let val ptp = all_modspec (pt, pos);
wneuper@339
   311
	  in all_solve auto c ptp end
wneuper@339
   312
     else
wneuper@339
   313
	 if p_ mem [Pbl, Met]
wneuper@339
   314
	 then if not (is_complete_mod (pt, pos))
wneuper@339
   315
	      then let val ptp = complete_mod (pt, pos)
wneuper@339
   316
		   in if autoord auto < 3 then ("ok", c, ptp)
wneuper@339
   317
		      else 
wneuper@339
   318
			  if not (is_complete_spec ptp)
wneuper@339
   319
			  then let val ptp = complete_spec ptp
wneuper@339
   320
			       in if autoord auto = 3 then ("ok", c, ptp)
wneuper@339
   321
				  else all_solve auto c ptp
wneuper@339
   322
			       end
wneuper@339
   323
			  else if autoord auto = 3 then ("ok", c, ptp)
wneuper@339
   324
			  else all_solve auto c ptp 
wneuper@339
   325
		   end
wneuper@339
   326
	      else 
wneuper@339
   327
		  if not (is_complete_spec (pt,pos))
wneuper@339
   328
		  then let val ptp = complete_spec (pt, pos)
wneuper@339
   329
		       in if autoord auto = 3 then ("ok", c, ptp)
wneuper@339
   330
			  else all_solve auto c ptp
wneuper@339
   331
		       end
wneuper@339
   332
		  else if autoord auto = 3 then ("ok", c, (pt, pos))
wneuper@339
   333
		  else all_solve auto c (pt, pos)
wneuper@339
   334
	 else complete_solve auto c (pt, pos);
wneuper@339
   335
(* val pbl = get_obj g_pbl (fst ptp) [];
wneuper@339
   336
   val (oris,_,_) = get_obj g_origin (fst ptp) [];
wneuper@339
   337
*)    
wneuper@339
   338
wneuper@339
   339
wneuper@339
   340
wneuper@339
   341
wneuper@339
   342
wneuper@339
   343
fun trymatch pI pt (pos as (p,_)) =
wneuper@339
   344
    let val PblObj {probl,origin=(os,_,_),spec=(dI,_,mI),...} = get_obj I pt p
wneuper@339
   345
	val spec = (dI,pI,mI)
wneuper@339
   346
	val {ppc,where_,prls,...} = get_pbt pI
wneuper@339
   347
	val (_, (pbl, pre)) = match_itms_oris (assoc_thy "Isac.thy") probl 
wneuper@339
   348
				  (ppc,where_,prls) os
wneuper@339
   349
    in ModSpec (ocalhd_complete pbl pre spec,
wneuper@339
   350
		Pbl, e_term, pbl, pre, spec) end;
wneuper@339
   351
wneuper@339
   352
fun tryrefine pI pt (pos as (p,_)) =
wneuper@339
   353
    let val PblObj {probl,origin=(os,_,_),spec=(dI,_,mI),...} = get_obj I pt p
wneuper@339
   354
    in case refine_pbl (assoc_thy "Isac.thy") pI probl of
wneuper@339
   355
	   None => (*copy from trymatch*)
wneuper@339
   356
	   let val {ppc,where_,prls,...} = get_pbt pI
wneuper@339
   357
	       val (_, (pbl, pre)) = match_itms_oris (assoc_thy "Isac.thy") 
wneuper@339
   358
						     probl (ppc,where_,prls) os
wneuper@339
   359
	   in ModSpec (ocalhd_complete pbl pre (dI,pI,mI),
wneuper@339
   360
		       Pbl, e_term, pbl, pre, (dI,pI,mI)) end
wneuper@339
   361
	 | Some (pI, (pbl, pre)) => 
wneuper@339
   362
	   ModSpec (ocalhd_complete pbl pre (dI,pI,mI),
wneuper@339
   363
		    Pbl, e_term, pbl, pre, (dI,pI,mI)) 
wneuper@339
   364
    end;
wneuper@339
   365
wneuper@339
   366
(* val pos as (p,p_) = ip;
wneuper@339
   367
   *)
wneuper@339
   368
fun detailstep pt (pos as (p,p_):pos') = 
wneuper@339
   369
    let val nd = get_nd pt p
wneuper@339
   370
	val cn = children nd
wneuper@339
   371
    in if null cn andalso (is_rewset o (get_obj g_tac nd)) [] (*subnode!*)
wneuper@339
   372
       then detailrls pt pos
wneuper@339
   373
       else ("donesteps", pt(*, get_formress [] ((lev_on o lev_dn) p) cn*),
wneuper@339
   374
	     (p @ [length (children (get_nd pt p))], Res) ) 
wneuper@339
   375
    end;
wneuper@339
   376
wneuper@339
   377
wneuper@339
   378
wneuper@339
   379
(***. for mathematics authoring on sml-toplevel; no XML .***)
wneuper@339
   380
wneuper@339
   381
type NEW = int list;
wneuper@339
   382
(* val sp = (dI',pI',mI');
wneuper@339
   383
   *)
wneuper@339
   384
wneuper@339
   385
(*15.8.03 for me with loc_specify/solve, nxt_specify/solve
wneuper@339
   386
 delete as soon as TESTg_form -> _mout_ dropped*)
wneuper@339
   387
fun TESTg_form ptp =
wneuper@339
   388
(* val ptp = (pt,p);
wneuper@339
   389
   *) 
wneuper@339
   390
    let val (form,_,_) = pt_extract ptp
wneuper@339
   391
    in case form of
wneuper@339
   392
	   Form t => Form' (FormKF (~1,EdUndef,0,Nundef,term2str t))
wneuper@339
   393
	 | ModSpec (_,p_, head, gfr, pre, _) => 
wneuper@339
   394
	   Form' (PpcKF (0,EdUndef,0,Nundef,
wneuper@339
   395
			 (case p_ of Pbl => Problem[] | Met => Method[],
wneuper@339
   396
			  itms2itemppc (assoc_thy"Isac.thy") gfr pre)))
wneuper@339
   397
    end;
wneuper@339
   398
wneuper@339
   399
fun CalcTreeTEST [(fmz, sp):fmz] = 
wneuper@339
   400
(* val [(fmz, sp):fmz] = [(fmz, (dI',pI',mI'))];
wneuper@339
   401
   *)
wneuper@339
   402
    let (*val _ = states:= [];   WN050707*)
wneuper@339
   403
	val cs as ((pt,p), (tac,_,_)::_) = nxt_specify_init_calc (fmz, sp);
wneuper@339
   404
	val f = TESTg_form (pt,p);
wneuper@339
   405
(*	val _ = (add_calc cs;  IteratorTEST 1; moveActiveRootTEST 1);WN050707*)
wneuper@339
   406
    in (p, []:NEW, f, (tac2IDstr tac, tac), Sundef, pt) end; 
wneuper@339
   407
       
wneuper@339
   408
(*for tests > 15.8.03 after separation setnexttactic / nextTac:
wneuper@339
   409
  external view: me should be used by math-authors as done so far
wneuper@339
   410
  internal view: loc_specify/solve, nxt_specify/solve used
wneuper@339
   411
                 i.e. same as in setnexttactic / nextTac*)
wneuper@339
   412
(*ENDE TESTPHASE 08/10.03:
wneuper@339
   413
  NEW loeschen, eigene Version von locatetac, step
wneuper@339
   414
  meNEW, CalcTreeTEST: tac'_ -replace-> tac, remove [](cid) *)
wneuper@339
   415
wneuper@339
   416
wneuper@339
   417
fun me ((_,tac):tac'_) (p:pos') (_:NEW(*remove*)) (pt:ptree) =
wneuper@339
   418
(* val (_,tac) = nxt;
wneuper@339
   419
   *) let val (pt, p) = 
wneuper@339
   420
(* val (msg, (tacis, pos's, (pt',p'))) = locatetac tac (pt,p);
wneuper@339
   421
   (writeln o (itms2str thy)) (get_obj g_pbl pt' (fst p'));
wneuper@339
   422
   writeln( istate2str (get_istate pt' ([3],Res)));
wneuper@339
   423
   term2str (fst (get_obj g_result pt' [3]));
wneuper@339
   424
   val (pt,p) = (pt',p');
wneuper@339
   425
   *)
wneuper@339
   426
	    case locatetac tac (pt,p) of
wneuper@339
   427
		("ok", (_, _, ptp))  => ptp
wneuper@339
   428
	      | ("unsafe-ok", (_, _, ptp)) => ptp
wneuper@339
   429
	      | ("not-applicable",_) => (pt, p)
wneuper@339
   430
	      | ("end-of-calculation", (_, _, ptp)) => ptp
wneuper@339
   431
	      | ("failure",_) => raise error "sys-error";
wneuper@339
   432
	val (_, ts) = 
wneuper@339
   433
(* (writeln o (itms2str thy)) (get_obj g_pbl pt (fst p));
wneuper@359
   434
   val (eee, (ts, _, (pt'',_))) = step p ((pt, e_pos'),[]);
wneuper@339
   435
   (writeln o (itms2str thy)) (get_obj g_pbl pt'' (fst p));
wneuper@339
   436
   *)
wneuper@339
   437
	    (case step p ((pt, e_pos'),[]) of
wneuper@339
   438
		 ("ok", (ts as (tac,_,_)::_, _, _)) => ("",ts)
wneuper@339
   439
	       | ("helpless",_) => ("helpless: cannot propose tac", [])
wneuper@339
   440
	       | ("no-fmz-spec",_) => raise error "no-fmz-spec"
wneuper@339
   441
	       | ("end-of-calculation", (ts, _, _)) => ("",ts))
wneuper@339
   442
	    handle _ => raise error "sys-error";
wneuper@339
   443
	val tac = case ts of ((tac,_,_)::_) => tac 
wneuper@339
   444
			   | _ => if p = ([],Res) then End_Proof'
wneuper@339
   445
				  else Empty_Tac;
wneuper@339
   446
    in (p:pos',[]:NEW, TESTg_form (pt, p), 
wneuper@339
   447
	(tac2IDstr tac, tac):tac'_, Sundef, pt) end;
wneuper@339
   448
(*
wneuper@339
   449
end
wneuper@339
   450
wneuper@339
   451
open mathengine;
wneuper@360
   452
*)
wneuper@360
   453
wneuper@360
   454
fun f2str (Form' (FormKF (_, _, _, _, cterm'))) = cterm';