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