author | wenzelm |
Fri, 17 Jan 2025 13:44:45 +0100 | |
changeset 81853 | f06281e21df9 |
parent 81852 | c693485575a9 |
child 81854 | 2a5cbd329241 |
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 |
81835 | 26 |
val inst_type : theory -> (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 |
|
81848 | 34 |
type state = (ctyp Inttab.table * int) * (cterm Inttab.table * int) * (thm Inttab.table * int) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
35 |
|
81848 | 36 |
val init_state: state = ((Inttab.empty, 0), (Inttab.empty, 0), (Inttab.empty, 0)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
37 |
|
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 |
59582 | 43 |
val th1b = Thm.implies_intr (strip_imp_concl (Thm.cprop_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 |
59582 | 52 |
val (tml, tmr) = Thm.dest_binop (strip_imp_concl (Thm.cprop_of th)) |
59586 | 53 |
val cty = Thm.ctyp_of_cterm tml |
60801 | 54 |
val i = Thm.instantiate' [SOME cty] [SOME tml, SOME tmr] |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
55 |
@{thm meta_eq_to_obj_eq} |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
56 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
57 |
Thm.implies_elim i th |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
58 |
end |
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 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
|
61 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
62 |
fun eq_mp th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
63 |
let |
59582 | 64 |
val (tm1l, tm1r) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1))) |
60801 | 65 |
val i1 = Thm.instantiate' [] [SOME tm1l, SOME tm1r] @{thm iffD1} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
66 |
val i2 = meta_mp i1 th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
67 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
68 |
meta_mp i2 th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
69 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
70 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
71 |
fun comb th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
72 |
let |
59582 | 73 |
val t1c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1)) |
74 |
val t2c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th2)) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
75 |
val (cf, cg) = Thm.dest_binop t1c |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
76 |
val (cx, cy) = Thm.dest_binop t2c |
59586 | 77 |
val [fd, fr] = Thm.dest_ctyp (Thm.ctyp_of_cterm cf) |
60801 | 78 |
val i1 = Thm.instantiate' [SOME fd, SOME fr] |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
79 |
[SOME cf, SOME cg, SOME cx, SOME cy] @{thm cong} |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
80 |
val i2 = meta_mp i1 th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
81 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
82 |
meta_mp i2 th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
83 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
84 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
85 |
fun trans th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
86 |
let |
59582 | 87 |
val t1c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1)) |
88 |
val t2c = Thm.dest_arg (strip_imp_concl (Thm.cprop_of th2)) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
89 |
val (r, s) = Thm.dest_binop t1c |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
90 |
val (_, t) = Thm.dest_binop t2c |
59586 | 91 |
val ty = Thm.ctyp_of_cterm r |
60801 | 92 |
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
|
93 |
val i2 = meta_mp i1 th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
94 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
95 |
meta_mp i2 th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
96 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
97 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
98 |
fun deduct th1 th2 = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
99 |
let |
59582 | 100 |
val th1c = strip_imp_concl (Thm.cprop_of th1) |
101 |
val th2c = strip_imp_concl (Thm.cprop_of th2) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
102 |
val th1a = implies_elim_all th1 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
103 |
val th2a = implies_elim_all th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
104 |
val th1b = Thm.implies_intr th2c th1a |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
105 |
val th2b = Thm.implies_intr th1c th2a |
60801 | 106 |
val i = Thm.instantiate' [] |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
107 |
[SOME (Thm.dest_arg th1c), SOME (Thm.dest_arg th2c)] @{thm iffI} |
59582 | 108 |
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
|
109 |
val i2 = Thm.implies_elim i1 th1b |
59582 | 110 |
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
|
111 |
val i4 = Thm.implies_elim i3 th2b |
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 |
implies_intr_hyps i4 |
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 conj1 th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
117 |
let |
59582 | 118 |
val (tml, tmr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th))) |
60801 | 119 |
val i = Thm.instantiate' [] [SOME tml, SOME tmr] @{thm conjunct1} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
120 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
121 |
meta_mp i th |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
122 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
123 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
124 |
fun conj2 th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
125 |
let |
59582 | 126 |
val (tml, tmr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th))) |
60801 | 127 |
val i = Thm.instantiate' [] [SOME tml, SOME tmr] @{thm conjunct2} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
128 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
129 |
meta_mp i th |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
130 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
131 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
132 |
fun refl ctm = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
133 |
let |
59586 | 134 |
val cty = Thm.ctyp_of_cterm ctm |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
135 |
in |
60801 | 136 |
Thm.instantiate' [SOME cty] [SOME ctm] @{thm refl} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
137 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
138 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
139 |
fun abs cv th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
140 |
let |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
141 |
val th1 = implies_elim_all th |
59582 | 142 |
val (tl, tr) = Thm.dest_binop (Thm.dest_arg (strip_imp_concl (Thm.cprop_of th1))) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
143 |
val (ll, lr) = (Thm.lambda cv tl, Thm.lambda cv tr) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
144 |
val (al, ar) = (Thm.apply ll cv, Thm.apply lr cv) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
145 |
val bl = beta al |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
146 |
val br = meta_eq_to_obj_eq (Thm.symmetric (Thm.beta_conversion false ar)) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
147 |
val th2 = trans (trans bl th1) br |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
148 |
val th3 = implies_elim_all th2 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
149 |
val th4 = Thm.forall_intr cv th3 |
60801 | 150 |
val i = Thm.instantiate' [SOME (Thm.ctyp_of_cterm cv), SOME (Thm.ctyp_of_cterm tl)] |
81829 | 151 |
[SOME ll, SOME lr] @{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
|
152 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
153 |
meta_mp i th4 |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
154 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
155 |
|
81852 | 156 |
fun freezeT thy th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
157 |
let |
81852 | 158 |
val tvars = Term.add_tvars (Thm.prop_of th) [] |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
159 |
val tfrees = map (fn ((t, _), s) => TFree (t, s)) tvars |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
160 |
in |
81852 | 161 |
Thm.instantiate (TVars.make (tvars ~~ map (Thm.global_ctyp_of thy) tfrees), Vars.empty) th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
162 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
163 |
|
81840 | 164 |
fun def' c rhs thy = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
165 |
let |
81840 | 166 |
val b = Binding.name c |
81852 | 167 |
val ty = type_of rhs |
168 |
val thy1 = Sign.add_consts [(b, ty, NoSyn)] thy |
|
169 |
val eq = Logic.mk_equals (Const (Sign.full_name thy1 b, ty), rhs) |
|
170 |
val (th, thy2) = Global_Theory.add_def (Binding.suffix_name "_hldef" b, eq) thy1 |
|
171 |
val def_thm = freezeT thy1 th |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
172 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
173 |
(meta_eq_to_obj_eq def_thm, thy2) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
174 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
175 |
|
81835 | 176 |
fun mdef thy name = |
177 |
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
|
178 |
SOME th => th |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
179 |
| NONE => error ("constant mapped but no definition: " ^ name) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
180 |
|
81840 | 181 |
fun def c rhs thy = |
182 |
case Import_Data.get_const_def thy c of |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
183 |
SOME _ => |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
184 |
let |
81840 | 185 |
val () = warning ("Const mapped but def provided: " ^ c) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
186 |
in |
81840 | 187 |
(mdef thy c, thy) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
188 |
end |
81840 | 189 |
| NONE => def' c (Thm.term_of rhs) thy |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
190 |
|
81829 | 191 |
fun typedef_hol2hollight nty oty rep abs pred a r = |
192 |
Thm.instantiate' [SOME nty, SOME oty] [SOME rep, SOME abs, SOME pred, SOME a, SOME r] |
|
193 |
@{lemma "type_definition Rep Abs (Collect P) \<Longrightarrow> Abs (Rep a) = a \<and> P r = (Rep (Abs r) = r)" |
|
194 |
by (metis type_definition.Rep_inverse type_definition.Abs_inverse |
|
195 |
type_definition.Rep mem_Collect_eq)} |
|
196 |
||
81835 | 197 |
fun typedef_hollight thy th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
198 |
let |
59582 | 199 |
val (th_s, cn) = Thm.dest_comb (Thm.dest_arg (Thm.cprop_of th)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
200 |
val (th_s, abst) = Thm.dest_comb th_s |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
201 |
val rept = Thm.dest_arg th_s |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
202 |
val P = Thm.dest_arg cn |
59586 | 203 |
val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
204 |
in |
81829 | 205 |
typedef_hol2hollight nty oty rept abst P |
206 |
(Thm.global_cterm_of thy (Free ("a", Thm.typ_of nty))) |
|
207 |
(Thm.global_cterm_of thy (Free ("r", Thm.typ_of oty))) |
|
47258
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 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
210 |
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
|
211 |
let |
59586 | 212 |
val ctT = Thm.ctyp_of_cterm ct |
81829 | 213 |
val nonempty = Thm.instantiate' [SOME ctT] [SOME cP, SOME ct] |
214 |
@{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
|
215 |
val th2 = meta_mp nonempty td_th |
59582 | 216 |
val c = |
217 |
case Thm.concl_of th2 of |
|
81841 | 218 |
\<^Const_>\<open>Trueprop for \<^Const_>\<open>Ex _ for \<open>Abs (_, _, \<^Const_>\<open>Set.member _ for _ c\<close>)\<close>\<close>\<close> => c |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
219 |
| _ => error "type_introduction: bad type definition theorem" |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
220 |
val tfrees = Term.add_tfrees c [] |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
221 |
val tnames = sort_strings (map fst tfrees) |
61110 | 222 |
val typedef_bindings = |
62513
702085ca8564
take qualification of type name more seriously: derived consts and facts are qualified uniformly;
wenzelm
parents:
62436
diff
changeset
|
223 |
{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
|
224 |
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
|
225 |
type_definition_name = Binding.name ("type_definition_" ^ tycname)} |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
226 |
val ((_, typedef_info), thy') = |
69829 | 227 |
Named_Target.theory_map_result (apsnd o Typedef.transform_info) |
228 |
(Typedef.add_typedef {overloaded = false} |
|
61260 | 229 |
(Binding.name tycname, map (rpair dummyS) tnames, NoSyn) c |
69829 | 230 |
(SOME typedef_bindings) (fn ctxt => resolve_tac ctxt [th2] 1)) thy |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
231 |
val aty = #abs_type (#1 typedef_info) |
60648 | 232 |
val th = freezeT thy' (#type_definition (#2 typedef_info)) |
59582 | 233 |
val (th_s, _) = Thm.dest_comb (Thm.dest_arg (Thm.cprop_of th)) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
234 |
val (th_s, abst) = Thm.dest_comb th_s |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
235 |
val rept = Thm.dest_arg th_s |
59586 | 236 |
val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
237 |
val typedef_th = |
81829 | 238 |
typedef_hol2hollight nty oty rept abst cP |
239 |
(Thm.global_cterm_of thy' (Free ("a", aty))) |
|
240 |
(Thm.global_cterm_of thy' (Free ("r", Thm.typ_of ctT))) |
|
47363
c7fc95e722ff
HOL/Import typed matches against Isabelle typedef result
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
47258
diff
changeset
|
241 |
val th4 = typedef_th OF [#type_definition (#2 typedef_info)] |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
242 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
243 |
(th4, thy') |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
244 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
245 |
|
81835 | 246 |
fun mtydef thy name = |
247 |
case Import_Data.get_typ_def thy name of |
|
248 |
SOME thn => meta_mp (typedef_hollight thy thn) thn |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
249 |
| NONE => error ("type mapped but no tydef thm registered: " ^ name) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
250 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
251 |
fun tydef tycname abs_name rep_name P t td_th thy = |
81835 | 252 |
case Import_Data.get_typ_def thy tycname of |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
253 |
SOME _ => |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
254 |
let |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
255 |
val () = warning ("Type mapped but proofs provided: " ^ tycname) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
256 |
in |
81835 | 257 |
(mtydef thy tycname, thy) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
258 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
259 |
| NONE => tydef' tycname abs_name rep_name P t td_th thy |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
260 |
|
81835 | 261 |
fun inst_type thy lambda th = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
262 |
let |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
263 |
fun assoc _ [] = error "assoc" |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
264 |
| assoc x ((x',y)::rest) = if x = x' then y else assoc x rest |
59582 | 265 |
val lambda = map (fn (a, b) => (Thm.typ_of a, b)) lambda |
266 |
val tys_before = Term.add_tfrees (Thm.prop_of th) [] |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
267 |
val th1 = Thm.varifyT_global th |
59582 | 268 |
val tys_after = Term.add_tvars (Thm.prop_of th1) [] |
60642
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
269 |
val tyinst = |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
270 |
map2 (fn bef => fn iS => |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
271 |
(case try (assoc (TFree bef)) lambda of |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
272 |
SOME cty => (iS, cty) |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
273 |
| NONE => (iS, Thm.global_ctyp_of thy (TFree bef)))) |
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60367
diff
changeset
|
274 |
tys_before tys_after |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
275 |
in |
74282 | 276 |
Thm.instantiate (TVars.make tyinst, Vars.empty) th1 |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
277 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
278 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
279 |
fun inst sigma th = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
280 |
let |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
281 |
val (dom, rng) = ListPair.unzip (rev sigma) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
282 |
in |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
283 |
th |> forall_intr_list dom |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
284 |
|> forall_elim_list rng |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
285 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
286 |
|
81831 | 287 |
val make_name = String.translate (fn #"." => "dot" | c => Char.toString c) |
288 |
||
289 |
fun make_free (x, ty) = Free (make_name x, ty) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
290 |
|
81831 | 291 |
fun make_tfree a = |
292 |
let val b = "'" ^ String.translate (fn #"?" => "t" | c => Char.toString c) a |
|
293 |
in TFree (b, \<^sort>\<open>type\<close>) end |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
294 |
|
81837 | 295 |
fun make_type thy (c, args) = |
296 |
let |
|
297 |
val d = |
|
298 |
(case Import_Data.get_typ_map thy c of |
|
299 |
SOME d => d |
|
81839 | 300 |
| NONE => Sign.full_bname thy (make_name c)) |
81837 | 301 |
in Type (d, args) end |
302 |
||
81831 | 303 |
fun make_const thy (c, ty) = |
304 |
let |
|
305 |
val d = |
|
81835 | 306 |
(case Import_Data.get_const_map thy c of |
81831 | 307 |
SOME d => d |
81839 | 308 |
| NONE => Sign.full_bname thy (make_name c)) |
81831 | 309 |
in Const (d, ty) end |
310 |
||
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
311 |
fun get (map, no) s = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
312 |
case Int.fromString s of |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
313 |
NONE => error "Import_Rule.get: not a number" |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
314 |
| SOME i => (case Inttab.lookup map (Int.abs i) of |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
315 |
NONE => error "Import_Rule.get: lookup failed" |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
316 |
| SOME res => (res, (if i < 0 then Inttab.delete (Int.abs i) map else map, no))) |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
317 |
|
81853 | 318 |
fun typ i (thy, (tyi, tmi, thi)) = let val (i, tyi) = (get tyi i) in (i, (thy, (tyi, tmi, thi))) end |
319 |
fun term i (thy, (tyi, tmi, thi)) = let val (i, tmi) = (get tmi i) in (i, (thy, (tyi, tmi, thi))) end |
|
320 |
fun thm i (thy, (tyi, tmi, thi)) = let val (i, thi) = (get thi i) in (i, (thy, (tyi, tmi, thi))) end |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
321 |
fun set (map, no) v = (Inttab.update_new (no + 1, v) map, no + 1) |
81853 | 322 |
fun set_typ v (thy, (tyi, tmi, thi)) = (thy, (set tyi v, tmi, thi)) |
323 |
fun set_term v (thy, (tyi, tmi, thi)) = (thy, (tyi, set tmi v, thi)) |
|
324 |
fun set_thm v (thy, (tyi, tmi, thi)) = (thy, (tyi, tmi, set thi v)) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
325 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
326 |
fun last_thm (_, _, (map, no)) = |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
327 |
case Inttab.lookup map no of |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
328 |
NONE => error "Import_Rule.last_thm: lookup failed" |
81852 | 329 |
| SOME th => th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
330 |
|
81849 | 331 |
fun list_last (x :: y :: zs) = apfst (fn t => x :: y :: t) (list_last zs) |
332 |
| list_last [x] = ([], x) |
|
333 |
| list_last [] = error "list_last: empty" |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
334 |
|
81849 | 335 |
fun pair_list (x :: y :: zs) = ((x, y) :: pair_list zs) |
336 |
| pair_list [] = [] |
|
337 |
| pair_list _ = error "pair_list: odd list length" |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
338 |
|
81852 | 339 |
fun store_thm binding th0 thy = |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
340 |
let |
60367 | 341 |
val ctxt = Proof_Context.init_global thy |
81852 | 342 |
val th = Drule.export_without_context_open th0 |
343 |
val tvs = Term.add_tvars (Thm.prop_of th) [] |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
344 |
val tns = map (fn (_, _) => "'") tvs |
81521 | 345 |
val nms = Name.variants (Variable.names_of ctxt) tns |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
346 |
val vs = map TVar ((nms ~~ (map (snd o fst) tvs)) ~~ (map snd tvs)) |
81852 | 347 |
val th' = Thm.instantiate (TVars.make (tvs ~~ map (Thm.ctyp_of ctxt) vs), Vars.empty) th |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
348 |
in |
81852 | 349 |
snd (Global_Theory.add_thm ((binding, th'), []) thy) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
350 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
351 |
|
81847 | 352 |
fun parse_line s = |
353 |
(case String.tokens (fn x => x = #"\n" orelse x = #" ") s of |
|
354 |
[] => error "parse_line: empty" |
|
355 |
| cmd :: args => |
|
356 |
(case String.explode cmd of |
|
357 |
[] => error "parse_line: empty command" |
|
358 |
| c :: cs => (c, String.implode cs :: args))) |
|
359 |
||
360 |
fun process_line str = |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
361 |
let |
81853 | 362 |
fun process (#"R", [t]) = term t #>> refl #-> set_thm |
363 |
| process (#"B", [t]) = term t #>> beta #-> set_thm |
|
364 |
| process (#"1", [th]) = thm th #>> conj1 #-> set_thm |
|
365 |
| process (#"2", [th]) = thm th #>> conj2 #-> set_thm |
|
366 |
| process (#"H", [t]) = term t #>> Thm.apply \<^cterm>\<open>Trueprop\<close> #>> Thm.trivial #-> set_thm |
|
81851 | 367 |
| process (#"A", [_, t]) = |
81853 | 368 |
term t #>> Thm.apply \<^cterm>\<open>Trueprop\<close> #>> Skip_Proof.make_thm_cterm #-> set_thm |
369 |
| process (#"C", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry comb #-> set_thm |
|
370 |
| process (#"T", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry trans #-> set_thm |
|
371 |
| process (#"E", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry eq_mp #-> set_thm |
|
372 |
| process (#"D", [th1, th2]) = thm th1 ##>> thm th2 #>> uncurry deduct #-> set_thm |
|
373 |
| process (#"L", [t, th]) = term t ##>> (fn ti => thm th ti) #>> uncurry abs #-> set_thm |
|
81851 | 374 |
| process (#"M", [s]) = (fn (thy, state) => |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
375 |
let |
70303 | 376 |
val ctxt = Proof_Context.init_global thy |
81852 | 377 |
val th = freezeT thy (Global_Theory.get_thm thy s) |
378 |
val ((_, [th']), _) = Variable.import true [th] ctxt |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
379 |
in |
81853 | 380 |
set_thm th' (thy, state) |
81851 | 381 |
end) |
382 |
| process (#"Q", l) = (fn (thy, state) => |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
383 |
let |
81849 | 384 |
val (tys, th) = list_last l |
81853 | 385 |
val (th, tstate) = thm th (thy, state) |
386 |
val (tys, tstate) = fold_map typ tys tstate |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
387 |
in |
81853 | 388 |
set_thm (inst_type thy (pair_list tys) th) tstate |
81851 | 389 |
end) |
390 |
| process (#"S", l) = (fn tstate => |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
391 |
let |
81849 | 392 |
val (tms, th) = list_last l |
81853 | 393 |
val (th, tstate) = thm th tstate |
394 |
val (tms, tstate) = fold_map term tms tstate |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
395 |
in |
81853 | 396 |
set_thm (inst (pair_list tms) th) tstate |
81851 | 397 |
end) |
398 |
| process (#"F", [name, t]) = (fn tstate => |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
399 |
let |
81853 | 400 |
val (tm, (thy, state)) = term t tstate |
81831 | 401 |
val (th, thy) = def (make_name name) tm thy |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
402 |
in |
81853 | 403 |
set_thm th (thy, state) |
81851 | 404 |
end) |
81853 | 405 |
| process (#"F", [name]) = (fn (thy, state) => set_thm (mdef thy name) (thy, state)) |
81851 | 406 |
| process (#"Y", [name, absname, repname, t1, t2, th]) = (fn tstate => |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
407 |
let |
81853 | 408 |
val (th, tstate) = thm th tstate |
409 |
val (t1, tstate) = term t1 tstate |
|
410 |
val (t2, (thy, state)) = term t2 tstate |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
411 |
val (th, thy) = tydef name absname repname t1 t2 th thy |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
412 |
in |
81853 | 413 |
set_thm th (thy, state) |
81851 | 414 |
end) |
81853 | 415 |
| process (#"Y", [name, _, _]) = (fn (thy, state) => set_thm (mtydef thy name) (thy, state)) |
81851 | 416 |
| process (#"t", [n]) = (fn (thy, state) => |
81853 | 417 |
set_typ (Thm.global_ctyp_of thy (make_tfree n)) (thy, state)) |
81851 | 418 |
| process (#"a", n :: l) = (fn (thy, state) => |
81853 | 419 |
fold_map typ l (thy, state) |>> |
420 |
(fn tys => Thm.global_ctyp_of thy (make_type thy (n, map Thm.typ_of tys))) |-> set_typ) |
|
81851 | 421 |
| process (#"v", [n, ty]) = (fn (thy, state) => |
81853 | 422 |
typ ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (make_free (n, Thm.typ_of ty))) |-> set_term) |
81851 | 423 |
| process (#"c", [n, ty]) = (fn (thy, state) => |
81853 | 424 |
typ ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (make_const thy (n, Thm.typ_of ty))) |-> set_term) |
425 |
| process (#"f", [t1, t2]) = term t1 ##>> term t2 #>> uncurry Thm.apply #-> set_term |
|
426 |
| process (#"l", [t1, t2]) = term t1 ##>> term t2 #>> uncurry Thm.lambda #-> set_term |
|
81851 | 427 |
| process (#"+", [s]) = (fn (thy, state) => |
428 |
(store_thm (Binding.name (make_name s)) (last_thm state) thy, state)) |
|
429 |
| process (c, _) = error ("process: unknown command: " ^ String.implode [c]) |
|
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
430 |
in |
81848 | 431 |
process (parse_line str) |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
432 |
end |
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
433 |
|
81847 | 434 |
fun import_file path0 thy = |
81846
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
435 |
let |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
436 |
val path = File.absolute_path (Resources.master_directory thy + path0) |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
437 |
val lines = |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
438 |
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
|
439 |
else File.read_lines path |
5a7bf0f038e2
more robust import_file path: proper master_directory;
wenzelm
parents:
81844
diff
changeset
|
440 |
in #1 (fold process_line lines (thy, init_state)) end |
47258
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
441 |
|
81847 | 442 |
val _ = |
443 |
Outer_Syntax.command \<^command_keyword>\<open>import_file\<close> "import recorded proofs from HOL Light" |
|
444 |
(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
|
445 |
|
880e587eee9f
Modernized HOL-Import for HOL Light
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff
changeset
|
446 |
end |