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