-- Mathlib/.lake/packages/batteries/Batteries/Data/String/Lemmas.lean
theorem utf8SetAux_of_valid (c' : Char) (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) :
    utf8SetAux c' (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs ++ cs'.modifyHead fun _ => c'

Proof state:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ (if { byteIdx := i } = { byteIdx := p } then c' :: (cs ++ cs')
    else c :: utf8SetAux c' (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p }) =
    c :: (cs ++ List.modifyHead (fun x => c') cs')

Tactic:
rw [if_neg]

Result:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ c :: utf8SetAux c' (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p } =
    c :: (cs ++ List.modifyHead (fun x => c') cs')

case hnc
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ ¬{ byteIdx := i } = { byteIdx := p }

Proof state:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ c :: utf8SetAux c' (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p } =
    c :: (cs ++ List.modifyHead (fun x => c') cs')

case hnc
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ ¬{ byteIdx := i } = { byteIdx := p }

Tactic:
case hnc => simp only [← hp, Pos.ext_iff]; exact ne_self_add_add_utf8Size

Result:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ c :: utf8SetAux c' (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p } =
    c :: (cs ++ List.modifyHead (fun x => c') cs')

Proof state:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ utf8SetAux c' (c :: cs ++ cs') { byteIdx := i } { byteIdx := p } = c :: cs ++ List.modifyHead (fun x => c') cs'

Tactic:
simp only [utf8SetAux, List.append_eq, List.cons_append]

Result:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ (if { byteIdx := i } = { byteIdx := p } then c' :: (cs ++ cs')
    else c :: utf8SetAux c' (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p }) =
    c :: (cs ++ List.modifyHead (fun x => c') cs')

Proof state:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ ¬{ byteIdx := i } = { byteIdx := p }

Tactic:
simp only [← hp, Pos.ext_iff]

Result:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ ¬i = i + utf8Len (c :: cs)

Proof state:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ ¬i = i + utf8Len (c :: cs)

Tactic:
exact ne_self_add_add_utf8Size

Result:
no goals

Proof state:
c' : Char
cs✝ cs'✝ : List Char
i p : Nat
c : Char
cs cs' : List Char
hp : i + utf8Len (c :: cs) = p
⊢ { byteIdx := i }.byteIdx + c.utf8Size + utf8Len cs = p

Tactic:
simpa [Nat.add_assoc, Nat.add_comm] using hp

Result:
no goals

Proof state:
c' : Char
cs cs'✝ : List Char
i p : Nat
c : Char
cs' : List Char
hp : i + utf8Len [] = p
⊢ utf8SetAux c' ([] ++ c :: cs') { byteIdx := i } { byteIdx := p } = [] ++ List.modifyHead (fun x => c') (c :: cs')

Tactic:
simp [← hp, utf8SetAux]

Result:
no goals

Proof state:
c' : Char
cs cs' : List Char
i p : Nat
hp : i + utf8Len [] = p
⊢ utf8SetAux c' ([] ++ []) { byteIdx := i } { byteIdx := p } = [] ++ List.modifyHead (fun x => c') []

Tactic:
rfl

Result:
no goals