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