-- Mathlib/Dynamics/Ergodic/Conservative.lean
theorem measure_mem_forall_ge_image_not_mem_eq_zero (hf : Conservative f μ)
    (hs : NullMeasurableSet s μ) (n : ℕ) :
    μ ({ x ∈ s | ∀ m ≥ n, f^[m] x ∉ s }) = 0

Proof state:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
⊢ μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0

Tactic:
by_contra H

Result:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
⊢ False

Proof state:
case intro.intro
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
this : NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ
m : ℕ
hmn : m > n
hm : μ (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s} ∩ f^[m] ⁻¹' (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s})) ≠ 0
⊢ False

Tactic:
rcases nonempty_of_measure_ne_zero hm with ⟨x, ⟨_, hxn⟩, hxm, -⟩

Result:
case intro.intro.intro.intro.intro.intro
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
this : NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ
m : ℕ
hmn : m > n
hm : μ (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s} ∩ f^[m] ⁻¹' (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s})) ≠ 0
x : α
left✝ : x ∈ s
hxn : x ∈ {x | ∀ m ≥ n, f^[m] x ∉ s}
hxm : f^[m] x ∈ s
⊢ False

Proof state:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
⊢ NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ

Tactic:
simp only [setOf_forall, ← compl_setOf]

Result:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
⊢ NullMeasurableSet (s ∩ ⋂ i, ⋂ (_ : i ≥ n), {a | f^[i] a ∈ s}ᶜ) μ

Proof state:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
⊢ NullMeasurableSet (s ∩ ⋂ i, ⋂ (_ : i ≥ n), {a | f^[i] a ∈ s}ᶜ) μ

Tactic:
exact hs.inter <| .biInter (to_countable _) fun m _ ↦
  (hs.preimage <| hf.toQuasiMeasurePreserving.iterate m).compl

Result:
no goals

Proof state:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
this : NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ
⊢ False

Tactic:
rcases (hf.exists_gt_measure_inter_ne_zero this H) n with ⟨m, hmn, hm⟩

Result:
case intro.intro
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
this : NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ
m : ℕ
hmn : m > n
hm : μ (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s} ∩ f^[m] ⁻¹' (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s})) ≠ 0
⊢ False

Proof state:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
⊢ False

Tactic:
have : NullMeasurableSet (s ∩ { x | ∀ m ≥ n, f^[m] x ∉ s }) μ := by
  simp only [setOf_forall, ← compl_setOf]
  exact hs.inter <| .biInter (to_countable _) fun m _ ↦
    (hs.preimage <| hf.toQuasiMeasurePreserving.iterate m).compl

Result:
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
this : NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ
⊢ False

Proof state:
case intro.intro.intro.intro.intro.intro
α : Type u_1
inst✝ : MeasurableSpace α
f : α → α
s : Set α
μ : Measure α
hf : Conservative f μ
hs : NullMeasurableSet s μ
n : ℕ
H : ¬μ {x | x ∈ s ∧ ∀ m ≥ n, f^[m] x ∉ s} = 0
this : NullMeasurableSet (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s}) μ
m : ℕ
hmn : m > n
hm : μ (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s} ∩ f^[m] ⁻¹' (s ∩ {x | ∀ m ≥ n, f^[m] x ∉ s})) ≠ 0
x : α
left✝ : x ∈ s
hxn : x ∈ {x | ∀ m ≥ n, f^[m] x ∉ s}
hxm : f^[m] x ∈ s
⊢ False

Tactic:
exact hxn m hmn.lt.le hxm

Result:
no goals