-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L67-L69)
def IsDynNetIn (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) (s : Set X) : Prop :=
s ⊆ F ∧ s.PairwiseDisjoint fun x : X ↦ ball x (dynEntourage T U n)

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L70-L72)
lemma IsDynNetIn.of_le (m_n : m ≤ n) (h : IsDynNetIn T F U m s) : IsDynNetIn T F U n s :=
⟨h.1, PairwiseDisjoint.mono h.2 fun x ↦ ball_mono (dynEntourage_antitone T U m_n) x⟩

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L73-L76)
lemma IsDynNetIn.of_entourage_subset (U_V : U ⊆ V) (h : IsDynNetIn T F V n s) :
    IsDynNetIn T F U n s :=
⟨h.1, PairwiseDisjoint.mono h.2 fun x ↦ ball_mono (dynEntourage_monotone T n U_V) x⟩

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.isDynNetIn_empty (L77-L78)
lemma isDynNetIn_empty : IsDynNetIn T F U n ∅ := ⟨empty_subset F, pairwise_empty _⟩

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L103-L106)
lemma IsDynNetIn.card_le_netMaxcard {s : Finset X} (h : IsDynNetIn T F U n s) :
    s.card ≤ netMaxcard T F U n :=
le_iSup₂ (α := ℕ∞) s h

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_monotone_time (L107-L110)
lemma netMaxcard_monotone_time (T : X → X) (F : Set X) (U : SetRel X X) :
    Monotone fun n : ℕ ↦ netMaxcard T F U n :=
fun _ _ m_n ↦ biSup_mono fun _ h ↦ h.of_le m_n

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.one_le_netMaxcard_iff (L170-L174)
lemma one_le_netMaxcard_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    1 ≤ netMaxcard T F U n ↔ F.Nonempty := by
rw [ENat.one_le_iff_ne_zero, nonempty_iff_ne_empty]
  exact not_iff_not.2 (netMaxcard_eq_zero_iff T F U n)

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_antitone (L266-L269)
lemma netEntropyEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ netEntropyEntourage T F U :=
fun _ _ U_V ↦ expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (netMaxcard_antitone T F n U_V)

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_le_netEntropyEntourage (L270-L273)
lemma netEntropyInfEntourage_le_netEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :
    netEntropyInfEntourage T F U ≤ netEntropyEntourage T F U :=
expGrowthInf_le_expGrowthSup

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_empty (L275-L279)
lemma netEntropyEntourage_empty : netEntropyEntourage T ∅ U = ⊥ := by
rw [netEntropyEntourage, ← expGrowthSup_zero]
  congr
  simp only [netMaxcard_empty, ENat.toENNReal_zero, Pi.zero_def]

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_empty (L281-L283)
lemma netEntropyInfEntourage_empty : netEntropyInfEntourage T ∅ U = ⊥ :=
eq_bot_mono (netEntropyInfEntourage_le_netEntropyEntourage T ∅ U) netEntropyEntourage_empty

-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_nonneg (L293-L296)
lemma netEntropyEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ netEntropyEntourage T F U :=
(netEntropyInfEntourage_nonneg T h U).trans (netEntropyInfEntourage_le_netEntropyEntourage T F U)

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_empty (L486-L488)
lemma coverEntropyInf_empty : coverEntropyInf T ∅ = ⊥ := by
simp only [coverEntropyInf, coverEntropyInfEntourage_empty, iSup_bot]

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_monotone_time (L213-L216)
lemma coverMincard_monotone_time (T : X → X) (F : Set X) (U : SetRel X X) :
    Monotone fun n : ℕ ↦ coverMincard T F U n :=
fun _ _ m_n ↦ biInf_mono fun _ h ↦ h.of_le m_n

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_antitone (L442-L447)
lemma coverEntropy_antitone (T : X → X) (F : Set X) :
    Antitone fun (u : UniformSpace X) ↦ @coverEntropy X u T F :=
fun _ _ h ↦ iSup₂_mono' fun U U_uni ↦ ⟨U, (le_def.1 h) U U_uni, le_refl _⟩

variable [UniformSpace X]

-- Mathlib.Dynamics.TopologicalEntropy.Subset.IsDynCoverOf (L50-L53)
lemma IsDynCoverOf.monotone_subset (F_G : F ⊆ G) (h : IsDynCoverOf T G U n s) :
    IsDynCoverOf T F U n s :=
F_G.trans h

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.isDynCoverOf_zero (L94-L96)
lemma isDynCoverOf_zero (T : X → X) (F : Set X) (U : SetRel X X) (h : s.Nonempty) :
    IsDynCoverOf T F U 0 s := by simp [IsDynCoverOf, h]

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_ball_dynEntourage (L61-L64)
lemma mem_ball_dynEntourage :
    y ∈ ball x (dynEntourage T U n) ↔ ∀ k < n, T^[k] y ∈ ball (T^[k] x) U := by
simp only [ball, mem_preimage, mem_dynEntourage]

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_eq_zero_iff (L246-L249)
lemma coverMincard_eq_zero_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    coverMincard T F U n = 0 ↔ F = ∅ := by
simp [coverMincard, ENat.iInf_eq_zero]

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.isDynCoverOf_univ (L97-L99)
lemma isDynCoverOf_univ (T : X → X) (F : Set X) (n : ℕ) (h : s.Nonempty) :
    IsDynCoverOf T F univ n s := by simp [IsDynCoverOf, h]

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.isSymm_dynEntourage (L91-L94)
instance isSymm_dynEntourage [U.IsSymm] : (dynEntourage T U n).IsSymm := by
simp [dynEntourage]; infer_instance

set_option linter.deprecated false in

-- Mathlib.Dynamics.TopologicalEntropy.Subset.IsDynNetIn (L54-L56)
lemma IsDynNetIn.monotone_subset (F_G : F ⊆ G) (h : IsDynNetIn T F U n s) : IsDynNetIn T G U n s :=
⟨h.1.trans F_G, h.2⟩

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_le_coverEntropy (L476-L480)
lemma coverEntropyInf_le_coverEntropy (T : X → X) (F : Set X) :
    coverEntropyInf T F ≤ coverEntropy T F :=
iSup₂_mono fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦
    coverEntropyInfEntourage_le_coverEntropyEntourage T F U

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.isRefl_dynEntourage (L87-L90)
instance isRefl_dynEntourage [U.IsRefl] : (dynEntourage T U n).IsRefl := by
simp [dynEntourage]; infer_instance

set_option linter.flexible false in -- simp followed by infer_instance

-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverMincard_monotone_subset (L57-L60)
lemma coverMincard_monotone_subset (T : X → X) (U : SetRel X X) (n : ℕ) :
    Monotone fun F : Set X ↦ coverMincard T F U n :=
fun _ _ F_G ↦ biInf_mono fun _ h ↦ h.monotone_subset F_G

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_empty (L354-L357)
lemma coverEntropyEntourage_empty : coverEntropyEntourage T ∅ U = ⊥ := by
simp only [coverEntropyEntourage, coverMincard_empty]
  rw [ENat.toENNReal_zero, ← Pi.zero_def, expGrowthSup_zero]

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_antitone (L438-L441)
lemma coverEntropyInf_antitone (T : X → X) (F : Set X) :
    Antitone fun (u : UniformSpace X) ↦ @coverEntropyInf X u T F :=
fun _ _ h ↦ iSup₂_mono' fun U U_uni ↦ ⟨U, (le_def.1 h) U U_uni, le_refl _⟩

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.IsDynCoverOf (L78-L80)
def IsDynCoverOf (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) (s : Set X) : Prop :=
IsCover (dynEntourage T U n) F s

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_antitone (L130-L133)
lemma dynEntourage_antitone (T : X → X) (U : SetRel X X) :
    Antitone (fun n : ℕ ↦ dynEntourage T U n) :=
fun m n m_n ↦ iInter₂_mono' fun k k_m ↦ by use k, lt_of_lt_of_le k_m m_n

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_eq_inter_Ico (L54-L57)
lemma dynEntourage_eq_inter_Ico (T : X → X) (U : SetRel X X) (n : ℕ) :
    dynEntourage T U n = ⋂ k : Ico 0 n, (map T T)^[k] ⁻¹' U := by
simp [dynEntourage]

-- Mathlib.Dynamics.TopologicalEntropy.Subset.netMaxcard_monotone_subset (L61-L64)
lemma netMaxcard_monotone_subset (T : X → X) (U : SetRel X X) (n : ℕ) :
    Monotone fun F : Set X ↦ netMaxcard T F U n :=
fun _ _ F_G ↦ biSup_mono fun _ h ↦ h.monotone_subset F_G

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_empty (L243-L245)
lemma coverMincard_empty : coverMincard T ∅ U n = 0 :=
(sInf_le (by simp [IsDynCoverOf])).antisymm (zero_le (coverMincard T ∅ U n))

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_nonneg (L493-L495)
lemma coverEntropy_nonneg (T : X → X) (h : F.Nonempty) : 0 ≤ coverEntropy T F :=
(coverEntropyInf_nonneg T h).trans (coverEntropyInf_le_coverEntropy T F)

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage (L51-L53)
def dynEntourage (T : X → X) (U : SetRel X X) (n : ℕ) : SetRel X X :=
⋂ k < n, (map T T)^[k] ⁻¹' U

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_monotone (L126-L129)
lemma dynEntourage_monotone (T : X → X) (n : ℕ) :
    Monotone (fun U : SetRel X X ↦ dynEntourage T U n) :=
fun _ _ h ↦ iInter₂_mono fun _ _ ↦ preimage_mono h

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_nonneg (L489-L492)
lemma coverEntropyInf_nonneg (T : X → X) (h : F.Nonempty) : 0 ≤ coverEntropyInf T F :=
(coverEntropyInfEntourage_le_coverEntropyInf T F univ_mem).trans_eq'
    (coverEntropyInfEntourage_univ T h)

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_univ (L142-L144)
lemma dynEntourage_univ {T : X → X} {n : ℕ} :
    dynEntourage T univ n = univ := by simp [dynEntourage]

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_empty (L359-L361)
lemma coverEntropyInfEntourage_empty : coverEntropyInfEntourage T ∅ U = ⊥ :=
eq_bot_mono (coverEntropyInfEntourage_le_coverEntropyEntourage T ∅ U) coverEntropyEntourage_empty

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_mono (L135-L137)
lemma dynEntourage_mono (hUV : U ⊆ V) (hmn : m ≤ n) : dynEntourage T U n ⊆ dynEntourage T V m :=
(dynEntourage_monotone _ _ hUV).trans (dynEntourage_antitone _ _ hmn)

-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_dynEntourage (L58-L60)
lemma mem_dynEntourage : (x, y) ∈ dynEntourage T U n ↔ ∀ k < n, (T^[k] x, T^[k] y) ∈ U := by
simp [dynEntourage]

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_le_coverEntropyEntourage (L349-L352)
lemma coverEntropyInfEntourage_le_coverEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :
    coverEntropyInfEntourage T F U ≤ coverEntropyEntourage T F U :=
expGrowthInf_le_expGrowthSup

-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_empty (L482-L484)
lemma coverEntropy_empty : coverEntropy T ∅ = ⊥ := by
simp only [coverEntropy, coverEntropyEntourage_empty, iSup_bot]

lemma netEntropyInfEntourage_univ (T : X → X) {F : Set X} (h : F.Nonempty) :
    netEntropyInfEntourage T F univ = 0

[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Dynamics.TopologicalEntropy.NetEntropy).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
lemma netEntropyInfEntourage_univ (T : X → X) {F : Set X} (h : F.Nonempty) :
    netEntropyInfEntourage T F univ = 0
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L67-L69)
def IsDynNetIn (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) (s : Set X) : Prop :=
s ⊆ F ∧ s.PairwiseDisjoint fun x : X ↦ ball x (dynEntourage T U n)
```

-- snippet 2
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L70-L72)
lemma IsDynNetIn.of_le (m_n : m ≤ n) (h : IsDynNetIn T F U m s) : IsDynNetIn T F U n s :=
⟨h.1, PairwiseDisjoint.mono h.2 fun x ↦ ball_mono (dynEntourage_antitone T U m_n) x⟩
```

-- snippet 3
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L73-L76)
lemma IsDynNetIn.of_entourage_subset (U_V : U ⊆ V) (h : IsDynNetIn T F V n s) :
    IsDynNetIn T F U n s :=
⟨h.1, PairwiseDisjoint.mono h.2 fun x ↦ ball_mono (dynEntourage_monotone T n U_V) x⟩
```

-- snippet 4
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.isDynNetIn_empty (L77-L78)
lemma isDynNetIn_empty : IsDynNetIn T F U n ∅ := ⟨empty_subset F, pairwise_empty _⟩
```

-- snippet 5
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.isDynNetIn_singleton (L79-L85)
lemma isDynNetIn_singleton (T : X → X) (U : SetRel X X) (n : ℕ) (h : x ∈ F) :
    IsDynNetIn T F U n {x} :=
⟨singleton_subset_iff.2 h, pairwise_singleton x _⟩

/-- Given an entourage `U` and a time `n`, a dynamical net has a smaller cardinality than
  a dynamical cover. This lemma is the first of two key results to compare two versions of
  topological entropy: with cover and with nets, the second being `coverMincard_le_netMaxcard`. -/
```

-- snippet 6
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L86-L102)
lemma IsDynNetIn.card_le_card_of_isDynCoverOf {s t : Finset X}
    (hs : IsDynNetIn T F U n s) (ht : IsDynCoverOf T F U n t) :
    s.card ≤ t.card := by
have (x : X) (x_s : x ∈ s) : ∃ z ∈ t, z ∈ ball x (dynEntourage T U n) := by
    simpa using ht (hs.1 x_s)
  choose! F s_t using this
  apply Finset.card_le_card_of_injOn F fun x x_s ↦ (s_t x x_s).1
  exact fun x x_s y y_s Fx_Fy ↦
    PairwiseDisjoint.elim_set hs.2 x_s y_s (F x) (s_t x x_s).2 (Fx_Fy ▸ (s_t y y_s).2)

/-! ### Maximal cardinality of dynamical nets -/

/-- The largest cardinality of a `(U, n)`-dynamical net of `F`. Takes values in `ℕ∞`, and is
infinite if and only if `F` admits nets of arbitrarily large size. -/
noncomputable def netMaxcard (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) : ℕ∞ :=
  ⨆ (s : Finset X) (_ : IsDynNetIn T F U n s), (s.card : ℕ∞)
```

-- snippet 7
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L103-L106)
lemma IsDynNetIn.card_le_netMaxcard {s : Finset X} (h : IsDynNetIn T F U n s) :
    s.card ≤ netMaxcard T F U n :=
le_iSup₂ (α := ℕ∞) s h
```

-- snippet 8
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_monotone_time (L107-L110)
lemma netMaxcard_monotone_time (T : X → X) (F : Set X) (U : SetRel X X) :
    Monotone fun n : ℕ ↦ netMaxcard T F U n :=
fun _ _ m_n ↦ biSup_mono fun _ h ↦ h.of_le m_n
```

-- snippet 9
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_antitone (L111-L115)
lemma netMaxcard_antitone (T : X → X) (F : Set X) (n : ℕ) :
    Antitone fun U : SetRel X X ↦ netMaxcard T F U n :=
fun _ _ U_V ↦ biSup_mono fun _ h ↦ h.of_entourage_subset U_V

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 10
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_finite_iff (L116-L150)
lemma netMaxcard_finite_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    netMaxcard T F U n < ⊤ ↔
    ∃ s : Finset X, IsDynNetIn T F U n s ∧ (s.card : ℕ∞) = netMaxcard T F U n := by
apply Iff.intro <;> intro h
  · obtain ⟨k, k_max⟩ := WithTop.ne_top_iff_exists.1 h.ne
    rw [← k_max]
    simp only [ENat.some_eq_coe, Nat.cast_inj]
    -- The criterion we want to use is `Nat.sSup_mem`. We rewrite `netMaxcard` with an `sSup`,
    -- then check its `BddAbove` and `Nonempty` hypotheses.
    have : netMaxcard T F U n
      = sSup (WithTop.some '' (Finset.card '' {s : Finset X | IsDynNetIn T F U n s})) := by
      rw [netMaxcard, ← image_comp, sSup_image]
      simp only [mem_setOf_eq, ENat.some_eq_coe, Function.comp_apply]
    rw [this] at k_max
    have h_bdda : BddAbove (Finset.card '' {s : Finset X | IsDynNetIn T F U n s}) := by
      refine ⟨k, mem_upperBounds.2 ?_⟩
      simp only [mem_image, mem_setOf_eq, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
      intro s h
      rw [← WithTop.coe_le_coe, k_max]
      apply le_sSup
      simp only [ENat.some_eq_coe, mem_image, mem_setOf_eq, Nat.cast_inj, exists_eq_right]
      exact Filter.frequently_principal.mp fun a ↦ a h rfl
    have h_nemp : (Finset.card '' {s : Finset X | IsDynNetIn T F U n s}).Nonempty := by
      refine ⟨0, ?_⟩
      simp only [mem_image, mem_setOf_eq, Finset.card_eq_zero, exists_eq_right, Finset.coe_empty]
      exact isDynNetIn_empty
    rw [← WithTop.coe_sSup' h_bdda, ENat.some_eq_coe, Nat.cast_inj] at k_max
    have key := Nat.sSup_mem h_nemp h_bdda
    rw [← k_max, mem_image] at key
    simp only [mem_setOf_eq] at key
    exact key
  · obtain ⟨s, _, s_card⟩ := h
    rw [← s_card]
    exact WithTop.coe_lt_top s.card
```

-- snippet 11
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_empty (L152-L158)
lemma netMaxcard_empty : netMaxcard T ∅ U n = 0 := by
rw [netMaxcard, ← bot_eq_zero, iSup₂_eq_bot]
  intro s s_net
  replace s_net := subset_empty_iff.1 s_net.1
  norm_cast at s_net
  rw [s_net, Finset.card_empty, CharP.cast_eq_zero, bot_eq_zero']
```

-- snippet 12
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_eq_zero_iff (L159-L169)
lemma netMaxcard_eq_zero_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    netMaxcard T F U n = 0 ↔ F = ∅ := by
refine ⟨fun h ↦ ?_, fun h ↦ by rw [h, netMaxcard_empty]⟩
  rw [eq_empty_iff_forall_notMem]
  intro x x_F
  have key := isDynNetIn_singleton T U n x_F
  rw [← Finset.coe_singleton] at key
  replace key := key.card_le_netMaxcard
  rw [Finset.card_singleton, Nat.cast_one, h] at key
  exact key.not_gt zero_lt_one
```

-- snippet 13
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.one_le_netMaxcard_iff (L170-L174)
lemma one_le_netMaxcard_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    1 ≤ netMaxcard T F U n ↔ F.Nonempty := by
rw [ENat.one_le_iff_ne_zero, nonempty_iff_ne_empty]
  exact not_iff_not.2 (netMaxcard_eq_zero_iff T F U n)
```

-- snippet 14
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_zero (L175-L182)
lemma netMaxcard_zero (T : X → X) (h : F.Nonempty) (U : SetRel X X) : netMaxcard T F U 0 = 1 := by
apply (iSup₂_le _).antisymm ((one_le_netMaxcard_iff T F U 0).2 h)
  intro s ⟨_, s_net⟩
  simp only [ball, dynEntourage_zero, preimage_univ] at s_net
  norm_cast
  refine Finset.card_le_one.2 fun x x_s y y_s ↦ ?_
  exact PairwiseDisjoint.elim_set s_net x_s y_s x (mem_univ x) (mem_univ x)
```

-- snippet 15
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_univ (L183-L191)
lemma netMaxcard_univ (T : X → X) (h : F.Nonempty) (n : ℕ) : netMaxcard T F univ n = 1 := by
apply (iSup₂_le _).antisymm ((one_le_netMaxcard_iff T F univ n).2 h)
  intro s ⟨_, s_net⟩
  simp only [ball, dynEntourage_univ, preimage_univ] at s_net
  norm_cast
  refine Finset.card_le_one.2 fun x x_s y y_s ↦ ?_
  exact PairwiseDisjoint.elim_set s_net x_s y_s x (mem_univ x) (mem_univ x)

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 16
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_infinite_iff (L192-L207)
lemma netMaxcard_infinite_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    netMaxcard T F U n = ⊤ ↔ ∀ k : ℕ, ∃ s : Finset X, IsDynNetIn T F U n s ∧ k ≤ s.card := by
apply Iff.intro <;> intro h
  · intro k
    rw [netMaxcard, iSup_subtype', iSup_eq_top] at h
    specialize h k (ENat.coe_lt_top k)
    simp only [Nat.cast_lt, Subtype.exists, exists_prop] at h
    obtain ⟨s, s_net, s_k⟩ := h
    exact ⟨s, s_net, s_k.le⟩
  · refine WithTop.eq_top_iff_forall_gt.2 fun k ↦ ?_
    specialize h (k + 1)
    obtain ⟨s, s_net, s_card⟩ := h
    apply s_net.card_le_netMaxcard.trans_lt'
    rw [ENat.some_eq_coe, Nat.cast_lt]
    exact (lt_add_one k).trans_le s_card
```

-- snippet 17
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_le_coverMincard (L208-L218)
lemma netMaxcard_le_coverMincard (T : X → X) (F : Set X) (n : ℕ) :
    netMaxcard T F U n ≤ coverMincard T F U n := by
rcases eq_top_or_lt_top (coverMincard T F U n) with h | h
  · exact h ▸ le_top
  · obtain ⟨t, t_cover, t_mincard⟩ := (coverMincard_finite_iff T F U n).1 h
    rw [← t_mincard]
    exact iSup₂_le fun s s_net ↦ Nat.cast_le.2 (s_net.card_le_card_of_isDynCoverOf t_cover)

/-- Given an entourage `U` and a time `n`, a minimal dynamical cover by `U ○ U` has a smaller
  cardinality than a maximal dynamical net by `U`. This lemma is the second of two key results to
  compare two versions topological entropy: with cover and with nets. -/
```

-- snippet 18
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.coverMincard_le_netMaxcard (L219-L261)
lemma coverMincard_le_netMaxcard (T : X → X) (F : Set X) [U.IsRefl] [U.IsSymm] (n : ℕ) :
    coverMincard T F (U ○ U) n ≤ netMaxcard T F U n := by
classical
  -- WLOG, there exists a maximal dynamical net `s`.
  rcases eq_top_or_lt_top (netMaxcard T F U n) with h | h
  · exact h ▸ le_top
  obtain ⟨s, s_net, s_card⟩ := (netMaxcard_finite_iff T F U n).1 h
  rw [← s_card]
  apply IsDynCoverOf.coverMincard_le_card
  --  We have to check that `s` is a cover for `dynEntourage T F (U ○ U) n`.
  -- If `s` is not a cover, then we can add to `s` a point `x` which is not covered
  -- and get a new net. This contradicts the maximality of `s`.
  rw [IsDynCoverOf, isCover_iff_subset_iUnion_ball]
  by_contra h
  obtain ⟨x, x_F, x_uncov⟩ := not_subset.1 h
  simp only [Finset.mem_coe, mem_iUnion, exists_prop, not_exists, not_and] at x_uncov
  have larger_net : IsDynNetIn T F U n (insert x s) := by
    refine ⟨insert_subset x_F s_net.1, pairwiseDisjoint_insert.2 ⟨s_net.2, ?_⟩⟩
    refine fun y y_s _ ↦ disjoint_left.2 fun z z_x z_y ↦ x_uncov y y_s ?_
    exact mem_ball_dynEntourage_comp T n x y (nonempty_of_mem ⟨z_x, z_y⟩)
  rw [← s.coe_insert x] at larger_net
  apply larger_net.card_le_netMaxcard.not_gt
  rw [← s_card, Nat.cast_lt]
  refine (lt_add_one s.card).trans_eq (s.card_insert_of_notMem fun x_s ↦ ?_).symm
  exact x_uncov x x_s (ball_mono (dynEntourage_monotone T n SetRel.left_subset_comp) x <|
    SetRel.rfl (dynEntourage T U n))

/-! ### Net entropy of entourages -/

open ENNReal EReal ExpGrowth Filter

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size of the
largest `(U, n)`-dynamical net of `F`. Takes values in the space of extended real numbers
`[-∞,+∞]`. This version uses a `limsup`, and is chosen as the default definition. -/
noncomputable def netEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthSup fun n : ℕ ↦ netMaxcard T F U n

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size of the
largest `(U, n)`-dynamical net of `F`. Takes values in the space of extended real numbers
`[-∞,+∞]`. This version uses a `liminf`, and is an alternative definition. -/
noncomputable def netEntropyInfEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthInf fun n : ℕ ↦ netMaxcard T F U n
```

-- snippet 19
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_antitone (L262-L265)
lemma netEntropyInfEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ netEntropyInfEntourage T F U :=
fun _ _ U_V ↦ expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (netMaxcard_antitone T F n U_V)
```

-- snippet 20
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_antitone (L266-L269)
lemma netEntropyEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ netEntropyEntourage T F U :=
fun _ _ U_V ↦ expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (netMaxcard_antitone T F n U_V)
```

-- snippet 21
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_le_netEntropyEntourage (L270-L273)
lemma netEntropyInfEntourage_le_netEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :
    netEntropyInfEntourage T F U ≤ netEntropyEntourage T F U :=
expGrowthInf_le_expGrowthSup
```

-- snippet 22
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_empty (L275-L279)
lemma netEntropyEntourage_empty : netEntropyEntourage T ∅ U = ⊥ := by
rw [netEntropyEntourage, ← expGrowthSup_zero]
  congr
  simp only [netMaxcard_empty, ENat.toENNReal_zero, Pi.zero_def]
```

-- snippet 23
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_empty (L281-L283)
lemma netEntropyInfEntourage_empty : netEntropyInfEntourage T ∅ U = ⊥ :=
eq_bot_mono (netEntropyInfEntourage_le_netEntropyEntourage T ∅ U) netEntropyEntourage_empty
```

-- snippet 24
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_nonneg (L284-L292)
lemma netEntropyInfEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ netEntropyInfEntourage T F U := by
apply Monotone.expGrowthInf_nonneg
  · exact fun _ _ m_n ↦ ENat.toENNReal_mono (netMaxcard_monotone_time T F U m_n)
  · rw [ne_eq, funext_iff.not, not_forall]
    use 0
    rw [netMaxcard_zero T h U, Pi.zero_apply, ENat.toENNReal_one]
    exact one_ne_zero
```

-- snippet 25
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_nonneg (L293-L296)
lemma netEntropyEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ netEntropyEntourage T F U :=
(netEntropyInfEntourage_nonneg T h U).trans (netEntropyInfEntourage_le_netEntropyEntourage T F U)
```

-- snippet 26
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_finite_of_isCompact_uniformContinuous (L290-L295)
lemma coverMincard_finite_of_isCompact_uniformContinuous [UniformSpace X] (F_comp : IsCompact F)
    (h : UniformContinuous T) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    coverMincard T F U n < ⊤ := by
obtain ⟨s, s_cover⟩ := exists_isDynCoverOf_of_isCompact_uniformContinuous F_comp h U_uni n
  exact s_cover.coverMincard_le_card.trans_lt (WithTop.coe_lt_top s.card)
```

-- snippet 27
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_nonneg (L371-L375)
lemma coverEntropyEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ coverEntropyEntourage T F U :=
(coverEntropyInfEntourage_nonneg T h U).trans
    (coverEntropyInfEntourage_le_coverEntropyEntourage T F U)
```

-- snippet 28
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.one_le_coverMincard_iff (L250-L254)
lemma one_le_coverMincard_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    1 ≤ coverMincard T F U n ↔ F.Nonempty := by
rw [ENat.one_le_iff_ne_zero, nonempty_iff_ne_empty, not_iff_not]
  exact coverMincard_eq_zero_iff T F U n
```

-- snippet 29
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_empty (L486-L488)
lemma coverEntropyInf_empty : coverEntropyInf T ∅ = ⊥ := by
simp only [coverEntropyInf, coverEntropyInfEntourage_empty, iSup_bot]
```

-- snippet 30
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.le_coverMincard_image (L93-L101)
lemma le_coverMincard_image (h : Semiconj φ S T) (F : Set X) [V.IsSymm] (n : ℕ) :
    coverMincard S F ((map φ φ) ⁻¹' (V ○ V)) n ≤ coverMincard T (φ '' F) V n := by
rcases eq_top_or_lt_top (coverMincard T (φ '' F) V n) with h' | h'
  · exact h' ▸ le_top
  obtain ⟨t, t_cover, t_card⟩ := (coverMincard_finite_iff T (φ '' F) V n).1 h'
  obtain ⟨s, s_cover, s_card⟩ := t_cover.preimage h
  rw [← t_card]
  exact s_cover.coverMincard_le_card.trans (WithTop.coe_le_coe.2 s_card)
```

-- snippet 31
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_mem_uniformity (L65-L77)
lemma dynEntourage_mem_uniformity [UniformSpace X] (h : UniformContinuous T)
    (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    dynEntourage T U n ∈ 𝓤 X := by
rw [dynEntourage_eq_inter_Ico T U n]
  induction n with
  | zero => simp
  | succ n ih =>
    simp only [iInter_coe_set, mem_Ico, Nat.zero_le, true_and] at ih ⊢
    rw [Set.biInter_lt_succ]
    apply Filter.inter_mem ih
    rw [map_iterate T T n]
    exact uniformContinuous_def.1 (UniformContinuous.iterate T n h) U U_uni
```

-- snippet 32
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_monotone_time (L213-L216)
lemma coverMincard_monotone_time (T : X → X) (F : Set X) (U : SetRel X X) :
    Monotone fun n : ℕ ↦ coverMincard T F U n :=
fun _ _ m_n ↦ biInf_mono fun _ h ↦ h.of_le m_n
```

-- snippet 33
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_restrict (L189-L193)
theorem coverEntropy_restrict [UniformSpace X] {T : X → X} {F : Set X} (h : MapsTo T F F) :
    coverEntropy (h.restrict T F F) univ = coverEntropy T F := by
rw [← coverEntropy_restrict_subset Subset.rfl h, coe_preimage_self F]

/-- The entropy of `φ '' F` is at most the entropy of `F` if `φ` is uniformly continuous. -/
```

-- snippet 34
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_antitone (L442-L447)
lemma coverEntropy_antitone (T : X → X) (F : Set X) :
    Antitone fun (u : UniformSpace X) ↦ @coverEntropy X u T F :=
fun _ _ h ↦ iSup₂_mono' fun U U_uni ↦ ⟨U, (le_def.1 h) U U_uni, le_refl _⟩

variable [UniformSpace X]
```

-- snippet 35
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_univ (L381-L385)
lemma coverEntropyInfEntourage_univ (T : X → X) (h : F.Nonempty) :
    coverEntropyInfEntourage T F univ = 0 := by
rw [← expGrowthInf_const one_ne_zero one_ne_top, coverEntropyInfEntourage]
  simp only [coverMincard_univ T h, ENat.toENNReal_one]
```

-- snippet 36
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_le_coverEntropyInfEntourage (L407-L411)
lemma coverEntropyEntourage_le_coverEntropyInfEntourage (F_inv : MapsTo T F F) [U.IsSymm] :
    coverEntropyEntourage T F (U ○ U) ≤ coverEntropyInfEntourage T F U := by
refine (le_liminf_of_le) (eventually_atTop.2 ⟨1, fun m m_pos ↦ ?_⟩)
  exact coverEntropyEntourage_le_log_coverMincard_div F_inv (Nat.one_le_iff_ne_zero.1 m_pos)
```

-- snippet 37
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_eq_iSup_basis (L458-L466)
lemma coverEntropy_eq_iSup_basis {ι : Sort*} {p : ι → Prop} {s : ι → SetRel X X}
    (h : (𝓤 X).HasBasis p s) (T : X → X) (F : Set X) :
    coverEntropy T F = ⨆ (i : ι) (_ : p i), coverEntropyEntourage T F (s i) := by
refine (iSup₂_le fun U U_uni ↦ ?_).antisymm
    (iSup₂_mono' fun i h_i ↦ ⟨s i, HasBasis.mem_of_mem h h_i, le_refl _⟩)
  obtain ⟨i, h_i, si_U⟩ := (HasBasis.mem_iff h).1 U_uni
  exact (coverEntropyEntourage_antitone T F si_U).trans
    (le_iSup₂ (f := fun (i : ι) (_ : p i) ↦ coverEntropyEntourage T F (s i)) i h_i)
```

-- snippet 38
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.IsDynCoverOf (L50-L53)
lemma IsDynCoverOf.monotone_subset (F_G : F ⊆ G) (h : IsDynCoverOf T G U n s) :
    IsDynCoverOf T F U n s :=
F_G.trans h
```

-- snippet 39
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.isDynCoverOf_zero (L94-L96)
lemma isDynCoverOf_zero (T : X → X) (F : Set X) (U : SetRel X X) (h : s.Nonempty) :
    IsDynCoverOf T F U 0 s := by simp [IsDynCoverOf, h]
```

-- snippet 40
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_ball_dynEntourage (L61-L64)
lemma mem_ball_dynEntourage :
    y ∈ ball x (dynEntourage T U n) ↔ ∀ k < n, T^[k] y ∈ ball (T^[k] x) U := by
simp only [ball, mem_preimage, mem_dynEntourage]
```

-- snippet 41
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverMincard_image_le (L102-L114)
lemma coverMincard_image_le (h : Semiconj φ S T) (F : Set X) (V : SetRel Y Y) (n : ℕ) :
    coverMincard T (φ '' F) V n ≤ coverMincard S F ((map φ φ) ⁻¹' V) n := by
classical
  rcases eq_top_or_lt_top (coverMincard S F ((map φ φ) ⁻¹' V) n) with h' | h'
  · exact h' ▸ le_top
  obtain ⟨s, s_cover, s_card⟩ := (coverMincard_finite_iff S F ((map φ φ) ⁻¹' V) n).1 h'
  rw [← s_card]
  have := s_cover.image h
  rw [← s.coe_image] at this
  exact this.coverMincard_le_card.trans (WithTop.coe_le_coe.2 s.card_image_le)

open ENNReal EReal ExpGrowth Filter
```

-- snippet 42
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_eq_zero_iff (L246-L249)
lemma coverMincard_eq_zero_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    coverMincard T F U n = 0 ↔ F = ∅ := by
simp [coverMincard, ENat.iInf_eq_zero]
```

-- snippet 43
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverEntropyInfEntourage_monotone (L65-L69)
lemma coverEntropyInfEntourage_monotone (T : X → X) (U : SetRel X X) :
    Monotone fun F : Set X ↦ coverEntropyInfEntourage T F U := by
refine fun F G F_G ↦ ExpGrowth.expGrowthInf_monotone fun n ↦ ?_
  exact ENat.toENNReal_mono (coverMincard_monotone_subset T U n F_G)
```

-- snippet 44
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_image_le_of_uniformContinuousOn_invariant (L208-L219)
lemma coverEntropy_image_le_of_uniformContinuousOn_invariant [UniformSpace X] [UniformSpace Y]
    {S : X → X} {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) {F G : Set X}
    (h' : UniformContinuousOn φ G) (hF : F ⊆ G) (hG : MapsTo S G G) :
    coverEntropy T (φ '' F) ≤ coverEntropy S F := by
rw [← coverEntropy_restrict_subset hF hG]
  have hφ : Semiconj (G.restrict φ) (hG.restrict S G G) T := by
    intro x
    rw [G.restrict_apply, G.restrict_apply, hG.val_restrict_apply, h.eq x]
  apply (coverEntropy_image_le_of_uniformContinuous hφ
    (uniformContinuousOn_iff_restrict.1 h') (val ⁻¹' F)).trans_eq'
  rw [← image_image_val_eq_restrict_image, image_preimage_coe G F, inter_eq_right.2 hF]
```

-- snippet 45
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.isDynCoverOf_univ (L97-L99)
lemma isDynCoverOf_univ (T : X → X) (F : Set X) (n : ℕ) (h : s.Nonempty) :
    IsDynCoverOf T F univ n s := by simp [IsDynCoverOf, h]
```

-- snippet 46
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.isSymm_dynEntourage (L91-L94)
instance isSymm_dynEntourage [U.IsSymm] : (dynEntourage T U n).IsSymm := by
simp [dynEntourage]; infer_instance

set_option linter.deprecated false in
```

-- snippet 47
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.IsDynNetIn (L54-L56)
lemma IsDynNetIn.monotone_subset (F_G : F ⊆ G) (h : IsDynNetIn T F U n s) : IsDynNetIn T G U n s :=
⟨h.1.trans F_G, h.2⟩
```

-- snippet 48
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_finite_of_isCompact_invariant (L412-L437)
lemma coverEntropyEntourage_finite_of_isCompact_invariant [UniformSpace X]
    (F_comp : IsCompact F) (F_inv : MapsTo T F F) (U_uni : U ∈ 𝓤 X) :
    coverEntropyEntourage T F U < ⊤ := by
obtain ⟨V, V_uni, V_symm, V_U⟩ := comp_symm_mem_uniformity_sets U_uni
  obtain ⟨s, s_cover⟩ := exists_isDynCoverOf_of_isCompact_invariant F_comp F_inv V_uni 1
  apply (coverEntropyEntourage_antitone T F V_U).trans_lt
  apply (s_cover.coverEntropyEntourage_le_log_card_div F_inv one_ne_zero).trans_lt
  rw [Nat.cast_one, div_one, log_lt_top_iff, ← ENat.toENNReal_top]
  exact_mod_cast (ENat.coe_ne_top (Finset.card s)).lt_top

/-! ### Cover entropy -/

/-- The entropy of `T` restricted to `F`, obtained by taking the supremum
  of `coverEntropyEntourage` over entourages. Note that this supremum is approached by taking small
  entourages. This first version uses a `limsup`, and is chosen as the default definition
  for topological entropy. -/
noncomputable def coverEntropy [UniformSpace X] (T : X → X) (F : Set X) :=
  ⨆ U ∈ 𝓤 X, coverEntropyEntourage T F U

/-- The entropy of `T` restricted to `F`, obtained by taking the supremum
  of `coverEntropyInfEntourage` over entourages. Note that this supremum is approached by taking
  small entourages. This second version uses a `liminf`, and is chosen as an alternative
  definition for topological entropy. -/
noncomputable def coverEntropyInf [UniformSpace X] (T : X → X) (F : Set X) :=
  ⨆ U ∈ 𝓤 X, coverEntropyInfEntourage T F U
```

-- snippet 49
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_eq_coverEntropy (L496-L503)
lemma coverEntropyInf_eq_coverEntropy (T : X → X) (h : MapsTo T F F) :
    coverEntropyInf T F = coverEntropy T F := by
refine le_antisymm (coverEntropyInf_le_coverEntropy T F) (iSup₂_le fun U U_uni ↦ ?_)
  obtain ⟨V, V_uni, V_symm, V_U⟩ := comp_symm_mem_uniformity_sets U_uni
  exact (coverEntropyEntourage_antitone T F V_U).trans <| le_iSup₂_of_le V V_uni <|
     coverEntropyEntourage_le_coverEntropyInfEntourage h

end Dynamics
```

-- snippet 50
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_restrict_subset (L175-L180)
lemma coverEntropy_restrict_subset [UniformSpace X] {T : X → X} {F G : Set X} (hF : F ⊆ G)
    (hG : MapsTo T G G) :
    coverEntropy (hG.restrict T G G) (val ⁻¹' F) = coverEntropy T F := by
rw [← coverEntropy_image_of_comap _ hG.val_restrict_apply (val ⁻¹' F), image_preimage_coe G F,
    inter_eq_right.2 hF]
```

-- snippet 51
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_le_coverEntropy (L476-L480)
lemma coverEntropyInf_le_coverEntropy (T : X → X) (F : Set X) :
    coverEntropyInf T F ≤ coverEntropy T F :=
iSup₂_mono fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦
    coverEntropyInfEntourage_le_coverEntropyEntourage T F U
```

-- snippet 52
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_le_pow (L285-L289)
lemma coverMincard_le_pow (F_inv : MapsTo T F F) [U.IsSymm] (m_pos : 0 < m) (n : ℕ) :
    coverMincard T F (U ○ U) n ≤ coverMincard T F U m ^ (n / m + 1) :=
(coverMincard_monotone_time T F (U ○ U) (Nat.lt_mul_div_succ n m_pos).le).trans
    (coverMincard_mul_le_pow F_inv m (n / m + 1))
```

-- snippet 53
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.isRefl_dynEntourage (L87-L90)
instance isRefl_dynEntourage [U.IsRefl] : (dynEntourage T U n).IsRefl := by
simp [dynEntourage]; infer_instance

set_option linter.flexible false in -- simp followed by infer_instance
```

-- snippet 54
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverMincard_monotone_subset (L57-L60)
lemma coverMincard_monotone_subset (T : X → X) (U : SetRel X X) (n : ℕ) :
    Monotone fun F : Set X ↦ coverMincard T F U n :=
fun _ _ F_G ↦ biInf_mono fun _ h ↦ h.monotone_subset F_G
```

-- snippet 55
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_empty (L354-L357)
lemma coverEntropyEntourage_empty : coverEntropyEntourage T ∅ U = ⊥ := by
simp only [coverEntropyEntourage, coverMincard_empty]
  rw [ENat.toENNReal_zero, ← Pi.zero_def, expGrowthSup_zero]
```

-- snippet 56
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_antitone (L438-L441)
lemma coverEntropyInf_antitone (T : X → X) (F : Set X) :
    Antitone fun (u : UniformSpace X) ↦ @coverEntropyInf X u T F :=
fun _ _ h ↦ iSup₂_mono' fun U U_uni ↦ ⟨U, (le_def.1 h) U U_uni, le_refl _⟩
```

-- snippet 57
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.IsDynCoverOf (L78-L80)
def IsDynCoverOf (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) (s : Set X) : Prop :=
IsCover (dynEntourage T U n) F s
```

-- snippet 58
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_eq_iSup_basis (L467-L475)
lemma coverEntropyInf_eq_iSup_basis {ι : Sort*} {p : ι → Prop} {s : ι → SetRel X X}
    (h : (𝓤 X).HasBasis p s) (T : X → X) (F : Set X) :
    coverEntropyInf T F = ⨆ (i : ι) (_ : p i), coverEntropyInfEntourage T F (s i) := by
refine (iSup₂_le fun U U_uni ↦ ?_).antisymm
    (iSup₂_mono' fun i h_i ↦ ⟨s i, HasBasis.mem_of_mem h h_i, le_refl _⟩)
  obtain ⟨i, h_i, si_U⟩ := (HasBasis.mem_iff h).1 U_uni
  exact (coverEntropyInfEntourage_antitone T F si_U).trans
    (le_iSup₂ (f := fun (i : ι) (_ : p i) ↦ coverEntropyInfEntourage T F (s i)) i h_i)
```

-- snippet 59
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverEntropyEntourage_monotone (L70-L74)
lemma coverEntropyEntourage_monotone (T : X → X) (U : SetRel X X) :
    Monotone fun F : Set X ↦ coverEntropyEntourage T F U := by
refine fun F G F_G ↦ ExpGrowth.expGrowthSup_monotone fun n ↦ ?_
  exact ENat.toENNReal_mono (coverMincard_monotone_subset T U n F_G)
```

-- snippet 60
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.nonempty_inter_of_coverMincard (L305-L340)
lemma nonempty_inter_of_coverMincard [U.IsSymm] {s : Finset X} (h : IsDynCoverOf T F U n s)
    (h' : #s = coverMincard T F U n) :
    ∀ x ∈ s, (F ∩ ball x (dynEntourage T U n)).Nonempty := by
-- Otherwise, there is a ball which does not intersect `F`. Removing it yields a smaller cover.
  classical
  by_contra! ⟨x, x_s, ball_empt⟩
  have smaller_cover : IsDynCoverOf T F U n (s.erase x) := by
    intro y y_F
    specialize h y_F
    simp only [s.mem_coe] at h
    simp only [s.coe_erase, mem_diff, s.mem_coe, mem_singleton_iff]
    obtain ⟨z, z_s, hz⟩ := h
    refine ⟨z, ⟨z_s, fun z_x ↦ notMem_empty y ?_⟩, hz⟩
    rw [← ball_empt]
    rw [z_x] at hz
    exact mem_inter y_F <| (dynEntourage T U n).symm hz
  apply smaller_cover.coverMincard_le_card.not_gt
  rw [← h']
  exact_mod_cast s.card_erase_lt_of_mem x_s

/-! ### Cover entropy of entourages -/

open ENNReal EReal ExpGrowth Filter

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size
  of the smallest `(U, n)`-refined cover of `F`. Takes values in the space of extended real numbers
  `[-∞, +∞]`. This first version uses a `limsup`, and is chosen as the default definition. -/
noncomputable def coverEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthSup fun n : ℕ ↦ coverMincard T F U n

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size
  of the smallest `(U, n)`-refined cover of `F`. Takes values in the space of extended real numbers
  `[-∞, +∞]`. This second version uses a `liminf`, and is chosen as an alternative definition. -/
noncomputable def coverEntropyInfEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthInf fun n : ℕ ↦ coverMincard T F U n
```

-- snippet 61
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_antitone (L130-L133)
lemma dynEntourage_antitone (T : X → X) (U : SetRel X X) :
    Antitone (fun n : ℕ ↦ dynEntourage T U n) :=
fun m n m_n ↦ iInter₂_mono' fun k k_m ↦ by use k, lt_of_lt_of_le k_m m_n
```

-- snippet 62
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_image_of_comap (L154-L174)
theorem coverEntropyInf_image_of_comap (u : UniformSpace Y) {S : X → X} {T : Y → Y} {φ : X → Y}
    (h : Semiconj φ S T) (F : Set X) :
    coverEntropyInf T (φ '' F) = @coverEntropyInf X (comap φ u) S F := by
let : UniformSpace X := comap φ u
  apply le_antisymm
  · refine iSup₂_le fun V V_uni ↦
      (coverEntropyInfEntourage_antitone _ _ SetRel.symmetrize_subset_self).trans <|
      (coverEntropyInfEntourage_image_le h F _).trans ?_
    apply coverEntropyInfEntourage_le_coverEntropyInf
    rw [uniformity_comap φ, mem_comap]
    exact ⟨_, symmetrize_mem_uniformity V_uni, .rfl⟩
  · refine iSup₂_le fun U U_uni ↦ ?_
    simp only [uniformity_comap φ, mem_comap] at U_uni
    obtain ⟨V, V_uni, V_sub⟩ := U_uni
    obtain ⟨W, W_uni, W_symm, W_V⟩ := comp_symm_mem_uniformity_sets V_uni
    apply (coverEntropyInfEntourage_antitone S F ((preimage_mono W_V).trans V_sub)).trans
    apply (le_coverEntropyInfEntourage_image h F).trans
    exact coverEntropyInfEntourage_le_coverEntropyInf T (φ '' F) W_uni

open Subtype
```

-- snippet 63
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_eq_inter_Ico (L54-L57)
lemma dynEntourage_eq_inter_Ico (T : X → X) (U : SetRel X X) (n : ℕ) :
    dynEntourage T U n = ⋂ k : Ico 0 n, (map T T)^[k] ⁻¹' U := by
simp [dynEntourage]
```

-- snippet 64
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInfEntourage_image_le (L127-L132)
lemma coverEntropyInfEntourage_image_le (h : Semiconj φ S T) (F : Set X) (V : SetRel Y Y) :
    coverEntropyInfEntourage T (φ '' F) V ≤ coverEntropyInfEntourage S F ((map φ φ) ⁻¹' V) :=
expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_image_le h F V n)

/-- The entropy of `φ '' F` equals the entropy of `F` if `X` is endowed with the pullback by `φ`
  of the uniform structure of `Y`. -/
```

-- snippet 65
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_image_le_of_uniformContinuous (L202-L207)
theorem coverEntropyInf_image_le_of_uniformContinuous [UniformSpace X] [UniformSpace Y] {S : X → X}
    {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) (h' : UniformContinuous φ) (F : Set X) :
    coverEntropyInf T (φ '' F) ≤ coverEntropyInf S F := by
rw [coverEntropyInf_image_of_comap _ h F]
  exact coverEntropyInf_antitone S F (uniformContinuous_iff.1 h')
```

-- snippet 66
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.netMaxcard_monotone_subset (L61-L64)
lemma netMaxcard_monotone_subset (T : X → X) (U : SetRel X X) (n : ℕ) :
    Monotone fun F : Set X ↦ netMaxcard T F U n :=
fun _ _ F_G ↦ biSup_mono fun _ h ↦ h.monotone_subset F_G
```

-- snippet 67
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_empty (L243-L245)
lemma coverMincard_empty : coverMincard T ∅ U n = 0 :=
(sInf_le (by simp [IsDynCoverOf])).antisymm (zero_le (coverMincard T ∅ U n))
```

-- snippet 68
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_antitone (L345-L348)
lemma coverEntropyEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ coverEntropyEntourage T F U :=
fun _ _ U_V ↦ expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_antitone T F n U_V)
```

-- snippet 69
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_le_coverEntropy (L448-L452)
lemma coverEntropyEntourage_le_coverEntropy (T : X → X) (F : Set X)
    (h : U ∈ 𝓤 X) :
    coverEntropyEntourage T F U ≤ coverEntropy T F :=
le_iSup₂ (f := fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦ coverEntropyEntourage T F U) U h
```

-- snippet 70
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.netEntropyInfEntourage_monotone (L75-L79)
lemma netEntropyInfEntourage_monotone (T : X → X) (U : SetRel X X) :
    Monotone fun F : Set X ↦ netEntropyInfEntourage T F U := by
refine fun F G F_G ↦ ExpGrowth.expGrowthInf_monotone fun n ↦ ?_
  exact ENat.toENNReal_mono (netMaxcard_monotone_subset T U n F_G)
```

-- snippet 71
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.exists_isDynCoverOf_of_isCompact_invariant (L191-L208)
lemma exists_isDynCoverOf_of_isCompact_invariant [UniformSpace X]
    (F_comp : IsCompact F) (F_inv : MapsTo T F F) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    ∃ s : Finset X, IsDynCoverOf T F U n s := by
obtain ⟨(V : SetRel X X), V_uni, V_symm, V_U⟩ := comp_symm_mem_uniformity_sets U_uni
  obtain ⟨s, _, s_cover⟩ := F_comp.elim_nhds_subcover (ball · V)
    fun (x : X) _ ↦ ball_mem_nhds x V_uni
  have : IsDynCoverOf T F V 1 s := .of_subset_iUnion_ball <| by simpa using s_cover
  obtain ⟨t, t_dyncover, t_card⟩ := this.iterate_le_pow F_inv n
  rw [one_mul n] at t_dyncover
  exact ⟨t, t_dyncover.of_entourage_subset V_U⟩

/-! ### Minimal cardinality of dynamical covers -/

/-- The smallest cardinality of a `(U, n)`-dynamical cover of `F`. Takes values in `ℕ∞`, and is
  infinite if and only if `F` admits no finite dynamical cover. -/
noncomputable def coverMincard (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) : ℕ∞ :=
  ⨅ (s : Finset X) (_ : IsDynCoverOf T F U n s), (s.card : ℕ∞)
```

-- snippet 72
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_le_log_coverMincard_div (L386-L399)
lemma coverEntropyEntourage_le_log_coverMincard_div (F_inv : MapsTo T F F) [U.IsSymm]
    (n_pos : n ≠ 0) :
    coverEntropyEntourage T F (U ○ U) ≤ log (coverMincard T F U n) / n := by
have cv_mono : Monotone fun m ↦ (coverMincard T F (U ○ U) m).toENNReal :=
    fun _ _ k_m ↦ ENat.toENNReal_mono (coverMincard_monotone_time T F (U ○ U) k_m)
  have h := cv_mono.expGrowthSup_comp_mul n_pos
  rw [mul_comm, ← div_eq_iff (natCast_ne_bot n) (natCast_ne_top n) (Nat.cast_ne_zero.2 n_pos)] at h
  rw [coverEntropyEntourage, ← h]
  apply monotone_div_right_of_nonneg n.cast_nonneg'
  rw [← expGrowthSup_pow]
  refine expGrowthSup_monotone fun m ↦ ?_
  rw [← ENat.toENNReal_pow]
  exact ENat.toENNReal_mono (coverMincard_mul_le_pow F_inv n m)
```

-- snippet 73
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_image_le_of_uniformContinuousOn_invariant (L220-L232)
lemma coverEntropyInf_image_le_of_uniformContinuousOn_invariant [UniformSpace X] [UniformSpace Y]
    {S : X → X} {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) {F G : Set X}
    (h' : UniformContinuousOn φ G) (hF : F ⊆ G) (hG : MapsTo S G G) :
    coverEntropyInf T (φ '' F) ≤ coverEntropyInf S F := by
rw [← coverEntropyInf_restrict_subset hF hG]
  have hφ : Semiconj (G.restrict φ) (hG.restrict S G G) T := by
    intro a
    rw [G.restrict_apply, G.restrict_apply, hG.val_restrict_apply, h.eq a]
  apply (coverEntropyInf_image_le_of_uniformContinuous hφ
    (uniformContinuousOn_iff_restrict.1 h') (val ⁻¹' F)).trans_eq'
  rw [← image_image_val_eq_restrict_image, image_preimage_coe G F, inter_eq_right.2 hF]

end Dynamics
```

-- snippet 74
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_nonneg (L493-L495)
lemma coverEntropy_nonneg (T : X → X) (h : F.Nonempty) : 0 ≤ coverEntropy T F :=
(coverEntropyInf_nonneg T h).trans (coverEntropyInf_le_coverEntropy T F)
```

-- snippet 75
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_antitone (L217-L221)
lemma coverMincard_antitone (T : X → X) (F : Set X) (n : ℕ) :
    Antitone fun U : SetRel X X ↦ coverMincard T F U n :=
fun _ _ U_V ↦ biInf_mono fun _ h ↦ h.of_entourage_subset U_V

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 76
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_mul_le_pow (L272-L284)
lemma coverMincard_mul_le_pow (F_inv : MapsTo T F F) [U.IsSymm] (m n : ℕ) :
    coverMincard T F (U ○ U) (m * n) ≤ coverMincard T F U m ^ n := by
rcases F.eq_empty_or_nonempty with rfl | F_nonempty
  · rw [coverMincard_empty]; exact zero_le _
  obtain rfl | hn := eq_or_ne n 0
  · rw [mul_zero, coverMincard_zero T F_nonempty (U ○ U), pow_zero]
  rcases eq_top_or_lt_top (coverMincard T F U m) with h | h
  · simp [*]
  · obtain ⟨s, s_cover, s_coverMincard⟩ := (coverMincard_finite_iff T F U m).1 h
    obtain ⟨t, t_cover, t_sn⟩ := s_cover.iterate_le_pow F_inv n
    rw [← s_coverMincard]
    exact t_cover.coverMincard_le_card.trans (WithTop.coe_le_coe.2 t_sn)
```

-- snippet 77
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.le_coverEntropyInfEntourage_image (L119-L122)
lemma le_coverEntropyInfEntourage_image (h : Semiconj φ S T) (F : Set X) [V.IsSymm] :
    coverEntropyInfEntourage S F ((map φ φ) ⁻¹' (V ○ V)) ≤ coverEntropyInfEntourage T (φ '' F) V :=
expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (le_coverMincard_image h F n)
```

-- snippet 78
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.le_coverEntropyEntourage_image (L115-L118)
lemma le_coverEntropyEntourage_image (h : Semiconj φ S T) (F : Set X) [V.IsSymm] :
    coverEntropyEntourage S F ((map φ φ) ⁻¹' (V ○ V)) ≤ coverEntropyEntourage T (φ '' F) V :=
expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (le_coverMincard_image h F n)
```

-- snippet 79
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_le_coverEntropyInf (L453-L457)
lemma coverEntropyInfEntourage_le_coverEntropyInf (T : X → X) (F : Set X)
    (h : U ∈ 𝓤 X) :
    coverEntropyInfEntourage T F U ≤ coverEntropyInf T F :=
le_iSup₂ (f := fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦ coverEntropyInfEntourage T F U) U h
```

-- snippet 80
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_finite_iff (L222-L241)
lemma coverMincard_finite_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    coverMincard T F U n < ⊤ ↔
    ∃ s : Finset X, IsDynCoverOf T F U n s ∧ s.card = coverMincard T F U n := by
refine ⟨fun h_fin ↦ ?_, fun ⟨s, _, s_coverMincard⟩ ↦ s_coverMincard ▸ WithTop.coe_lt_top s.card⟩
  obtain ⟨k, k_min⟩ := WithTop.ne_top_iff_exists.1 h_fin.ne
  rw [← k_min]
  simp only [ENat.some_eq_coe, Nat.cast_inj]
  have : Nonempty {s : Finset X // IsDynCoverOf T F U n s} := by
    by_contra h
    apply ENat.coe_ne_top k
    rw [← ENat.some_eq_coe, k_min, coverMincard, iInf₂_eq_top]
    simp only [ENat.coe_ne_top, imp_false]
    rw [nonempty_subtype, not_exists] at h
    exact h
  have key := ciInf_mem fun s : {s : Finset X // IsDynCoverOf T F U n s} ↦ (s.val.card : ℕ∞)
  rw [coverMincard, iInf_subtype'] at k_min
  rw [← k_min, mem_range, Subtype.exists] at key
  simp only [ENat.some_eq_coe, Nat.cast_inj, exists_prop] at key
  exact key
```

-- snippet 81
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_zero (L255-L263)
lemma coverMincard_zero (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    coverMincard T F U 0 = 1 := by
apply le_antisymm _ ((one_le_coverMincard_iff T F U 0).2 h)
  obtain ⟨x, _⟩ := h
  have := isDynCoverOf_zero T F U (singleton_nonempty x)
  rw [← Finset.coe_singleton] at this
  apply this.coverMincard_le_card.trans_eq
  rw [Finset.card_singleton, Nat.cast_one]
```

-- snippet 82
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage (L51-L53)
def dynEntourage (T : X → X) (U : SetRel X X) (n : ℕ) : SetRel X X :=
⋂ k < n, (map T T)^[k] ⁻¹' U
```

-- snippet 83
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyEntourage_image_le (L123-L126)
lemma coverEntropyEntourage_image_le (h : Semiconj φ S T) (F : Set X) (V : SetRel Y Y) :
    coverEntropyEntourage T (φ '' F) V ≤ coverEntropyEntourage S F ((map φ φ) ⁻¹' V) :=
expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_image_le h F V n)
```

-- snippet 84
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_monotone (L126-L129)
lemma dynEntourage_monotone (T : X → X) (n : ℕ) :
    Monotone (fun U : SetRel X X ↦ dynEntourage T U n) :=
fun _ _ h ↦ iInter₂_mono fun _ _ ↦ preimage_mono h
```

-- snippet 85
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_finite_of_isCompact_invariant (L296-L304)
lemma coverMincard_finite_of_isCompact_invariant [UniformSpace X] (F_comp : IsCompact F)
    (F_inv : MapsTo T F F) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    coverMincard T F U n < ⊤ := by
obtain ⟨s, s_cover⟩ := exists_isDynCoverOf_of_isCompact_invariant F_comp F_inv U_uni n
  exact s_cover.coverMincard_le_card.trans_lt (WithTop.coe_lt_top s.card)

/-- All dynamical balls of a minimal dynamical cover of `F` intersect `F`. This lemma is the key
  to relate Bowen-Dinaburg's definition of topological entropy with covers and their definition
  of topological entropy with nets. -/
```

-- snippet 86
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_nonneg (L489-L492)
lemma coverEntropyInf_nonneg (T : X → X) (h : F.Nonempty) : 0 ≤ coverEntropyInf T F :=
(coverEntropyInfEntourage_le_coverEntropyInf T F univ_mem).trans_eq'
    (coverEntropyInfEntourage_univ T h)
```

-- snippet 87
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_antitone (L341-L344)
lemma coverEntropyInfEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ coverEntropyInfEntourage T F U :=
fun _ _ U_V ↦ expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_antitone T F n U_V)
```

-- snippet 88
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.ball_dynEntourage_mem_nhds (L78-L86)
lemma ball_dynEntourage_mem_nhds [UniformSpace X] (h : Continuous T)
    (U_uni : U ∈ 𝓤 X) (n : ℕ) (x : X) :
    ball x (dynEntourage T U n) ∈ 𝓝 x := by
rw [dynEntourage_eq_inter_Ico T U n, ball_iInter, Filter.iInter_mem, Subtype.forall]
  intro k _
  simp only [map_iterate, _root_.ball_preimage]
  exact (h.iterate k).continuousAt.preimage_mem_nhds (ball_mem_nhds (T^[k] x) U_uni)

set_option linter.flexible false in -- simp followed by infer_instance
```

-- snippet 89
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_univ (L142-L144)
lemma dynEntourage_univ {T : X → X} {n : ℕ} :
    dynEntourage T univ n = univ := by simp [dynEntourage]
```

-- snippet 90
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.exists_isDynCoverOf_of_isCompact_uniformContinuous (L182-L190)
lemma exists_isDynCoverOf_of_isCompact_uniformContinuous [UniformSpace X]
    (F_comp : IsCompact F) (h : UniformContinuous T) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    ∃ s : Finset X, IsDynCoverOf T F U n s := by
obtain ⟨(V : SetRel X X), hV, hVsymm, hVU⟩ := symm_of_uniformity U_uni
  have uni_ite := dynEntourage_mem_uniformity h hV n
  let openCover x := ball x (dynEntourage T V n)
  obtain ⟨s, _, s_cover⟩ := F_comp.elim_nhds_subcover openCover fun x _ ↦ ball_mem_nhds x uni_ite
  exact ⟨s, .of_entourage_subset hVU <| .of_subset_iUnion_ball s_cover⟩
```

-- snippet 91
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_ball_dynEntourage_comp (L145-L151)
lemma mem_ball_dynEntourage_comp (T : X → X) (n : ℕ) {U : SetRel X X} [U.IsSymm]
    (x y : X) (h : (ball x (dynEntourage T U n) ∩ ball y (dynEntourage T U n)).Nonempty) :
    x ∈ ball y (dynEntourage T (U ○ U) n) := by
rcases h with ⟨z, z_Bx, z_By⟩
  rw [mem_ball_symmetry] at z_Bx
  exact dynEntourage_comp_subset T U U n (mem_ball_comp z_By z_Bx)
```

-- snippet 92
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_restrict_subset (L181-L187)
lemma coverEntropyInf_restrict_subset [UniformSpace X] {T : X → X} {F G : Set X} (hF : F ⊆ G)
    (hG : MapsTo T G G) :
    coverEntropyInf (hG.restrict T G G) (val ⁻¹' F) = coverEntropyInf T F := by
rw [← coverEntropyInf_image_of_comap _ hG.val_restrict_apply (val ⁻¹' F), image_preimage_coe G F,
    inter_eq_right.2 hF]

/-- The entropy of the restriction of `T` to an invariant set `F` is `coverEntropy T F`. This
```

-- snippet 93
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_empty (L359-L361)
lemma coverEntropyInfEntourage_empty : coverEntropyInfEntourage T ∅ U = ⊥ :=
eq_bot_mono (coverEntropyInfEntourage_le_coverEntropyEntourage T ∅ U) coverEntropyEntourage_empty
```

-- snippet 94
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_mono (L135-L137)
lemma dynEntourage_mono (hUV : U ⊆ V) (hmn : m ≤ n) : dynEntourage T U n ⊆ dynEntourage T V m :=
(dynEntourage_monotone _ _ hUV).trans (dynEntourage_antitone _ _ hmn)
```

-- snippet 95
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_image_of_comap (L133-L153)
theorem coverEntropy_image_of_comap (u : UniformSpace Y) {S : X → X} {T : Y → Y} {φ : X → Y}
    (h : Semiconj φ S T) (F : Set X) :
    coverEntropy T (φ '' F) = @coverEntropy X (comap φ u) S F := by
let : UniformSpace X := comap φ u
  apply le_antisymm
  · refine iSup₂_le fun V V_uni ↦
      (coverEntropyEntourage_antitone _ _ SetRel.symmetrize_subset_self).trans <|
      (coverEntropyEntourage_image_le h F _).trans ?_
    apply coverEntropyEntourage_le_coverEntropy
    rw [uniformity_comap φ, mem_comap]
    exact ⟨_, symmetrize_mem_uniformity V_uni, .rfl⟩
  · refine iSup₂_le fun U U_uni ↦ ?_
    simp only [uniformity_comap φ, mem_comap] at U_uni
    obtain ⟨V, V_uni, V_sub⟩ := U_uni
    obtain ⟨W, W_uni, W_symm, W_V⟩ := comp_symm_mem_uniformity_sets V_uni
    apply (coverEntropyEntourage_antitone S F ((preimage_mono W_V).trans V_sub)).trans
    apply (le_coverEntropyEntourage_image h F).trans
    exact coverEntropyEntourage_le_coverEntropy T (φ '' F) W_uni

/-- The entropy of `φ '' F` equals the entropy of `F` if `X` is endowed with the pullback by `φ`
  of the uniform structure of `Y`. This version uses a `liminf`. -/
```

-- snippet 96
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_dynEntourage (L58-L60)
lemma mem_dynEntourage : (x, y) ∈ dynEntourage T U n ↔ ∀ k < n, (T^[k] x, T^[k] y) ∈ U := by
simp [dynEntourage]
```

-- snippet 97
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.IsDynCoverOf (L65-L71)
lemma IsDynCoverOf.image (h : Semiconj φ S T) (h' : IsDynCoverOf S F (map φ φ ⁻¹' V) n s) :
    IsDynCoverOf T (φ '' F) V n (φ '' s) := by
rintro _ ⟨x, hx, rfl⟩
  obtain ⟨y, hy, hxy⟩ := h' hx
  refine ⟨_, Set.mem_image_of_mem _ hy, show (x, y) ∈ map φ φ ⁻¹' dynEntourage T V n from ?_⟩
  rwa [h.preimage_dynEntourage V n]
```

-- snippet 98
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_le_coverEntropyEntourage (L349-L352)
lemma coverEntropyInfEntourage_le_coverEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :
    coverEntropyInfEntourage T F U ≤ coverEntropyEntourage T F U :=
expGrowthInf_le_expGrowthSup
```

-- snippet 99
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_univ (L264-L271)
lemma coverMincard_univ (T : X → X) (h : F.Nonempty) (n : ℕ) : coverMincard T F univ n = 1 := by
apply le_antisymm _ ((one_le_coverMincard_iff T F univ n).2 h)
  obtain ⟨x, _⟩ := h
  have := isDynCoverOf_univ T F n (singleton_nonempty x)
  rw [← Finset.coe_singleton] at this
  apply this.coverMincard_le_card.trans_eq
  rw [Finset.card_singleton, Nat.cast_one]
```

-- snippet 100
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_univ (L376-L380)
lemma coverEntropyEntourage_univ (T : X → X) (h : F.Nonempty) :
    coverEntropyEntourage T F univ = 0 := by
rw [← expGrowthSup_const one_ne_zero one_ne_top, coverEntropyEntourage]
  simp only [coverMincard_univ T h, ENat.toENNReal_one]
```

-- snippet 101
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_nonneg (L362-L370)
lemma coverEntropyInfEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ coverEntropyInfEntourage T F U := by
apply Monotone.expGrowthInf_nonneg
  · exact fun _ _ m_n ↦ ENat.toENNReal_mono (coverMincard_monotone_time T F U m_n)
  · rw [ne_eq, funext_iff.not, not_forall]
    use 0
    rw [coverMincard_zero T h U, Pi.zero_apply, ENat.toENNReal_one]
    exact one_ne_zero
```

-- snippet 102
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_comp_subset (L111-L118)
lemma dynEntourage_comp_subset (T : X → X) (U V : SetRel X X) (n : ℕ) :
    (dynEntourage T U n) ○ (dynEntourage T V n) ⊆ dynEntourage T (U ○ V) n := by
simp only [dynEntourage, map_iterate, subset_iInter_iff]
  intro k k_n xy xy_comp
  simp only [SetRel.comp, mem_iInter, mem_preimage, map_apply, mem_setOf_eq] at xy_comp ⊢
  rcases xy_comp with ⟨z, hz1, hz2⟩
  exact mem_ball_comp (hz1 k k_n) (hz2 k k_n)
```

-- snippet 103
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_image_le_of_uniformContinuous (L194-L201)
theorem coverEntropy_image_le_of_uniformContinuous [UniformSpace X] [UniformSpace Y] {S : X → X}
    {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) (h' : UniformContinuous φ) (F : Set X) :
    coverEntropy T (φ '' F) ≤ coverEntropy S F := by
rw [coverEntropy_image_of_comap _ h F]
  exact coverEntropy_antitone S F (uniformContinuous_iff.1 h')

/-- The entropy of `φ '' F` is at most the entropy of `F` if `φ` is uniformly continuous. This
  version uses a `liminf`. -/
```

-- snippet 104
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.idRel_subset_dynEntourage (L96-L101)
lemma idRel_subset_dynEntourage (T : X → X) {U : Set (X × X)} (h : idRel ⊆ U) (n : ℕ) :
    idRel ⊆ (dynEntourage T U n) := by
simp only [dynEntourage, map_iterate, subset_iInter_iff, idRel_subset, mem_preimage, map_apply]
  exact fun _ _ _ ↦ h rfl

set_option linter.deprecated false in
```

-- snippet 105
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_empty (L482-L484)
lemma coverEntropy_empty : coverEntropy T ∅ = ⊥ := by
simp only [coverEntropy, coverEntropyEntourage_empty, iSup_bot]
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Dynamics.TopologicalEntropy.NetEntropy).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
lemma netEntropyInfEntourage_univ (T : X → X) {F : Set X} (h : F.Nonempty) :
    netEntropyInfEntourage T F univ = 0
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L67-L69)
def IsDynNetIn (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) (s : Set X) : Prop :=
s ⊆ F ∧ s.PairwiseDisjoint fun x : X ↦ ball x (dynEntourage T U n)
```

-- snippet 2
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L70-L72)
lemma IsDynNetIn.of_le (m_n : m ≤ n) (h : IsDynNetIn T F U m s) : IsDynNetIn T F U n s :=
⟨h.1, PairwiseDisjoint.mono h.2 fun x ↦ ball_mono (dynEntourage_antitone T U m_n) x⟩
```

-- snippet 3
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L73-L76)
lemma IsDynNetIn.of_entourage_subset (U_V : U ⊆ V) (h : IsDynNetIn T F V n s) :
    IsDynNetIn T F U n s :=
⟨h.1, PairwiseDisjoint.mono h.2 fun x ↦ ball_mono (dynEntourage_monotone T n U_V) x⟩
```

-- snippet 4
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.isDynNetIn_empty (L77-L78)
lemma isDynNetIn_empty : IsDynNetIn T F U n ∅ := ⟨empty_subset F, pairwise_empty _⟩
```

-- snippet 5
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.isDynNetIn_singleton (L79-L85)
lemma isDynNetIn_singleton (T : X → X) (U : SetRel X X) (n : ℕ) (h : x ∈ F) :
    IsDynNetIn T F U n {x} :=
⟨singleton_subset_iff.2 h, pairwise_singleton x _⟩

/-- Given an entourage `U` and a time `n`, a dynamical net has a smaller cardinality than
  a dynamical cover. This lemma is the first of two key results to compare two versions of
  topological entropy: with cover and with nets, the second being `coverMincard_le_netMaxcard`. -/
```

-- snippet 6
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L86-L102)
lemma IsDynNetIn.card_le_card_of_isDynCoverOf {s t : Finset X}
    (hs : IsDynNetIn T F U n s) (ht : IsDynCoverOf T F U n t) :
    s.card ≤ t.card := by
have (x : X) (x_s : x ∈ s) : ∃ z ∈ t, z ∈ ball x (dynEntourage T U n) := by
    simpa using ht (hs.1 x_s)
  choose! F s_t using this
  apply Finset.card_le_card_of_injOn F fun x x_s ↦ (s_t x x_s).1
  exact fun x x_s y y_s Fx_Fy ↦
    PairwiseDisjoint.elim_set hs.2 x_s y_s (F x) (s_t x x_s).2 (Fx_Fy ▸ (s_t y y_s).2)

/-! ### Maximal cardinality of dynamical nets -/

/-- The largest cardinality of a `(U, n)`-dynamical net of `F`. Takes values in `ℕ∞`, and is
infinite if and only if `F` admits nets of arbitrarily large size. -/
noncomputable def netMaxcard (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) : ℕ∞ :=
  ⨆ (s : Finset X) (_ : IsDynNetIn T F U n s), (s.card : ℕ∞)
```

-- snippet 7
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.IsDynNetIn (L103-L106)
lemma IsDynNetIn.card_le_netMaxcard {s : Finset X} (h : IsDynNetIn T F U n s) :
    s.card ≤ netMaxcard T F U n :=
le_iSup₂ (α := ℕ∞) s h
```

-- snippet 8
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_monotone_time (L107-L110)
lemma netMaxcard_monotone_time (T : X → X) (F : Set X) (U : SetRel X X) :
    Monotone fun n : ℕ ↦ netMaxcard T F U n :=
fun _ _ m_n ↦ biSup_mono fun _ h ↦ h.of_le m_n
```

-- snippet 9
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_antitone (L111-L115)
lemma netMaxcard_antitone (T : X → X) (F : Set X) (n : ℕ) :
    Antitone fun U : SetRel X X ↦ netMaxcard T F U n :=
fun _ _ U_V ↦ biSup_mono fun _ h ↦ h.of_entourage_subset U_V

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 10
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_finite_iff (L116-L150)
lemma netMaxcard_finite_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    netMaxcard T F U n < ⊤ ↔
    ∃ s : Finset X, IsDynNetIn T F U n s ∧ (s.card : ℕ∞) = netMaxcard T F U n := by
apply Iff.intro <;> intro h
  · obtain ⟨k, k_max⟩ := WithTop.ne_top_iff_exists.1 h.ne
    rw [← k_max]
    simp only [ENat.some_eq_coe, Nat.cast_inj]
    -- The criterion we want to use is `Nat.sSup_mem`. We rewrite `netMaxcard` with an `sSup`,
    -- then check its `BddAbove` and `Nonempty` hypotheses.
    have : netMaxcard T F U n
      = sSup (WithTop.some '' (Finset.card '' {s : Finset X | IsDynNetIn T F U n s})) := by
      rw [netMaxcard, ← image_comp, sSup_image]
      simp only [mem_setOf_eq, ENat.some_eq_coe, Function.comp_apply]
    rw [this] at k_max
    have h_bdda : BddAbove (Finset.card '' {s : Finset X | IsDynNetIn T F U n s}) := by
      refine ⟨k, mem_upperBounds.2 ?_⟩
      simp only [mem_image, mem_setOf_eq, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
      intro s h
      rw [← WithTop.coe_le_coe, k_max]
      apply le_sSup
      simp only [ENat.some_eq_coe, mem_image, mem_setOf_eq, Nat.cast_inj, exists_eq_right]
      exact Filter.frequently_principal.mp fun a ↦ a h rfl
    have h_nemp : (Finset.card '' {s : Finset X | IsDynNetIn T F U n s}).Nonempty := by
      refine ⟨0, ?_⟩
      simp only [mem_image, mem_setOf_eq, Finset.card_eq_zero, exists_eq_right, Finset.coe_empty]
      exact isDynNetIn_empty
    rw [← WithTop.coe_sSup' h_bdda, ENat.some_eq_coe, Nat.cast_inj] at k_max
    have key := Nat.sSup_mem h_nemp h_bdda
    rw [← k_max, mem_image] at key
    simp only [mem_setOf_eq] at key
    exact key
  · obtain ⟨s, _, s_card⟩ := h
    rw [← s_card]
    exact WithTop.coe_lt_top s.card
```

-- snippet 11
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_empty (L152-L158)
lemma netMaxcard_empty : netMaxcard T ∅ U n = 0 := by
rw [netMaxcard, ← bot_eq_zero, iSup₂_eq_bot]
  intro s s_net
  replace s_net := subset_empty_iff.1 s_net.1
  norm_cast at s_net
  rw [s_net, Finset.card_empty, CharP.cast_eq_zero, bot_eq_zero']
```

-- snippet 12
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_eq_zero_iff (L159-L169)
lemma netMaxcard_eq_zero_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    netMaxcard T F U n = 0 ↔ F = ∅ := by
refine ⟨fun h ↦ ?_, fun h ↦ by rw [h, netMaxcard_empty]⟩
  rw [eq_empty_iff_forall_notMem]
  intro x x_F
  have key := isDynNetIn_singleton T U n x_F
  rw [← Finset.coe_singleton] at key
  replace key := key.card_le_netMaxcard
  rw [Finset.card_singleton, Nat.cast_one, h] at key
  exact key.not_gt zero_lt_one
```

-- snippet 13
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.one_le_netMaxcard_iff (L170-L174)
lemma one_le_netMaxcard_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    1 ≤ netMaxcard T F U n ↔ F.Nonempty := by
rw [ENat.one_le_iff_ne_zero, nonempty_iff_ne_empty]
  exact not_iff_not.2 (netMaxcard_eq_zero_iff T F U n)
```

-- snippet 14
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_zero (L175-L182)
lemma netMaxcard_zero (T : X → X) (h : F.Nonempty) (U : SetRel X X) : netMaxcard T F U 0 = 1 := by
apply (iSup₂_le _).antisymm ((one_le_netMaxcard_iff T F U 0).2 h)
  intro s ⟨_, s_net⟩
  simp only [ball, dynEntourage_zero, preimage_univ] at s_net
  norm_cast
  refine Finset.card_le_one.2 fun x x_s y y_s ↦ ?_
  exact PairwiseDisjoint.elim_set s_net x_s y_s x (mem_univ x) (mem_univ x)
```

-- snippet 15
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_univ (L183-L191)
lemma netMaxcard_univ (T : X → X) (h : F.Nonempty) (n : ℕ) : netMaxcard T F univ n = 1 := by
apply (iSup₂_le _).antisymm ((one_le_netMaxcard_iff T F univ n).2 h)
  intro s ⟨_, s_net⟩
  simp only [ball, dynEntourage_univ, preimage_univ] at s_net
  norm_cast
  refine Finset.card_le_one.2 fun x x_s y y_s ↦ ?_
  exact PairwiseDisjoint.elim_set s_net x_s y_s x (mem_univ x) (mem_univ x)

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 16
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_infinite_iff (L192-L207)
lemma netMaxcard_infinite_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    netMaxcard T F U n = ⊤ ↔ ∀ k : ℕ, ∃ s : Finset X, IsDynNetIn T F U n s ∧ k ≤ s.card := by
apply Iff.intro <;> intro h
  · intro k
    rw [netMaxcard, iSup_subtype', iSup_eq_top] at h
    specialize h k (ENat.coe_lt_top k)
    simp only [Nat.cast_lt, Subtype.exists, exists_prop] at h
    obtain ⟨s, s_net, s_k⟩ := h
    exact ⟨s, s_net, s_k.le⟩
  · refine WithTop.eq_top_iff_forall_gt.2 fun k ↦ ?_
    specialize h (k + 1)
    obtain ⟨s, s_net, s_card⟩ := h
    apply s_net.card_le_netMaxcard.trans_lt'
    rw [ENat.some_eq_coe, Nat.cast_lt]
    exact (lt_add_one k).trans_le s_card
```

-- snippet 17
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netMaxcard_le_coverMincard (L208-L218)
lemma netMaxcard_le_coverMincard (T : X → X) (F : Set X) (n : ℕ) :
    netMaxcard T F U n ≤ coverMincard T F U n := by
rcases eq_top_or_lt_top (coverMincard T F U n) with h | h
  · exact h ▸ le_top
  · obtain ⟨t, t_cover, t_mincard⟩ := (coverMincard_finite_iff T F U n).1 h
    rw [← t_mincard]
    exact iSup₂_le fun s s_net ↦ Nat.cast_le.2 (s_net.card_le_card_of_isDynCoverOf t_cover)

/-- Given an entourage `U` and a time `n`, a minimal dynamical cover by `U ○ U` has a smaller
  cardinality than a maximal dynamical net by `U`. This lemma is the second of two key results to
  compare two versions topological entropy: with cover and with nets. -/
```

-- snippet 18
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.coverMincard_le_netMaxcard (L219-L261)
lemma coverMincard_le_netMaxcard (T : X → X) (F : Set X) [U.IsRefl] [U.IsSymm] (n : ℕ) :
    coverMincard T F (U ○ U) n ≤ netMaxcard T F U n := by
classical
  -- WLOG, there exists a maximal dynamical net `s`.
  rcases eq_top_or_lt_top (netMaxcard T F U n) with h | h
  · exact h ▸ le_top
  obtain ⟨s, s_net, s_card⟩ := (netMaxcard_finite_iff T F U n).1 h
  rw [← s_card]
  apply IsDynCoverOf.coverMincard_le_card
  --  We have to check that `s` is a cover for `dynEntourage T F (U ○ U) n`.
  -- If `s` is not a cover, then we can add to `s` a point `x` which is not covered
  -- and get a new net. This contradicts the maximality of `s`.
  rw [IsDynCoverOf, isCover_iff_subset_iUnion_ball]
  by_contra h
  obtain ⟨x, x_F, x_uncov⟩ := not_subset.1 h
  simp only [Finset.mem_coe, mem_iUnion, exists_prop, not_exists, not_and] at x_uncov
  have larger_net : IsDynNetIn T F U n (insert x s) := by
    refine ⟨insert_subset x_F s_net.1, pairwiseDisjoint_insert.2 ⟨s_net.2, ?_⟩⟩
    refine fun y y_s _ ↦ disjoint_left.2 fun z z_x z_y ↦ x_uncov y y_s ?_
    exact mem_ball_dynEntourage_comp T n x y (nonempty_of_mem ⟨z_x, z_y⟩)
  rw [← s.coe_insert x] at larger_net
  apply larger_net.card_le_netMaxcard.not_gt
  rw [← s_card, Nat.cast_lt]
  refine (lt_add_one s.card).trans_eq (s.card_insert_of_notMem fun x_s ↦ ?_).symm
  exact x_uncov x x_s (ball_mono (dynEntourage_monotone T n SetRel.left_subset_comp) x <|
    SetRel.rfl (dynEntourage T U n))

/-! ### Net entropy of entourages -/

open ENNReal EReal ExpGrowth Filter

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size of the
largest `(U, n)`-dynamical net of `F`. Takes values in the space of extended real numbers
`[-∞,+∞]`. This version uses a `limsup`, and is chosen as the default definition. -/
noncomputable def netEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthSup fun n : ℕ ↦ netMaxcard T F U n

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size of the
largest `(U, n)`-dynamical net of `F`. Takes values in the space of extended real numbers
`[-∞,+∞]`. This version uses a `liminf`, and is an alternative definition. -/
noncomputable def netEntropyInfEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthInf fun n : ℕ ↦ netMaxcard T F U n
```

-- snippet 19
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_antitone (L262-L265)
lemma netEntropyInfEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ netEntropyInfEntourage T F U :=
fun _ _ U_V ↦ expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (netMaxcard_antitone T F n U_V)
```

-- snippet 20
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_antitone (L266-L269)
lemma netEntropyEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ netEntropyEntourage T F U :=
fun _ _ U_V ↦ expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (netMaxcard_antitone T F n U_V)
```

-- snippet 21
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_le_netEntropyEntourage (L270-L273)
lemma netEntropyInfEntourage_le_netEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :
    netEntropyInfEntourage T F U ≤ netEntropyEntourage T F U :=
expGrowthInf_le_expGrowthSup
```

-- snippet 22
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_empty (L275-L279)
lemma netEntropyEntourage_empty : netEntropyEntourage T ∅ U = ⊥ := by
rw [netEntropyEntourage, ← expGrowthSup_zero]
  congr
  simp only [netMaxcard_empty, ENat.toENNReal_zero, Pi.zero_def]
```

-- snippet 23
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_empty (L281-L283)
lemma netEntropyInfEntourage_empty : netEntropyInfEntourage T ∅ U = ⊥ :=
eq_bot_mono (netEntropyInfEntourage_le_netEntropyEntourage T ∅ U) netEntropyEntourage_empty
```

-- snippet 24
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyInfEntourage_nonneg (L284-L292)
lemma netEntropyInfEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ netEntropyInfEntourage T F U := by
apply Monotone.expGrowthInf_nonneg
  · exact fun _ _ m_n ↦ ENat.toENNReal_mono (netMaxcard_monotone_time T F U m_n)
  · rw [ne_eq, funext_iff.not, not_forall]
    use 0
    rw [netMaxcard_zero T h U, Pi.zero_apply, ENat.toENNReal_one]
    exact one_ne_zero
```

-- snippet 25
```lean
-- Mathlib.Dynamics.TopologicalEntropy.NetEntropy.netEntropyEntourage_nonneg (L293-L296)
lemma netEntropyEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ netEntropyEntourage T F U :=
(netEntropyInfEntourage_nonneg T h U).trans (netEntropyInfEntourage_le_netEntropyEntourage T F U)
```

-- snippet 26
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_finite_of_isCompact_uniformContinuous (L290-L295)
lemma coverMincard_finite_of_isCompact_uniformContinuous [UniformSpace X] (F_comp : IsCompact F)
    (h : UniformContinuous T) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    coverMincard T F U n < ⊤ := by
obtain ⟨s, s_cover⟩ := exists_isDynCoverOf_of_isCompact_uniformContinuous F_comp h U_uni n
  exact s_cover.coverMincard_le_card.trans_lt (WithTop.coe_lt_top s.card)
```

-- snippet 27
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_nonneg (L371-L375)
lemma coverEntropyEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ coverEntropyEntourage T F U :=
(coverEntropyInfEntourage_nonneg T h U).trans
    (coverEntropyInfEntourage_le_coverEntropyEntourage T F U)
```

-- snippet 28
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.one_le_coverMincard_iff (L250-L254)
lemma one_le_coverMincard_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    1 ≤ coverMincard T F U n ↔ F.Nonempty := by
rw [ENat.one_le_iff_ne_zero, nonempty_iff_ne_empty, not_iff_not]
  exact coverMincard_eq_zero_iff T F U n
```

-- snippet 29
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_empty (L486-L488)
lemma coverEntropyInf_empty : coverEntropyInf T ∅ = ⊥ := by
simp only [coverEntropyInf, coverEntropyInfEntourage_empty, iSup_bot]
```

-- snippet 30
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.le_coverMincard_image (L93-L101)
lemma le_coverMincard_image (h : Semiconj φ S T) (F : Set X) [V.IsSymm] (n : ℕ) :
    coverMincard S F ((map φ φ) ⁻¹' (V ○ V)) n ≤ coverMincard T (φ '' F) V n := by
rcases eq_top_or_lt_top (coverMincard T (φ '' F) V n) with h' | h'
  · exact h' ▸ le_top
  obtain ⟨t, t_cover, t_card⟩ := (coverMincard_finite_iff T (φ '' F) V n).1 h'
  obtain ⟨s, s_cover, s_card⟩ := t_cover.preimage h
  rw [← t_card]
  exact s_cover.coverMincard_le_card.trans (WithTop.coe_le_coe.2 s_card)
```

-- snippet 31
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_mem_uniformity (L65-L77)
lemma dynEntourage_mem_uniformity [UniformSpace X] (h : UniformContinuous T)
    (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    dynEntourage T U n ∈ 𝓤 X := by
rw [dynEntourage_eq_inter_Ico T U n]
  induction n with
  | zero => simp
  | succ n ih =>
    simp only [iInter_coe_set, mem_Ico, Nat.zero_le, true_and] at ih ⊢
    rw [Set.biInter_lt_succ]
    apply Filter.inter_mem ih
    rw [map_iterate T T n]
    exact uniformContinuous_def.1 (UniformContinuous.iterate T n h) U U_uni
```

-- snippet 32
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_monotone_time (L213-L216)
lemma coverMincard_monotone_time (T : X → X) (F : Set X) (U : SetRel X X) :
    Monotone fun n : ℕ ↦ coverMincard T F U n :=
fun _ _ m_n ↦ biInf_mono fun _ h ↦ h.of_le m_n
```

-- snippet 33
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_restrict (L189-L193)
theorem coverEntropy_restrict [UniformSpace X] {T : X → X} {F : Set X} (h : MapsTo T F F) :
    coverEntropy (h.restrict T F F) univ = coverEntropy T F := by
rw [← coverEntropy_restrict_subset Subset.rfl h, coe_preimage_self F]

/-- The entropy of `φ '' F` is at most the entropy of `F` if `φ` is uniformly continuous. -/
```

-- snippet 34
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_antitone (L442-L447)
lemma coverEntropy_antitone (T : X → X) (F : Set X) :
    Antitone fun (u : UniformSpace X) ↦ @coverEntropy X u T F :=
fun _ _ h ↦ iSup₂_mono' fun U U_uni ↦ ⟨U, (le_def.1 h) U U_uni, le_refl _⟩

variable [UniformSpace X]
```

-- snippet 35
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_univ (L381-L385)
lemma coverEntropyInfEntourage_univ (T : X → X) (h : F.Nonempty) :
    coverEntropyInfEntourage T F univ = 0 := by
rw [← expGrowthInf_const one_ne_zero one_ne_top, coverEntropyInfEntourage]
  simp only [coverMincard_univ T h, ENat.toENNReal_one]
```

-- snippet 36
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_le_coverEntropyInfEntourage (L407-L411)
lemma coverEntropyEntourage_le_coverEntropyInfEntourage (F_inv : MapsTo T F F) [U.IsSymm] :
    coverEntropyEntourage T F (U ○ U) ≤ coverEntropyInfEntourage T F U := by
refine (le_liminf_of_le) (eventually_atTop.2 ⟨1, fun m m_pos ↦ ?_⟩)
  exact coverEntropyEntourage_le_log_coverMincard_div F_inv (Nat.one_le_iff_ne_zero.1 m_pos)
```

-- snippet 37
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_eq_iSup_basis (L458-L466)
lemma coverEntropy_eq_iSup_basis {ι : Sort*} {p : ι → Prop} {s : ι → SetRel X X}
    (h : (𝓤 X).HasBasis p s) (T : X → X) (F : Set X) :
    coverEntropy T F = ⨆ (i : ι) (_ : p i), coverEntropyEntourage T F (s i) := by
refine (iSup₂_le fun U U_uni ↦ ?_).antisymm
    (iSup₂_mono' fun i h_i ↦ ⟨s i, HasBasis.mem_of_mem h h_i, le_refl _⟩)
  obtain ⟨i, h_i, si_U⟩ := (HasBasis.mem_iff h).1 U_uni
  exact (coverEntropyEntourage_antitone T F si_U).trans
    (le_iSup₂ (f := fun (i : ι) (_ : p i) ↦ coverEntropyEntourage T F (s i)) i h_i)
```

-- snippet 38
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.IsDynCoverOf (L50-L53)
lemma IsDynCoverOf.monotone_subset (F_G : F ⊆ G) (h : IsDynCoverOf T G U n s) :
    IsDynCoverOf T F U n s :=
F_G.trans h
```

-- snippet 39
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.isDynCoverOf_zero (L94-L96)
lemma isDynCoverOf_zero (T : X → X) (F : Set X) (U : SetRel X X) (h : s.Nonempty) :
    IsDynCoverOf T F U 0 s := by simp [IsDynCoverOf, h]
```

-- snippet 40
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_ball_dynEntourage (L61-L64)
lemma mem_ball_dynEntourage :
    y ∈ ball x (dynEntourage T U n) ↔ ∀ k < n, T^[k] y ∈ ball (T^[k] x) U := by
simp only [ball, mem_preimage, mem_dynEntourage]
```

-- snippet 41
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverMincard_image_le (L102-L114)
lemma coverMincard_image_le (h : Semiconj φ S T) (F : Set X) (V : SetRel Y Y) (n : ℕ) :
    coverMincard T (φ '' F) V n ≤ coverMincard S F ((map φ φ) ⁻¹' V) n := by
classical
  rcases eq_top_or_lt_top (coverMincard S F ((map φ φ) ⁻¹' V) n) with h' | h'
  · exact h' ▸ le_top
  obtain ⟨s, s_cover, s_card⟩ := (coverMincard_finite_iff S F ((map φ φ) ⁻¹' V) n).1 h'
  rw [← s_card]
  have := s_cover.image h
  rw [← s.coe_image] at this
  exact this.coverMincard_le_card.trans (WithTop.coe_le_coe.2 s.card_image_le)

open ENNReal EReal ExpGrowth Filter
```

-- snippet 42
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_eq_zero_iff (L246-L249)
lemma coverMincard_eq_zero_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    coverMincard T F U n = 0 ↔ F = ∅ := by
simp [coverMincard, ENat.iInf_eq_zero]
```

-- snippet 43
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverEntropyInfEntourage_monotone (L65-L69)
lemma coverEntropyInfEntourage_monotone (T : X → X) (U : SetRel X X) :
    Monotone fun F : Set X ↦ coverEntropyInfEntourage T F U := by
refine fun F G F_G ↦ ExpGrowth.expGrowthInf_monotone fun n ↦ ?_
  exact ENat.toENNReal_mono (coverMincard_monotone_subset T U n F_G)
```

-- snippet 44
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_image_le_of_uniformContinuousOn_invariant (L208-L219)
lemma coverEntropy_image_le_of_uniformContinuousOn_invariant [UniformSpace X] [UniformSpace Y]
    {S : X → X} {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) {F G : Set X}
    (h' : UniformContinuousOn φ G) (hF : F ⊆ G) (hG : MapsTo S G G) :
    coverEntropy T (φ '' F) ≤ coverEntropy S F := by
rw [← coverEntropy_restrict_subset hF hG]
  have hφ : Semiconj (G.restrict φ) (hG.restrict S G G) T := by
    intro x
    rw [G.restrict_apply, G.restrict_apply, hG.val_restrict_apply, h.eq x]
  apply (coverEntropy_image_le_of_uniformContinuous hφ
    (uniformContinuousOn_iff_restrict.1 h') (val ⁻¹' F)).trans_eq'
  rw [← image_image_val_eq_restrict_image, image_preimage_coe G F, inter_eq_right.2 hF]
```

-- snippet 45
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.isDynCoverOf_univ (L97-L99)
lemma isDynCoverOf_univ (T : X → X) (F : Set X) (n : ℕ) (h : s.Nonempty) :
    IsDynCoverOf T F univ n s := by simp [IsDynCoverOf, h]
```

-- snippet 46
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.isSymm_dynEntourage (L91-L94)
instance isSymm_dynEntourage [U.IsSymm] : (dynEntourage T U n).IsSymm := by
simp [dynEntourage]; infer_instance

set_option linter.deprecated false in
```

-- snippet 47
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.IsDynNetIn (L54-L56)
lemma IsDynNetIn.monotone_subset (F_G : F ⊆ G) (h : IsDynNetIn T F U n s) : IsDynNetIn T G U n s :=
⟨h.1.trans F_G, h.2⟩
```

-- snippet 48
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_finite_of_isCompact_invariant (L412-L437)
lemma coverEntropyEntourage_finite_of_isCompact_invariant [UniformSpace X]
    (F_comp : IsCompact F) (F_inv : MapsTo T F F) (U_uni : U ∈ 𝓤 X) :
    coverEntropyEntourage T F U < ⊤ := by
obtain ⟨V, V_uni, V_symm, V_U⟩ := comp_symm_mem_uniformity_sets U_uni
  obtain ⟨s, s_cover⟩ := exists_isDynCoverOf_of_isCompact_invariant F_comp F_inv V_uni 1
  apply (coverEntropyEntourage_antitone T F V_U).trans_lt
  apply (s_cover.coverEntropyEntourage_le_log_card_div F_inv one_ne_zero).trans_lt
  rw [Nat.cast_one, div_one, log_lt_top_iff, ← ENat.toENNReal_top]
  exact_mod_cast (ENat.coe_ne_top (Finset.card s)).lt_top

/-! ### Cover entropy -/

/-- The entropy of `T` restricted to `F`, obtained by taking the supremum
  of `coverEntropyEntourage` over entourages. Note that this supremum is approached by taking small
  entourages. This first version uses a `limsup`, and is chosen as the default definition
  for topological entropy. -/
noncomputable def coverEntropy [UniformSpace X] (T : X → X) (F : Set X) :=
  ⨆ U ∈ 𝓤 X, coverEntropyEntourage T F U

/-- The entropy of `T` restricted to `F`, obtained by taking the supremum
  of `coverEntropyInfEntourage` over entourages. Note that this supremum is approached by taking
  small entourages. This second version uses a `liminf`, and is chosen as an alternative
  definition for topological entropy. -/
noncomputable def coverEntropyInf [UniformSpace X] (T : X → X) (F : Set X) :=
  ⨆ U ∈ 𝓤 X, coverEntropyInfEntourage T F U
```

-- snippet 49
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_eq_coverEntropy (L496-L503)
lemma coverEntropyInf_eq_coverEntropy (T : X → X) (h : MapsTo T F F) :
    coverEntropyInf T F = coverEntropy T F := by
refine le_antisymm (coverEntropyInf_le_coverEntropy T F) (iSup₂_le fun U U_uni ↦ ?_)
  obtain ⟨V, V_uni, V_symm, V_U⟩ := comp_symm_mem_uniformity_sets U_uni
  exact (coverEntropyEntourage_antitone T F V_U).trans <| le_iSup₂_of_le V V_uni <|
     coverEntropyEntourage_le_coverEntropyInfEntourage h

end Dynamics
```

-- snippet 50
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_restrict_subset (L175-L180)
lemma coverEntropy_restrict_subset [UniformSpace X] {T : X → X} {F G : Set X} (hF : F ⊆ G)
    (hG : MapsTo T G G) :
    coverEntropy (hG.restrict T G G) (val ⁻¹' F) = coverEntropy T F := by
rw [← coverEntropy_image_of_comap _ hG.val_restrict_apply (val ⁻¹' F), image_preimage_coe G F,
    inter_eq_right.2 hF]
```

-- snippet 51
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_le_coverEntropy (L476-L480)
lemma coverEntropyInf_le_coverEntropy (T : X → X) (F : Set X) :
    coverEntropyInf T F ≤ coverEntropy T F :=
iSup₂_mono fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦
    coverEntropyInfEntourage_le_coverEntropyEntourage T F U
```

-- snippet 52
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_le_pow (L285-L289)
lemma coverMincard_le_pow (F_inv : MapsTo T F F) [U.IsSymm] (m_pos : 0 < m) (n : ℕ) :
    coverMincard T F (U ○ U) n ≤ coverMincard T F U m ^ (n / m + 1) :=
(coverMincard_monotone_time T F (U ○ U) (Nat.lt_mul_div_succ n m_pos).le).trans
    (coverMincard_mul_le_pow F_inv m (n / m + 1))
```

-- snippet 53
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.isRefl_dynEntourage (L87-L90)
instance isRefl_dynEntourage [U.IsRefl] : (dynEntourage T U n).IsRefl := by
simp [dynEntourage]; infer_instance

set_option linter.flexible false in -- simp followed by infer_instance
```

-- snippet 54
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverMincard_monotone_subset (L57-L60)
lemma coverMincard_monotone_subset (T : X → X) (U : SetRel X X) (n : ℕ) :
    Monotone fun F : Set X ↦ coverMincard T F U n :=
fun _ _ F_G ↦ biInf_mono fun _ h ↦ h.monotone_subset F_G
```

-- snippet 55
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_empty (L354-L357)
lemma coverEntropyEntourage_empty : coverEntropyEntourage T ∅ U = ⊥ := by
simp only [coverEntropyEntourage, coverMincard_empty]
  rw [ENat.toENNReal_zero, ← Pi.zero_def, expGrowthSup_zero]
```

-- snippet 56
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_antitone (L438-L441)
lemma coverEntropyInf_antitone (T : X → X) (F : Set X) :
    Antitone fun (u : UniformSpace X) ↦ @coverEntropyInf X u T F :=
fun _ _ h ↦ iSup₂_mono' fun U U_uni ↦ ⟨U, (le_def.1 h) U U_uni, le_refl _⟩
```

-- snippet 57
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.IsDynCoverOf (L78-L80)
def IsDynCoverOf (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) (s : Set X) : Prop :=
IsCover (dynEntourage T U n) F s
```

-- snippet 58
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_eq_iSup_basis (L467-L475)
lemma coverEntropyInf_eq_iSup_basis {ι : Sort*} {p : ι → Prop} {s : ι → SetRel X X}
    (h : (𝓤 X).HasBasis p s) (T : X → X) (F : Set X) :
    coverEntropyInf T F = ⨆ (i : ι) (_ : p i), coverEntropyInfEntourage T F (s i) := by
refine (iSup₂_le fun U U_uni ↦ ?_).antisymm
    (iSup₂_mono' fun i h_i ↦ ⟨s i, HasBasis.mem_of_mem h h_i, le_refl _⟩)
  obtain ⟨i, h_i, si_U⟩ := (HasBasis.mem_iff h).1 U_uni
  exact (coverEntropyInfEntourage_antitone T F si_U).trans
    (le_iSup₂ (f := fun (i : ι) (_ : p i) ↦ coverEntropyInfEntourage T F (s i)) i h_i)
```

-- snippet 59
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.coverEntropyEntourage_monotone (L70-L74)
lemma coverEntropyEntourage_monotone (T : X → X) (U : SetRel X X) :
    Monotone fun F : Set X ↦ coverEntropyEntourage T F U := by
refine fun F G F_G ↦ ExpGrowth.expGrowthSup_monotone fun n ↦ ?_
  exact ENat.toENNReal_mono (coverMincard_monotone_subset T U n F_G)
```

-- snippet 60
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.nonempty_inter_of_coverMincard (L305-L340)
lemma nonempty_inter_of_coverMincard [U.IsSymm] {s : Finset X} (h : IsDynCoverOf T F U n s)
    (h' : #s = coverMincard T F U n) :
    ∀ x ∈ s, (F ∩ ball x (dynEntourage T U n)).Nonempty := by
-- Otherwise, there is a ball which does not intersect `F`. Removing it yields a smaller cover.
  classical
  by_contra! ⟨x, x_s, ball_empt⟩
  have smaller_cover : IsDynCoverOf T F U n (s.erase x) := by
    intro y y_F
    specialize h y_F
    simp only [s.mem_coe] at h
    simp only [s.coe_erase, mem_diff, s.mem_coe, mem_singleton_iff]
    obtain ⟨z, z_s, hz⟩ := h
    refine ⟨z, ⟨z_s, fun z_x ↦ notMem_empty y ?_⟩, hz⟩
    rw [← ball_empt]
    rw [z_x] at hz
    exact mem_inter y_F <| (dynEntourage T U n).symm hz
  apply smaller_cover.coverMincard_le_card.not_gt
  rw [← h']
  exact_mod_cast s.card_erase_lt_of_mem x_s

/-! ### Cover entropy of entourages -/

open ENNReal EReal ExpGrowth Filter

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size
  of the smallest `(U, n)`-refined cover of `F`. Takes values in the space of extended real numbers
  `[-∞, +∞]`. This first version uses a `limsup`, and is chosen as the default definition. -/
noncomputable def coverEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthSup fun n : ℕ ↦ coverMincard T F U n

/-- The entropy of an entourage `U`, defined as the exponential rate of growth of the size
  of the smallest `(U, n)`-refined cover of `F`. Takes values in the space of extended real numbers
  `[-∞, +∞]`. This second version uses a `liminf`, and is chosen as an alternative definition. -/
noncomputable def coverEntropyInfEntourage (T : X → X) (F : Set X) (U : SetRel X X) :=
  expGrowthInf fun n : ℕ ↦ coverMincard T F U n
```

-- snippet 61
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_antitone (L130-L133)
lemma dynEntourage_antitone (T : X → X) (U : SetRel X X) :
    Antitone (fun n : ℕ ↦ dynEntourage T U n) :=
fun m n m_n ↦ iInter₂_mono' fun k k_m ↦ by use k, lt_of_lt_of_le k_m m_n
```

-- snippet 62
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_image_of_comap (L154-L174)
theorem coverEntropyInf_image_of_comap (u : UniformSpace Y) {S : X → X} {T : Y → Y} {φ : X → Y}
    (h : Semiconj φ S T) (F : Set X) :
    coverEntropyInf T (φ '' F) = @coverEntropyInf X (comap φ u) S F := by
let : UniformSpace X := comap φ u
  apply le_antisymm
  · refine iSup₂_le fun V V_uni ↦
      (coverEntropyInfEntourage_antitone _ _ SetRel.symmetrize_subset_self).trans <|
      (coverEntropyInfEntourage_image_le h F _).trans ?_
    apply coverEntropyInfEntourage_le_coverEntropyInf
    rw [uniformity_comap φ, mem_comap]
    exact ⟨_, symmetrize_mem_uniformity V_uni, .rfl⟩
  · refine iSup₂_le fun U U_uni ↦ ?_
    simp only [uniformity_comap φ, mem_comap] at U_uni
    obtain ⟨V, V_uni, V_sub⟩ := U_uni
    obtain ⟨W, W_uni, W_symm, W_V⟩ := comp_symm_mem_uniformity_sets V_uni
    apply (coverEntropyInfEntourage_antitone S F ((preimage_mono W_V).trans V_sub)).trans
    apply (le_coverEntropyInfEntourage_image h F).trans
    exact coverEntropyInfEntourage_le_coverEntropyInf T (φ '' F) W_uni

open Subtype
```

-- snippet 63
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_eq_inter_Ico (L54-L57)
lemma dynEntourage_eq_inter_Ico (T : X → X) (U : SetRel X X) (n : ℕ) :
    dynEntourage T U n = ⋂ k : Ico 0 n, (map T T)^[k] ⁻¹' U := by
simp [dynEntourage]
```

-- snippet 64
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInfEntourage_image_le (L127-L132)
lemma coverEntropyInfEntourage_image_le (h : Semiconj φ S T) (F : Set X) (V : SetRel Y Y) :
    coverEntropyInfEntourage T (φ '' F) V ≤ coverEntropyInfEntourage S F ((map φ φ) ⁻¹' V) :=
expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_image_le h F V n)

/-- The entropy of `φ '' F` equals the entropy of `F` if `X` is endowed with the pullback by `φ`
  of the uniform structure of `Y`. -/
```

-- snippet 65
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_image_le_of_uniformContinuous (L202-L207)
theorem coverEntropyInf_image_le_of_uniformContinuous [UniformSpace X] [UniformSpace Y] {S : X → X}
    {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) (h' : UniformContinuous φ) (F : Set X) :
    coverEntropyInf T (φ '' F) ≤ coverEntropyInf S F := by
rw [coverEntropyInf_image_of_comap _ h F]
  exact coverEntropyInf_antitone S F (uniformContinuous_iff.1 h')
```

-- snippet 66
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.netMaxcard_monotone_subset (L61-L64)
lemma netMaxcard_monotone_subset (T : X → X) (U : SetRel X X) (n : ℕ) :
    Monotone fun F : Set X ↦ netMaxcard T F U n :=
fun _ _ F_G ↦ biSup_mono fun _ h ↦ h.monotone_subset F_G
```

-- snippet 67
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_empty (L243-L245)
lemma coverMincard_empty : coverMincard T ∅ U n = 0 :=
(sInf_le (by simp [IsDynCoverOf])).antisymm (zero_le (coverMincard T ∅ U n))
```

-- snippet 68
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_antitone (L345-L348)
lemma coverEntropyEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ coverEntropyEntourage T F U :=
fun _ _ U_V ↦ expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_antitone T F n U_V)
```

-- snippet 69
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_le_coverEntropy (L448-L452)
lemma coverEntropyEntourage_le_coverEntropy (T : X → X) (F : Set X)
    (h : U ∈ 𝓤 X) :
    coverEntropyEntourage T F U ≤ coverEntropy T F :=
le_iSup₂ (f := fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦ coverEntropyEntourage T F U) U h
```

-- snippet 70
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Subset.netEntropyInfEntourage_monotone (L75-L79)
lemma netEntropyInfEntourage_monotone (T : X → X) (U : SetRel X X) :
    Monotone fun F : Set X ↦ netEntropyInfEntourage T F U := by
refine fun F G F_G ↦ ExpGrowth.expGrowthInf_monotone fun n ↦ ?_
  exact ENat.toENNReal_mono (netMaxcard_monotone_subset T U n F_G)
```

-- snippet 71
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.exists_isDynCoverOf_of_isCompact_invariant (L191-L208)
lemma exists_isDynCoverOf_of_isCompact_invariant [UniformSpace X]
    (F_comp : IsCompact F) (F_inv : MapsTo T F F) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    ∃ s : Finset X, IsDynCoverOf T F U n s := by
obtain ⟨(V : SetRel X X), V_uni, V_symm, V_U⟩ := comp_symm_mem_uniformity_sets U_uni
  obtain ⟨s, _, s_cover⟩ := F_comp.elim_nhds_subcover (ball · V)
    fun (x : X) _ ↦ ball_mem_nhds x V_uni
  have : IsDynCoverOf T F V 1 s := .of_subset_iUnion_ball <| by simpa using s_cover
  obtain ⟨t, t_dyncover, t_card⟩ := this.iterate_le_pow F_inv n
  rw [one_mul n] at t_dyncover
  exact ⟨t, t_dyncover.of_entourage_subset V_U⟩

/-! ### Minimal cardinality of dynamical covers -/

/-- The smallest cardinality of a `(U, n)`-dynamical cover of `F`. Takes values in `ℕ∞`, and is
  infinite if and only if `F` admits no finite dynamical cover. -/
noncomputable def coverMincard (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) : ℕ∞ :=
  ⨅ (s : Finset X) (_ : IsDynCoverOf T F U n s), (s.card : ℕ∞)
```

-- snippet 72
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_le_log_coverMincard_div (L386-L399)
lemma coverEntropyEntourage_le_log_coverMincard_div (F_inv : MapsTo T F F) [U.IsSymm]
    (n_pos : n ≠ 0) :
    coverEntropyEntourage T F (U ○ U) ≤ log (coverMincard T F U n) / n := by
have cv_mono : Monotone fun m ↦ (coverMincard T F (U ○ U) m).toENNReal :=
    fun _ _ k_m ↦ ENat.toENNReal_mono (coverMincard_monotone_time T F (U ○ U) k_m)
  have h := cv_mono.expGrowthSup_comp_mul n_pos
  rw [mul_comm, ← div_eq_iff (natCast_ne_bot n) (natCast_ne_top n) (Nat.cast_ne_zero.2 n_pos)] at h
  rw [coverEntropyEntourage, ← h]
  apply monotone_div_right_of_nonneg n.cast_nonneg'
  rw [← expGrowthSup_pow]
  refine expGrowthSup_monotone fun m ↦ ?_
  rw [← ENat.toENNReal_pow]
  exact ENat.toENNReal_mono (coverMincard_mul_le_pow F_inv n m)
```

-- snippet 73
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_image_le_of_uniformContinuousOn_invariant (L220-L232)
lemma coverEntropyInf_image_le_of_uniformContinuousOn_invariant [UniformSpace X] [UniformSpace Y]
    {S : X → X} {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) {F G : Set X}
    (h' : UniformContinuousOn φ G) (hF : F ⊆ G) (hG : MapsTo S G G) :
    coverEntropyInf T (φ '' F) ≤ coverEntropyInf S F := by
rw [← coverEntropyInf_restrict_subset hF hG]
  have hφ : Semiconj (G.restrict φ) (hG.restrict S G G) T := by
    intro a
    rw [G.restrict_apply, G.restrict_apply, hG.val_restrict_apply, h.eq a]
  apply (coverEntropyInf_image_le_of_uniformContinuous hφ
    (uniformContinuousOn_iff_restrict.1 h') (val ⁻¹' F)).trans_eq'
  rw [← image_image_val_eq_restrict_image, image_preimage_coe G F, inter_eq_right.2 hF]

end Dynamics
```

-- snippet 74
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_nonneg (L493-L495)
lemma coverEntropy_nonneg (T : X → X) (h : F.Nonempty) : 0 ≤ coverEntropy T F :=
(coverEntropyInf_nonneg T h).trans (coverEntropyInf_le_coverEntropy T F)
```

-- snippet 75
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_antitone (L217-L221)
lemma coverMincard_antitone (T : X → X) (F : Set X) (n : ℕ) :
    Antitone fun U : SetRel X X ↦ coverMincard T F U n :=
fun _ _ U_V ↦ biInf_mono fun _ h ↦ h.of_entourage_subset U_V

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 76
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_mul_le_pow (L272-L284)
lemma coverMincard_mul_le_pow (F_inv : MapsTo T F F) [U.IsSymm] (m n : ℕ) :
    coverMincard T F (U ○ U) (m * n) ≤ coverMincard T F U m ^ n := by
rcases F.eq_empty_or_nonempty with rfl | F_nonempty
  · rw [coverMincard_empty]; exact zero_le _
  obtain rfl | hn := eq_or_ne n 0
  · rw [mul_zero, coverMincard_zero T F_nonempty (U ○ U), pow_zero]
  rcases eq_top_or_lt_top (coverMincard T F U m) with h | h
  · simp [*]
  · obtain ⟨s, s_cover, s_coverMincard⟩ := (coverMincard_finite_iff T F U m).1 h
    obtain ⟨t, t_cover, t_sn⟩ := s_cover.iterate_le_pow F_inv n
    rw [← s_coverMincard]
    exact t_cover.coverMincard_le_card.trans (WithTop.coe_le_coe.2 t_sn)
```

-- snippet 77
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.le_coverEntropyInfEntourage_image (L119-L122)
lemma le_coverEntropyInfEntourage_image (h : Semiconj φ S T) (F : Set X) [V.IsSymm] :
    coverEntropyInfEntourage S F ((map φ φ) ⁻¹' (V ○ V)) ≤ coverEntropyInfEntourage T (φ '' F) V :=
expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (le_coverMincard_image h F n)
```

-- snippet 78
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.le_coverEntropyEntourage_image (L115-L118)
lemma le_coverEntropyEntourage_image (h : Semiconj φ S T) (F : Set X) [V.IsSymm] :
    coverEntropyEntourage S F ((map φ φ) ⁻¹' (V ○ V)) ≤ coverEntropyEntourage T (φ '' F) V :=
expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (le_coverMincard_image h F n)
```

-- snippet 79
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_le_coverEntropyInf (L453-L457)
lemma coverEntropyInfEntourage_le_coverEntropyInf (T : X → X) (F : Set X)
    (h : U ∈ 𝓤 X) :
    coverEntropyInfEntourage T F U ≤ coverEntropyInf T F :=
le_iSup₂ (f := fun (U : SetRel X X) (_ : U ∈ 𝓤 X) ↦ coverEntropyInfEntourage T F U) U h
```

-- snippet 80
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_finite_iff (L222-L241)
lemma coverMincard_finite_iff (T : X → X) (F : Set X) (U : SetRel X X) (n : ℕ) :
    coverMincard T F U n < ⊤ ↔
    ∃ s : Finset X, IsDynCoverOf T F U n s ∧ s.card = coverMincard T F U n := by
refine ⟨fun h_fin ↦ ?_, fun ⟨s, _, s_coverMincard⟩ ↦ s_coverMincard ▸ WithTop.coe_lt_top s.card⟩
  obtain ⟨k, k_min⟩ := WithTop.ne_top_iff_exists.1 h_fin.ne
  rw [← k_min]
  simp only [ENat.some_eq_coe, Nat.cast_inj]
  have : Nonempty {s : Finset X // IsDynCoverOf T F U n s} := by
    by_contra h
    apply ENat.coe_ne_top k
    rw [← ENat.some_eq_coe, k_min, coverMincard, iInf₂_eq_top]
    simp only [ENat.coe_ne_top, imp_false]
    rw [nonempty_subtype, not_exists] at h
    exact h
  have key := ciInf_mem fun s : {s : Finset X // IsDynCoverOf T F U n s} ↦ (s.val.card : ℕ∞)
  rw [coverMincard, iInf_subtype'] at k_min
  rw [← k_min, mem_range, Subtype.exists] at key
  simp only [ENat.some_eq_coe, Nat.cast_inj, exists_prop] at key
  exact key
```

-- snippet 81
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_zero (L255-L263)
lemma coverMincard_zero (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    coverMincard T F U 0 = 1 := by
apply le_antisymm _ ((one_le_coverMincard_iff T F U 0).2 h)
  obtain ⟨x, _⟩ := h
  have := isDynCoverOf_zero T F U (singleton_nonempty x)
  rw [← Finset.coe_singleton] at this
  apply this.coverMincard_le_card.trans_eq
  rw [Finset.card_singleton, Nat.cast_one]
```

-- snippet 82
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage (L51-L53)
def dynEntourage (T : X → X) (U : SetRel X X) (n : ℕ) : SetRel X X :=
⋂ k < n, (map T T)^[k] ⁻¹' U
```

-- snippet 83
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyEntourage_image_le (L123-L126)
lemma coverEntropyEntourage_image_le (h : Semiconj φ S T) (F : Set X) (V : SetRel Y Y) :
    coverEntropyEntourage T (φ '' F) V ≤ coverEntropyEntourage S F ((map φ φ) ⁻¹' V) :=
expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_image_le h F V n)
```

-- snippet 84
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_monotone (L126-L129)
lemma dynEntourage_monotone (T : X → X) (n : ℕ) :
    Monotone (fun U : SetRel X X ↦ dynEntourage T U n) :=
fun _ _ h ↦ iInter₂_mono fun _ _ ↦ preimage_mono h
```

-- snippet 85
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_finite_of_isCompact_invariant (L296-L304)
lemma coverMincard_finite_of_isCompact_invariant [UniformSpace X] (F_comp : IsCompact F)
    (F_inv : MapsTo T F F) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    coverMincard T F U n < ⊤ := by
obtain ⟨s, s_cover⟩ := exists_isDynCoverOf_of_isCompact_invariant F_comp F_inv U_uni n
  exact s_cover.coverMincard_le_card.trans_lt (WithTop.coe_lt_top s.card)

/-- All dynamical balls of a minimal dynamical cover of `F` intersect `F`. This lemma is the key
  to relate Bowen-Dinaburg's definition of topological entropy with covers and their definition
  of topological entropy with nets. -/
```

-- snippet 86
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInf_nonneg (L489-L492)
lemma coverEntropyInf_nonneg (T : X → X) (h : F.Nonempty) : 0 ≤ coverEntropyInf T F :=
(coverEntropyInfEntourage_le_coverEntropyInf T F univ_mem).trans_eq'
    (coverEntropyInfEntourage_univ T h)
```

-- snippet 87
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_antitone (L341-L344)
lemma coverEntropyInfEntourage_antitone (T : X → X) (F : Set X) :
    Antitone fun U : SetRel X X ↦ coverEntropyInfEntourage T F U :=
fun _ _ U_V ↦ expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_antitone T F n U_V)
```

-- snippet 88
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.ball_dynEntourage_mem_nhds (L78-L86)
lemma ball_dynEntourage_mem_nhds [UniformSpace X] (h : Continuous T)
    (U_uni : U ∈ 𝓤 X) (n : ℕ) (x : X) :
    ball x (dynEntourage T U n) ∈ 𝓝 x := by
rw [dynEntourage_eq_inter_Ico T U n, ball_iInter, Filter.iInter_mem, Subtype.forall]
  intro k _
  simp only [map_iterate, _root_.ball_preimage]
  exact (h.iterate k).continuousAt.preimage_mem_nhds (ball_mem_nhds (T^[k] x) U_uni)

set_option linter.flexible false in -- simp followed by infer_instance
```

-- snippet 89
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_univ (L142-L144)
lemma dynEntourage_univ {T : X → X} {n : ℕ} :
    dynEntourage T univ n = univ := by simp [dynEntourage]
```

-- snippet 90
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.exists_isDynCoverOf_of_isCompact_uniformContinuous (L182-L190)
lemma exists_isDynCoverOf_of_isCompact_uniformContinuous [UniformSpace X]
    (F_comp : IsCompact F) (h : UniformContinuous T) (U_uni : U ∈ 𝓤 X) (n : ℕ) :
    ∃ s : Finset X, IsDynCoverOf T F U n s := by
obtain ⟨(V : SetRel X X), hV, hVsymm, hVU⟩ := symm_of_uniformity U_uni
  have uni_ite := dynEntourage_mem_uniformity h hV n
  let openCover x := ball x (dynEntourage T V n)
  obtain ⟨s, _, s_cover⟩ := F_comp.elim_nhds_subcover openCover fun x _ ↦ ball_mem_nhds x uni_ite
  exact ⟨s, .of_entourage_subset hVU <| .of_subset_iUnion_ball s_cover⟩
```

-- snippet 91
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_ball_dynEntourage_comp (L145-L151)
lemma mem_ball_dynEntourage_comp (T : X → X) (n : ℕ) {U : SetRel X X} [U.IsSymm]
    (x y : X) (h : (ball x (dynEntourage T U n) ∩ ball y (dynEntourage T U n)).Nonempty) :
    x ∈ ball y (dynEntourage T (U ○ U) n) := by
rcases h with ⟨z, z_Bx, z_By⟩
  rw [mem_ball_symmetry] at z_Bx
  exact dynEntourage_comp_subset T U U n (mem_ball_comp z_By z_Bx)
```

-- snippet 92
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropyInf_restrict_subset (L181-L187)
lemma coverEntropyInf_restrict_subset [UniformSpace X] {T : X → X} {F G : Set X} (hF : F ⊆ G)
    (hG : MapsTo T G G) :
    coverEntropyInf (hG.restrict T G G) (val ⁻¹' F) = coverEntropyInf T F := by
rw [← coverEntropyInf_image_of_comap _ hG.val_restrict_apply (val ⁻¹' F), image_preimage_coe G F,
    inter_eq_right.2 hF]

/-- The entropy of the restriction of `T` to an invariant set `F` is `coverEntropy T F`. This
```

-- snippet 93
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_empty (L359-L361)
lemma coverEntropyInfEntourage_empty : coverEntropyInfEntourage T ∅ U = ⊥ :=
eq_bot_mono (coverEntropyInfEntourage_le_coverEntropyEntourage T ∅ U) coverEntropyEntourage_empty
```

-- snippet 94
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_mono (L135-L137)
lemma dynEntourage_mono (hUV : U ⊆ V) (hmn : m ≤ n) : dynEntourage T U n ⊆ dynEntourage T V m :=
(dynEntourage_monotone _ _ hUV).trans (dynEntourage_antitone _ _ hmn)
```

-- snippet 95
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_image_of_comap (L133-L153)
theorem coverEntropy_image_of_comap (u : UniformSpace Y) {S : X → X} {T : Y → Y} {φ : X → Y}
    (h : Semiconj φ S T) (F : Set X) :
    coverEntropy T (φ '' F) = @coverEntropy X (comap φ u) S F := by
let : UniformSpace X := comap φ u
  apply le_antisymm
  · refine iSup₂_le fun V V_uni ↦
      (coverEntropyEntourage_antitone _ _ SetRel.symmetrize_subset_self).trans <|
      (coverEntropyEntourage_image_le h F _).trans ?_
    apply coverEntropyEntourage_le_coverEntropy
    rw [uniformity_comap φ, mem_comap]
    exact ⟨_, symmetrize_mem_uniformity V_uni, .rfl⟩
  · refine iSup₂_le fun U U_uni ↦ ?_
    simp only [uniformity_comap φ, mem_comap] at U_uni
    obtain ⟨V, V_uni, V_sub⟩ := U_uni
    obtain ⟨W, W_uni, W_symm, W_V⟩ := comp_symm_mem_uniformity_sets V_uni
    apply (coverEntropyEntourage_antitone S F ((preimage_mono W_V).trans V_sub)).trans
    apply (le_coverEntropyEntourage_image h F).trans
    exact coverEntropyEntourage_le_coverEntropy T (φ '' F) W_uni

/-- The entropy of `φ '' F` equals the entropy of `F` if `X` is endowed with the pullback by `φ`
  of the uniform structure of `Y`. This version uses a `liminf`. -/
```

-- snippet 96
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.mem_dynEntourage (L58-L60)
lemma mem_dynEntourage : (x, y) ∈ dynEntourage T U n ↔ ∀ k < n, (T^[k] x, T^[k] y) ∈ U := by
simp [dynEntourage]
```

-- snippet 97
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.IsDynCoverOf (L65-L71)
lemma IsDynCoverOf.image (h : Semiconj φ S T) (h' : IsDynCoverOf S F (map φ φ ⁻¹' V) n s) :
    IsDynCoverOf T (φ '' F) V n (φ '' s) := by
rintro _ ⟨x, hx, rfl⟩
  obtain ⟨y, hy, hxy⟩ := h' hx
  refine ⟨_, Set.mem_image_of_mem _ hy, show (x, y) ∈ map φ φ ⁻¹' dynEntourage T V n from ?_⟩
  rwa [h.preimage_dynEntourage V n]
```

-- snippet 98
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_le_coverEntropyEntourage (L349-L352)
lemma coverEntropyInfEntourage_le_coverEntropyEntourage (T : X → X) (F : Set X) (U : SetRel X X) :
    coverEntropyInfEntourage T F U ≤ coverEntropyEntourage T F U :=
expGrowthInf_le_expGrowthSup
```

-- snippet 99
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverMincard_univ (L264-L271)
lemma coverMincard_univ (T : X → X) (h : F.Nonempty) (n : ℕ) : coverMincard T F univ n = 1 := by
apply le_antisymm _ ((one_le_coverMincard_iff T F univ n).2 h)
  obtain ⟨x, _⟩ := h
  have := isDynCoverOf_univ T F n (singleton_nonempty x)
  rw [← Finset.coe_singleton] at this
  apply this.coverMincard_le_card.trans_eq
  rw [Finset.card_singleton, Nat.cast_one]
```

-- snippet 100
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyEntourage_univ (L376-L380)
lemma coverEntropyEntourage_univ (T : X → X) (h : F.Nonempty) :
    coverEntropyEntourage T F univ = 0 := by
rw [← expGrowthSup_const one_ne_zero one_ne_top, coverEntropyEntourage]
  simp only [coverMincard_univ T h, ENat.toENNReal_one]
```

-- snippet 101
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropyInfEntourage_nonneg (L362-L370)
lemma coverEntropyInfEntourage_nonneg (T : X → X) (h : F.Nonempty) (U : SetRel X X) :
    0 ≤ coverEntropyInfEntourage T F U := by
apply Monotone.expGrowthInf_nonneg
  · exact fun _ _ m_n ↦ ENat.toENNReal_mono (coverMincard_monotone_time T F U m_n)
  · rw [ne_eq, funext_iff.not, not_forall]
    use 0
    rw [coverMincard_zero T h U, Pi.zero_apply, ENat.toENNReal_one]
    exact one_ne_zero
```

-- snippet 102
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.dynEntourage_comp_subset (L111-L118)
lemma dynEntourage_comp_subset (T : X → X) (U V : SetRel X X) (n : ℕ) :
    (dynEntourage T U n) ○ (dynEntourage T V n) ⊆ dynEntourage T (U ○ V) n := by
simp only [dynEntourage, map_iterate, subset_iInter_iff]
  intro k k_n xy xy_comp
  simp only [SetRel.comp, mem_iInter, mem_preimage, map_apply, mem_setOf_eq] at xy_comp ⊢
  rcases xy_comp with ⟨z, hz1, hz2⟩
  exact mem_ball_comp (hz1 k k_n) (hz2 k k_n)
```

-- snippet 103
```lean
-- Mathlib.Dynamics.TopologicalEntropy.Semiconj.coverEntropy_image_le_of_uniformContinuous (L194-L201)
theorem coverEntropy_image_le_of_uniformContinuous [UniformSpace X] [UniformSpace Y] {S : X → X}
    {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) (h' : UniformContinuous φ) (F : Set X) :
    coverEntropy T (φ '' F) ≤ coverEntropy S F := by
rw [coverEntropy_image_of_comap _ h F]
  exact coverEntropy_antitone S F (uniformContinuous_iff.1 h')

/-- The entropy of `φ '' F` is at most the entropy of `F` if `φ` is uniformly continuous. This
  version uses a `liminf`. -/
```

-- snippet 104
```lean
-- Mathlib.Dynamics.TopologicalEntropy.DynamicalEntourage.idRel_subset_dynEntourage (L96-L101)
lemma idRel_subset_dynEntourage (T : X → X) {U : Set (X × X)} (h : idRel ⊆ U) (n : ℕ) :
    idRel ⊆ (dynEntourage T U n) := by
simp only [dynEntourage, map_iterate, subset_iInter_iff, idRel_subset, mem_preimage, map_apply]
  exact fun _ _ _ ↦ h rfl

set_option linter.deprecated false in
```

-- snippet 105
```lean
-- Mathlib.Dynamics.TopologicalEntropy.CoverEntropy.coverEntropy_empty (L482-L484)
lemma coverEntropy_empty : coverEntropy T ∅ = ⊥ := by
simp only [coverEntropy, coverEntropyEntourage_empty, iSup_bot]
```
[/INST]