src/HOL/Filter.thy
author paulson <lp15@cam.ac.uk>
Mon Feb 22 14:37:56 2016 +0000 (2016-02-22)
changeset 62379 340738057c8c
parent 62378 85ed00c1fe7c
child 63343 fb5d8a50c641
permissions -rw-r--r--
An assortment of useful lemmas about sums, norm, etc. Also: norm_conv_dist [symmetric] is now a simprule!
hoelzl@60036
     1
(*  Title:      HOL/Filter.thy
hoelzl@60036
     2
    Author:     Brian Huffman
hoelzl@60036
     3
    Author:     Johannes Hölzl
hoelzl@60036
     4
*)
hoelzl@60036
     5
wenzelm@60758
     6
section \<open>Filters on predicates\<close>
hoelzl@60036
     7
hoelzl@60036
     8
theory Filter
hoelzl@60036
     9
imports Set_Interval Lifting_Set
hoelzl@60036
    10
begin
hoelzl@60036
    11
wenzelm@60758
    12
subsection \<open>Filters\<close>
hoelzl@60036
    13
wenzelm@60758
    14
text \<open>
hoelzl@60036
    15
  This definition also allows non-proper filters.
wenzelm@60758
    16
\<close>
hoelzl@60036
    17
hoelzl@60036
    18
locale is_filter =
hoelzl@60036
    19
  fixes F :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
hoelzl@60036
    20
  assumes True: "F (\<lambda>x. True)"
hoelzl@60036
    21
  assumes conj: "F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x) \<Longrightarrow> F (\<lambda>x. P x \<and> Q x)"
hoelzl@60036
    22
  assumes mono: "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x)"
hoelzl@60036
    23
hoelzl@60036
    24
typedef 'a filter = "{F :: ('a \<Rightarrow> bool) \<Rightarrow> bool. is_filter F}"
hoelzl@60036
    25
proof
hoelzl@60036
    26
  show "(\<lambda>x. True) \<in> ?filter" by (auto intro: is_filter.intro)
hoelzl@60036
    27
qed
hoelzl@60036
    28
hoelzl@60036
    29
lemma is_filter_Rep_filter: "is_filter (Rep_filter F)"
hoelzl@60036
    30
  using Rep_filter [of F] by simp
hoelzl@60036
    31
hoelzl@60036
    32
lemma Abs_filter_inverse':
hoelzl@60036
    33
  assumes "is_filter F" shows "Rep_filter (Abs_filter F) = F"
hoelzl@60036
    34
  using assms by (simp add: Abs_filter_inverse)
hoelzl@60036
    35
hoelzl@60036
    36
wenzelm@60758
    37
subsubsection \<open>Eventually\<close>
hoelzl@60036
    38
hoelzl@60036
    39
definition eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
hoelzl@60036
    40
  where "eventually P F \<longleftrightarrow> Rep_filter F P"
hoelzl@60036
    41
wenzelm@61953
    42
syntax
wenzelm@61953
    43
  "_eventually" :: "pttrn => 'a filter => bool => bool"  ("(3\<forall>\<^sub>F _ in _./ _)" [0, 0, 10] 10)
hoelzl@60037
    44
translations
hoelzl@60038
    45
  "\<forall>\<^sub>Fx in F. P" == "CONST eventually (\<lambda>x. P) F"
hoelzl@60037
    46
hoelzl@60036
    47
lemma eventually_Abs_filter:
hoelzl@60036
    48
  assumes "is_filter F" shows "eventually P (Abs_filter F) = F P"
hoelzl@60036
    49
  unfolding eventually_def using assms by (simp add: Abs_filter_inverse)
hoelzl@60036
    50
hoelzl@60036
    51
lemma filter_eq_iff:
hoelzl@60036
    52
  shows "F = F' \<longleftrightarrow> (\<forall>P. eventually P F = eventually P F')"
hoelzl@60036
    53
  unfolding Rep_filter_inject [symmetric] fun_eq_iff eventually_def ..
hoelzl@60036
    54
hoelzl@60036
    55
lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
hoelzl@60036
    56
  unfolding eventually_def
hoelzl@60036
    57
  by (rule is_filter.True [OF is_filter_Rep_filter])
hoelzl@60036
    58
hoelzl@60036
    59
lemma always_eventually: "\<forall>x. P x \<Longrightarrow> eventually P F"
hoelzl@60036
    60
proof -
hoelzl@60036
    61
  assume "\<forall>x. P x" hence "P = (\<lambda>x. True)" by (simp add: ext)
hoelzl@60036
    62
  thus "eventually P F" by simp
hoelzl@60036
    63
qed
hoelzl@60036
    64
hoelzl@60040
    65
lemma eventuallyI: "(\<And>x. P x) \<Longrightarrow> eventually P F"
hoelzl@60040
    66
  by (auto intro: always_eventually)
hoelzl@60040
    67
hoelzl@60036
    68
lemma eventually_mono:
lp15@61806
    69
  "\<lbrakk>eventually P F; \<And>x. P x \<Longrightarrow> Q x\<rbrakk> \<Longrightarrow> eventually Q F"
lp15@61806
    70
  unfolding eventually_def
lp15@61806
    71
  by (blast intro: is_filter.mono [OF is_filter_Rep_filter])
lp15@61806
    72
hoelzl@60036
    73
lemma eventually_conj:
hoelzl@60036
    74
  assumes P: "eventually (\<lambda>x. P x) F"
hoelzl@60036
    75
  assumes Q: "eventually (\<lambda>x. Q x) F"
hoelzl@60036
    76
  shows "eventually (\<lambda>x. P x \<and> Q x) F"
hoelzl@60036
    77
  using assms unfolding eventually_def
hoelzl@60036
    78
  by (rule is_filter.conj [OF is_filter_Rep_filter])
hoelzl@60036
    79
hoelzl@60036
    80
lemma eventually_mp:
hoelzl@60036
    81
  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
hoelzl@60036
    82
  assumes "eventually (\<lambda>x. P x) F"
hoelzl@60036
    83
  shows "eventually (\<lambda>x. Q x) F"
lp15@61806
    84
proof -
lp15@61806
    85
  have "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) F"
hoelzl@60036
    86
    using assms by (rule eventually_conj)
lp15@61806
    87
  then show ?thesis
lp15@61810
    88
    by (blast intro: eventually_mono)
hoelzl@60036
    89
qed
hoelzl@60036
    90
hoelzl@60036
    91
lemma eventually_rev_mp:
hoelzl@60036
    92
  assumes "eventually (\<lambda>x. P x) F"
hoelzl@60036
    93
  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
hoelzl@60036
    94
  shows "eventually (\<lambda>x. Q x) F"
hoelzl@60036
    95
using assms(2) assms(1) by (rule eventually_mp)
hoelzl@60036
    96
hoelzl@60036
    97
lemma eventually_conj_iff:
hoelzl@60036
    98
  "eventually (\<lambda>x. P x \<and> Q x) F \<longleftrightarrow> eventually P F \<and> eventually Q F"
hoelzl@60036
    99
  by (auto intro: eventually_conj elim: eventually_rev_mp)
hoelzl@60036
   100
hoelzl@60036
   101
lemma eventually_elim2:
hoelzl@60036
   102
  assumes "eventually (\<lambda>i. P i) F"
hoelzl@60036
   103
  assumes "eventually (\<lambda>i. Q i) F"
hoelzl@60036
   104
  assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
hoelzl@60036
   105
  shows "eventually (\<lambda>i. R i) F"
hoelzl@60036
   106
  using assms by (auto elim!: eventually_rev_mp)
hoelzl@60036
   107
hoelzl@60040
   108
lemma eventually_ball_finite_distrib:
hoelzl@60040
   109
  "finite A \<Longrightarrow> (eventually (\<lambda>x. \<forall>y\<in>A. P x y) net) \<longleftrightarrow> (\<forall>y\<in>A. eventually (\<lambda>x. P x y) net)"
hoelzl@60040
   110
  by (induction A rule: finite_induct) (auto simp: eventually_conj_iff)
hoelzl@60040
   111
hoelzl@60040
   112
lemma eventually_ball_finite:
hoelzl@60040
   113
  "finite A \<Longrightarrow> \<forall>y\<in>A. eventually (\<lambda>x. P x y) net \<Longrightarrow> eventually (\<lambda>x. \<forall>y\<in>A. P x y) net"
hoelzl@60040
   114
  by (auto simp: eventually_ball_finite_distrib)
hoelzl@60040
   115
hoelzl@60040
   116
lemma eventually_all_finite:
hoelzl@60040
   117
  fixes P :: "'a \<Rightarrow> 'b::finite \<Rightarrow> bool"
hoelzl@60040
   118
  assumes "\<And>y. eventually (\<lambda>x. P x y) net"
hoelzl@60040
   119
  shows "eventually (\<lambda>x. \<forall>y. P x y) net"
hoelzl@60040
   120
using eventually_ball_finite [of UNIV P] assms by simp
hoelzl@60040
   121
hoelzl@60040
   122
lemma eventually_ex: "(\<forall>\<^sub>Fx in F. \<exists>y. P x y) \<longleftrightarrow> (\<exists>Y. \<forall>\<^sub>Fx in F. P x (Y x))"
hoelzl@60040
   123
proof
hoelzl@60040
   124
  assume "\<forall>\<^sub>Fx in F. \<exists>y. P x y"
hoelzl@60040
   125
  then have "\<forall>\<^sub>Fx in F. P x (SOME y. P x y)"
lp15@61810
   126
    by (auto intro: someI_ex eventually_mono)
hoelzl@60040
   127
  then show "\<exists>Y. \<forall>\<^sub>Fx in F. P x (Y x)"
hoelzl@60040
   128
    by auto
lp15@61810
   129
qed (auto intro: eventually_mono)
hoelzl@60040
   130
hoelzl@60036
   131
lemma not_eventually_impI: "eventually P F \<Longrightarrow> \<not> eventually Q F \<Longrightarrow> \<not> eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
hoelzl@60036
   132
  by (auto intro: eventually_mp)
hoelzl@60036
   133
hoelzl@60036
   134
lemma not_eventuallyD: "\<not> eventually P F \<Longrightarrow> \<exists>x. \<not> P x"
hoelzl@60036
   135
  by (metis always_eventually)
hoelzl@60036
   136
hoelzl@60036
   137
lemma eventually_subst:
hoelzl@60036
   138
  assumes "eventually (\<lambda>n. P n = Q n) F"
hoelzl@60036
   139
  shows "eventually P F = eventually Q F" (is "?L = ?R")
hoelzl@60036
   140
proof -
hoelzl@60036
   141
  from assms have "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
hoelzl@60036
   142
      and "eventually (\<lambda>x. Q x \<longrightarrow> P x) F"
lp15@61810
   143
    by (auto elim: eventually_mono)
hoelzl@60036
   144
  then show ?thesis by (auto elim: eventually_elim2)
hoelzl@60036
   145
qed
hoelzl@60036
   146
hoelzl@60040
   147
subsection \<open> Frequently as dual to eventually \<close>
hoelzl@60040
   148
hoelzl@60040
   149
definition frequently :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
hoelzl@60040
   150
  where "frequently P F \<longleftrightarrow> \<not> eventually (\<lambda>x. \<not> P x) F"
hoelzl@60040
   151
wenzelm@61953
   152
syntax
wenzelm@61953
   153
  "_frequently" :: "pttrn \<Rightarrow> 'a filter \<Rightarrow> bool \<Rightarrow> bool"  ("(3\<exists>\<^sub>F _ in _./ _)" [0, 0, 10] 10)
hoelzl@60040
   154
translations
hoelzl@60040
   155
  "\<exists>\<^sub>Fx in F. P" == "CONST frequently (\<lambda>x. P) F"
hoelzl@60040
   156
hoelzl@60040
   157
lemma not_frequently_False [simp]: "\<not> (\<exists>\<^sub>Fx in F. False)"
hoelzl@60040
   158
  by (simp add: frequently_def)
hoelzl@60040
   159
hoelzl@60040
   160
lemma frequently_ex: "\<exists>\<^sub>Fx in F. P x \<Longrightarrow> \<exists>x. P x"
hoelzl@60040
   161
  by (auto simp: frequently_def dest: not_eventuallyD)
hoelzl@60040
   162
hoelzl@60040
   163
lemma frequentlyE: assumes "frequently P F" obtains x where "P x"
hoelzl@60040
   164
  using frequently_ex[OF assms] by auto
hoelzl@60040
   165
hoelzl@60040
   166
lemma frequently_mp:
hoelzl@60040
   167
  assumes ev: "\<forall>\<^sub>Fx in F. P x \<longrightarrow> Q x" and P: "\<exists>\<^sub>Fx in F. P x" shows "\<exists>\<^sub>Fx in F. Q x"
lp15@61806
   168
proof -
hoelzl@60040
   169
  from ev have "eventually (\<lambda>x. \<not> Q x \<longrightarrow> \<not> P x) F"
hoelzl@60040
   170
    by (rule eventually_rev_mp) (auto intro!: always_eventually)
hoelzl@60040
   171
  from eventually_mp[OF this] P show ?thesis
hoelzl@60040
   172
    by (auto simp: frequently_def)
hoelzl@60040
   173
qed
hoelzl@60040
   174
hoelzl@60040
   175
lemma frequently_rev_mp:
hoelzl@60040
   176
  assumes "\<exists>\<^sub>Fx in F. P x"
hoelzl@60040
   177
  assumes "\<forall>\<^sub>Fx in F. P x \<longrightarrow> Q x"
hoelzl@60040
   178
  shows "\<exists>\<^sub>Fx in F. Q x"
hoelzl@60040
   179
using assms(2) assms(1) by (rule frequently_mp)
hoelzl@60040
   180
hoelzl@60040
   181
lemma frequently_mono: "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> frequently P F \<Longrightarrow> frequently Q F"
hoelzl@60040
   182
  using frequently_mp[of P Q] by (simp add: always_eventually)
hoelzl@60040
   183
hoelzl@60040
   184
lemma frequently_elim1: "\<exists>\<^sub>Fx in F. P x \<Longrightarrow> (\<And>i. P i \<Longrightarrow> Q i) \<Longrightarrow> \<exists>\<^sub>Fx in F. Q x"
hoelzl@60040
   185
  by (metis frequently_mono)
hoelzl@60040
   186
hoelzl@60040
   187
lemma frequently_disj_iff: "(\<exists>\<^sub>Fx in F. P x \<or> Q x) \<longleftrightarrow> (\<exists>\<^sub>Fx in F. P x) \<or> (\<exists>\<^sub>Fx in F. Q x)"
hoelzl@60040
   188
  by (simp add: frequently_def eventually_conj_iff)
hoelzl@60040
   189
hoelzl@60040
   190
lemma frequently_disj: "\<exists>\<^sub>Fx in F. P x \<Longrightarrow> \<exists>\<^sub>Fx in F. Q x \<Longrightarrow> \<exists>\<^sub>Fx in F. P x \<or> Q x"
hoelzl@60040
   191
  by (simp add: frequently_disj_iff)
hoelzl@60040
   192
hoelzl@60040
   193
lemma frequently_bex_finite_distrib:
hoelzl@60040
   194
  assumes "finite A" shows "(\<exists>\<^sub>Fx in F. \<exists>y\<in>A. P x y) \<longleftrightarrow> (\<exists>y\<in>A. \<exists>\<^sub>Fx in F. P x y)"
hoelzl@60040
   195
  using assms by induction (auto simp: frequently_disj_iff)
hoelzl@60040
   196
hoelzl@60040
   197
lemma frequently_bex_finite: "finite A \<Longrightarrow> \<exists>\<^sub>Fx in F. \<exists>y\<in>A. P x y \<Longrightarrow> \<exists>y\<in>A. \<exists>\<^sub>Fx in F. P x y"
hoelzl@60040
   198
  by (simp add: frequently_bex_finite_distrib)
hoelzl@60040
   199
hoelzl@60040
   200
lemma frequently_all: "(\<exists>\<^sub>Fx in F. \<forall>y. P x y) \<longleftrightarrow> (\<forall>Y. \<exists>\<^sub>Fx in F. P x (Y x))"
hoelzl@60040
   201
  using eventually_ex[of "\<lambda>x y. \<not> P x y" F] by (simp add: frequently_def)
hoelzl@60040
   202
hoelzl@60040
   203
lemma
hoelzl@60040
   204
  shows not_eventually: "\<not> eventually P F \<longleftrightarrow> (\<exists>\<^sub>Fx in F. \<not> P x)"
hoelzl@60040
   205
    and not_frequently: "\<not> frequently P F \<longleftrightarrow> (\<forall>\<^sub>Fx in F. \<not> P x)"
hoelzl@60040
   206
  by (auto simp: frequently_def)
hoelzl@60040
   207
hoelzl@60040
   208
lemma frequently_imp_iff:
hoelzl@60040
   209
  "(\<exists>\<^sub>Fx in F. P x \<longrightarrow> Q x) \<longleftrightarrow> (eventually P F \<longrightarrow> frequently Q F)"
hoelzl@60040
   210
  unfolding imp_conv_disj frequently_disj_iff not_eventually[symmetric] ..
hoelzl@60040
   211
hoelzl@60040
   212
lemma eventually_frequently_const_simps:
hoelzl@60040
   213
  "(\<exists>\<^sub>Fx in F. P x \<and> C) \<longleftrightarrow> (\<exists>\<^sub>Fx in F. P x) \<and> C"
hoelzl@60040
   214
  "(\<exists>\<^sub>Fx in F. C \<and> P x) \<longleftrightarrow> C \<and> (\<exists>\<^sub>Fx in F. P x)"
hoelzl@60040
   215
  "(\<forall>\<^sub>Fx in F. P x \<or> C) \<longleftrightarrow> (\<forall>\<^sub>Fx in F. P x) \<or> C"
hoelzl@60040
   216
  "(\<forall>\<^sub>Fx in F. C \<or> P x) \<longleftrightarrow> C \<or> (\<forall>\<^sub>Fx in F. P x)"
hoelzl@60040
   217
  "(\<forall>\<^sub>Fx in F. P x \<longrightarrow> C) \<longleftrightarrow> ((\<exists>\<^sub>Fx in F. P x) \<longrightarrow> C)"
hoelzl@60040
   218
  "(\<forall>\<^sub>Fx in F. C \<longrightarrow> P x) \<longleftrightarrow> (C \<longrightarrow> (\<forall>\<^sub>Fx in F. P x))"
hoelzl@60040
   219
  by (cases C; simp add: not_frequently)+
hoelzl@60040
   220
lp15@61806
   221
lemmas eventually_frequently_simps =
hoelzl@60040
   222
  eventually_frequently_const_simps
hoelzl@60040
   223
  not_eventually
hoelzl@60040
   224
  eventually_conj_iff
hoelzl@60040
   225
  eventually_ball_finite_distrib
hoelzl@60040
   226
  eventually_ex
hoelzl@60040
   227
  not_frequently
hoelzl@60040
   228
  frequently_disj_iff
hoelzl@60040
   229
  frequently_bex_finite_distrib
hoelzl@60040
   230
  frequently_all
hoelzl@60040
   231
  frequently_imp_iff
hoelzl@60040
   232
wenzelm@60758
   233
ML \<open>
wenzelm@61841
   234
  fun eventually_elim_tac facts =
wenzelm@61841
   235
    CONTEXT_SUBGOAL (fn (goal, i) => fn (ctxt, st) =>
wenzelm@61841
   236
      let
wenzelm@61841
   237
        val mp_thms = facts RL @{thms eventually_rev_mp}
wenzelm@61841
   238
        val raw_elim_thm =
wenzelm@61841
   239
          (@{thm allI} RS @{thm always_eventually})
wenzelm@61841
   240
          |> fold (fn thm1 => fn thm2 => thm2 RS thm1) mp_thms
wenzelm@61841
   241
          |> fold (fn _ => fn thm => @{thm impI} RS thm) facts
wenzelm@61841
   242
        val cases_prop =
wenzelm@61841
   243
          Thm.prop_of
wenzelm@61841
   244
            (Rule_Cases.internalize_params (raw_elim_thm RS Goal.init (Thm.cterm_of ctxt goal)))
wenzelm@61841
   245
        val cases = Rule_Cases.make_common ctxt cases_prop [(("elim", []), [])]
wenzelm@61841
   246
      in CONTEXT_CASES cases (resolve_tac ctxt [raw_elim_thm] i) (ctxt, st) end)
wenzelm@60758
   247
\<close>
hoelzl@60036
   248
wenzelm@60758
   249
method_setup eventually_elim = \<open>
wenzelm@61841
   250
  Scan.succeed (fn _ => CONTEXT_METHOD (fn facts => eventually_elim_tac facts 1))
wenzelm@60758
   251
\<close> "elimination of eventually quantifiers"
hoelzl@60036
   252
wenzelm@60758
   253
subsubsection \<open>Finer-than relation\<close>
hoelzl@60036
   254
wenzelm@60758
   255
text \<open>@{term "F \<le> F'"} means that filter @{term F} is finer than
wenzelm@60758
   256
filter @{term F'}.\<close>
hoelzl@60036
   257
hoelzl@60036
   258
instantiation filter :: (type) complete_lattice
hoelzl@60036
   259
begin
hoelzl@60036
   260
hoelzl@60036
   261
definition le_filter_def:
hoelzl@60036
   262
  "F \<le> F' \<longleftrightarrow> (\<forall>P. eventually P F' \<longrightarrow> eventually P F)"
hoelzl@60036
   263
hoelzl@60036
   264
definition
hoelzl@60036
   265
  "(F :: 'a filter) < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
hoelzl@60036
   266
hoelzl@60036
   267
definition
hoelzl@60036
   268
  "top = Abs_filter (\<lambda>P. \<forall>x. P x)"
hoelzl@60036
   269
hoelzl@60036
   270
definition
hoelzl@60036
   271
  "bot = Abs_filter (\<lambda>P. True)"
hoelzl@60036
   272
hoelzl@60036
   273
definition
hoelzl@60036
   274
  "sup F F' = Abs_filter (\<lambda>P. eventually P F \<and> eventually P F')"
hoelzl@60036
   275
hoelzl@60036
   276
definition
hoelzl@60036
   277
  "inf F F' = Abs_filter
hoelzl@60036
   278
      (\<lambda>P. \<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
hoelzl@60036
   279
hoelzl@60036
   280
definition
hoelzl@60036
   281
  "Sup S = Abs_filter (\<lambda>P. \<forall>F\<in>S. eventually P F)"
hoelzl@60036
   282
hoelzl@60036
   283
definition
hoelzl@60036
   284
  "Inf S = Sup {F::'a filter. \<forall>F'\<in>S. F \<le> F'}"
hoelzl@60036
   285
hoelzl@60036
   286
lemma eventually_top [simp]: "eventually P top \<longleftrightarrow> (\<forall>x. P x)"
hoelzl@60036
   287
  unfolding top_filter_def
hoelzl@60036
   288
  by (rule eventually_Abs_filter, rule is_filter.intro, auto)
hoelzl@60036
   289
hoelzl@60036
   290
lemma eventually_bot [simp]: "eventually P bot"
hoelzl@60036
   291
  unfolding bot_filter_def
hoelzl@60036
   292
  by (subst eventually_Abs_filter, rule is_filter.intro, auto)
hoelzl@60036
   293
hoelzl@60036
   294
lemma eventually_sup:
hoelzl@60036
   295
  "eventually P (sup F F') \<longleftrightarrow> eventually P F \<and> eventually P F'"
hoelzl@60036
   296
  unfolding sup_filter_def
hoelzl@60036
   297
  by (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@60036
   298
     (auto elim!: eventually_rev_mp)
hoelzl@60036
   299
hoelzl@60036
   300
lemma eventually_inf:
hoelzl@60036
   301
  "eventually P (inf F F') \<longleftrightarrow>
hoelzl@60036
   302
   (\<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
hoelzl@60036
   303
  unfolding inf_filter_def
hoelzl@60036
   304
  apply (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@60036
   305
  apply (fast intro: eventually_True)
hoelzl@60036
   306
  apply clarify
hoelzl@60036
   307
  apply (intro exI conjI)
hoelzl@60036
   308
  apply (erule (1) eventually_conj)
hoelzl@60036
   309
  apply (erule (1) eventually_conj)
hoelzl@60036
   310
  apply simp
hoelzl@60036
   311
  apply auto
hoelzl@60036
   312
  done
hoelzl@60036
   313
hoelzl@60036
   314
lemma eventually_Sup:
hoelzl@60036
   315
  "eventually P (Sup S) \<longleftrightarrow> (\<forall>F\<in>S. eventually P F)"
hoelzl@60036
   316
  unfolding Sup_filter_def
hoelzl@60036
   317
  apply (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@60036
   318
  apply (auto intro: eventually_conj elim!: eventually_rev_mp)
hoelzl@60036
   319
  done
hoelzl@60036
   320
hoelzl@60036
   321
instance proof
hoelzl@60036
   322
  fix F F' F'' :: "'a filter" and S :: "'a filter set"
hoelzl@60036
   323
  { show "F < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
hoelzl@60036
   324
    by (rule less_filter_def) }
hoelzl@60036
   325
  { show "F \<le> F"
hoelzl@60036
   326
    unfolding le_filter_def by simp }
hoelzl@60036
   327
  { assume "F \<le> F'" and "F' \<le> F''" thus "F \<le> F''"
hoelzl@60036
   328
    unfolding le_filter_def by simp }
hoelzl@60036
   329
  { assume "F \<le> F'" and "F' \<le> F" thus "F = F'"
hoelzl@60036
   330
    unfolding le_filter_def filter_eq_iff by fast }
hoelzl@60036
   331
  { show "inf F F' \<le> F" and "inf F F' \<le> F'"
hoelzl@60036
   332
    unfolding le_filter_def eventually_inf by (auto intro: eventually_True) }
hoelzl@60036
   333
  { assume "F \<le> F'" and "F \<le> F''" thus "F \<le> inf F' F''"
hoelzl@60036
   334
    unfolding le_filter_def eventually_inf
lp15@61810
   335
    by (auto intro: eventually_mono [OF eventually_conj]) }
hoelzl@60036
   336
  { show "F \<le> sup F F'" and "F' \<le> sup F F'"
hoelzl@60036
   337
    unfolding le_filter_def eventually_sup by simp_all }
hoelzl@60036
   338
  { assume "F \<le> F''" and "F' \<le> F''" thus "sup F F' \<le> F''"
hoelzl@60036
   339
    unfolding le_filter_def eventually_sup by simp }
hoelzl@60036
   340
  { assume "F'' \<in> S" thus "Inf S \<le> F''"
hoelzl@60036
   341
    unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
hoelzl@60036
   342
  { assume "\<And>F'. F' \<in> S \<Longrightarrow> F \<le> F'" thus "F \<le> Inf S"
hoelzl@60036
   343
    unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
hoelzl@60036
   344
  { assume "F \<in> S" thus "F \<le> Sup S"
hoelzl@60036
   345
    unfolding le_filter_def eventually_Sup by simp }
hoelzl@60036
   346
  { assume "\<And>F. F \<in> S \<Longrightarrow> F \<le> F'" thus "Sup S \<le> F'"
hoelzl@60036
   347
    unfolding le_filter_def eventually_Sup by simp }
hoelzl@60036
   348
  { show "Inf {} = (top::'a filter)"
hoelzl@60036
   349
    by (auto simp: top_filter_def Inf_filter_def Sup_filter_def)
hoelzl@60036
   350
      (metis (full_types) top_filter_def always_eventually eventually_top) }
hoelzl@60036
   351
  { show "Sup {} = (bot::'a filter)"
hoelzl@60036
   352
    by (auto simp: bot_filter_def Sup_filter_def) }
hoelzl@60036
   353
qed
hoelzl@60036
   354
hoelzl@60036
   355
end
hoelzl@60036
   356
hoelzl@60036
   357
lemma filter_leD:
hoelzl@60036
   358
  "F \<le> F' \<Longrightarrow> eventually P F' \<Longrightarrow> eventually P F"
hoelzl@60036
   359
  unfolding le_filter_def by simp
hoelzl@60036
   360
hoelzl@60036
   361
lemma filter_leI:
hoelzl@60036
   362
  "(\<And>P. eventually P F' \<Longrightarrow> eventually P F) \<Longrightarrow> F \<le> F'"
hoelzl@60036
   363
  unfolding le_filter_def by simp
hoelzl@60036
   364
hoelzl@60036
   365
lemma eventually_False:
hoelzl@60036
   366
  "eventually (\<lambda>x. False) F \<longleftrightarrow> F = bot"
hoelzl@60036
   367
  unfolding filter_eq_iff by (auto elim: eventually_rev_mp)
hoelzl@60036
   368
hoelzl@60040
   369
lemma eventually_frequently: "F \<noteq> bot \<Longrightarrow> eventually P F \<Longrightarrow> frequently P F"
hoelzl@60040
   370
  using eventually_conj[of P F "\<lambda>x. \<not> P x"]
hoelzl@60040
   371
  by (auto simp add: frequently_def eventually_False)
hoelzl@60040
   372
hoelzl@60040
   373
lemma eventually_const_iff: "eventually (\<lambda>x. P) F \<longleftrightarrow> P \<or> F = bot"
hoelzl@60040
   374
  by (cases P) (auto simp: eventually_False)
hoelzl@60040
   375
hoelzl@60040
   376
lemma eventually_const[simp]: "F \<noteq> bot \<Longrightarrow> eventually (\<lambda>x. P) F \<longleftrightarrow> P"
hoelzl@60040
   377
  by (simp add: eventually_const_iff)
hoelzl@60040
   378
hoelzl@60040
   379
lemma frequently_const_iff: "frequently (\<lambda>x. P) F \<longleftrightarrow> P \<and> F \<noteq> bot"
hoelzl@60040
   380
  by (simp add: frequently_def eventually_const_iff)
hoelzl@60040
   381
hoelzl@60040
   382
lemma frequently_const[simp]: "F \<noteq> bot \<Longrightarrow> frequently (\<lambda>x. P) F \<longleftrightarrow> P"
hoelzl@60040
   383
  by (simp add: frequently_const_iff)
hoelzl@60040
   384
hoelzl@61245
   385
lemma eventually_happens: "eventually P net \<Longrightarrow> net = bot \<or> (\<exists>x. P x)"
hoelzl@61245
   386
  by (metis frequentlyE eventually_frequently)
hoelzl@61245
   387
eberlm@61531
   388
lemma eventually_happens':
eberlm@61531
   389
  assumes "F \<noteq> bot" "eventually P F"
eberlm@61531
   390
  shows   "\<exists>x. P x"
eberlm@61531
   391
  using assms eventually_frequently frequentlyE by blast
eberlm@61531
   392
hoelzl@60036
   393
abbreviation (input) trivial_limit :: "'a filter \<Rightarrow> bool"
hoelzl@60036
   394
  where "trivial_limit F \<equiv> F = bot"
hoelzl@60036
   395
hoelzl@60036
   396
lemma trivial_limit_def: "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
hoelzl@60036
   397
  by (rule eventually_False [symmetric])
hoelzl@60036
   398
lp15@61806
   399
lemma False_imp_not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> \<not> trivial_limit net \<Longrightarrow> \<not> eventually (\<lambda>x. P x) net"
lp15@61806
   400
  by (simp add: eventually_False)
lp15@61806
   401
hoelzl@60036
   402
lemma eventually_Inf: "eventually P (Inf B) \<longleftrightarrow> (\<exists>X\<subseteq>B. finite X \<and> eventually P (Inf X))"
hoelzl@60036
   403
proof -
hoelzl@60036
   404
  let ?F = "\<lambda>P. \<exists>X\<subseteq>B. finite X \<and> eventually P (Inf X)"
lp15@61806
   405
hoelzl@60036
   406
  { fix P have "eventually P (Abs_filter ?F) \<longleftrightarrow> ?F P"
hoelzl@60036
   407
    proof (rule eventually_Abs_filter is_filter.intro)+
hoelzl@60036
   408
      show "?F (\<lambda>x. True)"
hoelzl@60036
   409
        by (rule exI[of _ "{}"]) (simp add: le_fun_def)
hoelzl@60036
   410
    next
hoelzl@60036
   411
      fix P Q
hoelzl@60036
   412
      assume "?F P" then guess X ..
hoelzl@60036
   413
      moreover
hoelzl@60036
   414
      assume "?F Q" then guess Y ..
hoelzl@60036
   415
      ultimately show "?F (\<lambda>x. P x \<and> Q x)"
hoelzl@60036
   416
        by (intro exI[of _ "X \<union> Y"])
hoelzl@60036
   417
           (auto simp: Inf_union_distrib eventually_inf)
hoelzl@60036
   418
    next
hoelzl@60036
   419
      fix P Q
hoelzl@60036
   420
      assume "?F P" then guess X ..
hoelzl@60036
   421
      moreover assume "\<forall>x. P x \<longrightarrow> Q x"
hoelzl@60036
   422
      ultimately show "?F Q"
lp15@61810
   423
        by (intro exI[of _ X]) (auto elim: eventually_mono)
hoelzl@60036
   424
    qed }
hoelzl@60036
   425
  note eventually_F = this
hoelzl@60036
   426
hoelzl@60036
   427
  have "Inf B = Abs_filter ?F"
hoelzl@60036
   428
  proof (intro antisym Inf_greatest)
hoelzl@60036
   429
    show "Inf B \<le> Abs_filter ?F"
hoelzl@60036
   430
      by (auto simp: le_filter_def eventually_F dest: Inf_superset_mono)
hoelzl@60036
   431
  next
hoelzl@60036
   432
    fix F assume "F \<in> B" then show "Abs_filter ?F \<le> F"
hoelzl@60036
   433
      by (auto simp add: le_filter_def eventually_F intro!: exI[of _ "{F}"])
hoelzl@60036
   434
  qed
hoelzl@60036
   435
  then show ?thesis
hoelzl@60036
   436
    by (simp add: eventually_F)
hoelzl@60036
   437
qed
hoelzl@60036
   438
hoelzl@60036
   439
lemma eventually_INF: "eventually P (INF b:B. F b) \<longleftrightarrow> (\<exists>X\<subseteq>B. finite X \<and> eventually P (INF b:X. F b))"
haftmann@62343
   440
  unfolding eventually_Inf [of P "F`B"]
haftmann@62343
   441
  by (metis finite_imageI image_mono finite_subset_image)
hoelzl@60036
   442
hoelzl@60036
   443
lemma Inf_filter_not_bot:
hoelzl@60036
   444
  fixes B :: "'a filter set"
hoelzl@60036
   445
  shows "(\<And>X. X \<subseteq> B \<Longrightarrow> finite X \<Longrightarrow> Inf X \<noteq> bot) \<Longrightarrow> Inf B \<noteq> bot"
hoelzl@60036
   446
  unfolding trivial_limit_def eventually_Inf[of _ B]
hoelzl@60036
   447
    bot_bool_def [symmetric] bot_fun_def [symmetric] bot_unique by simp
hoelzl@60036
   448
hoelzl@60036
   449
lemma INF_filter_not_bot:
hoelzl@60036
   450
  fixes F :: "'i \<Rightarrow> 'a filter"
hoelzl@60036
   451
  shows "(\<And>X. X \<subseteq> B \<Longrightarrow> finite X \<Longrightarrow> (INF b:X. F b) \<noteq> bot) \<Longrightarrow> (INF b:B. F b) \<noteq> bot"
haftmann@62343
   452
  unfolding trivial_limit_def eventually_INF [of _ _ B]
hoelzl@60036
   453
    bot_bool_def [symmetric] bot_fun_def [symmetric] bot_unique by simp
hoelzl@60036
   454
hoelzl@60036
   455
lemma eventually_Inf_base:
hoelzl@60036
   456
  assumes "B \<noteq> {}" and base: "\<And>F G. F \<in> B \<Longrightarrow> G \<in> B \<Longrightarrow> \<exists>x\<in>B. x \<le> inf F G"
hoelzl@60036
   457
  shows "eventually P (Inf B) \<longleftrightarrow> (\<exists>b\<in>B. eventually P b)"
hoelzl@60036
   458
proof (subst eventually_Inf, safe)
hoelzl@60036
   459
  fix X assume "finite X" "X \<subseteq> B"
hoelzl@60036
   460
  then have "\<exists>b\<in>B. \<forall>x\<in>X. b \<le> x"
hoelzl@60036
   461
  proof induct
hoelzl@60036
   462
    case empty then show ?case
wenzelm@60758
   463
      using \<open>B \<noteq> {}\<close> by auto
hoelzl@60036
   464
  next
hoelzl@60036
   465
    case (insert x X)
hoelzl@60036
   466
    then obtain b where "b \<in> B" "\<And>x. x \<in> X \<Longrightarrow> b \<le> x"
hoelzl@60036
   467
      by auto
wenzelm@60758
   468
    with \<open>insert x X \<subseteq> B\<close> base[of b x] show ?case
hoelzl@60036
   469
      by (auto intro: order_trans)
hoelzl@60036
   470
  qed
hoelzl@60036
   471
  then obtain b where "b \<in> B" "b \<le> Inf X"
hoelzl@60036
   472
    by (auto simp: le_Inf_iff)
hoelzl@60036
   473
  then show "eventually P (Inf X) \<Longrightarrow> Bex B (eventually P)"
hoelzl@60036
   474
    by (intro bexI[of _ b]) (auto simp: le_filter_def)
hoelzl@60036
   475
qed (auto intro!: exI[of _ "{x}" for x])
hoelzl@60036
   476
hoelzl@60036
   477
lemma eventually_INF_base:
hoelzl@60036
   478
  "B \<noteq> {} \<Longrightarrow> (\<And>a b. a \<in> B \<Longrightarrow> b \<in> B \<Longrightarrow> \<exists>x\<in>B. F x \<le> inf (F a) (F b)) \<Longrightarrow>
hoelzl@60036
   479
    eventually P (INF b:B. F b) \<longleftrightarrow> (\<exists>b\<in>B. eventually P (F b))"
haftmann@62343
   480
  by (subst eventually_Inf_base) auto
hoelzl@60036
   481
hoelzl@62369
   482
lemma eventually_INF1: "i \<in> I \<Longrightarrow> eventually P (F i) \<Longrightarrow> eventually P (INF i:I. F i)"
hoelzl@62369
   483
  using filter_leD[OF INF_lower] .
hoelzl@62369
   484
hoelzl@62367
   485
lemma eventually_INF_mono:
hoelzl@62367
   486
  assumes *: "\<forall>\<^sub>F x in \<Sqinter>i\<in>I. F i. P x"
hoelzl@62367
   487
  assumes T1: "\<And>Q R P. (\<And>x. Q x \<and> R x \<longrightarrow> P x) \<Longrightarrow> (\<And>x. T Q x \<Longrightarrow> T R x \<Longrightarrow> T P x)"
hoelzl@62367
   488
  assumes T2: "\<And>P. (\<And>x. P x) \<Longrightarrow> (\<And>x. T P x)"
hoelzl@62367
   489
  assumes **: "\<And>i P. i \<in> I \<Longrightarrow> \<forall>\<^sub>F x in F i. P x \<Longrightarrow> \<forall>\<^sub>F x in F' i. T P x"
hoelzl@62367
   490
  shows "\<forall>\<^sub>F x in \<Sqinter>i\<in>I. F' i. T P x"
hoelzl@62367
   491
proof -
hoelzl@62367
   492
  from * obtain X where "finite X" "X \<subseteq> I" "\<forall>\<^sub>F x in \<Sqinter>i\<in>X. F i. P x"
hoelzl@62378
   493
    unfolding eventually_INF[of _ _ I] by auto
hoelzl@62367
   494
  moreover then have "eventually (T P) (INFIMUM X F')"
hoelzl@62367
   495
    apply (induction X arbitrary: P)
hoelzl@62367
   496
    apply (auto simp: eventually_inf T2)
hoelzl@62367
   497
    subgoal for x S P Q R
hoelzl@62367
   498
      apply (intro exI[of _ "T Q"])
hoelzl@62367
   499
      apply (auto intro!: **) []
hoelzl@62367
   500
      apply (intro exI[of _ "T R"])
hoelzl@62367
   501
      apply (auto intro: T1) []
hoelzl@62367
   502
      done
hoelzl@62367
   503
    done
hoelzl@62367
   504
  ultimately show "\<forall>\<^sub>F x in \<Sqinter>i\<in>I. F' i. T P x"
hoelzl@62367
   505
    by (subst eventually_INF) auto
hoelzl@62367
   506
qed
hoelzl@62367
   507
hoelzl@60036
   508
wenzelm@60758
   509
subsubsection \<open>Map function for filters\<close>
hoelzl@60036
   510
hoelzl@60036
   511
definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
hoelzl@60036
   512
  where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
hoelzl@60036
   513
hoelzl@60036
   514
lemma eventually_filtermap:
hoelzl@60036
   515
  "eventually P (filtermap f F) = eventually (\<lambda>x. P (f x)) F"
hoelzl@60036
   516
  unfolding filtermap_def
hoelzl@60036
   517
  apply (rule eventually_Abs_filter)
hoelzl@60036
   518
  apply (rule is_filter.intro)
hoelzl@60036
   519
  apply (auto elim!: eventually_rev_mp)
hoelzl@60036
   520
  done
hoelzl@60036
   521
hoelzl@60036
   522
lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
hoelzl@60036
   523
  by (simp add: filter_eq_iff eventually_filtermap)
hoelzl@60036
   524
hoelzl@60036
   525
lemma filtermap_filtermap:
hoelzl@60036
   526
  "filtermap f (filtermap g F) = filtermap (\<lambda>x. f (g x)) F"
hoelzl@60036
   527
  by (simp add: filter_eq_iff eventually_filtermap)
hoelzl@60036
   528
hoelzl@60036
   529
lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
hoelzl@60036
   530
  unfolding le_filter_def eventually_filtermap by simp
hoelzl@60036
   531
hoelzl@60036
   532
lemma filtermap_bot [simp]: "filtermap f bot = bot"
hoelzl@60036
   533
  by (simp add: filter_eq_iff eventually_filtermap)
hoelzl@60036
   534
hoelzl@60036
   535
lemma filtermap_sup: "filtermap f (sup F1 F2) = sup (filtermap f F1) (filtermap f F2)"
hoelzl@60036
   536
  by (auto simp: filter_eq_iff eventually_filtermap eventually_sup)
hoelzl@60036
   537
hoelzl@60036
   538
lemma filtermap_inf: "filtermap f (inf F1 F2) \<le> inf (filtermap f F1) (filtermap f F2)"
hoelzl@60036
   539
  by (auto simp: le_filter_def eventually_filtermap eventually_inf)
hoelzl@60036
   540
hoelzl@60036
   541
lemma filtermap_INF: "filtermap f (INF b:B. F b) \<le> (INF b:B. filtermap f (F b))"
hoelzl@60036
   542
proof -
hoelzl@60036
   543
  { fix X :: "'c set" assume "finite X"
hoelzl@60036
   544
    then have "filtermap f (INFIMUM X F) \<le> (INF b:X. filtermap f (F b))"
hoelzl@60036
   545
    proof induct
hoelzl@60036
   546
      case (insert x X)
hoelzl@60036
   547
      have "filtermap f (INF a:insert x X. F a) \<le> inf (filtermap f (F x)) (filtermap f (INF a:X. F a))"
hoelzl@60036
   548
        by (rule order_trans[OF _ filtermap_inf]) simp
hoelzl@60036
   549
      also have "\<dots> \<le> inf (filtermap f (F x)) (INF a:X. filtermap f (F a))"
hoelzl@60036
   550
        by (intro inf_mono insert order_refl)
hoelzl@60036
   551
      finally show ?case
hoelzl@60036
   552
        by simp
hoelzl@60036
   553
    qed simp }
hoelzl@60036
   554
  then show ?thesis
hoelzl@60036
   555
    unfolding le_filter_def eventually_filtermap
hoelzl@60036
   556
    by (subst (1 2) eventually_INF) auto
hoelzl@60036
   557
qed
hoelzl@62101
   558
wenzelm@60758
   559
subsubsection \<open>Standard filters\<close>
hoelzl@60036
   560
hoelzl@60036
   561
definition principal :: "'a set \<Rightarrow> 'a filter" where
hoelzl@60036
   562
  "principal S = Abs_filter (\<lambda>P. \<forall>x\<in>S. P x)"
hoelzl@60036
   563
hoelzl@60036
   564
lemma eventually_principal: "eventually P (principal S) \<longleftrightarrow> (\<forall>x\<in>S. P x)"
hoelzl@60036
   565
  unfolding principal_def
hoelzl@60036
   566
  by (rule eventually_Abs_filter, rule is_filter.intro) auto
hoelzl@60036
   567
hoelzl@60036
   568
lemma eventually_inf_principal: "eventually P (inf F (principal s)) \<longleftrightarrow> eventually (\<lambda>x. x \<in> s \<longrightarrow> P x) F"
lp15@61810
   569
  unfolding eventually_inf eventually_principal by (auto elim: eventually_mono)
hoelzl@60036
   570
hoelzl@60036
   571
lemma principal_UNIV[simp]: "principal UNIV = top"
hoelzl@60036
   572
  by (auto simp: filter_eq_iff eventually_principal)
hoelzl@60036
   573
hoelzl@60036
   574
lemma principal_empty[simp]: "principal {} = bot"
hoelzl@60036
   575
  by (auto simp: filter_eq_iff eventually_principal)
hoelzl@60036
   576
hoelzl@60036
   577
lemma principal_eq_bot_iff: "principal X = bot \<longleftrightarrow> X = {}"
hoelzl@60036
   578
  by (auto simp add: filter_eq_iff eventually_principal)
hoelzl@60036
   579
hoelzl@60036
   580
lemma principal_le_iff[iff]: "principal A \<le> principal B \<longleftrightarrow> A \<subseteq> B"
hoelzl@60036
   581
  by (auto simp: le_filter_def eventually_principal)
hoelzl@60036
   582
hoelzl@60036
   583
lemma le_principal: "F \<le> principal A \<longleftrightarrow> eventually (\<lambda>x. x \<in> A) F"
hoelzl@60036
   584
  unfolding le_filter_def eventually_principal
hoelzl@60036
   585
  apply safe
hoelzl@60036
   586
  apply (erule_tac x="\<lambda>x. x \<in> A" in allE)
lp15@61810
   587
  apply (auto elim: eventually_mono)
hoelzl@60036
   588
  done
hoelzl@60036
   589
hoelzl@60036
   590
lemma principal_inject[iff]: "principal A = principal B \<longleftrightarrow> A = B"
hoelzl@60036
   591
  unfolding eq_iff by simp
hoelzl@60036
   592
hoelzl@60036
   593
lemma sup_principal[simp]: "sup (principal A) (principal B) = principal (A \<union> B)"
hoelzl@60036
   594
  unfolding filter_eq_iff eventually_sup eventually_principal by auto
hoelzl@60036
   595
hoelzl@60036
   596
lemma inf_principal[simp]: "inf (principal A) (principal B) = principal (A \<inter> B)"
hoelzl@60036
   597
  unfolding filter_eq_iff eventually_inf eventually_principal
hoelzl@60036
   598
  by (auto intro: exI[of _ "\<lambda>x. x \<in> A"] exI[of _ "\<lambda>x. x \<in> B"])
hoelzl@60036
   599
hoelzl@60036
   600
lemma SUP_principal[simp]: "(SUP i : I. principal (A i)) = principal (\<Union>i\<in>I. A i)"
haftmann@62343
   601
  unfolding filter_eq_iff eventually_Sup by (auto simp: eventually_principal)
hoelzl@60036
   602
hoelzl@60036
   603
lemma INF_principal_finite: "finite X \<Longrightarrow> (INF x:X. principal (f x)) = principal (\<Inter>x\<in>X. f x)"
hoelzl@60036
   604
  by (induct X rule: finite_induct) auto
hoelzl@60036
   605
hoelzl@60036
   606
lemma filtermap_principal[simp]: "filtermap f (principal A) = principal (f ` A)"
hoelzl@60036
   607
  unfolding filter_eq_iff eventually_filtermap eventually_principal by simp
hoelzl@60036
   608
wenzelm@60758
   609
subsubsection \<open>Order filters\<close>
hoelzl@60036
   610
hoelzl@60036
   611
definition at_top :: "('a::order) filter"
hoelzl@60036
   612
  where "at_top = (INF k. principal {k ..})"
hoelzl@60036
   613
hoelzl@60036
   614
lemma at_top_sub: "at_top = (INF k:{c::'a::linorder..}. principal {k ..})"
hoelzl@60036
   615
  by (auto intro!: INF_eq max.cobounded1 max.cobounded2 simp: at_top_def)
hoelzl@60036
   616
hoelzl@60036
   617
lemma eventually_at_top_linorder: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::linorder. \<forall>n\<ge>N. P n)"
hoelzl@60036
   618
  unfolding at_top_def
hoelzl@60036
   619
  by (subst eventually_INF_base) (auto simp: eventually_principal intro: max.cobounded1 max.cobounded2)
hoelzl@60036
   620
hoelzl@60036
   621
lemma eventually_ge_at_top:
hoelzl@60036
   622
  "eventually (\<lambda>x. (c::_::linorder) \<le> x) at_top"
hoelzl@60036
   623
  unfolding eventually_at_top_linorder by auto
hoelzl@60036
   624
hoelzl@60036
   625
lemma eventually_at_top_dense: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::{no_top, linorder}. \<forall>n>N. P n)"
hoelzl@60036
   626
proof -
hoelzl@60036
   627
  have "eventually P (INF k. principal {k <..}) \<longleftrightarrow> (\<exists>N::'a. \<forall>n>N. P n)"
hoelzl@60036
   628
    by (subst eventually_INF_base) (auto simp: eventually_principal intro: max.cobounded1 max.cobounded2)
hoelzl@60036
   629
  also have "(INF k. principal {k::'a <..}) = at_top"
lp15@61806
   630
    unfolding at_top_def
hoelzl@60036
   631
    by (intro INF_eq) (auto intro: less_imp_le simp: Ici_subset_Ioi_iff gt_ex)
hoelzl@60036
   632
  finally show ?thesis .
hoelzl@60036
   633
qed
hoelzl@60036
   634
hoelzl@60721
   635
lemma eventually_at_top_not_equal: "eventually (\<lambda>x::'a::{no_top, linorder}. x \<noteq> c) at_top"
hoelzl@60721
   636
  unfolding eventually_at_top_dense by auto
hoelzl@60721
   637
hoelzl@60721
   638
lemma eventually_gt_at_top: "eventually (\<lambda>x. (c::_::{no_top, linorder}) < x) at_top"
hoelzl@60036
   639
  unfolding eventually_at_top_dense by auto
hoelzl@60036
   640
eberlm@61531
   641
lemma eventually_all_ge_at_top:
eberlm@61531
   642
  assumes "eventually P (at_top :: ('a :: linorder) filter)"
eberlm@61531
   643
  shows   "eventually (\<lambda>x. \<forall>y\<ge>x. P y) at_top"
eberlm@61531
   644
proof -
eberlm@61531
   645
  from assms obtain x where "\<And>y. y \<ge> x \<Longrightarrow> P y" by (auto simp: eventually_at_top_linorder)
eberlm@61531
   646
  hence "\<forall>z\<ge>y. P z" if "y \<ge> x" for y using that by simp
eberlm@61531
   647
  thus ?thesis by (auto simp: eventually_at_top_linorder)
eberlm@61531
   648
qed
eberlm@61531
   649
hoelzl@60036
   650
definition at_bot :: "('a::order) filter"
hoelzl@60036
   651
  where "at_bot = (INF k. principal {.. k})"
hoelzl@60036
   652
hoelzl@60036
   653
lemma at_bot_sub: "at_bot = (INF k:{.. c::'a::linorder}. principal {.. k})"
hoelzl@60036
   654
  by (auto intro!: INF_eq min.cobounded1 min.cobounded2 simp: at_bot_def)
hoelzl@60036
   655
hoelzl@60036
   656
lemma eventually_at_bot_linorder:
hoelzl@60036
   657
  fixes P :: "'a::linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n\<le>N. P n)"
hoelzl@60036
   658
  unfolding at_bot_def
hoelzl@60036
   659
  by (subst eventually_INF_base) (auto simp: eventually_principal intro: min.cobounded1 min.cobounded2)
hoelzl@60036
   660
hoelzl@60036
   661
lemma eventually_le_at_bot:
hoelzl@60036
   662
  "eventually (\<lambda>x. x \<le> (c::_::linorder)) at_bot"
hoelzl@60036
   663
  unfolding eventually_at_bot_linorder by auto
hoelzl@60036
   664
hoelzl@60036
   665
lemma eventually_at_bot_dense: "eventually P at_bot \<longleftrightarrow> (\<exists>N::'a::{no_bot, linorder}. \<forall>n<N. P n)"
hoelzl@60036
   666
proof -
hoelzl@60036
   667
  have "eventually P (INF k. principal {..< k}) \<longleftrightarrow> (\<exists>N::'a. \<forall>n<N. P n)"
hoelzl@60036
   668
    by (subst eventually_INF_base) (auto simp: eventually_principal intro: min.cobounded1 min.cobounded2)
hoelzl@60036
   669
  also have "(INF k. principal {..< k::'a}) = at_bot"
lp15@61806
   670
    unfolding at_bot_def
hoelzl@60036
   671
    by (intro INF_eq) (auto intro: less_imp_le simp: Iic_subset_Iio_iff lt_ex)
hoelzl@60036
   672
  finally show ?thesis .
hoelzl@60036
   673
qed
hoelzl@60036
   674
hoelzl@60721
   675
lemma eventually_at_bot_not_equal: "eventually (\<lambda>x::'a::{no_bot, linorder}. x \<noteq> c) at_bot"
hoelzl@60721
   676
  unfolding eventually_at_bot_dense by auto
hoelzl@60721
   677
hoelzl@60036
   678
lemma eventually_gt_at_bot:
hoelzl@60036
   679
  "eventually (\<lambda>x. x < (c::_::unbounded_dense_linorder)) at_bot"
hoelzl@60036
   680
  unfolding eventually_at_bot_dense by auto
hoelzl@60036
   681
hoelzl@60036
   682
lemma trivial_limit_at_bot_linorder: "\<not> trivial_limit (at_bot ::('a::linorder) filter)"
hoelzl@60036
   683
  unfolding trivial_limit_def
hoelzl@60036
   684
  by (metis eventually_at_bot_linorder order_refl)
hoelzl@60036
   685
hoelzl@60036
   686
lemma trivial_limit_at_top_linorder: "\<not> trivial_limit (at_top ::('a::linorder) filter)"
hoelzl@60036
   687
  unfolding trivial_limit_def
hoelzl@60036
   688
  by (metis eventually_at_top_linorder order_refl)
hoelzl@60036
   689
wenzelm@60758
   690
subsection \<open>Sequentially\<close>
hoelzl@60036
   691
hoelzl@60036
   692
abbreviation sequentially :: "nat filter"
hoelzl@60036
   693
  where "sequentially \<equiv> at_top"
hoelzl@60036
   694
hoelzl@60036
   695
lemma eventually_sequentially:
hoelzl@60036
   696
  "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
hoelzl@60036
   697
  by (rule eventually_at_top_linorder)
hoelzl@60036
   698
hoelzl@60036
   699
lemma sequentially_bot [simp, intro]: "sequentially \<noteq> bot"
hoelzl@60036
   700
  unfolding filter_eq_iff eventually_sequentially by auto
hoelzl@60036
   701
hoelzl@60036
   702
lemmas trivial_limit_sequentially = sequentially_bot
hoelzl@60036
   703
hoelzl@60036
   704
lemma eventually_False_sequentially [simp]:
hoelzl@60036
   705
  "\<not> eventually (\<lambda>n. False) sequentially"
hoelzl@60036
   706
  by (simp add: eventually_False)
hoelzl@60036
   707
hoelzl@60036
   708
lemma le_sequentially:
hoelzl@60036
   709
  "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
hoelzl@60036
   710
  by (simp add: at_top_def le_INF_iff le_principal)
hoelzl@60036
   711
lp15@60974
   712
lemma eventually_sequentiallyI [intro?]:
hoelzl@60036
   713
  assumes "\<And>x. c \<le> x \<Longrightarrow> P x"
hoelzl@60036
   714
  shows "eventually P sequentially"
hoelzl@60036
   715
using assms by (auto simp: eventually_sequentially)
hoelzl@60036
   716
hoelzl@60040
   717
lemma eventually_sequentially_Suc: "eventually (\<lambda>i. P (Suc i)) sequentially \<longleftrightarrow> eventually P sequentially"
hoelzl@60040
   718
  unfolding eventually_sequentially by (metis Suc_le_D Suc_le_mono le_Suc_eq)
hoelzl@60040
   719
hoelzl@60040
   720
lemma eventually_sequentially_seg: "eventually (\<lambda>n. P (n + k)) sequentially \<longleftrightarrow> eventually P sequentially"
hoelzl@60040
   721
  using eventually_sequentially_Suc[of "\<lambda>n. P (n + k)" for k] by (induction k) auto
hoelzl@60036
   722
wenzelm@61955
   723
wenzelm@61955
   724
subsection \<open>The cofinite filter\<close>
hoelzl@60039
   725
hoelzl@60039
   726
definition "cofinite = Abs_filter (\<lambda>P. finite {x. \<not> P x})"
hoelzl@60039
   727
wenzelm@61955
   728
abbreviation Inf_many :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "\<exists>\<^sub>\<infinity>" 10)
wenzelm@61955
   729
  where "Inf_many P \<equiv> frequently P cofinite"
hoelzl@60040
   730
wenzelm@61955
   731
abbreviation Alm_all :: "('a \<Rightarrow> bool) \<Rightarrow> bool"  (binder "\<forall>\<^sub>\<infinity>" 10)
wenzelm@61955
   732
  where "Alm_all P \<equiv> eventually P cofinite"
hoelzl@60040
   733
wenzelm@61955
   734
notation (ASCII)
wenzelm@61955
   735
  Inf_many  (binder "INFM " 10) and
wenzelm@61955
   736
  Alm_all  (binder "MOST " 10)
hoelzl@60040
   737
hoelzl@60039
   738
lemma eventually_cofinite: "eventually P cofinite \<longleftrightarrow> finite {x. \<not> P x}"
hoelzl@60039
   739
  unfolding cofinite_def
hoelzl@60039
   740
proof (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@60039
   741
  fix P Q :: "'a \<Rightarrow> bool" assume "finite {x. \<not> P x}" "finite {x. \<not> Q x}"
hoelzl@60039
   742
  from finite_UnI[OF this] show "finite {x. \<not> (P x \<and> Q x)}"
hoelzl@60039
   743
    by (rule rev_finite_subset) auto
hoelzl@60039
   744
next
hoelzl@60039
   745
  fix P Q :: "'a \<Rightarrow> bool" assume P: "finite {x. \<not> P x}" and *: "\<forall>x. P x \<longrightarrow> Q x"
hoelzl@60039
   746
  from * show "finite {x. \<not> Q x}"
hoelzl@60039
   747
    by (intro finite_subset[OF _ P]) auto
hoelzl@60039
   748
qed simp
hoelzl@60039
   749
hoelzl@60040
   750
lemma frequently_cofinite: "frequently P cofinite \<longleftrightarrow> \<not> finite {x. P x}"
hoelzl@60040
   751
  by (simp add: frequently_def eventually_cofinite)
hoelzl@60040
   752
hoelzl@60039
   753
lemma cofinite_bot[simp]: "cofinite = (bot::'a filter) \<longleftrightarrow> finite (UNIV :: 'a set)"
hoelzl@60039
   754
  unfolding trivial_limit_def eventually_cofinite by simp
hoelzl@60039
   755
hoelzl@60039
   756
lemma cofinite_eq_sequentially: "cofinite = sequentially"
hoelzl@60039
   757
  unfolding filter_eq_iff eventually_sequentially eventually_cofinite
hoelzl@60039
   758
proof safe
hoelzl@60039
   759
  fix P :: "nat \<Rightarrow> bool" assume [simp]: "finite {x. \<not> P x}"
hoelzl@60039
   760
  show "\<exists>N. \<forall>n\<ge>N. P n"
hoelzl@60039
   761
  proof cases
hoelzl@60039
   762
    assume "{x. \<not> P x} \<noteq> {}" then show ?thesis
hoelzl@60039
   763
      by (intro exI[of _ "Suc (Max {x. \<not> P x})"]) (auto simp: Suc_le_eq)
hoelzl@60039
   764
  qed auto
hoelzl@60039
   765
next
hoelzl@60039
   766
  fix P :: "nat \<Rightarrow> bool" and N :: nat assume "\<forall>n\<ge>N. P n"
hoelzl@60039
   767
  then have "{x. \<not> P x} \<subseteq> {..< N}"
hoelzl@60039
   768
    by (auto simp: not_le)
hoelzl@60039
   769
  then show "finite {x. \<not> P x}"
hoelzl@60039
   770
    by (blast intro: finite_subset)
hoelzl@60039
   771
qed
hoelzl@60036
   772
hoelzl@62101
   773
subsubsection \<open>Product of filters\<close>
hoelzl@62101
   774
hoelzl@62101
   775
lemma filtermap_sequentually_ne_bot: "filtermap f sequentially \<noteq> bot"
hoelzl@62101
   776
  by (auto simp add: filter_eq_iff eventually_filtermap eventually_sequentially)
hoelzl@62101
   777
hoelzl@62101
   778
definition prod_filter :: "'a filter \<Rightarrow> 'b filter \<Rightarrow> ('a \<times> 'b) filter" (infixr "\<times>\<^sub>F" 80) where
hoelzl@62101
   779
  "prod_filter F G =
hoelzl@62101
   780
    (INF (P, Q):{(P, Q). eventually P F \<and> eventually Q G}. principal {(x, y). P x \<and> Q y})"
hoelzl@62101
   781
hoelzl@62101
   782
lemma eventually_prod_filter: "eventually P (F \<times>\<^sub>F G) \<longleftrightarrow>
hoelzl@62101
   783
  (\<exists>Pf Pg. eventually Pf F \<and> eventually Pg G \<and> (\<forall>x y. Pf x \<longrightarrow> Pg y \<longrightarrow> P (x, y)))"
hoelzl@62101
   784
  unfolding prod_filter_def
hoelzl@62101
   785
proof (subst eventually_INF_base, goal_cases)
hoelzl@62101
   786
  case 2
hoelzl@62101
   787
  moreover have "eventually Pf F \<Longrightarrow> eventually Qf F \<Longrightarrow> eventually Pg G \<Longrightarrow> eventually Qg G \<Longrightarrow>
hoelzl@62101
   788
    \<exists>P Q. eventually P F \<and> eventually Q G \<and>
hoelzl@62101
   789
      Collect P \<times> Collect Q \<subseteq> Collect Pf \<times> Collect Pg \<inter> Collect Qf \<times> Collect Qg" for Pf Pg Qf Qg
hoelzl@62101
   790
    by (intro conjI exI[of _ "inf Pf Qf"] exI[of _ "inf Pg Qg"])
hoelzl@62101
   791
       (auto simp: inf_fun_def eventually_conj)
hoelzl@62101
   792
  ultimately show ?case
hoelzl@62101
   793
    by auto
hoelzl@62101
   794
qed (auto simp: eventually_principal intro: eventually_True)
hoelzl@62101
   795
hoelzl@62367
   796
lemma eventually_prod1:
hoelzl@62367
   797
  assumes "B \<noteq> bot"
hoelzl@62367
   798
  shows "(\<forall>\<^sub>F (x, y) in A \<times>\<^sub>F B. P x) \<longleftrightarrow> (\<forall>\<^sub>F x in A. P x)"
hoelzl@62367
   799
  unfolding eventually_prod_filter
hoelzl@62367
   800
proof safe
hoelzl@62367
   801
  fix R Q assume "\<forall>\<^sub>F x in A. R x" "\<forall>\<^sub>F x in B. Q x" "\<forall>x y. R x \<longrightarrow> Q y \<longrightarrow> P x"
hoelzl@62367
   802
  moreover with \<open>B \<noteq> bot\<close> obtain y where "Q y" by (auto dest: eventually_happens)
hoelzl@62367
   803
  ultimately show "eventually P A"
hoelzl@62367
   804
    by (force elim: eventually_mono)
hoelzl@62367
   805
next
hoelzl@62367
   806
  assume "eventually P A"
hoelzl@62367
   807
  then show "\<exists>Pf Pg. eventually Pf A \<and> eventually Pg B \<and> (\<forall>x y. Pf x \<longrightarrow> Pg y \<longrightarrow> P x)"
hoelzl@62367
   808
    by (intro exI[of _ P] exI[of _ "\<lambda>x. True"]) auto
hoelzl@62367
   809
qed
hoelzl@62367
   810
hoelzl@62367
   811
lemma eventually_prod2:
hoelzl@62367
   812
  assumes "A \<noteq> bot"
hoelzl@62367
   813
  shows "(\<forall>\<^sub>F (x, y) in A \<times>\<^sub>F B. P y) \<longleftrightarrow> (\<forall>\<^sub>F y in B. P y)"
hoelzl@62367
   814
  unfolding eventually_prod_filter
hoelzl@62367
   815
proof safe
hoelzl@62367
   816
  fix R Q assume "\<forall>\<^sub>F x in A. R x" "\<forall>\<^sub>F x in B. Q x" "\<forall>x y. R x \<longrightarrow> Q y \<longrightarrow> P y"
hoelzl@62367
   817
  moreover with \<open>A \<noteq> bot\<close> obtain x where "R x" by (auto dest: eventually_happens)
hoelzl@62367
   818
  ultimately show "eventually P B"
hoelzl@62367
   819
    by (force elim: eventually_mono)
hoelzl@62367
   820
next
hoelzl@62367
   821
  assume "eventually P B"
hoelzl@62367
   822
  then show "\<exists>Pf Pg. eventually Pf A \<and> eventually Pg B \<and> (\<forall>x y. Pf x \<longrightarrow> Pg y \<longrightarrow> P y)"
hoelzl@62367
   823
    by (intro exI[of _ P] exI[of _ "\<lambda>x. True"]) auto
hoelzl@62367
   824
qed
hoelzl@62367
   825
hoelzl@62367
   826
lemma INF_filter_bot_base:
hoelzl@62367
   827
  fixes F :: "'a \<Rightarrow> 'b filter"
hoelzl@62367
   828
  assumes *: "\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> \<exists>k\<in>I. F k \<le> F i \<sqinter> F j"
hoelzl@62367
   829
  shows "(INF i:I. F i) = bot \<longleftrightarrow> (\<exists>i\<in>I. F i = bot)"
hoelzl@62367
   830
proof cases
hoelzl@62367
   831
  assume "\<exists>i\<in>I. F i = bot"
hoelzl@62367
   832
  moreover then have "(INF i:I. F i) \<le> bot"
hoelzl@62367
   833
    by (auto intro: INF_lower2)
hoelzl@62367
   834
  ultimately show ?thesis
hoelzl@62367
   835
    by (auto simp: bot_unique)
hoelzl@62367
   836
next
hoelzl@62367
   837
  assume **: "\<not> (\<exists>i\<in>I. F i = bot)"
hoelzl@62367
   838
  moreover have "(INF i:I. F i) \<noteq> bot"
hoelzl@62367
   839
  proof cases
hoelzl@62367
   840
    assume "I \<noteq> {}"
hoelzl@62367
   841
    show ?thesis
hoelzl@62367
   842
    proof (rule INF_filter_not_bot)
hoelzl@62367
   843
      fix J assume "finite J" "J \<subseteq> I"
hoelzl@62367
   844
      then have "\<exists>k\<in>I. F k \<le> (\<Sqinter>i\<in>J. F i)"
hoelzl@62367
   845
      proof (induction J)
hoelzl@62367
   846
        case empty then show ?case
hoelzl@62367
   847
          using \<open>I \<noteq> {}\<close> by auto
hoelzl@62367
   848
      next
hoelzl@62367
   849
        case (insert i J)
hoelzl@62367
   850
        moreover then obtain k where "k \<in> I" "F k \<le> (\<Sqinter>i\<in>J. F i)" by auto
hoelzl@62367
   851
        moreover note *[of i k]
hoelzl@62367
   852
        ultimately show ?case
hoelzl@62367
   853
          by auto
hoelzl@62367
   854
      qed
hoelzl@62367
   855
      with ** show "(\<Sqinter>i\<in>J. F i) \<noteq> \<bottom>"
hoelzl@62367
   856
        by (auto simp: bot_unique)
hoelzl@62367
   857
    qed
hoelzl@62367
   858
  qed (auto simp add: filter_eq_iff)
hoelzl@62367
   859
  ultimately show ?thesis
hoelzl@62367
   860
    by auto
hoelzl@62367
   861
qed
hoelzl@62367
   862
hoelzl@62367
   863
lemma Collect_empty_eq_bot: "Collect P = {} \<longleftrightarrow> P = \<bottom>"
hoelzl@62367
   864
  by auto
hoelzl@62367
   865
hoelzl@62367
   866
lemma prod_filter_eq_bot: "A \<times>\<^sub>F B = bot \<longleftrightarrow> A = bot \<or> B = bot"
hoelzl@62367
   867
  unfolding prod_filter_def
hoelzl@62367
   868
proof (subst INF_filter_bot_base; clarsimp simp: principal_eq_bot_iff Collect_empty_eq_bot bot_fun_def simp del: Collect_empty_eq)
hoelzl@62367
   869
  fix A1 A2 B1 B2 assume "\<forall>\<^sub>F x in A. A1 x" "\<forall>\<^sub>F x in A. A2 x" "\<forall>\<^sub>F x in B. B1 x" "\<forall>\<^sub>F x in B. B2 x"
hoelzl@62367
   870
  then show "\<exists>x. eventually x A \<and> (\<exists>y. eventually y B \<and> Collect x \<times> Collect y \<subseteq> Collect A1 \<times> Collect B1 \<and> Collect x \<times> Collect y \<subseteq> Collect A2 \<times> Collect B2)"
hoelzl@62367
   871
    by (intro exI[of _ "\<lambda>x. A1 x \<and> A2 x"] exI[of _ "\<lambda>x. B1 x \<and> B2 x"] conjI)
hoelzl@62367
   872
       (auto simp: eventually_conj_iff)
hoelzl@62367
   873
next
hoelzl@62367
   874
  show "(\<exists>x. eventually x A \<and> (\<exists>y. eventually y B \<and> (x = (\<lambda>x. False) \<or> y = (\<lambda>x. False)))) = (A = \<bottom> \<or> B = \<bottom>)"
hoelzl@62367
   875
    by (auto simp: trivial_limit_def intro: eventually_True)
hoelzl@62367
   876
qed
hoelzl@62367
   877
hoelzl@62101
   878
lemma prod_filter_mono: "F \<le> F' \<Longrightarrow> G \<le> G' \<Longrightarrow> F \<times>\<^sub>F G \<le> F' \<times>\<^sub>F G'"
hoelzl@62101
   879
  by (auto simp: le_filter_def eventually_prod_filter)
hoelzl@62101
   880
hoelzl@62367
   881
lemma prod_filter_mono_iff:
hoelzl@62367
   882
  assumes nAB: "A \<noteq> bot" "B \<noteq> bot"
hoelzl@62367
   883
  shows "A \<times>\<^sub>F B \<le> C \<times>\<^sub>F D \<longleftrightarrow> A \<le> C \<and> B \<le> D"
hoelzl@62367
   884
proof safe
hoelzl@62367
   885
  assume *: "A \<times>\<^sub>F B \<le> C \<times>\<^sub>F D"
hoelzl@62367
   886
  moreover with assms have "A \<times>\<^sub>F B \<noteq> bot"
hoelzl@62367
   887
    by (auto simp: bot_unique prod_filter_eq_bot)
hoelzl@62367
   888
  ultimately have "C \<times>\<^sub>F D \<noteq> bot"
hoelzl@62367
   889
    by (auto simp: bot_unique)
hoelzl@62367
   890
  then have nCD: "C \<noteq> bot" "D \<noteq> bot"
hoelzl@62367
   891
    by (auto simp: prod_filter_eq_bot)
hoelzl@62367
   892
hoelzl@62367
   893
  show "A \<le> C"
hoelzl@62367
   894
  proof (rule filter_leI)
hoelzl@62367
   895
    fix P assume "eventually P C" with *[THEN filter_leD, of "\<lambda>(x, y). P x"] show "eventually P A"
hoelzl@62367
   896
      using nAB nCD by (simp add: eventually_prod1 eventually_prod2)
hoelzl@62367
   897
  qed
hoelzl@62367
   898
hoelzl@62367
   899
  show "B \<le> D"
hoelzl@62367
   900
  proof (rule filter_leI)
hoelzl@62367
   901
    fix P assume "eventually P D" with *[THEN filter_leD, of "\<lambda>(x, y). P y"] show "eventually P B"
hoelzl@62367
   902
      using nAB nCD by (simp add: eventually_prod1 eventually_prod2)
hoelzl@62367
   903
  qed
hoelzl@62367
   904
qed (intro prod_filter_mono)
hoelzl@62367
   905
hoelzl@62101
   906
lemma eventually_prod_same: "eventually P (F \<times>\<^sub>F F) \<longleftrightarrow>
hoelzl@62101
   907
    (\<exists>Q. eventually Q F \<and> (\<forall>x y. Q x \<longrightarrow> Q y \<longrightarrow> P (x, y)))"
hoelzl@62101
   908
  unfolding eventually_prod_filter
hoelzl@62101
   909
  apply safe
hoelzl@62101
   910
  apply (rule_tac x="inf Pf Pg" in exI)
hoelzl@62101
   911
  apply (auto simp: inf_fun_def intro!: eventually_conj)
hoelzl@62101
   912
  done
hoelzl@62101
   913
hoelzl@62101
   914
lemma eventually_prod_sequentially:
hoelzl@62101
   915
  "eventually P (sequentially \<times>\<^sub>F sequentially) \<longleftrightarrow> (\<exists>N. \<forall>m \<ge> N. \<forall>n \<ge> N. P (n, m))"
hoelzl@62101
   916
  unfolding eventually_prod_same eventually_sequentially by auto
hoelzl@62101
   917
hoelzl@62101
   918
lemma principal_prod_principal: "principal A \<times>\<^sub>F principal B = principal (A \<times> B)"
hoelzl@62101
   919
  apply (simp add: filter_eq_iff eventually_prod_filter eventually_principal)
hoelzl@62101
   920
  apply safe
hoelzl@62101
   921
  apply blast
hoelzl@62101
   922
  apply (intro conjI exI[of _ "\<lambda>x. x \<in> A"] exI[of _ "\<lambda>x. x \<in> B"])
hoelzl@62101
   923
  apply auto
hoelzl@62101
   924
  done
hoelzl@62101
   925
hoelzl@62367
   926
lemma prod_filter_INF:
hoelzl@62367
   927
  assumes "I \<noteq> {}" "J \<noteq> {}"
hoelzl@62367
   928
  shows "(INF i:I. A i) \<times>\<^sub>F (INF j:J. B j) = (INF i:I. INF j:J. A i \<times>\<^sub>F B j)"
hoelzl@62367
   929
proof (safe intro!: antisym INF_greatest)
hoelzl@62367
   930
  from \<open>I \<noteq> {}\<close> obtain i where "i \<in> I" by auto
hoelzl@62367
   931
  from \<open>J \<noteq> {}\<close> obtain j where "j \<in> J" by auto
hoelzl@62367
   932
hoelzl@62367
   933
  show "(\<Sqinter>i\<in>I. \<Sqinter>j\<in>J. A i \<times>\<^sub>F B j) \<le> (\<Sqinter>i\<in>I. A i) \<times>\<^sub>F (\<Sqinter>j\<in>J. B j)"
hoelzl@62367
   934
    unfolding prod_filter_def
hoelzl@62367
   935
  proof (safe intro!: INF_greatest)
hoelzl@62367
   936
    fix P Q assume P: "\<forall>\<^sub>F x in \<Sqinter>i\<in>I. A i. P x" and Q: "\<forall>\<^sub>F x in \<Sqinter>j\<in>J. B j. Q x"
hoelzl@62367
   937
    let ?X = "(\<Sqinter>i\<in>I. \<Sqinter>j\<in>J. \<Sqinter>(P, Q)\<in>{(P, Q). (\<forall>\<^sub>F x in A i. P x) \<and> (\<forall>\<^sub>F x in B j. Q x)}. principal {(x, y). P x \<and> Q y})"
hoelzl@62367
   938
    have "?X \<le> principal {x. P (fst x)} \<sqinter> principal {x. Q (snd x)}"
hoelzl@62367
   939
    proof (intro inf_greatest)
hoelzl@62367
   940
      have "?X \<le> (\<Sqinter>i\<in>I. \<Sqinter>P\<in>{P. eventually P (A i)}. principal {x. P (fst x)})"
hoelzl@62367
   941
        by (auto intro!: INF_greatest INF_lower2[of j] INF_lower2 \<open>j\<in>J\<close> INF_lower2[of "(_, \<lambda>x. True)"])
hoelzl@62367
   942
      also have "\<dots> \<le> principal {x. P (fst x)}"
hoelzl@62367
   943
        unfolding le_principal
hoelzl@62367
   944
      proof (rule eventually_INF_mono[OF P])
hoelzl@62367
   945
        fix i P assume "i \<in> I" "eventually P (A i)"
hoelzl@62367
   946
        then show "\<forall>\<^sub>F x in \<Sqinter>P\<in>{P. eventually P (A i)}. principal {x. P (fst x)}. x \<in> {x. P (fst x)}"
hoelzl@62367
   947
          unfolding le_principal[symmetric] by (auto intro!: INF_lower)
hoelzl@62367
   948
      qed auto
hoelzl@62367
   949
      finally show "?X \<le> principal {x. P (fst x)}" .
hoelzl@62367
   950
hoelzl@62367
   951
      have "?X \<le> (\<Sqinter>i\<in>J. \<Sqinter>P\<in>{P. eventually P (B i)}. principal {x. P (snd x)})"
hoelzl@62367
   952
        by (auto intro!: INF_greatest INF_lower2[of i] INF_lower2 \<open>i\<in>I\<close> INF_lower2[of "(\<lambda>x. True, _)"])
hoelzl@62367
   953
      also have "\<dots> \<le> principal {x. Q (snd x)}"
hoelzl@62367
   954
        unfolding le_principal
hoelzl@62367
   955
      proof (rule eventually_INF_mono[OF Q])
hoelzl@62367
   956
        fix j Q assume "j \<in> J" "eventually Q (B j)"
hoelzl@62367
   957
        then show "\<forall>\<^sub>F x in \<Sqinter>P\<in>{P. eventually P (B j)}. principal {x. P (snd x)}. x \<in> {x. Q (snd x)}"
hoelzl@62367
   958
          unfolding le_principal[symmetric] by (auto intro!: INF_lower)
hoelzl@62367
   959
      qed auto
hoelzl@62367
   960
      finally show "?X \<le> principal {x. Q (snd x)}" .
hoelzl@62367
   961
    qed
hoelzl@62367
   962
    also have "\<dots> = principal {(x, y). P x \<and> Q y}"
hoelzl@62367
   963
      by auto
hoelzl@62367
   964
    finally show "?X \<le> principal {(x, y). P x \<and> Q y}" .
hoelzl@62367
   965
  qed
hoelzl@62367
   966
qed (intro prod_filter_mono INF_lower)
hoelzl@62367
   967
hoelzl@62367
   968
lemma filtermap_Pair: "filtermap (\<lambda>x. (f x, g x)) F \<le> filtermap f F \<times>\<^sub>F filtermap g F"
hoelzl@62367
   969
  by (simp add: le_filter_def eventually_filtermap eventually_prod_filter)
hoelzl@62367
   970
     (auto elim: eventually_elim2)
hoelzl@62367
   971
hoelzl@62369
   972
lemma eventually_prodI: "eventually P F \<Longrightarrow> eventually Q G \<Longrightarrow> eventually (\<lambda>x. P (fst x) \<and> Q (snd x)) (F \<times>\<^sub>F G)"
hoelzl@62369
   973
  unfolding prod_filter_def
hoelzl@62369
   974
  by (intro eventually_INF1[of "(P, Q)"]) (auto simp: eventually_principal)
hoelzl@62369
   975
hoelzl@62369
   976
lemma prod_filter_INF1: "I \<noteq> {} \<Longrightarrow> (INF i:I. A i) \<times>\<^sub>F B = (INF i:I. A i \<times>\<^sub>F B)"
hoelzl@62369
   977
  using prod_filter_INF[of I "{B}" A "\<lambda>x. x"] by simp
hoelzl@62369
   978
hoelzl@62369
   979
lemma prod_filter_INF2: "J \<noteq> {} \<Longrightarrow> A \<times>\<^sub>F (INF i:J. B i) = (INF i:J. A \<times>\<^sub>F B i)"
hoelzl@62369
   980
  using prod_filter_INF[of "{A}" J "\<lambda>x. x" B] by simp
hoelzl@62369
   981
wenzelm@60758
   982
subsection \<open>Limits\<close>
hoelzl@60036
   983
hoelzl@60036
   984
definition filterlim :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b filter \<Rightarrow> 'a filter \<Rightarrow> bool" where
hoelzl@60036
   985
  "filterlim f F2 F1 \<longleftrightarrow> filtermap f F1 \<le> F2"
hoelzl@60036
   986
hoelzl@60036
   987
syntax
hoelzl@60036
   988
  "_LIM" :: "pttrns \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(3LIM (_)/ (_)./ (_) :> (_))" [1000, 10, 0, 10] 10)
hoelzl@60036
   989
hoelzl@60036
   990
translations
hoelzl@62367
   991
  "LIM x F1. f :> F2" == "CONST filterlim (\<lambda>x. f) F2 F1"
hoelzl@60036
   992
lp15@62379
   993
lemma filterlim_top [simp]: "filterlim f top F"
lp15@62379
   994
  by (simp add: filterlim_def)
lp15@62379
   995
hoelzl@60036
   996
lemma filterlim_iff:
hoelzl@60036
   997
  "(LIM x F1. f x :> F2) \<longleftrightarrow> (\<forall>P. eventually P F2 \<longrightarrow> eventually (\<lambda>x. P (f x)) F1)"
hoelzl@60036
   998
  unfolding filterlim_def le_filter_def eventually_filtermap ..
hoelzl@60036
   999
hoelzl@60036
  1000
lemma filterlim_compose:
hoelzl@60036
  1001
  "filterlim g F3 F2 \<Longrightarrow> filterlim f F2 F1 \<Longrightarrow> filterlim (\<lambda>x. g (f x)) F3 F1"
hoelzl@60036
  1002
  unfolding filterlim_def filtermap_filtermap[symmetric] by (metis filtermap_mono order_trans)
hoelzl@60036
  1003
hoelzl@60036
  1004
lemma filterlim_mono:
hoelzl@60036
  1005
  "filterlim f F2 F1 \<Longrightarrow> F2 \<le> F2' \<Longrightarrow> F1' \<le> F1 \<Longrightarrow> filterlim f F2' F1'"
hoelzl@60036
  1006
  unfolding filterlim_def by (metis filtermap_mono order_trans)
hoelzl@60036
  1007
hoelzl@60036
  1008
lemma filterlim_ident: "LIM x F. x :> F"
hoelzl@60036
  1009
  by (simp add: filterlim_def filtermap_ident)
hoelzl@60036
  1010
hoelzl@60036
  1011
lemma filterlim_cong:
hoelzl@60036
  1012
  "F1 = F1' \<Longrightarrow> F2 = F2' \<Longrightarrow> eventually (\<lambda>x. f x = g x) F2 \<Longrightarrow> filterlim f F1 F2 = filterlim g F1' F2'"
hoelzl@60036
  1013
  by (auto simp: filterlim_def le_filter_def eventually_filtermap elim: eventually_elim2)
hoelzl@60036
  1014
hoelzl@60036
  1015
lemma filterlim_mono_eventually:
hoelzl@60036
  1016
  assumes "filterlim f F G" and ord: "F \<le> F'" "G' \<le> G"
hoelzl@60036
  1017
  assumes eq: "eventually (\<lambda>x. f x = f' x) G'"
hoelzl@60036
  1018
  shows "filterlim f' F' G'"
hoelzl@60036
  1019
  apply (rule filterlim_cong[OF refl refl eq, THEN iffD1])
hoelzl@60036
  1020
  apply (rule filterlim_mono[OF _ ord])
hoelzl@60036
  1021
  apply fact
hoelzl@60036
  1022
  done
hoelzl@60036
  1023
hoelzl@60036
  1024
lemma filtermap_mono_strong: "inj f \<Longrightarrow> filtermap f F \<le> filtermap f G \<longleftrightarrow> F \<le> G"
hoelzl@60036
  1025
  apply (auto intro!: filtermap_mono) []
hoelzl@60036
  1026
  apply (auto simp: le_filter_def eventually_filtermap)
hoelzl@60036
  1027
  apply (erule_tac x="\<lambda>x. P (inv f x)" in allE)
hoelzl@60036
  1028
  apply auto
hoelzl@60036
  1029
  done
hoelzl@60036
  1030
hoelzl@60036
  1031
lemma filtermap_eq_strong: "inj f \<Longrightarrow> filtermap f F = filtermap f G \<longleftrightarrow> F = G"
hoelzl@60036
  1032
  by (simp add: filtermap_mono_strong eq_iff)
hoelzl@60036
  1033
hoelzl@60721
  1034
lemma filtermap_fun_inverse:
hoelzl@60721
  1035
  assumes g: "filterlim g F G"
hoelzl@60721
  1036
  assumes f: "filterlim f G F"
hoelzl@60721
  1037
  assumes ev: "eventually (\<lambda>x. f (g x) = x) G"
hoelzl@60721
  1038
  shows "filtermap f F = G"
hoelzl@60721
  1039
proof (rule antisym)
hoelzl@60721
  1040
  show "filtermap f F \<le> G"
hoelzl@60721
  1041
    using f unfolding filterlim_def .
hoelzl@60721
  1042
  have "G = filtermap f (filtermap g G)"
hoelzl@60721
  1043
    using ev by (auto elim: eventually_elim2 simp: filter_eq_iff eventually_filtermap)
hoelzl@60721
  1044
  also have "\<dots> \<le> filtermap f F"
hoelzl@60721
  1045
    using g by (intro filtermap_mono) (simp add: filterlim_def)
hoelzl@60721
  1046
  finally show "G \<le> filtermap f F" .
hoelzl@60721
  1047
qed
hoelzl@60721
  1048
hoelzl@60036
  1049
lemma filterlim_principal:
hoelzl@60036
  1050
  "(LIM x F. f x :> principal S) \<longleftrightarrow> (eventually (\<lambda>x. f x \<in> S) F)"
hoelzl@60036
  1051
  unfolding filterlim_def eventually_filtermap le_principal ..
hoelzl@60036
  1052
hoelzl@60036
  1053
lemma filterlim_inf:
hoelzl@60036
  1054
  "(LIM x F1. f x :> inf F2 F3) \<longleftrightarrow> ((LIM x F1. f x :> F2) \<and> (LIM x F1. f x :> F3))"
hoelzl@60036
  1055
  unfolding filterlim_def by simp
hoelzl@60036
  1056
hoelzl@60036
  1057
lemma filterlim_INF:
hoelzl@60036
  1058
  "(LIM x F. f x :> (INF b:B. G b)) \<longleftrightarrow> (\<forall>b\<in>B. LIM x F. f x :> G b)"
hoelzl@60036
  1059
  unfolding filterlim_def le_INF_iff ..
hoelzl@60036
  1060
hoelzl@60036
  1061
lemma filterlim_INF_INF:
hoelzl@60036
  1062
  "(\<And>m. m \<in> J \<Longrightarrow> \<exists>i\<in>I. filtermap f (F i) \<le> G m) \<Longrightarrow> LIM x (INF i:I. F i). f x :> (INF j:J. G j)"
hoelzl@60036
  1063
  unfolding filterlim_def by (rule order_trans[OF filtermap_INF INF_mono])
hoelzl@60036
  1064
hoelzl@60036
  1065
lemma filterlim_base:
lp15@61806
  1066
  "(\<And>m x. m \<in> J \<Longrightarrow> i m \<in> I) \<Longrightarrow> (\<And>m x. m \<in> J \<Longrightarrow> x \<in> F (i m) \<Longrightarrow> f x \<in> G m) \<Longrightarrow>
hoelzl@60036
  1067
    LIM x (INF i:I. principal (F i)). f x :> (INF j:J. principal (G j))"
hoelzl@60036
  1068
  by (force intro!: filterlim_INF_INF simp: image_subset_iff)
hoelzl@60036
  1069
lp15@61806
  1070
lemma filterlim_base_iff:
hoelzl@60036
  1071
  assumes "I \<noteq> {}" and chain: "\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> F i \<subseteq> F j \<or> F j \<subseteq> F i"
hoelzl@60036
  1072
  shows "(LIM x (INF i:I. principal (F i)). f x :> INF j:J. principal (G j)) \<longleftrightarrow>
hoelzl@60036
  1073
    (\<forall>j\<in>J. \<exists>i\<in>I. \<forall>x\<in>F i. f x \<in> G j)"
hoelzl@60036
  1074
  unfolding filterlim_INF filterlim_principal
hoelzl@60036
  1075
proof (subst eventually_INF_base)
hoelzl@60036
  1076
  fix i j assume "i \<in> I" "j \<in> I"
hoelzl@60036
  1077
  with chain[OF this] show "\<exists>x\<in>I. principal (F x) \<le> inf (principal (F i)) (principal (F j))"
hoelzl@60036
  1078
    by auto
wenzelm@60758
  1079
qed (auto simp: eventually_principal \<open>I \<noteq> {}\<close>)
hoelzl@60036
  1080
hoelzl@60036
  1081
lemma filterlim_filtermap: "filterlim f F1 (filtermap g F2) = filterlim (\<lambda>x. f (g x)) F1 F2"
hoelzl@60036
  1082
  unfolding filterlim_def filtermap_filtermap ..
hoelzl@60036
  1083
hoelzl@60036
  1084
lemma filterlim_sup:
hoelzl@60036
  1085
  "filterlim f F F1 \<Longrightarrow> filterlim f F F2 \<Longrightarrow> filterlim f F (sup F1 F2)"
hoelzl@60036
  1086
  unfolding filterlim_def filtermap_sup by auto
hoelzl@60036
  1087
hoelzl@60036
  1088
lemma filterlim_sequentially_Suc:
hoelzl@60036
  1089
  "(LIM x sequentially. f (Suc x) :> F) \<longleftrightarrow> (LIM x sequentially. f x :> F)"
hoelzl@60036
  1090
  unfolding filterlim_iff by (subst eventually_sequentially_Suc) simp
hoelzl@60036
  1091
hoelzl@60036
  1092
lemma filterlim_Suc: "filterlim Suc sequentially sequentially"
hoelzl@60036
  1093
  by (simp add: filterlim_iff eventually_sequentially) (metis le_Suc_eq)
hoelzl@60036
  1094
hoelzl@60182
  1095
lemma filterlim_If:
hoelzl@60182
  1096
  "LIM x inf F (principal {x. P x}). f x :> G \<Longrightarrow>
hoelzl@60182
  1097
    LIM x inf F (principal {x. \<not> P x}). g x :> G \<Longrightarrow>
hoelzl@60182
  1098
    LIM x F. if P x then f x else g x :> G"
hoelzl@60182
  1099
  unfolding filterlim_iff eventually_inf_principal by (auto simp: eventually_conj_iff)
hoelzl@60036
  1100
hoelzl@62367
  1101
lemma filterlim_Pair:
hoelzl@62367
  1102
  "LIM x F. f x :> G \<Longrightarrow> LIM x F. g x :> H \<Longrightarrow> LIM x F. (f x, g x) :> G \<times>\<^sub>F H"
hoelzl@62367
  1103
  unfolding filterlim_def
hoelzl@62367
  1104
  by (rule order_trans[OF filtermap_Pair prod_filter_mono])
hoelzl@62367
  1105
wenzelm@60758
  1106
subsection \<open>Limits to @{const at_top} and @{const at_bot}\<close>
hoelzl@60036
  1107
hoelzl@60036
  1108
lemma filterlim_at_top:
hoelzl@60036
  1109
  fixes f :: "'a \<Rightarrow> ('b::linorder)"
hoelzl@60036
  1110
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z \<le> f x) F)"
lp15@61810
  1111
  by (auto simp: filterlim_iff eventually_at_top_linorder elim!: eventually_mono)
hoelzl@60036
  1112
hoelzl@60036
  1113
lemma filterlim_at_top_mono:
hoelzl@60036
  1114
  "LIM x F. f x :> at_top \<Longrightarrow> eventually (\<lambda>x. f x \<le> (g x::'a::linorder)) F \<Longrightarrow>
hoelzl@60036
  1115
    LIM x F. g x :> at_top"
hoelzl@60036
  1116
  by (auto simp: filterlim_at_top elim: eventually_elim2 intro: order_trans)
hoelzl@60036
  1117
hoelzl@60036
  1118
lemma filterlim_at_top_dense:
hoelzl@60036
  1119
  fixes f :: "'a \<Rightarrow> ('b::unbounded_dense_linorder)"
hoelzl@60036
  1120
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z < f x) F)"
lp15@61810
  1121
  by (metis eventually_mono[of _ F] eventually_gt_at_top order_less_imp_le
hoelzl@60036
  1122
            filterlim_at_top[of f F] filterlim_iff[of f at_top F])
hoelzl@60036
  1123
hoelzl@60036
  1124
lemma filterlim_at_top_ge:
hoelzl@60036
  1125
  fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
hoelzl@60036
  1126
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z\<ge>c. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@60036
  1127
  unfolding at_top_sub[of c] filterlim_INF by (auto simp add: filterlim_principal)
hoelzl@60036
  1128
hoelzl@60036
  1129
lemma filterlim_at_top_at_top:
hoelzl@60036
  1130
  fixes f :: "'a::linorder \<Rightarrow> 'b::linorder"
hoelzl@60036
  1131
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@60036
  1132
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@60036
  1133
  assumes Q: "eventually Q at_top"
hoelzl@60036
  1134
  assumes P: "eventually P at_top"
hoelzl@60036
  1135
  shows "filterlim f at_top at_top"
hoelzl@60036
  1136
proof -
hoelzl@60036
  1137
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@60036
  1138
    unfolding eventually_at_top_linorder by auto
hoelzl@60036
  1139
  show ?thesis
hoelzl@60036
  1140
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
hoelzl@60036
  1141
    fix z assume "x \<le> z"
hoelzl@60036
  1142
    with x have "P z" by auto
hoelzl@60036
  1143
    have "eventually (\<lambda>x. g z \<le> x) at_top"
hoelzl@60036
  1144
      by (rule eventually_ge_at_top)
hoelzl@60036
  1145
    with Q show "eventually (\<lambda>x. z \<le> f x) at_top"
wenzelm@60758
  1146
      by eventually_elim (metis mono bij \<open>P z\<close>)
hoelzl@60036
  1147
  qed
hoelzl@60036
  1148
qed
hoelzl@60036
  1149
hoelzl@60036
  1150
lemma filterlim_at_top_gt:
hoelzl@60036
  1151
  fixes f :: "'a \<Rightarrow> ('b::unbounded_dense_linorder)" and c :: "'b"
hoelzl@60036
  1152
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z>c. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@60036
  1153
  by (metis filterlim_at_top order_less_le_trans gt_ex filterlim_at_top_ge)
hoelzl@60036
  1154
lp15@61806
  1155
lemma filterlim_at_bot:
hoelzl@60036
  1156
  fixes f :: "'a \<Rightarrow> ('b::linorder)"
hoelzl@60036
  1157
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x \<le> Z) F)"
lp15@61810
  1158
  by (auto simp: filterlim_iff eventually_at_bot_linorder elim!: eventually_mono)
hoelzl@60036
  1159
hoelzl@60036
  1160
lemma filterlim_at_bot_dense:
hoelzl@60036
  1161
  fixes f :: "'a \<Rightarrow> ('b::{dense_linorder, no_bot})"
hoelzl@60036
  1162
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x < Z) F)"
hoelzl@60036
  1163
proof (auto simp add: filterlim_at_bot[of f F])
hoelzl@60036
  1164
  fix Z :: 'b
hoelzl@60036
  1165
  from lt_ex [of Z] obtain Z' where 1: "Z' < Z" ..
hoelzl@60036
  1166
  assume "\<forall>Z. eventually (\<lambda>x. f x \<le> Z) F"
hoelzl@60036
  1167
  hence "eventually (\<lambda>x. f x \<le> Z') F" by auto
hoelzl@60036
  1168
  thus "eventually (\<lambda>x. f x < Z) F"
lp15@61810
  1169
    apply (rule eventually_mono)
hoelzl@60036
  1170
    using 1 by auto
lp15@61806
  1171
  next
lp15@61806
  1172
    fix Z :: 'b
hoelzl@60036
  1173
    show "\<forall>Z. eventually (\<lambda>x. f x < Z) F \<Longrightarrow> eventually (\<lambda>x. f x \<le> Z) F"
lp15@61810
  1174
      by (drule spec [of _ Z], erule eventually_mono, auto simp add: less_imp_le)
hoelzl@60036
  1175
qed
hoelzl@60036
  1176
hoelzl@60036
  1177
lemma filterlim_at_bot_le:
hoelzl@60036
  1178
  fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
hoelzl@60036
  1179
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F)"
hoelzl@60036
  1180
  unfolding filterlim_at_bot
hoelzl@60036
  1181
proof safe
hoelzl@60036
  1182
  fix Z assume *: "\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F"
hoelzl@60036
  1183
  with *[THEN spec, of "min Z c"] show "eventually (\<lambda>x. Z \<ge> f x) F"
lp15@61810
  1184
    by (auto elim!: eventually_mono)
hoelzl@60036
  1185
qed simp
hoelzl@60036
  1186
hoelzl@60036
  1187
lemma filterlim_at_bot_lt:
hoelzl@60036
  1188
  fixes f :: "'a \<Rightarrow> ('b::unbounded_dense_linorder)" and c :: "'b"
hoelzl@60036
  1189
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z<c. eventually (\<lambda>x. Z \<ge> f x) F)"
hoelzl@60036
  1190
  by (metis filterlim_at_bot filterlim_at_bot_le lt_ex order_le_less_trans)
hoelzl@60036
  1191
hoelzl@60036
  1192
wenzelm@60758
  1193
subsection \<open>Setup @{typ "'a filter"} for lifting and transfer\<close>
hoelzl@60036
  1194
hoelzl@60036
  1195
context begin interpretation lifting_syntax .
hoelzl@60036
  1196
hoelzl@60036
  1197
definition rel_filter :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> 'b filter \<Rightarrow> bool"
hoelzl@60036
  1198
where "rel_filter R F G = ((R ===> op =) ===> op =) (Rep_filter F) (Rep_filter G)"
hoelzl@60036
  1199
hoelzl@60036
  1200
lemma rel_filter_eventually:
lp15@61806
  1201
  "rel_filter R F G \<longleftrightarrow>
hoelzl@60036
  1202
  ((R ===> op =) ===> op =) (\<lambda>P. eventually P F) (\<lambda>P. eventually P G)"
hoelzl@60036
  1203
by(simp add: rel_filter_def eventually_def)
hoelzl@60036
  1204
hoelzl@60036
  1205
lemma filtermap_id [simp, id_simps]: "filtermap id = id"
hoelzl@60036
  1206
by(simp add: fun_eq_iff id_def filtermap_ident)
hoelzl@60036
  1207
hoelzl@60036
  1208
lemma filtermap_id' [simp]: "filtermap (\<lambda>x. x) = (\<lambda>F. F)"
hoelzl@60036
  1209
using filtermap_id unfolding id_def .
hoelzl@60036
  1210
hoelzl@60036
  1211
lemma Quotient_filter [quot_map]:
hoelzl@60036
  1212
  assumes Q: "Quotient R Abs Rep T"
hoelzl@60036
  1213
  shows "Quotient (rel_filter R) (filtermap Abs) (filtermap Rep) (rel_filter T)"
hoelzl@60036
  1214
unfolding Quotient_alt_def
hoelzl@60036
  1215
proof(intro conjI strip)
hoelzl@60036
  1216
  from Q have *: "\<And>x y. T x y \<Longrightarrow> Abs x = y"
hoelzl@60036
  1217
    unfolding Quotient_alt_def by blast
hoelzl@60036
  1218
hoelzl@60036
  1219
  fix F G
hoelzl@60036
  1220
  assume "rel_filter T F G"
hoelzl@60036
  1221
  thus "filtermap Abs F = G" unfolding filter_eq_iff
hoelzl@60036
  1222
    by(auto simp add: eventually_filtermap rel_filter_eventually * rel_funI del: iffI elim!: rel_funD)
hoelzl@60036
  1223
next
hoelzl@60036
  1224
  from Q have *: "\<And>x. T (Rep x) x" unfolding Quotient_alt_def by blast
hoelzl@60036
  1225
hoelzl@60036
  1226
  fix F
lp15@61806
  1227
  show "rel_filter T (filtermap Rep F) F"
hoelzl@60036
  1228
    by(auto elim: rel_funD intro: * intro!: ext arg_cong[where f="\<lambda>P. eventually P F"] rel_funI
hoelzl@60036
  1229
            del: iffI simp add: eventually_filtermap rel_filter_eventually)
hoelzl@60036
  1230
qed(auto simp add: map_fun_def o_def eventually_filtermap filter_eq_iff fun_eq_iff rel_filter_eventually
hoelzl@60036
  1231
         fun_quotient[OF fun_quotient[OF Q identity_quotient] identity_quotient, unfolded Quotient_alt_def])
hoelzl@60036
  1232
hoelzl@60036
  1233
lemma eventually_parametric [transfer_rule]:
hoelzl@60036
  1234
  "((A ===> op =) ===> rel_filter A ===> op =) eventually eventually"
hoelzl@60036
  1235
by(simp add: rel_fun_def rel_filter_eventually)
hoelzl@60036
  1236
hoelzl@60038
  1237
lemma frequently_parametric [transfer_rule]:
hoelzl@60038
  1238
  "((A ===> op =) ===> rel_filter A ===> op =) frequently frequently"
hoelzl@60038
  1239
  unfolding frequently_def[abs_def] by transfer_prover
hoelzl@60038
  1240
hoelzl@60036
  1241
lemma rel_filter_eq [relator_eq]: "rel_filter op = = op ="
hoelzl@60036
  1242
by(auto simp add: rel_filter_eventually rel_fun_eq fun_eq_iff filter_eq_iff)
hoelzl@60036
  1243
hoelzl@60036
  1244
lemma rel_filter_mono [relator_mono]:
hoelzl@60036
  1245
  "A \<le> B \<Longrightarrow> rel_filter A \<le> rel_filter B"
hoelzl@60036
  1246
unfolding rel_filter_eventually[abs_def]
hoelzl@60036
  1247
by(rule le_funI)+(intro fun_mono fun_mono[THEN le_funD, THEN le_funD] order.refl)
hoelzl@60036
  1248
hoelzl@60036
  1249
lemma rel_filter_conversep [simp]: "rel_filter A\<inverse>\<inverse> = (rel_filter A)\<inverse>\<inverse>"
lp15@61233
  1250
apply (simp add: rel_filter_eventually fun_eq_iff rel_fun_def)
lp15@61233
  1251
apply (safe; metis)
lp15@61233
  1252
done
hoelzl@60036
  1253
hoelzl@60036
  1254
lemma is_filter_parametric_aux:
hoelzl@60036
  1255
  assumes "is_filter F"
hoelzl@60036
  1256
  assumes [transfer_rule]: "bi_total A" "bi_unique A"
hoelzl@60036
  1257
  and [transfer_rule]: "((A ===> op =) ===> op =) F G"
hoelzl@60036
  1258
  shows "is_filter G"
hoelzl@60036
  1259
proof -
hoelzl@60036
  1260
  interpret is_filter F by fact
hoelzl@60036
  1261
  show ?thesis
hoelzl@60036
  1262
  proof
hoelzl@60036
  1263
    have "F (\<lambda>_. True) = G (\<lambda>x. True)" by transfer_prover
hoelzl@60036
  1264
    thus "G (\<lambda>x. True)" by(simp add: True)
hoelzl@60036
  1265
  next
hoelzl@60036
  1266
    fix P' Q'
hoelzl@60036
  1267
    assume "G P'" "G Q'"
hoelzl@60036
  1268
    moreover
wenzelm@60758
  1269
    from bi_total_fun[OF \<open>bi_unique A\<close> bi_total_eq, unfolded bi_total_def]
hoelzl@60036
  1270
    obtain P Q where [transfer_rule]: "(A ===> op =) P P'" "(A ===> op =) Q Q'" by blast
hoelzl@60036
  1271
    have "F P = G P'" "F Q = G Q'" by transfer_prover+
hoelzl@60036
  1272
    ultimately have "F (\<lambda>x. P x \<and> Q x)" by(simp add: conj)
hoelzl@60036
  1273
    moreover have "F (\<lambda>x. P x \<and> Q x) = G (\<lambda>x. P' x \<and> Q' x)" by transfer_prover
hoelzl@60036
  1274
    ultimately show "G (\<lambda>x. P' x \<and> Q' x)" by simp
hoelzl@60036
  1275
  next
hoelzl@60036
  1276
    fix P' Q'
hoelzl@60036
  1277
    assume "\<forall>x. P' x \<longrightarrow> Q' x" "G P'"
hoelzl@60036
  1278
    moreover
wenzelm@60758
  1279
    from bi_total_fun[OF \<open>bi_unique A\<close> bi_total_eq, unfolded bi_total_def]
hoelzl@60036
  1280
    obtain P Q where [transfer_rule]: "(A ===> op =) P P'" "(A ===> op =) Q Q'" by blast
hoelzl@60036
  1281
    have "F P = G P'" by transfer_prover
hoelzl@60036
  1282
    moreover have "(\<forall>x. P x \<longrightarrow> Q x) \<longleftrightarrow> (\<forall>x. P' x \<longrightarrow> Q' x)" by transfer_prover
hoelzl@60036
  1283
    ultimately have "F Q" by(simp add: mono)
hoelzl@60036
  1284
    moreover have "F Q = G Q'" by transfer_prover
hoelzl@60036
  1285
    ultimately show "G Q'" by simp
hoelzl@60036
  1286
  qed
hoelzl@60036
  1287
qed
hoelzl@60036
  1288
hoelzl@60036
  1289
lemma is_filter_parametric [transfer_rule]:
hoelzl@60036
  1290
  "\<lbrakk> bi_total A; bi_unique A \<rbrakk>
hoelzl@60036
  1291
  \<Longrightarrow> (((A ===> op =) ===> op =) ===> op =) is_filter is_filter"
hoelzl@60036
  1292
apply(rule rel_funI)
hoelzl@60036
  1293
apply(rule iffI)
hoelzl@60036
  1294
 apply(erule (3) is_filter_parametric_aux)
hoelzl@60036
  1295
apply(erule is_filter_parametric_aux[where A="conversep A"])
lp15@61233
  1296
apply (simp_all add: rel_fun_def)
lp15@61233
  1297
apply metis
hoelzl@60036
  1298
done
hoelzl@60036
  1299
hoelzl@60036
  1300
lemma left_total_rel_filter [transfer_rule]:
hoelzl@60036
  1301
  assumes [transfer_rule]: "bi_total A" "bi_unique A"
hoelzl@60036
  1302
  shows "left_total (rel_filter A)"
hoelzl@60036
  1303
proof(rule left_totalI)
hoelzl@60036
  1304
  fix F :: "'a filter"
wenzelm@60758
  1305
  from bi_total_fun[OF bi_unique_fun[OF \<open>bi_total A\<close> bi_unique_eq] bi_total_eq]
lp15@61806
  1306
  obtain G where [transfer_rule]: "((A ===> op =) ===> op =) (\<lambda>P. eventually P F) G"
hoelzl@60036
  1307
    unfolding  bi_total_def by blast
hoelzl@60036
  1308
  moreover have "is_filter (\<lambda>P. eventually P F) \<longleftrightarrow> is_filter G" by transfer_prover
hoelzl@60036
  1309
  hence "is_filter G" by(simp add: eventually_def is_filter_Rep_filter)
hoelzl@60036
  1310
  ultimately have "rel_filter A F (Abs_filter G)"
hoelzl@60036
  1311
    by(simp add: rel_filter_eventually eventually_Abs_filter)
hoelzl@60036
  1312
  thus "\<exists>G. rel_filter A F G" ..
hoelzl@60036
  1313
qed
hoelzl@60036
  1314
hoelzl@60036
  1315
lemma right_total_rel_filter [transfer_rule]:
hoelzl@60036
  1316
  "\<lbrakk> bi_total A; bi_unique A \<rbrakk> \<Longrightarrow> right_total (rel_filter A)"
hoelzl@60036
  1317
using left_total_rel_filter[of "A\<inverse>\<inverse>"] by simp
hoelzl@60036
  1318
hoelzl@60036
  1319
lemma bi_total_rel_filter [transfer_rule]:
hoelzl@60036
  1320
  assumes "bi_total A" "bi_unique A"
hoelzl@60036
  1321
  shows "bi_total (rel_filter A)"
hoelzl@60036
  1322
unfolding bi_total_alt_def using assms
hoelzl@60036
  1323
by(simp add: left_total_rel_filter right_total_rel_filter)
hoelzl@60036
  1324
hoelzl@60036
  1325
lemma left_unique_rel_filter [transfer_rule]:
hoelzl@60036
  1326
  assumes "left_unique A"
hoelzl@60036
  1327
  shows "left_unique (rel_filter A)"
hoelzl@60036
  1328
proof(rule left_uniqueI)
hoelzl@60036
  1329
  fix F F' G
hoelzl@60036
  1330
  assume [transfer_rule]: "rel_filter A F G" "rel_filter A F' G"
hoelzl@60036
  1331
  show "F = F'"
hoelzl@60036
  1332
    unfolding filter_eq_iff
hoelzl@60036
  1333
  proof
hoelzl@60036
  1334
    fix P :: "'a \<Rightarrow> bool"
hoelzl@60036
  1335
    obtain P' where [transfer_rule]: "(A ===> op =) P P'"
hoelzl@60036
  1336
      using left_total_fun[OF assms left_total_eq] unfolding left_total_def by blast
lp15@61806
  1337
    have "eventually P F = eventually P' G"
hoelzl@60036
  1338
      and "eventually P F' = eventually P' G" by transfer_prover+
hoelzl@60036
  1339
    thus "eventually P F = eventually P F'" by simp
hoelzl@60036
  1340
  qed
hoelzl@60036
  1341
qed
hoelzl@60036
  1342
hoelzl@60036
  1343
lemma right_unique_rel_filter [transfer_rule]:
hoelzl@60036
  1344
  "right_unique A \<Longrightarrow> right_unique (rel_filter A)"
hoelzl@60036
  1345
using left_unique_rel_filter[of "A\<inverse>\<inverse>"] by simp
hoelzl@60036
  1346
hoelzl@60036
  1347
lemma bi_unique_rel_filter [transfer_rule]:
hoelzl@60036
  1348
  "bi_unique A \<Longrightarrow> bi_unique (rel_filter A)"
hoelzl@60036
  1349
by(simp add: bi_unique_alt_def left_unique_rel_filter right_unique_rel_filter)
hoelzl@60036
  1350
hoelzl@60036
  1351
lemma top_filter_parametric [transfer_rule]:
hoelzl@60036
  1352
  "bi_total A \<Longrightarrow> (rel_filter A) top top"
hoelzl@60036
  1353
by(simp add: rel_filter_eventually All_transfer)
hoelzl@60036
  1354
hoelzl@60036
  1355
lemma bot_filter_parametric [transfer_rule]: "(rel_filter A) bot bot"
hoelzl@60036
  1356
by(simp add: rel_filter_eventually rel_fun_def)
hoelzl@60036
  1357
hoelzl@60036
  1358
lemma sup_filter_parametric [transfer_rule]:
hoelzl@60036
  1359
  "(rel_filter A ===> rel_filter A ===> rel_filter A) sup sup"
hoelzl@60036
  1360
by(fastforce simp add: rel_filter_eventually[abs_def] eventually_sup dest: rel_funD)
hoelzl@60036
  1361
hoelzl@60036
  1362
lemma Sup_filter_parametric [transfer_rule]:
hoelzl@60036
  1363
  "(rel_set (rel_filter A) ===> rel_filter A) Sup Sup"
hoelzl@60036
  1364
proof(rule rel_funI)
hoelzl@60036
  1365
  fix S T
hoelzl@60036
  1366
  assume [transfer_rule]: "rel_set (rel_filter A) S T"
hoelzl@60036
  1367
  show "rel_filter A (Sup S) (Sup T)"
hoelzl@60036
  1368
    by(simp add: rel_filter_eventually eventually_Sup) transfer_prover
hoelzl@60036
  1369
qed
hoelzl@60036
  1370
hoelzl@60036
  1371
lemma principal_parametric [transfer_rule]:
hoelzl@60036
  1372
  "(rel_set A ===> rel_filter A) principal principal"
hoelzl@60036
  1373
proof(rule rel_funI)
hoelzl@60036
  1374
  fix S S'
hoelzl@60036
  1375
  assume [transfer_rule]: "rel_set A S S'"
hoelzl@60036
  1376
  show "rel_filter A (principal S) (principal S')"
hoelzl@60036
  1377
    by(simp add: rel_filter_eventually eventually_principal) transfer_prover
hoelzl@60036
  1378
qed
hoelzl@60036
  1379
hoelzl@60036
  1380
context
hoelzl@60036
  1381
  fixes A :: "'a \<Rightarrow> 'b \<Rightarrow> bool"
lp15@61806
  1382
  assumes [transfer_rule]: "bi_unique A"
hoelzl@60036
  1383
begin
hoelzl@60036
  1384
hoelzl@60036
  1385
lemma le_filter_parametric [transfer_rule]:
hoelzl@60036
  1386
  "(rel_filter A ===> rel_filter A ===> op =) op \<le> op \<le>"
hoelzl@60036
  1387
unfolding le_filter_def[abs_def] by transfer_prover
hoelzl@60036
  1388
hoelzl@60036
  1389
lemma less_filter_parametric [transfer_rule]:
hoelzl@60036
  1390
  "(rel_filter A ===> rel_filter A ===> op =) op < op <"
hoelzl@60036
  1391
unfolding less_filter_def[abs_def] by transfer_prover
hoelzl@60036
  1392
hoelzl@60036
  1393
context
hoelzl@60036
  1394
  assumes [transfer_rule]: "bi_total A"
hoelzl@60036
  1395
begin
hoelzl@60036
  1396
hoelzl@60036
  1397
lemma Inf_filter_parametric [transfer_rule]:
hoelzl@60036
  1398
  "(rel_set (rel_filter A) ===> rel_filter A) Inf Inf"
hoelzl@60036
  1399
unfolding Inf_filter_def[abs_def] by transfer_prover
hoelzl@60036
  1400
hoelzl@60036
  1401
lemma inf_filter_parametric [transfer_rule]:
hoelzl@60036
  1402
  "(rel_filter A ===> rel_filter A ===> rel_filter A) inf inf"
hoelzl@60036
  1403
proof(intro rel_funI)+
hoelzl@60036
  1404
  fix F F' G G'
hoelzl@60036
  1405
  assume [transfer_rule]: "rel_filter A F F'" "rel_filter A G G'"
hoelzl@60036
  1406
  have "rel_filter A (Inf {F, G}) (Inf {F', G'})" by transfer_prover
hoelzl@60036
  1407
  thus "rel_filter A (inf F G) (inf F' G')" by simp
hoelzl@60036
  1408
qed
hoelzl@60036
  1409
hoelzl@60036
  1410
end
hoelzl@60036
  1411
hoelzl@60036
  1412
end
hoelzl@60036
  1413
hoelzl@60036
  1414
end
hoelzl@60036
  1415
hoelzl@62123
  1416
text \<open>Code generation for filters\<close>
hoelzl@62123
  1417
hoelzl@62123
  1418
definition abstract_filter :: "(unit \<Rightarrow> 'a filter) \<Rightarrow> 'a filter"
hoelzl@62123
  1419
  where [simp]: "abstract_filter f = f ()"
hoelzl@62123
  1420
hoelzl@62123
  1421
code_datatype principal abstract_filter
hoelzl@62123
  1422
hoelzl@62123
  1423
hide_const (open) abstract_filter
hoelzl@62123
  1424
hoelzl@62123
  1425
declare [[code drop: filterlim prod_filter filtermap eventually
hoelzl@62123
  1426
  "inf :: _ filter \<Rightarrow> _" "sup :: _ filter \<Rightarrow> _" "less_eq :: _ filter \<Rightarrow> _"
hoelzl@62123
  1427
  Abs_filter]]
hoelzl@62123
  1428
hoelzl@62123
  1429
declare filterlim_principal [code]
hoelzl@62123
  1430
declare principal_prod_principal [code]
hoelzl@62123
  1431
declare filtermap_principal [code]
hoelzl@62123
  1432
declare eventually_principal [code]
hoelzl@62123
  1433
declare inf_principal [code]
hoelzl@62123
  1434
declare sup_principal [code]
hoelzl@62123
  1435
declare principal_le_iff [code]
hoelzl@62123
  1436
hoelzl@62123
  1437
lemma Rep_filter_iff_eventually [simp, code]:
hoelzl@62123
  1438
  "Rep_filter F P \<longleftrightarrow> eventually P F"
hoelzl@62123
  1439
  by (simp add: eventually_def)
hoelzl@62123
  1440
hoelzl@62123
  1441
lemma bot_eq_principal_empty [code]:
hoelzl@62123
  1442
  "bot = principal {}"
hoelzl@62123
  1443
  by simp
hoelzl@62123
  1444
hoelzl@62123
  1445
lemma top_eq_principal_UNIV [code]:
hoelzl@62123
  1446
  "top = principal UNIV"
hoelzl@62123
  1447
  by simp
hoelzl@62123
  1448
hoelzl@62123
  1449
instantiation filter :: (equal) equal
hoelzl@62123
  1450
begin
hoelzl@62123
  1451
hoelzl@62123
  1452
definition equal_filter :: "'a filter \<Rightarrow> 'a filter \<Rightarrow> bool"
hoelzl@62123
  1453
  where "equal_filter F F' \<longleftrightarrow> F = F'"
hoelzl@62123
  1454
hoelzl@62123
  1455
lemma equal_filter [code]:
hoelzl@62123
  1456
  "HOL.equal (principal A) (principal B) \<longleftrightarrow> A = B"
hoelzl@62123
  1457
  by (simp add: equal_filter_def)
hoelzl@62123
  1458
hoelzl@62123
  1459
instance
hoelzl@62123
  1460
  by standard (simp add: equal_filter_def)
hoelzl@62123
  1461
lp15@61806
  1462
end
hoelzl@62123
  1463
hoelzl@62123
  1464
end