src/Tools/isac/Specify/step-specify.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 04 Feb 2020 17:11:54 +0100
changeset 59790 a1944acd8dcf
parent 59775 3f2ec35c0cc5
child 59791 0db869a16f83
permissions -rw-r--r--
lucin: rename central structure to Lucin
     1 (* Title:  Specify/step-specify.sml
     2    Author: Walther Neuper 2019
     3    (c) due to copyright terms
     4 *)
     5 
     6 signature STEP_SPECIFY =
     7 sig
     8   val by_tactic: Tactic.input -> Calc.T -> Chead.calcstate'
     9 (*val do_next: Step.specify_do_next requires Lucin.by_tactic, which is not yet known in Step_Specify*)
    10 
    11 end
    12 
    13 (**)
    14 structure Step_Specify(**): STEP_SPECIFY(**) =
    15 struct
    16 (**)
    17 open Pos
    18 open Ctree
    19 open Chead
    20 
    21 (* was fun Math_Engine.nxt_specify_ *)
    22 fun by_tactic (tac as Tactic.Model_Problem) (pt, pos as (p, _)) =
    23     let
    24       val (oris, ospec, probl, spec, ctxt) = case get_obj I pt p of
    25         PblObj {origin = (oris, ospec, _), probl, spec, ctxt, ...} => (oris, ospec, probl, spec, ctxt)
    26       | _ => error "by_tactic Model_Problem; uncovered case get_obj"
    27       val (dI, pI, mI) = some_spec ospec spec
    28       val thy = Celem.assoc_thy dI
    29       val mpc = (#ppc o Specify.get_met) mI (* just for reuse complete_mod_ *)
    30       val {cas, ppc, ...} = Specify.get_pbt pI
    31       val pbl = Generate.init_pbl ppc (* fill in descriptions *)
    32       (*----------------if you think, this should be done by the Dialog 
    33        in the java front-end, search there for WN060225-modelProblem----*)
    34       val (pbl, met) = case cas of
    35         NONE => (pbl, [])
    36   		| _ => complete_mod_ (oris, mpc, ppc, probl)
    37       (*----------------------------------------------------------------*)
    38       val tac_ = Tactic.Model_Problem' (pI, pbl, met)
    39       val (pos,c,_,pt) = Generate.generate1 thy tac_ (Istate_Def.Uistate, ctxt) pos pt
    40     in ([(tac, tac_, (pos, (Istate_Def.Uistate, ContextC.e_ctxt)))], c, (pt,pos)) end
    41   | by_tactic (Tactic.Add_Given ct) ptp = nxt_specif_additem "#Given" ct ptp
    42   | by_tactic (Tactic.Add_Find  ct) ptp = nxt_specif_additem "#Find"  ct ptp
    43   | by_tactic (Tactic.Add_Relation ct) ptp = nxt_specif_additem"#Relate" ct ptp
    44     (*. called only if no_met is specified .*)     
    45   | by_tactic (Tactic.Refine_Tacitly pI) (ptp as (pt, pos as (p,_))) =
    46     let 
    47       val (oris, dI, ctxt) = case get_obj I pt p of
    48         (PblObj {origin = (oris, (dI, _, _), _), ctxt, ...}) => (oris, dI, ctxt)
    49       | _ => error "by_tactic Refine_Tacitly: uncovered case get_obj"
    50       val opt = Specify.refine_ori oris pI
    51     in 
    52       case opt of
    53 	      SOME pI' => 
    54 	        let 
    55             val {met, ...} = Specify.get_pbt pI'
    56 	          (*val pt = update_pbl pt p pbl ..done by Model_Problem*)
    57 	          val mI = if length met = 0 then Celem.e_metID else hd met
    58             val thy = Celem.assoc_thy dI
    59 	          val (pos, c, _, pt) = 
    60 		          Generate.generate1 thy (Tactic.Refine_Tacitly' (pI, pI', dI, mI,(*pbl*)[])) (Istate_Def.Uistate, ctxt) pos pt
    61 	        in
    62 	          ([(Tactic.Refine_Tacitly pI, Tactic.Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]),
    63 	              (pos, (Istate_Def.Uistate, ContextC.e_ctxt)))], c, (pt,pos)) 
    64           end
    65 	    | NONE => ([], [], ptp)
    66     end
    67   | by_tactic (Tactic.Refine_Problem pI) (ptp as (pt, pos as (p,_))) =
    68     let
    69       val (dI, dI', probl, ctxt) = case get_obj I pt p of
    70         PblObj {origin= (_, (dI, _, _), _), spec = (dI', _, _), probl, ctxt, ...} =>
    71           (dI, dI', probl, ctxt)
    72       | _ => error "by_tactic Refine_Problem: uncovered case get_obj"
    73 	    val thy = if dI' = Rule.e_domID then dI else dI'
    74     in 
    75       case Specify.refine_pbl (Celem.assoc_thy thy) pI probl of
    76 	      NONE => ([], [], ptp)
    77 	    | SOME rfd => 
    78 	      let 
    79           val (pos,c,_,pt) = Generate.generate1 (Celem.assoc_thy thy) (Tactic.Refine_Problem' rfd) (Istate_Def.Uistate, ctxt) pos pt
    80 	      in
    81 	        ([(Tactic.Refine_Problem pI, Tactic.Refine_Problem' rfd, (pos, (Istate_Def.Uistate, ContextC.e_ctxt)))], c, (pt,pos))
    82         end
    83     end
    84   | by_tactic (Tactic.Specify_Problem pI) (pt, pos as (p,_)) =
    85     let
    86       val (oris, dI, dI', pI', probl, ctxt) = case get_obj I pt p of
    87         PblObj {origin = (oris, (dI,_,_),_), spec = (dI',pI',_), probl, ctxt, ...} =>
    88           (oris, dI, dI', pI', probl, ctxt)
    89       | _ => error ""
    90 	    val thy = Celem.assoc_thy (if dI' = Rule.e_domID then dI else dI');
    91       val {ppc,where_,prls,...} = Specify.get_pbt pI
    92 	    val pbl = 
    93 	      if pI' = Celem.e_pblID andalso pI = Celem.e_pblID
    94 	      then (false, (Generate.init_pbl ppc, []))
    95 	      else Specify.match_itms_oris thy probl (ppc,where_,prls) oris
    96 	      (*FIXXXME~~~~~~~~~~~~~~~: take pbl and compare with new pI WN.8.03*)
    97 	    val (c, pt) = case Generate.generate1 thy (Tactic.Specify_Problem' (pI, pbl)) (Istate_Def.Uistate, ctxt) pos pt of
    98 	      ((_, Pbl), c, _, pt) => (c, pt)
    99 	    | _ => error ""
   100     in
   101       ([(Tactic.Specify_Problem pI, Tactic.Specify_Problem' (pI, pbl), (pos, (Istate_Def.Uistate, ContextC.e_ctxt)))], c, (pt,pos))
   102     end
   103   (* transfers oris (not required in pbl) to met-model for script-env
   104      FIXME.WN.8.03: application of several mIDs to SAME model?       *)
   105   | by_tactic (Tactic.Specify_Method mID) (pt, pos as (p,_)) = 
   106     let
   107       val (oris, pbl, dI, met, ctxt) = case get_obj I pt p of
   108         PblObj {origin = (oris, _, _), probl = pbl, spec = (dI, _, _), meth=met, ctxt, ...}
   109           => (oris, pbl, dI, met, ctxt)
   110       | _ => error "by_tactic Specify_Method: uncovered case get_obj"
   111       val {ppc,pre,prls,...} = Specify.get_met mID
   112       val thy = Celem.assoc_thy dI
   113       val oris = Specify.add_field' thy ppc oris
   114       val met = if met=[] then pbl else met (* WN0602 what if more itms in met? *)
   115       val (_, (itms, _)) = Specify.match_itms_oris thy met (ppc,pre,prls ) oris
   116       val itms = Specify.hack_until_review_Specify_2 mID itms
   117       val (pos, c, _, pt) = 
   118 	      Generate.generate1 thy (Tactic.Specify_Method' (mID, oris, itms)) (Istate_Def.Uistate, ctxt) pos pt
   119     in
   120       ([(Tactic.Specify_Method mID, Tactic.Specify_Method' (mID, oris, itms), (pos, (Istate_Def.Uistate, ContextC.e_ctxt)))], c, (pt, pos)) 
   121     end    
   122   | by_tactic (Tactic.Specify_Theory dI) (pt, pos as (_, Pbl)) =
   123     let
   124       val ctxt = get_ctxt pt pos
   125 	    val (pos, c, _, pt) = 
   126 	      Generate.generate1 (Celem.assoc_thy "Isac_Knowledge") (Tactic.Specify_Theory' dI)  (Istate_Def.Uistate, ctxt) pos pt
   127     in (*FIXXXME: check if pbl can still be parsed*)
   128 	    ([(Tactic.Specify_Theory dI, Tactic.Specify_Theory' dI, (pos, (Istate_Def.Uistate, ctxt)))], c,
   129 	      (pt, pos))
   130     end
   131   | by_tactic (Tactic.Specify_Theory dI) (pt, pos as (_, Met)) =
   132     let
   133       val ctxt = get_ctxt pt pos
   134 	    val (pos, c, _, pt) = Generate.generate1 (Celem.assoc_thy "Isac_Knowledge") (Tactic.Specify_Theory' dI) (Istate_Def.Uistate, ctxt) pos pt
   135     in  (*FIXXXME: check if met can still be parsed*)
   136 	    ([(Tactic.Specify_Theory dI, Tactic.Specify_Theory' dI, (pos, (Istate_Def.Uistate, ctxt)))], c, (pt, pos))
   137     end
   138   | by_tactic m' _ = error ("by_tactic: not impl. for " ^ Tactic.tac2str m')
   139 
   140 (**)end(**)