src/HOL/ex/While_Combinator_Example.thy
author nipkow
Sun, 28 Nov 2010 15:20:51 +0100
changeset 41030 0a54cfc9add3
parent 37759 8380686be5cd
child 41661 64cd30d6b0b8
permissions -rw-r--r--
gave more standard finite set rules simp and intro attribute
krauss@37759
     1
(*  Title:      HOL/Library/While_Combinator.thy
krauss@37759
     2
    Author:     Tobias Nipkow
krauss@37759
     3
    Copyright   2000 TU Muenchen
krauss@37759
     4
*)
krauss@37759
     5
krauss@37759
     6
header {* An application of the While combinator *}
krauss@37759
     7
krauss@37759
     8
theory While_Combinator_Example
krauss@37759
     9
imports While_Combinator
krauss@37759
    10
begin
krauss@37759
    11
krauss@37759
    12
text {* Computation of the @{term lfp} on finite sets via 
krauss@37759
    13
  iteration. *}
krauss@37759
    14
krauss@37759
    15
theorem lfp_conv_while:
krauss@37759
    16
  "[| mono f; finite U; f U = U |] ==>
krauss@37759
    17
    lfp f = fst (while (\<lambda>(A, fA). A \<noteq> fA) (\<lambda>(A, fA). (fA, f fA)) ({}, f {}))"
krauss@37759
    18
apply (rule_tac P = "\<lambda>(A, B). (A \<subseteq> U \<and> B = f A \<and> A \<subseteq> B \<and> B \<subseteq> lfp f)" and
krauss@37759
    19
                r = "((Pow U \<times> UNIV) \<times> (Pow U \<times> UNIV)) \<inter>
krauss@37759
    20
                     inv_image finite_psubset (op - U o fst)" in while_rule)
krauss@37759
    21
   apply (subst lfp_unfold)
krauss@37759
    22
    apply assumption
krauss@37759
    23
   apply (simp add: monoD)
krauss@37759
    24
  apply (subst lfp_unfold)
krauss@37759
    25
   apply assumption
krauss@37759
    26
  apply clarsimp
krauss@37759
    27
  apply (blast dest: monoD)
krauss@37759
    28
 apply (fastsimp intro!: lfp_lowerbound)
krauss@37759
    29
 apply (blast intro: wf_finite_psubset Int_lower2 [THEN [2] wf_subset])
krauss@37759
    30
apply (clarsimp simp add: finite_psubset_def order_less_le)
nipkow@41030
    31
apply (blast dest: monoD)
krauss@37759
    32
done
krauss@37759
    33
krauss@37759
    34
krauss@37759
    35
subsection {* Example *}
krauss@37759
    36
krauss@37759
    37
text{* Cannot use @{thm[source]set_eq_subset} because it leads to
krauss@37759
    38
looping because the antisymmetry simproc turns the subset relationship
krauss@37759
    39
back into equality. *}
krauss@37759
    40
krauss@37759
    41
theorem "P (lfp (\<lambda>N::int set. {0} \<union> {(n + 2) mod 6 | n. n \<in> N})) =
krauss@37759
    42
  P {0, 4, 2}"
krauss@37759
    43
proof -
krauss@37759
    44
  have seteq: "!!A B. (A = B) = ((!a : A. a:B) & (!b:B. b:A))"
krauss@37759
    45
    by blast
krauss@37759
    46
  have aux: "!!f A B. {f n | n. A n \<or> B n} = {f n | n. A n} \<union> {f n | n. B n}"
krauss@37759
    47
    apply blast
krauss@37759
    48
    done
krauss@37759
    49
  show ?thesis
krauss@37759
    50
    apply (subst lfp_conv_while [where ?U = "{0, 1, 2, 3, 4, 5}"])
krauss@37759
    51
       apply (rule monoI)
krauss@37759
    52
      apply blast
krauss@37759
    53
     apply simp
krauss@37759
    54
    apply (simp add: aux set_eq_subset)
krauss@37759
    55
    txt {* The fixpoint computation is performed purely by rewriting: *}
krauss@37759
    56
    apply (simp add: while_unfold aux seteq del: subset_empty)
krauss@37759
    57
    done
krauss@37759
    58
qed
krauss@37759
    59
krauss@37759
    60
end