walther@59894
|
1 |
(* Title: Interpret/lucas-interpreter.sml
|
walther@59894
|
2 |
Author: Walther Neuper 2019
|
walther@59894
|
3 |
(c) due to copyright terms
|
walther@59894
|
4 |
*)
|
walther@59894
|
5 |
|
walther@59894
|
6 |
signature COMPUTER_ALGEBRA_SYSTEM_COMMAND =
|
walther@59894
|
7 |
sig
|
walther@59982
|
8 |
type T = CAS_Def.T
|
walther@60097
|
9 |
val input : term -> (Ctree.ctree * SpecificationC.T) option
|
walther@59982
|
10 |
val is_from: TermC.as_string -> Formalise.T -> bool
|
wenzelm@60223
|
11 |
\<^isac_test>\<open>
|
walther@59982
|
12 |
val input_: References.T -> (term * term list) list ->
|
walther@60154
|
13 |
Problem.id * I_Model.T * MethodC.id * I_Model.T * Pre_Conds.T * Proof.context
|
walther@59982
|
14 |
|
walther@59982
|
15 |
val dtss2itm_: Model_Pattern.T -> term * term list ->
|
walther@59982
|
16 |
int list * bool * string * I_Model.feedback (*I_Model.single'*)
|
walther@59982
|
17 |
val flattup2: 'a * ('b * 'c * 'd * 'e) -> 'a * 'b * 'c * 'd * 'e
|
wenzelm@60223
|
18 |
\<close>
|
walther@59894
|
19 |
end
|
walther@59894
|
20 |
|
walther@59894
|
21 |
(**)
|
walther@59894
|
22 |
structure CAS_Cmd(**): COMPUTER_ALGEBRA_SYSTEM_COMMAND(**) =
|
walther@59894
|
23 |
struct
|
walther@59894
|
24 |
(**)
|
walther@59894
|
25 |
|
walther@59896
|
26 |
type T = CAS_Def.T;
|
walther@59896
|
27 |
|
walther@59982
|
28 |
fun dtss2itm_ ppc (d, ts) =
|
walther@59982
|
29 |
let
|
walther@59982
|
30 |
val (f, (d, id)) = the (find_first ((curry op= d) o
|
walther@59982
|
31 |
(#1: (term * term) -> term) o
|
walther@59982
|
32 |
(#2: Model_Pattern.single -> (term * term))) ppc)
|
walther@59982
|
33 |
in
|
walther@59982
|
34 |
([1], true, f, I_Model.Cor ((d, ts), (id, ts)))
|
walther@59982
|
35 |
end
|
walther@59982
|
36 |
|
walther@59982
|
37 |
fun flattup2 (a, (b ,c, d, e)) = (a, b, c, d, e)
|
walther@59982
|
38 |
|
walther@59982
|
39 |
fun is_from (hdf : TermC.as_string) ((fmz_, spec) : Formalise.T) =
|
walther@59982
|
40 |
hdf <> "" andalso fmz_ = [] andalso spec = References.empty
|
walther@59982
|
41 |
|
walther@59982
|
42 |
fun input_ ((dI, pI, mI): References.T) dtss = (*WN110515 reconsider thy..ctxt*)
|
walther@59982
|
43 |
let
|
walther@59982
|
44 |
val thy = ThyC.get_theory dI
|
walther@59982
|
45 |
val {ppc, ...} = Problem.from_store pI
|
walther@59982
|
46 |
val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
|
walther@59982
|
47 |
val its = O_Model.add_id its_
|
walther@59982
|
48 |
val pits = map flattup2 its
|
walther@59982
|
49 |
val (pI, mI) =
|
walther@59982
|
50 |
if mI <> ["no_met"]
|
walther@59982
|
51 |
then (pI, mI)
|
walther@59982
|
52 |
else
|
walther@59982
|
53 |
case Refine.problem thy pI pits of
|
walther@59982
|
54 |
SOME (pI,_) => (pI, (hd o #met o Problem.from_store) pI)
|
walther@59982
|
55 |
| NONE => (pI, (hd o #met o Problem.from_store) pI)
|
walther@60154
|
56 |
val {ppc, pre, prls, ...} = MethodC.from_store mI
|
walther@59982
|
57 |
val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
|
walther@59982
|
58 |
val its = O_Model.add_id its_
|
walther@59982
|
59 |
val mits = map flattup2 its
|
walther@60018
|
60 |
val (_, pre) = Pre_Conds.check prls pre mits 0
|
walther@59982
|
61 |
val ctxt = Proof_Context.init_global thy
|
walther@59982
|
62 |
in (pI, pits, mI, mits, pre, ctxt) end;
|
walther@59982
|
63 |
|
walther@59982
|
64 |
(* check if the input term is a CAScmd and return a ctree with a _complete_ calchead *)
|
walther@59982
|
65 |
fun input hdt =
|
walther@59982
|
66 |
let
|
walther@59982
|
67 |
val (h, argl) = strip_comb hdt
|
walther@59982
|
68 |
in
|
walther@59982
|
69 |
case assoc_cas (ThyC.get_theory "Isac_Knowledge") h of
|
walther@59982
|
70 |
NONE => NONE
|
walther@59982
|
71 |
| SOME (spec as (dI,_,_), argl2dtss) =>
|
walther@59982
|
72 |
let
|
walther@59982
|
73 |
val dtss = argl2dtss argl
|
walther@59982
|
74 |
val (pI, pits, mI, mits, pre, ctxt) = input_ spec dtss
|
walther@59982
|
75 |
val spec = (dI, pI, mI)
|
walther@59982
|
76 |
val (pt,_) = Ctree.cappend_problem Ctree.e_ctree [] (Istate_Def.empty, ContextC.empty)
|
walther@59982
|
77 |
([], References.empty) ([], References.empty, hdt, ctxt)
|
walther@59982
|
78 |
val pt = Ctree.update_spec pt [] spec
|
walther@59982
|
79 |
val pt = Ctree.update_pbl pt [] pits
|
walther@59982
|
80 |
val pt = Ctree.update_met pt [] mits
|
walther@59982
|
81 |
in
|
walther@60097
|
82 |
SOME (pt, (true, Pos.Met, hdt, mits, pre, spec) : SpecificationC.T)
|
walther@59982
|
83 |
end
|
walther@59982
|
84 |
end
|
walther@59894
|
85 |
|
walther@59894
|
86 |
(**)end(**)
|