src/Tools/isac/Interpret/ctree.sml
changeset 59279 255c853ea2f0
parent 59278 a474900d5bd2
child 59280 ee5efb0697f6
equal deleted inserted replaced
59278:a474900d5bd2 59279:255c853ea2f0
   170   val lev_up : pos -> pos
   170   val lev_up : pos -> pos
   171   val lev_of : pos' -> int
   171   val lev_of : pos' -> int
   172   val pos_plus : int -> pos' -> pos'
   172   val pos_plus : int -> pos' -> pos'
   173   val lev_back' : pos' -> pos'                                                (* for inform.sml *)
   173   val lev_back' : pos' -> pos'                                                (* for inform.sml *)
   174 
   174 
   175   datatype ptree = EmptyPtree | Nd of ppobj * ptree list
   175   datatype ctree = EmptyPtree | Nd of ppobj * ctree list
   176   val e_ptree : ptree (* TODO: replace by EmptyPtree*)
   176   val e_ctree : ctree (* TODO: replace by EmptyPtree*)
   177   val existpt' : pos' -> ptree -> bool                                     (* for interface.sml *)
   177   val existpt' : pos' -> ctree -> bool                                     (* for interface.sml *)
   178   val exist_lev_on' : ptree -> pos' -> bool                                (* for interface.sml *)
   178   val exist_lev_on' : ctree -> pos' -> bool                                (* for interface.sml *)
   179   val is_interpos : pos' -> bool                                           (* for interface.sml *)
   179   val is_interpos : pos' -> bool                                           (* for interface.sml *)
   180   val lev_on' : ptree -> pos' -> pos'                                      (* for interface.sml *)
   180   val lev_on' : ctree -> pos' -> pos'                                      (* for interface.sml *)
   181   val lev_pred' : ptree -> pos' -> pos'                                    (* for interface.sml *)
   181   val lev_pred' : ctree -> pos' -> pos'                                    (* for interface.sml *)
   182   val move_up : pos -> ptree -> pos' -> pos'                          (* for interface.sml *)
   182   val move_up : pos -> ctree -> pos' -> pos'                          (* for interface.sml *)
   183   val movelevel_dn : pos -> ptree -> pos' -> pos'                          (* for interface.sml *)
   183   val movelevel_dn : pos -> ctree -> pos' -> pos'                          (* for interface.sml *)
   184   val movelevel_up : pos -> ptree -> pos' -> pos'                          (* for interface.sml *)
   184   val movelevel_up : pos -> ctree -> pos' -> pos'                          (* for interface.sml *)
   185   val movecalchd_up : ptree -> pos' -> pos'                                (* for interface.sml *)
   185   val movecalchd_up : ctree -> pos' -> pos'                                (* for interface.sml *)
   186   val par_pblobj : ptree -> pos -> pos
   186   val par_pblobj : ctree -> pos -> pos
   187   val ins_chn : ptree list -> ptree -> pos -> ptree                       (* for solve.sml *)
   187   val ins_chn : ctree list -> ctree -> pos -> ctree                       (* for solve.sml *)
   188   val children : ptree -> ptree list                                           (* for solve.sml *)
   188   val children : ctree -> ctree list                                           (* for solve.sml *)
   189   val get_nd : ptree -> pos -> ptree                                           (* for solve.sml *)
   189   val get_nd : ctree -> pos -> ctree                                           (* for solve.sml *)
   190   val just_created_ : ppobj -> bool                                       (* for mathengine.sml *)
   190   val just_created_ : ppobj -> bool                                       (* for mathengine.sml *)
   191   val just_created : ptree * pos' -> bool                                 (* for mathengine.sml *)
   191   val just_created : ctree * pos' -> bool                                 (* for mathengine.sml *)
   192   val is_curr_endof_calc : ptree -> pos' -> bool                           (* for interface.sml *)
   192   val is_curr_endof_calc : ctree -> pos' -> bool                           (* for interface.sml *)
   193   val e_origin : ori list * spec * term                                   (* for mathengine.sml *)
   193   val e_origin : ori list * spec * term                                   (* for mathengine.sml *)
   194 
   194 
   195   val move_dn : pos -> ptree -> pos' -> pos'
   195   val move_dn : pos -> ctree -> pos' -> pos'
   196   val is_pblobj : ppobj -> bool
   196   val is_pblobj : ppobj -> bool
   197   val is_pblobj' : ptree -> pos -> bool
   197   val is_pblobj' : ctree -> pos -> bool
   198   val is_pblnd : ptree -> bool
   198   val is_pblnd : ctree -> bool
   199   val last_onlev : ptree -> pos -> bool
   199   val last_onlev : ctree -> pos -> bool
   200 
   200 
   201   val g_spec : ppobj -> spec
   201   val g_spec : ppobj -> spec
   202   val g_loc : ppobj -> (istate * Proof.context) option * (istate * Proof.context) option
   202   val g_loc : ppobj -> (istate * Proof.context) option * (istate * Proof.context) option
   203   val g_form : ppobj -> term
   203   val g_form : ppobj -> term
   204   val g_pbl : ppobj -> itm list
   204   val g_pbl : ppobj -> itm list
   208   val g_tac : ppobj -> tac
   208   val g_tac : ppobj -> tac
   209   val g_domID : ppobj -> domID                           (* for appl.sml TODO: replace by thyID *)
   209   val g_domID : ppobj -> domID                           (* for appl.sml TODO: replace by thyID *)
   210   val g_env : ppobj -> (istate * Proof.context) option                          (* for appl.sml *)
   210   val g_env : ppobj -> (istate * Proof.context) option                          (* for appl.sml *)
   211 
   211 
   212   val g_origin : ppobj -> ori list * spec * term                              (* for script.sml *)
   212   val g_origin : ppobj -> ori list * spec * term                              (* for script.sml *)
   213   val get_loc : ptree -> pos' -> istate * Proof.context                       (* for script.sml *)
   213   val get_loc : ctree -> pos' -> istate * Proof.context                       (* for script.sml *)
   214   val get_istate : ptree -> pos' -> istate                                    (* for script.sml *)
   214   val get_istate : ctree -> pos' -> istate                                    (* for script.sml *)
   215   val get_ctxt : ptree -> pos' -> Proof.context
   215   val get_ctxt : ctree -> pos' -> Proof.context
   216   val get_obj : (ppobj -> 'a) -> ptree -> pos -> 'a
   216   val get_obj : (ppobj -> 'a) -> ctree -> pos -> 'a
   217   val get_curr_formula : ptree * pos' -> term
   217   val get_curr_formula : ctree * pos' -> term
   218   val get_assumptions_ : ptree -> pos' -> term list                             (* for appl.sml *)
   218   val get_assumptions_ : ctree -> pos' -> term list                             (* for appl.sml *)
   219 
   219 
   220   val append_result : ptree -> pos -> istate * Proof.context -> result ->
   220   val append_result : ctree -> pos -> istate * Proof.context -> result ->
   221     ostate -> ptree * 'a list
   221     ostate -> ctree * 'a list
   222   val append_atomic :                                                          (* for solve.sml *)
   222   val append_atomic :                                                          (* for solve.sml *)
   223      pos -> istate * Proof.context -> term -> tac -> result -> ostate -> ptree -> ptree
   223      pos -> istate * Proof.context -> term -> tac -> result -> ostate -> ctree -> ctree
   224   val cappend_atomic : ptree -> pos -> istate * Proof.context -> term -> tac -> result ->
   224   val cappend_atomic : ctree -> pos -> istate * Proof.context -> term -> tac -> result ->
   225     ostate -> ptree * pos' list
   225     ostate -> ctree * pos' list
   226   val cappend_form : ptree -> pos -> istate * Proof.context -> term -> ptree * pos' list
   226   val cappend_form : ctree -> pos -> istate * Proof.context -> term -> ctree * pos' list
   227   val cappend_problem : ptree -> pos -> istate * Proof.context -> fmz ->
   227   val cappend_problem : ctree -> pos -> istate * Proof.context -> fmz ->
   228     ori list * spec * term -> ptree * pos' list
   228     ori list * spec * term -> ctree * pos' list
   229 
   229 
   230   val update_branch : ptree -> pos -> branch -> ptree
   230   val update_branch : ctree -> pos -> branch -> ctree
   231   val update_ctxt : ptree -> pos -> Proof.context -> ptree
   231   val update_ctxt : ctree -> pos -> Proof.context -> ctree
   232   val update_env : ptree -> pos -> (istate * Proof.context) option -> ptree
   232   val update_env : ctree -> pos -> (istate * Proof.context) option -> ctree
   233   val update_oris : ptree -> pos -> ori list -> ptree
   233   val update_oris : ctree -> pos -> ori list -> ctree
   234   val update_orispec : ptree -> pos -> spec -> ptree
   234   val update_orispec : ctree -> pos -> spec -> ctree
   235   val update_pbl : ptree -> pos -> itm list -> ptree
   235   val update_pbl : ctree -> pos -> itm list -> ctree
   236   val update_pblppc : ptree -> pos -> itm list -> ptree (* =vvv= ? *)
   236   val update_pblppc : ctree -> pos -> itm list -> ctree (* =vvv= ? *)
   237   val update_pblID : ptree -> pos -> pblID -> ptree     (* =^^^= ? *)
   237   val update_pblID : ctree -> pos -> pblID -> ctree     (* =^^^= ? *)
   238   val update_met : ptree -> pos -> itm list -> ptree    (* =vvv= ? *)
   238   val update_met : ctree -> pos -> itm list -> ctree    (* =vvv= ? *)
   239   val update_metppc : ptree -> pos -> itm list -> ptree (* =^^^= ? *)
   239   val update_metppc : ctree -> pos -> itm list -> ctree (* =^^^= ? *)
   240   val update_metID : ptree -> pos -> metID -> ptree
   240   val update_metID : ctree -> pos -> metID -> ctree
   241   val update_domID : ptree -> pos -> domID -> ptree
   241   val update_domID : ctree -> pos -> domID -> ctree
   242   val update_spec : ptree -> pos -> spec -> ptree
   242   val update_spec : ctree -> pos -> spec -> ctree
   243   val update_tac : ptree -> pos -> tac -> ptree
   243   val update_tac : ctree -> pos -> tac -> ctree
   244 
   244 
   245   val e_ctxt : Proof.context
   245   val e_ctxt : Proof.context
   246   val is_e_ctxt : Proof.context -> bool                                         (* for appl.sml *)
   246   val is_e_ctxt : Proof.context -> bool                                         (* for appl.sml *)
   247   val new_val : term -> istate -> istate
   247   val new_val : term -> istate -> istate
   248   (* for calchead.sml *)
   248   (* for calchead.sml *)
   250   type ocalhd = bool * pos_ * term * itm list * (bool * term) list * spec
   250   type ocalhd = bool * pos_ * term * itm list * (bool * term) list * spec
   251   datatype ptform = Form of term | ModSpec of ocalhd
   251   datatype ptform = Form of term | ModSpec of ocalhd
   252   val get_somespec' : spec -> spec -> spec
   252   val get_somespec' : spec -> spec -> spec
   253   exception PTREE of string;
   253   exception PTREE of string;
   254   (* for appl.sml *)
   254   (* for appl.sml *)
   255   val par_pbl_det : ptree -> pos -> bool * pos * rls
   255   val par_pbl_det : ctree -> pos -> bool * pos * rls
   256   (* for rewtools.sml *)
   256   (* for rewtools.sml *)
   257   val rule2tac : theory -> (term * term) list -> rule -> tac
   257   val rule2tac : theory -> (term * term) list -> rule -> tac
   258   val eq_tac : tac * tac -> bool
   258   val eq_tac : tac * tac -> bool
   259   (* for script.sml *)
   259   (* for script.sml *)
   260   val rootthy : ptree -> theory
   260   val rootthy : ctree -> theory
   261 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
   261 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
   262   val update_loc' : ptree -> pos -> (istate * Proof.context) option * (istate * Proof.context) option -> ptree
   262   val update_loc' : ctree -> pos -> (istate * Proof.context) option * (istate * Proof.context) option -> ctree
   263   val append_problem : int list -> istate * Proof.context -> fmz -> ori list * spec * term -> ptree -> ptree
   263   val append_problem : int list -> istate * Proof.context -> fmz -> ori list * spec * term -> ctree -> ctree
   264   val g_res : ppobj -> term
   264   val g_res : ppobj -> term
   265   val pr_ptree : (pos -> ppobj -> string) -> ptree -> string
   265   val pr_ctree : (pos -> ppobj -> string) -> ctree -> string
   266   val pr_short : pos -> ppobj -> string
   266   val pr_short : pos -> ppobj -> string
   267   val existpt : pos -> ptree -> bool
   267   val existpt : pos -> ctree -> bool
   268   val is_empty_tac : tac -> bool
   268   val is_empty_tac : tac -> bool
   269   val e_subs : string list
   269   val e_subs : string list
   270   val e_sube : cterm' list
   270   val e_sube : cterm' list
   271   val g_branch : ppobj -> branch
   271   val g_branch : ppobj -> branch
   272   val g_ctxt : ppobj -> Proof.context
   272   val g_ctxt : ppobj -> Proof.context
   273   val g_fmz : ppobj -> fmz
   273   val g_fmz : ppobj -> fmz
   274   val get_allp : pos' list -> pos * (int list * pos_) -> ptree -> pos' list
   274   val get_allp : pos' list -> pos * (int list * pos_) -> ctree -> pos' list
   275   val get_allps : (pos * pos_) list -> posel list -> ptree list -> pos' list
   275   val get_allps : (pos * pos_) list -> posel list -> ctree list -> pos' list
   276   val get_allpos' : pos * posel -> ptree -> pos' list
   276   val get_allpos' : pos * posel -> ctree -> pos' list
   277   val get_allpos's : pos * posel -> ptree list -> (pos * pos_) list
   277   val get_allpos's : pos * posel -> ctree list -> (pos * pos_) list
   278   val cut_bottom : pos * posel -> ptree -> (ptree * pos' list) * bool
   278   val cut_bottom : pos * posel -> ctree -> (ctree * pos' list) * bool
   279   val cut_tree : ptree -> pos * 'a -> ptree * pos' list
   279   val cut_tree : ctree -> pos * 'a -> ctree * pos' list
   280   val cut_level : pos' list -> pos -> ptree -> int list * pos_ -> ptree * pos' list
   280   val cut_level : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
   281   val cut_level_'_ : pos' list -> pos -> ptree -> int list * pos_ -> ptree * pos' list
   281   val cut_level_'_ : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
   282   val get_trace : ptree -> int list -> int list -> int list list
   282   val get_trace : ctree -> int list -> int list -> int list list
   283   val subte2subst : term list -> (term * term) list
   283   val subte2subst : term list -> (term * term) list
   284   val branch2str : branch -> string
   284   val branch2str : branch -> string
   285 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
   285 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
   286 end
   286 end
   287 (*
   287 (*
   288 structure Ctree :
   288 structure Ctree :
   289 sig
   289 sig
   290   val Ets : ets exception PTREE of string
   290   val Ets : ets exception PTREE of string
   291   val append_atomic :
   291   val append_atomic :
   292      pos -> istate * Proof.context -> term -> tac -> term * term list -> ostate -> ptree -> ptree
   292      pos -> istate * Proof.context -> term -> tac -> term * term list -> ostate -> ctree -> ctree
   293   val append_form : int list -> istate * Proof.context -> term -> ptree -> ptree
   293   val append_form : int list -> istate * Proof.context -> term -> ctree -> ctree
   294   val append_parent : pos -> istate * Proof.context -> term -> tac -> branch -> ptree -> ptree
   294   val append_parent : pos -> istate * Proof.context -> term -> tac -> branch -> ctree -> ctree
   295   val append_problem : int list -> istate * Proof.context -> fmz -> ori list * spec * term -> ptree -> ptree
   295   val append_problem : int list -> istate * Proof.context -> fmz -> ori list * spec * term -> ctree -> ctree
   296   val append_result : ptree -> pos -> istate * Proof.context -> term * term list -> ostate -> ptree * 'a list
   296   val append_result : ctree -> pos -> istate * Proof.context -> term * term list -> ostate -> ctree * 'a list
   297   val appl_branch : (ppobj -> bool) * (posel -> ptree list -> ptree list) -> ptree -> int list -> ptree * bool
   297   val appl_branch : (ppobj -> bool) * (posel -> ctree list -> ctree list) -> ctree -> int list -> ctree * bool
   298   val appl_obj : (ppobj -> ppobj) -> ptree -> pos -> ptree
   298   val appl_obj : (ppobj -> ppobj) -> ctree -> pos -> ctree
   299   val appl_to_node : (ppobj -> ppobj) -> ptree -> ptree
   299   val appl_to_node : (ppobj -> ppobj) -> ctree -> ctree
   300   datatype branch = AndB | CollectB | IntersectB | MapB | NoBranch | OrB | SequenceB | TransitiveB
   300   datatype branch = AndB | CollectB | IntersectB | MapB | NoBranch | OrB | SequenceB | TransitiveB
   301   val branch2str : branch -> string
   301   val branch2str : branch -> string
   302   val cappend_atomic :
   302   val cappend_atomic :
   303      ptree -> pos -> istate * Proof.context -> term -> tac -> term * term list -> ostate -> ptree * pos' list
   303      ctree -> pos -> istate * Proof.context -> term -> tac -> term * term list -> ostate -> ctree * pos' list
   304   val cappend_form : ptree -> pos -> istate * Proof.context -> term -> ptree * pos' list
   304   val cappend_form : ctree -> pos -> istate * Proof.context -> term -> ctree * pos' list
   305   val cappend_parent : ptree -> pos -> istate * Proof.context -> term -> tac -> branch -> ptree * pos' list
   305   val cappend_parent : ctree -> pos -> istate * Proof.context -> term -> tac -> branch -> ctree * pos' list
   306   val cappend_problem :
   306   val cappend_problem :
   307      ptree -> int list -> istate * Proof.context -> fmz -> ori list * spec * term -> ptree * pos' list
   307      ctree -> int list -> istate * Proof.context -> fmz -> ori list * spec * term -> ctree * pos' list
   308   eqtype cellID
   308   eqtype cellID
   309   val children : ptree -> ptree list
   309   val children : ctree -> ctree list
   310   type cid = cellID list
   310   type cid = cellID list
   311   datatype con = land | lor
   311   datatype con = land | lor
   312   val cut_bottom : pos * posel -> ptree -> (ptree * pos' list) * bool
   312   val cut_bottom : pos * posel -> ctree -> (ctree * pos' list) * bool
   313   val cut_level : pos' list -> pos -> ptree -> int list * pos_ -> ptree * pos' list
   313   val cut_level : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
   314   val cut_level_'_ : pos' list -> pos -> ptree -> int list * pos_ -> ptree * pos' list
   314   val cut_level_'_ : pos' list -> pos -> ctree -> int list * pos_ -> ctree * pos' list
   315   val cut_levup : pos' list -> bool -> ptree -> ptree -> posel list * posel -> ptree -> ptree * pos' list
   315   val cut_levup : pos' list -> bool -> ctree -> ctree -> posel list * posel -> ctree -> ctree * pos' list
   316   val cut_tree : ptree -> pos * 'a -> ptree * pos' list
   316   val cut_tree : ctree -> pos * 'a -> ctree * pos' list
   317   val cutlevup : ppobj -> bool
   317   val cutlevup : ppobj -> bool
   318   val del_res : ppobj -> ppobj
   318   val del_res : ppobj -> ppobj
   319   val delete_result : ptree -> pos -> ptree
   319   val delete_result : ctree -> pos -> ctree
   320   val e_ctxt : Proof.context
   320   val e_ctxt : Proof.context
   321   val e_fmz : 'a list * spec
   321   val e_fmz : 'a list * spec
   322   val e_ocalhd : bool * pos_ * term * itm list * (bool * term) list * spec
   322   val e_ocalhd : bool * pos_ * term * itm list * (bool * term) list * spec
   323   val e_origin : ori list * spec * term
   323   val e_origin : ori list * spec * term
   324   val e_ptform : ptform
   324   val e_ptform : ptform
   325   val e_ptform' : ptform
   325   val e_ptform' : ptform
   326   val e_ptree : ptree
   326   val e_ctree : ctree
   327   val e_scrstate : scrstate
   327   val e_scrstate : scrstate
   328   val e_sube : cterm' list
   328   val e_sube : cterm' list
   329   val e_subs : string list
   329   val e_subs : string list
   330   val e_subte : term list
   330   val e_subte : term list
   331   val empty_envp : envp type env = (term * term) list
   331   val empty_envp : envp type env = (term * term) list
   332   type envp = (int * term list) list * (int * rls) list * (int * ets) list * (string * pos) list
   332   type envp = (int * term list) list * (int * rls) list * (int * ets) list * (string * pos) list
   333   val eq_tac : tac * tac -> bool type ets = (loc_ * (tac_ * env * env * term * term * safe)) list
   333   val eq_tac : tac * tac -> bool type ets = (loc_ * (tac_ * env * env * term * term * safe)) list
   334   val ets2s : loc_ * (tac_ * subst * subst * term * term * safe) -> string
   334   val ets2s : loc_ * (tac_ * subst * subst * term * term * safe) -> string
   335   val ets2str : ets -> string
   335   val ets2str : ets -> string
   336   val exist_lev_on' : ptree -> pos' -> bool
   336   val exist_lev_on' : ctree -> pos' -> bool
   337   val existpt : pos -> ptree -> bool
   337   val existpt : pos -> ctree -> bool
   338   val existpt' : pos' -> ptree -> bool
   338   val existpt' : pos' -> ctree -> bool
   339   type fmz = fmz_ * spec
   339   type fmz = fmz_ * spec
   340   type fmz_ = cterm' list
   340   type fmz_ = cterm' list
   341   val g_branch : ppobj -> branch
   341   val g_branch : ppobj -> branch
   342   val g_cell : ppobj -> lrd option
   342   val g_cell : ppobj -> lrd option
   343   val g_ctxt : ppobj -> Proof.context
   343   val g_ctxt : ppobj -> Proof.context
   344   val g_domID : ppobj -> domID
   344   val g_domID : ppobj -> domID
   345   val g_env : ppobj -> (istate * Proof.context) option
   345   val g_env : ppobj -> (istate * Proof.context) option
   346   val g_fmz : ppobj -> fmz
   346   val g_fmz : ppobj -> fmz
   347   val g_form : ppobj -> term
   347   val g_form : ppobj -> term
   348   val g_form' : ptree -> term
   348   val g_form' : ctree -> term
   349   val g_loc : ppobj -> (istate * Proof.context) option * (istate * Proof.context) option
   349   val g_loc : ppobj -> (istate * Proof.context) option * (istate * Proof.context) option
   350   val g_met : ppobj -> itm list
   350   val g_met : ppobj -> itm list
   351   val g_metID : ppobj -> metID
   351   val g_metID : ppobj -> metID
   352   val g_origin : ppobj -> ori list * spec * term
   352   val g_origin : ppobj -> ori list * spec * term
   353   val g_ostate : ppobj -> ostate
   353   val g_ostate : ppobj -> ostate
   354   val g_ostate' : ptree -> ostate
   354   val g_ostate' : ctree -> ostate
   355   val g_pbl : ppobj -> itm list
   355   val g_pbl : ppobj -> itm list
   356   val g_res : ppobj -> term
   356   val g_res : ppobj -> term
   357   val g_res' : ptree -> term
   357   val g_res' : ctree -> term
   358   val g_result : ppobj -> term * term list
   358   val g_result : ppobj -> term * term list
   359   val g_spec : ppobj -> spec
   359   val g_spec : ppobj -> spec
   360   val g_tac : ppobj -> tac
   360   val g_tac : ppobj -> tac
   361   val get_all : (ppobj -> 'a) -> ptree -> 'a list
   361   val get_all : (ppobj -> 'a) -> ctree -> 'a list
   362   val get_allp : pos' list -> pos * (int list * pos_) -> ptree -> pos' list
   362   val get_allp : pos' list -> pos * (int list * pos_) -> ctree -> pos' list
   363   val get_allpos' : pos * posel -> ptree -> pos' list
   363   val get_allpos' : pos * posel -> ctree -> pos' list
   364   val get_allpos's : pos * posel -> ptree list -> (pos * pos_) list
   364   val get_allpos's : pos * posel -> ctree list -> (pos * pos_) list
   365   val get_allps : (pos * pos_) list -> posel list -> ptree list -> pos' list
   365   val get_allps : (pos * pos_) list -> posel list -> ctree list -> pos' list
   366   val get_alls : (ppobj -> 'a) -> ptree list -> 'a list
   366   val get_alls : (ppobj -> 'a) -> ctree list -> 'a list
   367   val get_assumptions_ : ptree -> pos * pos_ -> term list
   367   val get_assumptions_ : ctree -> pos * pos_ -> term list
   368   val get_ctxt : ptree -> pos * pos_ -> Proof.context
   368   val get_ctxt : ctree -> pos * pos_ -> Proof.context
   369   val get_curr_formula : ptree * (pos * pos_) -> term
   369   val get_curr_formula : ctree * (pos * pos_) -> term
   370   val get_istate : ptree -> pos * pos_ -> istate
   370   val get_istate : ctree -> pos * pos_ -> istate
   371   val get_loc : ptree -> pos * pos_ -> istate * Proof.context
   371   val get_loc : ctree -> pos * pos_ -> istate * Proof.context
   372   val get_nd : ptree -> pos -> ptree
   372   val get_nd : ctree -> pos -> ctree
   373   val get_obj : (ppobj -> 'a) -> ptree -> pos -> 'a
   373   val get_obj : (ppobj -> 'a) -> ctree -> pos -> 'a
   374   val get_somespec : spec -> spec -> spec
   374   val get_somespec : spec -> spec -> spec
   375   val get_somespec' : spec -> spec -> spec
   375   val get_somespec' : spec -> spec -> spec
   376   val get_trace : ptree -> int list -> int list -> int list list
   376   val get_trace : ctree -> int list -> int list -> int list list
   377   val gpt_cell : ptree -> lrd option
   377   val gpt_cell : ctree -> lrd option
   378   type iist = istate option * istate option
   378   type iist = istate option * istate option
   379   val ind : pos' -> int
   379   val ind : pos' -> int
   380   val ins_chn : ptree list -> ptree -> int list -> ptree
   380   val ins_chn : ctree list -> ctree -> int list -> ctree
   381   val ins_nth : int -> 'a -> 'a list -> 'a list
   381   val ins_nth : int -> 'a -> 'a list -> 'a list
   382   val insert_pt : ppobj -> ptree -> int list -> ptree
   382   val insert_pt : ppobj -> ctree -> int list -> ctree
   383   val is_curr_endof_calc : ptree -> pos' -> bool
   383   val is_curr_endof_calc : ctree -> pos' -> bool
   384   val is_e_ctxt : Proof.context -> bool
   384   val is_e_ctxt : Proof.context -> bool
   385   val is_empty_tac : tac -> bool
   385   val is_empty_tac : tac -> bool
   386   val is_interpos : pos' -> bool
   386   val is_interpos : pos' -> bool
   387   val is_pblnd : ptree -> bool
   387   val is_pblnd : ctree -> bool
   388   val is_pblobj : ppobj -> bool
   388   val is_pblobj : ppobj -> bool
   389   val is_pblobj' : ptree -> pos -> bool
   389   val is_pblobj' : ctree -> pos -> bool
   390   val is_prfobj : ppobj -> bool
   390   val is_prfobj : ppobj -> bool
   391   val is_rewset : tac -> bool
   391   val is_rewset : tac -> bool
   392   val is_rewtac : tac -> bool
   392   val is_rewtac : tac -> bool
   393   val isasub2subst : term -> (term * term) list
   393   val isasub2subst : term -> (term * term) list
   394   datatype istate = RrlsState of rrlsstate | ScrState of scrstate | Uistate
   394   datatype istate = RrlsState of rrlsstate | ScrState of scrstate | Uistate
   395   val istate2str : istate -> string
   395   val istate2str : istate -> string
   396   val istates2str : istate option * istate option -> string
   396   val istates2str : istate option * istate option -> string
   397   val just_created : ptree * pos' -> bool
   397   val just_created : ctree * pos' -> bool
   398   val just_created_ : ppobj -> bool
   398   val just_created_ : ppobj -> bool
   399   val last_onlev : ptree -> pos -> bool
   399   val last_onlev : ctree -> pos -> bool
   400   val lev_back' : pos' -> pos'
   400   val lev_back' : pos' -> pos'
   401   val lev_dn : posel list -> posel list
   401   val lev_dn : posel list -> posel list
   402   val lev_dnRes : pos' -> pos'
   402   val lev_dnRes : pos' -> pos'
   403   val lev_dn_ : pos' -> pos'
   403   val lev_dn_ : pos' -> pos'
   404   val lev_of : pos' -> int
   404   val lev_of : pos' -> int
   405   val lev_on : pos -> posel list
   405   val lev_on : pos -> posel list
   406   val lev_on' : ptree -> pos' -> pos'
   406   val lev_on' : ctree -> pos' -> pos'
   407   val lev_onFrm : pos' -> pos'
   407   val lev_onFrm : pos' -> pos'
   408   val lev_pred : pos -> pos
   408   val lev_pred : pos -> pos
   409   val lev_pred' : ptree -> pos' -> pos'
   409   val lev_pred' : ctree -> pos' -> pos'
   410   val lev_up : pos -> pos
   410   val lev_up : pos -> pos
   411   val lev_up_ : pos' -> pos'
   411   val lev_up_ : pos' -> pos'
   412   val move_dn : pos -> ptree -> int list * pos_ -> int list * pos_
   412   val move_dn : pos -> ctree -> int list * pos_ -> int list * pos_
   413   val move_up : int list -> ptree -> int list * pos_ -> int list * pos_
   413   val move_up : int list -> ctree -> int list * pos_ -> int list * pos_
   414   val movecalchd_up : ptree -> pos' -> pos'
   414   val movecalchd_up : ctree -> pos' -> pos'
   415   val movelevel_dn : int list -> ptree -> int list * pos_ -> int list * pos_
   415   val movelevel_dn : int list -> ctree -> int list * pos_ -> int list * pos_
   416   val movelevel_up : int list -> ptree -> int list * pos_ -> int list * pos_
   416   val movelevel_up : int list -> ctree -> int list * pos_ -> int list * pos_
   417   val new_val : term -> istate -> istate
   417   val new_val : term -> istate -> istate
   418   val nth : int -> 'a list -> 'a
   418   val nth : int -> 'a list -> 'a
   419   type ocalhd = bool * pos_ * term * itm list * (bool * term) list * spec
   419   type ocalhd = bool * pos_ * term * itm list * (bool * term) list * spec
   420   val ocalhd2str : ocalhd -> string
   420   val ocalhd2str : ocalhd -> string
   421   datatype ostate = Complete | Incomplete | Inconsistent
   421   datatype ostate = Complete | Incomplete | Inconsistent
   422   val ostate2str : ostate -> string
   422   val ostate2str : ostate -> string
   423   val par_children : ptree -> pos -> ptree list * pos
   423   val par_children : ctree -> pos -> ctree list * pos
   424   val par_pbl_det : ptree -> pos -> bool * pos * rls
   424   val par_pbl_det : ctree -> pos -> bool * pos * rls
   425   val par_pblobj : ptree -> pos -> pos
   425   val par_pblobj : ctree -> pos -> pos
   426   type pos = posel list
   426   type pos = posel list
   427   type pos' = pos * pos_
   427   type pos' = pos * pos_
   428   val pos's2str : (int list * pos_) list -> string
   428   val pos's2str : (int list * pos_) list -> string
   429   val pos2str : int list -> string
   429   val pos2str : int list -> string
   430   datatype pos_ = Frm | Met | Pbl | Res | Und
   430   datatype pos_ = Frm | Met | Pbl | Res | Und
   447       cell: lrd option,
   447       cell: lrd option,
   448       form: term,
   448       form: term,
   449       loc: (istate * Proof.context) option * (istate * Proof.context) option,
   449       loc: (istate * Proof.context) option * (istate * Proof.context) option,
   450       ostate: ostate, result: term * term list, tac: tac}
   450       ostate: ostate, result: term * term list, tac: tac}
   451   val pr_pos : int list -> string
   451   val pr_pos : int list -> string
   452   val pr_ptree : (pos -> ppobj -> string) -> ptree -> string
   452   val pr_ctree : (pos -> ppobj -> string) -> ctree -> string
   453   val pr_short : pos -> ppobj -> string
   453   val pr_short : pos -> ppobj -> string
   454   val pre_pos : pos -> pos
   454   val pre_pos : pos -> pos
   455   val preconds2str : (bool * term) list -> string
   455   val preconds2str : (bool * term) list -> string
   456   datatype ptform = Form of term | ModSpec of ocalhd
   456   datatype ptform = Form of term | ModSpec of ocalhd
   457   datatype ptree = EmptyPtree | Nd of ppobj * ptree list
   457   datatype ctree = EmptyPtree | Nd of ppobj * ctree list
   458   val rep_pblobj :
   458   val rep_pblobj :
   459      ppobj ->
   459      ppobj ->
   460      {branch: branch,
   460      {branch: branch,
   461       cell: lrd option,
   461       cell: lrd option,
   462       ctxt: Proof.context,
   462       ctxt: Proof.context,
   492   val repl_spec : spec -> ppobj -> ppobj
   492   val repl_spec : spec -> ppobj -> ppobj
   493   val repl_tac : tac -> ppobj -> ppobj
   493   val repl_tac : tac -> ppobj -> ppobj
   494   val res2str : term * term list -> string
   494   val res2str : term * term list -> string
   495   val rls_of : tac -> rls'
   495   val rls_of : tac -> rls'
   496   val rls_of_rewset : tac -> rls' * subst option
   496   val rls_of_rewset : tac -> rls' * subst option
   497   val rootthy : ptree -> theory
   497   val rootthy : ctree -> theory
   498   val rta2str : rule * (term * term list) -> string
   498   val rta2str : rule * (term * term list) -> string
   499   val rule2tac : theory -> (term * term) list -> rule -> tac
   499   val rule2tac : theory -> (term * term) list -> rule -> tac
   500   val safe2str : safe -> string
   500   val safe2str : safe -> string
   501   type scrstate = env * loc_ * term option * term * safe * bool
   501   type scrstate = env * loc_ * term option * term * safe * bool
   502   val scrstate2str : subst * loc_ * term option * term * safe * bool -> string
   502   val scrstate2str : subst * loc_ * term option * term * safe * bool -> string
   556      | Take' of term | Take_Inst' of term
   556      | Take' of term | Take_Inst' of term
   557   val tac_2str : tac_ -> string
   557   val tac_2str : tac_ -> string
   558   val test_trans : ppobj -> bool
   558   val test_trans : ppobj -> bool
   559   val thm_of_rew : tac -> thmID * subst option
   559   val thm_of_rew : tac -> thmID * subst option
   560   val topt2str : term option -> string
   560   val topt2str : term option -> string
   561   val update_branch : ptree -> pos -> branch -> ptree
   561   val update_branch : ctree -> pos -> branch -> ctree
   562   val update_ctxt : ptree -> pos -> Proof.context -> ptree
   562   val update_ctxt : ctree -> pos -> Proof.context -> ctree
   563   val update_domID : ptree -> pos -> domID -> ptree
   563   val update_domID : ctree -> pos -> domID -> ctree
   564   val update_env : ptree -> pos -> (istate * Proof.context) option -> ptree
   564   val update_env : ctree -> pos -> (istate * Proof.context) option -> ctree
   565   val update_loc' : ptree -> pos -> (istate * Proof.context) option * (istate * Proof.context) option -> ptree
   565   val update_loc' : ctree -> pos -> (istate * Proof.context) option * (istate * Proof.context) option -> ctree
   566   val update_met : ptree -> pos -> itm list -> ptree
   566   val update_met : ctree -> pos -> itm list -> ctree
   567   val update_metID : ptree -> pos -> metID -> ptree
   567   val update_metID : ctree -> pos -> metID -> ctree
   568   val update_metppc : ptree -> pos -> itm list -> ptree
   568   val update_metppc : ctree -> pos -> itm list -> ctree
   569   val update_oris : ptree -> pos -> ori list -> ptree
   569   val update_oris : ctree -> pos -> ori list -> ctree
   570   val update_orispec : ptree -> pos -> spec -> ptree
   570   val update_orispec : ctree -> pos -> spec -> ctree
   571   val update_pbl : ptree -> pos -> itm list -> ptree
   571   val update_pbl : ctree -> pos -> itm list -> ctree
   572   val update_pblID : ptree -> pos -> pblID -> ptree
   572   val update_pblID : ctree -> pos -> pblID -> ctree
   573   val update_pblppc : ptree -> pos -> itm list -> ptree
   573   val update_pblppc : ctree -> pos -> itm list -> ctree
   574   val update_spec : ptree -> pos -> spec -> ptree
   574   val update_spec : ctree -> pos -> spec -> ctree
   575   val update_tac : ptree -> pos -> tac -> ptree end
   575   val update_tac : ctree -> pos -> tac -> ctree end
   576 *)
   576 *)
   577 
   577 
   578 (**)
   578 (**)
   579 structure Ctree(**): CALC_TREEE(**) =
   579 structure Ctree(**): CALC_TREEE(**) =
   580 struct
   580 struct
   627   | str2pos_ "Res" = Res
   627   | str2pos_ "Res" = Res
   628   | str2pos_ "Und" = Und
   628   | str2pos_ "Und" = Und
   629   | str2pos_ str = error ("str2pos_: wrong argument = " ^ str)
   629   | str2pos_ str = error ("str2pos_: wrong argument = " ^ str)
   630 
   630 
   631 type pos' = pos * pos_;
   631 type pos' = pos * pos_;
   632 (*WN0312 remembering interator (pos * pos_) for ptree 
   632 (*WN0312 remembering interator (pos * pos_) for ctree 
   633 	   pos : lev_on, lev_dn, lev_up, 
   633 	   pos : lev_on, lev_dn, lev_up, 
   634            lev_onFrm, lev_dnRes (..see solve Apply_Method !) 
   634            lev_onFrm, lev_dnRes (..see solve Apply_Method !) 
   635      pos_:
   635      pos_:
   636 # generate1 sets pos_ if possible  ...?WN0502?NOT...
   636 # generate1 sets pos_ if possible  ...?WN0502?NOT...
   637 # generate1 does NOT set pos, because certain nodes can be lev_on OR lev_dn
   637 # generate1 does NOT set pos, because certain nodes can be lev_on OR lev_dn
  1157   ",\n  res= " ^ term2str res ^
  1157   ",\n  res= " ^ term2str res ^
  1158   ",\n  " ^ safe2str s ^ "))";
  1158   ",\n  " ^ safe2str s ^ "))";
  1159 fun ets2str (ets: ets) = (strs2str o (map ets2s)) ets;
  1159 fun ets2str (ets: ets) = (strs2str o (map ets2s)) ets;
  1160 
  1160 
  1161 
  1161 
  1162 type envp =(*9.5.03: unused, delete with field in ptree.PblObj FIXXXME*)
  1162 type envp =(*9.5.03: unused, delete with field in ctree.PblObj FIXXXME*)
  1163    (int * term list) list * (*assoc-list: args of met*)
  1163    (int * term list) list * (*assoc-list: args of met*)
  1164    (int * rls) list *       (*assoc-list: tacs already done ///15.9.00*)
  1164    (int * rls) list *       (*assoc-list: tacs already done ///15.9.00*)
  1165    (int * ets) list *       (*assoc-list: tacs etc. already done*)
  1165    (int * ets) list *       (*assoc-list: tacs etc. already done*)
  1166    (string * pos) list;     (*asms * from where*)
  1166    (string * pos) list;     (*asms * from where*)
  1167 val empty_envp = ([], [], [], []): envp; 
  1167 val empty_envp = ([], [], [], []): envp; 
  1210    for the first tactic in a script generating the first formula at (p,Frm);
  1210    for the first tactic in a script generating the first formula at (p,Frm);
  1211    this trouble has been covered by 'init_form' and 'Take' so far,
  1211    this trouble has been covered by 'init_form' and 'Take' so far,
  1212    but it is crucial if the first tactic in a script is eg. 'Subproblem';
  1212    but it is crucial if the first tactic in a script is eg. 'Subproblem';
  1213    see 'type tac ', Apply_Method.
  1213    see 'type tac ', Apply_Method.
  1214 .*)
  1214 .*)
  1215 datatype ptree = 
  1215 datatype ctree = 
  1216     EmptyPtree
  1216     EmptyPtree
  1217   | Nd of ppobj * (ptree list);
  1217   | Nd of ppobj * (ctree list);
  1218 val e_ptree = EmptyPtree;
  1218 val e_ctree = EmptyPtree;
  1219 type state = ptree * pos
  1219 type state = ctree * pos
  1220 
  1220 
  1221 fun rep_prfobj (PrfObj {cell,form,tac,loc,branch,result,ostate}) =
  1221 fun rep_prfobj (PrfObj {cell,form,tac,loc,branch,result,ostate}) =
  1222   {cell=cell,form=form,tac=tac,loc=loc,branch=branch,result=result,ostate=ostate};
  1222   {cell=cell,form=form,tac=tac,loc=loc,branch=branch,result=result,ostate=ostate};
  1223 fun rep_pblobj (PblObj {cell,origin,fmz,spec,probl,meth,ctxt,
  1223 fun rep_pblobj (PblObj {cell,origin,fmz,spec,probl,meth,ctxt,
  1224       env,loc,branch,result,ostate}) =
  1224       env,loc,branch,result,ostate}) =
  1277 fun lev_dn_ (p, _) = (lev_dn p, Res)
  1277 fun lev_dn_ (p, _) = (lev_dn p, Res)
  1278 fun ind (p,_) = length p; (*WN050108 deprecated in favour of lev_of*)
  1278 fun ind (p,_) = length p; (*WN050108 deprecated in favour of lev_of*)
  1279 fun lev_of (p,_) = length p;
  1279 fun lev_of (p,_) = length p;
  1280 
  1280 
  1281 
  1281 
  1282 (** convert ptree to a string **)
  1282 (** convert ctree to a string **)
  1283 
  1283 
  1284 (* convert a pos from list to string *)
  1284 (* convert a pos from list to string *)
  1285 fun pr_pos ps = (space_implode "." (map string_of_int ps))^".   ";
  1285 fun pr_pos ps = (space_implode "." (map string_of_int ps))^".   ";
  1286 (* show hd origin or form only *)
  1286 (* show hd origin or form only *)
  1287 fun pr_short p (PblObj {origin = (ori,_,_),...}) = 
  1287 fun pr_short p (PblObj {origin = (ori,_,_),...}) = 
  1299    "\n")
  1299    "\n")
  1300   | pr_cell p (PrfObj {cell = c, form = form,...}) =
  1300   | pr_cell p (PrfObj {cell = c, form = form,...}) =
  1301   ((ints2str c) ^"   "^ (term2str form) ^ "\n");
  1301   ((ints2str c) ^"   "^ (term2str form) ^ "\n");
  1302 *)
  1302 *)
  1303 
  1303 
  1304 (* convert ptree *)
  1304 (* convert ctree *)
  1305 fun pr_ptree f pt =
  1305 fun pr_ctree f pt =
  1306   let
  1306   let
  1307     fun pr_pt pfn _  EmptyPtree = ""
  1307     fun pr_pt pfn _  EmptyPtree = ""
  1308       | pr_pt pfn ps (Nd (b, [])) = pfn ps b
  1308       | pr_pt pfn ps (Nd (b, [])) = pfn ps b
  1309       | pr_pt pfn ps (Nd (b, ts)) = (pfn ps b)^
  1309       | pr_pt pfn ps (Nd (b, ts)) = (pfn ps b)^
  1310       (prts pfn ps 1 ts)
  1310       (prts pfn ps 1 ts)
  1319        [Nd("xx1",[]),
  1319        [Nd("xx1",[]),
  1320 	Nd("xx2",
  1320 	Nd("xx2",
  1321 	   [Nd("xx2.1.",[]),
  1321 	   [Nd("xx2.1.",[]),
  1322 	    Nd("xx2.2.",[])]),
  1322 	    Nd("xx2.2.",[])]),
  1323 	Nd("xx3",[])]);
  1323 	Nd("xx3",[])]);
  1324 > tracing (pr_ptree prfn (!pt));
  1324 > tracing (pr_ctree prfn (!pt));
  1325 *)
  1325 *)
  1326 
  1326 
  1327 
  1327 
  1328 (** access the branches of ptree **)
  1328 (** access the branches of ctree **)
  1329 
  1329 
  1330 fun ins_nth 1 e l  = e::l
  1330 fun ins_nth 1 e l  = e::l
  1331   | ins_nth n e [] = raise PTREE "ins_nth n e []"
  1331   | ins_nth n e [] = raise PTREE "ins_nth n e []"
  1332   | ins_nth n e (l::ls) = l::(ins_nth (n-1) e ls);
  1332   | ins_nth n e (l::ls) = l::(ins_nth (n-1) e ls);
  1333 fun repl []      _ _ = raise PTREE "repl [] _ _"
  1333 fun repl []      _ _ = raise PTREE "repl [] _ _"
  1448   | is_interpos _ = false;
  1448   | is_interpos _ = false;
  1449 
  1449 
  1450 fun last_onlev pt pos = not (existpt (lev_on pos) pt);
  1450 fun last_onlev pt pos = not (existpt (lev_on pos) pt);
  1451 
  1451 
  1452 
  1452 
  1453 (*.find the position of the next parent which is a PblObj in ptree.*)
  1453 (*.find the position of the next parent which is a PblObj in ctree.*)
  1454 fun par_pblobj pt [] = []
  1454 fun par_pblobj pt [] = []
  1455   | par_pblobj pt p =
  1455   | par_pblobj pt p =
  1456     let fun par pt [] = []
  1456     let fun par pt [] = []
  1457 	  | par pt p = if is_pblobj (get_obj I pt p) then p
  1457 	  | par pt p = if is_pblobj (get_obj I pt p) then p
  1458 		       else par pt (lev_up p)
  1458 		       else par pt (lev_up p)
  1466 	  | par p = let val Nd (obj, children) = get_nd pt p
  1466 	  | par p = let val Nd (obj, children) = get_nd pt p
  1467 		    in if is_pblobj obj then (children, p) else par (lev_up p)
  1467 		    in if is_pblobj obj then (children, p) else par (lev_up p)
  1468 		    end;
  1468 		    end;
  1469     in par (lev_up p) end; 
  1469     in par (lev_up p) end; 
  1470 
  1470 
  1471 (*.get the children of a node in ptree.*)
  1471 (*.get the children of a node in ctree.*)
  1472 fun children (Nd (PblObj _, cn)) = cn
  1472 fun children (Nd (PblObj _, cn)) = cn
  1473   | children (Nd (PrfObj _, cn)) = cn;
  1473   | children (Nd (PrfObj _, cn)) = cn;
  1474 
  1474 
  1475 
  1475 
  1476 (*.find the next parent, which is either a PblObj (return true)
  1476 (*.find the next parent, which is either a PblObj (return true)
  1490     in par pt (lev_up p) end; 
  1490     in par pt (lev_up p) end; 
  1491 
  1491 
  1492 
  1492 
  1493 
  1493 
  1494 
  1494 
  1495 (*.get from the whole ptree by f : ppobj -> 'a.*)
  1495 (*.get from the whole ctree by f : ppobj -> 'a.*)
  1496 fun get_all f EmptyPtree   = []
  1496 fun get_all f EmptyPtree   = []
  1497   | get_all f (Nd (b, [])) = [f b]
  1497   | get_all f (Nd (b, [])) = [f b]
  1498   | get_all f (Nd (b, bs)) = [f b] @ (get_alls f bs)
  1498   | get_all f (Nd (b, bs)) = [f b] @ (get_alls f bs)
  1499 and get_alls f [] = []
  1499 and get_alls f [] = []
  1500   | get_alls f pts = flat (map (get_all f) pts);
  1500   | get_alls f pts = flat (map (get_all f) pts);
  1501 
  1501 
  1502 
  1502 
  1503 (*.insert obj b into ptree at pos, ev.overwriting this pos.
  1503 (*.insert obj b into ctree at pos, ev.overwriting this pos.
  1504 covers library.ML TODO.WN110315 rename*)
  1504 covers library.ML TODO.WN110315 rename*)
  1505 fun insert_pt b EmptyPtree   []  = Nd (b, [])
  1505 fun insert_pt b EmptyPtree   []  = Nd (b, [])
  1506   | insert_pt b EmptyPtree    _        = raise PTREE "insert_pt b Empty _"
  1506   | insert_pt b EmptyPtree    _        = raise PTREE "insert_pt b Empty _"
  1507   | insert_pt b (Nd ( _,  _)) []       = raise PTREE "insert_pt b _ []"
  1507   | insert_pt b (Nd ( _,  _)) []       = raise PTREE "insert_pt b _ []"
  1508   | insert_pt b (Nd (b', bs)) (p::[])  = 
  1508   | insert_pt b (Nd (b', bs)) (p::[])  = 
  1509      Nd (b', repl_app bs p (Nd (b,[]))) 
  1509      Nd (b', repl_app bs p (Nd (b,[]))) 
  1510   | insert_pt b (Nd (b', bs)) (p::ps)  =
  1510   | insert_pt b (Nd (b', bs)) (p::ps)  =
  1511      Nd (b', repl_app bs p (insert_pt b (nth p bs) ps));
  1511      Nd (b', repl_app bs p (insert_pt b (nth p bs) ps));
  1512 (*
  1512 (*
  1513 > type ppobj = string;
  1513 > type ppobj = string;
  1514 > tracing (pr_ptree prfn (!pt));
  1514 > tracing (pr_ctree prfn (!pt));
  1515 (*val pt = Unsynchronized.ref Empty;*)
  1515 (*val pt = Unsynchronized.ref Empty;*)
  1516   pt:= insert_pt ("root'":ppobj) EmptyPtree [];
  1516   pt:= insert_pt ("root'":ppobj) EmptyPtree [];
  1517   pt:= insert_pt ("xx1":ppobj) (!pt) [1];
  1517   pt:= insert_pt ("xx1":ppobj) (!pt) [1];
  1518   pt:= insert_pt ("xx2":ppobj) (!pt) [2];
  1518   pt:= insert_pt ("xx2":ppobj) (!pt) [2];
  1519   pt:= insert_pt ("xx3":ppobj) (!pt) [3];
  1519   pt:= insert_pt ("xx3":ppobj) (!pt) [3];
  1675 datatype ptform = Form of term | ModSpec of ocalhd;
  1675 datatype ptform = Form of term | ModSpec of ocalhd;
  1676 val e_ptform = Form e_term;
  1676 val e_ptform = Form e_term;
  1677 val e_ptform' = ModSpec e_ocalhd;
  1677 val e_ptform' = ModSpec e_ocalhd;
  1678 
  1678 
  1679 (*.applies (snd f) to the branches at a pos if ((fst f) b),
  1679 (*.applies (snd f) to the branches at a pos if ((fst f) b),
  1680    f : (ppobj -> bool) * (int -> ptree list -> ptree list).*)
  1680    f : (ppobj -> bool) * (int -> ctree list -> ctree list).*)
  1681 
  1681 
  1682 fun appl_branch f EmptyPtree [] = (EmptyPtree, false)
  1682 fun appl_branch f EmptyPtree [] = (EmptyPtree, false)
  1683   | appl_branch f EmptyPtree _  = raise PTREE "appl_branch f Empty _"
  1683   | appl_branch f EmptyPtree _  = raise PTREE "appl_branch f Empty _"
  1684   | appl_branch f (Nd ( _, _)) [] = raise PTREE "appl_branch f _ []"
  1684   | appl_branch f (Nd ( _, _)) [] = raise PTREE "appl_branch f _ []"
  1685   | appl_branch f (Nd (b, bs)) (p::[]) = 
  1685   | appl_branch f (Nd (b, bs)) (p::[]) = 
  1775 >  posless [6] [6,5,2];
  1775 >  posless [6] [6,5,2];
  1776 true
  1776 true
  1777 +++ see Isabelle/../library.ML*)
  1777 +++ see Isabelle/../library.ML*)
  1778 
  1778 
  1779 
  1779 
  1780 (**.development for extracting an 'interval' from ptree.**)
  1780 (**.development for extracting an 'interval' from ctree.**)
  1781 
  1781 
  1782 (*WN0510 version stopped in favour of get_interval with !!!move_dn, getFormulaeFromTo
  1782 (*WN0510 version stopped in favour of get_interval with !!!move_dn, getFormulaeFromTo
  1783   actually used (inefficient) version with move_dn: see modspec.sml*)
  1783   actually used (inefficient) version with move_dn: see modspec.sml*)
  1784 local
  1784 local
  1785 
  1785 
  1810 
  1810 
  1811   | getnds i _ (b,p) q (nd::(nds as _::_)) =       (*intern, ...*)
  1811   | getnds i _ (b,p) q (nd::(nds as _::_)) =       (*intern, ...*)
  1812     (getnd i             (       b,[0]) [99999] nd) @
  1812     (getnd i             (       b,[0]) [99999] nd) @
  1813     (getnds ~99999 false (lev_on b,[0]) q nds); 
  1813     (getnds ~99999 false (lev_on b,[0]) q nds); 
  1814 in
  1814 in
  1815 (*get an 'interval from to' from a ptree as 'intervals f t' of respective nodes
  1815 (*get an 'interval from to' from a ctree as 'intervals f t' of respective nodes
  1816   where 'from' are pos, i.e. a key as int list, 'f' an int (to,t analoguous)
  1816   where 'from' are pos, i.e. a key as int list, 'f' an int (to,t analoguous)
  1817 (1) the 'f' are given 
  1817 (1) the 'f' are given 
  1818 (1a) by 'from' if 'f' = the respective element of 'from' (left margin)
  1818 (1a) by 'from' if 'f' = the respective element of 'from' (left margin)
  1819 (1b) -inifinity, if 'f' > the respective element of 'from' (internal node)
  1819 (1b) -inifinity, if 'f' > the respective element of 'from' (internal node)
  1820 (2) the 't' ar given
  1820 (2) the 't' ar given
  1847     let val domID = if dI = e_domID then dI' else dI
  1847     let val domID = if dI = e_domID then dI' else dI
  1848 	val pblID = if pI = e_pblID then pI' else pI
  1848 	val pblID = if pI = e_pblID then pI' else pI
  1849 	val metID = if mI = e_metID then mI' else mI
  1849 	val metID = if mI = e_metID then mI' else mI
  1850     in (domID, pblID, metID) end;
  1850     in (domID, pblID, metID) end;
  1851 
  1851 
  1852 (*extract a formula or model from ptree for itms2itemppc or model2xml*)
  1852 (*extract a formula or model from ctree for itms2itemppc or model2xml*)
  1853 fun preconds2str bts = 
  1853 fun preconds2str bts = 
  1854     (strs2str o (map (linefeed o pair2str o
  1854     (strs2str o (map (linefeed o pair2str o
  1855 		      (apsnd term2str) o 
  1855 		      (apsnd term2str) o 
  1856 		      (apfst bool2str)))) bts;
  1856 		      (apfst bool2str)))) bts;
  1857 fun ocalhd2str (b, p, hdf, itms, prec, spec) =
  1857 fun ocalhd2str (b, p, hdf, itms, prec, spec) =
  1862 
  1862 
  1863 
  1863 
  1864 fun is_pblnd (Nd (ppobj, _)) = is_pblobj ppobj;
  1864 fun is_pblnd (Nd (ppobj, _)) = is_pblobj ppobj;
  1865 
  1865 
  1866 
  1866 
  1867 (**.functions for the 'ptree iterator' as seen from the FE-Kernel interface.**)
  1867 (**.functions for the 'ctree iterator' as seen from the FE-Kernel interface.**)
  1868 
  1868 
  1869 (*move one step down into existing nodes of ptree; regard TransitiveB
  1869 (*move one step down into existing nodes of ctree; regard TransitiveB
  1870 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##################
  1870 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##################
  1871 fun move_dn _ (Nd (c, ns)) ([],p_) = (*root problem*)
  1871 fun move_dn _ (Nd (c, ns)) ([],p_) = (*root problem*)
  1872 (* val (Nd (c, ns), ([],p_)) = (pt, get_pos cI uI);
  1872 (* val (Nd (c, ns), ([],p_)) = (pt, get_pos cI uI);
  1873    *)
  1873    *)
  1874     if is_pblobj c 
  1874     if is_pblobj c 
  1934 				    then (P@[p+1], Res)
  1934 				    then (P@[p+1], Res)
  1935 				    else (P@[p+1,1], Frm)(*040221*)
  1935 				    else (P@[p+1,1], Frm)(*040221*)
  1936 			       else (P@[p+1], if is_pblnd (nth (p+1) ns) 
  1936 			       else (P@[p+1], if is_pblnd (nth (p+1) ns) 
  1937 					      then Pbl else Frm); 
  1937 					      then Pbl else Frm); 
  1938 *)
  1938 *)
  1939 (*.move one step down into existing nodes of ptree; skip Res = Frm.nxt;
  1939 (*.move one step down into existing nodes of ctree; skip Res = Frm.nxt;
  1940    move_dn at the end of the calc-tree raises PTREE.*)
  1940    move_dn at the end of the calc-tree raises PTREE.*)
  1941 fun move_dn _ (Nd (c, ns)) ([],p_) = (*root problem*)
  1941 fun move_dn _ (Nd (c, ns)) ([],p_) = (*root problem*)
  1942     (case p_ of 
  1942     (case p_ of 
  1943 	     Res => raise PTREE "move_dn: end of calculation"
  1943 	     Res => raise PTREE "move_dn: end of calculation"
  1944 	   | _ => if null ns (*go down from Pbl + Met*)
  1944 	   | _ => if null ns (*go down from Pbl + Met*)
  1978 	     else (P @ [p, 1], 
  1978 	     else (P @ [p, 1], 
  1979 		   if (is_pblnd o hd o children o (nth p)) ns
  1979 		   if (is_pblnd o hd o children o (nth p)) ns
  1980 		   then Pbl else Frm);
  1980 		   then Pbl else Frm);
  1981 
  1981 
  1982 
  1982 
  1983 (*.go one level down into ptree.*)
  1983 (*.go one level down into ctree.*)
  1984 fun movelevel_dn [] (Nd (c, ns)) ([],p_) = (*root problem*)
  1984 fun movelevel_dn [] (Nd (c, ns)) ([],p_) = (*root problem*)
  1985     if is_pblobj c 
  1985     if is_pblobj c 
  1986     then if null ns 
  1986     then if null ns 
  1987 	 then raise PTREE "solve problem not started"
  1987 	 then raise PTREE "solve problem not started"
  1988 	 else ([1], if (is_pblnd o hd) ns then Pbl else Frm)
  1988 	 else ([1], if (is_pblnd o hd) ns then Pbl else Frm)
  2015 			  if (is_pblnd o hd o children o (nth p)) ns
  2015 			  if (is_pblnd o hd o children o (nth p)) ns
  2016 			  then Pbl else Frm);
  2016 			  then Pbl else Frm);
  2017 
  2017 
  2018 
  2018 
  2019 
  2019 
  2020 (*.go to the previous position in ptree; regard TransitiveB.*)
  2020 (*.go to the previous position in ctree; regard TransitiveB.*)
  2021 fun move_up _ (Nd (c, ns)) ([],p_) = (*root problem*)
  2021 fun move_up _ (Nd (c, ns)) ([],p_) = (*root problem*)
  2022     if is_pblobj c 
  2022     if is_pblobj c 
  2023     then case p_ of Res => if null ns then ([], Pbl) (*Res -> Pbl (not Met)!*)
  2023     then case p_ of Res => if null ns then ([], Pbl) (*Res -> Pbl (not Met)!*)
  2024 			   else ([length ns], Res)
  2024 			   else ([length ns], Res)
  2025 		  | _  => raise PTREE "begin of calculation"
  2025 		  | _  => raise PTREE "begin of calculation"
  2046 			    then (P@[p-1], Res) else (P@[p], Frm)
  2046 			    then (P@[p-1], Res) else (P@[p], Frm)
  2047 		       else (P @ [p, nc], Res) end; (*go down*)
  2047 		       else (P @ [p, nc], Res) end; (*go down*)
  2048 
  2048 
  2049 
  2049 
  2050 
  2050 
  2051 (*.go one level up in ptree; sets the position on Frm.*)
  2051 (*.go one level up in ctree; sets the position on Frm.*)
  2052 fun movelevel_up _ (Nd (c, ns)) (([],p_):pos') = (*root problem*)
  2052 fun movelevel_up _ (Nd (c, ns)) (([],p_):pos') = (*root problem*)
  2053     raise PTREE "pos not existent"
  2053     raise PTREE "pos not existent"
  2054 
  2054 
  2055   (*iterate towards end of pos*)
  2055   (*iterate towards end of pos*)
  2056   | movelevel_up P  (Nd (_, ns)) (p::(ps as (_::_)),p_) = 
  2056   | movelevel_up P  (Nd (_, ns)) (p::(ps as (_::_)),p_) = 
  2108 
  2108 
  2109 (**.insert into ctree and cut branches accordingly.**)
  2109 (**.insert into ctree and cut branches accordingly.**)
  2110   
  2110   
  2111 (*.get all positions of certain intervals on the ctree.*)
  2111 (*.get all positions of certain intervals on the ctree.*)
  2112 (*OLD VERSION without move_dn; kept for occasional redesign
  2112 (*OLD VERSION without move_dn; kept for occasional redesign
  2113    get all pos's to be cut in a ptree
  2113    get all pos's to be cut in a ctree
  2114    below a pos or from a ptree list after i-th element (NO level_up).*)
  2114    below a pos or from a ctree list after i-th element (NO level_up).*)
  2115 fun get_allpos' (_:pos, _:posel) EmptyPtree   = ([]:pos' list)
  2115 fun get_allpos' (_:pos, _:posel) EmptyPtree   = ([]:pos' list)
  2116   | get_allpos' (p, 1) (Nd (b, bs)) = (*p is pos of Nd*)
  2116   | get_allpos' (p, 1) (Nd (b, bs)) = (*p is pos of Nd*)
  2117     if g_ostate b = Incomplete 
  2117     if g_ostate b = Incomplete 
  2118     then ((*tracing("get_allpos' (p, 1) Incomplete: p="^ints2str' p);*)
  2118     then ((*tracing("get_allpos' (p, 1) Incomplete: p="^ints2str' p);*)
  2119 	  [(p,Frm)] @ (get_allpos's (p, 1) bs)
  2119 	  [(p,Frm)] @ (get_allpos's (p, 1) bs)
  2141 
  2141 
  2142 
  2142 
  2143 (*.cut branches.*)
  2143 (*.cut branches.*)
  2144 (*before WN041019......
  2144 (*before WN041019......
  2145 val cut_branch = (test_trans, curry take):
  2145 val cut_branch = (test_trans, curry take):
  2146     (ppobj -> bool) * (int -> ptree list -> ptree list);
  2146     (ppobj -> bool) * (int -> ctree list -> ctree list);
  2147 .. formlery used for ...
  2147 .. formlery used for ...
  2148 fun cut_tree''' _ [] = EmptyPtree
  2148 fun cut_tree''' _ [] = EmptyPtree
  2149   | cut_tree''' pt pos = 
  2149   | cut_tree''' pt pos = 
  2150   let val (pt',cut) = appl_branch cut_branch pt pos
  2150   let val (pt',cut) = appl_branch cut_branch pt pos
  2151   in if cut andalso length pos > 1 then cut_tree''' pt' (lev_up pos)
  2151   in if cut andalso length pos > 1 then cut_tree''' pt' (lev_up pos)
  2209 		     then [] else [([], Res)])) end;
  2209 		     then [] else [([], Res)])) end;
  2210 
  2210 
  2211 
  2211 
  2212 (*########/ inserted from ctreeNEW.sml \#################################**)
  2212 (*########/ inserted from ctreeNEW.sml \#################################**)
  2213 
  2213 
  2214 (*.get all positions in a ptree until ([],Res) or ostate=Incomplete
  2214 (*.get all positions in a ctree until ([],Res) or ostate=Incomplete
  2215 val get_allp = fn : 
  2215 val get_allp = fn : 
  2216   pos' list -> : accumulated, start with []
  2216   pos' list -> : accumulated, start with []
  2217   pos ->       : the offset for subtrees wrt the root
  2217   pos ->       : the offset for subtrees wrt the root
  2218   ptree ->     : (sub)tree
  2218   ctree ->     : (sub)tree
  2219   pos'         : initialization (the last pos' before ...)
  2219   pos'         : initialization (the last pos' before ...)
  2220   -> pos' list : of positions in this (sub) tree (relative to the root)
  2220   -> pos' list : of positions in this (sub) tree (relative to the root)
  2221 .*)
  2221 .*)
  2222 (* val (cuts, P, pt, pos) = ([], [3], get_nd pt [3], ([], Frm):pos');
  2222 (* val (cuts, P, pt, pos) = ([], [3], get_nd pt [3], ([], Frm):pos');
  2223    val (cuts, P, pt, pos) = ([], [2], get_nd pt [2], ([], Frm):pos');
  2223    val (cuts, P, pt, pos) = ([], [2], get_nd pt [2], ([], Frm):pos');
  2259 val cutlevup = test_trans;(*WN060727 after summerterm tests.LK0502 withdrawn*)
  2259 val cutlevup = test_trans;(*WN060727 after summerterm tests.LK0502 withdrawn*)
  2260     
  2260     
  2261 (*cut_bottom new sml603..608
  2261 (*cut_bottom new sml603..608
  2262 cut the level at the bottom of the pos (used by cappend_...)
  2262 cut the level at the bottom of the pos (used by cappend_...)
  2263 and handle the parent in order to avoid extra case for root
  2263 and handle the parent in order to avoid extra case for root
  2264 fn: ptree ->         : the _whole_ ptree for cut_levup
  2264 fn: ctree ->         : the _whole_ ctree for cut_levup
  2265     pos * posel ->   : the pos after split_last
  2265     pos * posel ->   : the pos after split_last
  2266     ptree ->         : the parent of the Nd to be cut
  2266     ctree ->         : the parent of the Nd to be cut
  2267 return
  2267 return
  2268     (ptree *         : the updated ptree
  2268     (ctree *         : the updated ctree
  2269      pos' list) *    : the pos's cut
  2269      pos' list) *    : the pos's cut
  2270      bool            : cutting shall be continued on the higher level(s)
  2270      bool            : cutting shall be continued on the higher level(s)
  2271 *)
  2271 *)
  2272 fun cut_bottom _ (pt' as Nd (b, [])) = ((pt', []), cutlevup b)
  2272 fun cut_bottom _ (pt' as Nd (b, [])) = ((pt', []), cutlevup b)
  2273   | cut_bottom (P:pos, p:posel) (Nd (b, bs)) =
  2273   | cut_bottom (P:pos, p:posel) (Nd (b, bs)) =
  2303 (*.go all levels from the bottom of 'pos' up to the root, 
  2303 (*.go all levels from the bottom of 'pos' up to the root, 
  2304  on each level compose the children of a node and accumulate the cut Nds
  2304  on each level compose the children of a node and accumulate the cut Nds
  2305 args
  2305 args
  2306    pos' list ->      : for accumulation
  2306    pos' list ->      : for accumulation
  2307    bool -> 	     : cutting shall be continued on the higher level(s)
  2307    bool -> 	     : cutting shall be continued on the higher level(s)
  2308    ptree -> 	     : the whole ptree for 'get_nd pt P' on each level
  2308    ctree -> 	     : the whole ctree for 'get_nd pt P' on each level
  2309    ptree -> 	     : the Nd from the lower level for insertion at path
  2309    ctree -> 	     : the Nd from the lower level for insertion at path
  2310    pos * posel ->    : pos=path split for convenience
  2310    pos * posel ->    : pos=path split for convenience
  2311    ptree -> 	     : Nd the children of are under consideration on this call 
  2311    ctree -> 	     : Nd the children of are under consideration on this call 
  2312 returns		     :
  2312 returns		     :
  2313    ptree * pos' list : the updated parent-Nd and the pos's of the Nds cut
  2313    ctree * pos' list : the updated parent-Nd and the pos's of the Nds cut
  2314 .*)
  2314 .*)
  2315 fun cut_levup (cuts:pos' list) clevup pt pt' (P:pos, p:posel) (Nd (b, bs)) =
  2315 fun cut_levup (cuts:pos' list) clevup pt pt' (P:pos, p:posel) (Nd (b, bs)) =
  2316     let (*divide level into 3 parts...*)
  2316     let (*divide level into 3 parts...*)
  2317 	val keep = take (p - 1, bs)
  2317 	val keep = take (p - 1, bs)
  2318 	(*val pt' comes as argument from below*)
  2318 	(*val pt' comes as argument from below*)