author | wenzelm |
Mon, 29 Aug 2005 16:18:04 +0200 | |
changeset 17184 | 3d80209e9a53 |
parent 16417 | 9bc16273c2d4 |
child 17388 | 495c799df31d |
permissions | -rw-r--r-- |
16417 | 1 |
theory InductiveInvariant imports Main begin |
15636 | 2 |
|
3 |
(** Authors: Sava Krsti\'{c} and John Matthews **) |
|
4 |
(** Date: Sep 12, 2003 **) |
|
5 |
||
6 |
text {* A formalization of some of the results in |
|
7 |
\emph{Inductive Invariants for Nested Recursion}, |
|
8 |
by Sava Krsti\'{c} and John Matthews. |
|
9 |
Appears in the proceedings of TPHOLs 2003, LNCS vol. 2758, pp. 253-269. *} |
|
10 |
||
11 |
||
12 |
text "S is an inductive invariant of the functional F with respect to the wellfounded relation r." |
|
13 |
||
14 |
constdefs indinv :: "('a * 'a) set => ('a => 'b => bool) => (('a => 'b) => ('a => 'b)) => bool" |
|
15 |
"indinv r S F == \<forall>f x. (\<forall>y. (y,x) : r --> S y (f y)) --> S x (F f x)" |
|
16 |
||
17 |
||
18 |
text "S is an inductive invariant of the functional F on set D with respect to the wellfounded relation r." |
|
19 |
||
20 |
constdefs indinv_on :: "('a * 'a) set => 'a set => ('a => 'b => bool) => (('a => 'b) => ('a => 'b)) => bool" |
|
21 |
"indinv_on r D S F == \<forall>f. \<forall>x\<in>D. (\<forall>y\<in>D. (y,x) \<in> r --> S y (f y)) --> S x (F f x)" |
|
22 |
||
23 |
||
24 |
text "The key theorem, corresponding to theorem 1 of the paper. All other results |
|
25 |
in this theory are proved using instances of this theorem, and theorems |
|
26 |
derived from this theorem." |
|
27 |
||
28 |
theorem indinv_wfrec: |
|
29 |
assumes WF: "wf r" and |
|
30 |
INV: "indinv r S F" |
|
31 |
shows "S x (wfrec r F x)" |
|
32 |
proof (induct_tac x rule: wf_induct [OF WF]) |
|
33 |
fix x |
|
34 |
assume IHYP: "\<forall>y. (y,x) \<in> r --> S y (wfrec r F y)" |
|
35 |
then have "\<forall>y. (y,x) \<in> r --> S y (cut (wfrec r F) r x y)" by (simp add: tfl_cut_apply) |
|
36 |
with INV have "S x (F (cut (wfrec r F) r x) x)" by (unfold indinv_def, blast) |
|
37 |
thus "S x (wfrec r F x)" using WF by (simp add: wfrec) |
|
38 |
qed |
|
39 |
||
40 |
theorem indinv_on_wfrec: |
|
41 |
assumes WF: "wf r" and |
|
42 |
INV: "indinv_on r D S F" and |
|
43 |
D: "x\<in>D" |
|
44 |
shows "S x (wfrec r F x)" |
|
45 |
apply (insert INV D indinv_wfrec [OF WF, of "% x y. x\<in>D --> S x y"]) |
|
46 |
by (simp add: indinv_on_def indinv_def) |
|
47 |
||
48 |
theorem ind_fixpoint_on_lemma: |
|
49 |
assumes WF: "wf r" and |
|
50 |
INV: "\<forall>f. \<forall>x\<in>D. (\<forall>y\<in>D. (y,x) \<in> r --> S y (wfrec r F y) & f y = wfrec r F y) |
|
51 |
--> S x (wfrec r F x) & F f x = wfrec r F x" and |
|
52 |
D: "x\<in>D" |
|
53 |
shows "F (wfrec r F) x = wfrec r F x & S x (wfrec r F x)" |
|
54 |
proof (rule indinv_on_wfrec [OF WF _ D, of "% a b. F (wfrec r F) a = b & wfrec r F a = b & S a b" F, simplified]) |
|
55 |
show "indinv_on r D (%a b. F (wfrec r F) a = b & wfrec r F a = b & S a b) F" |
|
56 |
proof (unfold indinv_on_def, clarify) |
|
57 |
fix f x |
|
58 |
assume A1: "\<forall>y\<in>D. (y, x) \<in> r --> F (wfrec r F) y = f y & wfrec r F y = f y & S y (f y)" |
|
59 |
assume D': "x\<in>D" |
|
60 |
from A1 INV [THEN spec, of f, THEN bspec, OF D'] |
|
61 |
have "S x (wfrec r F x)" and |
|
62 |
"F f x = wfrec r F x" by auto |
|
63 |
moreover |
|
64 |
from A1 have "\<forall>y\<in>D. (y, x) \<in> r --> S y (wfrec r F y)" by auto |
|
65 |
with D' INV [THEN spec, of "wfrec r F", simplified] |
|
66 |
have "F (wfrec r F) x = wfrec r F x" by blast |
|
67 |
ultimately show "F (wfrec r F) x = F f x & wfrec r F x = F f x & S x (F f x)" by auto |
|
68 |
qed |
|
69 |
qed |
|
70 |
||
71 |
theorem ind_fixpoint_lemma: |
|
72 |
assumes WF: "wf r" and |
|
73 |
INV: "\<forall>f x. (\<forall>y. (y,x) \<in> r --> S y (wfrec r F y) & f y = wfrec r F y) |
|
74 |
--> S x (wfrec r F x) & F f x = wfrec r F x" |
|
75 |
shows "F (wfrec r F) x = wfrec r F x & S x (wfrec r F x)" |
|
76 |
apply (rule ind_fixpoint_on_lemma [OF WF _ UNIV_I, simplified]) |
|
77 |
by (rule INV) |
|
78 |
||
79 |
theorem tfl_indinv_wfrec: |
|
80 |
"[| f == wfrec r F; wf r; indinv r S F |] |
|
81 |
==> S x (f x)" |
|
82 |
by (simp add: indinv_wfrec) |
|
83 |
||
84 |
theorem tfl_indinv_on_wfrec: |
|
85 |
"[| f == wfrec r F; wf r; indinv_on r D S F; x\<in>D |] |
|
86 |
==> S x (f x)" |
|
87 |
by (simp add: indinv_on_wfrec) |
|
88 |
||
14244
f58598341d30
InductiveInvariant_examples illustrates advanced recursive function definitions
paulson
parents:
diff
changeset
|
89 |
end |