-- Lean 4 proof step from Mathlib.MeasureTheory.Constructions.BorelSpace.Order (goal)
Goal:
α : Type u_1
δ : Type u_4
inst : TopologicalSpace α
mα : MeasurableSpace α
inst_1 : BorelSpace α
mδ : MeasurableSpace δ
inst_2 : ConditionallyCompleteLinearOrder α
inst_3 : OrderTopology α
inst_4 : SecondCountableTopology α
ι : Type u_5
ι' : Type u_6
f : ι → δ → α
v : Filter ι
hf : ∀ (i : ι), Measurable (f i)
p : ι' → Prop
s : ι' → Set ι
hv : v.HasCountableBasis p s
hs : ∀ (j : ι'), (s j).Countable
We We₁ We₂ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦ liminf (fun (x_1 : ι) ↦ f x_1 x) v
inl :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : IsEmpty.{max 1 (u_6 + 1)} (Subtype p)),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦ liminf (fun (x_1 : ι) ↦ f x_1 x) v
inr inr₁ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p)),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦ liminf (fun (x_1 : ι) ↦ f x_1 x) v
pos :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ∃ (j : Subtype p), s (↑j : ι') = ∅),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦ liminf (fun (x_1 : ι) ↦ f x_1 x) v
neg neg₁ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦ liminf (fun (x_1 : ι) ↦ f x_1 x) v
neg₂ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
      if ∀ (j : Subtype p), ¬BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x) then
        sSup ∅
      else
        ⨆ (j : Subtype p),
          ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
            f (↑i : ι) x
neg₃ neg₄ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
      if ∀ (j : Subtype p), ¬BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x) then
        sSup ∅
      else
        ⨆ (j : Subtype p),
          ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
            f (↑i : ι) x
neg₅ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j)),
      Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
        if ∀ (j : Subtype p), ¬BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x) then
          sSup ∅
        else
          ⨆ (j : Subtype p),
            ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
              f (↑i : ι) x
neg₆ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}),
      Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
        if ∀ (j : Subtype p), ¬BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x) then
          sSup ∅
        else
          ⨆ (j : Subtype p),
            ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
              f (↑i : ι) x
neg₇ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
        ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
          f (↑i : ι) x
neg₈ neg₉ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
        ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
          f (↑i : ι) x
neg₁₀ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      let F0 : Subtype p → δ → α := fun (j : Subtype p) (x : δ) ↦ ⨅ (i : (↑(s (↑j : ι')) : Type u_5)), f (↑i : ι) x;
      ∀ (F0_meas : ∀ (j : Subtype p), Measurable (F0 j)),
        Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦
          ⨅ (i : (↑(s (↑(liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (x_1 : ι) ↦ f x_1 x) s p j) : ι')) : Type u_5)),
            f (↑i : ι) x
neg₁₁ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      let reparam : δ → Subtype p → Subtype p := fun (x : δ) ↦
        liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (i : ι) ↦ f i x) s p;
      let F0 : Subtype p → δ → α := fun (j : Subtype p) (x : δ) ↦ ⨅ (i : (↑(s (↑j : ι')) : Type u_5)), f (↑i : ι) x;
      ∀ (F0_meas : ∀ (j : Subtype p), Measurable (F0 j)),
        let F1 : δ → α := fun (x : δ) ↦ F0 (reparam x j) x;
        ∀ (hF1 : F1 = fun (x : δ) ↦ F0 (reparam x j) x), Measurable F1
neg₁₂ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      let reparam : δ → Subtype p → Subtype p := fun (x : δ) ↦
        liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (i : ι) ↦ f i x) s p;
      let F0 : Subtype p → δ → α := fun (j : Subtype p) (x : δ) ↦ ⨅ (i : (↑(s (↑j : ι')) : Type u_5)), f (↑i : ι) x;
      ∀ (F0_meas : ∀ (j : Subtype p), Measurable (F0 j)),
        let F1 : δ → α := fun (x : δ) ↦ F0 (reparam x j) x;
        ∀ (hF1 : F1 = fun (x : δ) ↦ F0 (reparam x j) x), Measurable F1
neg₁₃ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      let reparam : δ → Subtype p → Subtype p := fun (x : δ) ↦
        liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (i : ι) ↦ f i x) s p;
      let F0 : Subtype p → δ → α := fun (j : Subtype p) (x : δ) ↦ ⨅ (i : (↑(s (↑j : ι')) : Type u_5)), f (↑i : ι) x;
      ∀ (F0_meas : ∀ (j : Subtype p), Measurable (F0 j)),
        let F1 : δ → α := fun (x : δ) ↦ F0 (reparam x j) x;
        ∀ (hF1 : F1 = fun (x : δ) ↦ F0 (reparam x j) x), Measurable F1
neg₁₄ :
  ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
    (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
    let m : Subtype p → Set δ := fun (j : Subtype p) ↦
      {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
    ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
      (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
      let reparam : δ → Subtype p → Subtype p := fun (x : δ) ↦
        liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (i : ι) ↦ f i x) s p;
      let F0 : Subtype p → δ → α := fun (j : Subtype p) (x : δ) ↦ ⨅ (i : (↑(s (↑j : ι')) : Type u_5)), f (↑i : ι) x;
      ∀ (F0_meas : ∀ (j : Subtype p), Measurable (F0 j)),
        let F1 : δ → α := fun (x : δ) ↦ F0 (reparam x j) x;
        ∀ (hF1 : F1 = fun (x : δ) ↦ F0 (reparam x j) x),
          let g : ℕ → Subtype p := Classical.choose (p := Function.Surjective) ⋯;
          ∀ (Z : ∀ (x : δ), ∃ (n : ℕ), x ∈ m (g n) ∨ ∀ (k : Subtype p), x ∉ m k), Measurable F1
⊢ Measurable.{u_4, u_1} (β := α) fun (x : δ) ↦ liminf (fun (x_1 : ι) ↦ f x_1 x) v
have neg₁₅ : ∀ (this : Countable.{max 1 (u_6 + 1)} (Subtype p)) (hp : Nonempty.{max 1 (u_6 + 1)} (Subtype p))
  (H : ¬∃ (j : Subtype p), s (↑j : ι') = ∅) (this_1 : ∀ (i : ι'), Countable.{u_5 + 1} (↑(s i) : Type u_5)),
  let m : Subtype p → Set δ := fun (j : Subtype p) ↦
    {x : δ | BddBelow.{u_1} (α := α) (range fun (i : (↑(s (↑j : ι')) : Type u_5)) ↦ f (↑i : ι) x)};
  ∀ (m_meas : ∀ (j : Subtype p), MeasurableSet (m j))
    (mc_meas : MeasurableSet.{u_4} (α := δ) {x : δ | ∀ (j : Subtype p), x ∉ m j}) (j : Subtype p),
    let reparam : δ → Subtype p → Subtype p := fun (x : δ) ↦
      liminf_reparam.{u_1, u_5, u_6} (α := α) (fun (i : ι) ↦ f i x) s p;
    let F0 : Subtype p → δ → α := fun (j : Subtype p) (x : δ) ↦ ⨅ (i : (↑(s (↑j : ι')) : Type u_5)), f (↑i : ι) x;
    ∀ (F0_meas : ∀ (j : Subtype p), Measurable (F0 j)),
      let F1 : δ → α := fun (x : δ) ↦ F0 (reparam x j) x;
      ∀ (hF1 : F1 = fun (x : δ) ↦ F0 (reparam x j) x),
        let g : ℕ → Subtype p := Classical.choose (p := Function.Surjective) sorry;
        ∀ (Z : ∀ (x : δ), ∃ (n : ℕ), x ∈ m (g n) ∨ ∀ (k : Subtype p), x ∉ m k)
          (this :
            F1 = fun (x : δ) ↦
              if x ∈ m j then F0 j x
              else F0 (g (Nat.find (p := fun (n : ℕ) ↦ x ∈ m (g n) ∨ ∀ (k : Subtype p), x ∉ m k) sorry)) x),
          Measurable F1
Tactic: classical
  /- We would like to write the liminf as `⨆ (j : Subtype p), ⨅ (i : s j), f i x`, as the
  measurability would follow from the measurability of infs and sups. Unfortunately, this is not
  true in general conditionally complete linear orders because of issues with empty sets or sets
  which are not bounded above or below. A slightly more complicated expression for the liminf,
  valid in general, is given in `Filter.HasBasis.liminf_eq_ite`. This expression, built from
  `if ... then ... else` and infs and sups, can be readily checked to be measurable. -/
  have : Countable (Subtype p) := hv.countable
  rcases isEmpty_or_nonempty (Subtype p) with hp | hp
  · simp [hv.liminf_eq_sSup_iUnion_iInter]
  by_cases H : ∃ (j : Subtype p), s j = ∅
  · simp_rw [hv.liminf_eq_ite, if_pos H, measurable_const]
  simp_rw [hv.liminf_eq_ite, if_neg H]
  have : ∀ i, Countable (s i) := fun i ↦ countable_coe_iff.2 (hs i)
  let m : Subtype p → Set δ := fun j ↦ {x | BddBelow (range (fun (i : s j) ↦ f i x))}
  have m_meas : ∀ j, MeasurableSet (m j) :=
    fun j ↦ measurableSet_bddBelow_range (fun (i : s j) ↦ hf i)
  have mc_meas : MeasurableSet {x | ∀ (j : Subtype p), x ∉ m j} := by
    rw [setOf_forall]
    exact MeasurableSet.iInter (fun j ↦ (m_meas j).compl)
  refine measurable_const.piecewise mc_meas <| .iSup fun j ↦ ?_
  let reparam : δ → Subtype p → Subtype p := fun x ↦ liminf_reparam (fun i ↦ f i x) s p
  let F0 : Subtype p → δ → α := fun j x ↦ ⨅ (i : s j), f i x
  have F0_meas : ∀ j, Measurable (F0 j) := fun j ↦ .iInf (fun (i : s j) ↦ hf i)
  set F1 : δ → α := fun x ↦ F0 (reparam x j) x with hF1
  change Measurable F1
  let g : ℕ → Subtype p := Classical.choose (exists_surjective_nat (Subtype p))
  have Z : ∀ x, ∃ n, x ∈ m (g n) ∨ ∀ k, x ∉ m k := by
    intro x
    by_cases! H : ∃ k, x ∈ m k
    · rcases H with ⟨k, hk⟩
      rcases Classical.choose_spec (exists_surjective_nat (Subtype p)) k with ⟨n, rfl⟩
      exact ⟨n, Or.inl hk⟩
    · exact ⟨0, Or.inr H⟩
  have : F1 = fun x ↦ if x ∈ m j then F0 j x else F0 (g (Nat.find (Z x))) x := by
    ext x
    have A : reparam x j = if x ∈ m j then j else g (Nat.find (Z x)) := rfl
    split_ifs with hjx
    · have : reparam x j = j := by rw [A, if_pos hjx]
      simp only [hF1, this]
    · have : reparam x j = g (Nat.find (Z x)) := by rw [A, if_neg hjx]
      simp only [hF1, this]
  rw [this]
  apply Measurable.piecewise (m_meas j) (F0_meas j)
  apply Measurable.find (fun n ↦ F0_meas (g n)) (fun n ↦ ?_)
  exact (m_meas (g n)).union mc_meas