Theorem: Combinatorics.exists_mono_homothetic_copy
File: Mathlib/Combinatorics/HalesJewett.lean

tactic: obtain ⟨ι, _inst, hι⟩ := Line.exists_mono_in_high_dimension S κ
state_before: M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
⊢ ∃ a, a > 0 ∧ ∃ b c, ∀ (s : M), s ∈ S → C (a • s + b) = c

tactic: skip
state_before: case intro.intro
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
hι : ∀ (C : (ι → { x // x ∈ S }) → κ), ∃ l, Line.IsMono C l
⊢ ∃ a, a > 0 ∧ ∃ b c, ∀ (s : M), s ∈ S → C (a • s + b) = c

tactic: specialize hι fun v => C <| ∑ i, v i
state_before: case intro.intro
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
hι : ∀ (C : (ι → { x // x ∈ S }) → κ), ∃ l, Line.IsMono C l
⊢ ∃ a, a > 0 ∧ ∃ b c, ∀ (s : M), s ∈ S → C (a • s + b) = c

tactic: obtain ⟨l, c, hl⟩ := hι
state_before: case intro.intro
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
hι : ∃ l, Line.IsMono (fun v => C (∑ i : ι, ↑(v i))) l
⊢ ∃ a, a > 0 ∧ ∃ b c, ∀ (s : M), s ∈ S → C (a • s + b) = c

tactic: set s : Finset ι :=  Finset.univ.filter (fun i => l.idxFun i = none ) with hs
state_before: case intro.intro.intro.intro
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
⊢ ∃ a, a > 0 ∧ ∃ b c, ∀ (s : M), s ∈ S → C (a • s + b) = c

tactic: refine'
  ⟨s.card, Finset.card_pos.mpr ⟨l.proper.choose, _⟩, ∑ i in sᶜ, ((l.idxFun i).map _).getD 0,
    c, _⟩
state_before: case intro.intro.intro.intro
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
⊢ ∃ a, a > 0 ∧ ∃ b c, ∀ (s : M), s ∈ S → C (a • s + b) = c

tactic: intro x xs
state_before: case intro.intro.intro.intro.refine'_3
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
⊢ ∀ (s_1 : M),
    s_1 ∈ S → C (Finset.card s • s_1 + ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0) = c

tactic: rw [← hl ⟨x, xs⟩]
state_before: case intro.intro.intro.intro.refine'_3
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ C (Finset.card s • x + ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0) = c

tactic: clear hl
state_before: case intro.intro.intro.intro.refine'_3
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ C (Finset.card s • x + ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0) =
    (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs })

tactic: congr
state_before: case intro.intro.intro.intro.refine'_3
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ C (Finset.card s • x + ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0) =
    (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs })

tactic: rw [← Finset.sum_add_sum_compl s]
state_before: case intro.intro.intro.intro.refine'_3.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ Finset.card s • x + ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0 =
    ∑ i : ι, ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: congr 1
state_before: case intro.intro.intro.intro.refine'_3.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ Finset.card s • x + ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0 =
    ∑ i in s, ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i) +
      ∑ i in sᶜ, ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: rw [hs, Finset.mem_filter]
state_before: case intro.intro.intro.intro.refine'_1
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
⊢ Exists.choose (_ : ∃ i, Line.idxFun l i = none) ∈ s

tactic: exact ⟨Finset.mem_univ _, l.proper.choose_spec⟩
state_before: case intro.intro.intro.intro.refine'_1
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
⊢ Exists.choose (_ : ∃ i, Line.idxFun l i = none) ∈ Finset.univ ∧
    Line.idxFun l (Exists.choose (_ : ∃ i, Line.idxFun l i = none)) = none

tactic: exact fun m => m
state_before: case intro.intro.intro.intro.refine'_2
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
hl : ∀ (x : { x // x ∈ S }), (fun v => C (∑ i : ι, ↑(v i))) ((fun x i => Option.getD (Line.idxFun l i) x) x) = c
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
i : ι
⊢ { x // x ∈ S } → M

tactic: rw [← Finset.sum_const]
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ Finset.card s • x = ∑ i in s, ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: apply Finset.sum_congr rfl
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ ∑ _x in s, x = ∑ i in s, ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: intro i hi
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ ∀ (x_1 : ι), x_1 ∈ s → x = ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } x_1)

tactic: rw [hs, Finset.mem_filter] at hi
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
i : ι
hi : i ∈ s
⊢ x = ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: rw [l.apply_none _ _ hi.right, Subtype.coe_mk]
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
i : ι
hi : i ∈ Finset.univ ∧ Line.idxFun l i = none
⊢ x = ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: apply Finset.sum_congr rfl
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ ∑ i in sᶜ, Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0 =
    ∑ i in sᶜ, ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: intro i hi
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
⊢ ∀ (x_1 : ι),
    x_1 ∈ sᶜ →
      Option.getD (Option.map (fun m => ↑m) (Line.idxFun l x_1)) 0 =
        ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } x_1)

tactic: rw [hs, Finset.compl_filter, Finset.mem_filter] at hi
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
i : ι
hi : i ∈ sᶜ
⊢ Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0 =
    ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: obtain ⟨y, hy⟩ := Option.ne_none_iff_exists.mp hi.right
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
i : ι
hi : i ∈ Finset.univ ∧ ¬Line.idxFun l i = none
⊢ Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0 =
    ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)

tactic: simp_rw [← hy, Option.map_some', Option.getD]
state_before: case intro.intro.intro.intro.refine'_3.e_a.e_a.intro
M : Type u_1
κ : Type u_2
inst✝¹ : AddCommMonoid M
S : Finset M
inst✝ : Finite κ
C : M → κ
ι : Type
_inst : Fintype ι
l : Line { x // x ∈ S } ι
c : κ
s : Finset ι := Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
hs : s = Finset.filter (fun i => Line.idxFun l i = none) Finset.univ
x : M
xs : x ∈ S
i : ι
hi : i ∈ Finset.univ ∧ ¬Line.idxFun l i = none
y : { x // x ∈ S }
hy : some y = Line.idxFun l i
⊢ Option.getD (Option.map (fun m => ↑m) (Line.idxFun l i)) 0 =
    ↑((fun x i => Option.getD (Line.idxFun l i) x) { val := x, property := xs } i)