Theorem: Substring.ValidFor.take
File: Std/Data/String/Lemmas.lean

tactic: have : Substring.nextn {..} .. = _ := h.nextn (m₁ := []) n
state_before: l m r : List Char
s : Substring
h : ValidFor l m r s
n : Nat
⊢ ValidFor l (List.take n m) (List.drop n m ++ r) (Substring.take s n)

tactic: simp at this
state_before: l m r : List Char
s : Substring
h : ValidFor l m r s
n : Nat
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n { byteIdx := utf8Len [] } =
    { byteIdx := utf8Len [] + utf8Len (List.take n m) }
⊢ ValidFor l (List.take n m) (List.drop n m ++ r) (Substring.take s n)

tactic: simp [Substring.take, this]
state_before: l m r : List Char
s : Substring
h : ValidFor l m r s
n : Nat
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ ValidFor l (List.take n m) (List.drop n m ++ r) (Substring.take s n)

tactic: simp [h.str, h.startPos, h.stopPos]
state_before: l m r : List Char
s : Substring
h : ValidFor l m r s
n : Nat
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ ValidFor l (List.take n m) (List.drop n m ++ r)
    { str := s.str, startPos := s.startPos, stopPos := s.startPos + { byteIdx := utf8Len (List.take n m) } }

tactic: rw [← List.take_append_drop n m] at h
state_before: l m r : List Char
s : Substring
h : ValidFor l m r s
n : Nat
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ ValidFor l (List.take n m) (List.drop n m ++ r)
    { str := { data := l ++ (m ++ r) }, startPos := { byteIdx := utf8Len l },
      stopPos := { byteIdx := utf8Len l } + { byteIdx := utf8Len (List.take n m) } }

tactic: refine .of_eq _ ?_ (by simp) (by simp)
state_before: l m r : List Char
s : Substring
n : Nat
h : ValidFor l (List.take n m ++ List.drop n m) r s
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ ValidFor l (List.take n m) (List.drop n m ++ r)
    { str := { data := l ++ (m ++ r) }, startPos := { byteIdx := utf8Len l },
      stopPos := { byteIdx := utf8Len l } + { byteIdx := utf8Len (List.take n m) } }

tactic: conv => lhs; rw [← List.take_append_drop n m]
state_before: l m r : List Char
s : Substring
n : Nat
h : ValidFor l (List.take n m ++ List.drop n m) r s
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ { str := { data := l ++ (m ++ r) }, startPos := { byteIdx := utf8Len l },
          stopPos := { byteIdx := utf8Len l } + { byteIdx := utf8Len (List.take n m) } }.str.data =
    l ++ List.take n m ++ (List.drop n m ++ r)

tactic: simp [-List.take_append_drop, Nat.add_assoc]
state_before: l m r : List Char
s : Substring
n : Nat
h : ValidFor l (List.take n m ++ List.drop n m) r s
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ { str := { data := l ++ (List.take n m ++ List.drop n m ++ r) }, startPos := { byteIdx := utf8Len l },
          stopPos :=
            { byteIdx := utf8Len l } +
              { byteIdx := utf8Len (List.take n (List.take n m ++ List.drop n m)) } }.str.data =
    l ++ List.take n m ++ (List.drop n m ++ r)

tactic: simp
state_before: l m r : List Char
s : Substring
n : Nat
h : ValidFor l (List.take n m ++ List.drop n m) r s
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ { str := { data := l ++ (m ++ r) }, startPos := { byteIdx := utf8Len l },
          stopPos := { byteIdx := utf8Len l } + { byteIdx := utf8Len (List.take n m) } }.startPos.byteIdx =
    utf8Len l

tactic: simp
state_before: l m r : List Char
s : Substring
n : Nat
h : ValidFor l (List.take n m ++ List.drop n m) r s
this :
  Substring.nextn { str := s.str, startPos := s.startPos, stopPos := s.stopPos } n 0 =
    { byteIdx := utf8Len (List.take n m) }
⊢ { str := { data := l ++ (m ++ r) }, startPos := { byteIdx := utf8Len l },
          stopPos := { byteIdx := utf8Len l } + { byteIdx := utf8Len (List.take n m) } }.stopPos.byteIdx =
    utf8Len l + utf8Len (List.take n m)