src/HOL/Library/While_Combinator_Example.thy
author nipkow
Thu, 21 Dec 2000 19:19:18 +0100
changeset 10724 819ee80305a8
parent 10653 55f33da63366
child 10948 1bd100c82300
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10251
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
     1
header {* \title{} *}
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
     2
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
     3
theory While_Combinator_Example = While_Combinator:
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
     4
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
     5
text {*
10653
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
     6
 \medskip An application: computation of the @{term lfp} on finite
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
     7
 sets via iteration.
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
     8
*}
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
     9
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    10
theorem lfp_conv_while:
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    11
  "mono f ==> finite U ==> f U = U ==>
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    12
    lfp f = fst (while (\<lambda>(A, fA). A \<noteq> fA) (\<lambda>(A, fA). (fA, f fA)) ({}, f {}))"
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    13
apply (rule_tac P = "\<lambda>(A, B). (A \<subseteq> U \<and> B = f A \<and> A \<subseteq> B \<and> B \<subseteq> lfp f)" and
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    14
                r = "((Pow U <*> UNIV) <*> (Pow U <*> UNIV)) \<inter>
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    15
                     inv_image finite_psubset (op - U o fst)" in while_rule)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    16
   apply (subst lfp_unfold)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    17
    apply assumption
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    18
   apply (simp add: monoD)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    19
  apply (subst lfp_unfold)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    20
   apply assumption
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    21
  apply clarsimp
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    22
  apply (blast dest: monoD)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    23
 apply (fastsimp intro!: lfp_lowerbound)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    24
 apply (blast intro: wf_finite_psubset Int_lower2 [THEN [2] wf_subset])
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    25
apply (clarsimp simp add: inv_image_def finite_psubset_def order_less_le)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    26
apply (blast intro!: finite_Diff dest: monoD)
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    27
done
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    28
55f33da63366 small mods.
nipkow
parents: 10392
diff changeset
    29
text {*
10251
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    30
 An example of using the @{term while} combinator.
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    31
*}
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    32
10392
wenzelm
parents: 10251
diff changeset
    33
lemma aux: "{f n | n. A n \<or> B n} = {f n | n. A n} \<union> {f n | n. B n}"
10251
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    34
  apply blast
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    35
  done
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    36
10392
wenzelm
parents: 10251
diff changeset
    37
theorem "P (lfp (\<lambda>N::int set. {#0} \<union> {(n + #2) mod #6 | n. n \<in> N})) =
10251
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    38
    P {#0, #4, #2}"
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    39
  apply (subst lfp_conv_while [where ?U = "{#0, #1, #2, #3, #4, #5}"])
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    40
     apply (rule monoI)
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    41
    apply blast
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    42
   apply simp
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    43
  apply (simp add: aux set_eq_subset)
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    44
  txt {* The fixpoint computation is performed purely by rewriting: *}
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    45
  apply (simp add: while_unfold aux set_eq_subset del: subset_empty)
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    46
  done
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    47
5cc44cae9590 A general ``while'' combinator (from main HOL);
wenzelm
parents:
diff changeset
    48
end