| author | haftmann | 
| Mon, 26 Oct 2009 09:03:57 +0100 | |
| changeset 33176 | d6936fd7cda8 | 
| parent 29271 | 1d685baea08e | 
| child 33722 | e588744f14da | 
| 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: 
12866diff
changeset | 4 | Simplification functions for proof terms involving meta level rules. | 
| 11522 | 5 | *) | 
| 6 | ||
| 7 | signature PROOF_REWRITE_RULES = | |
| 8 | sig | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 9 | val rew : bool -> typ list -> Proofterm.proof -> Proofterm.proof option | 
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 10 | val rprocs : bool -> (typ list -> Proofterm.proof -> Proofterm.proof option) list | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 11 | val rewrite_terms : (term -> term) -> Proofterm.proof -> Proofterm.proof | 
| 17203 | 12 | val elim_defs : theory -> bool -> thm list -> Proofterm.proof -> Proofterm.proof | 
| 13608 | 13 | val elim_vars : (typ -> term) -> Proofterm.proof -> Proofterm.proof | 
| 22280 | 14 | val hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof | 
| 15 | val un_hhf_proof : term -> term -> Proofterm.proof -> Proofterm.proof | |
| 11522 | 16 | end; | 
| 17 | ||
| 18 | structure ProofRewriteRules : PROOF_REWRITE_RULES = | |
| 19 | struct | |
| 20 | ||
| 21 | open Proofterm; | |
| 22 | ||
| 19309 | 23 | fun rew b _ = | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 24 | let | 
| 17137 | 25 | fun ?? x = if b then SOME x else NONE; | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 26 | fun ax (prf as PAxm (s, prop, _)) Ts = | 
| 15531 | 27 | if b then PAxm (s, prop, SOME Ts) else prf; | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 28 | fun ty T = if b then | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 29 | let val Type (_, [Type (_, [U, _]), _]) = T | 
| 15531 | 30 | in SOME U end | 
| 31 | else NONE; | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 32 | val equal_intr_axm = ax equal_intr_axm []; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 33 | val equal_elim_axm = ax equal_elim_axm []; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 34 | val symmetric_axm = ax symmetric_axm [propT]; | 
| 11522 | 35 | |
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 36 |     fun rew' (PThm (_, (("Pure.protectD", _, _), _)) % _ %%
 | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 37 |         (PThm (_, (("Pure.protectI", _, _), _)) % _ %% prf)) = SOME prf
 | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 38 |       | rew' (PThm (_, (("Pure.conjunctionD1", _, _), _)) % _ % _ %%
 | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 39 |         (PThm (_, (("Pure.conjunctionI", _, _), _)) % _ % _ %% prf %% _)) = SOME prf
 | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 40 |       | rew' (PThm (_, (("Pure.conjunctionD2", _, _), _)) % _ % _ %%
 | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 41 |         (PThm (_, (("Pure.conjunctionI", _, _), _)) % _ % _ %% _ %% prf)) = SOME prf
 | 
| 26424 | 42 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | 
| 43 |         (PAxm ("Pure.equal_intr", _, _) % _ % _ %% prf %% _)) = SOME prf
 | |
| 44 |       | rew' (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 45 |         (PAxm ("Pure.equal_intr", _, _) % A % B %% prf1 %% prf2)) =
 | |
| 15531 | 46 | SOME (equal_intr_axm % B % A %% prf2 %% prf1) | 
| 12002 | 47 | |
| 26424 | 48 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A) % SOME (_ $ B) %%
 | 
| 49 |         (PAxm ("Pure.combination", _, _) % SOME (Const ("prop", _)) %
 | |
| 50 |           _ % _ % _ %% (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %%
 | |
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 51 |         ((tg as PThm (_, (("Pure.protectI", _, _), _))) % _ %% prf2)) =
 | 
| 15531 | 52 | SOME (tg %> B %% (equal_elim_axm %> A %> B %% prf1 %% prf2)) | 
| 12002 | 53 | |
| 26424 | 54 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A) % SOME (_ $ B) %%
 | 
| 55 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 56 |           (PAxm ("Pure.combination", _, _) % SOME (Const ("prop", _)) %
 | |
| 57 |              _ % _ % _ %% (PAxm ("Pure.reflexive", _, _) % _) %% prf1)) %%
 | |
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 58 |         ((tg as PThm (_, (("Pure.protectI", _, _), _))) % _ %% prf2)) =
 | 
| 15531 | 59 | SOME (tg %> B %% (equal_elim_axm %> A %> B %% | 
| 17137 | 60 | (symmetric_axm % ?? B % ?? A %% prf1) %% prf2)) | 
| 11522 | 61 | |
| 26424 | 62 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %%
 | 
| 63 |         (PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %%
 | |
| 64 |           (PAxm ("Pure.combination", _, _) % SOME (Const ("==>", _)) % _ % _ % _ %%
 | |
| 65 |              (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2)) =
 | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 66 | let | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 67 | val _ $ A $ C = Envir.beta_norm X; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 68 | val _ $ B $ D = Envir.beta_norm Y | 
| 17137 | 69 |         in SOME (AbsP ("H1", ?? X, AbsP ("H2", ?? B,
 | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 70 | equal_elim_axm %> C %> D %% incr_pboundvars 2 0 prf2 %% | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 71 | (PBound 1 %% (equal_elim_axm %> B %> A %% | 
| 17137 | 72 | (symmetric_axm % ?? A % ?? B %% incr_pboundvars 2 0 prf1) %% PBound 0))))) | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 73 | end | 
| 11522 | 74 | |
| 26424 | 75 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %%
 | 
| 76 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 77 |           (PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %%
 | |
| 78 |             (PAxm ("Pure.combination", _, _) % SOME (Const ("==>", _)) % _ % _ % _ %%
 | |
| 79 |                (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2))) =
 | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 80 | let | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 81 | val _ $ A $ C = Envir.beta_norm Y; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 82 | val _ $ B $ D = Envir.beta_norm X | 
| 17137 | 83 |         in SOME (AbsP ("H1", ?? X, AbsP ("H2", ?? A,
 | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 84 | equal_elim_axm %> D %> C %% | 
| 17137 | 85 | (symmetric_axm % ?? C % ?? D %% incr_pboundvars 2 0 prf2) | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 86 | %% (PBound 1 %% (equal_elim_axm %> A %> B %% incr_pboundvars 2 0 prf1 %% PBound 0))))) | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 87 | end | 
| 11522 | 88 | |
| 26424 | 89 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %%
 | 
| 90 |         (PAxm ("Pure.combination", _, _) % SOME (Const ("all", _)) % _ % _ % _ %%
 | |
| 91 |           (PAxm ("Pure.reflexive", _, _) % _) %%
 | |
| 92 |             (PAxm ("Pure.abstract_rule", _, _) % _ % _ %% prf))) =
 | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 93 | let | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 94 | val Const (_, T) $ P = Envir.beta_norm X; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 95 | val _ $ Q = Envir.beta_norm Y; | 
| 17137 | 96 |         in SOME (AbsP ("H", ?? X, Abst ("x", ty T,
 | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 97 | equal_elim_axm %> incr_boundvars 1 P $ Bound 0 %> incr_boundvars 1 Q $ Bound 0 %% | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 98 | (incr_pboundvars 1 1 prf %> Bound 0) %% (PBound 0 %> Bound 0)))) | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 99 | end | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 100 | |
| 26424 | 101 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME X % SOME Y %%
 | 
| 102 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%        
 | |
| 103 |           (PAxm ("Pure.combination", _, _) % SOME (Const ("all", _)) % _ % _ % _ %%
 | |
| 104 |             (PAxm ("Pure.reflexive", _, _) % _) %%
 | |
| 105 |               (PAxm ("Pure.abstract_rule", _, _) % _ % _ %% prf)))) =
 | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 106 | let | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 107 | val Const (_, T) $ P = Envir.beta_norm X; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 108 | val _ $ Q = Envir.beta_norm Y; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 109 | val t = incr_boundvars 1 P $ Bound 0; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 110 | val u = incr_boundvars 1 Q $ Bound 0 | 
| 17137 | 111 |         in SOME (AbsP ("H", ?? X, Abst ("x", ty T,
 | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 112 | equal_elim_axm %> t %> u %% | 
| 17137 | 113 | (symmetric_axm % ?? u % ?? t %% (incr_pboundvars 1 1 prf %> Bound 0)) | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 114 | %% (PBound 0 %> Bound 0)))) | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 115 | end | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 116 | |
| 26424 | 117 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME A % SOME C %%
 | 
| 118 |         (PAxm ("Pure.transitive", _, _) % _ % SOME B % _ %% prf1 %% prf2) %% prf3) =
 | |
| 15531 | 119 | SOME (equal_elim_axm %> B %> C %% prf2 %% | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 120 | (equal_elim_axm %> A %> B %% prf1 %% prf3)) | 
| 26424 | 121 |       | rew' (PAxm ("Pure.equal_elim", _, _) % SOME A % SOME C %%
 | 
| 122 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 123 |           (PAxm ("Pure.transitive", _, _) % _ % SOME B % _ %% prf1 %% prf2)) %% prf3) =
 | |
| 17137 | 124 | SOME (equal_elim_axm %> B %> C %% (symmetric_axm % ?? C % ?? B %% prf1) %% | 
| 125 | (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: 
12237diff
changeset | 126 | |
| 26424 | 127 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | 
| 128 |         (PAxm ("Pure.reflexive", _, _) % _) %% prf) = SOME prf
 | |
| 129 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | |
| 130 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 131 |           (PAxm ("Pure.reflexive", _, _) % _)) %% prf) = SOME prf
 | |
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 132 | |
| 26424 | 133 |       | rew' (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | 
| 134 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %% prf)) = SOME prf
 | |
| 11522 | 135 | |
| 26424 | 136 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | 
| 137 |         (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A $ C) % SOME (_ $ B $ D) %%
 | |
| 138 |           (PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %%
 | |
| 139 |             (PAxm ("Pure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
 | |
| 140 |               (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3) %% prf4) =
 | |
| 15531 | 141 | SOME (equal_elim_axm %> C %> D %% prf2 %% | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 142 | (equal_elim_axm %> A %> C %% prf3 %% | 
| 17137 | 143 | (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: 
12237diff
changeset | 144 | |
| 26424 | 145 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | 
| 146 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 147 |           (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ A $ C) % SOME (_ $ B $ D) %%
 | |
| 148 |             (PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %%
 | |
| 149 |               (PAxm ("Pure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
 | |
| 150 |                 (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2) %% prf3)) %% prf4) =
 | |
| 15531 | 151 | SOME (equal_elim_axm %> A %> B %% prf1 %% | 
| 17137 | 152 | (equal_elim_axm %> C %> A %% (symmetric_axm % ?? A % ?? C %% prf3) %% | 
| 153 | (equal_elim_axm %> D %> C %% (symmetric_axm % ?? C % ?? D %% prf2) %% prf4))) | |
| 11522 | 154 | |
| 26424 | 155 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | 
| 156 |         (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ B $ D) % SOME (_ $ A $ C) %%
 | |
| 157 |           (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 158 |             (PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %%
 | |
| 159 |               (PAxm ("Pure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
 | |
| 160 |                 (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3) %% prf4) =
 | |
| 17137 | 161 | 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: 
12237diff
changeset | 162 | (equal_elim_axm %> B %> D %% prf3 %% | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 163 | (equal_elim_axm %> A %> B %% prf1 %% prf4))) | 
| 11522 | 164 | |
| 26424 | 165 |       | rew' (PAxm ("Pure.equal_elim", _, _) % _ % _ %%
 | 
| 166 |         (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 167 |           (PAxm ("Pure.equal_elim", _, _) % SOME (_ $ B $ D) % SOME (_ $ A $ C) %%
 | |
| 168 |             (PAxm ("Pure.symmetric", _, _) % _ % _ %%
 | |
| 169 |               (PAxm ("Pure.combination", _, _) % _ % _ % _ % _ %%
 | |
| 170 |                 (PAxm ("Pure.combination", _, _) % SOME (Const ("==", _)) % _ % _ % _ %%
 | |
| 171 |                   (PAxm ("Pure.reflexive", _, _) % _) %% prf1) %% prf2)) %% prf3)) %% prf4) =
 | |
| 17137 | 172 | SOME (equal_elim_axm %> B %> A %% (symmetric_axm % ?? A % ?? B %% prf1) %% | 
| 173 | (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: 
12237diff
changeset | 174 | (equal_elim_axm %> C %> D %% prf2 %% prf4))) | 
| 11522 | 175 | |
| 26424 | 176 |       | rew' ((prf as PAxm ("Pure.combination", _, _) %
 | 
| 15531 | 177 |         SOME ((eq as Const ("==", T)) $ t) % _ % _ % _) %%
 | 
| 26424 | 178 |           (PAxm ("Pure.reflexive", _, _) % _)) =
 | 
| 13257 | 179 | let val (U, V) = (case T of | 
| 180 | Type (_, [U, V]) => (U, V) | _ => (dummyT, dummyT)) | |
| 17137 | 181 | in SOME (prf %% (ax combination_axm [V, U] %> eq % ?? eq % ?? t % ?? t %% | 
| 182 | (ax reflexive_axm [T] % ?? eq) %% (ax reflexive_axm [U] % ?? t))) | |
| 13257 | 183 | end | 
| 184 | ||
| 19309 | 185 | | rew' _ = NONE; | 
| 12866 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 186 | in rew' end; | 
| 
c00df7765656
Rewrite procedure now works for both compact and full proof objects.
 berghofe parents: 
12237diff
changeset | 187 | |
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 188 | fun rprocs b = [rew b]; | 
| 26463 | 189 | val _ = Context.>> (Context.map_theory (fold Proofterm.add_prf_rproc (rprocs false))); | 
| 11522 | 190 | |
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 191 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 192 | (**** apply rewriting function to all terms in proof ****) | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 193 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 194 | fun rewrite_terms r = | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 195 | let | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 196 | fun rew_term Ts t = | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 197 | let | 
| 29271 
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
28806diff
changeset | 198 | val frees = | 
| 
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
28806diff
changeset | 199 | map Free (Name.invent_list (OldTerm.add_term_names (t, [])) "xa" (length Ts) ~~ Ts); | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 200 | val t' = r (subst_bounds (frees, t)); | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 201 | fun strip [] t = t | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 202 | | strip (_ :: xs) (Abs (_, _, t)) = strip xs t; | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 203 | in | 
| 19473 | 204 | strip Ts (fold lambda frees t') | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 205 | end; | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 206 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 207 | fun rew Ts (prf1 %% prf2) = rew Ts prf1 %% rew Ts prf2 | 
| 15531 | 208 | | rew Ts (prf % SOME t) = rew Ts prf % SOME (rew_term Ts t) | 
| 209 | | rew Ts (Abst (s, SOME T, prf)) = Abst (s, SOME T, rew (T :: Ts) prf) | |
| 210 | | 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: 
12866diff
changeset | 211 | | rew _ prf = prf | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 212 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 213 | in rew [] end; | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 214 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 215 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 216 | (**** eliminate definitions in proof ****) | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 217 | |
| 16861 | 218 | 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: 
12866diff
changeset | 219 | |
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 220 | fun insert_refl defs Ts (prf1 %% prf2) = | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 221 | insert_refl defs Ts prf1 %% insert_refl defs Ts prf2 | 
| 15531 | 222 | | insert_refl defs Ts (Abst (s, SOME T, prf)) = | 
| 223 | Abst (s, SOME T, insert_refl defs (T :: Ts) prf) | |
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 224 | | insert_refl defs Ts (AbsP (s, t, prf)) = | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 225 | AbsP (s, t, insert_refl defs Ts prf) | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 226 | | insert_refl defs Ts prf = (case strip_combt prf of | 
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 227 | (PThm (_, ((s, prop, SOME Ts), _)), ts) => | 
| 20664 | 228 | if member (op =) defs s then | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 229 | let | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 230 | val vs = vars_of prop; | 
| 29271 
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
28806diff
changeset | 231 | val tvars = OldTerm.term_tvars prop; | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 232 | val (_, rhs) = Logic.dest_equals prop; | 
| 18185 | 233 | val rhs' = Term.betapplys (subst_TVars (map fst tvars ~~ Ts) | 
| 23178 | 234 |                 (fold_rev (fn x => fn b => Abs ("", dummyT, abstract_over (x, b))) vs rhs),
 | 
| 19466 | 235 | map the ts); | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 236 | in | 
| 15531 | 237 | change_type (SOME [fastype_of1 (Ts, rhs')]) reflexive_axm %> rhs' | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 238 | end | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 239 | else prf | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 240 | | (_, []) => prf | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 241 | | (prf', ts) => proof_combt' (insert_refl defs Ts prf', ts)); | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 242 | |
| 17203 | 243 | fun elim_defs thy r defs prf = | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 244 | let | 
| 13341 | 245 | val defs' = map (Logic.dest_equals o prop_of o Drule.abs_def) defs | 
| 21646 
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
 wenzelm parents: 
20664diff
changeset | 246 | val defnames = map Thm.get_name defs; | 
| 13341 | 247 | val f = if not r then I else | 
| 248 | let | |
| 249 | val cnames = map (fst o dest_Const o fst) defs'; | |
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 250 | val thms = fold_proof_atoms true | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 251 | (fn PThm (_, ((name, prop, _), _)) => | 
| 29271 
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
28806diff
changeset | 252 | if member (op =) defnames name orelse | 
| 
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
28806diff
changeset | 253 | not (exists_Const (member (op =) cnames o #1) prop) | 
| 
1d685baea08e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
28806diff
changeset | 254 | then I | 
| 28806 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 255 | else cons (name, SOME prop) | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 256 | | _ => I) [prf] []; | 
| 
ba0ffe4cfc2b
rewrite_proof: simplified simprocs (no name required);
 wenzelm parents: 
26463diff
changeset | 257 | in Reconstruct.expand_proof thy thms end; | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 258 | in | 
| 17203 | 259 | rewrite_terms (Pattern.rewrite_term thy defs' []) | 
| 13341 | 260 | (insert_refl defnames [] (f prf)) | 
| 12906 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 261 | end; | 
| 
165f4e1937f4
New function for eliminating definitions in proof term.
 berghofe parents: 
12866diff
changeset | 262 | |
| 13608 | 263 | |
| 264 | (**** eliminate all variables that don't occur in the proposition ****) | |
| 265 | ||
| 266 | fun elim_vars mk_default prf = | |
| 267 | let | |
| 268 | val prop = Reconstruct.prop_of prf; | |
| 19309 | 269 | val tv = Term.add_vars prop []; | 
| 270 | val tf = Term.add_frees prop []; | |
| 271 | ||
| 272 | fun hidden_variable (Var v) = not (member (op =) tv v) | |
| 273 | | hidden_variable (Free f) = not (member (op =) tf f) | |
| 274 | | hidden_variable _ = false; | |
| 13917 | 275 | |
| 276 | fun mk_default' T = list_abs | |
| 277 | (apfst (map (pair "x")) (apsnd mk_default (strip_type T))); | |
| 278 | ||
| 279 | fun elim_varst (t $ u) = elim_varst t $ elim_varst u | |
| 280 | | elim_varst (Abs (s, T, t)) = Abs (s, T, elim_varst t) | |
| 19309 | 281 | | elim_varst (t as Free (x, T)) = if member (op =) tf (x, T) then t else mk_default' T | 
| 282 | | elim_varst (t as Var (xi, T)) = if member (op =) tv (xi, T) then t else mk_default' T | |
| 283 | | elim_varst t = t; | |
| 13608 | 284 | in | 
| 19309 | 285 | map_proof_terms (fn t => | 
| 286 | if Term.exists_subterm hidden_variable t then Envir.beta_norm (elim_varst t) else t) I prf | |
| 13608 | 287 | end; | 
| 288 | ||
| 22280 | 289 | |
| 290 | (**** convert between hhf and non-hhf form ****) | |
| 291 | ||
| 292 | fun hhf_proof P Q prf = | |
| 293 | let | |
| 294 | val params = Logic.strip_params Q; | |
| 295 | val Hs = Logic.strip_assums_hyp P; | |
| 296 | val Hs' = Logic.strip_assums_hyp Q; | |
| 297 | val k = length Hs; | |
| 298 | val l = length params; | |
| 299 |     fun mk_prf i j Hs Hs' (Const ("all", _) $ Abs (_, _, P)) prf =
 | |
| 300 | mk_prf i (j - 1) Hs Hs' P (prf %> Bound j) | |
| 301 |       | mk_prf i j (H :: Hs) (H' :: Hs') (Const ("==>", _) $ _ $ P) prf =
 | |
| 302 | mk_prf (i - 1) j Hs Hs' P (prf %% un_hhf_proof H' H (PBound i)) | |
| 303 | | mk_prf _ _ _ _ _ prf = prf | |
| 304 | in | |
| 305 | prf |> Proofterm.incr_pboundvars k l |> mk_prf (k - 1) (l - 1) Hs Hs' P |> | |
| 306 |     fold_rev (fn P => fn prf => AbsP ("H", SOME P, prf)) Hs' |>
 | |
| 307 | fold_rev (fn (s, T) => fn prf => Abst (s, SOME T, prf)) params | |
| 308 | end | |
| 309 | and un_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; | |
| 316 |     fun mk_prf (Const ("all", _) $ Abs (s, T, P)) prf =
 | |
| 317 | Abst (s, SOME T, mk_prf P prf) | |
| 318 |       | mk_prf (Const ("==>", _) $ P $ Q) prf =
 | |
| 319 |           AbsP ("H", SOME P, mk_prf Q prf)
 | |
| 320 | | mk_prf _ prf = prf | |
| 321 | in | |
| 322 | prf |> Proofterm.incr_pboundvars k l |> | |
| 323 | fold (fn i => fn prf => prf %> Bound i) (l - 1 downto 0) |> | |
| 324 | fold (fn ((H, H'), i) => fn prf => prf %% hhf_proof H' H (PBound i)) | |
| 325 | (Hs ~~ Hs' ~~ (k - 1 downto 0)) |> | |
| 326 | mk_prf Q | |
| 327 | end; | |
| 328 | ||
| 11522 | 329 | end; |