l3lab/ntp-mathlib huggingface dataset:
/-- Let `f : α → α` be a (pre)ergodic map.
Let `g : α → X` be a measurable function from `α` to a nonempty measurable space
with a countable family of measurable sets separating the points of `X`.
If `g` is invariant under `f`, then `g` is a.e. constant. -/
theorem PreErgodic.ae_eq_const_of_ae_eq_comp (h : PreErgodic f μ) (hgm : Measurable g)
    (hg_eq : g ∘ f = g) : ∃ c, g =ᵐ[μ] const α c :=
  exists_eventuallyEq_const_of_forall_separating MeasurableSet fun U hU ↦
    h.ae_mem_or_ae_nmem (s := g ⁻¹' U) (hgm hU) <| by 

Proof state:
α : Type u_1
X : Type u_2
inst✝³ : MeasurableSpace α
μ : Measure α
inst✝² : Nonempty X
inst✝¹ : MeasurableSpace X
inst✝ : HasCountableSeparatingOn X MeasurableSet univ
f : α → α
g : α → X
h : PreErgodic f
hgm : Measurable g
hg_eq : g ∘ f = g
U : Set X
hU : MeasurableSet U
⊢ f ⁻¹' (g ⁻¹' U) = g ⁻¹' U

Next tactic:
rw [← preimage_comp, hg_eq]
/-- Let `f : α → α` be a quasi ergodic map.
Let `g : α → X` be an a.e. strongly measurable function
from `α` to a nonempty metrizable topological space.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem ae_eq_const_of_ae_eq_comp_ae {g : α → X} (h : QuasiErgodic f μ)
    (hgm : AEStronglyMeasurable g μ) (hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c := by
  

Proof state:
α : Type u_1
X : Type u_2
inst✝³ : MeasurableSpace α
μ : Measure α
inst✝² : TopologicalSpace X
inst✝¹ : MetrizableSpace X
inst✝ : Nonempty X
f : α → α
g : α → X
h : QuasiErgodic f
hgm : AEStronglyMeasurable g μ
hg_eq : g ∘ f =ᵐ[μ] g
⊢ ∃ c, g =ᵐ[μ] const α c

Next tactic:
borelize X
/-- Let `f : α → α` be a quasi ergodic map.
Let `g : α → X` be an a.e. strongly measurable function
from `α` to a nonempty metrizable topological space.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem ae_eq_const_of_ae_eq_comp_ae {g : α → X} (h : QuasiErgodic f μ)
    (hgm : AEStronglyMeasurable g μ) (hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c := by
  borelize X
  

Proof state:
α : Type u_1
X : Type u_2
inst✝³ : MeasurableSpace α
μ : Measure α
inst✝² : TopologicalSpace X
inst✝¹ : MetrizableSpace X
inst✝ : Nonempty X
f : α → α
g : α → X
h : QuasiErgodic f
hgm : AEStronglyMeasurable g μ
hg_eq : g ∘ f =ᵐ[μ] g
this✝¹ : MeasurableSpace X := borel X
this✝ : BorelSpace X
⊢ ∃ c, g =ᵐ[μ] const α c

Next tactic:
rcases hgm.isSeparable_ae_range with ⟨t, ht, hgt⟩
/-- Let `f : α → α` be a quasi ergodic map.
Let `g : α → X` be an a.e. strongly measurable function
from `α` to a nonempty metrizable topological space.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem ae_eq_const_of_ae_eq_comp_ae {g : α → X} (h : QuasiErgodic f μ)
    (hgm : AEStronglyMeasurable g μ) (hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c := by
  borelize X
  rcases hgm.isSeparable_ae_range with ⟨t, ht, hgt⟩
  

Proof state:
case intro.intro
α : Type u_1
X : Type u_2
inst✝³ : MeasurableSpace α
μ : Measure α
inst✝² : TopologicalSpace X
inst✝¹ : MetrizableSpace X
inst✝ : Nonempty X
f : α → α
g : α → X
h : QuasiErgodic f
hgm : AEStronglyMeasurable g μ
hg_eq : g ∘ f =ᵐ[μ] g
this✝¹ : MeasurableSpace X := borel X
this✝ : BorelSpace X
t : Set X
ht : IsSeparable t
hgt : ∀ᵐ (x : α) ∂μ, g x ∈ t
⊢ ∃ c, g =ᵐ[μ] const α c

Next tactic:
haveI := ht.secondCountableTopology
/-- Let `f : α → α` be a quasi ergodic map.
Let `g : α → X` be an a.e. strongly measurable function
from `α` to a nonempty metrizable topological space.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem ae_eq_const_of_ae_eq_comp_ae {g : α → X} (h : QuasiErgodic f μ)
    (hgm : AEStronglyMeasurable g μ) (hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c := by
  borelize X
  rcases hgm.isSeparable_ae_range with ⟨t, ht, hgt⟩
  haveI := ht.secondCountableTopology
  

Proof state:
case intro.intro
α : Type u_1
X : Type u_2
inst✝³ : MeasurableSpace α
μ : Measure α
inst✝² : TopologicalSpace X
inst✝¹ : MetrizableSpace X
inst✝ : Nonempty X
f : α → α
g : α → X
h : QuasiErgodic f
hgm : AEStronglyMeasurable g μ
hg_eq : g ∘ f =ᵐ[μ] g
this✝¹ : MeasurableSpace X := borel X
this✝ : BorelSpace X
t : Set X
ht : IsSeparable t
hgt : ∀ᵐ (x : α) ∂μ, g x ∈ t
this : SecondCountableTopology ↑t
⊢ ∃ c, g =ᵐ[μ] const α c

Next tactic:
exact h.ae_eq_const_of_ae_eq_comp_of_ae_range₀ hgt hgm.aemeasurable.nullMeasurable hg_eq
@[simp]
theorem maximals_singleton : maximals r {a} = {a} :=
  (maximals_subset _ _).antisymm <|
    singleton_subset_iff.2 <|
      ⟨rfl, by
        

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
⊢ ∀ ⦃b : α⦄, b ∈ {a} → r a b → r b a

Next tactic:
rintro b (rfl : b = a)
@[simp]
theorem maximals_singleton : maximals r {a} = {a} :=
  (maximals_subset _ _).antisymm <|
    singleton_subset_iff.2 <|
      ⟨rfl, by
        rintro b (rfl : b = a)
        

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
b✝ b : α
⊢ r b b → r b b

Next tactic:
exact id
theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝ : IsAntisymm α r
x : α
⊢ x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y : α⦄, y ∈ s → r x y → x = y

Next tactic:
simp only [maximals, Set.mem_sep_iff, and_congr_right_iff]
theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by
  simp only [maximals, Set.mem_sep_iff, and_congr_right_iff]
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝ : IsAntisymm α r
x : α
⊢ x ∈ s → ((∀ ⦃b : α⦄, b ∈ s → r x b → r b x) ↔ ∀ ⦃y : α⦄, y ∈ s → r x y → x = y)

Next tactic:
refine' fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ _⟩
theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by
  simp only [maximals, Set.mem_sep_iff, and_congr_right_iff]
  refine' fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ _⟩
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝ : IsAntisymm α r
x : α
x✝ : x ∈ s
h : ∀ ⦃y : α⦄, y ∈ s → r x y → x = y
y : α
hys : y ∈ s
hxy : r x y
⊢ r y x

Next tactic:
convert hxy
theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by
  simp only [maximals, Set.mem_sep_iff, and_congr_right_iff]
  refine' fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ _⟩
  convert hxy <;> 

Proof state:
case h.e'_1
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝ : IsAntisymm α r
x : α
x✝ : x ∈ s
h : ∀ ⦃y : α⦄, y ∈ s → r x y → x = y
y : α
hys : y ∈ s
hxy : r x y
⊢ y = x

Next tactic:
rw [h hys hxy]
theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by
  simp only [maximals, Set.mem_sep_iff, and_congr_right_iff]
  refine' fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ _⟩
  convert hxy <;> 

Proof state:
case h.e'_2
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝ : IsAntisymm α r
x : α
x✝ : x ∈ s
h : ∀ ⦃y : α⦄, y ∈ s → r x y → x = y
y : α
hys : y ∈ s
hxy : r x y
⊢ x = y

Next tactic:
rw [h hys hxy]
/-- This theorem can't be used to rewrite without specifying `rlt`, since `rlt` would have to be
  guessed. See `mem_minimals_iff_forall_ssubset_not_mem` and `mem_minimals_iff_forall_lt_not_mem`
  for `⊆` and `≤` versions.  -/
theorem mem_minimals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] :
    x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt y x → y ∉ s := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝¹ : IsAntisymm α r
x : α
rlt : α → α → Prop
inst✝ : IsNonstrictStrictOrder α r rlt
⊢ x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y : α⦄, rlt y x → y ∉ s

Next tactic:
simp [minimals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)]
theorem mem_maximals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] :
    x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt x y → y ∉ s := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝¹ : IsAntisymm α r
x : α
rlt : α → α → Prop
inst✝ : IsNonstrictStrictOrder α r rlt
⊢ x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y : α⦄, rlt x y → y ∉ s

Next tactic:
simp [maximals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)]
theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s)
    (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝¹ : IsAntisymm α r
inst✝ : IsTrans α r
hts : t ⊆ s
h : ∀ x ∈ s, ∃ y ∈ t, r y x
⊢ minimals r s = minimals r t

Next tactic:
refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩,
    fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩
theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s)
    (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by
  refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩,
    fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩
  · 

Proof state:
case refine_1
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
inst✝¹ : IsAntisymm α r
inst✝ : IsTrans α r
hts : t ⊆ s
h : ∀ x ∈ s, ∃ y ∈ t, r y x
a : α
x✝ : a ∈ minimals r s
has : a ∈ s
hmin : ∀ ⦃b : α⦄, b ∈ s → r b a → r a b
⊢ a ∈ t

Next tactic:
obtain ⟨a', ha', haa'⟩ := h _ has
theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s)
    (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by
  refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩,
    fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩
  · obtain ⟨a', ha', haa'⟩ := h _ has
    

Proof state:
case refine_1.intro.intro
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
inst✝¹ : IsAntisymm α r
inst✝ : IsTrans α r
hts : t ⊆ s
h : ∀ x ∈ s, ∃ y ∈ t, r y x
a : α
x✝ : a ∈ minimals r s
has : a ∈ s
hmin : ∀ ⦃b : α⦄, b ∈ s → r b a → r a b
a' : α
ha' : a' ∈ t
haa' : r a' a
⊢ a ∈ t

Next tactic:
rwa [antisymm (hmin (hts ha') haa') haa']
theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s)
    (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by
  refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩,
    fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩
  · obtain ⟨a', ha', haa'⟩ := h _ has
    rwa [antisymm (hmin (hts ha') haa') haa']
  

Proof state:
case refine_2
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝¹ : IsAntisymm α r
inst✝ : IsTrans α r
hts : t ⊆ s
h : ∀ x ∈ s, ∃ y ∈ t, r y x
a : α
x✝ : a ∈ minimals r t
hat : a ∈ t
hmin : ∀ ⦃b : α⦄, b ∈ t → r b a → r a b
b : α
hbs : b ∈ s
hba : r b a
⊢ r a b

Next tactic:
obtain ⟨b', hb't, hb'b⟩ := h b hbs
theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s)
    (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by
  refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩,
    fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩
  · obtain ⟨a', ha', haa'⟩ := h _ has
    rwa [antisymm (hmin (hts ha') haa') haa']
  obtain ⟨b', hb't, hb'b⟩ := h b hbs
  

Proof state:
case refine_2.intro.intro
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝¹ : IsAntisymm α r
inst✝ : IsTrans α r
hts : t ⊆ s
h : ∀ x ∈ s, ∃ y ∈ t, r y x
a : α
x✝ : a ∈ minimals r t
hat : a ∈ t
hmin : ∀ ⦃b : α⦄, b ∈ t → r b a → r a b
b : α
hbs : b ∈ s
hba : r b a
b' : α
hb't : b' ∈ t
hb'b : r b' b
⊢ r a b

Next tactic:
rwa [antisymm (hmin hb't (Trans.trans hb'b hba)) (Trans.trans hb'b hba)]
theorem maximals_eq_minimals [IsSymm α r] : maximals r s = minimals r s := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
inst✝ : IsSymm α r
⊢ maximals r s = minimals r s

Next tactic:
rw [minimals_of_symm, maximals_of_symm]
theorem Set.Subsingleton.maximals_eq (h : s.Subsingleton) : maximals r s = s := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
h : Set.Subsingleton s
⊢ maximals r s = s

Next tactic:
rcases h.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩)
theorem Set.Subsingleton.maximals_eq (h : s.Subsingleton) : maximals r s = s := by
  rcases h.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩)
  

Proof state:
case inl
α : Type u_1
r r₁ r₂ : α → α → Prop
t : Set α
a b : α
h : Set.Subsingleton ∅
⊢ maximals r ∅ = ∅
case inr.intro α : Type u_1 r r₁ r₂ : α → α → Prop t : Set α a b x : α h : Set.Subsingleton {x} ⊢ maximals r {x} = {x}

Next tactic:
exacts [minimals_empty _, maximals_singleton _ _]
theorem maximals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) :
    maximals r₂ s ⊆ maximals r₁ s := fun a ha =>
  ⟨ha.1, fun b hb hab => by
    

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝ : IsAntisymm α r₂
h : ∀ (a b : α), r₁ a b → r₂ a b
a : α
ha : a ∈ maximals r₂ s
b : α
hb : b ∈ s
hab : r₁ a b
⊢ r₁ b a

Next tactic:
have := eq_of_mem_maximals ha hb (h _ _ hab)
theorem maximals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) :
    maximals r₂ s ⊆ maximals r₁ s := fun a ha =>
  ⟨ha.1, fun b hb hab => by
    have := eq_of_mem_maximals ha hb (h _ _ hab)
    

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝ : IsAntisymm α r₂
h : ∀ (a b : α), r₁ a b → r₂ a b
a : α
ha : a ∈ maximals r₂ s
b : α
hb : b ∈ s
hab : r₁ a b
this : a = b
⊢ r₁ b a

Next tactic:
subst this
theorem maximals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) :
    maximals r₂ s ⊆ maximals r₁ s := fun a ha =>
  ⟨ha.1, fun b hb hab => by
    have := eq_of_mem_maximals ha hb (h _ _ hab)
    subst this
    

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
inst✝ : IsAntisymm α r₂
h : ∀ (a b : α), r₁ a b → r₂ a b
a : α
ha : a ∈ maximals r₂ s
hb : a ∈ s
hab : r₁ a a
⊢ r₁ a a

Next tactic:
exact hab
theorem minimals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) :
    minimals r₂ s ⊆ minimals r₁ s := fun a ha =>
  ⟨ha.1, fun b hb hab => by
    

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝ : IsAntisymm α r₂
h : ∀ (a b : α), r₁ a b → r₂ a b
a : α
ha : a ∈ minimals r₂ s
b : α
hb : b ∈ s
hab : r₁ b a
⊢ r₁ a b

Next tactic:
have := eq_of_mem_minimals ha hb (h _ _ hab)
theorem minimals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) :
    minimals r₂ s ⊆ minimals r₁ s := fun a ha =>
  ⟨ha.1, fun b hb hab => by
    have := eq_of_mem_minimals ha hb (h _ _ hab)
    

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝ : IsAntisymm α r₂
h : ∀ (a b : α), r₁ a b → r₂ a b
a : α
ha : a ∈ minimals r₂ s
b : α
hb : b ∈ s
hab : r₁ b a
this : a = b
⊢ r₁ a b

Next tactic:
subst this
theorem minimals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) :
    minimals r₂ s ⊆ minimals r₁ s := fun a ha =>
  ⟨ha.1, fun b hb hab => by
    have := eq_of_mem_minimals ha hb (h _ _ hab)
    subst this
    

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
inst✝ : IsAntisymm α r₂
h : ∀ (a b : α), r₁ a b → r₂ a b
a : α
ha : a ∈ minimals r₂ s
hb : a ∈ s
hab : r₁ a a
⊢ r₁ a a

Next tactic:
exact hab
theorem maximals_union : maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
⊢ maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t

Next tactic:
intro a ha
theorem maximals_union : maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t := by
  intro a ha
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b a : α
ha : a ∈ maximals r (s ∪ t)
⊢ a ∈ maximals r s ∪ maximals r t

Next tactic:
obtain h | h := ha.1
theorem maximals_union : maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t := by
  intro a ha
  obtain h | h := ha.1
  · 

Proof state:
case inl
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b a : α
ha : a ∈ maximals r (s ∪ t)
h : a ∈ s
⊢ a ∈ maximals r s ∪ maximals r t

Next tactic:
exact Or.inl ⟨h, fun b hb => ha.2 <| Or.inl hb⟩
theorem maximals_union : maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t := by
  intro a ha
  obtain h | h := ha.1
  · exact Or.inl ⟨h, fun b hb => ha.2 <| Or.inl hb⟩
  · 

Proof state:
case inr
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b a : α
ha : a ∈ maximals r (s ∪ t)
h : a ∈ t
⊢ a ∈ maximals r s ∪ maximals r t

Next tactic:
exact Or.inr ⟨h, fun b hb => ha.2 <| Or.inr hb⟩
theorem IsAntichain.maximals_eq (h : IsAntichain r s) : maximals r s = s :=
  (maximals_subset _ _).antisymm fun a ha =>
    ⟨ha, fun b hb hab => by
      

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
h : IsAntichain r s
a : α
ha : a ∈ s
b : α
hb : b ∈ s
hab : r a b
⊢ r b a

Next tactic:
obtain rfl := h.eq ha hb hab
theorem IsAntichain.maximals_eq (h : IsAntichain r s) : maximals r s = s :=
  (maximals_subset _ _).antisymm fun a ha =>
    ⟨ha, fun b hb hab => by
      obtain rfl := h.eq ha hb hab
      

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
h : IsAntichain r s
a : α
ha hb : a ∈ s
hab : r a a
⊢ r a a

Next tactic:
exact hab
/-- If `maximals r s` is included in but *shadows* the antichain `t`, then it is actually
equal to `t`. -/
theorem IsAntichain.max_maximals (ht : IsAntichain r t) (h : maximals r s ⊆ t)
    (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ maximals r s, r b a) : maximals r s = t := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
ht : IsAntichain r t
h : maximals r s ⊆ t
hs : ∀ ⦃a : α⦄, a ∈ t → ∃ b ∈ maximals r s, r b a
⊢ maximals r s = t

Next tactic:
refine' h.antisymm fun a ha => _
/-- If `maximals r s` is included in but *shadows* the antichain `t`, then it is actually
equal to `t`. -/
theorem IsAntichain.max_maximals (ht : IsAntichain r t) (h : maximals r s ⊆ t)
    (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ maximals r s, r b a) : maximals r s = t := by
  refine' h.antisymm fun a ha => _
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
ht : IsAntichain r t
h : maximals r s ⊆ t
hs : ∀ ⦃a : α⦄, a ∈ t → ∃ b ∈ maximals r s, r b a
a : α
ha : a ∈ t
⊢ a ∈ maximals r s

Next tactic:
obtain ⟨b, hb, hr⟩ := hs ha
/-- If `maximals r s` is included in but *shadows* the antichain `t`, then it is actually
equal to `t`. -/
theorem IsAntichain.max_maximals (ht : IsAntichain r t) (h : maximals r s ⊆ t)
    (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ maximals r s, r b a) : maximals r s = t := by
  refine' h.antisymm fun a ha => _
  obtain ⟨b, hb, hr⟩ := hs ha
  

Proof state:
case intro.intro
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
ht : IsAntichain r t
h : maximals r s ⊆ t
hs : ∀ ⦃a : α⦄, a ∈ t → ∃ b ∈ maximals r s, r b a
a : α
ha : a ∈ t
b : α
hb : b ∈ maximals r s
hr : r b a
⊢ a ∈ maximals r s

Next tactic:
rwa [of_not_not fun hab => ht (h hb) ha (Ne.symm hab) hr]
/-- If `minimals r s` is included in but *shadows* the antichain `t`, then it is actually
equal to `t`. -/
theorem IsAntichain.max_minimals (ht : IsAntichain r t) (h : minimals r s ⊆ t)
    (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ minimals r s, r a b) : minimals r s = t := by
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a b : α
ht : IsAntichain r t
h : minimals r s ⊆ t
hs : ∀ ⦃a : α⦄, a ∈ t → ∃ b ∈ minimals r s, r a b
⊢ minimals r s = t

Next tactic:
refine' h.antisymm fun a ha => _
/-- If `minimals r s` is included in but *shadows* the antichain `t`, then it is actually
equal to `t`. -/
theorem IsAntichain.max_minimals (ht : IsAntichain r t) (h : minimals r s ⊆ t)
    (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ minimals r s, r a b) : minimals r s = t := by
  refine' h.antisymm fun a ha => _
  

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b : α
ht : IsAntichain r t
h : minimals r s ⊆ t
hs : ∀ ⦃a : α⦄, a ∈ t → ∃ b ∈ minimals r s, r a b
a : α
ha : a ∈ t
⊢ a ∈ minimals r s

Next tactic:
obtain ⟨b, hb, hr⟩ := hs ha
/-- If `minimals r s` is included in but *shadows* the antichain `t`, then it is actually
equal to `t`. -/
theorem IsAntichain.max_minimals (ht : IsAntichain r t) (h : minimals r s ⊆ t)
    (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ minimals r s, r a b) : minimals r s = t := by
  refine' h.antisymm fun a ha => _
  obtain ⟨b, hb, hr⟩ := hs ha
  

Proof state:
case intro.intro
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
ht : IsAntichain r t
h : minimals r s ⊆ t
hs : ∀ ⦃a : α⦄, a ∈ t → ∃ b ∈ minimals r s, r a b
a : α
ha : a ∈ t
b : α
hb : b ∈ minimals r s
hr : r a b
⊢ a ∈ minimals r s

Next tactic:
rwa [of_not_not fun hab => ht ha (h hb) hab hr]
theorem IsAntichain.minimals_upperClosure (hs : IsAntichain (· ≤ ·) s) :
    minimals (· ≤ ·) (upperClosure s : Set α) = s :=
  hs.max_minimals
    (fun a ⟨⟨b, hb, hba⟩, _⟩ => by 

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝ : PartialOrder α
hs : IsAntichain (fun x x_1 => x ≤ x_1) s
a : α
x✝ : a ∈ minimals (fun x x_1 => x ≤ x_1) ↑(upperClosure s)
b : α
hb : b ∈ s
hba : b ≤ a
right✝ : ∀ ⦃b : α⦄, b ∈ ↑(upperClosure s) → (fun x x_1 => x ≤ x_1) b a → (fun x x_1 => x ≤ x_1) a b
⊢ a ∈ s

Next tactic:
rwa [eq_of_mem_minimals ‹a ∈ _› (subset_upperClosure hb) hba]
theorem IsAntichain.minimals_upperClosure (hs : IsAntichain (· ≤ ·) s) :
    minimals (· ≤ ·) (upperClosure s : Set α) = s :=
  hs.max_minimals
    (fun a ⟨⟨b, hb, hba⟩, _⟩ => by rwa [eq_of_mem_minimals ‹a ∈ _› (subset_upperClosure hb) hba])
    fun a ha =>
    ⟨a, ⟨subset_upperClosure ha, fun b ⟨c, hc, hcb⟩ hba => by 

Proof state:
α : Type u_1
r r₁ r₂ : α → α → Prop
s t : Set α
a✝ b✝ : α
inst✝ : PartialOrder α
hs : IsAntichain (fun x x_1 => x ≤ x_1) s
a : α
ha : a ∈ s
b : α
x✝ : b ∈ ↑(upperClosure s)
hba : (fun x x_1 => x ≤ x_1) b a
c : α
hc : c ∈ s
hcb : c ≤ b
⊢ (fun x x_1 => x ≤ x_1) a b

Next tactic:
rwa [hs.eq' ha hc (hcb.trans hba)]
theorem minimals_image_of_rel_iff_rel (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) :
    minimals s (f '' x) = f '' (minimals r x) := by
  

Proof state:
β : Type u_2
α : Type u_1
r✝ r₁ r₂ : α → α → Prop
s✝ t : Set α
a b : α
inst✝ : PartialOrder α
f : α → β
r : α → α → Prop
s : β → β → Prop
x : Set α
hf : ∀ ⦃a a' : α⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))
⊢ minimals s (f '' x) = f '' minimals r x

Next tactic:
ext a
theorem minimals_image_of_rel_iff_rel (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) :
    minimals s (f '' x) = f '' (minimals r x) := by
  ext a
  

Proof state:
case h
β : Type u_2
α : Type u_1
r✝ r₁ r₂ : α → α → Prop
s✝ t : Set α
a✝ b : α
inst✝ : PartialOrder α
f : α → β
r : α → α → Prop
s : β → β → Prop
x : Set α
hf : ∀ ⦃a a' : α⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))
a : β
⊢ a ∈ minimals s (f '' x) ↔ a ∈ f '' minimals r x

Next tactic:
simp only [minimals, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
theorem minimals_image_of_rel_iff_rel (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) :
    minimals s (f '' x) = f '' (minimals r x) := by
  ext a
  simp only [minimals, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
  

Proof state:
case h
β : Type u_2
α : Type u_1
r✝ r₁ r₂ : α → α → Prop
s✝ t : Set α
a✝ b : α
inst✝ : PartialOrder α
f : α → β
r : α → α → Prop
s : β → β → Prop
x : Set α
hf : ∀ ⦃a a' : α⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))
a : β
⊢ a ∈ {a | (∃ x_1 ∈ x, f x_1 = a) ∧ ∀ a_1 ∈ x, s (f a_1) a → s a (f a_1)} ↔
    ∃ x_1 ∈ {a | a ∈ x ∧ ∀ ⦃b : α⦄, b ∈ x → r b a → r a b}, f x_1 = a

Next tactic:
constructor
theorem minimals_image_of_rel_iff_rel (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) :
    minimals s (f '' x) = f '' (minimals r x) := by
  ext a
  simp only [minimals, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
  constructor
  · 

Proof state:
case h.mp
β : Type u_2
α : Type u_1
r✝ r₁ r₂ : α → α → Prop
s✝ t : Set α
a✝ b : α
inst✝ : PartialOrder α
f : α → β
r : α → α → Prop
s : β → β → Prop
x : Set α
hf : ∀ ⦃a a' : α⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))
a : β
⊢ a ∈ {a | (∃ x_1 ∈ x, f x_1 = a) ∧ ∀ a_1 ∈ x, s (f a_1) a → s a (f a_1)} →
    ∃ x_1 ∈ {a | a ∈ x ∧ ∀ ⦃b : α⦄, b ∈ x → r b a → r a b}, f x_1 = a

Next tactic:
rintro ⟨⟨a, ha, rfl⟩ , h⟩