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

tactic: unfold anyAux
state_before: p : Char → Bool
l r : List Char
⊢ { data := l ++ [] ++ r }.anyAux { byteIdx := utf8Len l + utf8Len [] } p { byteIdx := utf8Len l } = [].any p
state_after: p : Char → Bool
l r : List Char
⊢ (if h : { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len [] } then
      if p ({ data := l ++ [] ++ r }.get { byteIdx := utf8Len l }) = true then true
      else
        let_fun this := ⋯;
        { data := l ++ [] ++ r }.anyAux { byteIdx := utf8Len l + utf8Len [] } p
          ({ data := l ++ [] ++ r }.next { byteIdx := utf8Len l })
    else false) =
    [].any p

tactic: simp
state_before: p : Char → Bool
l r : List Char
⊢ (if h : { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len [] } then
      if p ({ data := l ++ [] ++ r }.get { byteIdx := utf8Len l }) = true then true
      else
        let_fun this := ⋯;
        { data := l ++ [] ++ r }.anyAux { byteIdx := utf8Len l + utf8Len [] } p
          ({ data := l ++ [] ++ r }.next { byteIdx := utf8Len l })
    else false) =
    [].any p
state_after: no goals

tactic: unfold anyAux
state_before: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ { data := l ++ c :: m ++ r }.anyAux { byteIdx := utf8Len l + utf8Len (c :: m) } p { byteIdx := utf8Len l } =
    (c :: m).any p
state_after: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ (if h : { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len (c :: m) } then
      if p ({ data := l ++ c :: m ++ r }.get { byteIdx := utf8Len l }) = true then true
      else
        let_fun this := ⋯;
        { data := l ++ c :: m ++ r }.anyAux { byteIdx := utf8Len l + utf8Len (c :: m) } p
          ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l })
    else false) =
    (c :: m).any p

tactic: rw [dif_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)]
state_before: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ (if h : { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len (c :: m) } then
      if p ({ data := l ++ c :: m ++ r }.get { byteIdx := utf8Len l }) = true then true
      else
        let_fun this := ⋯;
        { data := l ++ c :: m ++ r }.anyAux { byteIdx := utf8Len l + utf8Len (c :: m) } p
          ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l })
    else false) =
    (c :: m).any p
state_after: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ (if p ({ data := l ++ c :: m ++ r }.get { byteIdx := utf8Len l }) = true then true
    else
      let_fun this := ⋯;
      { data := l ++ c :: m ++ r }.anyAux { byteIdx := utf8Len l + utf8Len (c :: m) } p
        ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l })) =
    (c :: m).any p

tactic: simp only [List.append_assoc, List.cons_append, get_of_valid l (c :: (m ++ r)),
  Char.reduceDefault, List.headD_cons, utf8Len_cons, next_of_valid l c (m ++ r),
  Bool.if_true_left, Bool.decide_eq_true, List.any_cons]
state_before: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ (if p ({ data := l ++ c :: m ++ r }.get { byteIdx := utf8Len l }) = true then true
    else
      let_fun this := ⋯;
      { data := l ++ c :: m ++ r }.anyAux { byteIdx := utf8Len l + utf8Len (c :: m) } p
        ({ data := l ++ c :: m ++ r }.next { byteIdx := utf8Len l })) =
    (c :: m).any p
state_after: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ (p c ||
      { data := l ++ c :: (m ++ r) }.anyAux { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) } p
        { byteIdx := utf8Len l + c.utf8Size }) =
    (p c || m.any p)

tactic: cases p c <;> simp
state_before: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ (p c ||
      { data := l ++ c :: (m ++ r) }.anyAux { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) } p
        { byteIdx := utf8Len l + c.utf8Size }) =
    (p c || m.any p)
state_after: case false
p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ { data := l ++ c :: (m ++ r) }.anyAux { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) } p
      { byteIdx := utf8Len l + c.utf8Size } =
    m.any p

tactic: simpa [← Nat.add_assoc, Nat.add_right_comm] using anyAux_of_valid p (l++[c]) m r
state_before: case false
p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ { data := l ++ c :: (m ++ r) }.anyAux { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) } p
      { byteIdx := utf8Len l + c.utf8Size } =
    m.any p
state_after: no goals

tactic: exact Nat.lt_add_of_pos_right add_csize_pos
state_before: p : Char → Bool
l : List Char
c : Char
m r : List Char
⊢ { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len (c :: m) }
state_after: no goals