Theorem: Substring.ValidFor.extract
File: .lake/packages/batteries/Batteries/Data/String/Lemmas.lean

tactic: simp only [Substring.extract, ge_iff_le, Pos.mk_le_mk, List.append_assoc, utf8Len_append]
state_before: l m r ml mm mr : List Char
b e : Pos
⊢ ∃ l' r',
    ValidFor l' mm r'
      ({ str := { data := l ++ (ml ++ mm ++ mr) ++ r }, startPos := { byteIdx := utf8Len l },
            stopPos := { byteIdx := utf8Len l + utf8Len (ml ++ mm ++ mr) } }.extract
        { byteIdx := utf8Len ml } { byteIdx := utf8Len ml + utf8Len mm })
state_after: l m r ml mm mr : List Char
b e : Pos
⊢ ∃ l' r',
    ValidFor l' mm r'
      (if utf8Len ml + utf8Len mm ≤ utf8Len ml then { str := "", startPos := 0, stopPos := 0 }
      else
        { str := { data := l ++ (ml ++ (mm ++ (mr ++ r))) },
          startPos :=
            { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
          stopPos :=
            { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) })

tactic: split
state_before: l m r ml mm mr : List Char
b e : Pos
⊢ ∃ l' r',
    ValidFor l' mm r'
      (if utf8Len ml + utf8Len mm ≤ utf8Len ml then { str := "", startPos := 0, stopPos := 0 }
      else
        { str := { data := l ++ (ml ++ (mm ++ (mr ++ r))) },
          startPos :=
            { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
          stopPos :=
            { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) })
state_after: case isTrue
l m r ml mm mr : List Char
b e : Pos
h✝ : utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r', ValidFor l' mm r' { str := "", startPos := 0, stopPos := 0 }

case isFalse
l m r ml mm mr : List Char
b e : Pos
h✝ : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r',
    ValidFor l' mm r'
      { str := { data := l ++ (ml ++ (mm ++ (mr ++ r))) },
        startPos :=
          { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
        stopPos :=
          { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) }

tactic: next h =>
rw [utf8Len_eq_zero.1 <| Nat.le_zero.1 <| Nat.add_le_add_iff_left.1 h]
exact ⟨[], [], ⟨⟩⟩
state_before: case isTrue
l m r ml mm mr : List Char
b e : Pos
h✝ : utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r', ValidFor l' mm r' { str := "", startPos := 0, stopPos := 0 }
state_after: no goals

tactic: rw [utf8Len_eq_zero.1 <| Nat.le_zero.1 <| Nat.add_le_add_iff_left.1 h]
state_before: l m r ml mm mr : List Char
b e : Pos
h : utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r', ValidFor l' mm r' { str := "", startPos := 0, stopPos := 0 }
state_after: l m r ml mm mr : List Char
b e : Pos
h : utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r', ValidFor l' [] r' { str := "", startPos := 0, stopPos := 0 }

tactic: exact ⟨[], [], ⟨⟩⟩
state_before: l m r ml mm mr : List Char
b e : Pos
h : utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r', ValidFor l' [] r' { str := "", startPos := 0, stopPos := 0 }
state_after: no goals

tactic: next h =>
refine ⟨l ++ ml, mr ++ r, .of_eq _ (by simp) ?_ ?_⟩ <;>
  simp only [Pos.add_byteIdx, Nat.min_eq_min, utf8Len_append]
    <;> rw [Nat.min_eq_right]
    <;> try simp [Nat.add_le_add_iff_left, Nat.le_add_right]
rw [Nat.add_assoc]
state_before: case isFalse
l m r ml mm mr : List Char
b e : Pos
h✝ : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r',
    ValidFor l' mm r'
      { str := { data := l ++ (ml ++ (mm ++ (mr ++ r))) },
        startPos :=
          { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
        stopPos :=
          { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) }
state_after: no goals

tactic: refine ⟨l ++ ml, mr ++ r, .of_eq _ (by simp) ?_ ?_⟩ <;>
  simp only [Pos.add_byteIdx, Nat.min_eq_min, utf8Len_append]
    <;> rw [Nat.min_eq_right]
    <;> try simp [Nat.add_le_add_iff_left, Nat.le_add_right]
state_before: l m r ml mm mr : List Char
b e : Pos
h : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ ∃ l' r',
    ValidFor l' mm r'
      { str := { data := l ++ (ml ++ (mm ++ (mr ++ r))) },
        startPos :=
          { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
        stopPos :=
          { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) }
state_after: case refine_2
l m r ml mm mr : List Char
b e : Pos
h : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ utf8Len l + (utf8Len ml + utf8Len mm) = utf8Len l + utf8Len ml + utf8Len mm

tactic: rw [Nat.add_assoc]
state_before: case refine_2
l m r ml mm mr : List Char
b e : Pos
h : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ utf8Len l + (utf8Len ml + utf8Len mm) = utf8Len l + utf8Len ml + utf8Len mm
state_after: no goals

tactic: simp
state_before: l m r ml mm mr : List Char
b e : Pos
h : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ { str := { data := l ++ (ml ++ (mm ++ (mr ++ r))) },
          startPos :=
            { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
          stopPos :=
            { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }.min
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) }.str.data =
    l ++ ml ++ mm ++ (mr ++ r)
state_after: no goals

tactic: simp [Nat.add_le_add_iff_left, Nat.le_add_right]
state_before: case refine_2
l m r ml mm mr : List Char
b e : Pos
h : ¬utf8Len ml + utf8Len mm ≤ utf8Len ml
⊢ utf8Len l + (utf8Len ml + utf8Len mm) ≤ utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr))
state_after: no goals