author | wenzelm |
Tue, 21 Jan 2025 23:15:03 +0100 | |
changeset 81948 | 0e2f019477e2 |
parent 81947 | 5be5b2114ecd |
child 81949 | eea30b3de57f |
permissions | -rw-r--r-- |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
1 |
(* Title: HOL/Import/import_rule.ML |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
2 |
Author: Cezary Kaliszyk, University of Innsbruck |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
3 |
Author: Alexander Krauss, QAware GmbH |
81933 | 4 |
Author: Makarius |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
5 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
6 |
Importer proof rules and processing of lines and files. |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
7 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
8 |
Based on earlier code by Steven Obua and Sebastian Skalberg. |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
9 |
*) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
10 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
11 |
signature IMPORT_RULE = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
12 |
sig |
81926 | 13 |
val trace : bool Config.T |
14 |
type name = {hol: string, isabelle: string} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
15 |
val beta : cterm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
16 |
val eq_mp : thm -> thm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
17 |
val comb : thm -> thm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
18 |
val trans : thm -> thm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
19 |
val deduct : thm -> thm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
20 |
val conj1 : thm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
21 |
val conj2 : thm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
22 |
val refl : cterm -> thm |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
23 |
val abs : cterm -> thm -> thm |
81835 | 24 |
val mdef : theory -> string -> thm |
81926 | 25 |
val def : name -> cterm -> theory -> thm * theory |
81835 | 26 |
val mtydef : theory -> string -> thm |
81926 | 27 |
val tydef : name -> string -> string -> cterm -> cterm -> thm -> theory -> thm * theory |
81856
4af2e864c26c
clarified inst_type: more direct Thm.instantiate_frees;
wenzelm
parents:
81855
diff
changeset
|
28 |
val inst_type : (ctyp * ctyp) list -> thm -> thm |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
29 |
val inst : (cterm * cterm) list -> thm -> thm |
81847 | 30 |
val import_file : Path.T -> theory -> theory |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
31 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
32 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
33 |
structure Import_Rule: IMPORT_RULE = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
34 |
struct |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
35 |
|
81926 | 36 |
(* tracing *) |
37 |
||
38 |
val trace = Attrib.setup_config_bool \<^binding>\<open>import_trace\<close> (K false) |
|
39 |
||
40 |
type name = {hol: string, isabelle: string} |
|
41 |
||
42 |
fun print_name {hol, isabelle} = |
|
43 |
if hol = isabelle then quote hol |
|
44 |
else quote hol ^ " = " ^ quote isabelle |
|
45 |
||
46 |
fun print_item kind name = |
|
47 |
Markup.markup Markup.keyword1 kind ^ " " ^ print_name name |
|
48 |
||
49 |
fun tracing_item thy kind name = |
|
50 |
if Config.get_global thy trace then tracing (print_item kind name) else () |
|
51 |
||
52 |
||
53 |
||
81909 | 54 |
(** primitive rules of HOL Light **) |
55 |
||
56 |
(* basic logic *) |
|
57 |
||
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
58 |
fun to_obj_eq th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
59 |
let |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
60 |
val (t, u) = Thm.dest_equals (Thm.cprop_of th) |
81866 | 61 |
val A = Thm.ctyp_of_cterm t |
62 |
val rl = Thm.instantiate' [SOME A] [SOME t, SOME u] @{thm meta_eq_to_obj_eq} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
63 |
in |
81866 | 64 |
Thm.implies_elim rl th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
65 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
66 |
|
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
67 |
fun to_meta_eq th = |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
68 |
let |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
69 |
val (t, u) = Thm.dest_binop (HOLogic.dest_judgment (Thm.cprop_of th)) |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
70 |
val A = Thm.ctyp_of_cterm t |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
71 |
val rl = Thm.instantiate' [SOME A] [SOME t, SOME u] @{thm eq_reflection} |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
72 |
in |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
73 |
Thm.implies_elim rl th |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
74 |
end |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
75 |
|
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
76 |
fun beta t = Thm.beta_conversion false t |> to_obj_eq |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
77 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
78 |
fun eq_mp th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
79 |
let |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
80 |
val (Q, P) = Thm.dest_binop (HOLogic.dest_judgment (Thm.cprop_of th1)) |
81944 | 81 |
val rl = Thm.instantiate' [] [SOME Q, SOME P] @{thm iffD1} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
82 |
in |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
83 |
Thm.implies_elim (Thm.implies_elim rl th1) th2 |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
84 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
85 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
86 |
fun comb th1 th2 = |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
87 |
Thm.combination (to_meta_eq th1) (to_meta_eq th2) |> to_obj_eq |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
88 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
89 |
fun trans th1 th2 = |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
90 |
Thm.transitive (to_meta_eq th1) (to_meta_eq th2) |> to_obj_eq |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
91 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
92 |
fun deduct th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
93 |
let |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
94 |
val Q = Thm.cprop_of th1 |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
95 |
val P = Thm.cprop_of th2 |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
96 |
val th1' = Thm.implies_intr P th1 |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
97 |
val th2' = Thm.implies_intr Q th2 |
81944 | 98 |
val rl = |
99 |
Thm.instantiate' [] [SOME (HOLogic.dest_judgment Q), SOME (HOLogic.dest_judgment P)] |
|
100 |
@{thm iffI} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
101 |
in |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
102 |
Thm.implies_elim (Thm.implies_elim rl th2') th1' |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
103 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
104 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
105 |
fun conj1 th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
106 |
let |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
107 |
val (P, Q) = Thm.dest_binop (HOLogic.dest_judgment (Thm.cprop_of th)) |
81944 | 108 |
val rl = Thm.instantiate' [] [SOME P, SOME Q] @{thm conjunct1} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
109 |
in |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
110 |
Thm.implies_elim rl th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
111 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
112 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
113 |
fun conj2 th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
114 |
let |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
115 |
val (P, Q) = Thm.dest_binop (HOLogic.dest_judgment (Thm.cprop_of th)) |
81944 | 116 |
val rl = Thm.instantiate' [] [SOME P, SOME Q] @{thm conjunct2} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
117 |
in |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
118 |
Thm.implies_elim rl th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
119 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
120 |
|
81866 | 121 |
fun refl t = |
122 |
let val A = Thm.ctyp_of_cterm t |
|
123 |
in Thm.instantiate' [SOME A] [SOME t] @{thm refl} end |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
124 |
|
81866 | 125 |
fun abs x th = |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
126 |
to_meta_eq th |> Thm.abstract_rule (Term.term_name (Thm.term_of x)) x |> to_obj_eq |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
127 |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
128 |
|
81909 | 129 |
|
130 |
(* instantiation *) |
|
131 |
||
81852 | 132 |
fun freezeT thy th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
133 |
let |
81857 | 134 |
fun add (v as ((a, _), S)) tvars = |
135 |
if TVars.defined tvars v then tvars |
|
136 |
else TVars.add (v, Thm.global_ctyp_of thy (TFree (a, S))) tvars |
|
137 |
val tyinst = |
|
138 |
TVars.build (Thm.prop_of th |> (fold_types o fold_atyps) (fn TVar v => add v | _ => I)) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
139 |
in |
81857 | 140 |
Thm.instantiate (tyinst, Vars.empty) th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
141 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
142 |
|
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
143 |
fun freeze' th = |
81858
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
144 |
let |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
145 |
val vars = Vars.build (th |> Thm.add_vars) |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
146 |
val inst = vars |> Vars.map (fn _ => fn v => |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
147 |
let |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
148 |
val Var ((x, _), _) = Thm.term_of v |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
149 |
val ty = Thm.ctyp_of_cterm v |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
150 |
in Thm.free (x, ty) end) |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
151 |
in |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
152 |
Thm.instantiate (TVars.empty, inst) th |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
153 |
end |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
154 |
|
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
155 |
fun freeze thy = freezeT thy #> freeze'; |
81858
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
156 |
|
81937 | 157 |
fun inst_type theta = |
81909 | 158 |
let |
159 |
val tyinst = |
|
81937 | 160 |
TFrees.build (theta |> fold (fn (a, b) => |
81909 | 161 |
TFrees.add (Term.dest_TFree (Thm.typ_of a), b))) |
162 |
in |
|
163 |
Thm.instantiate_frees (tyinst, Frees.empty) |
|
164 |
end |
|
165 |
||
81937 | 166 |
fun inst theta th = |
81909 | 167 |
let |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
168 |
val inst = |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
169 |
Frees.build (theta |> fold (fn (a, b) => |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
170 |
Frees.add (Term.dest_Free (Thm.term_of a), b))) |
81909 | 171 |
in |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
172 |
Thm.instantiate_frees (TFrees.empty, inst) th |
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
173 |
|> freeze' |
81909 | 174 |
end |
175 |
||
176 |
||
177 |
(* constant definitions *) |
|
178 |
||
81926 | 179 |
fun def' (name as {isabelle = c, ...}) rhs thy = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
180 |
let |
81926 | 181 |
val _ = tracing_item thy "const" name; |
81840 | 182 |
val b = Binding.name c |
81852 | 183 |
val ty = type_of rhs |
184 |
val thy1 = Sign.add_consts [(b, ty, NoSyn)] thy |
|
185 |
val eq = Logic.mk_equals (Const (Sign.full_name thy1 b, ty), rhs) |
|
186 |
val (th, thy2) = Global_Theory.add_def (Binding.suffix_name "_hldef" b, eq) thy1 |
|
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
187 |
val def_thm = freezeT thy1 th |> to_obj_eq |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
188 |
in |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
189 |
(def_thm, thy2) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
190 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
191 |
|
81835 | 192 |
fun mdef thy name = |
81866 | 193 |
(case Import_Data.get_const_def thy name of |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
194 |
SOME th => th |
81866 | 195 |
| NONE => error ("Constant mapped, but no definition: " ^ quote name)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
196 |
|
81926 | 197 |
fun def (name as {isabelle = c, ...}) rhs thy = |
81861 | 198 |
if is_some (Import_Data.get_const_def thy c) then |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
199 |
(warning ("Const mapped, but def provided: " ^ quote c); (freeze thy (mdef thy c), thy)) |
81926 | 200 |
else def' name (Thm.term_of rhs) thy |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
201 |
|
81909 | 202 |
|
203 |
(* type definitions *) |
|
204 |
||
81861 | 205 |
fun typedef_hol2hollight A B rep abs pred a r = |
206 |
Thm.instantiate' [SOME A, SOME B] [SOME rep, SOME abs, SOME pred, SOME a, SOME r] |
|
81829 | 207 |
@{lemma "type_definition Rep Abs (Collect P) \<Longrightarrow> Abs (Rep a) = a \<and> P r = (Rep (Abs r) = r)" |
208 |
by (metis type_definition.Rep_inverse type_definition.Abs_inverse |
|
209 |
type_definition.Rep mem_Collect_eq)} |
|
210 |
||
81861 | 211 |
fun typedef_hollight th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
212 |
let |
81866 | 213 |
val ((rep, abs), P) = |
81943 | 214 |
Thm.dest_comb (HOLogic.dest_judgment (Thm.cprop_of th)) |
81866 | 215 |
|>> (Thm.dest_comb #>> Thm.dest_arg) |
216 |
||> Thm.dest_arg |
|
217 |
val [A, B] = Thm.dest_ctyp (Thm.ctyp_of_cterm rep) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
218 |
in |
81866 | 219 |
typedef_hol2hollight A B rep abs P (Thm.free ("a", A)) (Thm.free ("r", B)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
220 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
221 |
|
81926 | 222 |
fun tydef' (name as {isabelle = tycname, ...}) abs_name rep_name cP ct td_th thy = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
223 |
let |
81926 | 224 |
val _ = tracing_item thy "type" name; |
225 |
||
59586 | 226 |
val ctT = Thm.ctyp_of_cterm ct |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
227 |
val th2 = |
81905 | 228 |
Thm.instantiate' [SOME ctT] [SOME cP, SOME ct] |
229 |
@{lemma "P t \<Longrightarrow> \<exists>x. x \<in> Collect P" by auto} |
|
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
230 |
|> Thm.elim_implies td_th |
59582 | 231 |
val c = |
81866 | 232 |
(case Thm.concl_of th2 of |
81841 | 233 |
\<^Const_>\<open>Trueprop for \<^Const_>\<open>Ex _ for \<open>Abs (_, _, \<^Const_>\<open>Set.member _ for _ c\<close>)\<close>\<close>\<close> => c |
81866 | 234 |
| _ => raise THM ("type_introduction: bad type definition theorem", 0, [th2])) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
235 |
val tfrees = Term.add_tfrees c [] |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
236 |
val tnames = sort_strings (map fst tfrees) |
61110 | 237 |
val typedef_bindings = |
62513
702085ca8564
take qualification of type name more seriously: derived consts and facts are qualified uniformly;
wenzelm
parents:
62436
diff
changeset
|
238 |
{Rep_name = Binding.name rep_name, |
702085ca8564
take qualification of type name more seriously: derived consts and facts are qualified uniformly;
wenzelm
parents:
62436
diff
changeset
|
239 |
Abs_name = Binding.name abs_name, |
702085ca8564
take qualification of type name more seriously: derived consts and facts are qualified uniformly;
wenzelm
parents:
62436
diff
changeset
|
240 |
type_definition_name = Binding.name ("type_definition_" ^ tycname)} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
241 |
val ((_, typedef_info), thy') = |
81947 | 242 |
Typedef.add_typedef_global {overloaded = false} |
61260 | 243 |
(Binding.name tycname, map (rpair dummyS) tnames, NoSyn) c |
81947 | 244 |
(SOME typedef_bindings) (fn ctxt => resolve_tac ctxt [th2] 1) thy |
81855 | 245 |
val aty = Thm.global_ctyp_of thy' (#abs_type (#1 typedef_info)) |
60648 | 246 |
val th = freezeT thy' (#type_definition (#2 typedef_info)) |
81946
ee680c69de38
misc tuning: prefer specific variants of Thm.dest_comb;
wenzelm
parents:
81944
diff
changeset
|
247 |
val (rep, abs) = Thm.dest_binop (Thm.dest_fun (HOLogic.dest_judgment (Thm.cprop_of th))) |
81861 | 248 |
val [A, B] = Thm.dest_ctyp (Thm.ctyp_of_cterm rep) |
249 |
val typedef_th = typedef_hol2hollight A B rep abs cP (Thm.free ("a", aty)) (Thm.free ("r", ctT)) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
250 |
in |
81855 | 251 |
(typedef_th OF [#type_definition (#2 typedef_info)], thy') |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
252 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
253 |
|
81835 | 254 |
fun mtydef thy name = |
81866 | 255 |
(case Import_Data.get_typ_def thy name of |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
256 |
SOME th => Thm.implies_elim (typedef_hollight th) th |
81866 | 257 |
| NONE => error ("Type mapped, but no tydef thm registered: " ^ quote name)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
258 |
|
81926 | 259 |
fun tydef (name as {hol = tycname, ...}) abs_name rep_name P t td_th thy = |
81866 | 260 |
if is_some (Import_Data.get_typ_def thy tycname) then |
261 |
(warning ("Type mapped but proofs provided: " ^ quote tycname); (mtydef thy tycname, thy)) |
|
81926 | 262 |
else tydef' name abs_name rep_name P t td_th thy |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
263 |
|
81909 | 264 |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
265 |
|
81909 | 266 |
(** importer **) |
267 |
||
268 |
(* basic entities *) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
269 |
|
81926 | 270 |
fun make_name hol = |
271 |
{hol = hol, isabelle = String.translate (fn #"." => "dot" | c => Char.toString c) hol} |
|
81831 | 272 |
|
81932 | 273 |
fun make_bound a = |
274 |
(case try (unprefix "_") a of |
|
275 |
SOME b => if forall_string Symbol.is_ascii_digit b then "u" else b |
|
276 |
| NONE => a); |
|
277 |
||
81926 | 278 |
fun make_free x ty = Thm.free (#isabelle (make_name x), ty); |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
279 |
|
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
280 |
fun make_tfree thy a = |
81831 | 281 |
let val b = "'" ^ String.translate (fn #"?" => "t" | c => Char.toString c) a |
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
282 |
in Thm.global_ctyp_of thy (TFree (b, \<^sort>\<open>type\<close>)) end |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
283 |
|
81908 | 284 |
fun make_type thy c args = |
81837 | 285 |
let |
286 |
val d = |
|
287 |
(case Import_Data.get_typ_map thy c of |
|
288 |
SOME d => d |
|
81926 | 289 |
| NONE => Sign.full_bname thy (#isabelle (make_name c))) |
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
290 |
val T = Thm.global_ctyp_of thy (Type (d, replicate (length args) dummyT)) |
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
291 |
in Thm.make_ctyp T args end |
81837 | 292 |
|
81908 | 293 |
fun make_const thy c ty = |
81831 | 294 |
let |
295 |
val d = |
|
81835 | 296 |
(case Import_Data.get_const_map thy c of |
81831 | 297 |
SOME d => d |
81926 | 298 |
| NONE => Sign.full_bname thy (#isabelle (make_name c))) |
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
299 |
in Thm.global_cterm_of thy (Const (d, Thm.typ_of ty)) end |
81831 | 300 |
|
81942
da3c3948a39c
clarified signature: more uniform cterm operations, without context;
wenzelm
parents:
81938
diff
changeset
|
301 |
val make_thm = Skip_Proof.make_thm_cterm o HOLogic.mk_judgment |
81948
0e2f019477e2
more direct emulation of HOL Light inferences: prefer Pure rules over HOL thms;
wenzelm
parents:
81947
diff
changeset
|
302 |
val assume_thm = Thm.assume_cterm o HOLogic.mk_judgment |
81908 | 303 |
|
81854 | 304 |
|
81909 | 305 |
(* import file *) |
306 |
||
307 |
local |
|
308 |
||
81854 | 309 |
datatype state = |
310 |
State of theory * (ctyp Inttab.table * int) * (cterm Inttab.table * int) * (thm Inttab.table * int) |
|
311 |
||
312 |
fun init_state thy = State (thy, (Inttab.empty, 0), (Inttab.empty, 0), (Inttab.empty, 0)) |
|
313 |
||
81913 | 314 |
fun get (tab, reg) s = |
81854 | 315 |
(case Int.fromString s of |
81859
6cc57bd46179
clarified exceptions and messages: use "error" only for user-errors, not system failures;
wenzelm
parents:
81858
diff
changeset
|
316 |
NONE => raise Fail "get: not a number" |
81854 | 317 |
| SOME i => |
318 |
(case Inttab.lookup tab (Int.abs i) of |
|
81859
6cc57bd46179
clarified exceptions and messages: use "error" only for user-errors, not system failures;
wenzelm
parents:
81858
diff
changeset
|
319 |
NONE => raise Fail "get: lookup failed" |
81913 | 320 |
| SOME res => (res, (if i < 0 then Inttab.delete (Int.abs i) tab else tab, reg)))) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
321 |
|
81854 | 322 |
fun get_theory (State (thy, _, _, _)) = thy; |
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
323 |
val theory = `get_theory; |
81913 | 324 |
fun theory_op f (State (thy, a, b, c)) = let val (y, thy') = f thy in (y, State (thy', a, b, c)) end; |
81854 | 325 |
|
326 |
fun typ i (State (thy, a, b, c)) = let val (i, a') = get a i in (i, State (thy, a', b, c)) end |
|
327 |
fun term i (State (thy, a, b, c)) = let val (i, b') = get b i in (i, State (thy, a, b', c)) end |
|
328 |
fun thm i (State (thy, a, b, c)) = let val (i, c') = get c i in (i, State (thy, a, b, c')) end |
|
329 |
||
81908 | 330 |
val typs = fold_map typ |
331 |
val terms = fold_map term |
|
332 |
||
81913 | 333 |
fun set (tab, reg) res = (Inttab.update_new (reg + 1, res) tab, reg + 1) |
81854 | 334 |
fun set_typ ty (State (thy, a, b, c)) = State (thy, set a ty, b, c) |
335 |
fun set_term tm (State (thy, a, b, c)) = State (thy, a, set b tm, c) |
|
336 |
fun set_thm th (State (thy, a, b, c)) = State (thy, a, b, set c th) |
|
337 |
||
81911 | 338 |
fun stored_thm name (State (thy, a, b, c)) = |
339 |
let val th = freeze thy (Global_Theory.get_thm thy name) |
|
340 |
in State (thy, a, b, set c th) end |
|
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
341 |
|
81913 | 342 |
fun store_thm name (State (thy, a, b, c as (tab, reg))) = |
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
343 |
let |
81926 | 344 |
val _ = tracing_item thy "thm" name; |
345 |
||
81912 | 346 |
val th = |
81913 | 347 |
(case Inttab.lookup tab reg of |
348 |
NONE => raise Fail "store_thm: lookup failed" |
|
81912 | 349 |
| SOME th0 => Drule.export_without_context_open th0) |
350 |
||
351 |
val tvars = TVars.build (Thm.fold_terms {hyps = false} TVars.add_tvars th); |
|
352 |
val names = Name.invent_global_types (TVars.size tvars) |
|
353 |
val tyinst = |
|
354 |
TVars.build (fold2 |
|
355 |
(fn v as ((_, i), S) => fn b => TVars.add (v, Thm.global_ctyp_of thy (TVar ((b, i), S)))) |
|
356 |
(TVars.list_set tvars) names) |
|
357 |
||
358 |
val th' = Thm.instantiate (tyinst, Vars.empty) th |
|
81926 | 359 |
val thy' = #2 (Global_Theory.add_thm ((Binding.name (#isabelle name), th'), []) thy) |
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
360 |
in State (thy', a, b, c) end |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
361 |
|
81849 | 362 |
fun pair_list (x :: y :: zs) = ((x, y) :: pair_list zs) |
363 |
| pair_list [] = [] |
|
81859
6cc57bd46179
clarified exceptions and messages: use "error" only for user-errors, not system failures;
wenzelm
parents:
81858
diff
changeset
|
364 |
| pair_list _ = raise Fail "pair_list: odd list length" |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
365 |
|
81847 | 366 |
fun parse_line s = |
367 |
(case String.tokens (fn x => x = #"\n" orelse x = #" ") s of |
|
81859
6cc57bd46179
clarified exceptions and messages: use "error" only for user-errors, not system failures;
wenzelm
parents:
81858
diff
changeset
|
368 |
[] => raise Fail "parse_line: empty" |
81847 | 369 |
| cmd :: args => |
370 |
(case String.explode cmd of |
|
81859
6cc57bd46179
clarified exceptions and messages: use "error" only for user-errors, not system failures;
wenzelm
parents:
81858
diff
changeset
|
371 |
[] => raise Fail "parse_line: empty command" |
81847 | 372 |
| c :: cs => (c, String.implode cs :: args))) |
373 |
||
81907 | 374 |
fun command (#"R", [t]) = term t #>> refl #-> set_thm |
375 |
| command (#"B", [t]) = term t #>> beta #-> set_thm |
|
376 |
| command (#"1", [th]) = thm th #>> conj1 #-> set_thm |
|
377 |
| command (#"2", [th]) = thm th #>> conj2 #-> set_thm |
|
81908 | 378 |
| command (#"H", [t]) = term t #>> assume_thm #-> set_thm |
379 |
| command (#"A", [_, t]) = term t #>> make_thm #-> set_thm |
|
81907 | 380 |
| command (#"C", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry comb #-> set_thm |
381 |
| command (#"T", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry trans #-> set_thm |
|
382 |
| command (#"E", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry eq_mp #-> set_thm |
|
383 |
| command (#"D", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry deduct #-> set_thm |
|
384 |
| command (#"L", [t, th]) = term t ##>> thm th #>> uncurry abs #-> set_thm |
|
81911 | 385 |
| command (#"M", [name]) = stored_thm name |
81907 | 386 |
| command (#"Q", args) = |
81910 | 387 |
split_last args |> (fn (tys, th) => thm th #-> (fn th => typs tys #-> (fn tys => |
81908 | 388 |
set_thm (inst_type (pair_list tys) th)))) |
81907 | 389 |
| command (#"S", args) = |
81910 | 390 |
split_last args |> (fn (ts, th) => thm th #-> (fn th => terms ts #-> (fn ts => |
81908 | 391 |
set_thm (inst (pair_list ts) th)))) |
81907 | 392 |
| command (#"F", [name, t]) = |
393 |
term t #-> (fn t => theory_op (def (make_name name) t) #-> set_thm) |
|
394 |
| command (#"F", [name]) = theory #-> (fn thy => set_thm (mdef thy name)) |
|
395 |
| command (#"Y", [name, abs, rep, t1, t2, th]) = |
|
396 |
thm th #-> (fn th => term t1 #-> (fn t1 => term t2 #-> (fn t2 => |
|
81926 | 397 |
theory_op (tydef (make_name name) abs rep t1 t2 th) #-> set_thm))) |
81907 | 398 |
| command (#"Y", [name, _, _]) = theory #-> (fn thy => set_thm (mtydef thy name)) |
81913 | 399 |
| command (#"t", [a]) = theory #-> (fn thy => set_typ (make_tfree thy a)) |
81908 | 400 |
| command (#"a", c :: tys) = theory #-> (fn thy => typs tys #>> make_type thy c #-> set_typ) |
401 |
| command (#"v", [x, ty]) = typ ty #>> make_free x #-> set_term |
|
402 |
| command (#"c", [c, ty]) = theory #-> (fn thy => typ ty #>> make_const thy c #-> set_term) |
|
403 |
| command (#"f", [t, u]) = term t #-> (fn t => term u #-> (fn u => set_term (Thm.apply t u))) |
|
81932 | 404 |
| command (#"l", [x, t]) = |
405 |
term x #-> (fn x => term t #-> (fn t => |
|
406 |
set_term (Thm.lambda_name (make_bound (#1 (dest_Free (Thm.term_of x))), x) t))) |
|
81926 | 407 |
| command (#"+", [name]) = store_thm (make_name name) |
81907 | 408 |
| command (c, _) = raise Fail ("process: unknown command: " ^ String.str c) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
409 |
|
81909 | 410 |
in |
411 |
||
81847 | 412 |
fun import_file path0 thy = |
81846
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
413 |
let |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
414 |
val path = File.absolute_path (Resources.master_directory thy + path0) |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
415 |
val lines = |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
416 |
if Path.is_zst path then Bytes.read path |> Zstd.uncompress |> Bytes.trim_split_lines |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
417 |
else File.read_lines path |
81908 | 418 |
in init_state thy |> fold (parse_line #> command) lines |> get_theory end |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
419 |
|
81847 | 420 |
val _ = |
421 |
Outer_Syntax.command \<^command_keyword>\<open>import_file\<close> "import recorded proofs from HOL Light" |
|
422 |
(Parse.path >> (fn name => Toplevel.theory (fn thy => import_file (Path.explode name) thy))) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
423 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
424 |
end |
81909 | 425 |
|
426 |
end |