l3lab/ntp-mathlib huggingface dataset:
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · 

Proof state:
case h
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
⊢ ↑0 '' (↑f ⁻¹' {x}) ⊆ {0}

Next tactic:
rw [Set.image_subset_iff]
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        

Proof state:
case h
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
⊢ ↑f ⁻¹' {x} ⊆ ↑0 ⁻¹' {0}

Next tactic:
convert Set.subset_univ _
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        

Proof state:
case h.e'_4
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
⊢ ↑0 ⁻¹' {0} = univ

Next tactic:
exact preimage_const_of_mem (mem_singleton _)
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · 

Proof state:
case h
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
⊢ x ∉ ↑s

Next tactic:
rwa [Finset.mem_coe]
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · rwa [Finset.mem_coe]
    

Proof state:
case insert
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
Pg : P g
⊢ P f

Next tactic:
convert h_add _ Pg (h_ind x mx)
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · rwa [Finset.mem_coe]
    convert h_add _ Pg (h_ind x mx)
    · 

Proof state:
case h.e'_1
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
Pg : P g
⊢ f = g + piecewise (↑f ⁻¹' {x}) mx (const α x) (const α 0)

Next tactic:
ext1 y
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · rwa [Finset.mem_coe]
    convert h_add _ Pg (h_ind x mx)
    · ext1 y
      

Proof state:
case h.e'_1.H
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
Pg : P g
y : α
⊢ ↑f y = ↑(g + piecewise (↑f ⁻¹' {x}) mx (const α x) (const α 0)) y

Next tactic:
by_cases hy : y ∈ f ⁻¹' {x}
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · rwa [Finset.mem_coe]
    convert h_add _ Pg (h_ind x mx)
    · ext1 y
      by_cases hy : y ∈ f ⁻¹' {x}
      · 

Proof state:
case pos
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
Pg : P g
y : α
hy : y ∈ ↑f ⁻¹' {x}
⊢ ↑f y = ↑(g + piecewise (↑f ⁻¹' {x}) mx (const α x) (const α 0)) y

Next tactic:
simpa [piecewise_eq_of_mem _ _ _ hy, -piecewise_eq_indicator]
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · rwa [Finset.mem_coe]
    convert h_add _ Pg (h_ind x mx)
    · ext1 y
      by_cases hy : y ∈ f ⁻¹' {x}
      · simpa [piecewise_eq_of_mem _ _ _ hy, -piecewise_eq_indicator]
      · 

Proof state:
case neg
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
Pg : P g
y : α
hy : y ∉ ↑f ⁻¹' {x}
⊢ ↑f y = ↑(g + piecewise (↑f ⁻¹' {x}) mx (const α x) (const α 0)) y

Next tactic:
simp [piecewise_eq_of_not_mem _ _ _ hy, -piecewise_eq_indicator]
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).

It is possible to make the hypotheses in `h_add` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
@[elab_as_elim]
protected theorem induction {α γ} [MeasurableSpace α] [AddMonoid γ] {P : SimpleFunc α γ → Prop}
    (h_ind :
      ∀ (c) {s} (hs : MeasurableSet s),
        P (SimpleFunc.piecewise s hs (SimpleFunc.const _ c) (SimpleFunc.const _ 0)))
    (h_add : ∀ ⦃f g : SimpleFunc α γ⦄, Disjoint (support f) (support g) → P f → P g → P (f + g))
    (f : SimpleFunc α γ) : P f := by
  generalize h : f.range \ {0} = s
  rw [← Finset.coe_inj, Finset.coe_sdiff, Finset.coe_singleton, SimpleFunc.coe_range] at h
  induction s using Finset.induction generalizing f with
  | empty =>
    rw [Finset.coe_empty, diff_eq_empty, range_subset_singleton] at h
    convert h_ind 0 MeasurableSet.univ
    ext x
    simp [h]
  | @insert x s hxs ih =>
    have mx := f.measurableSet_preimage {x}
    let g := SimpleFunc.piecewise (f ⁻¹' {x}) mx 0 f
    have Pg : P g := by
      apply ih
      simp only [SimpleFunc.coe_piecewise, range_piecewise]
      rw [image_compl_preimage, union_diff_distrib, diff_diff_comm, h, Finset.coe_insert,
        insert_diff_self_of_not_mem, diff_eq_empty.mpr, Set.empty_union]
      · rw [Set.image_subset_iff]
        convert Set.subset_univ _
        exact preimage_const_of_mem (mem_singleton _)
      · rwa [Finset.mem_coe]
    convert h_add _ Pg (h_ind x mx)
    · ext1 y
      by_cases hy : y ∈ f ⁻¹' {x}
      · simpa [piecewise_eq_of_mem _ _ _ hy, -piecewise_eq_indicator]
      · simp [piecewise_eq_of_not_mem _ _ _ hy, -piecewise_eq_indicator]
    

Proof state:
case insert
α✝ : Type u_1
β : Type u_2
γ✝ : Type u_3
δ : Type u_4
α : Type u_5
γ : Type u_6
inst✝¹ : MeasurableSpace α
inst✝ : AddMonoid γ
P : (α →ₛ γ) → Prop
h_ind : ∀ (c : γ) {s : Set α} (hs : MeasurableSet s), P (piecewise s hs (const α c) (const α 0))
h_add : ∀ ⦃f g : α →ₛ γ⦄, Disjoint (support ↑f) (support ↑g) → P f → P g → P (f + g)
x : γ
s : Finset γ
hxs : x ∉ s
ih : ∀ (f : α →ₛ γ), range ↑f \ {0} = ↑s → P f
f : α →ₛ γ
h : range ↑f \ {0} = ↑(insert x s)
mx : MeasurableSet (↑f ⁻¹' {x})
g : α →ₛ γ := piecewise (↑f ⁻¹' {x}) mx 0 f
Pg : P g
⊢ Disjoint (support ↑g) (support ↑(piecewise (↑f ⁻¹' {x}) mx (const α x) (const α 0)))

Next tactic:
rw [disjoint_iff_inf_le]