src/Tools/isac/Interpret/sub-problem.sml
author wneuper <Walther.Neuper@jku.at>
Wed, 19 Oct 2022 13:10:24 +0200
changeset 60568 dd387c9fa89a
parent 60559 aba19e46dd84
child 60585 b7071d1dd263
permissions -rw-r--r--
cleanup 1: clarify adapt_to_type for Prog_Tac
walther@59817
     1
signature SUB_PROBLEM =
walther@59817
     2
sig
walther@59823
     3
  val tac_from_prog: Ctree.ctree -> term -> Tactic.input * Tactic.T
walther@59817
     4
end
walther@59817
     5
walther@59817
     6
(**)
walther@59817
     7
structure Sub_Problem(**): SUB_PROBLEM(**) =
walther@59817
     8
struct
walther@59817
     9
(**)
walther@59817
    10
walther@60335
    11
fun tac_from_prog pt (stac as Const (\<^const_name>\<open>Prog_Tac.SubProblem\<close>, _) $ spec' $ ags') =
walther@59817
    12
    let
walther@59817
    13
      val (dI, pI, mI) = Prog_Tac.dest_spec spec'
walther@59965
    14
      val thy = ThyC.sub_common (ThyC.get_theory dI, Ctree.rootthy pt);
Walther@60568
    15
      val ctxt = Proof_Context.init_global thy (*TODO: use ctxt from pt *)
walther@59817
    16
	    val ags = TermC.isalist2list ags';
walther@59817
    17
	    val (pI, pors, mI) = 
walther@59817
    18
	      if mI = ["no_met"]
walther@59817
    19
	      then
walther@59817
    20
          let
Walther@60559
    21
            val pors = (M_Match.arguments thy ((#ppc o (Problem.from_store ctxt)) pI) ags): O_Model.T
walther@59817
    22
		          handle ERROR "actual args do not match formal args"
Walther@60559
    23
			          => (M_Match.arguments_msg ctxt pI stac ags (*raise exn*);[]);
Walther@60559
    24
		        val pI' = Refine.refine_ori' ctxt pors pI;
walther@59817
    25
		      in (pI', pors (* refinement over models with diff.prec only *), 
Walther@60559
    26
		          (hd o #met o Problem.from_store ctxt) pI') end
Walther@60559
    27
	      else (pI, (M_Match.arguments thy ((#ppc o Problem.from_store ctxt) pI) ags)
walther@59817
    28
		      handle ERROR "actual args do not match formal args"
Walther@60559
    29
		      => (M_Match.arguments_msg ctxt pI stac ags(*raise exn*); []), mI);
walther@59987
    30
      val (fmz_, vals) = O_Model.values' pors;
Walther@60559
    31
	    val {cas, ppc, thy, ...} = Problem.from_store ctxt pI
walther@59880
    32
	    val dI = Context.theory_name thy (*take dI from _refined_ pbl*)
walther@59965
    33
	    val dI = Context.theory_name (ThyC.sub_common (ThyC.get_theory dI, Ctree.rootthy pt))
walther@59817
    34
	    val ctxt = ContextC.initialise dI vals
walther@59817
    35
	    val hdl =
walther@59817
    36
        case cas of
Walther@60559
    37
		      NONE => Auto_Prog.pblterm dI pI
walther@59987
    38
		    | SOME t => subst_atomic ((Model_Pattern.variables ppc) ~~~ vals) t
walther@59817
    39
      val f = Auto_Prog.subpbl (strip_thy dI) pI
walther@59823
    40
    in
walther@59823
    41
      (Tactic.Subproblem (dI, pI),	Tactic.Subproblem' ((dI, pI, mI), pors, hdl, fmz_, ctxt, f))
walther@59817
    42
    end
Walther@60556
    43
  | tac_from_prog _ t = raise ERROR ("Sub_Problem.tac_from_prog not impl. for " ^ UnparseC.term t)
walther@59817
    44
walther@59817
    45
(**)end(**)