src/HOLCF/Eventual.thy
author haftmann
Tue, 20 Jul 2010 06:35:29 +0200
changeset 37891 c26f9d06e82c
parent 35794 8cd7134275cc
permissions -rw-r--r--
robustified metis proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35794
8cd7134275cc use headers consistently
huffman
parents: 35771
diff changeset
     1
(*  Title:      HOLCF/Eventual.thy
8cd7134275cc use headers consistently
huffman
parents: 35771
diff changeset
     2
    Author:     Brian Huffman
8cd7134275cc use headers consistently
huffman
parents: 35771
diff changeset
     3
*)
8cd7134275cc use headers consistently
huffman
parents: 35771
diff changeset
     4
8cd7134275cc use headers consistently
huffman
parents: 35771
diff changeset
     5
header {* Eventually-constant sequences *}
8cd7134275cc use headers consistently
huffman
parents: 35771
diff changeset
     6
27408
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
     7
theory Eventual
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
     8
imports Infinite_Set
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
     9
begin
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    10
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    11
subsection {* Lemmas about MOST *}
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    12
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    13
lemma MOST_INFM:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    14
  assumes inf: "infinite (UNIV::'a set)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    15
  shows "MOST x::'a. P x \<Longrightarrow> INFM x::'a. P x"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    16
  unfolding Alm_all_def Inf_many_def
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    17
  apply (auto simp add: Collect_neg_eq)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    18
  apply (drule (1) finite_UnI)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    19
  apply (simp add: Compl_partition2 inf)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    20
  done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    21
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    22
lemma MOST_SucI: "MOST n. P n \<Longrightarrow> MOST n. P (Suc n)"
35771
2b75230f272f remove redundant lemmas
huffman
parents: 27408
diff changeset
    23
by (rule MOST_inj [OF _ inj_Suc])
27408
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    24
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    25
lemma MOST_SucD: "MOST n. P (Suc n) \<Longrightarrow> MOST n. P n"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    26
unfolding MOST_nat
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    27
apply (clarify, rule_tac x="Suc m" in exI, clarify)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    28
apply (erule Suc_lessE, simp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    29
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    30
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    31
lemma MOST_Suc_iff: "(MOST n. P (Suc n)) \<longleftrightarrow> (MOST n. P n)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    32
by (rule iffI [OF MOST_SucD MOST_SucI])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    33
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    34
lemma INFM_finite_Bex_distrib:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    35
  "finite A \<Longrightarrow> (INFM y. \<exists>x\<in>A. P x y) \<longleftrightarrow> (\<exists>x\<in>A. INFM y. P x y)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    36
by (induct set: finite, simp, simp add: INFM_disj_distrib)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    37
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    38
lemma MOST_finite_Ball_distrib:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    39
  "finite A \<Longrightarrow> (MOST y. \<forall>x\<in>A. P x y) \<longleftrightarrow> (\<forall>x\<in>A. MOST y. P x y)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    40
by (induct set: finite, simp, simp add: MOST_conj_distrib)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    41
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    42
lemma MOST_ge_nat: "MOST n::nat. m \<le> n"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    43
unfolding MOST_nat_le by fast
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    44
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    45
subsection {* Eventually constant sequences *}
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    46
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    47
definition
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    48
  eventually_constant :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    49
where
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    50
  "eventually_constant S = (\<exists>x. MOST i. S i = x)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    51
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    52
lemma eventually_constant_MOST_MOST:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    53
  "eventually_constant S \<longleftrightarrow> (MOST m. MOST n. S n = S m)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    54
unfolding eventually_constant_def MOST_nat
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    55
apply safe
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    56
apply (rule_tac x=m in exI, clarify)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    57
apply (rule_tac x=m in exI, clarify)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    58
apply simp
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    59
apply fast
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    60
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    61
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    62
lemma eventually_constantI: "MOST i. S i = x \<Longrightarrow> eventually_constant S"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    63
unfolding eventually_constant_def by fast
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    64
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    65
lemma eventually_constant_comp:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    66
  "eventually_constant (\<lambda>i. S i) \<Longrightarrow> eventually_constant (\<lambda>i. f (S i))"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    67
unfolding eventually_constant_def
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    68
apply (erule exE, rule_tac x="f x" in exI)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    69
apply (erule MOST_mono, simp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    70
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    71
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    72
lemma eventually_constant_Suc_iff:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    73
  "eventually_constant (\<lambda>i. S (Suc i)) \<longleftrightarrow> eventually_constant (\<lambda>i. S i)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    74
unfolding eventually_constant_def
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    75
by (subst MOST_Suc_iff, rule refl)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    76
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    77
lemma eventually_constant_SucD:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    78
  "eventually_constant (\<lambda>i. S (Suc i)) \<Longrightarrow> eventually_constant (\<lambda>i. S i)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    79
by (rule eventually_constant_Suc_iff [THEN iffD1])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    80
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    81
subsection {* Limits of eventually constant sequences *}
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    82
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    83
definition
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    84
  eventual :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a" where
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    85
  "eventual S = (THE x. MOST i. S i = x)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    86
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    87
lemma eventual_eqI: "MOST i. S i = x \<Longrightarrow> eventual S = x"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    88
unfolding eventual_def
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    89
apply (rule the_equality, assumption)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    90
apply (rename_tac y)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    91
apply (subgoal_tac "MOST i::nat. y = x", simp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    92
apply (erule MOST_rev_mp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    93
apply (erule MOST_rev_mp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    94
apply simp
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    95
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    96
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    97
lemma MOST_eq_eventual:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    98
  "eventually_constant S \<Longrightarrow> MOST i. S i = eventual S"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
    99
unfolding eventually_constant_def
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   100
by (erule exE, simp add: eventual_eqI)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   101
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   102
lemma eventual_mem_range:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   103
  "eventually_constant S \<Longrightarrow> eventual S \<in> range S"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   104
apply (drule MOST_eq_eventual)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   105
apply (simp only: MOST_nat_le, clarify)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   106
apply (drule spec, drule mp, rule order_refl)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   107
apply (erule range_eqI [OF sym])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   108
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   109
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   110
lemma eventually_constant_MOST_iff:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   111
  assumes S: "eventually_constant S"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   112
  shows "(MOST n. P (S n)) \<longleftrightarrow> P (eventual S)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   113
apply (subgoal_tac "(MOST n. P (S n)) \<longleftrightarrow> (MOST n::nat. P (eventual S))")
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   114
apply simp
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   115
apply (rule iffI)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   116
apply (rule MOST_rev_mp [OF MOST_eq_eventual [OF S]])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   117
apply (erule MOST_mono, force)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   118
apply (rule MOST_rev_mp [OF MOST_eq_eventual [OF S]])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   119
apply (erule MOST_mono, simp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   120
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   121
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   122
lemma MOST_eventual:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   123
  "\<lbrakk>eventually_constant S; MOST n. P (S n)\<rbrakk> \<Longrightarrow> P (eventual S)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   124
proof -
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   125
  assume "eventually_constant S"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   126
  hence "MOST n. S n = eventual S"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   127
    by (rule MOST_eq_eventual)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   128
  moreover assume "MOST n. P (S n)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   129
  ultimately have "MOST n. S n = eventual S \<and> P (S n)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   130
    by (rule MOST_conj_distrib [THEN iffD2, OF conjI])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   131
  hence "MOST n::nat. P (eventual S)"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   132
    by (rule MOST_mono) auto
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   133
  thus ?thesis by simp
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   134
qed
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   135
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   136
lemma eventually_constant_MOST_Suc_eq:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   137
  "eventually_constant S \<Longrightarrow> MOST n. S (Suc n) = S n"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   138
apply (drule MOST_eq_eventual)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   139
apply (frule MOST_Suc_iff [THEN iffD2])
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   140
apply (erule MOST_rev_mp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   141
apply (erule MOST_rev_mp)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   142
apply simp
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   143
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   144
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   145
lemma eventual_comp:
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   146
  "eventually_constant S \<Longrightarrow> eventual (\<lambda>i. f (S i)) = f (eventual (\<lambda>i. S i))"
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   147
apply (rule eventual_eqI)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   148
apply (rule MOST_mono)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   149
apply (erule MOST_eq_eventual)
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   150
apply simp
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   151
done
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   152
22a515a55bf5 theory of eventually-constant sequences
huffman
parents:
diff changeset
   153
end