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

tactic: rw [← m.reverse_reverse]
state_before: α : Type u_1
f : Char → α → α
l m r : List Char
a : α
⊢ foldrAux f a { data := l ++ m ++ r } { byteIdx := utf8Len l + utf8Len m } { byteIdx := utf8Len l } = List.foldr f a m
state_after: α : Type u_1
f : Char → α → α
l m r : List Char
a : α
⊢ foldrAux f a { data := l ++ m.reverse.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse.reverse }
      { byteIdx := utf8Len l } =
    List.foldr f a m.reverse.reverse

tactic: induction m.reverse generalizing r a with (unfold foldrAux; simp)
| cons c m IH =>
  rw [if_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)]
  simp only [← Nat.add_assoc, by simpa using prev_of_valid (l ++ m.reverse) c r]
  simp only [by simpa using get_of_valid (l ++ m.reverse) (c :: r)]
  simpa using IH (c::r) (f c a)
state_before: α : Type u_1
f : Char → α → α
l m r : List Char
a : α
⊢ foldrAux f a { data := l ++ m.reverse.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse.reverse }
      { byteIdx := utf8Len l } =
    List.foldr f a m.reverse.reverse
state_after: no goals

tactic: unfold foldrAux
state_before: case nil
α : Type u_1
f : Char → α → α
l m r : List Char
a : α
⊢ foldrAux f a { data := l ++ [].reverse ++ r } { byteIdx := utf8Len l + utf8Len [].reverse } { byteIdx := utf8Len l } =
    List.foldr f a [].reverse
state_after: case nil
α : Type u_1
f : Char → α → α
l m r : List Char
a : α
⊢ (if h : { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len [].reverse } then
      let_fun this := ⋯;
      let i := { data := l ++ [].reverse ++ r }.prev { byteIdx := utf8Len l + utf8Len [].reverse };
      let a := f ({ data := l ++ [].reverse ++ r }.get i) a;
      foldrAux f a { data := l ++ [].reverse ++ r } i { byteIdx := utf8Len l }
    else a) =
    List.foldr f a [].reverse

tactic: simp
state_before: case nil
α : Type u_1
f : Char → α → α
l m r : List Char
a : α
⊢ (if h : { byteIdx := utf8Len l } < { byteIdx := utf8Len l + utf8Len [].reverse } then
      let_fun this := ⋯;
      let i := { data := l ++ [].reverse ++ r }.prev { byteIdx := utf8Len l + utf8Len [].reverse };
      let a := f ({ data := l ++ [].reverse ++ r }.get i) a;
      foldrAux f a { data := l ++ [].reverse ++ r } i { byteIdx := utf8Len l }
    else a) =
    List.foldr f a [].reverse
state_after: no goals

tactic: rw [if_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)]
state_before: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ (if utf8Len l < utf8Len l + (utf8Len m + c.utf8Size) then
      foldrAux f
        (f
          ({ data := l ++ (m.reverse ++ c :: r) }.get
            ({ data := l ++ (m.reverse ++ c :: r) }.prev { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) }))
          a)
        { data := l ++ (m.reverse ++ c :: r) }
        ({ data := l ++ (m.reverse ++ c :: r) }.prev { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) })
        { byteIdx := utf8Len l }
    else a) =
    List.foldl (fun x y => f y x) (f c a) m
state_after: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ foldrAux f
      (f
        ({ data := l ++ (m.reverse ++ c :: r) }.get
          ({ data := l ++ (m.reverse ++ c :: r) }.prev { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) }))
        a)
      { data := l ++ (m.reverse ++ c :: r) }
      ({ data := l ++ (m.reverse ++ c :: r) }.prev { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) })
      { byteIdx := utf8Len l } =
    List.foldl (fun x y => f y x) (f c a) m

tactic: simp only [← Nat.add_assoc, by simpa using prev_of_valid (l ++ m.reverse) c r]
state_before: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ foldrAux f
      (f
        ({ data := l ++ (m.reverse ++ c :: r) }.get
          ({ data := l ++ (m.reverse ++ c :: r) }.prev { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) }))
        a)
      { data := l ++ (m.reverse ++ c :: r) }
      ({ data := l ++ (m.reverse ++ c :: r) }.prev { byteIdx := utf8Len l + (utf8Len m + c.utf8Size) })
      { byteIdx := utf8Len l } =
    List.foldl (fun x y => f y x) (f c a) m
state_after: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ foldrAux f (f ({ data := l ++ (m.reverse ++ c :: r) }.get { byteIdx := utf8Len l + utf8Len m }) a)
      { data := l ++ (m.reverse ++ c :: r) } { byteIdx := utf8Len l + utf8Len m } { byteIdx := utf8Len l } =
    List.foldl (fun x y => f y x) (f c a) m

tactic: simp only [by simpa using get_of_valid (l ++ m.reverse) (c :: r)]
state_before: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ foldrAux f (f ({ data := l ++ (m.reverse ++ c :: r) }.get { byteIdx := utf8Len l + utf8Len m }) a)
      { data := l ++ (m.reverse ++ c :: r) } { byteIdx := utf8Len l + utf8Len m } { byteIdx := utf8Len l } =
    List.foldl (fun x y => f y x) (f c a) m
state_after: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ foldrAux f (f c a) { data := l ++ (m.reverse ++ c :: r) } { byteIdx := utf8Len l + utf8Len m }
      { byteIdx := utf8Len l } =
    List.foldl (fun x y => f y x) (f c a) m

tactic: simpa using IH (c::r) (f c a)
state_before: case cons
α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ foldrAux f (f c a) { data := l ++ (m.reverse ++ c :: r) } { byteIdx := utf8Len l + utf8Len m }
      { byteIdx := utf8Len l } =
    List.foldl (fun x y => f y x) (f c a) m
state_after: no goals

tactic: exact Nat.lt_add_of_pos_right add_csize_pos
state_before: α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ utf8Len l < utf8Len l + (utf8Len m + c.utf8Size)
state_after: no goals

tactic: simpa using prev_of_valid (l ++ m.reverse) c r
state_before: α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ ?m.140547
state_after: no goals

tactic: simpa using get_of_valid (l ++ m.reverse) (c :: r)
state_before: α : Type u_1
f : Char → α → α
l m✝ : List Char
c : Char
m : List Char
IH :
  ∀ (r : List Char) (a : α),
    foldrAux f a { data := l ++ m.reverse ++ r } { byteIdx := utf8Len l + utf8Len m.reverse } { byteIdx := utf8Len l } =
      List.foldr f a m.reverse
r : List Char
a : α
⊢ ?m.140675
state_after: no goals