author | wenzelm |
Tue, 21 Apr 2020 22:19:59 +0200 | |
changeset 71777 | 3875815f5967 |
parent 71087 | 77580c977e0c |
child 71843 | 07c85c68ff03 |
permissions | -rw-r--r-- |
11522 | 1 |
(* Title: Pure/Proof/proof_rewrite_rules.ML |
11539 | 2 |
Author: Stefan Berghofer, TU Muenchen |
11522 | 3 |
|
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
4 |
Simplification functions for proof terms involving meta level rules. |
11522 | 5 |
*) |
6 |
||
7 |
signature PROOF_REWRITE_RULES = |
|
8 |
sig |
|
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
9 |
val rew : bool -> typ list -> term option list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option |
33722
e588744f14da
generalized procs for rewrite_proof: allow skeleton;
wenzelm
parents:
29271
diff
changeset
|
10 |
val rprocs : bool -> |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
11 |
(typ list -> term option list -> Proofterm.proof -> (Proofterm.proof * Proofterm.proof) option) list |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
12 |
val rewrite_terms : (term -> term) -> Proofterm.proof -> Proofterm.proof |
70449 | 13 |
val elim_defs : theory -> bool -> thm list -> Proofterm.proof -> Proofterm.proof |
13608 | 14 |
val elim_vars : (typ -> term) -> Proofterm.proof -> Proofterm.proof |
22280 | 15 |
val hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof |
16 |
val un_hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof |
|
70836 | 17 |
val expand_of_sort_proof : theory -> term option list -> typ * sort -> Proofterm.proof list |
70837 | 18 |
val expand_of_class_proof : theory -> term option list -> typ * class -> proof |
70449 | 19 |
val expand_of_class : theory -> typ list -> term option list -> Proofterm.proof -> |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
20 |
(Proofterm.proof * Proofterm.proof) option |
70879 | 21 |
val standard_preproc: (proof * proof) list -> theory -> proof -> proof |
11522 | 22 |
end; |
23 |
||
70840 | 24 |
structure Proof_Rewrite_Rules : PROOF_REWRITE_RULES = |
11522 | 25 |
struct |
26 |
||
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
27 |
fun rew b _ _ = |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
28 |
let |
17137 | 29 |
fun ?? x = if b then SOME x else NONE; |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
30 |
fun ax (prf as PAxm (s, prop, _)) Ts = |
15531 | 31 |
if b then PAxm (s, prop, SOME Ts) else prf; |
71087 | 32 |
fun ty T = |
33 |
if b then |
|
34 |
(case T of |
|
35 |
Type (_, [Type (_, [U, _]), _]) => SOME U |
|
36 |
| _ => NONE) |
|
15531 | 37 |
else NONE; |
37310 | 38 |
val equal_intr_axm = ax Proofterm.equal_intr_axm []; |
39 |
val equal_elim_axm = ax Proofterm.equal_elim_axm []; |
|
40 |
val symmetric_axm = ax Proofterm.symmetric_axm [propT]; |
|
11522 | 41 |
|
70493 | 42 |
fun rew' (PThm ({name = "Pure.protectD", ...}, _) % _ %% |
43 |
(PThm ({name = "Pure.protectI", ...}, _) % _ %% prf)) = SOME prf |
|
44 |
| rew' (PThm ({name = "Pure.conjunctionD1", ...}, _) % _ % _ %% |
|
45 |
(PThm ({name = "Pure.conjunctionI", ...}, _) % _ % _ %% prf %% _)) = SOME prf |
|
46 |
| rew' (PThm ({name = "Pure.conjunctionD2", ...}, _) % _ % _ %% |
|
47 |
(PThm ({name = "Pure.conjunctionI", ...}, _) % _ % _ %% _ %% prf)) = SOME prf |
|
26424 | 48 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
49 |
(PAxm ("Pure.equal_intr", _, _) % _ % _ %% prf %% _)) = SOME prf |
|
50 |
| rew' (PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
51 |
(PAxm ("Pure.equal_intr", _, _) % A % B %% prf1 %% prf2)) = |
|
15531 | 52 |
SOME (equal_intr_axm % B % A %% prf2 %% prf1) |
12002 | 53 |
|
26424 | 54 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A) % SOME (_ $ B) %% |
56244 | 55 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.prop", _)) % |
26424 | 56 |
_ % _ % _ %% (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% |
70493 | 57 |
((tg as PThm ({name = "Pure.protectI", ...}, _)) % _ %% prf2)) = |
15531 | 58 |
SOME (tg %> B %% (equal_elim_axm %> A %> B %% prf1 %% prf2)) |
12002 | 59 |
|
26424 | 60 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A) % SOME (_ $ B) %% |
61 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
56244 | 62 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.prop", _)) % |
26424 | 63 |
_ % _ % _ %% (PAxm ("Pure.reflexive", _, _) % _) %% prf1)) %% |
70493 | 64 |
((tg as PThm ({name = "Pure.protectI", ...}, _)) % _ %% prf2)) = |
15531 | 65 |
SOME (tg %> B %% (equal_elim_axm %> A %> B %% |
17137 | 66 |
(symmetric_axm % ?? B % ?? A %% prf1) %% prf2)) |
11522 | 67 |
|
26424 | 68 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %% |
69 |
(PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %% |
|
56245 | 70 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.imp", _)) % _ % _ % _ %% |
26424 | 71 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2)) = |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
72 |
let |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
73 |
val _ $ A $ C = Envir.beta_norm X; |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
74 |
val _ $ B $ D = Envir.beta_norm Y |
17137 | 75 |
in SOME (AbsP ("H1", ?? X, AbsP ("H2", ?? B, |
37310 | 76 |
Proofterm.equal_elim_axm %> C %> D %% Proofterm.incr_pboundvars 2 0 prf2 %% |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
77 |
(PBound 1 %% (equal_elim_axm %> B %> A %% |
37310 | 78 |
(Proofterm.symmetric_axm % ?? A % ?? B %% Proofterm.incr_pboundvars 2 0 prf1) %% |
79 |
PBound 0))))) |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
80 |
end |
11522 | 81 |
|
26424 | 82 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %% |
83 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
84 |
(PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %% |
|
56245 | 85 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.imp", _)) % _ % _ % _ %% |
26424 | 86 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2))) = |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
87 |
let |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
88 |
val _ $ A $ C = Envir.beta_norm Y; |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
89 |
val _ $ B $ D = Envir.beta_norm X |
17137 | 90 |
in SOME (AbsP ("H1", ?? X, AbsP ("H2", ?? A, |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
91 |
equal_elim_axm %> D %> C %% |
37310 | 92 |
(symmetric_axm % ?? C % ?? D %% Proofterm.incr_pboundvars 2 0 prf2) %% |
93 |
(PBound 1 %% |
|
94 |
(equal_elim_axm %> A %> B %% Proofterm.incr_pboundvars 2 0 prf1 %% PBound 0))))) |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
95 |
end |
11522 | 96 |
|
26424 | 97 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %% |
56245 | 98 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.all", _)) % _ % _ % _ %% |
26424 | 99 |
(PAxm ("Pure.reflexive", _, _) % _) %% |
100 |
(PAxm ("Pure.abstract_rule", _, _) % _ % _ %% prf))) = |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
101 |
let |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
102 |
val Const (_, T) $ P = Envir.beta_norm X; |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
103 |
val _ $ Q = Envir.beta_norm Y; |
17137 | 104 |
in SOME (AbsP ("H", ?? X, Abst ("x", ty T, |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
105 |
equal_elim_axm %> incr_boundvars 1 P $ Bound 0 %> incr_boundvars 1 Q $ Bound 0 %% |
37310 | 106 |
(Proofterm.incr_pboundvars 1 1 prf %> Bound 0) %% (PBound 0 %> Bound 0)))) |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
107 |
end |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
108 |
|
26424 | 109 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %% |
110 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
56245 | 111 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.all", _)) % _ % _ % _ %% |
26424 | 112 |
(PAxm ("Pure.reflexive", _, _) % _) %% |
113 |
(PAxm ("Pure.abstract_rule", _, _) % _ % _ %% prf)))) = |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
114 |
let |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
115 |
val Const (_, T) $ P = Envir.beta_norm X; |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
116 |
val _ $ Q = Envir.beta_norm Y; |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
117 |
val t = incr_boundvars 1 P $ Bound 0; |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
118 |
val u = incr_boundvars 1 Q $ Bound 0 |
17137 | 119 |
in SOME (AbsP ("H", ?? X, Abst ("x", ty T, |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
120 |
equal_elim_axm %> t %> u %% |
37310 | 121 |
(symmetric_axm % ?? u % ?? t %% (Proofterm.incr_pboundvars 1 1 prf %> Bound 0)) |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
122 |
%% (PBound 0 %> Bound 0)))) |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
123 |
end |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
124 |
|
26424 | 125 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME A % SOME C %% |
126 |
(PAxm ("Pure.transitive", _, _) % _ % SOME B % _ %% prf1 %% prf2) %% prf3) = |
|
15531 | 127 |
SOME (equal_elim_axm %> B %> C %% prf2 %% |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
128 |
(equal_elim_axm %> A %> B %% prf1 %% prf3)) |
26424 | 129 |
| rew' (PAxm ("Pure.equal_elim", _, _) % SOME A % SOME C %% |
130 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
131 |
(PAxm ("Pure.transitive", _, _) % _ % SOME B % _ %% prf1 %% prf2)) %% prf3) = |
|
17137 | 132 |
SOME (equal_elim_axm %> B %> C %% (symmetric_axm % ?? C % ?? B %% prf1) %% |
133 |
(equal_elim_axm %> A %> B %% (symmetric_axm % ?? B % ?? A %% prf2) %% prf3)) |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
134 |
|
26424 | 135 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
136 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf) = SOME prf |
|
137 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
|
138 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
139 |
(PAxm ("Pure.reflexive", _, _) % _)) %% prf) = SOME prf |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
140 |
|
26424 | 141 |
| rew' (PAxm ("Pure.symmetric", _, _) % _ % _ %% |
142 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% prf)) = SOME prf |
|
11522 | 143 |
|
26424 | 144 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
145 |
(PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A $ C) % SOME (_ $ B $ D) %% |
|
146 |
(PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %% |
|
56245 | 147 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.eq", _)) % _ % _ % _ %% |
26424 | 148 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3) %% prf4) = |
15531 | 149 |
SOME (equal_elim_axm %> C %> D %% prf2 %% |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
150 |
(equal_elim_axm %> A %> C %% prf3 %% |
17137 | 151 |
(equal_elim_axm %> B %> A %% (symmetric_axm % ?? A % ?? B %% prf1) %% prf4))) |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
152 |
|
26424 | 153 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
154 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
155 |
(PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A $ C) % SOME (_ $ B $ D) %% |
|
156 |
(PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %% |
|
56245 | 157 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.eq", _)) % _ % _ % _ %% |
26424 | 158 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3)) %% prf4) = |
15531 | 159 |
SOME (equal_elim_axm %> A %> B %% prf1 %% |
17137 | 160 |
(equal_elim_axm %> C %> A %% (symmetric_axm % ?? A % ?? C %% prf3) %% |
161 |
(equal_elim_axm %> D %> C %% (symmetric_axm % ?? C % ?? D %% prf2) %% prf4))) |
|
11522 | 162 |
|
26424 | 163 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
164 |
(PAxm ("Pure.equal_elim", _, _) % SOME (_ $ B $ D) % SOME (_ $ A $ C) %% |
|
165 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
166 |
(PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %% |
|
56245 | 167 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.eq", _)) % _ % _ % _ %% |
26424 | 168 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3) %% prf4) = |
17137 | 169 |
SOME (equal_elim_axm %> D %> C %% (symmetric_axm % ?? C % ?? D %% prf2) %% |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
170 |
(equal_elim_axm %> B %> D %% prf3 %% |
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
171 |
(equal_elim_axm %> A %> B %% prf1 %% prf4))) |
11522 | 172 |
|
26424 | 173 |
| rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %% |
174 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
175 |
(PAxm ("Pure.equal_elim", _, _) % SOME (_ $ B $ D) % SOME (_ $ A $ C) %% |
|
176 |
(PAxm ("Pure.symmetric", _, _) % _ % _ %% |
|
177 |
(PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %% |
|
56245 | 178 |
(PAxm ("Pure.combination", _, _) % SOME (Const ("Pure.eq", _)) % _ % _ % _ %% |
26424 | 179 |
(PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3)) %% prf4) = |
17137 | 180 |
SOME (equal_elim_axm %> B %> A %% (symmetric_axm % ?? A % ?? B %% prf1) %% |
181 |
(equal_elim_axm %> D %> B %% (symmetric_axm % ?? B % ?? D %% prf3) %% |
|
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
182 |
(equal_elim_axm %> C %> D %% prf2 %% prf4))) |
11522 | 183 |
|
26424 | 184 |
| rew' ((prf as PAxm ("Pure.combination", _, _) % |
56245 | 185 |
SOME ((eq as Const ("Pure.eq", T)) $ t) % _ % _ % _) %% |
26424 | 186 |
(PAxm ("Pure.reflexive", _, _) % _)) = |
13257 | 187 |
let val (U, V) = (case T of |
188 |
Type (_, [U, V]) => (U, V) | _ => (dummyT, dummyT)) |
|
37310 | 189 |
in SOME (prf %% (ax Proofterm.combination_axm [U, V] %> eq % ?? eq % ?? t % ?? t %% |
190 |
(ax Proofterm.reflexive_axm [T] % ?? eq) %% (ax Proofterm.reflexive_axm [U] % ?? t))) |
|
13257 | 191 |
end |
192 |
||
19309 | 193 |
| rew' _ = NONE; |
37310 | 194 |
in rew' #> Option.map (rpair Proofterm.no_skel) end; |
12866
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
berghofe
parents:
12237
diff
changeset
|
195 |
|
28806
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
wenzelm
parents:
26463
diff
changeset
|
196 |
fun rprocs b = [rew b]; |
53171 | 197 |
val _ = Theory.setup (fold Proofterm.add_prf_rproc (rprocs false)); |
11522 | 198 |
|
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
199 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
200 |
(**** apply rewriting function to all terms in proof ****) |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
201 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
202 |
fun rewrite_terms r = |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
203 |
let |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
204 |
fun rew_term Ts t = |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
205 |
let |
29271
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
28806
diff
changeset
|
206 |
val frees = |
43329
84472e198515
tuned signature: Name.invent and Name.invent_names;
wenzelm
parents:
43322
diff
changeset
|
207 |
map Free (Name.invent (Term.declare_term_frees t Name.context) "xa" (length Ts) ~~ Ts); |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
208 |
val t' = r (subst_bounds (frees, t)); |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
209 |
fun strip [] t = t |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
210 |
| strip (_ :: xs) (Abs (_, _, t)) = strip xs t; |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
211 |
in |
19473 | 212 |
strip Ts (fold lambda frees t') |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
213 |
end; |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
214 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
215 |
fun rew Ts (prf1 %% prf2) = rew Ts prf1 %% rew Ts prf2 |
15531 | 216 |
| rew Ts (prf % SOME t) = rew Ts prf % SOME (rew_term Ts t) |
217 |
| rew Ts (Abst (s, SOME T, prf)) = Abst (s, SOME T, rew (T :: Ts) prf) |
|
218 |
| rew Ts (AbsP (s, SOME t, prf)) = AbsP (s, SOME (rew_term Ts t), rew Ts prf) |
|
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
219 |
| rew _ prf = prf |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
220 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
221 |
in rew [] end; |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
222 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
223 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
224 |
(**** eliminate definitions in proof ****) |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
225 |
|
16861 | 226 |
fun vars_of t = rev (fold_aterms (fn v as Var _ => insert (op =) v | _ => I) t []); |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
227 |
|
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
228 |
fun insert_refl defs Ts (prf1 %% prf2) = |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
229 |
let val (prf1', b) = insert_refl defs Ts prf1 |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
230 |
in |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
231 |
if b then (prf1', true) |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
232 |
else (prf1' %% fst (insert_refl defs Ts prf2), false) |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
233 |
end |
15531 | 234 |
| insert_refl defs Ts (Abst (s, SOME T, prf)) = |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
235 |
(Abst (s, SOME T, fst (insert_refl defs (T :: Ts) prf)), false) |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
236 |
| insert_refl defs Ts (AbsP (s, t, prf)) = |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
237 |
(AbsP (s, t, fst (insert_refl defs Ts prf)), false) |
37310 | 238 |
| insert_refl defs Ts prf = |
239 |
(case Proofterm.strip_combt prf of |
|
70493 | 240 |
(PThm ({name = s, prop, types = SOME Ts, ...}, _), ts) => |
20664 | 241 |
if member (op =) defs s then |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
242 |
let |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
243 |
val vs = vars_of prop; |
36042
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
krauss
parents:
33722
diff
changeset
|
244 |
val tvars = Term.add_tvars prop [] |> rev; |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
245 |
val (_, rhs) = Logic.dest_equals (Logic.strip_imp_concl prop); |
18185 | 246 |
val rhs' = Term.betapplys (subst_TVars (map fst tvars ~~ Ts) |
23178 | 247 |
(fold_rev (fn x => fn b => Abs ("", dummyT, abstract_over (x, b))) vs rhs), |
19466 | 248 |
map the ts); |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
249 |
in |
70417 | 250 |
(Proofterm.change_types (SOME [fastype_of1 (Ts, rhs')]) |
37310 | 251 |
Proofterm.reflexive_axm %> rhs', true) |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
252 |
end |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
253 |
else (prf, false) |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
254 |
| (_, []) => (prf, false) |
37310 | 255 |
| (prf', ts) => (Proofterm.proof_combt' (fst (insert_refl defs Ts prf'), ts), false)); |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
256 |
|
70449 | 257 |
fun elim_defs thy r defs prf = |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
258 |
let |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
259 |
val defs' = map (Logic.dest_equals o |
59582 | 260 |
map_types Type.strip_sorts o Thm.prop_of o Drule.abs_def) defs; |
36744
6e1f3d609a68
renamed Thm.get_name -> Thm.derivation_name and Thm.put_name -> Thm.name_derivation, to emphasize the true nature of these operations;
wenzelm
parents:
36042
diff
changeset
|
261 |
val defnames = map Thm.derivation_name defs; |
70826 | 262 |
val prf' = |
263 |
if r then |
|
264 |
let |
|
265 |
val cnames = map (fst o dest_Const o fst) defs'; |
|
70915
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70879
diff
changeset
|
266 |
val expand = Proofterm.fold_proof_atoms true |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70879
diff
changeset
|
267 |
(fn PThm ({serial, name, prop, ...}, _) => |
70826 | 268 |
if member (op =) defnames name orelse |
269 |
not (exists_Const (member (op =) cnames o #1) prop) |
|
270 |
then I |
|
70915
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70879
diff
changeset
|
271 |
else Inttab.update (serial, "") |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70879
diff
changeset
|
272 |
| _ => I) [prf] Inttab.empty; |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70879
diff
changeset
|
273 |
in Proofterm.expand_proof thy (Inttab.lookup expand o #serial) prf end |
70826 | 274 |
else prf; |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
275 |
in |
70449 | 276 |
rewrite_terms (Pattern.rewrite_term thy defs' []) |
70826 | 277 |
(fst (insert_refl defnames [] prf')) |
12906
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
278 |
end; |
165f4e1937f4
New function for eliminating definitions in proof term.
berghofe
parents:
12866
diff
changeset
|
279 |
|
13608 | 280 |
|
281 |
(**** eliminate all variables that don't occur in the proposition ****) |
|
282 |
||
283 |
fun elim_vars mk_default prf = |
|
284 |
let |
|
70447
755d58b48cec
clarified modules: provide reconstruct_proof / expand_proof at the bottom of proof term construction;
wenzelm
parents:
70417
diff
changeset
|
285 |
val prop = Proofterm.prop_of prf; |
19309 | 286 |
val tv = Term.add_vars prop []; |
287 |
val tf = Term.add_frees prop []; |
|
288 |
||
289 |
fun hidden_variable (Var v) = not (member (op =) tv v) |
|
290 |
| hidden_variable (Free f) = not (member (op =) tf f) |
|
291 |
| hidden_variable _ = false; |
|
13917 | 292 |
|
46219
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
wenzelm
parents:
43329
diff
changeset
|
293 |
fun mk_default' T = |
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
wenzelm
parents:
43329
diff
changeset
|
294 |
fold_rev (Term.abs o pair "x") (binder_types T) (mk_default (body_type T)); |
13917 | 295 |
|
296 |
fun elim_varst (t $ u) = elim_varst t $ elim_varst u |
|
297 |
| elim_varst (Abs (s, T, t)) = Abs (s, T, elim_varst t) |
|
19309 | 298 |
| elim_varst (t as Free (x, T)) = if member (op =) tf (x, T) then t else mk_default' T |
299 |
| elim_varst (t as Var (xi, T)) = if member (op =) tv (xi, T) then t else mk_default' T |
|
300 |
| elim_varst t = t; |
|
13608 | 301 |
in |
37310 | 302 |
Proofterm.map_proof_terms (fn t => |
19309 | 303 |
if Term.exists_subterm hidden_variable t then Envir.beta_norm (elim_varst t) else t) I prf |
13608 | 304 |
end; |
305 |
||
22280 | 306 |
|
307 |
(**** convert between hhf and non-hhf form ****) |
|
308 |
||
309 |
fun hhf_proof P Q prf = |
|
310 |
let |
|
311 |
val params = Logic.strip_params Q; |
|
312 |
val Hs = Logic.strip_assums_hyp P; |
|
313 |
val Hs' = Logic.strip_assums_hyp Q; |
|
314 |
val k = length Hs; |
|
315 |
val l = length params; |
|
56245 | 316 |
fun mk_prf i j Hs Hs' (Const ("Pure.all", _) $ Abs (_, _, P)) prf = |
22280 | 317 |
mk_prf i (j - 1) Hs Hs' P (prf %> Bound j) |
56245 | 318 |
| mk_prf i j (H :: Hs) (H' :: Hs') (Const ("Pure.imp", _) $ _ $ P) prf = |
22280 | 319 |
mk_prf (i - 1) j Hs Hs' P (prf %% un_hhf_proof H' H (PBound i)) |
320 |
| mk_prf _ _ _ _ _ prf = prf |
|
321 |
in |
|
322 |
prf |> Proofterm.incr_pboundvars k l |> mk_prf (k - 1) (l - 1) Hs Hs' P |> |
|
323 |
fold_rev (fn P => fn prf => AbsP ("H", SOME P, prf)) Hs' |> |
|
324 |
fold_rev (fn (s, T) => fn prf => Abst (s, SOME T, prf)) params |
|
325 |
end |
|
326 |
and un_hhf_proof P Q prf = |
|
327 |
let |
|
328 |
val params = Logic.strip_params Q; |
|
329 |
val Hs = Logic.strip_assums_hyp P; |
|
330 |
val Hs' = Logic.strip_assums_hyp Q; |
|
331 |
val k = length Hs; |
|
332 |
val l = length params; |
|
56245 | 333 |
fun mk_prf (Const ("Pure.all", _) $ Abs (s, T, P)) prf = |
22280 | 334 |
Abst (s, SOME T, mk_prf P prf) |
56245 | 335 |
| mk_prf (Const ("Pure.imp", _) $ P $ Q) prf = |
22280 | 336 |
AbsP ("H", SOME P, mk_prf Q prf) |
337 |
| mk_prf _ prf = prf |
|
338 |
in |
|
339 |
prf |> Proofterm.incr_pboundvars k l |> |
|
340 |
fold (fn i => fn prf => prf %> Bound i) (l - 1 downto 0) |> |
|
341 |
fold (fn ((H, H'), i) => fn prf => prf %% hhf_proof H' H (PBound i)) |
|
342 |
(Hs ~~ Hs' ~~ (k - 1 downto 0)) |> |
|
343 |
mk_prf Q |
|
344 |
end; |
|
345 |
||
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
346 |
|
71777
3875815f5967
clarified signature: avoid clash with Isabelle/Scala Term.OFCLASS on case-insensible file-system;
wenzelm
parents:
71087
diff
changeset
|
347 |
(**** expand PClass proofs ****) |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
348 |
|
70836 | 349 |
fun expand_of_sort_proof thy hyps (T, S) = |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
350 |
let |
70836 | 351 |
val of_class_hyps = map (fn SOME t => try Logic.dest_of_class t | NONE => NONE) hyps; |
352 |
fun of_class_index p = |
|
353 |
(case find_index (fn SOME h => h = p | NONE => false) of_class_hyps of |
|
354 |
~1 => raise Fail "expand_of_class_proof: missing class hypothesis" |
|
355 |
| i => PBound i); |
|
356 |
||
357 |
val sorts = AList.coalesce (op =) (rev (map_filter I of_class_hyps)); |
|
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
358 |
fun get_sort T = the_default [] (AList.lookup (op =) sorts T); |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
359 |
val subst = map_atyps |
70836 | 360 |
(fn T as TVar (ai, _) => TVar (ai, get_sort T) |
361 |
| T as TFree (a, _) => TFree (a, get_sort T)); |
|
362 |
||
363 |
fun reconstruct prop = |
|
364 |
Proofterm.reconstruct_proof thy prop #> |
|
70915
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70879
diff
changeset
|
365 |
Proofterm.expand_proof thy Proofterm.expand_name_empty #> |
70836 | 366 |
Same.commit (Proofterm.map_proof_same Same.same Same.same of_class_index); |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
367 |
in |
70836 | 368 |
map2 reconstruct (Logic.mk_of_sort (T, S)) |
70458 | 369 |
(Proofterm.of_sort_proof (Sign.classes_of thy) (Thm.classrel_proof thy) (Thm.arity_proof thy) |
71777
3875815f5967
clarified signature: avoid clash with Isabelle/Scala Term.OFCLASS on case-insensible file-system;
wenzelm
parents:
71087
diff
changeset
|
370 |
(PClass o apfst Type.strip_sorts) (subst T, S)) |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
371 |
end; |
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
372 |
|
70837 | 373 |
fun expand_of_class_proof thy hyps (T, c) = |
374 |
hd (expand_of_sort_proof thy hyps (T, [c])); |
|
375 |
||
71777
3875815f5967
clarified signature: avoid clash with Isabelle/Scala Term.OFCLASS on case-insensible file-system;
wenzelm
parents:
71087
diff
changeset
|
376 |
fun expand_of_class thy (_: typ list) hyps (PClass (T, c)) = |
70837 | 377 |
SOME (expand_of_class_proof thy hyps (T, c), Proofterm.no_skel) |
70836 | 378 |
| expand_of_class _ _ _ _ = NONE; |
37233
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
berghofe
parents:
36744
diff
changeset
|
379 |
|
70879 | 380 |
|
381 |
(* standard preprocessor *) |
|
382 |
||
383 |
fun standard_preproc rews thy = |
|
384 |
Proofterm.rewrite_proof thy (rews, rprocs true @ [expand_of_class thy]); |
|
385 |
||
11522 | 386 |
end; |