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

tactic: simp [Substring.extract]
state_before: l m r ml mm mr : List Char
b e : Pos
⊢ ∃ l' r',
    ValidFor l' mm r'
      (Substring.extract
        { str := { data := l ++ (ml ++ mm ++ mr) ++ r }, startPos := { byteIdx := utf8Len l },
          stopPos := { byteIdx := utf8Len l + utf8Len (ml ++ mm ++ mr) } }
        { byteIdx := utf8Len ml } { 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 :=
            Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
          stopPos :=
            Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
              ({ 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_le_left _ _ 0).1 h]
exact ⟨[], [], ⟨⟩⟩
state_before: case inl
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 }

tactic: rw [utf8Len_eq_zero.1 <| Nat.le_zero.1 <| (Nat.add_le_add_iff_le_left _ _ 0).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 }

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 }

tactic: next h =>
refine ⟨l ++ ml, mr ++ r, .of_eq _ (by simp) ?_ ?_⟩ <;>
  simp [Nat.min_eq_min] <;> rw [Nat.min_eq_right] <;>
  simp [Nat.add_le_add_iff_le_left, Nat.le_add_right]
rw [Nat.add_assoc]
state_before: case inr
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 :=
          Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
        stopPos :=
          Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) }

tactic: refine ⟨l ++ ml, mr ++ r, .of_eq _ (by simp) ?_ ?_⟩ <;>
  simp [Nat.min_eq_min] <;> rw [Nat.min_eq_right] <;>
  simp [Nat.add_le_add_iff_le_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 :=
          Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
            ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
        stopPos :=
          Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
            ({ byteIdx := utf8Len l } + { byteIdx := 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

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 :=
            Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml }),
          stopPos :=
            Pos.min { byteIdx := utf8Len l + (utf8Len ml + (utf8Len mm + utf8Len mr)) }
              ({ byteIdx := utf8Len l } + { byteIdx := utf8Len ml + utf8Len mm }) }.str.data =
    l ++ ml ++ mm ++ (mr ++ r)