author | wenzelm |
Wed, 25 Mar 2009 16:52:50 +0100 | |
changeset 30716 | 2ee706293eb5 |
parent 30712 | fc9d8b1bf1e0 |
child 31903 | c5221dbc40f6 |
permissions | -rw-r--r-- |
11519 | 1 |
(* Title: Pure/proofterm.ML |
11540 | 2 |
Author: Stefan Berghofer, TU Muenchen |
11519 | 3 |
|
11540 | 4 |
LF style proof terms. |
11519 | 5 |
*) |
6 |
||
11615 | 7 |
infix 8 % %% %>; |
11519 | 8 |
|
9 |
signature BASIC_PROOFTERM = |
|
10 |
sig |
|
11543
d61b913431c5
renamed `keep_derivs' to `proofs', and made an integer;
wenzelm
parents:
11540
diff
changeset
|
11 |
val proofs: int ref |
11519 | 12 |
|
13 |
datatype proof = |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
14 |
MinProof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
15 |
| PBound of int |
11519 | 16 |
| Abst of string * typ option * proof |
17 |
| AbsP of string * term option * proof |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
18 |
| op % of proof * term option |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
19 |
| op %% of proof * proof |
11519 | 20 |
| Hyp of term |
21 |
| PAxm of string * term * typ list option |
|
22 |
| Oracle of string * term * typ list option |
|
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
23 |
| Promise of serial * term * typ list |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
24 |
| PThm of serial * ((string * term * typ list option) * proof_body future) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
25 |
and proof_body = PBody of |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
26 |
{oracles: (string * term) OrdList.T, |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
27 |
thms: (serial * (string * term * proof_body future)) OrdList.T, |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
28 |
proof: proof} |
11519 | 29 |
|
11615 | 30 |
val %> : proof * term -> proof |
11519 | 31 |
end; |
32 |
||
33 |
signature PROOFTERM = |
|
34 |
sig |
|
35 |
include BASIC_PROOFTERM |
|
36 |
||
28815 | 37 |
type oracle = string * term |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
38 |
type pthm = serial * (string * term * proof_body future) |
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
39 |
val join_body: proof_body future -> |
28815 | 40 |
{oracles: oracle OrdList.T, thms: pthm OrdList.T, proof: proof} |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
41 |
val join_proof: proof_body future -> proof |
28815 | 42 |
val proof_of: proof_body -> proof |
30711 | 43 |
val fold_proof_atoms: bool -> (proof -> 'a -> 'a) -> proof list -> 'a -> 'a |
28815 | 44 |
val fold_body_thms: (string * term * proof_body -> 'a -> 'a) -> proof_body list -> 'a -> 'a |
30712 | 45 |
val status_of: proof_body list -> {failed: bool, oracle: bool, unfinished: bool} |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
46 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
47 |
val oracle_ord: oracle * oracle -> order |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
48 |
val thm_ord: pthm * pthm -> order |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
49 |
val merge_oracles: oracle OrdList.T -> oracle OrdList.T -> oracle OrdList.T |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
50 |
val merge_thms: pthm OrdList.T -> pthm OrdList.T -> pthm OrdList.T |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
51 |
val all_oracles_of: proof_body -> oracle OrdList.T |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
52 |
val approximate_proof_body: proof -> proof_body |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
53 |
|
11519 | 54 |
(** primitive operations **) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
55 |
val proof_combt: proof * term list -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
56 |
val proof_combt': proof * term option list -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
57 |
val proof_combP: proof * proof list -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
58 |
val strip_combt: proof -> proof * term option list |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
59 |
val strip_combP: proof -> proof * proof list |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
60 |
val strip_thm: proof_body -> proof_body |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
61 |
val map_proof_terms_option: (term -> term option) -> (typ -> typ option) -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
62 |
val map_proof_terms: (term -> term) -> (typ -> typ) -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
63 |
val fold_proof_terms: (term -> 'a -> 'a) -> (typ -> 'a -> 'a) -> proof -> 'a -> 'a |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
64 |
val maxidx_proof: proof -> int -> int |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
65 |
val size_of_proof: proof -> int |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
66 |
val change_type: typ list option -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
67 |
val prf_abstract_over: term -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
68 |
val prf_incr_bv: int -> int -> int -> int -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
69 |
val incr_pboundvars: int -> int -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
70 |
val prf_loose_bvar1: proof -> int -> bool |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
71 |
val prf_loose_Pbvar1: proof -> int -> bool |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
72 |
val prf_add_loose_bnos: int -> int -> proof -> int list * int list -> int list * int list |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
73 |
val norm_proof: Envir.env -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
74 |
val norm_proof': Envir.env -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
75 |
val prf_subst_bounds: term list -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
76 |
val prf_subst_pbounds: proof list -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
77 |
val freeze_thaw_prf: proof -> proof * (proof -> proof) |
11519 | 78 |
|
79 |
(** proof terms for specific inference rules **) |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
80 |
val implies_intr_proof: term -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
81 |
val forall_intr_proof: term -> string -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
82 |
val varify_proof: term -> (string * sort) list -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
83 |
val freezeT: term -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
84 |
val rotate_proof: term list -> term -> int -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
85 |
val permute_prems_prf: term list -> int -> int -> proof -> proof |
19908 | 86 |
val generalize: string list * string list -> int -> proof -> proof |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
87 |
val instantiate: ((indexname * sort) * typ) list * ((indexname * typ) * term) list |
16880 | 88 |
-> proof -> proof |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
89 |
val lift_proof: term -> int -> term -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
90 |
val assumption_proof: term list -> term -> int -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
91 |
val bicompose_proof: bool -> term list -> term list -> term list -> term option -> |
23296
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
92 |
int -> int -> proof -> proof -> proof |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
93 |
val equality_axms: (string * term) list |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
94 |
val reflexive_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
95 |
val symmetric_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
96 |
val transitive_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
97 |
val equal_intr_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
98 |
val equal_elim_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
99 |
val abstract_rule_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
100 |
val combination_axm: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
101 |
val reflexive: proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
102 |
val symmetric: proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
103 |
val transitive: term -> typ -> proof -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
104 |
val abstract_rule: term -> string -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
105 |
val combination: term -> term -> term -> term -> typ -> proof -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
106 |
val equal_intr: term -> term -> proof -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
107 |
val equal_elim: term -> term -> proof -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
108 |
val axm_proof: string -> term -> proof |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
109 |
val oracle_proof: string -> term -> oracle * proof |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
110 |
val promise_proof: theory -> serial -> term -> proof |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
111 |
val fulfill_proof: theory -> (serial * proof_body) list -> proof_body -> proof_body |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
112 |
val thm_proof: theory -> string -> term list -> term -> |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
113 |
(serial * proof_body future) list -> proof_body -> pthm * proof |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
114 |
val get_name: term list -> term -> proof -> string |
11519 | 115 |
|
116 |
(** rewriting on proof terms **) |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
117 |
val add_prf_rrule: proof * proof -> theory -> theory |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
118 |
val add_prf_rproc: (typ list -> proof -> proof option) -> theory -> theory |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
119 |
val rewrite_proof: theory -> (proof * proof) list * |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
120 |
(typ list -> proof -> proof option) list -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
121 |
val rewrite_proof_notypes: (proof * proof) list * |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
122 |
(typ list -> proof -> proof option) list -> proof -> proof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
123 |
val rew_proof: theory -> proof -> proof |
11519 | 124 |
end |
125 |
||
126 |
structure Proofterm : PROOFTERM = |
|
127 |
struct |
|
128 |
||
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
129 |
open Envir; |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
130 |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
131 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
132 |
(***** datatype proof *****) |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
133 |
|
11519 | 134 |
datatype proof = |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
135 |
MinProof |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
136 |
| PBound of int |
11519 | 137 |
| Abst of string * typ option * proof |
138 |
| AbsP of string * term option * proof |
|
12497 | 139 |
| op % of proof * term option |
140 |
| op %% of proof * proof |
|
11519 | 141 |
| Hyp of term |
142 |
| PAxm of string * term * typ list option |
|
143 |
| Oracle of string * term * typ list option |
|
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
144 |
| Promise of serial * term * typ list |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
145 |
| PThm of serial * ((string * term * typ list option) * proof_body future) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
146 |
and proof_body = PBody of |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
147 |
{oracles: (string * term) OrdList.T, |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
148 |
thms: (serial * (string * term * proof_body future)) OrdList.T, |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
149 |
proof: proof}; |
11519 | 150 |
|
28815 | 151 |
type oracle = string * term; |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
152 |
type pthm = serial * (string * term * proof_body future); |
28815 | 153 |
|
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
154 |
val join_body = Future.join #> (fn PBody args => args); |
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
155 |
val join_proof = #proof o join_body; |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
156 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
157 |
fun proof_of (PBody {proof, ...}) = proof; |
17017 | 158 |
|
159 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
160 |
(***** proof atoms *****) |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
161 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
162 |
fun fold_proof_atoms all f = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
163 |
let |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
164 |
fun app (Abst (_, _, prf)) = app prf |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
165 |
| app (AbsP (_, _, prf)) = app prf |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
166 |
| app (prf % _) = app prf |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
167 |
| app (prf1 %% prf2) = app prf1 #> app prf2 |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
168 |
| app (prf as PThm (i, (_, body))) = (fn (x, seen) => |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
169 |
if Inttab.defined seen i then (x, seen) |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
170 |
else |
28815 | 171 |
let val (x', seen') = |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
172 |
(if all then app (join_proof body) else I) (x, Inttab.update (i, ()) seen) |
28815 | 173 |
in (f prf x', seen') end) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
174 |
| app prf = (fn (x, seen) => (f prf x, seen)); |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
175 |
in fn prfs => fn x => #1 (fold app prfs (x, Inttab.empty)) end; |
19357
dade85a75c9f
Added alternative version of thms_of_proof that does not recursively
berghofe
parents:
19304
diff
changeset
|
176 |
|
30711 | 177 |
fun fold_body_thms f = |
178 |
let |
|
179 |
fun app (PBody {thms, ...}) = thms |> fold (fn (i, (name, prop, body)) => fn (x, seen) => |
|
180 |
if Inttab.defined seen i then (x, seen) |
|
181 |
else |
|
182 |
let |
|
183 |
val body' = Future.join body; |
|
184 |
val (x', seen') = app body' (x, Inttab.update (i, ()) seen); |
|
185 |
in (f (name, prop, body') x', seen') end); |
|
186 |
in fn bodies => fn x => #1 (fold app bodies (x, Inttab.empty)) end; |
|
187 |
||
30712 | 188 |
fun status_of bodies = |
30711 | 189 |
let |
190 |
fun status (PBody {oracles, thms, ...}) x = |
|
191 |
let |
|
192 |
val ((oracle, unfinished, failed), seen) = |
|
193 |
(thms, x) |-> fold (fn (i, (_, _, body)) => fn (st, seen) => |
|
194 |
if Inttab.defined seen i then (st, seen) |
|
195 |
else |
|
196 |
let val seen' = Inttab.update (i, ()) seen in |
|
197 |
(case Future.peek body of |
|
198 |
SOME (Exn.Result body') => status body' (st, seen') |
|
199 |
| SOME (Exn.Exn _) => |
|
200 |
let val (oracle, unfinished, _) = st |
|
201 |
in ((oracle, unfinished, true), seen') end |
|
202 |
| NONE => |
|
203 |
let val (oracle, _, failed) = st |
|
204 |
in ((oracle, true, failed), seen') end) |
|
205 |
end); |
|
206 |
in ((oracle orelse not (null oracles), unfinished, failed), seen) end; |
|
30712 | 207 |
val (oracle, unfinished, failed) = #1 (fold status bodies ((false, false, false), Inttab.empty)); |
30711 | 208 |
in {oracle = oracle, unfinished = unfinished, failed = failed} end; |
209 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
210 |
|
28815 | 211 |
(* proof body *) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
212 |
|
29269
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
29265
diff
changeset
|
213 |
val oracle_ord = prod_ord fast_string_ord TermOrd.fast_term_ord; |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
214 |
fun thm_ord ((i, _): pthm, (j, _)) = int_ord (j, i); |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
215 |
|
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
216 |
val merge_oracles = OrdList.union oracle_ord; |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
217 |
val merge_thms = OrdList.union thm_ord; |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
218 |
|
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
219 |
val all_oracles_of = |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
220 |
let |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
221 |
fun collect (PBody {oracles, thms, ...}) = thms |> fold (fn (i, (_, _, body)) => fn (x, seen) => |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
222 |
if Inttab.defined seen i then (x, seen) |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
223 |
else |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
224 |
let |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
225 |
val body' = Future.join body; |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
226 |
val (x', seen') = collect body' (x, Inttab.update (i, ()) seen); |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
227 |
in (merge_oracles oracles x', seen') end); |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
228 |
in fn body => #1 (collect body ([], Inttab.empty)) end; |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
229 |
|
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
230 |
fun approximate_proof_body prf = |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
231 |
let |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
232 |
val (oracles, thms) = fold_proof_atoms false |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
233 |
(fn Oracle (s, prop, _) => apfst (cons (s, prop)) |
28815 | 234 |
| PThm (i, ((name, prop, _), body)) => apsnd (cons (i, (name, prop, body))) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
235 |
| _ => I) [prf] ([], []); |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
236 |
in |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
237 |
PBody |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
238 |
{oracles = OrdList.make oracle_ord oracles, |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
239 |
thms = OrdList.make thm_ord thms, |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
240 |
proof = prf} |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
241 |
end; |
11519 | 242 |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
243 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
244 |
(***** proof objects with different levels of detail *****) |
11519 | 245 |
|
15531 | 246 |
fun (prf %> t) = prf % SOME t; |
11519 | 247 |
|
15570 | 248 |
val proof_combt = Library.foldl (op %>); |
249 |
val proof_combt' = Library.foldl (op %); |
|
250 |
val proof_combP = Library.foldl (op %%); |
|
11519 | 251 |
|
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
252 |
fun strip_combt prf = |
11615 | 253 |
let fun stripc (prf % t, ts) = stripc (prf, t::ts) |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
254 |
| stripc x = x |
11519 | 255 |
in stripc (prf, []) end; |
256 |
||
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
257 |
fun strip_combP prf = |
11615 | 258 |
let fun stripc (prf %% prf', prfs) = stripc (prf, prf'::prfs) |
11519 | 259 |
| stripc x = x |
260 |
in stripc (prf, []) end; |
|
261 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
262 |
fun strip_thm (body as PBody {proof, ...}) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
263 |
(case strip_combt (fst (strip_combP proof)) of |
29635
31d14e9fa0da
proof_body: turned lazy into future -- ensures that body is fulfilled eventually, without explicit force;
wenzelm
parents:
29270
diff
changeset
|
264 |
(PThm (_, (_, body')), _) => Future.join body' |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
265 |
| _ => body); |
11519 | 266 |
|
23178 | 267 |
val mk_Abst = fold_rev (fn (s, T:typ) => fn prf => Abst (s, NONE, prf)); |
15531 | 268 |
fun mk_AbsP (i, prf) = funpow i (fn prf => AbsP ("H", NONE, prf)) prf; |
11519 | 269 |
|
20000 | 270 |
fun apsome f NONE = raise SAME |
271 |
| apsome f (SOME x) = (case f x of NONE => raise SAME | some => some); |
|
272 |
||
15531 | 273 |
fun apsome' f NONE = raise SAME |
274 |
| apsome' f (SOME x) = SOME (f x); |
|
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
275 |
|
20000 | 276 |
fun map_proof_terms_option f g = |
277 |
let |
|
278 |
fun map_typs (T :: Ts) = |
|
279 |
(case g T of |
|
280 |
NONE => T :: map_typs Ts |
|
281 |
| SOME T' => T' :: (map_typs Ts handle SAME => Ts)) |
|
282 |
| map_typs [] = raise SAME; |
|
283 |
||
284 |
fun mapp (Abst (s, T, prf)) = (Abst (s, apsome g T, mapph prf) |
|
285 |
handle SAME => Abst (s, T, mapp prf)) |
|
286 |
| mapp (AbsP (s, t, prf)) = (AbsP (s, apsome f t, mapph prf) |
|
287 |
handle SAME => AbsP (s, t, mapp prf)) |
|
288 |
| mapp (prf % t) = (mapp prf % (apsome f t handle SAME => t) |
|
289 |
handle SAME => prf % apsome f t) |
|
290 |
| mapp (prf1 %% prf2) = (mapp prf1 %% mapph prf2 |
|
291 |
handle SAME => prf1 %% mapp prf2) |
|
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
292 |
| mapp (PAxm (a, prop, SOME Ts)) = PAxm (a, prop, SOME (map_typs Ts)) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
293 |
| mapp (Oracle (a, prop, SOME Ts)) = Oracle (a, prop, SOME (map_typs Ts)) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
294 |
| mapp (Promise (i, prop, Ts)) = Promise (i, prop, map_typs Ts) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
295 |
| mapp (PThm (i, ((a, prop, SOME Ts), body))) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
296 |
PThm (i, ((a, prop, SOME (map_typs Ts)), body)) |
20000 | 297 |
| mapp _ = raise SAME |
298 |
and mapph prf = (mapp prf handle SAME => prf) |
|
299 |
||
300 |
in mapph end; |
|
301 |
||
22662 | 302 |
fun same eq f x = |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
303 |
let val x' = f x |
22662 | 304 |
in if eq (x, x') then raise SAME else x' end; |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
305 |
|
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
306 |
fun map_proof_terms f g = |
20000 | 307 |
map_proof_terms_option |
22662 | 308 |
(fn t => SOME (same (op =) f t) handle SAME => NONE) |
309 |
(fn T => SOME (same (op =) g T) handle SAME => NONE); |
|
11519 | 310 |
|
20147 | 311 |
fun fold_proof_terms f g (Abst (_, SOME T, prf)) = g T #> fold_proof_terms f g prf |
312 |
| fold_proof_terms f g (Abst (_, NONE, prf)) = fold_proof_terms f g prf |
|
313 |
| fold_proof_terms f g (AbsP (_, SOME t, prf)) = f t #> fold_proof_terms f g prf |
|
314 |
| fold_proof_terms f g (AbsP (_, NONE, prf)) = fold_proof_terms f g prf |
|
315 |
| fold_proof_terms f g (prf % SOME t) = fold_proof_terms f g prf #> f t |
|
316 |
| fold_proof_terms f g (prf % NONE) = fold_proof_terms f g prf |
|
317 |
| fold_proof_terms f g (prf1 %% prf2) = |
|
318 |
fold_proof_terms f g prf1 #> fold_proof_terms f g prf2 |
|
20159 | 319 |
| fold_proof_terms _ g (PAxm (_, _, SOME Ts)) = fold g Ts |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
320 |
| fold_proof_terms _ g (Oracle (_, _, SOME Ts)) = fold g Ts |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
321 |
| fold_proof_terms _ g (Promise (_, _, Ts)) = fold g Ts |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
322 |
| fold_proof_terms _ g (PThm (_, ((_, _, SOME Ts), _))) = fold g Ts |
20147 | 323 |
| fold_proof_terms _ _ _ = I; |
11519 | 324 |
|
20300 | 325 |
fun maxidx_proof prf = fold_proof_terms Term.maxidx_term Term.maxidx_typ prf; |
12868 | 326 |
|
13744 | 327 |
fun size_of_proof (Abst (_, _, prf)) = 1 + size_of_proof prf |
13749 | 328 |
| size_of_proof (AbsP (_, t, prf)) = 1 + size_of_proof prf |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
329 |
| size_of_proof (prf % _) = 1 + size_of_proof prf |
13744 | 330 |
| size_of_proof (prf1 %% prf2) = size_of_proof prf1 + size_of_proof prf2 |
331 |
| size_of_proof _ = 1; |
|
332 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
333 |
fun change_type opTs (PAxm (name, prop, _)) = PAxm (name, prop, opTs) |
12907
27e6d344d724
New function change_type for changing type assignments of theorems,
berghofe
parents:
12890
diff
changeset
|
334 |
| change_type opTs (Oracle (name, prop, _)) = Oracle (name, prop, opTs) |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
335 |
| change_type opTs (Promise _) = error "change_type: unexpected promise" |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
336 |
| change_type opTs (PThm (i, ((name, prop, _), body))) = PThm (i, ((name, prop, opTs), body)) |
12907
27e6d344d724
New function change_type for changing type assignments of theorems,
berghofe
parents:
12890
diff
changeset
|
337 |
| change_type _ prf = prf; |
27e6d344d724
New function change_type for changing type assignments of theorems,
berghofe
parents:
12890
diff
changeset
|
338 |
|
11519 | 339 |
|
340 |
(***** utilities *****) |
|
341 |
||
342 |
fun strip_abs (_::Ts) (Abs (_, _, t)) = strip_abs Ts t |
|
343 |
| strip_abs _ t = t; |
|
344 |
||
15570 | 345 |
fun mk_abs Ts t = Library.foldl (fn (t', T) => Abs ("", T, t')) (t, Ts); |
11519 | 346 |
|
347 |
||
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
348 |
(*Abstraction of a proof term over its occurrences of v, |
11519 | 349 |
which must contain no loose bound variables. |
350 |
The resulting proof term is ready to become the body of an Abst.*) |
|
351 |
||
352 |
fun prf_abstract_over v = |
|
353 |
let |
|
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
354 |
fun abst' lev u = if v aconv u then Bound lev else |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
355 |
(case u of |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
356 |
Abs (a, T, t) => Abs (a, T, abst' (lev + 1) t) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
357 |
| f $ t => (abst' lev f $ absth' lev t handle SAME => f $ abst' lev t) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
358 |
| _ => raise SAME) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
359 |
and absth' lev t = (abst' lev t handle SAME => t); |
11519 | 360 |
|
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
361 |
fun abst lev (AbsP (a, t, prf)) = |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
362 |
(AbsP (a, apsome' (abst' lev) t, absth lev prf) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
363 |
handle SAME => AbsP (a, t, abst lev prf)) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
364 |
| abst lev (Abst (a, T, prf)) = Abst (a, T, abst (lev + 1) prf) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
365 |
| abst lev (prf1 %% prf2) = (abst lev prf1 %% absth lev prf2 |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
366 |
handle SAME => prf1 %% abst lev prf2) |
15570 | 367 |
| abst lev (prf % t) = (abst lev prf % Option.map (absth' lev) t |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
368 |
handle SAME => prf % apsome' (abst' lev) t) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
369 |
| abst _ _ = raise SAME |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
370 |
and absth lev prf = (abst lev prf handle SAME => prf) |
11519 | 371 |
|
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
372 |
in absth 0 end; |
11519 | 373 |
|
374 |
||
375 |
(*increments a proof term's non-local bound variables |
|
376 |
required when moving a proof term within abstractions |
|
377 |
inc is increment for bound variables |
|
378 |
lev is level at which a bound variable is considered 'loose'*) |
|
379 |
||
380 |
fun incr_bv' inct tlev t = incr_bv (inct, tlev, t); |
|
381 |
||
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
382 |
fun prf_incr_bv' incP inct Plev tlev (PBound i) = |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
383 |
if i >= Plev then PBound (i+incP) else raise SAME |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
384 |
| prf_incr_bv' incP inct Plev tlev (AbsP (a, t, body)) = |
22662 | 385 |
(AbsP (a, apsome' (same (op =) (incr_bv' inct tlev)) t, |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
386 |
prf_incr_bv incP inct (Plev+1) tlev body) handle SAME => |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
387 |
AbsP (a, t, prf_incr_bv' incP inct (Plev+1) tlev body)) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
388 |
| prf_incr_bv' incP inct Plev tlev (Abst (a, T, body)) = |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
389 |
Abst (a, T, prf_incr_bv' incP inct Plev (tlev+1) body) |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
390 |
| prf_incr_bv' incP inct Plev tlev (prf %% prf') = |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
391 |
(prf_incr_bv' incP inct Plev tlev prf %% prf_incr_bv incP inct Plev tlev prf' |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
392 |
handle SAME => prf %% prf_incr_bv' incP inct Plev tlev prf') |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
393 |
| prf_incr_bv' incP inct Plev tlev (prf % t) = |
15570 | 394 |
(prf_incr_bv' incP inct Plev tlev prf % Option.map (incr_bv' inct tlev) t |
22662 | 395 |
handle SAME => prf % apsome' (same (op =) (incr_bv' inct tlev)) t) |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
396 |
| prf_incr_bv' _ _ _ _ _ = raise SAME |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
397 |
and prf_incr_bv incP inct Plev tlev prf = |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
398 |
(prf_incr_bv' incP inct Plev tlev prf handle SAME => prf); |
11519 | 399 |
|
400 |
fun incr_pboundvars 0 0 prf = prf |
|
401 |
| incr_pboundvars incP inct prf = prf_incr_bv incP inct 0 0 prf; |
|
402 |
||
403 |
||
11615 | 404 |
fun prf_loose_bvar1 (prf1 %% prf2) k = prf_loose_bvar1 prf1 k orelse prf_loose_bvar1 prf2 k |
15531 | 405 |
| prf_loose_bvar1 (prf % SOME t) k = prf_loose_bvar1 prf k orelse loose_bvar1 (t, k) |
406 |
| prf_loose_bvar1 (_ % NONE) _ = true |
|
407 |
| prf_loose_bvar1 (AbsP (_, SOME t, prf)) k = loose_bvar1 (t, k) orelse prf_loose_bvar1 prf k |
|
408 |
| prf_loose_bvar1 (AbsP (_, NONE, _)) k = true |
|
11519 | 409 |
| prf_loose_bvar1 (Abst (_, _, prf)) k = prf_loose_bvar1 prf (k+1) |
410 |
| prf_loose_bvar1 _ _ = false; |
|
411 |
||
412 |
fun prf_loose_Pbvar1 (PBound i) k = i = k |
|
11615 | 413 |
| prf_loose_Pbvar1 (prf1 %% prf2) k = prf_loose_Pbvar1 prf1 k orelse prf_loose_Pbvar1 prf2 k |
414 |
| prf_loose_Pbvar1 (prf % _) k = prf_loose_Pbvar1 prf k |
|
11519 | 415 |
| prf_loose_Pbvar1 (AbsP (_, _, prf)) k = prf_loose_Pbvar1 prf (k+1) |
416 |
| prf_loose_Pbvar1 (Abst (_, _, prf)) k = prf_loose_Pbvar1 prf k |
|
417 |
| prf_loose_Pbvar1 _ _ = false; |
|
418 |
||
12279 | 419 |
fun prf_add_loose_bnos plev tlev (PBound i) (is, js) = |
17492 | 420 |
if i < plev then (is, js) else (insert (op =) (i-plev) is, js) |
12279 | 421 |
| prf_add_loose_bnos plev tlev (prf1 %% prf2) p = |
422 |
prf_add_loose_bnos plev tlev prf2 |
|
423 |
(prf_add_loose_bnos plev tlev prf1 p) |
|
424 |
| prf_add_loose_bnos plev tlev (prf % opt) (is, js) = |
|
425 |
prf_add_loose_bnos plev tlev prf (case opt of |
|
17492 | 426 |
NONE => (is, insert (op =) ~1 js) |
15531 | 427 |
| SOME t => (is, add_loose_bnos (t, tlev, js))) |
12279 | 428 |
| prf_add_loose_bnos plev tlev (AbsP (_, opt, prf)) (is, js) = |
429 |
prf_add_loose_bnos (plev+1) tlev prf (case opt of |
|
17492 | 430 |
NONE => (is, insert (op =) ~1 js) |
15531 | 431 |
| SOME t => (is, add_loose_bnos (t, tlev, js))) |
12279 | 432 |
| prf_add_loose_bnos plev tlev (Abst (_, _, prf)) p = |
433 |
prf_add_loose_bnos plev (tlev+1) prf p |
|
434 |
| prf_add_loose_bnos _ _ _ _ = ([], []); |
|
435 |
||
11519 | 436 |
|
437 |
(**** substitutions ****) |
|
438 |
||
20509 | 439 |
fun del_conflicting_tvars envT T = TermSubst.instantiateT |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19357
diff
changeset
|
440 |
(map_filter (fn ixnS as (_, S) => |
26328 | 441 |
(Type.lookup envT ixnS; NONE) handle TYPE _ => |
29270
0eade173f77e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
29269
diff
changeset
|
442 |
SOME (ixnS, TFree ("'dummy", S))) (OldTerm.typ_tvars T)) T; |
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
443 |
|
20509 | 444 |
fun del_conflicting_vars env t = TermSubst.instantiate |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19357
diff
changeset
|
445 |
(map_filter (fn ixnS as (_, S) => |
26328 | 446 |
(Type.lookup (type_env env) ixnS; NONE) handle TYPE _ => |
29270
0eade173f77e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
29269
diff
changeset
|
447 |
SOME (ixnS, TFree ("'dummy", S))) (OldTerm.term_tvars t), |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19357
diff
changeset
|
448 |
map_filter (fn Var (ixnT as (_, T)) => |
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
449 |
(Envir.lookup (env, ixnT); NONE) handle TYPE _ => |
29265
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents:
29261
diff
changeset
|
450 |
SOME (ixnT, Free ("dummy", T))) (OldTerm.term_vars t)) t; |
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
451 |
|
11519 | 452 |
fun norm_proof env = |
453 |
let |
|
12497 | 454 |
val envT = type_env env; |
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
455 |
fun msg s = warning ("type conflict in norm_proof:\n" ^ s); |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
456 |
fun htype f t = f env t handle TYPE (s, _, _) => |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
457 |
(msg s; f env (del_conflicting_vars env t)); |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
458 |
fun htypeT f T = f envT T handle TYPE (s, _, _) => |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
459 |
(msg s; f envT (del_conflicting_tvars envT T)); |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
460 |
fun htypeTs f Ts = f envT Ts handle TYPE (s, _, _) => |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
461 |
(msg s; f envT (map (del_conflicting_tvars envT) Ts)); |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
462 |
fun norm (Abst (s, T, prf)) = (Abst (s, apsome' (htypeT norm_type_same) T, normh prf) |
11519 | 463 |
handle SAME => Abst (s, T, norm prf)) |
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
464 |
| norm (AbsP (s, t, prf)) = (AbsP (s, apsome' (htype norm_term_same) t, normh prf) |
11519 | 465 |
handle SAME => AbsP (s, t, norm prf)) |
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
466 |
| norm (prf % t) = (norm prf % Option.map (htype norm_term) t |
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
467 |
handle SAME => prf % apsome' (htype norm_term_same) t) |
11615 | 468 |
| norm (prf1 %% prf2) = (norm prf1 %% normh prf2 |
469 |
handle SAME => prf1 %% norm prf2) |
|
18316
4b62e0cb3aa8
Improved norm_proof to handle proofs containing term (type) variables
berghofe
parents:
18030
diff
changeset
|
470 |
| norm (PAxm (s, prop, Ts)) = PAxm (s, prop, apsome' (htypeTs norm_types_same) Ts) |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
471 |
| norm (Oracle (s, prop, Ts)) = Oracle (s, prop, apsome' (htypeTs norm_types_same) Ts) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
472 |
| norm (Promise (i, prop, Ts)) = Promise (i, prop, htypeTs norm_types_same Ts) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
473 |
| norm (PThm (i, ((s, t, Ts), body))) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
474 |
PThm (i, ((s, t, apsome' (htypeTs norm_types_same) Ts), body)) |
11519 | 475 |
| norm _ = raise SAME |
476 |
and normh prf = (norm prf handle SAME => prf); |
|
477 |
in normh end; |
|
478 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
479 |
|
11519 | 480 |
(***** Remove some types in proof term (to save space) *****) |
481 |
||
482 |
fun remove_types (Abs (s, _, t)) = Abs (s, dummyT, remove_types t) |
|
483 |
| remove_types (t $ u) = remove_types t $ remove_types u |
|
484 |
| remove_types (Const (s, _)) = Const (s, dummyT) |
|
485 |
| remove_types t = t; |
|
486 |
||
487 |
fun remove_types_env (Envir.Envir {iTs, asol, maxidx}) = |
|
15797 | 488 |
Envir.Envir {iTs = iTs, asol = Vartab.map (apsnd remove_types) asol, |
489 |
maxidx = maxidx}; |
|
11519 | 490 |
|
491 |
fun norm_proof' env prf = norm_proof (remove_types_env env) prf; |
|
492 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
493 |
|
11519 | 494 |
(**** substitution of bound variables ****) |
495 |
||
496 |
fun prf_subst_bounds args prf = |
|
497 |
let |
|
498 |
val n = length args; |
|
499 |
fun subst' lev (Bound i) = |
|
500 |
(if i<lev then raise SAME (*var is locally bound*) |
|
30146 | 501 |
else incr_boundvars lev (nth args (i-lev)) |
502 |
handle Subscript => Bound (i-n)) (*loose: change it*) |
|
11519 | 503 |
| subst' lev (Abs (a, T, body)) = Abs (a, T, subst' (lev+1) body) |
504 |
| subst' lev (f $ t) = (subst' lev f $ substh' lev t |
|
505 |
handle SAME => f $ subst' lev t) |
|
506 |
| subst' _ _ = raise SAME |
|
507 |
and substh' lev t = (subst' lev t handle SAME => t); |
|
508 |
||
509 |
fun subst lev (AbsP (a, t, body)) = (AbsP (a, apsome' (subst' lev) t, substh lev body) |
|
510 |
handle SAME => AbsP (a, t, subst lev body)) |
|
511 |
| subst lev (Abst (a, T, body)) = Abst (a, T, subst (lev+1) body) |
|
11615 | 512 |
| subst lev (prf %% prf') = (subst lev prf %% substh lev prf' |
513 |
handle SAME => prf %% subst lev prf') |
|
15570 | 514 |
| subst lev (prf % t) = (subst lev prf % Option.map (substh' lev) t |
11615 | 515 |
handle SAME => prf % apsome' (subst' lev) t) |
11519 | 516 |
| subst _ _ = raise SAME |
517 |
and substh lev prf = (subst lev prf handle SAME => prf) |
|
518 |
in case args of [] => prf | _ => substh 0 prf end; |
|
519 |
||
520 |
fun prf_subst_pbounds args prf = |
|
521 |
let |
|
522 |
val n = length args; |
|
523 |
fun subst (PBound i) Plev tlev = |
|
20147 | 524 |
(if i < Plev then raise SAME (*var is locally bound*) |
30146 | 525 |
else incr_pboundvars Plev tlev (nth args (i-Plev)) |
11519 | 526 |
handle Subscript => PBound (i-n) (*loose: change it*)) |
527 |
| subst (AbsP (a, t, body)) Plev tlev = AbsP (a, t, subst body (Plev+1) tlev) |
|
528 |
| subst (Abst (a, T, body)) Plev tlev = Abst (a, T, subst body Plev (tlev+1)) |
|
11615 | 529 |
| subst (prf %% prf') Plev tlev = (subst prf Plev tlev %% substh prf' Plev tlev |
530 |
handle SAME => prf %% subst prf' Plev tlev) |
|
531 |
| subst (prf % t) Plev tlev = subst prf Plev tlev % t |
|
11519 | 532 |
| subst prf _ _ = raise SAME |
533 |
and substh prf Plev tlev = (subst prf Plev tlev handle SAME => prf) |
|
534 |
in case args of [] => prf | _ => substh prf 0 0 end; |
|
535 |
||
536 |
||
537 |
(**** Freezing and thawing of variables in proof terms ****) |
|
538 |
||
539 |
fun frzT names = |
|
17325 | 540 |
map_type_tvar (fn (ixn, xs) => TFree ((the o AList.lookup (op =) names) ixn, xs)); |
11519 | 541 |
|
542 |
fun thawT names = |
|
17325 | 543 |
map_type_tfree (fn (s, xs) => case AList.lookup (op =) names s of |
15531 | 544 |
NONE => TFree (s, xs) |
545 |
| SOME ixn => TVar (ixn, xs)); |
|
11519 | 546 |
|
547 |
fun freeze names names' (t $ u) = |
|
548 |
freeze names names' t $ freeze names names' u |
|
549 |
| freeze names names' (Abs (s, T, t)) = |
|
550 |
Abs (s, frzT names' T, freeze names names' t) |
|
551 |
| freeze names names' (Const (s, T)) = Const (s, frzT names' T) |
|
552 |
| freeze names names' (Free (s, T)) = Free (s, frzT names' T) |
|
553 |
| freeze names names' (Var (ixn, T)) = |
|
17325 | 554 |
Free ((the o AList.lookup (op =) names) ixn, frzT names' T) |
11519 | 555 |
| freeze names names' t = t; |
556 |
||
557 |
fun thaw names names' (t $ u) = |
|
558 |
thaw names names' t $ thaw names names' u |
|
559 |
| thaw names names' (Abs (s, T, t)) = |
|
560 |
Abs (s, thawT names' T, thaw names names' t) |
|
561 |
| thaw names names' (Const (s, T)) = Const (s, thawT names' T) |
|
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
562 |
| thaw names names' (Free (s, T)) = |
11519 | 563 |
let val T' = thawT names' T |
17325 | 564 |
in case AList.lookup (op =) names s of |
15531 | 565 |
NONE => Free (s, T') |
566 |
| SOME ixn => Var (ixn, T') |
|
11519 | 567 |
end |
568 |
| thaw names names' (Var (ixn, T)) = Var (ixn, thawT names' T) |
|
569 |
| thaw names names' t = t; |
|
570 |
||
571 |
fun freeze_thaw_prf prf = |
|
572 |
let |
|
573 |
val (fs, Tfs, vs, Tvs) = fold_proof_terms |
|
20147 | 574 |
(fn t => fn (fs, Tfs, vs, Tvs) => |
29261 | 575 |
(Term.add_free_names t fs, Term.add_tfree_names t Tfs, |
576 |
Term.add_var_names t vs, Term.add_tvar_names t Tvs)) |
|
20147 | 577 |
(fn T => fn (fs, Tfs, vs, Tvs) => |
29261 | 578 |
(fs, Term.add_tfree_namesT T Tfs, |
579 |
vs, Term.add_tvar_namesT T Tvs)) |
|
20147 | 580 |
prf ([], [], [], []); |
29261 | 581 |
val names = vs ~~ Name.variant_list fs (map fst vs); |
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20000
diff
changeset
|
582 |
val names' = Tvs ~~ Name.variant_list Tfs (map fst Tvs); |
11519 | 583 |
val rnames = map swap names; |
584 |
val rnames' = map swap names'; |
|
585 |
in |
|
586 |
(map_proof_terms (freeze names names') (frzT names') prf, |
|
587 |
map_proof_terms (thaw rnames rnames') (thawT rnames')) |
|
588 |
end; |
|
589 |
||
590 |
||
591 |
(***** implication introduction *****) |
|
592 |
||
593 |
fun implies_intr_proof h prf = |
|
594 |
let |
|
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
595 |
fun abshyp i (Hyp t) = if h aconv t then PBound i else raise SAME |
11519 | 596 |
| abshyp i (Abst (s, T, prf)) = Abst (s, T, abshyp i prf) |
597 |
| abshyp i (AbsP (s, t, prf)) = AbsP (s, t, abshyp (i+1) prf) |
|
11615 | 598 |
| abshyp i (prf % t) = abshyp i prf % t |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
599 |
| abshyp i (prf1 %% prf2) = (abshyp i prf1 %% abshyph i prf2 |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
600 |
handle SAME => prf1 %% abshyp i prf2) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
601 |
| abshyp _ _ = raise SAME |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
602 |
and abshyph i prf = (abshyp i prf handle SAME => prf) |
11519 | 603 |
in |
15531 | 604 |
AbsP ("H", NONE (*h*), abshyph 0 prf) |
11519 | 605 |
end; |
606 |
||
607 |
||
608 |
(***** forall introduction *****) |
|
609 |
||
15531 | 610 |
fun forall_intr_proof x a prf = Abst (a, NONE, prf_abstract_over x prf); |
11519 | 611 |
|
612 |
||
613 |
(***** varify *****) |
|
614 |
||
615 |
fun varify_proof t fixed prf = |
|
616 |
let |
|
19304 | 617 |
val fs = Term.fold_types (Term.fold_atyps |
618 |
(fn TFree v => if member (op =) fixed v then I else insert (op =) v | _ => I)) t []; |
|
29261 | 619 |
val used = Name.context |
620 |
|> fold_types (fold_atyps (fn TVar ((a, _), _) => Name.declare a | _ => I)) t; |
|
621 |
val fmap = fs ~~ (#1 (Name.variants (map fst fs) used)); |
|
11519 | 622 |
fun thaw (f as (a, S)) = |
17314 | 623 |
(case AList.lookup (op =) fmap f of |
15531 | 624 |
NONE => TFree f |
625 |
| SOME b => TVar ((b, 0), S)); |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
626 |
in map_proof_terms (map_types (map_type_tfree thaw)) (map_type_tfree thaw) prf end; |
11519 | 627 |
|
628 |
||
629 |
local |
|
630 |
||
631 |
fun new_name (ix, (pairs,used)) = |
|
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
20000
diff
changeset
|
632 |
let val v = Name.variant used (string_of_indexname ix) |
11519 | 633 |
in ((ix, v) :: pairs, v :: used) end; |
634 |
||
17325 | 635 |
fun freeze_one alist (ix, sort) = (case AList.lookup (op =) alist ix of |
15531 | 636 |
NONE => TVar (ix, sort) |
637 |
| SOME name => TFree (name, sort)); |
|
11519 | 638 |
|
639 |
in |
|
640 |
||
641 |
fun freezeT t prf = |
|
642 |
let |
|
29270
0eade173f77e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
29269
diff
changeset
|
643 |
val used = OldTerm.it_term_types OldTerm.add_typ_tfree_names (t, []) |
0eade173f77e
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
wenzelm
parents:
29269
diff
changeset
|
644 |
and tvars = map #1 (OldTerm.it_term_types OldTerm.add_typ_tvars (t, [])); |
23178 | 645 |
val (alist, _) = List.foldr new_name ([], used) tvars; |
11519 | 646 |
in |
647 |
(case alist of |
|
648 |
[] => prf (*nothing to do!*) |
|
649 |
| _ => |
|
650 |
let val frzT = map_type_tvar (freeze_one alist) |
|
20548
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents:
20509
diff
changeset
|
651 |
in map_proof_terms (map_types frzT) frzT prf end) |
11519 | 652 |
end; |
653 |
||
654 |
end; |
|
655 |
||
656 |
||
657 |
(***** rotate assumptions *****) |
|
658 |
||
659 |
fun rotate_proof Bs Bi m prf = |
|
660 |
let |
|
661 |
val params = Term.strip_all_vars Bi; |
|
662 |
val asms = Logic.strip_imp_prems (Term.strip_all_body Bi); |
|
663 |
val i = length asms; |
|
664 |
val j = length Bs; |
|
665 |
in |
|
666 |
mk_AbsP (j+1, proof_combP (prf, map PBound |
|
23178 | 667 |
(j downto 1) @ [mk_Abst params (mk_AbsP (i, |
11519 | 668 |
proof_combP (proof_combt (PBound i, map Bound ((length params - 1) downto 0)), |
23178 | 669 |
map PBound (((i-m-1) downto 0) @ ((i-1) downto (i-m))))))])) |
11519 | 670 |
end; |
671 |
||
672 |
||
673 |
(***** permute premises *****) |
|
674 |
||
675 |
fun permute_prems_prf prems j k prf = |
|
676 |
let val n = length prems |
|
677 |
in mk_AbsP (n, proof_combP (prf, |
|
678 |
map PBound ((n-1 downto n-j) @ (k-1 downto 0) @ (n-j-1 downto k)))) |
|
679 |
end; |
|
680 |
||
681 |
||
19908 | 682 |
(***** generalization *****) |
683 |
||
20000 | 684 |
fun generalize (tfrees, frees) idx = |
685 |
map_proof_terms_option |
|
20509 | 686 |
(TermSubst.generalize_option (tfrees, frees) idx) |
687 |
(TermSubst.generalizeT_option tfrees idx); |
|
19908 | 688 |
|
689 |
||
11519 | 690 |
(***** instantiation *****) |
691 |
||
20000 | 692 |
fun instantiate (instT, inst) = |
693 |
map_proof_terms_option |
|
20509 | 694 |
(TermSubst.instantiate_option (instT, map (apsnd remove_types) inst)) |
695 |
(TermSubst.instantiateT_option instT); |
|
11519 | 696 |
|
697 |
||
698 |
(***** lifting *****) |
|
699 |
||
700 |
fun lift_proof Bi inc prop prf = |
|
701 |
let |
|
702 |
fun lift'' Us Ts t = strip_abs Ts (Logic.incr_indexes (Us, inc) (mk_abs Ts t)); |
|
703 |
||
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
704 |
fun lift' Us Ts (Abst (s, T, prf)) = |
22662 | 705 |
(Abst (s, apsome' (same (op =) (Logic.incr_tvar inc)) T, lifth' Us (dummyT::Ts) prf) |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
706 |
handle SAME => Abst (s, T, lift' Us (dummyT::Ts) prf)) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
707 |
| lift' Us Ts (AbsP (s, t, prf)) = |
22662 | 708 |
(AbsP (s, apsome' (same (op =) (lift'' Us Ts)) t, lifth' Us Ts prf) |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
709 |
handle SAME => AbsP (s, t, lift' Us Ts prf)) |
15570 | 710 |
| lift' Us Ts (prf % t) = (lift' Us Ts prf % Option.map (lift'' Us Ts) t |
22662 | 711 |
handle SAME => prf % apsome' (same (op =) (lift'' Us Ts)) t) |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
712 |
| lift' Us Ts (prf1 %% prf2) = (lift' Us Ts prf1 %% lifth' Us Ts prf2 |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
713 |
handle SAME => prf1 %% lift' Us Ts prf2) |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
714 |
| lift' _ _ (PAxm (s, prop, Ts)) = |
22662 | 715 |
PAxm (s, prop, apsome' (same (op =) (map (Logic.incr_tvar inc))) Ts) |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
716 |
| lift' _ _ (Oracle (s, prop, Ts)) = |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
717 |
Oracle (s, prop, apsome' (same (op =) (map (Logic.incr_tvar inc))) Ts) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
718 |
| lift' _ _ (Promise (i, prop, Ts)) = |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
719 |
Promise (i, prop, same (op =) (map (Logic.incr_tvar inc)) Ts) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
720 |
| lift' _ _ (PThm (i, ((s, prop, Ts), body))) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
721 |
PThm (i, ((s, prop, apsome' (same (op =) (map (Logic.incr_tvar inc))) Ts), body)) |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
722 |
| lift' _ _ _ = raise SAME |
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
723 |
and lifth' Us Ts prf = (lift' Us Ts prf handle SAME => prf); |
11519 | 724 |
|
18030 | 725 |
val ps = map (Logic.lift_all inc Bi) (Logic.strip_imp_prems prop); |
11519 | 726 |
val k = length ps; |
727 |
||
23178 | 728 |
fun mk_app b (i, j, prf) = |
11615 | 729 |
if b then (i-1, j, prf %% PBound i) else (i, j-1, prf %> Bound j); |
11519 | 730 |
|
731 |
fun lift Us bs i j (Const ("==>", _) $ A $ B) = |
|
20147 | 732 |
AbsP ("H", NONE (*A*), lift Us (true::bs) (i+1) j B) |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
733 |
| lift Us bs i j (Const ("all", _) $ Abs (a, T, t)) = |
20147 | 734 |
Abst (a, NONE (*T*), lift (T::Us) (false::bs) i (j+1) t) |
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
735 |
| lift Us bs i j _ = proof_combP (lifth' (rev Us) [] prf, |
23178 | 736 |
map (fn k => (#3 (fold_rev mk_app bs (i-1, j-1, PBound k)))) |
11519 | 737 |
(i + k - 1 downto i)); |
738 |
in |
|
739 |
mk_AbsP (k, lift [] [] 0 0 Bi) |
|
740 |
end; |
|
741 |
||
742 |
||
743 |
(***** proof by assumption *****) |
|
744 |
||
23296
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
745 |
fun mk_asm_prf t i m = |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
746 |
let |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
747 |
fun imp_prf _ i 0 = PBound i |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
748 |
| imp_prf (Const ("==>", _) $ A $ B) i m = AbsP ("H", NONE (*A*), imp_prf B (i+1) (m-1)) |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
749 |
| imp_prf _ i _ = PBound i; |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
750 |
fun all_prf (Const ("all", _) $ Abs (a, T, t)) = Abst (a, NONE (*T*), all_prf t) |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
751 |
| all_prf t = imp_prf t (~i) m |
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
752 |
in all_prf t end; |
11519 | 753 |
|
754 |
fun assumption_proof Bs Bi n prf = |
|
755 |
mk_AbsP (length Bs, proof_combP (prf, |
|
23296
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
756 |
map PBound (length Bs - 1 downto 0) @ [mk_asm_prf Bi n ~1])); |
11519 | 757 |
|
758 |
||
759 |
(***** Composition of object rule with proof state *****) |
|
760 |
||
761 |
fun flatten_params_proof i j n (Const ("==>", _) $ A $ B, k) = |
|
15531 | 762 |
AbsP ("H", NONE (*A*), flatten_params_proof (i+1) j n (B, k)) |
11519 | 763 |
| flatten_params_proof i j n (Const ("all", _) $ Abs (a, T, t), k) = |
15531 | 764 |
Abst (a, NONE (*T*), flatten_params_proof i (j+1) n (t, k)) |
11519 | 765 |
| flatten_params_proof i j n (_, k) = proof_combP (proof_combt (PBound (k+i), |
19304 | 766 |
map Bound (j-1 downto 0)), map PBound (remove (op =) (i-n) (i-1 downto 0))); |
11519 | 767 |
|
23296
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
768 |
fun bicompose_proof flatten Bs oldAs newAs A n m rprf sprf = |
11519 | 769 |
let |
770 |
val la = length newAs; |
|
771 |
val lb = length Bs; |
|
772 |
in |
|
773 |
mk_AbsP (lb+la, proof_combP (sprf, |
|
11615 | 774 |
map PBound (lb + la - 1 downto la)) %% |
23296
25f28f9c28a3
Adapted Proofterm.bicompose_proof to Larry's changes in
berghofe
parents:
23178
diff
changeset
|
775 |
proof_combP (rprf, (if n>0 then [mk_asm_prf (the A) n m] else []) @ |
18485 | 776 |
map (if flatten then flatten_params_proof 0 0 n else PBound o snd) |
777 |
(oldAs ~~ (la - 1 downto 0)))) |
|
11519 | 778 |
end; |
779 |
||
780 |
||
781 |
(***** axioms for equality *****) |
|
782 |
||
14854 | 783 |
val aT = TFree ("'a", []); |
784 |
val bT = TFree ("'b", []); |
|
11519 | 785 |
val x = Free ("x", aT); |
786 |
val y = Free ("y", aT); |
|
787 |
val z = Free ("z", aT); |
|
788 |
val A = Free ("A", propT); |
|
789 |
val B = Free ("B", propT); |
|
790 |
val f = Free ("f", aT --> bT); |
|
791 |
val g = Free ("g", aT --> bT); |
|
792 |
||
793 |
local open Logic in |
|
794 |
||
795 |
val equality_axms = |
|
796 |
[("reflexive", mk_equals (x, x)), |
|
797 |
("symmetric", mk_implies (mk_equals (x, y), mk_equals (y, x))), |
|
798 |
("transitive", list_implies ([mk_equals (x, y), mk_equals (y, z)], mk_equals (x, z))), |
|
799 |
("equal_intr", list_implies ([mk_implies (A, B), mk_implies (B, A)], mk_equals (A, B))), |
|
800 |
("equal_elim", list_implies ([mk_equals (A, B), A], B)), |
|
27330 | 801 |
("abstract_rule", mk_implies |
802 |
(all x (mk_equals (f $ x, g $ x)), mk_equals (lambda x (f $ x), lambda x (g $ x)))), |
|
803 |
("combination", list_implies |
|
804 |
([mk_equals (f, g), mk_equals (x, y)], mk_equals (f $ x, g $ y)))]; |
|
11519 | 805 |
|
806 |
val [reflexive_axm, symmetric_axm, transitive_axm, equal_intr_axm, |
|
807 |
equal_elim_axm, abstract_rule_axm, combination_axm] = |
|
26424 | 808 |
map (fn (s, t) => PAxm ("Pure." ^ s, varify t, NONE)) equality_axms; |
11519 | 809 |
|
810 |
end; |
|
811 |
||
15531 | 812 |
val reflexive = reflexive_axm % NONE; |
11519 | 813 |
|
26424 | 814 |
fun symmetric (prf as PAxm ("Pure.reflexive", _, _) % _) = prf |
15531 | 815 |
| symmetric prf = symmetric_axm % NONE % NONE %% prf; |
11519 | 816 |
|
26424 | 817 |
fun transitive _ _ (PAxm ("Pure.reflexive", _, _) % _) prf2 = prf2 |
818 |
| transitive _ _ prf1 (PAxm ("Pure.reflexive", _, _) % _) = prf1 |
|
11519 | 819 |
| transitive u (Type ("prop", [])) prf1 prf2 = |
15531 | 820 |
transitive_axm % NONE % SOME (remove_types u) % NONE %% prf1 %% prf2 |
11519 | 821 |
| transitive u T prf1 prf2 = |
15531 | 822 |
transitive_axm % NONE % NONE % NONE %% prf1 %% prf2; |
11519 | 823 |
|
824 |
fun abstract_rule x a prf = |
|
15531 | 825 |
abstract_rule_axm % NONE % NONE %% forall_intr_proof x a prf; |
11519 | 826 |
|
26424 | 827 |
fun check_comb (PAxm ("Pure.combination", _, _) % f % g % _ % _ %% prf %% _) = |
19502 | 828 |
is_some f orelse check_comb prf |
26424 | 829 |
| check_comb (PAxm ("Pure.transitive", _, _) % _ % _ % _ %% prf1 %% prf2) = |
11519 | 830 |
check_comb prf1 andalso check_comb prf2 |
26424 | 831 |
| check_comb (PAxm ("Pure.symmetric", _, _) % _ % _ %% prf) = check_comb prf |
11519 | 832 |
| check_comb _ = false; |
833 |
||
834 |
fun combination f g t u (Type (_, [T, U])) prf1 prf2 = |
|
835 |
let |
|
836 |
val f = Envir.beta_norm f; |
|
837 |
val g = Envir.beta_norm g; |
|
838 |
val prf = if check_comb prf1 then |
|
15531 | 839 |
combination_axm % NONE % NONE |
11519 | 840 |
else (case prf1 of |
26424 | 841 |
PAxm ("Pure.reflexive", _, _) % _ => |
15531 | 842 |
combination_axm %> remove_types f % NONE |
11615 | 843 |
| _ => combination_axm %> remove_types f %> remove_types g) |
11519 | 844 |
in |
845 |
(case T of |
|
11615 | 846 |
Type ("fun", _) => prf % |
11519 | 847 |
(case head_of f of |
15531 | 848 |
Abs _ => SOME (remove_types t) |
849 |
| Var _ => SOME (remove_types t) |
|
850 |
| _ => NONE) % |
|
11519 | 851 |
(case head_of g of |
15531 | 852 |
Abs _ => SOME (remove_types u) |
853 |
| Var _ => SOME (remove_types u) |
|
854 |
| _ => NONE) %% prf1 %% prf2 |
|
855 |
| _ => prf % NONE % NONE %% prf1 %% prf2) |
|
11519 | 856 |
end; |
857 |
||
858 |
fun equal_intr A B prf1 prf2 = |
|
11615 | 859 |
equal_intr_axm %> remove_types A %> remove_types B %% prf1 %% prf2; |
11519 | 860 |
|
861 |
fun equal_elim A B prf1 prf2 = |
|
11615 | 862 |
equal_elim_axm %> remove_types A %> remove_types B %% prf1 %% prf2; |
11519 | 863 |
|
864 |
||
865 |
(***** axioms and theorems *****) |
|
866 |
||
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
867 |
val proofs = ref 2; |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
868 |
|
28812
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
berghofe
parents:
28803
diff
changeset
|
869 |
fun vars_of t = map Var (rev (Term.add_vars t [])); |
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
berghofe
parents:
28803
diff
changeset
|
870 |
fun frees_of t = map Free (rev (Term.add_frees t [])); |
11519 | 871 |
|
872 |
fun test_args _ [] = true |
|
873 |
| test_args is (Bound i :: ts) = |
|
17492 | 874 |
not (member (op =) is i) andalso test_args (i :: is) ts |
11519 | 875 |
| test_args _ _ = false; |
876 |
||
877 |
fun is_fun (Type ("fun", _)) = true |
|
878 |
| is_fun (TVar _) = true |
|
879 |
| is_fun _ = false; |
|
880 |
||
881 |
fun add_funvars Ts (vs, t) = |
|
882 |
if is_fun (fastype_of1 (Ts, t)) then |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19357
diff
changeset
|
883 |
vs union map_filter (fn Var (ixn, T) => |
15531 | 884 |
if is_fun T then SOME ixn else NONE | _ => NONE) (vars_of t) |
11519 | 885 |
else vs; |
886 |
||
887 |
fun add_npvars q p Ts (vs, Const ("==>", _) $ t $ u) = |
|
888 |
add_npvars q p Ts (add_npvars q (not p) Ts (vs, t), u) |
|
889 |
| add_npvars q p Ts (vs, Const ("all", Type (_, [Type (_, [T, _]), _])) $ t) = |
|
890 |
add_npvars q p Ts (vs, if p andalso q then betapply (t, Var (("",0), T)) else t) |
|
12041 | 891 |
| add_npvars q p Ts (vs, Abs (_, T, t)) = add_npvars q p (T::Ts) (vs, t) |
892 |
| add_npvars _ _ Ts (vs, t) = add_npvars' Ts (vs, t) |
|
893 |
and add_npvars' Ts (vs, t) = (case strip_comb t of |
|
11519 | 894 |
(Var (ixn, _), ts) => if test_args [] ts then vs |
17314 | 895 |
else Library.foldl (add_npvars' Ts) |
896 |
(AList.update (op =) (ixn, |
|
897 |
Library.foldl (add_funvars Ts) ((these ooo AList.lookup) (op =) vs ixn, ts)) vs, ts) |
|
15570 | 898 |
| (Abs (_, T, u), ts) => Library.foldl (add_npvars' (T::Ts)) (vs, u :: ts) |
899 |
| (_, ts) => Library.foldl (add_npvars' Ts) (vs, ts)); |
|
11519 | 900 |
|
901 |
fun prop_vars (Const ("==>", _) $ P $ Q) = prop_vars P union prop_vars Q |
|
902 |
| prop_vars (Const ("all", _) $ Abs (_, _, t)) = prop_vars t |
|
903 |
| prop_vars t = (case strip_comb t of |
|
904 |
(Var (ixn, _), _) => [ixn] | _ => []); |
|
905 |
||
906 |
fun is_proj t = |
|
907 |
let |
|
908 |
fun is_p i t = (case strip_comb t of |
|
909 |
(Bound j, []) => false |
|
910 |
| (Bound j, ts) => j >= i orelse exists (is_p i) ts |
|
911 |
| (Abs (_, _, u), _) => is_p (i+1) u |
|
912 |
| (_, ts) => exists (is_p i) ts) |
|
913 |
in (case strip_abs_body t of |
|
914 |
Bound _ => true |
|
915 |
| t' => is_p 0 t') |
|
916 |
end; |
|
917 |
||
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
918 |
fun needed_vars prop = |
20853 | 919 |
Library.foldl (op union) |
920 |
([], map (uncurry (insert (op =))) (add_npvars true true [] ([], prop))) union |
|
11519 | 921 |
prop_vars prop; |
922 |
||
923 |
fun gen_axm_proof c name prop = |
|
924 |
let |
|
925 |
val nvs = needed_vars prop; |
|
926 |
val args = map (fn (v as Var (ixn, _)) => |
|
17492 | 927 |
if member (op =) nvs ixn then SOME v else NONE) (vars_of prop) @ |
28812
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
berghofe
parents:
28803
diff
changeset
|
928 |
map SOME (frees_of prop); |
11519 | 929 |
in |
15531 | 930 |
proof_combt' (c (name, prop, NONE), args) |
11519 | 931 |
end; |
932 |
||
933 |
val axm_proof = gen_axm_proof PAxm; |
|
17017 | 934 |
|
935 |
val dummy = Const (Term.dummy_patternN, dummyT); |
|
936 |
||
937 |
fun oracle_proof name prop = |
|
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
938 |
if ! proofs = 0 then ((name, dummy), Oracle (name, dummy, NONE)) |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
939 |
else ((name, prop), gen_axm_proof Oracle name prop); |
11519 | 940 |
|
17492 | 941 |
fun shrink_proof thy = |
942 |
let |
|
943 |
fun shrink ls lev (prf as Abst (a, T, body)) = |
|
944 |
let val (b, is, ch, body') = shrink ls (lev+1) body |
|
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
945 |
in (b, is, ch, if ch then Abst (a, T, body') else prf) end |
17492 | 946 |
| shrink ls lev (prf as AbsP (a, t, body)) = |
947 |
let val (b, is, ch, body') = shrink (lev::ls) lev body |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19357
diff
changeset
|
948 |
in (b orelse member (op =) is 0, map_filter (fn 0 => NONE | i => SOME (i-1)) is, |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
949 |
ch, if ch then AbsP (a, t, body') else prf) |
17492 | 950 |
end |
951 |
| shrink ls lev prf = |
|
952 |
let val (is, ch, _, prf') = shrink' ls lev [] [] prf |
|
953 |
in (false, is, ch, prf') end |
|
954 |
and shrink' ls lev ts prfs (prf as prf1 %% prf2) = |
|
955 |
let |
|
956 |
val p as (_, is', ch', prf') = shrink ls lev prf2; |
|
957 |
val (is, ch, ts', prf'') = shrink' ls lev ts (p::prfs) prf1 |
|
958 |
in (is union is', ch orelse ch', ts', |
|
959 |
if ch orelse ch' then prf'' %% prf' else prf) |
|
960 |
end |
|
961 |
| shrink' ls lev ts prfs (prf as prf1 % t) = |
|
962 |
let val (is, ch, (ch', t')::ts', prf') = shrink' ls lev (t::ts) prfs prf1 |
|
963 |
in (is, ch orelse ch', ts', |
|
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
964 |
if ch orelse ch' then prf' % t' else prf) end |
17492 | 965 |
| shrink' ls lev ts prfs (prf as PBound i) = |
30146 | 966 |
(if exists (fn SOME (Bound j) => lev-j <= nth ls i | _ => true) ts |
18928
042608ffa2ec
subsituted gen_duplicates / has_duplicates for duplicates whenever appropriate
haftmann
parents:
18485
diff
changeset
|
967 |
orelse has_duplicates (op =) |
042608ffa2ec
subsituted gen_duplicates / has_duplicates for duplicates whenever appropriate
haftmann
parents:
18485
diff
changeset
|
968 |
(Library.foldl (fn (js, SOME (Bound j)) => j :: js | (js, _) => js) ([], ts)) |
17492 | 969 |
orelse exists #1 prfs then [i] else [], false, map (pair false) ts, prf) |
26631
d6b6c74a8bcf
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26424
diff
changeset
|
970 |
| shrink' ls lev ts prfs (Hyp t) = ([], false, map (pair false) ts, Hyp t) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
971 |
| shrink' ls lev ts prfs MinProof = ([], false, map (pair false) ts, MinProof) |
17492 | 972 |
| shrink' ls lev ts prfs prf = |
973 |
let |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
974 |
val prop = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
975 |
(case prf of |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
976 |
PAxm (_, prop, _) => prop |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
977 |
| Oracle (_, prop, _) => prop |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
978 |
| Promise (_, prop, _) => prop |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
979 |
| PThm (_, ((_, prop, _), _)) => prop |
28319
13cb2108c2b9
added Promise constructor, which is similar to Oracle but may be replaced later;
wenzelm
parents:
27330
diff
changeset
|
980 |
| _ => error "shrink: proof not in normal form"); |
17492 | 981 |
val vs = vars_of prop; |
19012 | 982 |
val (ts', ts'') = chop (length vs) ts; |
17492 | 983 |
val insts = Library.take (length ts', map (fst o dest_Var) vs) ~~ ts'; |
984 |
val nvs = Library.foldl (fn (ixns', (ixn, ixns)) => |
|
985 |
insert (op =) ixn (case AList.lookup (op =) insts ixn of |
|
986 |
SOME (SOME t) => if is_proj t then ixns union ixns' else ixns' |
|
987 |
| _ => ixns union ixns')) |
|
988 |
(needed prop ts'' prfs, add_npvars false true [] ([], prop)); |
|
989 |
val insts' = map |
|
990 |
(fn (ixn, x as SOME _) => if member (op =) nvs ixn then (false, x) else (true, NONE) |
|
991 |
| (_, x) => (false, x)) insts |
|
992 |
in ([], false, insts' @ map (pair false) ts'', prf) end |
|
993 |
and needed (Const ("==>", _) $ t $ u) ts ((b, _, _, _)::prfs) = |
|
994 |
(if b then map (fst o dest_Var) (vars_of t) else []) union needed u ts prfs |
|
995 |
| needed (Var (ixn, _)) (_::_) _ = [ixn] |
|
996 |
| needed _ _ _ = []; |
|
997 |
in shrink end; |
|
11519 | 998 |
|
999 |
||
1000 |
(**** Simple first order matching functions for terms and proofs ****) |
|
1001 |
||
1002 |
exception PMatch; |
|
1003 |
||
1004 |
(** see pattern.ML **) |
|
1005 |
||
15570 | 1006 |
fun flt (i: int) = List.filter (fn n => n < i); |
12279 | 1007 |
|
1008 |
fun fomatch Ts tymatch j = |
|
11519 | 1009 |
let |
1010 |
fun mtch (instsp as (tyinsts, insts)) = fn |
|
1011 |
(Var (ixn, T), t) => |
|
12279 | 1012 |
if j>0 andalso not (null (flt j (loose_bnos t))) |
1013 |
then raise PMatch |
|
1014 |
else (tymatch (tyinsts, fn () => (T, fastype_of1 (Ts, t))), |
|
1015 |
(ixn, t) :: insts) |
|
11519 | 1016 |
| (Free (a, T), Free (b, U)) => |
20147 | 1017 |
if a=b then (tymatch (tyinsts, K (T, U)), insts) else raise PMatch |
11519 | 1018 |
| (Const (a, T), Const (b, U)) => |
20147 | 1019 |
if a=b then (tymatch (tyinsts, K (T, U)), insts) else raise PMatch |
11519 | 1020 |
| (f $ t, g $ u) => mtch (mtch instsp (f, g)) (t, u) |
12279 | 1021 |
| (Bound i, Bound j) => if i=j then instsp else raise PMatch |
11519 | 1022 |
| _ => raise PMatch |
1023 |
in mtch end; |
|
1024 |
||
12279 | 1025 |
fun match_proof Ts tymatch = |
11519 | 1026 |
let |
15531 | 1027 |
fun optmatch _ inst (NONE, _) = inst |
1028 |
| optmatch _ _ (SOME _, NONE) = raise PMatch |
|
1029 |
| optmatch mtch inst (SOME x, SOME y) = mtch inst (x, y) |
|
12279 | 1030 |
|
1031 |
fun matcht Ts j (pinst, tinst) (t, u) = |
|
1032 |
(pinst, fomatch Ts tymatch j tinst (t, Envir.beta_norm u)); |
|
1033 |
fun matchT (pinst, (tyinsts, insts)) p = |
|
1034 |
(pinst, (tymatch (tyinsts, K p), insts)); |
|
15570 | 1035 |
fun matchTs inst (Ts, Us) = Library.foldl (uncurry matchT) (inst, Ts ~~ Us); |
12279 | 1036 |
|
1037 |
fun mtch Ts i j (pinst, tinst) (Hyp (Var (ixn, _)), prf) = |
|
1038 |
if i = 0 andalso j = 0 then ((ixn, prf) :: pinst, tinst) |
|
1039 |
else (case apfst (flt i) (apsnd (flt j) |
|
1040 |
(prf_add_loose_bnos 0 0 prf ([], []))) of |
|
1041 |
([], []) => ((ixn, incr_pboundvars (~i) (~j) prf) :: pinst, tinst) |
|
1042 |
| ([], _) => if j = 0 then |
|
1043 |
((ixn, incr_pboundvars (~i) (~j) prf) :: pinst, tinst) |
|
1044 |
else raise PMatch |
|
1045 |
| _ => raise PMatch) |
|
1046 |
| mtch Ts i j inst (prf1 % opt1, prf2 % opt2) = |
|
1047 |
optmatch (matcht Ts j) (mtch Ts i j inst (prf1, prf2)) (opt1, opt2) |
|
1048 |
| mtch Ts i j inst (prf1 %% prf2, prf1' %% prf2') = |
|
1049 |
mtch Ts i j (mtch Ts i j inst (prf1, prf1')) (prf2, prf2') |
|
1050 |
| mtch Ts i j inst (Abst (_, opT, prf1), Abst (_, opU, prf2)) = |
|
18485 | 1051 |
mtch (the_default dummyT opU :: Ts) i (j+1) |
12279 | 1052 |
(optmatch matchT inst (opT, opU)) (prf1, prf2) |
1053 |
| mtch Ts i j inst (prf1, Abst (_, opU, prf2)) = |
|
18485 | 1054 |
mtch (the_default dummyT opU :: Ts) i (j+1) inst |
12279 | 1055 |
(incr_pboundvars 0 1 prf1 %> Bound 0, prf2) |
1056 |
| mtch Ts i j inst (AbsP (_, opt, prf1), AbsP (_, opu, prf2)) = |
|
1057 |
mtch Ts (i+1) j (optmatch (matcht Ts j) inst (opt, opu)) (prf1, prf2) |
|
1058 |
| mtch Ts i j inst (prf1, AbsP (_, _, prf2)) = |
|
1059 |
mtch Ts (i+1) j inst (incr_pboundvars 1 0 prf1 %% PBound 0, prf2) |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1060 |
| mtch Ts i j inst (PAxm (s1, _, opTs), PAxm (s2, _, opUs)) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1061 |
if s1 = s2 then optmatch matchTs inst (opTs, opUs) |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1062 |
else raise PMatch |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1063 |
| mtch Ts i j inst (PThm (_, ((name1, prop1, opTs), _)), PThm (_, ((name2, prop2, opUs), _))) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1064 |
if name1 = name2 andalso prop1 = prop2 then |
12279 | 1065 |
optmatch matchTs inst (opTs, opUs) |
11519 | 1066 |
else raise PMatch |
12279 | 1067 |
| mtch _ _ _ inst (PBound i, PBound j) = if i = j then inst else raise PMatch |
1068 |
| mtch _ _ _ _ _ = raise PMatch |
|
1069 |
in mtch Ts 0 0 end; |
|
11519 | 1070 |
|
1071 |
fun prf_subst (pinst, (tyinsts, insts)) = |
|
1072 |
let |
|
15797 | 1073 |
val substT = Envir.typ_subst_TVars tyinsts; |
11519 | 1074 |
|
17325 | 1075 |
fun subst' lev (t as Var (ixn, _)) = (case AList.lookup (op =) insts ixn of |
15531 | 1076 |
NONE => t |
1077 |
| SOME u => incr_boundvars lev u) |
|
11519 | 1078 |
| subst' lev (Const (s, T)) = Const (s, substT T) |
1079 |
| subst' lev (Free (s, T)) = Free (s, substT T) |
|
1080 |
| subst' lev (Abs (a, T, body)) = Abs (a, substT T, subst' (lev+1) body) |
|
1081 |
| subst' lev (f $ t) = subst' lev f $ subst' lev t |
|
1082 |
| subst' _ t = t; |
|
1083 |
||
1084 |
fun subst plev tlev (AbsP (a, t, body)) = |
|
15570 | 1085 |
AbsP (a, Option.map (subst' tlev) t, subst (plev+1) tlev body) |
11519 | 1086 |
| subst plev tlev (Abst (a, T, body)) = |
15570 | 1087 |
Abst (a, Option.map substT T, subst plev (tlev+1) body) |
11615 | 1088 |
| subst plev tlev (prf %% prf') = subst plev tlev prf %% subst plev tlev prf' |
15570 | 1089 |
| subst plev tlev (prf % t) = subst plev tlev prf % Option.map (subst' tlev) t |
17325 | 1090 |
| subst plev tlev (prf as Hyp (Var (ixn, _))) = (case AList.lookup (op =) pinst ixn of |
15531 | 1091 |
NONE => prf |
1092 |
| SOME prf' => incr_pboundvars plev tlev prf') |
|
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1093 |
| subst _ _ (PAxm (id, prop, Ts)) = PAxm (id, prop, Option.map (map substT) Ts) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1094 |
| subst _ _ (Oracle (id, prop, Ts)) = Oracle (id, prop, Option.map (map substT) Ts) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1095 |
| subst _ _ (Promise (i, prop, Ts)) = Promise (i, prop, (map substT) Ts) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1096 |
| subst _ _ (PThm (i, ((id, prop, Ts), body))) = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1097 |
PThm (i, ((id, prop, Option.map (map substT) Ts), body)) |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1098 |
| subst _ _ t = t; |
11519 | 1099 |
in subst 0 0 end; |
1100 |
||
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
1101 |
(*A fast unification filter: true unless the two terms cannot be unified. |
12871
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1102 |
Terms must be NORMAL. Treats all Vars as distinct. *) |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1103 |
fun could_unify prf1 prf2 = |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1104 |
let |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1105 |
fun matchrands (prf1 %% prf2) (prf1' %% prf2') = |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1106 |
could_unify prf2 prf2' andalso matchrands prf1 prf1' |
15531 | 1107 |
| matchrands (prf % SOME t) (prf' % SOME t') = |
12871
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1108 |
Term.could_unify (t, t') andalso matchrands prf prf' |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1109 |
| matchrands (prf % _) (prf' % _) = matchrands prf prf' |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1110 |
| matchrands _ _ = true |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1111 |
|
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1112 |
fun head_of (prf %% _) = head_of prf |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1113 |
| head_of (prf % _) = head_of prf |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1114 |
| head_of prf = prf |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1115 |
|
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1116 |
in case (head_of prf1, head_of prf2) of |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1117 |
(_, Hyp (Var _)) => true |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1118 |
| (Hyp (Var _), _) => true |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1119 |
| (PAxm (a, _, _), PAxm (b, _, _)) => a = b andalso matchrands prf1 prf2 |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1120 |
| (PThm (_, ((a, propa, _), _)), PThm (_, ((b, propb, _), _))) => |
12871
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1121 |
a = b andalso propa = propb andalso matchrands prf1 prf2 |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1122 |
| (PBound i, PBound j) => i = j andalso matchrands prf1 prf2 |
12871
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1123 |
| (AbsP _, _) => true (*because of possible eta equality*) |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1124 |
| (Abst _, _) => true |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1125 |
| (_, AbsP _) => true |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1126 |
| (_, Abst _) => true |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1127 |
| _ => false |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1128 |
end; |
21486a0557d1
Added function could_unify to speed up rewriting of proof terms.
berghofe
parents:
12868
diff
changeset
|
1129 |
|
28329
e6a5fa9f1e41
added conditional add_oracles, keep oracles_of_proof private;
wenzelm
parents:
28319
diff
changeset
|
1130 |
|
11519 | 1131 |
(**** rewriting on proof terms ****) |
1132 |
||
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1133 |
val skel0 = PBound 0; |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1134 |
|
12279 | 1135 |
fun rewrite_prf tymatch (rules, procs) prf = |
11519 | 1136 |
let |
15531 | 1137 |
fun rew _ (Abst (_, _, body) % SOME t) = SOME (prf_subst_bounds [t] body, skel0) |
1138 |
| rew _ (AbsP (_, _, body) %% prf) = SOME (prf_subst_pbounds [prf] body, skel0) |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1139 |
| rew Ts prf = (case get_first (fn r => r Ts prf) procs of |
15531 | 1140 |
SOME prf' => SOME (prf', skel0) |
1141 |
| NONE => get_first (fn (prf1, prf2) => SOME (prf_subst |
|
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1142 |
(match_proof Ts tymatch ([], (Vartab.empty, [])) (prf1, prf)) prf2, prf2) |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1143 |
handle PMatch => NONE) (filter (could_unify prf o fst) rules)); |
11519 | 1144 |
|
11615 | 1145 |
fun rew0 Ts (prf as AbsP (_, _, prf' %% PBound 0)) = |
11519 | 1146 |
if prf_loose_Pbvar1 prf' 0 then rew Ts prf |
1147 |
else |
|
1148 |
let val prf'' = incr_pboundvars (~1) 0 prf' |
|
19502 | 1149 |
in SOME (the_default (prf'', skel0) (rew Ts prf'')) end |
15531 | 1150 |
| rew0 Ts (prf as Abst (_, _, prf' % SOME (Bound 0))) = |
11519 | 1151 |
if prf_loose_bvar1 prf' 0 then rew Ts prf |
1152 |
else |
|
1153 |
let val prf'' = incr_pboundvars 0 (~1) prf' |
|
19502 | 1154 |
in SOME (the_default (prf'', skel0) (rew Ts prf'')) end |
11519 | 1155 |
| rew0 Ts prf = rew Ts prf; |
1156 |
||
15531 | 1157 |
fun rew1 _ (Hyp (Var _)) _ = NONE |
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1158 |
| rew1 Ts skel prf = (case rew2 Ts skel prf of |
15531 | 1159 |
SOME prf1 => (case rew0 Ts prf1 of |
19502 | 1160 |
SOME (prf2, skel') => SOME (the_default prf2 (rew1 Ts skel' prf2)) |
15531 | 1161 |
| NONE => SOME prf1) |
1162 |
| NONE => (case rew0 Ts prf of |
|
19502 | 1163 |
SOME (prf1, skel') => SOME (the_default prf1 (rew1 Ts skel' prf1)) |
15531 | 1164 |
| NONE => NONE)) |
11519 | 1165 |
|
15531 | 1166 |
and rew2 Ts skel (prf % SOME t) = (case prf of |
11519 | 1167 |
Abst (_, _, body) => |
1168 |
let val prf' = prf_subst_bounds [t] body |
|
19502 | 1169 |
in SOME (the_default prf' (rew2 Ts skel0 prf')) end |
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1170 |
| _ => (case rew1 Ts (case skel of skel' % _ => skel' | _ => skel0) prf of |
15531 | 1171 |
SOME prf' => SOME (prf' % SOME t) |
1172 |
| NONE => NONE)) |
|
15570 | 1173 |
| rew2 Ts skel (prf % NONE) = Option.map (fn prf' => prf' % NONE) |
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1174 |
(rew1 Ts (case skel of skel' % _ => skel' | _ => skel0) prf) |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1175 |
| rew2 Ts skel (prf1 %% prf2) = (case prf1 of |
11519 | 1176 |
AbsP (_, _, body) => |
1177 |
let val prf' = prf_subst_pbounds [prf2] body |
|
19502 | 1178 |
in SOME (the_default prf' (rew2 Ts skel0 prf')) end |
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1179 |
| _ => |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1180 |
let val (skel1, skel2) = (case skel of |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1181 |
skel1 %% skel2 => (skel1, skel2) |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1182 |
| _ => (skel0, skel0)) |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1183 |
in case rew1 Ts skel1 prf1 of |
15531 | 1184 |
SOME prf1' => (case rew1 Ts skel2 prf2 of |
1185 |
SOME prf2' => SOME (prf1' %% prf2') |
|
1186 |
| NONE => SOME (prf1' %% prf2)) |
|
1187 |
| NONE => (case rew1 Ts skel2 prf2 of |
|
1188 |
SOME prf2' => SOME (prf1 %% prf2') |
|
1189 |
| NONE => NONE) |
|
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1190 |
end) |
19502 | 1191 |
| rew2 Ts skel (Abst (s, T, prf)) = (case rew1 (the_default dummyT T :: Ts) |
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1192 |
(case skel of Abst (_, _, skel') => skel' | _ => skel0) prf of |
15531 | 1193 |
SOME prf' => SOME (Abst (s, T, prf')) |
1194 |
| NONE => NONE) |
|
13102
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1195 |
| rew2 Ts skel (AbsP (s, t, prf)) = (case rew1 Ts |
b6f8aae5f152
Added skeletons to speed up rewriting on proof terms.
berghofe
parents:
12923
diff
changeset
|
1196 |
(case skel of AbsP (_, _, skel') => skel' | _ => skel0) prf of |
15531 | 1197 |
SOME prf' => SOME (AbsP (s, t, prf')) |
1198 |
| NONE => NONE) |
|
1199 |
| rew2 _ _ _ = NONE |
|
11519 | 1200 |
|
19502 | 1201 |
in the_default prf (rew1 [] skel0 prf) end; |
11519 | 1202 |
|
17203 | 1203 |
fun rewrite_proof thy = rewrite_prf (fn (tyenv, f) => |
1204 |
Sign.typ_match thy (f ()) tyenv handle Type.TYPE_MATCH => raise PMatch); |
|
11519 | 1205 |
|
11715
592923615f77
Tuned several functions to improve sharing of unchanged subproofs.
berghofe
parents:
11652
diff
changeset
|
1206 |
fun rewrite_proof_notypes rews = rewrite_prf fst rews; |
11615 | 1207 |
|
16940 | 1208 |
|
11519 | 1209 |
(**** theory data ****) |
1210 |
||
16458 | 1211 |
structure ProofData = TheoryDataFun |
22846 | 1212 |
( |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1213 |
type T = (stamp * (proof * proof)) list * (stamp * (typ list -> proof -> proof option)) list; |
11519 | 1214 |
|
12233 | 1215 |
val empty = ([], []); |
1216 |
val copy = I; |
|
16458 | 1217 |
val extend = I; |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1218 |
fun merge _ ((rules1, procs1), (rules2, procs2)) : T = |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1219 |
(AList.merge (op =) (K true) (rules1, rules2), |
22662 | 1220 |
AList.merge (op =) (K true) (procs1, procs2)); |
22846 | 1221 |
); |
11519 | 1222 |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1223 |
fun get_data thy = let val (rules, procs) = ProofData.get thy in (map #2 rules, map #2 procs) end; |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1224 |
fun rew_proof thy = rewrite_prf fst (get_data thy); |
23780
a0e7305dd0cb
Added function rew_proof (for pre-normalizing proofs).
berghofe
parents:
23296
diff
changeset
|
1225 |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1226 |
fun add_prf_rrule r = (ProofData.map o apfst) (cons (stamp (), r)); |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1227 |
fun add_prf_rproc p = (ProofData.map o apsnd) (cons (stamp (), p)); |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1228 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1229 |
|
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1230 |
(***** promises *****) |
11519 | 1231 |
|
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1232 |
fun promise_proof thy i prop = |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1233 |
let |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1234 |
val _ = prop |> Term.exists_subterm (fn t => |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1235 |
(Term.is_Free t orelse Term.is_Var t) andalso |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1236 |
error ("promise_proof: illegal variable " ^ Syntax.string_of_term_global thy t)); |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1237 |
val _ = prop |> Term.exists_type (Term.exists_subtype |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1238 |
(fn TFree (a, _) => error ("promise_proof: illegal type variable " ^ quote a) |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1239 |
| _ => false)); |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1240 |
in Promise (i, prop, map TVar (Term.add_tvars prop [])) end; |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1241 |
|
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1242 |
fun fulfill_proof _ [] body0 = body0 |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
1243 |
| fulfill_proof thy ps body0 = |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1244 |
let |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1245 |
val PBody {oracles = oracles0, thms = thms0, proof = proof0} = body0; |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
1246 |
val oracles = fold (fn (_, PBody {oracles, ...}) => merge_oracles oracles) ps oracles0; |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
1247 |
val thms = fold (fn (_, PBody {thms, ...}) => merge_thms thms) ps thms0; |
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
1248 |
val proofs = fold (fn (i, PBody {proof, ...}) => Inttab.update (i, proof)) ps Inttab.empty; |
28875
c1c0e23ed063
eliminated finish_proof, keep pre/post normalization of results separate;
wenzelm
parents:
28846
diff
changeset
|
1249 |
|
c1c0e23ed063
eliminated finish_proof, keep pre/post normalization of results separate;
wenzelm
parents:
28846
diff
changeset
|
1250 |
fun fill (Promise (i, prop, Ts)) = |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
1251 |
(case Inttab.lookup proofs i of |
28875
c1c0e23ed063
eliminated finish_proof, keep pre/post normalization of results separate;
wenzelm
parents:
28846
diff
changeset
|
1252 |
NONE => NONE |
30716
2ee706293eb5
removed misleading make_proof_body, make_oracles, make_thms, which essentially assume a *full* proof;
wenzelm
parents:
30712
diff
changeset
|
1253 |
| SOME prf => SOME (instantiate (Term.add_tvars prop [] ~~ Ts, []) prf)) |
28875
c1c0e23ed063
eliminated finish_proof, keep pre/post normalization of results separate;
wenzelm
parents:
28846
diff
changeset
|
1254 |
| fill _ = NONE; |
c1c0e23ed063
eliminated finish_proof, keep pre/post normalization of results separate;
wenzelm
parents:
28846
diff
changeset
|
1255 |
val (rules, procs) = get_data thy; |
c1c0e23ed063
eliminated finish_proof, keep pre/post normalization of results separate;
wenzelm
parents:
28846
diff
changeset
|
1256 |
val proof = rewrite_prf fst (rules, K fill :: procs) proof0; |
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1257 |
in PBody {oracles = oracles, thms = thms, proof = proof} end; |
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1258 |
|
29642 | 1259 |
fun fulfill_proof_future _ [] body = Future.value body |
1260 |
| fulfill_proof_future thy promises body = |
|
1261 |
Future.fork_deps (map snd promises) (fn () => |
|
1262 |
fulfill_proof thy (map (apsnd Future.join) promises) body); |
|
1263 |
||
28828
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1264 |
|
c25dd83a6f9f
unified treatment of PAxm/Oracle/Promise in basic proof term operations;
wenzelm
parents:
28815
diff
changeset
|
1265 |
(***** theorems *****) |
11519 | 1266 |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1267 |
fun thm_proof thy name hyps prop promises body = |
11519 | 1268 |
let |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1269 |
val PBody {oracles = oracles0, thms = thms0, proof = prf} = body; |
12923 | 1270 |
val prop = Logic.list_implies (hyps, prop); |
11519 | 1271 |
val nvs = needed_vars prop; |
1272 |
val args = map (fn (v as Var (ixn, _)) => |
|
17492 | 1273 |
if member (op =) nvs ixn then SOME v else NONE) (vars_of prop) @ |
28812
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
berghofe
parents:
28803
diff
changeset
|
1274 |
map SOME (frees_of prop); |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1275 |
|
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1276 |
val proof0 = |
28876 | 1277 |
if ! proofs = 2 then |
1278 |
#4 (shrink_proof thy [] 0 (rew_proof thy (fold_rev implies_intr_proof hyps prf))) |
|
1279 |
else MinProof; |
|
29642 | 1280 |
val body0 = PBody {oracles = oracles0, thms = thms0, proof = proof0}; |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1281 |
|
29642 | 1282 |
fun new_prf () = (serial (), name, prop, fulfill_proof_future thy promises body0); |
28815 | 1283 |
val (i, name, prop, body') = |
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1284 |
(case strip_combt (fst (strip_combP prf)) of |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1285 |
(PThm (i, ((old_name, prop', NONE), body')), args') => |
28815 | 1286 |
if (old_name = "" orelse old_name = name) andalso prop = prop' andalso args = args' |
1287 |
then (i, name, prop, body') |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1288 |
else new_prf () |
28815 | 1289 |
| _ => new_prf ()); |
1290 |
val head = PThm (i, ((name, prop, NONE), body')); |
|
11519 | 1291 |
in |
28815 | 1292 |
((i, (name, prop, body')), proof_combP (proof_combt' (head, args), map Hyp hyps)) |
11519 | 1293 |
end; |
1294 |
||
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
1295 |
fun get_name hyps prop prf = |
12923 | 1296 |
let val prop = Logic.list_implies (hyps, prop) in |
1297 |
(case strip_combt (fst (strip_combP prf)) of |
|
28803
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1298 |
(PAxm (name, prop', _), _) => if prop = prop' then name else "" (* FIXME !? *) |
d90258bbb18f
reworked type proof: MinProof is vacous, added Promise, refined PThm (with serial);
wenzelm
parents:
28329
diff
changeset
|
1299 |
| (PThm (_, ((name, prop', _), _)), _) => if prop = prop' then name else "" |
21646
c07b5b0e8492
thm/prf: separate official name vs. additional tags;
wenzelm
parents:
20853
diff
changeset
|
1300 |
| _ => "") |
12923 | 1301 |
end; |
11519 | 1302 |
|
1303 |
end; |
|
1304 |
||
1305 |
structure BasicProofterm : BASIC_PROOFTERM = Proofterm; |
|
1306 |
open BasicProofterm; |