Theorem: String.utf8PrevAux_of_valid
File: .lake/packages/batteries/Batteries/Data/String/Lemmas.lean

tactic: match cs with
| [] => simp [utf8PrevAux, ← hp, Pos.addChar_eq]
| c'::cs =>
  simp only [utf8PrevAux, Pos.addChar_eq, ← hp, utf8Len_cons, List.append_eq]
  rw [if_neg]
  case hnc =>
    simp only [Pos.ext_iff]
    rw [Nat.add_right_comm, Nat.add_left_comm]
    apply ne_add_csize_add_self
  refine (utf8PrevAux_of_valid (by simp [Nat.add_assoc, Nat.add_left_comm])).trans ?_
  simp [Nat.add_assoc, Nat.add_comm]
state_before: cs cs' : List Char
c : Char
i p : Nat
hp : i + (utf8Len cs + c.utf8Size) = p
⊢ utf8PrevAux (cs ++ c :: cs') { byteIdx := i } { byteIdx := p } = { byteIdx := i + utf8Len cs }
state_after: no goals

tactic: simp [utf8PrevAux, ← hp, Pos.addChar_eq]
state_before: cs cs' : List Char
c : Char
i p : Nat
hp : i + (utf8Len [] + c.utf8Size) = p
⊢ utf8PrevAux ([] ++ c :: cs') { byteIdx := i } { byteIdx := p } = { byteIdx := i + utf8Len [] }
state_after: no goals

tactic: simp only [utf8PrevAux, Pos.addChar_eq, ← hp, utf8Len_cons, List.append_eq]
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ utf8PrevAux (c' :: cs ++ c :: cs') { byteIdx := i } { byteIdx := p } = { byteIdx := i + utf8Len (c' :: cs) }
state_after: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ (if { byteIdx := i + c'.utf8Size } = { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) } then { byteIdx := i }
    else
      utf8PrevAux (cs ++ c :: cs') { byteIdx := i + c'.utf8Size }
        { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) }) =
    { byteIdx := i + (utf8Len cs + c'.utf8Size) }

tactic: rw [if_neg]
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ (if { byteIdx := i + c'.utf8Size } = { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) } then { byteIdx := i }
    else
      utf8PrevAux (cs ++ c :: cs') { byteIdx := i + c'.utf8Size }
        { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) }) =
    { byteIdx := i + (utf8Len cs + c'.utf8Size) }
state_after: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ utf8PrevAux (cs ++ c :: cs') { byteIdx := i + c'.utf8Size }
      { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) } =
    { byteIdx := i + (utf8Len cs + c'.utf8Size) }

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

tactic: case hnc =>
  simp only [Pos.ext_iff]
  rw [Nat.add_right_comm, Nat.add_left_comm]
  apply ne_add_csize_add_self
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ utf8PrevAux (cs ++ c :: cs') { byteIdx := i + c'.utf8Size }
      { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) } =
    { byteIdx := i + (utf8Len cs + c'.utf8Size) }

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

tactic: refine (utf8PrevAux_of_valid (by simp [Nat.add_assoc, Nat.add_left_comm])).trans ?_
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ utf8PrevAux (cs ++ c :: cs') { byteIdx := i + c'.utf8Size }
      { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) } =
    { byteIdx := i + (utf8Len cs + c'.utf8Size) }
state_after: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ { byteIdx := i + c'.utf8Size + utf8Len cs } = { byteIdx := i + (utf8Len cs + c'.utf8Size) }

tactic: simp [Nat.add_assoc, Nat.add_comm]
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ { byteIdx := i + c'.utf8Size + utf8Len cs } = { byteIdx := i + (utf8Len cs + c'.utf8Size) }
state_after: no goals

tactic: simp only [Pos.ext_iff]
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ ¬{ byteIdx := i + c'.utf8Size } = { byteIdx := i + (utf8Len cs + c'.utf8Size + c.utf8Size) }
state_after: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ ¬i + c'.utf8Size = i + (utf8Len cs + c'.utf8Size + c.utf8Size)

tactic: rw [Nat.add_right_comm, Nat.add_left_comm]
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ ¬i + c'.utf8Size = i + (utf8Len cs + c'.utf8Size + c.utf8Size)
state_after: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ ¬i + c'.utf8Size = utf8Len cs + c.utf8Size + (i + c'.utf8Size)

tactic: apply ne_add_csize_add_self
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ ¬i + c'.utf8Size = utf8Len cs + c.utf8Size + (i + c'.utf8Size)
state_after: no goals

tactic: simp [Nat.add_assoc, Nat.add_left_comm]
state_before: cs✝ cs' : List Char
c : Char
i p : Nat
c' : Char
cs : List Char
hp : i + (utf8Len (c' :: cs) + c.utf8Size) = p
⊢ i + c'.utf8Size + (utf8Len cs + c.utf8Size) = i + (utf8Len cs + c'.utf8Size + c.utf8Size)
state_after: no goals