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