1 (* Title: Interpret/lucas-interpreter.sml
2 Author: Walther Neuper 2019
3 (c) due to copyright terms
5 \<open>ML_structure MethodC\<close> holds the essential information required for automated doing
6 \<open>ML_structure Specification\<close> and \<open>ML_structure Solution\<close>.
8 Why \<open>ML_structure MethodC\<close> is parsed with general types within the current \<open>ML_structure Context\<close>
9 and refined with appropriate types from the ctxt of an Example.
19 val id_to_string: id -> string
22 val prep_store: theory -> Check_Unique.id -> string list -> References_Def.id ->
23 id * (Model_Pattern.m_field * (Model_Def.descriptor * term)) list * term list * ml_input * thm ->
26 val set_data: ml_input -> theory -> theory
27 val the_data: theory -> ml_input
29 val from_store': theory -> id -> T
30 val from_store: Proof.context -> id -> T
34 structure MethodC(**): METHOD(**) =
39 val empty = Meth_Def.empty;
41 type id = Meth_Def.id;
42 val id_empty = Meth_Def.id_empty;
43 val id_to_string = Meth_Def.id_to_string;
46 (** prepare MethodC for Store **)
48 (* a subset of MethodC.T record's fields occuring in \<open>method\<close> *)
50 {calc: Rule_Def.eval_ml_from_prog list, errpats: Error_Pattern_Def.T list, rew_rls: Rule_Set.T,
51 where_rls: Rule_Set.T, rew_ord: Rewrite_Ord.id, rls': Rule_Set.T, prog_rls: Rule_Set.T}
53 fun prep_store thy guh mathauthors start_refine (met_id, model, where_,
54 {rew_ord = ro, rls' = rls, prog_rls = prog_rls, where_rls = where_rls, calc = _(*scr_isa_fns*),
55 errpats = ep, rew_rls = nr}, prog) =
57 val sc = Program.prep_program prog
58 val calc = if Thm.eq_thm (prog, @{thm refl}) then [] else Auto_Prog.get_calcs thy sc
60 ({guh = guh, mathauthors = mathauthors, start_refine = start_refine, model = model(*'*),
61 where_ = where_, rew_ord = ro, asm_rls = rls, prog_rls = prog_rls, where_rls = where_rls,
62 calc = calc, errpats = ep, rew_rls = nr, program = Rule.Prog sc}: T, met_id)
67 structure Data = Theory_Data
69 type T = ml_input option;
74 val set_data = Data.put o SOME;
75 val the_data = the o Data.get;
79 val drop_pos_model = (fn (a, b, _) => (a, b))
80 val drop_pos_where_ = (fn (b, _) => b)
83 Scan.option (Problem.parse_item \<^keyword>\<open>Program\<close> (Parse.position Parse.name));
88 Outer_Syntax.command \<^command_keyword>\<open>method\<close>
89 "prepare ISAC method and register it to Knowledge Store"
90 (Parse.name -- Parse.!!! (\<^keyword>\<open>:\<close> |-- Parse.name --
91 Parse.!!! (\<^keyword>\<open>=\<close> |-- Parse.ML_source -- Problem.parse_authors --
92 parse_program -- (** )Problem.parse_model_input( **)Problem.parse_pos_model_input(**) )) >>
93 (fn (name, (id, (((source, maa), program), model_input))) => Toplevel.theory (fn thy =>
95 val ctxt = Proof_Context.init_global thy
96 val met_id = References_Def.explode_id id;
97 val (model, where_) = Model_Pattern.parse_pos ctxt model_input
98 val (model', where_') = (map drop_pos_model model, map drop_pos_where_ where_)
100 ML_Context.expression (Input.pos_of source)
101 (ml "Theory.setup (MethodC.set_data (" @ ML_Lex.read_source source @ ml "))")
102 |> Context.theory_map;
103 val ml_input = the_data (set_data thy);
107 | SOME a => Global_Theory.get_thm thy (Global_Theory.check_fact thy a));
108 val arg = prep_store thy name maa id_empty (met_id, model', where_', ml_input, thm);
109 in Know_Store.add_mets ctxt [arg] thy end)))
113 (** get MethodC from Store **)
115 fun adapt_to_type ctxt {guh, mathauthors, start_refine, rew_ord, asm_rls, prog_rls, (*crls,*) rew_rls, errpats, calc,
116 program, where_rls, model, where_} =
118 val where_ = map (ParseC.adapt_term_to_type ctxt) where_
119 val model = map (Model_Pattern.adapt_to_type ctxt) model
120 val errpats = map (Error_Pattern_Def.adapt_to_type ctxt) errpats
122 {guh = guh, mathauthors = mathauthors, start_refine = start_refine, rew_ord = rew_ord, asm_rls = asm_rls,
123 prog_rls = prog_rls, (*crls = crls,*) rew_rls = rew_rls, errpats = errpats, calc = calc, program = program, where_rls = where_rls,
124 model = model, where_ = where_}
127 (* TODO: throws exn 'get_pbt not found: ' ... confusing !! take 'ketype' as an argument *)
128 fun from_store' thy id =
129 (Store.get (Know_Store.get_mets thy) id id)
131 raise error ("*** ERROR MethodC.from_store' thy " ^ strs2str id ^ " not found");
132 fun from_store ctxt id =
134 val pbl = Store.get (get_mets ()) id id
135 in adapt_to_type ctxt pbl end
137 raise error ("*** ERROR MethodC.from_store ctxt " ^ strs2str id ^ " not found");