walther@59866
|
1 |
(* Title: BaseDefinitions/thmC-def.sml
|
walther@59858
|
2 |
Author: Walther Neuper
|
walther@59858
|
3 |
(c) due to copyright terms
|
walther@59858
|
4 |
|
walther@59865
|
5 |
Probably this structure can be dropped due to improved reflection in Isabelle.
|
walther@59858
|
6 |
*)
|
walther@59865
|
7 |
signature THEOREM_ISAC_DEF =
|
walther@59858
|
8 |
sig
|
walther@59861
|
9 |
type thm'
|
walther@59861
|
10 |
type thm''
|
walther@59865
|
11 |
eqtype thmID
|
walther@59861
|
12 |
|
walther@59865
|
13 |
val id_of_thm: Rule_Def.rule -> string
|
walther@59865
|
14 |
val string_of_thmI: thm -> string
|
walther@59861
|
15 |
val thmID_of_derivation_name: string -> string
|
walther@59861
|
16 |
val thmID_of_derivation_name': thm -> string
|
walther@59861
|
17 |
val thm''_of_thm: thm -> thm''
|
walther@59864
|
18 |
val thm_of_thm: Rule_Def.rule -> thm
|
walther@59861
|
19 |
|
walther@59871
|
20 |
(* required only for ProgLang/ListC *)
|
walther@59871
|
21 |
val numerals_to_Free: thm -> thm (* belongs to ThmC *)
|
walther@59871
|
22 |
val int_of_str_opt: string -> int option (* belongs to TermC *)
|
walther@59871
|
23 |
val numbers_to_string: term -> term (* belongs to TermC *)
|
walther@59871
|
24 |
val uminus_to_string: term -> term (* belongs to TermC *)
|
walther@59871
|
25 |
|
walther@59858
|
26 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59858
|
27 |
val thm2str: thm -> string
|
walther@59858
|
28 |
val thms2str : thm list -> string
|
walther@59865
|
29 |
val string_of_thm': theory -> thm -> string
|
walther@59858
|
30 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
walther@59858
|
31 |
val string_of_thm: thm -> string
|
walther@59858
|
32 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
walther@59858
|
33 |
end
|
walther@59858
|
34 |
|
walther@59858
|
35 |
(**)
|
walther@59865
|
36 |
structure ThmC_Def(**): THEOREM_ISAC_DEF(**) =
|
walther@59858
|
37 |
struct
|
walther@59858
|
38 |
(**)
|
walther@59858
|
39 |
|
walther@59861
|
40 |
(* TODO CLEANUP Thm:
|
walther@59861
|
41 |
Thm (string, thm): (a) needs string to identify sym_thmID for handling in front-end;
|
walther@59865
|
42 |
(b) investigate if ""RS sym" attaches a [.]" still occurs: ThmC_Def.string_of_thmI
|
walther@59861
|
43 |
thmID : type for data from user input + program
|
walther@59861
|
44 |
thmDeriv : type for thy_hierarchy ONLY
|
walther@59861
|
45 |
obsolete types : thm' (SEE "ad thm'"), thm''.
|
walther@59861
|
46 |
revise funs : id_of_thm, thm_of_thm, rep_thm_G', eq_thmI, eq_thmI', thm''_of_thm thm.
|
walther@59861
|
47 |
activate : thmID_of_derivation_name'
|
walther@59861
|
48 |
*)
|
walther@59871
|
49 |
type thmID = string; (* identifier for a thm (the shortest string possible, without points) *)
|
walther@59865
|
50 |
(*
|
walther@59865
|
51 |
ad thm': there are two kinds of theorems ...
|
walther@59865
|
52 |
(1) defined in isabelle
|
walther@59865
|
53 |
(2) not known, eg. calc_thm, instantiated rls
|
walther@59865
|
54 |
the latter have a thmid "#..."
|
walther@59865
|
55 |
and thus outside isa we ALWAYS transport both (thmID, ThmC_Def.string_of_thmI)
|
walther@59865
|
56 |
and have a special assoc_thm / assoc_rls in this interface
|
walther@59865
|
57 |
*)
|
walther@59871
|
58 |
type thm' = thmID * UnparseC.term_as_string;(*WN060610 deprecated in favour of thm'';
|
walther@59871
|
59 |
WN180324: used in TODO review:
|
walther@59865
|
60 |
val thm'2xml : int -> ThmC_Def.thm' -> Celem.xml
|
walther@59865
|
61 |
val assoc_thm': theory -> ThmC_Def.thm' -> thm
|
walther@59865
|
62 |
| Calculate' of ThyC.theory' * string * term * (term * ThmC_Def.thm')
|
walther@59861
|
63 |
*)
|
walther@59861
|
64 |
(* tricky combination of (string, term) for theorems in Isac:
|
walther@59861
|
65 |
* case 1 general: frontend + lucin, e.g. applicable_in..Rewrite: (thmID, _) --> (thmID, thm)
|
walther@59861
|
66 |
by Global_Theory.get_thm, special cases ("add_commute",..) see convert_metaview_to_thmid.
|
walther@59861
|
67 |
* case 2 "sym_..": Global_Theory.get_thm..RS sym
|
walther@59861
|
68 |
* case 3 ad-hoc thm "#..." mk_thm from ad-hoc term (numerals only) in calculate_:
|
walther@59861
|
69 |
from applicable_in..Calculate: opstr --calculate_/adhoc_thm--> (thmID, thm)
|
walther@59861
|
70 |
*)
|
walther@59861
|
71 |
type thm'' = thmID * thm; (* only for transport via libisabelle isac-java <--- ME *)
|
walther@59861
|
72 |
|
walther@59858
|
73 |
fun thm2str thm =
|
walther@59858
|
74 |
let
|
walther@59858
|
75 |
val t = Thm.prop_of thm
|
walther@59858
|
76 |
val ctxt = Proof_Context.init_global (Thy_Info.get_theory ("Isac.Isac_Knowledge"))
|
walther@59858
|
77 |
val ctxt' = Config.put show_markup false ctxt
|
walther@59858
|
78 |
in Print_Mode.setmp [] (Syntax.string_of_term ctxt') t end;
|
walther@59858
|
79 |
fun thms2str thms = (strs2str o (map thm2str)) thms
|
walther@59858
|
80 |
|
walther@59858
|
81 |
(*check for [.] as caused by "fun assoc_thm'"*)
|
walther@59870
|
82 |
fun string_of_thm thm = UnparseC.term_in_ctxt (ThyC.thy2ctxt' "Isac_Knowledge") (Thm.prop_of thm)
|
walther@59870
|
83 |
fun string_of_thm' thy thm = UnparseC.term_in_ctxt (ThyC.thy2ctxt thy) (Thm.prop_of thm)
|
walther@59858
|
84 |
fun string_of_thmI thm =
|
walther@59858
|
85 |
let
|
walther@59858
|
86 |
val str = (de_quote o string_of_thm) thm
|
walther@59858
|
87 |
val (a, b) = split_nlast (5, Symbol.explode str)
|
walther@59858
|
88 |
in
|
walther@59858
|
89 |
case b of
|
walther@59858
|
90 |
[" ", " ","[", ".", "]"] => implode a
|
walther@59858
|
91 |
| _ => str
|
walther@59858
|
92 |
end
|
walther@59858
|
93 |
|
walther@59871
|
94 |
fun id_of_thm (Rule_Def.Thm (id, _)) = id
|
walther@59867
|
95 |
| id_of_thm _ = raise ERROR ("id_of_thm: uncovered case " (* ^ to_string r *))
|
walther@59861
|
96 |
|
walther@59861
|
97 |
fun thmID_of_derivation_name dn = last_elem (space_explode "." dn);
|
walther@59861
|
98 |
fun thmID_of_derivation_name' thm = (thmID_of_derivation_name o Thm.get_name_hint) thm
|
walther@59871
|
99 |
fun thm_of_thm (Rule_Def.Thm (_, thm)) = thm
|
walther@59867
|
100 |
| thm_of_thm _ = raise ERROR ("thm_of_thm: uncovered case " (* ^ to_string r *))
|
walther@59861
|
101 |
fun thm''_of_thm thm = (thmID_of_derivation_name' thm, thm) : thm''
|
walther@59861
|
102 |
|
walther@59871
|
103 |
fun int_of_str_opt str =
|
walther@59871
|
104 |
let
|
walther@59871
|
105 |
val ss = Symbol.explode str
|
walther@59871
|
106 |
val ss' = case ss of "(" :: s => drop_last s | _ => ss
|
walther@59871
|
107 |
val (sign, istr) = case ss' of "-" :: istr => (~1, istr) | _ => (1, ss')
|
walther@59871
|
108 |
in
|
walther@59871
|
109 |
case Library.read_int istr of (i, []) => SOME (sign * i) | _ => NONE
|
walther@59871
|
110 |
end;
|
walther@59871
|
111 |
|
walther@59871
|
112 |
(** transform binary numeralsstrings **)
|
walther@59871
|
113 |
|
walther@59871
|
114 |
(*Makarius 100308, hacked by WN*)
|
walther@59871
|
115 |
val numbers_to_string =
|
walther@59871
|
116 |
let
|
walther@59871
|
117 |
fun dest_num t =
|
walther@59871
|
118 |
(case try HOLogic.dest_number t of
|
walther@59871
|
119 |
SOME (T, i) =>
|
walther@59871
|
120 |
(*if T = @{typ int} orelse T = @{typ real} then WN*)
|
walther@59871
|
121 |
SOME (Free (signed_string_of_int i, T))
|
walther@59871
|
122 |
(*else NONE WN*)
|
walther@59871
|
123 |
| NONE => NONE);
|
walther@59871
|
124 |
fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
|
walther@59871
|
125 |
| to_str (t as (u1 $ u2)) =
|
walther@59871
|
126 |
(case dest_num t of
|
walther@59871
|
127 |
SOME t' => t'
|
walther@59871
|
128 |
| NONE => to_str u1 $ to_str u2)
|
walther@59871
|
129 |
| to_str t = perhaps dest_num t;
|
walther@59871
|
130 |
in to_str end
|
walther@59871
|
131 |
val uminus_to_string =
|
walther@59871
|
132 |
let
|
walther@59871
|
133 |
fun dest_num t =
|
walther@59871
|
134 |
case t of
|
walther@59871
|
135 |
(Const ("Groups.uminus_class.uminus", _) $ Free (s, T)) =>
|
walther@59871
|
136 |
(case int_of_str_opt s of
|
walther@59871
|
137 |
SOME i => SOME (Free (signed_string_of_int (~1 * i), T))
|
walther@59871
|
138 |
| NONE => NONE)
|
walther@59871
|
139 |
| _ => NONE;
|
walther@59871
|
140 |
fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
|
walther@59871
|
141 |
| to_str (t as (u1 $ u2)) =
|
walther@59871
|
142 |
(case dest_num t of SOME t' => t' | NONE => to_str u1 $ to_str u2)
|
walther@59871
|
143 |
| to_str t = perhaps dest_num t;
|
walther@59871
|
144 |
in to_str end;
|
walther@59871
|
145 |
fun numerals_to_Free thm =
|
walther@59871
|
146 |
let
|
walther@59871
|
147 |
val (deriv,
|
walther@59871
|
148 |
{cert = cert, tags = tags, maxidx = maxidx, shyps = shyps,
|
walther@59871
|
149 |
hyps = hyps, tpairs = tpairs, prop = prop}) = Thm.rep_thm_G thm
|
walther@59871
|
150 |
val prop' = numbers_to_string prop;
|
walther@59871
|
151 |
in Thm.assbl_thm deriv cert tags maxidx shyps hyps tpairs prop' end;
|
walther@59871
|
152 |
|
walther@59858
|
153 |
(**)end(**)
|