src/Tools/isac/Interpret/mathengine.sml
changeset 59405 49d7d410b83c
parent 59395 862eb17f9e16
child 59411 3e241a6938ce
equal deleted inserted replaced
59404:6a2753b8d70c 59405:49d7d410b83c
    15   val locatetac :
    15   val locatetac :
    16     Tac.tac -> Ctree.state -> string * (Generate.taci list * Ctree.pos' list * (Ctree.state))
    16     Tac.tac -> Ctree.state -> string * (Generate.taci list * Ctree.pos' list * (Ctree.state))
    17   val step : Ctree.pos' -> Chead.calcstate -> string * Chead.calcstate'
    17   val step : Ctree.pos' -> Chead.calcstate -> string * Chead.calcstate'
    18   val detailstep :
    18   val detailstep :
    19     Ctree.ctree -> Ctree.pos' -> string * Ctree.ctree * Ctree.pos'
    19     Ctree.ctree -> Ctree.pos' -> string * Ctree.ctree * Ctree.pos'
    20   val get_pblID : Ctree.state -> pblID option
    20   val get_pblID : Ctree.state -> Celem.pblID option
    21 
    21 
    22   val initcontext_met : Ctree.ctree -> Ctree.pos' -> bool * string list * scr * Model.itm list * (bool * term) list
    22   val initcontext_met : Ctree.ctree -> Ctree.pos' -> bool * string list * Celem.scr * Model.itm list * (bool * term) list
    23   val initcontext_pbl : Ctree.ctree -> Ctree.pos' -> bool * string list * term * Model.itm list * (bool * term) list
    23   val initcontext_pbl : Ctree.ctree -> Ctree.pos' -> bool * string list * term * Model.itm list * (bool * term) list
    24   val context_met : metID -> Ctree.ctree -> Ctree.pos -> bool * metID * scr * Model.itm list * (bool * term) list
    24   val context_met : Celem.metID -> Ctree.ctree -> Ctree.pos -> bool * Celem.metID * Celem.scr * Model.itm list * (bool * term) list
    25   val context_pbl : pblID -> Ctree.ctree -> Ctree.pos -> bool * pblID * term * Model.itm list * (bool * term) list
    25   val context_pbl : Celem.pblID -> Ctree.ctree -> Ctree.pos -> bool * Celem.pblID * term * Model.itm list * (bool * term) list
    26   val set_method : metID -> Ctree.state -> Ctree.ctree * Ctree.ocalhd
    26   val set_method : Celem.metID -> Ctree.state -> Ctree.ctree * Ctree.ocalhd
    27   val set_problem : pblID -> Ctree.state -> Ctree.ctree * Ctree.ocalhd
    27   val set_problem : Celem.pblID -> Ctree.state -> Ctree.ctree * Ctree.ocalhd
    28   val set_theory : thyID -> Ctree.state -> Ctree.ctree * Ctree.ocalhd
    28   val set_theory : Celem.thyID -> Ctree.state -> Ctree.ctree * Ctree.ocalhd
    29   val tryrefine : pblID -> Ctree.ctree -> Ctree.pos' -> bool * pblID * term * Model.itm list * (bool * term) list
    29   val tryrefine : Celem.pblID -> Ctree.ctree -> Ctree.pos' -> bool * Celem.pblID * term * Model.itm list * (bool * term) list
    30 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
    30 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
    31   val CalcTreeTEST : Selem.fmz list -> Ctree.pos' * NEW * Generate.mout * (string * Tac.tac) * Selem.safe * Ctree.ctree
    31   val CalcTreeTEST : Selem.fmz list -> Ctree.pos' * NEW * Generate.mout * (string * Tac.tac) * Selem.safe * Ctree.ctree
    32   val f2str : Generate.mout -> cterm'
    32   val f2str : Generate.mout -> Celem.cterm'
    33 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
    33 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
    34   type nxt_
    34   type nxt_
    35   type lOc_
    35   type lOc_
    36   val loc_solve_ : string * Tac.tac_ -> Ctree.ctree *  Ctree.pos' -> lOc_
    36   val loc_solve_ : string * Tac.tac_ -> Ctree.ctree *  Ctree.pos' -> lOc_
    37   val loc_specify_ : Tac.tac_ -> Ctree.state -> lOc_
    37   val loc_specify_ : Tac.tac_ -> Ctree.state -> lOc_
    51 fun get_pblID (pt, (p, _): Ctree.pos') =
    51 fun get_pblID (pt, (p, _): Ctree.pos') =
    52   let val p' = Ctree.par_pblobj pt p
    52   let val p' = Ctree.par_pblobj pt p
    53   	val (_, pI, _) = Ctree.get_obj Ctree.g_spec pt p'
    53   	val (_, pI, _) = Ctree.get_obj Ctree.g_spec pt p'
    54   	val (_, (_, oI, _), _) = Ctree.get_obj Ctree.g_origin pt p'
    54   	val (_, (_, oI, _), _) = Ctree.get_obj Ctree.g_origin pt p'
    55   in
    55   in
    56     if pI <> e_pblID
    56     if pI <> Celem.e_pblID
    57     then SOME pI
    57     then SOME pI
    58     else
    58     else
    59       if oI <> e_pblID then SOME oI else NONE end;
    59       if oI <> Celem.e_pblID then SOME oI else NONE end;
    60 
    60 
    61 datatype lOc_ =
    61 datatype lOc_ =
    62   ERror of string              (*after loc_specify, loc_solve*)
    62   ERror of string              (*after loc_specify, loc_solve*)
    63 | UNsafe of Chead.calcstate'   (*after loc_specify, loc_solve*)
    63 | UNsafe of Chead.calcstate'   (*after loc_specify, loc_solve*)
    64 | Updated of Chead.calcstate'  (*after loc_specify, loc_solve*)
    64 | Updated of Chead.calcstate'  (*after loc_specify, loc_solve*)
   121       case mI' of
   121       case mI' of
   122         ["no_met"] => Chead.nxt_specif (Tac.Refine_Tacitly pI') (pt, (p, Ctree.Pbl))
   122         ["no_met"] => Chead.nxt_specif (Tac.Refine_Tacitly pI') (pt, (p, Ctree.Pbl))
   123       | _ => Chead.nxt_specif Tac.Model_Problem (pt, (p, Ctree.Pbl))
   123       | _ => Chead.nxt_specif Tac.Model_Problem (pt, (p, Ctree.Pbl))
   124     else 
   124     else 
   125       let 
   125       let 
   126         val cpI = if pI = e_pblID then pI' else pI;
   126         val cpI = if pI = Celem.e_pblID then pI' else pI;
   127   	    val cmI = if mI = e_metID then mI' else mI;
   127   	    val cmI = if mI = Celem.e_metID then mI' else mI;
   128   	    val {ppc, prls, where_, ...} = Specify.get_pbt cpI;
   128   	    val {ppc, prls, where_, ...} = Specify.get_pbt cpI;
   129   	    val pre = Stool.check_preconds "thy 100820" prls where_ probl;
   129   	    val pre = Stool.check_preconds "thy 100820" prls where_ probl;
   130   	    val pb = foldl and_ (true, map fst pre);
   130   	    val pb = foldl and_ (true, map fst pre);
   131   	    (*FIXME.WN0308:    ~~~~~: just check true in itms of pbl/met?*)
   131   	    (*FIXME.WN0308:    ~~~~~: just check true in itms of pbl/met?*)
   132   	    val (_, tac) =
   132   	    val (_, tac) =
   280       case Ctree.get_obj I pt p of
   280       case Ctree.get_obj I pt p of
   281         Ctree.PblObj {probl, origin = (os, (_, pI, _), hdl), spec=(_, pI', _), ...}
   281         Ctree.PblObj {probl, origin = (os, (_, pI, _), hdl), spec=(_, pI', _), ...}
   282           => (probl, os, pI, hdl, pI')
   282           => (probl, os, pI, hdl, pI')
   283       | Ctree.PrfObj _ => error "initcontext_pbl: uncovered case"
   283       | Ctree.PrfObj _ => error "initcontext_pbl: uncovered case"
   284   	val pblID =
   284   	val pblID =
   285   	  if pI' = e_pblID 
   285   	  if pI' = Celem.e_pblID 
   286   		then (* TODO.WN051125 (#init o get_pbt) pI *) takelast (2, pI)
   286   		then (* TODO.WN051125 (#init o get_pbt) pI *) takelast (2, pI)
   287   		else pI'
   287   		else pI'
   288   	val {ppc, where_, prls, ...} = Specify.get_pbt pblID
   288   	val {ppc, where_, prls, ...} = Specify.get_pbt pblID
   289   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (assoc_thy "Isac") probl (ppc,where_,prls) os
   289   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (Celem.assoc_thy "Isac") probl (ppc, where_, prls) os
   290   in
   290   in
   291     (model_ok, pblID, hdl, pbl, pre)
   291     (model_ok, pblID, hdl, pbl, pre)
   292   end
   292   end
   293 
   293 
   294 fun initcontext_met pt (p,_) =
   294 fun initcontext_met pt (p,_) =
   295   let
   295   let
   296     val (meth, os, mI, mI') =
   296     val (meth, os, mI, mI') =
   297       case Ctree.get_obj I pt p of
   297       case Ctree.get_obj I pt p of
   298         Ctree.PblObj {meth, origin = (os, (_, _, mI), _), spec=(_, _, mI'), ...} => (meth, os, mI, mI')
   298         Ctree.PblObj {meth, origin = (os, (_, _, mI), _), spec=(_, _, mI'), ...} => (meth, os, mI, mI')
   299       | Ctree.PrfObj _ => error "initcontext_met: uncovered case"
   299       | Ctree.PrfObj _ => error "initcontext_met: uncovered case"
   300   	val metID = if mI' = e_metID 
   300   	val metID = if mI' = Celem.e_metID 
   301   		    then (*TODO.WN051125 (#init o get_pbt) pI *) takelast (2, mI)
   301   		    then (*TODO.WN051125 (#init o get_pbt) pI *) takelast (2, mI)
   302   		    else mI'
   302   		    else mI'
   303   	val {ppc, pre, prls, scr, ...} = Specify.get_met metID
   303   	val {ppc, pre, prls, scr, ...} = Specify.get_met metID
   304   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (assoc_thy "Isac") meth (ppc,pre,prls) os
   304   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (Celem.assoc_thy "Isac") meth (ppc,pre,prls) os
   305   in
   305   in
   306     (model_ok, metID, scr, pbl, pre)
   306     (model_ok, metID, scr, pbl, pre)
   307   end
   307   end
   308 
   308 
   309 (* match the model of a problem at pos p with the model-pattern of the problem with pblID *)
   309 (* match the model of a problem at pos p with the model-pattern of the problem with pblID *)
   312     val (probl, os, hdl) =
   312     val (probl, os, hdl) =
   313       case Ctree.get_obj I pt p of
   313       case Ctree.get_obj I pt p of
   314         Ctree.PblObj {probl,origin = (os, _, hdl),...} => (probl, os, hdl)
   314         Ctree.PblObj {probl,origin = (os, _, hdl),...} => (probl, os, hdl)
   315       | Ctree.PrfObj _ => error "context_pbl: uncovered case"
   315       | Ctree.PrfObj _ => error "context_pbl: uncovered case"
   316   	val {ppc,where_,prls,...} = Specify.get_pbt pI
   316   	val {ppc,where_,prls,...} = Specify.get_pbt pI
   317   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (assoc_thy "Isac") probl (ppc,where_,prls) os
   317   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (Celem.assoc_thy "Isac") probl (ppc,where_,prls) os
   318   in
   318   in
   319     (model_ok, pI, hdl, pbl, pre)
   319     (model_ok, pI, hdl, pbl, pre)
   320   end
   320   end
   321 
   321 
   322 fun context_met mI pt p =
   322 fun context_met mI pt p =
   324     val (meth, os) =
   324     val (meth, os) =
   325       case Ctree.get_obj I pt p of
   325       case Ctree.get_obj I pt p of
   326         Ctree.PblObj {meth, origin = (os, _, _),...} => (meth, os)
   326         Ctree.PblObj {meth, origin = (os, _, _),...} => (meth, os)
   327       | Ctree.PrfObj _ => error "context_met: uncovered case"
   327       | Ctree.PrfObj _ => error "context_met: uncovered case"
   328   	val {ppc,pre,prls,scr,...} = Specify.get_met mI
   328   	val {ppc,pre,prls,scr,...} = Specify.get_met mI
   329   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (assoc_thy "Isac") meth (ppc,pre,prls) os
   329   	val (model_ok, (pbl, pre)) = Specify.match_itms_oris (Celem.assoc_thy "Isac") meth (ppc,pre,prls) os
   330   in
   330   in
   331     (model_ok, mI, scr, pbl, pre)
   331     (model_ok, mI, scr, pbl, pre)
   332   end
   332   end
   333 
   333 
   334 fun tryrefine pI pt (p,_) =
   334 fun tryrefine pI pt (p,_) =
   336     val (probl, os, hdl) =
   336     val (probl, os, hdl) =
   337       case Ctree.get_obj I pt p of
   337       case Ctree.get_obj I pt p of
   338         Ctree.PblObj {probl, origin = (os, _, hdl), ...} => (probl, os, hdl)
   338         Ctree.PblObj {probl, origin = (os, _, hdl), ...} => (probl, os, hdl)
   339       | Ctree.PrfObj _ => error "context_met: uncovered case"
   339       | Ctree.PrfObj _ => error "context_met: uncovered case"
   340   in
   340   in
   341     case Specify.refine_pbl (assoc_thy "Isac") pI probl of
   341     case Specify.refine_pbl (Celem.assoc_thy "Isac") pI probl of
   342   	  NONE => (*copy from context_pbl*)
   342   	  NONE => (*copy from context_pbl*)
   343   	    let
   343   	    let
   344   	      val {ppc,where_,prls,...} = Specify.get_pbt pI
   344   	      val {ppc,where_,prls,...} = Specify.get_pbt pI
   345   	      val (_, (pbl, pre)) = Specify.match_itms_oris (assoc_thy "Isac") probl (ppc,where_,prls) os
   345   	      val (_, (pbl, pre)) = Specify.match_itms_oris (Celem.assoc_thy "Isac") probl (ppc,where_,prls) os
   346         in
   346         in
   347           (false, pI, hdl, pbl, pre)
   347           (false, pI, hdl, pbl, pre)
   348         end
   348         end
   349   	| SOME (pI, (pbl, pre)) => (true, pI, hdl, pbl, pre) 
   349   	| SOME (pI, (pbl, pre)) => (true, pI, hdl, pbl, pre) 
   350   end
   350   end
   372 fun TESTg_form ptp =
   372 fun TESTg_form ptp =
   373   let
   373   let
   374     val (form, _, _) = Chead.pt_extract ptp
   374     val (form, _, _) = Chead.pt_extract ptp
   375   in
   375   in
   376     case form of
   376     case form of
   377       Ctree.Form t => Generate.FormKF (term2str t)
   377       Ctree.Form t => Generate.FormKF (Celem.term2str t)
   378     | Ctree.ModSpec (_, p_, _, gfr, pre, _) =>
   378     | Ctree.ModSpec (_, p_, _, gfr, pre, _) =>
   379       Generate.PpcKF (
   379       Generate.PpcKF (
   380         (case p_ of Ctree.Pbl => Generate.Problem []
   380         (case p_ of Ctree.Pbl => Generate.Problem []
   381           | Ctree.Met => Generate.Method []
   381           | Ctree.Met => Generate.Method []
   382           | _ => error "TESTg_form: uncovered case",
   382           | _ => error "TESTg_form: uncovered case",
   383  			Specify.itms2itemppc (assoc_thy"Isac") gfr pre))
   383  			Specify.itms2itemppc (Celem.assoc_thy"Isac") gfr pre))
   384    end
   384    end
   385 
   385 
   386 (* create a calc-tree; for use within sml: thus "^^^" NOT decoded to "^" etc;
   386 (* create a calc-tree; for use within sml: thus "^^^" NOT decoded to "^" etc;
   387    compare "fun CalcTree" which DOES decode                        *)
   387    compare "fun CalcTree" which DOES decode                        *)
   388 fun CalcTreeTEST [(fmz, sp)] = 
   388 fun CalcTreeTEST [(fmz, sp)] =