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

tactic: unfold offsetOfPosAux
state_before: l r : List Char
n : Nat
⊢ { data := l ++ [] ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len [] } { byteIdx := utf8Len l } n =
    n + [].length
state_after: l r : List Char
n : Nat
⊢ (if { byteIdx := utf8Len l } ≥ { byteIdx := utf8Len l + utf8Len [] } then n
    else
      if h : { data := l ++ [] ++ r }.atEnd { byteIdx := utf8Len l } = true then n
      else
        let_fun this := ⋯;
        { data := l ++ [] ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len [] }
          ({ data := l ++ [] ++ r }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + [].length

tactic: simp
state_before: l r : List Char
n : Nat
⊢ (if { byteIdx := utf8Len l } ≥ { byteIdx := utf8Len l + utf8Len [] } then n
    else
      if h : { data := l ++ [] ++ r }.atEnd { byteIdx := utf8Len l } = true then n
      else
        let_fun this := ⋯;
        { data := l ++ [] ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len [] }
          ({ data := l ++ [] ++ r }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + [].length
state_after: no goals

tactic: unfold offsetOfPosAux
state_before: l : List Char
c : Char
m r : List Char
n : Nat
⊢ { data := l ++ c :: m ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) } { byteIdx := utf8Len l } n =
    n + (c :: m).length
state_after: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if { byteIdx := utf8Len l } ≥ { byteIdx := utf8Len l + utf8Len (c :: m) } then n
    else
      if h : { data := l ++ c :: m ++ r }.atEnd { byteIdx := utf8Len l } = true then n
      else
        let_fun this := ⋯;
        { data := l ++ c :: m ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) }
          ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + (c :: m).length

tactic: rw [if_neg (by exact Nat.not_le.2 (Nat.lt_add_of_pos_right add_csize_pos))]
state_before: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if { byteIdx := utf8Len l } ≥ { byteIdx := utf8Len l + utf8Len (c :: m) } then n
    else
      if h : { data := l ++ c :: m ++ r }.atEnd { byteIdx := utf8Len l } = true then n
      else
        let_fun this := ⋯;
        { data := l ++ c :: m ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) }
          ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + (c :: m).length
state_after: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if h : { data := l ++ c :: m ++ r }.atEnd { byteIdx := utf8Len l } = true then n
    else
      let_fun this := ⋯;
      { data := l ++ c :: m ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) }
        ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + (c :: m).length

tactic: simp only [List.append_assoc, atEnd_of_valid l (c::m++r)]
state_before: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if h : { data := l ++ c :: m ++ r }.atEnd { byteIdx := utf8Len l } = true then n
    else
      let_fun this := ⋯;
      { data := l ++ c :: m ++ r }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) }
        ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + (c :: m).length
state_after: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if h : c :: m ++ r = [] then n
    else
      { data := l ++ (c :: m ++ r) }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) }
        ({ data := l ++ (c :: m ++ r) }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + (c :: m).length

tactic: simp only [List.cons_append, utf8Len_cons, next_of_valid l c (m ++ r)]
state_before: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if h : c :: m ++ r = [] then n
    else
      { data := l ++ (c :: m ++ r) }.offsetOfPosAux { byteIdx := utf8Len l + utf8Len (c :: m) }
        ({ data := l ++ (c :: m ++ r) }.next { byteIdx := utf8Len l }) (n + 1)) =
    n + (c :: m).length
state_after: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if h : False then n
    else
      { data := l ++ c :: (m ++ r) }.offsetOfPosAux { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) }
        { byteIdx := utf8Len l + c.utf8Size } (n + 1)) =
    n + (c :: m).length

tactic: simpa [← Nat.add_assoc, Nat.add_right_comm] using
  offsetOfPosAux_of_valid (l++[c]) m r (n + 1)
state_before: l : List Char
c : Char
m r : List Char
n : Nat
⊢ (if h : False then n
    else
      { data := l ++ c :: (m ++ r) }.offsetOfPosAux { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) }
        { byteIdx := utf8Len l + c.utf8Size } (n + 1)) =
    n + (c :: m).length
state_after: no goals

tactic: exact Nat.not_le.2 (Nat.lt_add_of_pos_right add_csize_pos)
state_before: l : List Char
c : Char
m r : List Char
n : Nat
⊢ ¬{ byteIdx := utf8Len l } ≥ { byteIdx := utf8Len l + utf8Len (c :: m) }
state_after: no goals