author | wenzelm |
Mon, 20 Jan 2025 23:00:17 +0100 | |
changeset 81933 | cb05f8d3fd05 |
parent 81932 | 0a1ed07a458a |
child 81937 | 372ff330a9d9 |
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 |
||
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
58 |
fun implies_elim_all th = implies_elim_list th (map Thm.assume (cprems_of th)) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
59 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
60 |
fun meta_mp th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
61 |
let |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
62 |
val th1a = implies_elim_all th1 |
81865 | 63 |
val th1b = Thm.implies_intr (Thm.cconcl_of th2) th1a |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
64 |
val th2a = implies_elim_all th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
65 |
val th3 = Thm.implies_elim th1b th2a |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
66 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
67 |
implies_intr_hyps th3 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
68 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
69 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
70 |
fun meta_eq_to_obj_eq th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
71 |
let |
81866 | 72 |
val (t, u) = Thm.dest_equals (Thm.cconcl_of th) |
73 |
val A = Thm.ctyp_of_cterm t |
|
74 |
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
|
75 |
in |
81866 | 76 |
Thm.implies_elim rl th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
77 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
78 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
79 |
fun beta ct = meta_eq_to_obj_eq (Thm.beta_conversion false ct) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
80 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
81 |
fun eq_mp th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
82 |
let |
81866 | 83 |
val (Q, P) = Thm.dest_binop (Thm.dest_arg (Thm.cconcl_of th1)) |
84 |
val i1 = Thm.instantiate' [] [SOME Q, SOME P] @{thm iffD1} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
85 |
val i2 = meta_mp i1 th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
86 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
87 |
meta_mp i2 th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
88 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
89 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
90 |
fun comb th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
91 |
let |
81866 | 92 |
val t1 = Thm.dest_arg (Thm.cconcl_of th1) |
93 |
val t2 = Thm.dest_arg (Thm.cconcl_of th2) |
|
94 |
val (f, g) = Thm.dest_binop t1 |
|
95 |
val (x, y) = Thm.dest_binop t2 |
|
96 |
val [A, B] = Thm.dest_ctyp (Thm.ctyp_of_cterm f) |
|
97 |
val i1 = Thm.instantiate' [SOME A, SOME B] [SOME f, SOME g, SOME x, SOME y] @{thm cong} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
98 |
val i2 = meta_mp i1 th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
99 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
100 |
meta_mp i2 th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
101 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
102 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
103 |
fun trans th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
104 |
let |
81866 | 105 |
val t1 = Thm.dest_arg (Thm.cconcl_of th1) |
106 |
val t2 = Thm.dest_arg (Thm.cconcl_of th2) |
|
107 |
val (r, s) = Thm.dest_binop t1 |
|
108 |
val t = Thm.dest_arg t2 |
|
59586 | 109 |
val ty = Thm.ctyp_of_cterm r |
60801 | 110 |
val i1 = Thm.instantiate' [SOME ty] [SOME r, SOME s, SOME t] @{thm trans} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
111 |
val i2 = meta_mp i1 th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
112 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
113 |
meta_mp i2 th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
114 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
115 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
116 |
fun deduct th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
117 |
let |
81865 | 118 |
val th1c = Thm.cconcl_of th1 |
119 |
val th2c = Thm.cconcl_of th2 |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
120 |
val th1a = implies_elim_all th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
121 |
val th2a = implies_elim_all th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
122 |
val th1b = Thm.implies_intr th2c th1a |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
123 |
val th2b = Thm.implies_intr th1c th2a |
81866 | 124 |
val i = Thm.instantiate' [] [SOME (Thm.dest_arg th1c), SOME (Thm.dest_arg th2c)] @{thm iffI} |
59582 | 125 |
val i1 = Thm.implies_elim i (Thm.assume (Thm.cprop_of th2b)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
126 |
val i2 = Thm.implies_elim i1 th1b |
59582 | 127 |
val i3 = Thm.implies_intr (Thm.cprop_of th2b) i2 |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
128 |
val i4 = Thm.implies_elim i3 th2b |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
129 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
130 |
implies_intr_hyps i4 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
131 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
132 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
133 |
fun conj1 th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
134 |
let |
81866 | 135 |
val (P, Q) = Thm.dest_binop (Thm.dest_arg (Thm.cconcl_of th)) |
136 |
val i = Thm.instantiate' [] [SOME P, SOME Q] @{thm conjunct1} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
137 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
138 |
meta_mp i th |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
139 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
140 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
141 |
fun conj2 th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
142 |
let |
81866 | 143 |
val (P, Q) = Thm.dest_binop (Thm.dest_arg (Thm.cconcl_of th)) |
144 |
val i = Thm.instantiate' [] [SOME P, SOME Q] @{thm conjunct2} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
145 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
146 |
meta_mp i th |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
147 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
148 |
|
81866 | 149 |
fun refl t = |
150 |
let val A = Thm.ctyp_of_cterm t |
|
151 |
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
|
152 |
|
81866 | 153 |
fun abs x th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
154 |
let |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
155 |
val th1 = implies_elim_all th |
81865 | 156 |
val (tl, tr) = Thm.dest_binop (Thm.dest_arg (Thm.cconcl_of th1)) |
81866 | 157 |
val (f, g) = (Thm.lambda x tl, Thm.lambda x tr) |
158 |
val (al, ar) = (Thm.apply f x, Thm.apply g x) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
159 |
val bl = beta al |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
160 |
val br = meta_eq_to_obj_eq (Thm.symmetric (Thm.beta_conversion false ar)) |
81866 | 161 |
val th2 = |
162 |
trans (trans bl th1) br |
|
163 |
|> implies_elim_all |
|
164 |
|> Thm.forall_intr x |
|
165 |
val i = |
|
166 |
Thm.instantiate' [SOME (Thm.ctyp_of_cterm x), SOME (Thm.ctyp_of_cterm tl)] |
|
167 |
[SOME f, SOME g] @{lemma "(\<And>x. f x = g x) \<Longrightarrow> f = g" by (rule ext)} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
168 |
in |
81866 | 169 |
meta_mp i th2 |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
170 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
171 |
|
81909 | 172 |
|
173 |
(* instantiation *) |
|
174 |
||
81852 | 175 |
fun freezeT thy th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
176 |
let |
81857 | 177 |
fun add (v as ((a, _), S)) tvars = |
178 |
if TVars.defined tvars v then tvars |
|
179 |
else TVars.add (v, Thm.global_ctyp_of thy (TFree (a, S))) tvars |
|
180 |
val tyinst = |
|
181 |
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
|
182 |
in |
81857 | 183 |
Thm.instantiate (tyinst, Vars.empty) th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
184 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
185 |
|
81858
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
186 |
fun freeze thy = freezeT thy #> (fn th => |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
187 |
let |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
188 |
val vars = Vars.build (th |> Thm.add_vars) |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
189 |
val inst = vars |> Vars.map (fn _ => fn v => |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
190 |
let |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
191 |
val Var ((x, _), _) = Thm.term_of v |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
192 |
val ty = Thm.ctyp_of_cterm v |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
193 |
in Thm.free (x, ty) end) |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
194 |
in |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
195 |
Thm.instantiate (TVars.empty, inst) th |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
196 |
end) |
81f3adce1eda
minor performance tuning: more elementary operations;
wenzelm
parents:
81857
diff
changeset
|
197 |
|
81909 | 198 |
fun inst_type lambda = |
199 |
let |
|
200 |
val tyinst = |
|
201 |
TFrees.build (lambda |> fold (fn (a, b) => |
|
202 |
TFrees.add (Term.dest_TFree (Thm.typ_of a), b))) |
|
203 |
in |
|
204 |
Thm.instantiate_frees (tyinst, Frees.empty) |
|
205 |
end |
|
206 |
||
207 |
fun inst sigma th = |
|
208 |
let |
|
209 |
val (dom, rng) = ListPair.unzip (rev sigma) |
|
210 |
in |
|
211 |
th |> forall_intr_list dom |
|
212 |
|> forall_elim_list rng |
|
213 |
end |
|
214 |
||
215 |
||
216 |
(* constant definitions *) |
|
217 |
||
81926 | 218 |
fun def' (name as {isabelle = c, ...}) rhs thy = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
219 |
let |
81926 | 220 |
val _ = tracing_item thy "const" name; |
81840 | 221 |
val b = Binding.name c |
81852 | 222 |
val ty = type_of rhs |
223 |
val thy1 = Sign.add_consts [(b, ty, NoSyn)] thy |
|
224 |
val eq = Logic.mk_equals (Const (Sign.full_name thy1 b, ty), rhs) |
|
225 |
val (th, thy2) = Global_Theory.add_def (Binding.suffix_name "_hldef" b, eq) thy1 |
|
226 |
val def_thm = freezeT thy1 th |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
227 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
228 |
(meta_eq_to_obj_eq def_thm, thy2) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
229 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
230 |
|
81835 | 231 |
fun mdef thy name = |
81866 | 232 |
(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
|
233 |
SOME th => th |
81866 | 234 |
| 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
|
235 |
|
81926 | 236 |
fun def (name as {isabelle = c, ...}) rhs thy = |
81861 | 237 |
if is_some (Import_Data.get_const_def thy c) then |
238 |
(warning ("Const mapped, but def provided: " ^ quote c); (mdef thy c, thy)) |
|
81926 | 239 |
else def' name (Thm.term_of rhs) thy |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
240 |
|
81909 | 241 |
|
242 |
(* type definitions *) |
|
243 |
||
81861 | 244 |
fun typedef_hol2hollight A B rep abs pred a r = |
245 |
Thm.instantiate' [SOME A, SOME B] [SOME rep, SOME abs, SOME pred, SOME a, SOME r] |
|
81829 | 246 |
@{lemma "type_definition Rep Abs (Collect P) \<Longrightarrow> Abs (Rep a) = a \<and> P r = (Rep (Abs r) = r)" |
247 |
by (metis type_definition.Rep_inverse type_definition.Abs_inverse |
|
248 |
type_definition.Rep mem_Collect_eq)} |
|
249 |
||
81861 | 250 |
fun typedef_hollight th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
251 |
let |
81866 | 252 |
val ((rep, abs), P) = |
253 |
Thm.dest_comb (Thm.dest_arg (Thm.cprop_of th)) |
|
254 |
|>> (Thm.dest_comb #>> Thm.dest_arg) |
|
255 |
||> Thm.dest_arg |
|
256 |
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
|
257 |
in |
81866 | 258 |
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
|
259 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
260 |
|
81926 | 261 |
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
|
262 |
let |
81926 | 263 |
val _ = tracing_item thy "type" name; |
264 |
||
59586 | 265 |
val ctT = Thm.ctyp_of_cterm ct |
81905 | 266 |
val nonempty = |
267 |
Thm.instantiate' [SOME ctT] [SOME cP, SOME ct] |
|
268 |
@{lemma "P t \<Longrightarrow> \<exists>x. x \<in> Collect P" by auto} |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
269 |
val th2 = meta_mp nonempty td_th |
59582 | 270 |
val c = |
81866 | 271 |
(case Thm.concl_of th2 of |
81841 | 272 |
\<^Const_>\<open>Trueprop for \<^Const_>\<open>Ex _ for \<open>Abs (_, _, \<^Const_>\<open>Set.member _ for _ c\<close>)\<close>\<close>\<close> => c |
81866 | 273 |
| _ => 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
|
274 |
val tfrees = Term.add_tfrees c [] |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
275 |
val tnames = sort_strings (map fst tfrees) |
61110 | 276 |
val typedef_bindings = |
62513
702085ca8564
take qualification of type name more seriously: derived consts and facts are qualified uniformly;
wenzelm
parents:
62436
diff
changeset
|
277 |
{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
|
278 |
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
|
279 |
type_definition_name = Binding.name ("type_definition_" ^ tycname)} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
280 |
val ((_, typedef_info), thy') = |
69829 | 281 |
Named_Target.theory_map_result (apsnd o Typedef.transform_info) |
282 |
(Typedef.add_typedef {overloaded = false} |
|
61260 | 283 |
(Binding.name tycname, map (rpair dummyS) tnames, NoSyn) c |
69829 | 284 |
(SOME typedef_bindings) (fn ctxt => resolve_tac ctxt [th2] 1)) thy |
81855 | 285 |
val aty = Thm.global_ctyp_of thy' (#abs_type (#1 typedef_info)) |
60648 | 286 |
val th = freezeT thy' (#type_definition (#2 typedef_info)) |
81866 | 287 |
val (rep, abs) = |
288 |
Thm.dest_comb (#1 (Thm.dest_comb (Thm.dest_arg (Thm.cprop_of th)))) |>> Thm.dest_arg |
|
81861 | 289 |
val [A, B] = Thm.dest_ctyp (Thm.ctyp_of_cterm rep) |
290 |
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
|
291 |
in |
81855 | 292 |
(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
|
293 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
294 |
|
81835 | 295 |
fun mtydef thy name = |
81866 | 296 |
(case Import_Data.get_typ_def thy name of |
297 |
SOME th => meta_mp (typedef_hollight th) th |
|
298 |
| 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
|
299 |
|
81926 | 300 |
fun tydef (name as {hol = tycname, ...}) abs_name rep_name P t td_th thy = |
81866 | 301 |
if is_some (Import_Data.get_typ_def thy tycname) then |
302 |
(warning ("Type mapped but proofs provided: " ^ quote tycname); (mtydef thy tycname, thy)) |
|
81926 | 303 |
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
|
304 |
|
81909 | 305 |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
306 |
|
81909 | 307 |
(** importer **) |
308 |
||
309 |
(* basic entities *) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
310 |
|
81926 | 311 |
fun make_name hol = |
312 |
{hol = hol, isabelle = String.translate (fn #"." => "dot" | c => Char.toString c) hol} |
|
81831 | 313 |
|
81932 | 314 |
fun make_bound a = |
315 |
(case try (unprefix "_") a of |
|
316 |
SOME b => if forall_string Symbol.is_ascii_digit b then "u" else b |
|
317 |
| NONE => a); |
|
318 |
||
81926 | 319 |
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
|
320 |
|
81906
016e27e10758
misc tuning and clarification: prefer state operations, avoid redundant ctyp_of/cterm_of;
wenzelm
parents:
81905
diff
changeset
|
321 |
fun make_tfree thy a = |
81831 | 322 |
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
|
323 |
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
|
324 |
|
81908 | 325 |
fun make_type thy c args = |
81837 | 326 |
let |
327 |
val d = |
|
328 |
(case Import_Data.get_typ_map thy c of |
|
329 |
SOME d => d |
|
81926 | 330 |
| 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
|
331 |
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
|
332 |
in Thm.make_ctyp T args end |
81837 | 333 |
|
81908 | 334 |
fun make_const thy c ty = |
81831 | 335 |
let |
336 |
val d = |
|
81835 | 337 |
(case Import_Data.get_const_map thy c of |
81831 | 338 |
SOME d => d |
81926 | 339 |
| 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
|
340 |
in Thm.global_cterm_of thy (Const (d, Thm.typ_of ty)) end |
81831 | 341 |
|
81908 | 342 |
val make_thm = Skip_Proof.make_thm_cterm o Thm.apply \<^cterm>\<open>Trueprop\<close> |
343 |
val assume_thm = Thm.trivial o Thm.apply \<^cterm>\<open>Trueprop\<close> |
|
344 |
||
81854 | 345 |
|
81909 | 346 |
(* import file *) |
347 |
||
348 |
local |
|
349 |
||
81854 | 350 |
datatype state = |
351 |
State of theory * (ctyp Inttab.table * int) * (cterm Inttab.table * int) * (thm Inttab.table * int) |
|
352 |
||
353 |
fun init_state thy = State (thy, (Inttab.empty, 0), (Inttab.empty, 0), (Inttab.empty, 0)) |
|
354 |
||
81913 | 355 |
fun get (tab, reg) s = |
81854 | 356 |
(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
|
357 |
NONE => raise Fail "get: not a number" |
81854 | 358 |
| SOME i => |
359 |
(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
|
360 |
NONE => raise Fail "get: lookup failed" |
81913 | 361 |
| 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
|
362 |
|
81854 | 363 |
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
|
364 |
val theory = `get_theory; |
81913 | 365 |
fun theory_op f (State (thy, a, b, c)) = let val (y, thy') = f thy in (y, State (thy', a, b, c)) end; |
81854 | 366 |
|
367 |
fun typ i (State (thy, a, b, c)) = let val (i, a') = get a i in (i, State (thy, a', b, c)) end |
|
368 |
fun term i (State (thy, a, b, c)) = let val (i, b') = get b i in (i, State (thy, a, b', c)) end |
|
369 |
fun thm i (State (thy, a, b, c)) = let val (i, c') = get c i in (i, State (thy, a, b, c')) end |
|
370 |
||
81908 | 371 |
val typs = fold_map typ |
372 |
val terms = fold_map term |
|
373 |
||
81913 | 374 |
fun set (tab, reg) res = (Inttab.update_new (reg + 1, res) tab, reg + 1) |
81854 | 375 |
fun set_typ ty (State (thy, a, b, c)) = State (thy, set a ty, b, c) |
376 |
fun set_term tm (State (thy, a, b, c)) = State (thy, a, set b tm, c) |
|
377 |
fun set_thm th (State (thy, a, b, c)) = State (thy, a, b, set c th) |
|
378 |
||
81911 | 379 |
fun stored_thm name (State (thy, a, b, c)) = |
380 |
let val th = freeze thy (Global_Theory.get_thm thy name) |
|
381 |
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
|
382 |
|
81913 | 383 |
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
|
384 |
let |
81926 | 385 |
val _ = tracing_item thy "thm" name; |
386 |
||
81912 | 387 |
val th = |
81913 | 388 |
(case Inttab.lookup tab reg of |
389 |
NONE => raise Fail "store_thm: lookup failed" |
|
81912 | 390 |
| SOME th0 => Drule.export_without_context_open th0) |
391 |
||
392 |
val tvars = TVars.build (Thm.fold_terms {hyps = false} TVars.add_tvars th); |
|
393 |
val names = Name.invent_global_types (TVars.size tvars) |
|
394 |
val tyinst = |
|
395 |
TVars.build (fold2 |
|
396 |
(fn v as ((_, i), S) => fn b => TVars.add (v, Thm.global_ctyp_of thy (TVar ((b, i), S)))) |
|
397 |
(TVars.list_set tvars) names) |
|
398 |
||
399 |
val th' = Thm.instantiate (tyinst, Vars.empty) th |
|
81926 | 400 |
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
|
401 |
in State (thy', a, b, c) end |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
402 |
|
81849 | 403 |
fun pair_list (x :: y :: zs) = ((x, y) :: pair_list zs) |
404 |
| pair_list [] = [] |
|
81859
6cc57bd46179
clarified exceptions and messages: use "error" only for user-errors, not system failures;
wenzelm
parents:
81858
diff
changeset
|
405 |
| 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
|
406 |
|
81847 | 407 |
fun parse_line s = |
408 |
(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
|
409 |
[] => raise Fail "parse_line: empty" |
81847 | 410 |
| cmd :: args => |
411 |
(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
|
412 |
[] => raise Fail "parse_line: empty command" |
81847 | 413 |
| c :: cs => (c, String.implode cs :: args))) |
414 |
||
81907 | 415 |
fun command (#"R", [t]) = term t #>> refl #-> set_thm |
416 |
| command (#"B", [t]) = term t #>> beta #-> set_thm |
|
417 |
| command (#"1", [th]) = thm th #>> conj1 #-> set_thm |
|
418 |
| command (#"2", [th]) = thm th #>> conj2 #-> set_thm |
|
81908 | 419 |
| command (#"H", [t]) = term t #>> assume_thm #-> set_thm |
420 |
| command (#"A", [_, t]) = term t #>> make_thm #-> set_thm |
|
81907 | 421 |
| command (#"C", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry comb #-> set_thm |
422 |
| command (#"T", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry trans #-> set_thm |
|
423 |
| command (#"E", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry eq_mp #-> set_thm |
|
424 |
| command (#"D", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry deduct #-> set_thm |
|
425 |
| command (#"L", [t, th]) = term t ##>> thm th #>> uncurry abs #-> set_thm |
|
81911 | 426 |
| command (#"M", [name]) = stored_thm name |
81907 | 427 |
| command (#"Q", args) = |
81910 | 428 |
split_last args |> (fn (tys, th) => thm th #-> (fn th => typs tys #-> (fn tys => |
81908 | 429 |
set_thm (inst_type (pair_list tys) th)))) |
81907 | 430 |
| command (#"S", args) = |
81910 | 431 |
split_last args |> (fn (ts, th) => thm th #-> (fn th => terms ts #-> (fn ts => |
81908 | 432 |
set_thm (inst (pair_list ts) th)))) |
81907 | 433 |
| command (#"F", [name, t]) = |
434 |
term t #-> (fn t => theory_op (def (make_name name) t) #-> set_thm) |
|
435 |
| command (#"F", [name]) = theory #-> (fn thy => set_thm (mdef thy name)) |
|
436 |
| command (#"Y", [name, abs, rep, t1, t2, th]) = |
|
437 |
thm th #-> (fn th => term t1 #-> (fn t1 => term t2 #-> (fn t2 => |
|
81926 | 438 |
theory_op (tydef (make_name name) abs rep t1 t2 th) #-> set_thm))) |
81907 | 439 |
| command (#"Y", [name, _, _]) = theory #-> (fn thy => set_thm (mtydef thy name)) |
81913 | 440 |
| command (#"t", [a]) = theory #-> (fn thy => set_typ (make_tfree thy a)) |
81908 | 441 |
| command (#"a", c :: tys) = theory #-> (fn thy => typs tys #>> make_type thy c #-> set_typ) |
442 |
| command (#"v", [x, ty]) = typ ty #>> make_free x #-> set_term |
|
443 |
| command (#"c", [c, ty]) = theory #-> (fn thy => typ ty #>> make_const thy c #-> set_term) |
|
444 |
| command (#"f", [t, u]) = term t #-> (fn t => term u #-> (fn u => set_term (Thm.apply t u))) |
|
81932 | 445 |
| command (#"l", [x, t]) = |
446 |
term x #-> (fn x => term t #-> (fn t => |
|
447 |
set_term (Thm.lambda_name (make_bound (#1 (dest_Free (Thm.term_of x))), x) t))) |
|
81926 | 448 |
| command (#"+", [name]) = store_thm (make_name name) |
81907 | 449 |
| 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
|
450 |
|
81909 | 451 |
in |
452 |
||
81847 | 453 |
fun import_file path0 thy = |
81846
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
454 |
let |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
455 |
val path = File.absolute_path (Resources.master_directory thy + path0) |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
456 |
val lines = |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
457 |
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
|
458 |
else File.read_lines path |
81908 | 459 |
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
|
460 |
|
81847 | 461 |
val _ = |
462 |
Outer_Syntax.command \<^command_keyword>\<open>import_file\<close> "import recorded proofs from HOL Light" |
|
463 |
(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
|
464 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
465 |
end |
81909 | 466 |
|
467 |
end |