walther@59866
|
1 |
(* Title: BaseDefinitions/thmC.sml
|
walther@59865
|
2 |
Author: Walther Neuper
|
walther@59865
|
3 |
(c) due to copyright terms
|
walther@59865
|
4 |
|
walther@59876
|
5 |
This structure could be dropped due to improved reflection in Isabelle;
|
walther@59876
|
6 |
but ThmC.sym_thm requires still an identifying string thm_id.
|
walther@59865
|
7 |
*)
|
walther@59865
|
8 |
signature THEOREM_ISAC =
|
walther@59865
|
9 |
sig
|
walther@59874
|
10 |
type T = ThmC_Def.T
|
walther@59874
|
11 |
type id = ThmC_Def.id;
|
walther@59875
|
12 |
|
walther@59871
|
13 |
val numerals_to_Free: thm -> thm
|
walther@59876
|
14 |
val thm_from_thy: theory -> ThmC_Def.id -> thm
|
walther@59865
|
15 |
|
walther@59876
|
16 |
val string_of_thm: thm -> string
|
walther@59876
|
17 |
val string_of_thms: thm list -> string
|
walther@59874
|
18 |
|
walther@59876
|
19 |
val cut_id: string -> string
|
walther@59876
|
20 |
val id_of_thm: thm -> string
|
walther@59876
|
21 |
val of_thm: thm -> T
|
walther@59874
|
22 |
|
walther@59876
|
23 |
val is_sym: id -> bool
|
walther@59876
|
24 |
val revert_sym_rule: theory -> Rule.rule -> Rule.rule
|
walther@59874
|
25 |
|
walther@59872
|
26 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59876
|
27 |
val string_of_thm_in_thy: theory -> thm -> string
|
walther@59876
|
28 |
val id_drop_sym: id -> id
|
walther@59876
|
29 |
val make_sym_rule: Rule.rule -> Rule.rule
|
walther@59876
|
30 |
val make_sym_rule_set: Rule_Set.T -> Rule_Set.T
|
walther@59872
|
31 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
walther@59876
|
32 |
val sym_thm: thm -> thm
|
walther@59872
|
33 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
walther@59865
|
34 |
end
|
walther@59865
|
35 |
|
walther@59865
|
36 |
(**)
|
walther@59865
|
37 |
structure ThmC(**): THEOREM_ISAC(**) =
|
walther@59865
|
38 |
struct
|
walther@59865
|
39 |
(**)
|
walther@59865
|
40 |
|
walther@59874
|
41 |
type T = ThmC_Def.T;
|
walther@59874
|
42 |
type id = ThmC_Def.id;
|
walther@59871
|
43 |
|
walther@59876
|
44 |
val string_of_thm = ThmC_Def.string_of_thm;
|
walther@59876
|
45 |
val string_of_thms = ThmC_Def.string_of_thms;
|
walther@59875
|
46 |
|
walther@59876
|
47 |
fun cut_id dn = last_elem (space_explode "." dn); (*the cut_id is the key into KEStore*)
|
walther@59876
|
48 |
fun id_of_thm thm = (cut_id o Thm.get_name_hint) thm;
|
walther@59876
|
49 |
fun of_thm thm = (id_of_thm thm, thm);
|
walther@59865
|
50 |
|
walther@59876
|
51 |
fun string_of_thm_in_thy thy thm = UnparseC.term_in_ctxt (ThyC.thy2ctxt thy) (Thm.prop_of thm);
|
walther@59874
|
52 |
|
walther@59874
|
53 |
|
walther@59876
|
54 |
(** convert Isabelle's numerals to ISAC's specific format, LEGACY **)
|
walther@59874
|
55 |
|
walther@59876
|
56 |
val numerals_to_Free = ThmC_Def.numerals_to_Free; (* numeral \<rightarrow> Free ("int", T) *)
|
walther@59872
|
57 |
|
walther@59872
|
58 |
(*
|
walther@59872
|
59 |
"metaview" as seen from programs and from user input;
|
walther@59872
|
60 |
both are parsed as terms by the function package.
|
walther@59872
|
61 |
*)
|
walther@59876
|
62 |
fun id_Isac_to_Isabelle thy thmid = (* Isac uses thmid *)
|
walther@59872
|
63 |
let val thmid' = case thmid of
|
walther@59872
|
64 |
"add_commute" => "add.commute"
|
walther@59872
|
65 |
| "mult_commute" => "mult.commute"
|
walther@59872
|
66 |
| "add_left_commute" => "add.left_commute"
|
walther@59872
|
67 |
| "mult_left_commute" => "mult.left_commute"
|
walther@59872
|
68 |
| "add_assoc" => "add.assoc"
|
walther@59872
|
69 |
| "mult_assoc" => "mult.assoc"
|
walther@59872
|
70 |
| _ => thmid
|
walther@59872
|
71 |
in (Global_Theory.get_thm thy) thmid' end;
|
walther@59876
|
72 |
(**)
|
walther@59876
|
73 |
|
walther@59876
|
74 |
|
walther@59876
|
75 |
(** handle symmetric equalities, generated by deriving input terms **)
|
walther@59876
|
76 |
|
walther@59876
|
77 |
fun is_sym id =
|
walther@59876
|
78 |
case Symbol.explode id of "s" :: "y" :: "m" :: "_" :: _ => true
|
walther@59876
|
79 |
| _ => false;
|
walther@59876
|
80 |
fun id_drop_sym id =
|
walther@59876
|
81 |
case Symbol.explode id of "s" :: "y" :: "m" :: "_" :: id => implode id
|
walther@59876
|
82 |
| _ => id
|
walther@59872
|
83 |
|
walther@59872
|
84 |
(* get the theorem associated with the xstring-identifier;
|
walther@59876
|
85 |
if the identifier starts with "sym_" then swap lhs = rhs" around "=";
|
walther@59876
|
86 |
in case identifiers starting with "#" come from Num_Calc and
|
walther@59876
|
87 |
get an ad-hoc theorem (containing numerals only) -- rejected here
|
walther@59876
|
88 |
*)
|
walther@59876
|
89 |
fun thm_from_thy thy thmid =
|
walther@59872
|
90 |
case Symbol.explode thmid of
|
walther@59876
|
91 |
"s" :: "y" :: "m" :: "_" :: "#" :: _ =>
|
walther@59876
|
92 |
raise ERROR ("thm_from_thy not impl.for " ^ thmid)
|
walther@59876
|
93 |
| "s" :: "y" :: "m" :: "_" :: id =>
|
walther@59876
|
94 |
((numerals_to_Free o (Global_Theory.get_thm thy)) (implode id)) RS sym
|
walther@59876
|
95 |
| "#" :: _ =>
|
walther@59876
|
96 |
raise ERROR ("thm_from_thy not impl.for " ^ thmid)
|
walther@59876
|
97 |
| _ =>
|
walther@59876
|
98 |
(**)thmid |> id_Isac_to_Isabelle thy |> numerals_to_Free(**)
|
walther@59876
|
99 |
(** )thmid |> Global_Theory.get_thm thy |> numerals_to_Free( **)
|
walther@59872
|
100 |
|
walther@59872
|
101 |
(* A1==>...==> An ==> (Lhs = Rhs) goes to A1 ==>...==> An ==> (Rhs = Lhs) *)
|
walther@59872
|
102 |
fun sym_thm thm =
|
walther@59872
|
103 |
let
|
walther@59872
|
104 |
val (deriv,
|
walther@59872
|
105 |
{cert = cert, tags = tags, maxidx = maxidx, shyps = shyps, hyps = hyps, tpairs = tpairs,
|
walther@59872
|
106 |
prop = prop}) = Thm.rep_thm_G thm
|
walther@59872
|
107 |
val (lhs, rhs) = (TermC.dest_equals o TermC.strip_trueprop o Logic.strip_imp_concl) prop
|
walther@59872
|
108 |
val prop' = case TermC.strip_imp_prems' prop of
|
walther@59872
|
109 |
NONE => HOLogic.Trueprop $ (TermC.mk_equality (rhs, lhs))
|
walther@59872
|
110 |
| SOME cs => TermC.ins_concl cs (HOLogic.Trueprop $ (TermC.mk_equality (rhs, lhs)))
|
walther@59876
|
111 |
in
|
walther@59876
|
112 |
Thm.assbl_thm deriv cert tags maxidx shyps hyps tpairs prop'
|
walther@59876
|
113 |
end
|
walther@59872
|
114 |
|
walther@59876
|
115 |
fun make_sym_rule_set Rule_Set.Empty = Rule_Set.Empty
|
walther@59876
|
116 |
| make_sym_rule_set (Rule_Def.Repeat {id, scr, calc, errpatts, erls, srls, rules, rew_ord, preconds}) =
|
walther@59872
|
117 |
Rule_Def.Repeat {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, srls = srls,
|
walther@59872
|
118 |
rules = rules, rew_ord = rew_ord, preconds = preconds}
|
walther@59876
|
119 |
| make_sym_rule_set (Rule_Set.Seqence {id, scr, calc, errpatts, erls, srls, rules, rew_ord, preconds}) =
|
walther@59872
|
120 |
Rule_Set.Seqence {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls, srls = srls,
|
walther@59872
|
121 |
rules = rules, rew_ord = rew_ord, preconds = preconds}
|
walther@59876
|
122 |
| make_sym_rule_set (Rule_Set.Rrls {id, scr, calc, errpatts, erls, prepat, rew_ord}) =
|
walther@59872
|
123 |
Rule_Set.Rrls {id = "sym_" ^ id, scr = scr, calc = calc, errpatts = errpatts, erls = erls,
|
walther@59872
|
124 |
prepat = prepat, rew_ord = rew_ord}
|
walther@59872
|
125 |
|
walther@59876
|
126 |
(* toggles sym_* and keeps "#:" for ad-hoc theorems *)
|
walther@59876
|
127 |
fun make_sym_rule (Rule.Thm (thmID, thm)) =
|
walther@59876
|
128 |
let
|
walther@59876
|
129 |
val thm' = sym_thm thm
|
walther@59876
|
130 |
val thmID' = case Symbol.explode thmID of
|
walther@59876
|
131 |
"s" :: "y" :: "m" :: "_" :: id => implode id
|
walther@59876
|
132 |
| "#" :: ":" :: _ => "#: " ^ string_of_thm thm'
|
walther@59876
|
133 |
| _ => "sym_" ^ thmID
|
walther@59876
|
134 |
in Rule.Thm (thmID', thm') end
|
walther@59876
|
135 |
| make_sym_rule (Rule.Rls_ rls) = Rule.Rls_ (make_sym_rule_set rls)
|
walther@59876
|
136 |
| make_sym_rule r = error ("make_sym_rule: not for " ^ Rule.to_string r)
|
walther@59872
|
137 |
|
walther@59876
|
138 |
fun revert_sym_rule thy (Rule.Thm (id, thm)) =
|
walther@59876
|
139 |
if is_sym (cut_id id)
|
walther@59874
|
140 |
then
|
walther@59874
|
141 |
let
|
walther@59876
|
142 |
val id' = id_drop_sym id
|
walther@59876
|
143 |
val thm' = thm_from_thy thy id'
|
walther@59876
|
144 |
val id'' = Thm.get_name_hint thm'
|
walther@59876
|
145 |
in Rule.Thm (id'', thm') end
|
walther@59874
|
146 |
else Rule.Thm (Thm.get_name_hint thm, thm)
|
walther@59876
|
147 |
| revert_sym_rule _ rule = raise ERROR ("revert_sym_rule: NOT for " ^ Rule.to_string rule)
|
walther@59874
|
148 |
|
walther@59874
|
149 |
(**)end(**)
|