Theorem: List.Chain'.two_mul_count_bool_eq_ite
File: Mathlib/Data/Bool/Count.lean

tactic: by_cases h2 : Even (length l)
state_before: l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) l
b : Bool
⊢ 2 * count b l = if Even l.length then l.length else if (some b == l.head?) = true then l.length + 1 else l.length - 1
state_after: case pos
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) l
b : Bool
h2 : Even l.length
⊢ 2 * count b l = if Even l.length then l.length else if (some b == l.head?) = true then l.length + 1 else l.length - 1

case neg
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) l
b : Bool
h2 : ¬Even l.length
⊢ 2 * count b l = if Even l.length then l.length else if (some b == l.head?) = true then l.length + 1 else l.length - 1

tactic: rw [if_pos h2, hl.two_mul_count_bool_of_even h2]
state_before: case pos
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) l
b : Bool
h2 : Even l.length
⊢ 2 * count b l = if Even l.length then l.length else if (some b == l.head?) = true then l.length + 1 else l.length - 1
state_after: no goals

tactic: cases' l with x l
state_before: case neg
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) l
b : Bool
h2 : ¬Even l.length
⊢ 2 * count b l = if Even l.length then l.length else if (some b == l.head?) = true then l.length + 1 else l.length - 1
state_after: case neg.nil
b : Bool
hl : Chain' (fun x x_1 => x ≠ x_1) []
h2 : ¬Even [].length
⊢ 2 * count b [] =
    if Even [].length then [].length else if (some b == [].head?) = true then [].length + 1 else [].length - 1

case neg.cons
b x : Bool
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) (x :: l)
h2 : ¬Even (x :: l).length
⊢ 2 * count b (x :: l) =
    if Even (x :: l).length then (x :: l).length
    else if (some b == (x :: l).head?) = true then (x :: l).length + 1 else (x :: l).length - 1

tactic: simp only [if_neg h2, count_cons, mul_add, head?, Option.mem_some_iff, @eq_comm _ x]
state_before: case neg.cons
b x : Bool
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) (x :: l)
h2 : ¬Even (x :: l).length
⊢ 2 * count b (x :: l) =
    if Even (x :: l).length then (x :: l).length
    else if (some b == (x :: l).head?) = true then (x :: l).length + 1 else (x :: l).length - 1
state_after: case neg.cons
b x : Bool
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) (x :: l)
h2 : ¬Even (x :: l).length
⊢ (2 * count b l + 2 * if b = x then 1 else 0) =
    if (some b == some x) = true then (x :: l).length + 1 else (x :: l).length - 1

tactic: rw [length_cons, Nat.even_add_one, not_not] at h2
state_before: case neg.cons
b x : Bool
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) (x :: l)
h2 : ¬Even (x :: l).length
⊢ (2 * count b l + 2 * if b = x then 1 else 0) =
    if (some b == some x) = true then (x :: l).length + 1 else (x :: l).length - 1
state_after: case neg.cons
b x : Bool
l : List Bool
hl : Chain' (fun x x_1 => x ≠ x_1) (x :: l)
h2 : Even l.length
⊢ (2 * count b l + 2 * if b = x then 1 else 0) =
    if (some b == some x) = true then (x :: l).length + 1 else (x :: l).length - 1

tactic: rw [hl.two_mul_count_bool_of_even h2]
state_before: case neg.cons
b x : Bool
l : List Bool
h2 : Even l.length
hl : Chain' (fun x x_1 => x ≠ x_1) l
⊢ (2 * count b l + 2 * if b = x then 1 else 0) =
    if (some b == some x) = true then (x :: l).length + 1 else (x :: l).length - 1
state_after: case neg.cons
b x : Bool
l : List Bool
h2 : Even l.length
hl : Chain' (fun x x_1 => x ≠ x_1) l
⊢ (l.length + 2 * if b = x then 1 else 0) =
    if (some b == some x) = true then (x :: l).length + 1 else (x :: l).length - 1

tactic: cases b <;> cases x <;> split_ifs <;> simp <;> contradiction
state_before: case neg.cons
b x : Bool
l : List Bool
h2 : Even l.length
hl : Chain' (fun x x_1 => x ≠ x_1) l
⊢ (l.length + 2 * if b = x then 1 else 0) =
    if (some b == some x) = true then (x :: l).length + 1 else (x :: l).length - 1
state_after: no goals

tactic: exact (h2 even_zero).elim
state_before: case neg.nil
b : Bool
hl : Chain' (fun x x_1 => x ≠ x_1) []
h2 : ¬Even [].length
⊢ 2 * count b [] =
    if Even [].length then [].length else if (some b == [].head?) = true then [].length + 1 else [].length - 1
state_after: no goals