author | wenzelm |
Fri, 06 Jan 2006 15:18:20 +0100 | |
changeset 18591 | 04b9f2bf5a48 |
parent 18011 | 685d95c793ff |
child 18598 | 94d658871c98 |
permissions | -rw-r--r-- |
16978 | 1 |
(* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
2 |
(* Title: Provers/eqsubst.ML |
16434 | 3 |
ID: $Id$ |
15481 | 4 |
Author: Lucas Dixon, University of Edinburgh |
5 |
lucas.dixon@ed.ac.uk |
|
16978 | 6 |
Modified: 18 Feb 2005 - Lucas - |
15481 | 7 |
Created: 29 Jan 2005 |
8 |
*) |
|
16978 | 9 |
(* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) |
15481 | 10 |
(* DESCRIPTION: |
11 |
||
12 |
A Tactic to perform a substiution using an equation. |
|
13 |
||
14 |
*) |
|
15 |
(* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) |
|
16 |
||
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
17 |
|
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
18 |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
19 |
(* Logic specific data stub *) |
15481 | 20 |
signature EQRULE_DATA = |
21 |
sig |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
22 |
|
15481 | 23 |
(* to make a meta equality theorem in the current logic *) |
24 |
val prep_meta_eq : thm -> thm list |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
25 |
|
15481 | 26 |
end; |
27 |
||
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
28 |
|
15481 | 29 |
(* the signature of an instance of the SQSUBST tactic *) |
18591 | 30 |
signature EQSUBST = |
15481 | 31 |
sig |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
32 |
|
16978 | 33 |
exception eqsubst_occL_exp of |
34 |
string * (int list) * (thm list) * int * thm; |
|
15959
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
35 |
|
17795 | 36 |
type match |
37 |
type searchinfo |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
38 |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
39 |
val prep_subst_in_asm : |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
40 |
int (* subgoal to subst in *) |
16978 | 41 |
-> thm (* target theorem with subgoals *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
42 |
-> int (* premise to subst in *) |
16978 | 43 |
-> (cterm list (* certified free var placeholders for vars *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
44 |
* int (* premice no. to subst *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
45 |
* int (* number of assumptions of premice *) |
16978 | 46 |
* thm) (* premice as a new theorem for forward reasoning *) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
47 |
* searchinfo (* search info: prem id etc *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
48 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
49 |
val prep_subst_in_asms : |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
50 |
int (* subgoal to subst in *) |
16978 | 51 |
-> thm (* target theorem with subgoals *) |
52 |
-> ((cterm list (* certified free var placeholders for vars *) |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
53 |
* int (* premice no. to subst *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
54 |
* int (* number of assumptions of premice *) |
16978 | 55 |
* thm) (* premice as a new theorem for forward reasoning *) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
56 |
* searchinfo) list |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
57 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
58 |
val apply_subst_in_asm : |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
59 |
int (* subgoal *) |
16978 | 60 |
-> thm (* overall theorem *) |
61 |
-> thm (* rule *) |
|
62 |
-> (cterm list (* certified free var placeholders for vars *) |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
63 |
* int (* assump no being subst *) |
16978 | 64 |
* int (* num of premises of asm *) |
65 |
* thm) (* premthm *) |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
66 |
* match |
16978 | 67 |
-> thm Seq.seq |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
68 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
69 |
val prep_concl_subst : |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
70 |
int (* subgoal *) |
16978 | 71 |
-> thm (* overall goal theorem *) |
72 |
-> (cterm list * thm) * searchinfo (* (cvfs, conclthm), matchf *) |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
73 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
74 |
val apply_subst_in_concl : |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
75 |
int (* subgoal *) |
16978 | 76 |
-> thm (* thm with all goals *) |
77 |
-> cterm list (* certified free var placeholders for vars *) |
|
78 |
* thm (* trivial thm of goal concl *) |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
79 |
(* possible matches/unifiers *) |
16978 | 80 |
-> thm (* rule *) |
15550
806214035275
lucas - added more comments and an extra type to clarify the code.
dixon
parents:
15538
diff
changeset
|
81 |
-> match |
16978 | 82 |
-> thm Seq.seq (* substituted goal *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
83 |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
84 |
(* basic notion of search *) |
16978 | 85 |
val searchf_tlr_unify_all : |
86 |
(searchinfo |
|
87 |
-> term (* lhs *) |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
88 |
-> match Seq.seq Seq.seq) |
16978 | 89 |
val searchf_tlr_unify_valid : |
90 |
(searchinfo |
|
91 |
-> term (* lhs *) |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
92 |
-> match Seq.seq Seq.seq) |
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
93 |
|
16978 | 94 |
(* specialise search constructor for conclusion skipping occurrences. *) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
95 |
val skip_first_occs_search : |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
96 |
int -> ('a -> 'b -> 'c Seq.seq Seq.seq) -> 'a -> 'b -> 'c Seq.seq |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
97 |
(* specialised search constructor for assumptions using skips *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
98 |
val skip_first_asm_occs_search : |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
99 |
('a -> 'b -> 'c Seq.seq Seq.seq) -> |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
100 |
'a -> int -> 'b -> 'c IsaPLib.skipseqT |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
101 |
|
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
102 |
(* tactics and methods *) |
16978 | 103 |
val eqsubst_asm_meth : int list -> thm list -> Proof.method |
104 |
val eqsubst_asm_tac : |
|
105 |
int list -> thm list -> int -> thm -> thm Seq.seq |
|
106 |
val eqsubst_asm_tac' : |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
107 |
(* search function with skips *) |
16978 | 108 |
(searchinfo -> int -> term -> match IsaPLib.skipseqT) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
109 |
-> int (* skip to *) |
16978 | 110 |
-> thm (* rule *) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
111 |
-> int (* subgoal number *) |
16978 | 112 |
-> thm (* tgt theorem with subgoals *) |
113 |
-> thm Seq.seq (* new theorems *) |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
114 |
|
16978 | 115 |
val eqsubst_meth : int list -> thm list -> Proof.method |
116 |
val eqsubst_tac : |
|
117 |
int list -> thm list -> int -> thm -> thm Seq.seq |
|
118 |
val eqsubst_tac' : |
|
119 |
(searchinfo -> term -> match Seq.seq) |
|
120 |
-> thm -> int -> thm -> thm Seq.seq |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
121 |
|
16978 | 122 |
val meth : (bool * int list) * thm list -> Proof.context -> Proof.method |
15481 | 123 |
val setup : (Theory.theory -> Theory.theory) list |
124 |
end; |
|
125 |
||
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
126 |
|
18591 | 127 |
functor EqSubstFun (EqRuleData : EQRULE_DATA): EQSUBST = |
128 |
struct |
|
15481 | 129 |
|
15915
b0e8b37642a4
lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents:
15855
diff
changeset
|
130 |
(* a type abriviation for match information *) |
16978 | 131 |
type match = |
132 |
((indexname * (sort * typ)) list (* type instantiations *) |
|
133 |
* (indexname * (typ * term)) list) (* term instantiations *) |
|
134 |
* (string * typ) list (* fake named type abs env *) |
|
135 |
* (string * typ) list (* type abs env *) |
|
136 |
* term (* outer term *) |
|
15550
806214035275
lucas - added more comments and an extra type to clarify the code.
dixon
parents:
15538
diff
changeset
|
137 |
|
16978 | 138 |
type searchinfo = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
139 |
Sign.sg (* sign for matching *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
140 |
* int (* maxidx *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
141 |
* BasicIsaFTerm.FcTerm (* focusterm to search under *) |
15550
806214035275
lucas - added more comments and an extra type to clarify the code.
dixon
parents:
15538
diff
changeset
|
142 |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
143 |
(* FOR DEBUGGING... |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
144 |
type trace_subst_errT = int (* subgoal *) |
16978 | 145 |
* thm (* thm with all goals *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
146 |
* (Thm.cterm list (* certified free var placeholders for vars *) |
16978 | 147 |
* thm) (* trivial thm of goal concl *) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
148 |
(* possible matches/unifiers *) |
16978 | 149 |
* thm (* rule *) |
150 |
* (((indexname * typ) list (* type instantiations *) |
|
151 |
* (indexname * term) list ) (* term instantiations *) |
|
152 |
* (string * typ) list (* Type abs env *) |
|
153 |
* term) (* outer term *); |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
154 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
155 |
val trace_subst_err = (ref NONE : trace_subst_errT option ref); |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
156 |
val trace_subst_search = ref false; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
157 |
exception trace_subst_exp of trace_subst_errT; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
158 |
*) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
159 |
|
16978 | 160 |
(* also defined in /HOL/Tools/inductive_codegen.ML, |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
161 |
maybe move this to seq.ML ? *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
162 |
infix 5 :->; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
163 |
fun s :-> f = Seq.flat (Seq.map f s); |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
164 |
|
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
165 |
(* search from top, left to right, then down *) |
16978 | 166 |
fun search_tlr_all_f f ft = |
15481 | 167 |
let |
16978 | 168 |
fun maux ft = |
169 |
let val t' = (IsaFTerm.focus_of_fcterm ft) |
|
170 |
(* val _ = |
|
171 |
if !trace_subst_search then |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
172 |
(writeln ("Examining: " ^ (TermLib.string_of_term t')); |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
173 |
TermLib.writeterm t'; ()) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
174 |
else (); *) |
16978 | 175 |
in |
176 |
(case t' of |
|
177 |
(_ $ _) => Seq.append(maux (IsaFTerm.focus_left ft), |
|
178 |
Seq.cons(f ft, |
|
15481 | 179 |
maux (IsaFTerm.focus_right ft))) |
15929
68bd1e16552a
lucas - added option to select occurance to rewrite e.g. (occ 4)
dixon
parents:
15915
diff
changeset
|
180 |
| (Abs _) => Seq.cons(f ft, maux (IsaFTerm.focus_abs ft)) |
68bd1e16552a
lucas - added option to select occurance to rewrite e.g. (occ 4)
dixon
parents:
15915
diff
changeset
|
181 |
| leaf => Seq.single (f ft)) end |
15481 | 182 |
in maux ft end; |
183 |
||
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
184 |
(* search from top, left to right, then down *) |
16978 | 185 |
fun search_tlr_valid_f f ft = |
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
186 |
let |
16978 | 187 |
fun maux ft = |
188 |
let |
|
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
189 |
val hereseq = if IsaFTerm.valid_match_start ft then f ft else Seq.empty |
16978 | 190 |
in |
191 |
(case (IsaFTerm.focus_of_fcterm ft) of |
|
192 |
(_ $ _) => Seq.append(maux (IsaFTerm.focus_left ft), |
|
193 |
Seq.cons(hereseq, |
|
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
194 |
maux (IsaFTerm.focus_right ft))) |
15929
68bd1e16552a
lucas - added option to select occurance to rewrite e.g. (occ 4)
dixon
parents:
15915
diff
changeset
|
195 |
| (Abs _) => Seq.cons(hereseq, maux (IsaFTerm.focus_abs ft)) |
68bd1e16552a
lucas - added option to select occurance to rewrite e.g. (occ 4)
dixon
parents:
15915
diff
changeset
|
196 |
| leaf => Seq.single (hereseq)) |
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
197 |
end |
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
198 |
in maux ft end; |
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
199 |
|
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
200 |
(* search all unifications *) |
16978 | 201 |
fun searchf_tlr_unify_all (sgn, maxidx, ft) lhs = |
202 |
IsaFTerm.find_fcterm_matches |
|
203 |
search_tlr_all_f |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
204 |
(IsaFTerm.clean_unify_ft sgn maxidx lhs) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
205 |
ft; |
15481 | 206 |
|
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
207 |
(* search only for 'valid' unifiers (non abs subterms and non vars) *) |
16978 | 208 |
fun searchf_tlr_unify_valid (sgn, maxidx, ft) lhs = |
209 |
IsaFTerm.find_fcterm_matches |
|
210 |
search_tlr_valid_f |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
211 |
(IsaFTerm.clean_unify_ft sgn maxidx lhs) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
212 |
ft; |
15929
68bd1e16552a
lucas - added option to select occurance to rewrite e.g. (occ 4)
dixon
parents:
15915
diff
changeset
|
213 |
|
15814
d65f461c8672
lucas - fixed a big with renaming of bound variables. Other small changes.
dixon
parents:
15550
diff
changeset
|
214 |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
215 |
(* apply a substitution in the conclusion of the theorem th *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
216 |
(* cfvs are certified free var placeholders for goal params *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
217 |
(* conclthm is a theorem of for just the conclusion *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
218 |
(* m is instantiation/match information *) |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
219 |
(* rule is the equation for substitution *) |
16978 | 220 |
fun apply_subst_in_concl i th (cfvs, conclthm) rule m = |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
221 |
(RWInst.rw m rule conclthm) |
15855 | 222 |
|> IsaND.unfix_frees cfvs |
15915
b0e8b37642a4
lucas - improved interface to isand.ML and cleaned up clean-unification code, and added some better comments.
dixon
parents:
15855
diff
changeset
|
223 |
|> RWInst.beta_eta_contract |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
224 |
|> (fn r => Tactic.rtac r i th); |
15481 | 225 |
|
226 |
(* substitute within the conclusion of goal i of gth, using a meta |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
227 |
equation rule. Note that we assume rule has var indicies zero'd *) |
16978 | 228 |
fun prep_concl_subst i gth = |
229 |
let |
|
15481 | 230 |
val th = Thm.incr_indexes 1 gth; |
231 |
val tgt_term = Thm.prop_of th; |
|
232 |
||
233 |
val sgn = Thm.sign_of_thm th; |
|
234 |
val ctermify = Thm.cterm_of sgn; |
|
235 |
val trivify = Thm.trivial o ctermify; |
|
236 |
||
237 |
val (fixedbody, fvs) = IsaND.fix_alls_term i tgt_term; |
|
238 |
val cfvs = rev (map ctermify fvs); |
|
239 |
||
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
240 |
val conclterm = Logic.strip_imp_concl fixedbody; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
241 |
val conclthm = trivify conclterm; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
242 |
val maxidx = Term.maxidx_of_term conclterm; |
16978 | 243 |
val ft = ((IsaFTerm.focus_right |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
244 |
o IsaFTerm.focus_left |
16978 | 245 |
o IsaFTerm.fcterm_of_term |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
246 |
o Thm.prop_of) conclthm) |
15481 | 247 |
in |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
248 |
((cfvs, conclthm), (sgn, maxidx, ft)) |
15481 | 249 |
end; |
250 |
||
251 |
(* substitute using an object or meta level equality *) |
|
16978 | 252 |
fun eqsubst_tac' searchf instepthm i th = |
253 |
let |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
254 |
val (cvfsconclthm, searchinfo) = prep_concl_subst i th; |
16978 | 255 |
val stepthms = |
256 |
Seq.map Drule.zero_var_indexes |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
257 |
(Seq.of_list (EqRuleData.prep_meta_eq instepthm)); |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
258 |
fun rewrite_with_thm r = |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
259 |
let val (lhs,_) = Logic.dest_equals (Thm.concl_of r); |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
260 |
in (searchf searchinfo lhs) |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
261 |
:-> (apply_subst_in_concl i th cvfsconclthm r) end; |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
262 |
in stepthms :-> rewrite_with_thm end; |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
263 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
264 |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
265 |
(* Tactic.distinct_subgoals_tac -- fails to free type variables *) |
15959
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
266 |
|
16978 | 267 |
(* custom version of distinct subgoals that works with term and |
268 |
type variables. Asssumes th is in beta-eta normal form. |
|
15959
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
269 |
Also, does nothing if flexflex contraints are present. *) |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
270 |
fun distinct_subgoals th = |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
271 |
if List.null (Thm.tpairs_of th) then |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
272 |
let val (fixes,fixedthm) = IsaND.fix_vars_and_tvars th |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
273 |
val (fixedthconcl,cprems) = IsaND.hide_prems fixedthm |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
274 |
in |
16978 | 275 |
IsaND.unfix_frees_and_tfrees |
15959
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
276 |
fixes |
16978 | 277 |
(Drule.implies_intr_list |
278 |
(Library.gen_distinct |
|
15959
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
279 |
(fn (x, y) => Thm.term_of x = Thm.term_of y) |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
280 |
cprems) fixedthconcl) |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
281 |
end |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
282 |
else th; |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
283 |
|
16978 | 284 |
(* General substiuttion of multiple occurances using one of |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
285 |
the given theorems*) |
16978 | 286 |
exception eqsubst_occL_exp of |
287 |
string * (int list) * (thm list) * int * thm; |
|
288 |
fun skip_first_occs_search occ srchf sinfo lhs = |
|
289 |
case (IsaPLib.skipto_seqseq occ (srchf sinfo lhs)) of |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
290 |
IsaPLib.skipmore _ => Seq.empty |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
291 |
| IsaPLib.skipseq ss => Seq.flat ss; |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
292 |
|
16978 | 293 |
fun eqsubst_tac occL thms i th = |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
294 |
let val nprems = Thm.nprems_of th in |
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
295 |
if nprems < i then Seq.empty else |
16978 | 296 |
let val thmseq = (Seq.of_list thms) |
297 |
fun apply_occ occ th = |
|
298 |
thmseq :-> |
|
299 |
(fn r => eqsubst_tac' (skip_first_occs_search |
|
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
300 |
occ searchf_tlr_unify_valid) r |
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
301 |
(i + ((Thm.nprems_of th) - nprems)) |
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
302 |
th); |
16978 | 303 |
val sortedoccL = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
304 |
Library.sort (Library.rev_order o Library.int_ord) occL; |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
305 |
in |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
306 |
Seq.map distinct_subgoals (Seq.EVERY (map apply_occ sortedoccL) th) |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
307 |
end |
15959
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
308 |
end |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
309 |
handle THM _ => raise eqsubst_occL_exp ("THM",occL,thms,i,th); |
366d39e95d3c
lucas - fixed bug with uninstantiated type contexts in eqsubst and added the automatic removal of duplicate subgoals (when there are no flex-flex constraints)
dixon
parents:
15936
diff
changeset
|
310 |
|
15481 | 311 |
|
312 |
(* inthms are the given arguments in Isar, and treated as eqstep with |
|
313 |
the first one, then the second etc *) |
|
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
314 |
fun eqsubst_meth occL inthms = |
16978 | 315 |
Method.METHOD |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
316 |
(fn facts => |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
317 |
HEADGOAL ( Method.insert_tac facts THEN' eqsubst_tac occL inthms )); |
15481 | 318 |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
319 |
(* apply a substitution inside assumption j, keeps asm in the same place *) |
16978 | 320 |
fun apply_subst_in_asm i th rule ((cfvs, j, ngoalprems, pth),m) = |
321 |
let |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
322 |
val th2 = Thm.rotate_rule (j - 1) i th; (* put premice first *) |
16978 | 323 |
val preelimrule = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
324 |
(RWInst.rw m rule pth) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
325 |
|> (Seq.hd o Tactic.prune_params_tac) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
326 |
|> Thm.permute_prems 0 ~1 (* put old asm first *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
327 |
|> IsaND.unfix_frees cfvs (* unfix any global params *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
328 |
|> RWInst.beta_eta_contract; (* normal form *) |
16978 | 329 |
(* val elimrule = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
330 |
preelimrule |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
331 |
|> Tactic.make_elim (* make into elim rule *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
332 |
|> Thm.lift_rule (th2, i); (* lift into context *) |
16007
4dcccaa11a13
lucas - bugfix to subst in assumptions: fixed index error for conditional rules.
dixon
parents:
16004
diff
changeset
|
333 |
*) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
334 |
in |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
335 |
(* ~j because new asm starts at back, thus we subtract 1 *) |
16007
4dcccaa11a13
lucas - bugfix to subst in assumptions: fixed index error for conditional rules.
dixon
parents:
16004
diff
changeset
|
336 |
Seq.map (Thm.rotate_rule (~j) ((Thm.nprems_of rule) + i)) |
4dcccaa11a13
lucas - bugfix to subst in assumptions: fixed index error for conditional rules.
dixon
parents:
16004
diff
changeset
|
337 |
(Tactic.dtac preelimrule i th2) |
4dcccaa11a13
lucas - bugfix to subst in assumptions: fixed index error for conditional rules.
dixon
parents:
16004
diff
changeset
|
338 |
|
16978 | 339 |
(* (Thm.bicompose |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
340 |
false (* use unification *) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
341 |
(true, (* elim resolution *) |
16007
4dcccaa11a13
lucas - bugfix to subst in assumptions: fixed index error for conditional rules.
dixon
parents:
16004
diff
changeset
|
342 |
elimrule, (2 + (Thm.nprems_of rule)) - ngoalprems) |
4dcccaa11a13
lucas - bugfix to subst in assumptions: fixed index error for conditional rules.
dixon
parents:
16004
diff
changeset
|
343 |
i th2) *) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
344 |
end; |
15481 | 345 |
|
346 |
||
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
347 |
(* prepare to substitute within the j'th premise of subgoal i of gth, |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
348 |
using a meta-level equation. Note that we assume rule has var indicies |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
349 |
zero'd. Note that we also assume that premt is the j'th premice of |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
350 |
subgoal i of gth. Note the repetition of work done for each |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
351 |
assumption, i.e. this can be made more efficient for search over |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
352 |
multiple assumptions. *) |
16978 | 353 |
fun prep_subst_in_asm i gth j = |
354 |
let |
|
15481 | 355 |
val th = Thm.incr_indexes 1 gth; |
356 |
val tgt_term = Thm.prop_of th; |
|
357 |
||
358 |
val sgn = Thm.sign_of_thm th; |
|
359 |
val ctermify = Thm.cterm_of sgn; |
|
360 |
val trivify = Thm.trivial o ctermify; |
|
361 |
||
362 |
val (fixedbody, fvs) = IsaND.fix_alls_term i tgt_term; |
|
363 |
val cfvs = rev (map ctermify fvs); |
|
364 |
||
18011
685d95c793ff
cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents:
17795
diff
changeset
|
365 |
val asmt = nth (Logic.strip_imp_prems fixedbody) (j - 1); |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
366 |
val asm_nprems = length (Logic.strip_imp_prems asmt); |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
367 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
368 |
val pth = trivify asmt; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
369 |
val maxidx = Term.maxidx_of_term asmt; |
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
370 |
|
16978 | 371 |
val ft = ((IsaFTerm.focus_right |
372 |
o IsaFTerm.fcterm_of_term |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
373 |
o Thm.prop_of) pth) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
374 |
in ((cfvs, j, asm_nprems, pth), (sgn, maxidx, ft)) end; |
15481 | 375 |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
376 |
(* prepare subst in every possible assumption *) |
16978 | 377 |
fun prep_subst_in_asms i gth = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
378 |
map (prep_subst_in_asm i gth) |
16978 | 379 |
((rev o IsaPLib.mk_num_list o length) |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
380 |
(Logic.prems_of_goal (Thm.prop_of gth) i)); |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
381 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
382 |
|
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
383 |
(* substitute in an assumption using an object or meta level equality *) |
16978 | 384 |
fun eqsubst_asm_tac' searchf skipocc instepthm i th = |
385 |
let |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
386 |
val asmpreps = prep_subst_in_asms i th; |
16978 | 387 |
val stepthms = |
388 |
Seq.map Drule.zero_var_indexes |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
389 |
(Seq.of_list (EqRuleData.prep_meta_eq instepthm)) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
390 |
fun rewrite_with_thm r = |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
391 |
let val (lhs,_) = Logic.dest_equals (Thm.concl_of r) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
392 |
fun occ_search occ [] = Seq.empty |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
393 |
| occ_search occ ((asminfo, searchinfo)::moreasms) = |
16978 | 394 |
(case searchf searchinfo occ lhs of |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
395 |
IsaPLib.skipmore i => occ_search i moreasms |
16978 | 396 |
| IsaPLib.skipseq ss => |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
397 |
Seq.append (Seq.map (Library.pair asminfo) |
16978 | 398 |
(Seq.flat ss), |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
399 |
occ_search 1 moreasms)) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
400 |
(* find later substs also *) |
16978 | 401 |
in |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
402 |
(occ_search skipocc asmpreps) :-> (apply_subst_in_asm i th r) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
403 |
end; |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
404 |
in stepthms :-> rewrite_with_thm end; |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
405 |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
406 |
|
16978 | 407 |
fun skip_first_asm_occs_search searchf sinfo occ lhs = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
408 |
IsaPLib.skipto_seqseq occ (searchf sinfo lhs); |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
409 |
|
16978 | 410 |
fun eqsubst_asm_tac occL thms i th = |
411 |
let val nprems = Thm.nprems_of th |
|
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
412 |
in |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
413 |
if nprems < i then Seq.empty else |
16978 | 414 |
let val thmseq = (Seq.of_list thms) |
415 |
fun apply_occ occK th = |
|
416 |
thmseq :-> |
|
417 |
(fn r => |
|
418 |
eqsubst_asm_tac' (skip_first_asm_occs_search |
|
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
419 |
searchf_tlr_unify_valid) occK r |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
420 |
(i + ((Thm.nprems_of th) - nprems)) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
421 |
th); |
16978 | 422 |
val sortedoccs = |
16004
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
423 |
Library.sort (Library.rev_order o Library.int_ord) occL |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
424 |
in |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
425 |
Seq.map distinct_subgoals |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
426 |
(Seq.EVERY (map apply_occ sortedoccs) th) |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
427 |
end |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
428 |
end |
031f56012483
lucas - fixed subst in assumptions to count redexes from left to right.
dixon
parents:
15959
diff
changeset
|
429 |
handle THM _ => raise eqsubst_occL_exp ("THM",occL,thms,i,th); |
15481 | 430 |
|
431 |
(* inthms are the given arguments in Isar, and treated as eqstep with |
|
432 |
the first one, then the second etc *) |
|
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
433 |
fun eqsubst_asm_meth occL inthms = |
16978 | 434 |
Method.METHOD |
15538
d8edf54cc28c
lucas - re-arranged code and added comments. Also added check to make sure the subgoal that we are being applied to exists. If it does not, empty seq is returned.
dixon
parents:
15486
diff
changeset
|
435 |
(fn facts => |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
436 |
HEADGOAL (Method.insert_tac facts THEN' eqsubst_asm_tac occL inthms )); |
15481 | 437 |
|
438 |
(* combination method that takes a flag (true indicates that subst |
|
439 |
should be done to an assumption, false = apply to the conclusion of |
|
440 |
the goal) as well as the theorems to use *) |
|
16978 | 441 |
fun meth ((asmflag, occL), inthms) ctxt = |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
442 |
if asmflag then eqsubst_asm_meth occL inthms else eqsubst_meth occL inthms; |
15481 | 443 |
|
444 |
(* syntax for options, given "(asm)" will give back true, without |
|
445 |
gives back false *) |
|
446 |
val options_syntax = |
|
447 |
(Args.parens (Args.$$$ "asm") >> (K true)) || |
|
448 |
(Scan.succeed false); |
|
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
449 |
|
15929
68bd1e16552a
lucas - added option to select occurance to rewrite e.g. (occ 4)
dixon
parents:
15915
diff
changeset
|
450 |
val ith_syntax = |
15936
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
451 |
(Args.parens (Scan.repeat Args.nat)) |
817ac93ee786
lucas - added ability to provide multiple replacements for subst: syntax is now: subst (1 3) myrule
dixon
parents:
15929
diff
changeset
|
452 |
|| (Scan.succeed [0]); |
15481 | 453 |
|
454 |
(* method syntax, first take options, then theorems *) |
|
455 |
fun meth_syntax meth src ctxt = |
|
16978 | 456 |
meth (snd (Method.syntax ((Scan.lift options_syntax) |
457 |
-- (Scan.lift ith_syntax) |
|
458 |
-- Attrib.local_thms) src ctxt)) |
|
15481 | 459 |
ctxt; |
460 |
||
461 |
(* setup function for adding method to theory. *) |
|
16978 | 462 |
val setup = |
15481 | 463 |
[Method.add_method ("subst", meth_syntax meth, "Substiution with an equation. Use \"(asm)\" option to substitute in an assumption.")]; |
464 |
||
16978 | 465 |
end; |