Theorem: FirstOrder.Language.BoundedFormula.listDecode_encode_list
File: Mathlib/ModelTheory/Encoding.lean

tactic: suffices h : ∀ (φ : Σn, L.BoundedFormula α n) (l),
    (listDecode (listEncode φ.2 ++ l)).1 = φ ∧ (listDecode (listEncode φ.2 ++ l)).2.1 = l
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l : List ((n : ℕ) × BoundedFormula L α n)
⊢ (listDecode (List.bind l fun φ => listEncode φ.snd)).fst = headI l

tactic: induction' l with φ l _
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l : List ((n : ℕ) × BoundedFormula L α n)
h :
  ∀ (φ : (n : ℕ) × BoundedFormula L α n) (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode φ.snd ++ l)).fst = φ ∧ ↑(listDecode (listEncode φ.snd ++ l)).snd = l
⊢ (listDecode (List.bind l fun φ => listEncode φ.snd)).fst = headI l

tactic: rw [List.nil_bind]
state_before: case nil
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
h :
  ∀ (φ : (n : ℕ) × BoundedFormula L α n) (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode φ.snd ++ l)).fst = φ ∧ ↑(listDecode (listEncode φ.snd ++ l)).snd = l
⊢ (listDecode (List.bind [] fun φ => listEncode φ.snd)).fst = headI []

tactic: simp [listDecode]
state_before: case nil
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
h :
  ∀ (φ : (n : ℕ) × BoundedFormula L α n) (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode φ.snd ++ l)).fst = φ ∧ ↑(listDecode (listEncode φ.snd ++ l)).snd = l
⊢ (listDecode []).fst = headI []

tactic: rw [cons_bind, (h φ _).1, headI_cons]
state_before: case cons
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
h :
  ∀ (φ : (n : ℕ) × BoundedFormula L α n) (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode φ.snd ++ l)).fst = φ ∧ ↑(listDecode (listEncode φ.snd ++ l)).snd = l
φ : (n : ℕ) × BoundedFormula L α n
l : List ((n : ℕ) × BoundedFormula L α n)
tail_ih✝ : (listDecode (List.bind l fun φ => listEncode φ.snd)).fst = headI l
⊢ (listDecode (List.bind (φ :: l) fun φ => listEncode φ.snd)).fst = headI (φ :: l)

tactic: rintro ⟨n, φ⟩
state_before: case h
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l : List ((n : ℕ) × BoundedFormula L α n)
⊢ ∀ (φ : (n : ℕ) × BoundedFormula L α n) (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode φ.snd ++ l)).fst = φ ∧ ↑(listDecode (listEncode φ.snd ++ l)).snd = l

tactic: induction' φ with _ _ _ _ φ_n φ_l φ_R ts _ _ _ ih1 ih2 _ _ ih <;> intro l
state_before: case h.mk
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l : List ((n : ℕ) × BoundedFormula L α n)
n : ℕ
φ : BoundedFormula L α n
⊢ ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n, snd := φ }.snd ++ l)).fst = { fst := n, snd := φ } ∧
      ↑(listDecode (listEncode { fst := n, snd := φ }.snd ++ l)).snd = l

tactic: rw [listEncode, singleton_append, listDecode]
state_before: case h.mk.falsum
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (listDecode (listEncode { fst := n✝, snd := falsum }.snd ++ l)).fst = { fst := n✝, snd := falsum } ∧
    ↑(listDecode (listEncode { fst := n✝, snd := falsum }.snd ++ l)).snd = l

tactic: simp only [eq_self_iff_true, heq_iff_eq, and_self_iff]
state_before: case h.mk.falsum
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ ({ fst := { fst := n✝, snd := falsum }.fst, snd := falsum },
          { val := l,
            property :=
              (_ :
                SizeOf.sizeOf l ≤
                  max 1 (SizeOf.sizeOf (Sum.inr (Sum.inr ({ fst := n✝, snd := falsum }.fst + 2)) :: l))) }).fst =
      { fst := n✝, snd := falsum } ∧
    ↑({ fst := { fst := n✝, snd := falsum }.fst, snd := falsum },
            { val := l,
              property :=
                (_ :
                  SizeOf.sizeOf l ≤
                    max 1 (SizeOf.sizeOf (Sum.inr (Sum.inr ({ fst := n✝, snd := falsum }.fst + 2)) :: l))) }).snd =
      l

tactic: rw [listEncode, cons_append, cons_append, listDecode, dif_pos]
state_before: case h.mk.equal
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
t₁✝ t₂✝ : Term L (α ⊕ Fin n✝)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (listDecode (listEncode { fst := n✝, snd := equal t₁✝ t₂✝ }.snd ++ l)).fst = { fst := n✝, snd := equal t₁✝ t₂✝ } ∧
    ↑(listDecode (listEncode { fst := n✝, snd := equal t₁✝ t₂✝ }.snd ++ l)).snd = l

tactic: simp only [eq_mp_eq_cast, cast_eq, eq_self_iff_true, heq_iff_eq, and_self_iff, nil_append]
state_before: case h.mk.equal
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
t₁✝ t₂✝ : Term L (α ⊕ Fin n✝)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ ({ fst := { fst := n✝, snd := equal t₁✝ t₂✝ }.fst,
            snd :=
              equal t₁✝
                (Eq.mp
                  (_ :
                    Term L (α ⊕ Fin { fst := n✝, snd := equal t₁✝ t₂✝ }.fst) =
                      Term L (α ⊕ Fin { fst := n✝, snd := equal t₁✝ t₂✝ }.fst))
                  t₂✝) },
          { val := [] ++ l,
            property :=
              (_ :
                SizeOf.sizeOf ([] ++ l) ≤
                  max 1
                    (SizeOf.sizeOf
                      (Sum.inl { fst := { fst := n✝, snd := equal t₁✝ t₂✝ }.fst, snd := t₁✝ } ::
                        Sum.inl { fst := { fst := n✝, snd := equal t₁✝ t₂✝ }.fst, snd := t₂✝ } :: ([] ++ l)))) }).fst =
      { fst := n✝, snd := equal t₁✝ t₂✝ } ∧
    ↑({ fst := { fst := n✝, snd := equal t₁✝ t₂✝ }.fst,
              snd :=
                equal t₁✝
                  (Eq.mp
                    (_ :
                      Term L (α ⊕ Fin { fst := n✝, snd := equal t₁✝ t₂✝ }.fst) =
                        Term L (α ⊕ Fin { fst := n✝, snd := equal t₁✝ t₂✝ }.fst))
                    t₂✝) },
            { val := [] ++ l,
              property :=
                (_ :
                  SizeOf.sizeOf ([] ++ l) ≤
                    max 1
                      (SizeOf.sizeOf
                        (Sum.inl { fst := { fst := n✝, snd := equal t₁✝ t₂✝ }.fst, snd := t₁✝ } ::
                          Sum.inl { fst := { fst := n✝, snd := equal t₁✝ t₂✝ }.fst, snd := t₂✝ } ::
                            ([] ++ l)))) }).snd =
      l

tactic: simp only [eq_self_iff_true, heq_iff_eq, and_self_iff]
state_before: case h.mk.equal.hc
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
t₁✝ t₂✝ : Term L (α ⊕ Fin n✝)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ { fst := n✝, snd := equal t₁✝ t₂✝ }.fst = { fst := n✝, snd := equal t₁✝ t₂✝ }.fst

tactic: rw [listEncode, cons_append, cons_append, singleton_append, cons_append, listDecode]
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (listDecode (listEncode { fst := φ_n, snd := rel φ_R ts }.snd ++ l)).fst = { fst := φ_n, snd := rel φ_R ts } ∧
    ↑(listDecode (listEncode { fst := φ_n, snd := rel φ_R ts }.snd ++ l)).snd = l

tactic: rw [dif_pos]
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ (if h :
              ∀ (i : Fin φ_l),
                Option.isSome
                    (Option.join
                      (get?
                        (List.map Sum.getLeft
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l))
                        ↑i)) =
                  true then
            if h' :
                ∀ (i : Fin φ_l),
                  (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).fst =
                    { fst := φ_n, snd := rel φ_R ts }.fst then
              { fst := { fst := φ_n, snd := rel φ_R ts }.fst,
                snd :=
                  rel φ_R fun i =>
                    Eq.mp
                      (_ :
                        Term L
                            (α ⊕
                              Fin
                                (Option.get
                                    (Option.join
                                      (get?
                                        (List.map Sum.getLeft
                                          (List.map
                                              (fun i =>
                                                Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                              (finRange φ_l) ++
                                            l))
                                        ↑i))
                                    (_ :
                                      Option.isSome
                                          (Option.join
                                            (get?
                                              (List.map Sum.getLeft
                                                (List.map
                                                    (fun i =>
                                                      Sum.inl
                                                        { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                    (finRange φ_l) ++
                                                  l))
                                              ↑i)) =
                                        true)).fst) =
                          Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                      (Option.get
                          (Option.join
                            (get?
                              (List.map Sum.getLeft
                                (List.map
                                    (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                    (finRange φ_l) ++
                                  l))
                              ↑i))
                          (_ :
                            Option.isSome
                                (Option.join
                                  (get?
                                    (List.map Sum.getLeft
                                      (List.map
                                          (fun i =>
                                            Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                          (finRange φ_l) ++
                                        l))
                                    ↑i)) =
                              true)).snd }
            else default
          else default,
          {
            val :=
              drop φ_l
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l),
            property :=
              (_ :
                SizeOf.sizeOf
                    (drop φ_l
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l)) ≤
                  max 1
                    (SizeOf.sizeOf
                      (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                        Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l)))) }).fst =
      { fst := φ_n, snd := rel φ_R ts } ∧
    ↑(if h :
                ∀ (i : Fin φ_l),
                  Option.isSome
                      (Option.join
                        (get?
                          (List.map Sum.getLeft
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l))
                          ↑i)) =
                    true then
              if h' :
                  ∀ (i : Fin φ_l),
                    (Option.get
                          (Option.join
                            (get?
                              (List.map Sum.getLeft
                                (List.map
                                    (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                    (finRange φ_l) ++
                                  l))
                              ↑i))
                          (_ :
                            Option.isSome
                                (Option.join
                                  (get?
                                    (List.map Sum.getLeft
                                      (List.map
                                          (fun i =>
                                            Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                          (finRange φ_l) ++
                                        l))
                                    ↑i)) =
                              true)).fst =
                      { fst := φ_n, snd := rel φ_R ts }.fst then
                { fst := { fst := φ_n, snd := rel φ_R ts }.fst,
                  snd :=
                    rel φ_R fun i =>
                      Eq.mp
                        (_ :
                          Term L
                              (α ⊕
                                Fin
                                  (Option.get
                                      (Option.join
                                        (get?
                                          (List.map Sum.getLeft
                                            (List.map
                                                (fun i =>
                                                  Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                (finRange φ_l) ++
                                              l))
                                          ↑i))
                                      (_ :
                                        Option.isSome
                                            (Option.join
                                              (get?
                                                (List.map Sum.getLeft
                                                  (List.map
                                                      (fun i =>
                                                        Sum.inl
                                                          { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                      (finRange φ_l) ++
                                                    l))
                                                ↑i)) =
                                          true)).fst) =
                            Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                        (Option.get
                            (Option.join
                              (get?
                                (List.map Sum.getLeft
                                  (List.map
                                      (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                      (finRange φ_l) ++
                                    l))
                                ↑i))
                            (_ :
                              Option.isSome
                                  (Option.join
                                    (get?
                                      (List.map Sum.getLeft
                                        (List.map
                                            (fun i =>
                                              Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                            (finRange φ_l) ++
                                          l))
                                      ↑i)) =
                                true)).snd }
              else default
            else default,
            {
              val :=
                drop φ_l
                  (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                      (finRange φ_l) ++
                    l),
              property :=
                (_ :
                  SizeOf.sizeOf
                      (drop φ_l
                        (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                            (finRange φ_l) ++
                          l)) ≤
                    max 1
                      (SizeOf.sizeOf
                        (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                          Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l)))) }).snd =
      l

tactic: swap
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ (if h' :
              ∀ (i : Fin φ_l),
                (Option.get
                      (Option.join
                        (get?
                          (List.map Sum.getLeft
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l))
                          ↑i))
                      (_ :
                        Option.isSome
                            (Option.join
                              (get?
                                (List.map Sum.getLeft
                                  (List.map
                                      (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                      (finRange φ_l) ++
                                    l))
                                ↑i)) =
                          true)).fst =
                  { fst := φ_n, snd := rel φ_R ts }.fst then
            { fst := { fst := φ_n, snd := rel φ_R ts }.fst,
              snd :=
                rel φ_R fun i =>
                  Eq.mp
                    (_ :
                      Term L
                          (α ⊕
                            Fin
                              (Option.get
                                  (Option.join
                                    (get?
                                      (List.map Sum.getLeft
                                        (List.map
                                            (fun i =>
                                              Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                            (finRange φ_l) ++
                                          l))
                                      ↑i))
                                  (_ :
                                    Option.isSome
                                        (Option.join
                                          (get?
                                            (List.map Sum.getLeft
                                              (List.map
                                                  (fun i =>
                                                    Sum.inl
                                                      { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                  (finRange φ_l) ++
                                                l))
                                            ↑i)) =
                                      true)).fst) =
                        Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                    (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).snd }
          else default,
          {
            val :=
              drop φ_l
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l),
            property :=
              (_ :
                SizeOf.sizeOf
                    (drop φ_l
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l)) ≤
                  max 1
                    (SizeOf.sizeOf
                      (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                        Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l)))) }).fst =
      { fst := φ_n, snd := rel φ_R ts } ∧
    ↑(if h' :
                ∀ (i : Fin φ_l),
                  (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).fst =
                    { fst := φ_n, snd := rel φ_R ts }.fst then
              { fst := { fst := φ_n, snd := rel φ_R ts }.fst,
                snd :=
                  rel φ_R fun i =>
                    Eq.mp
                      (_ :
                        Term L
                            (α ⊕
                              Fin
                                (Option.get
                                    (Option.join
                                      (get?
                                        (List.map Sum.getLeft
                                          (List.map
                                              (fun i =>
                                                Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                              (finRange φ_l) ++
                                            l))
                                        ↑i))
                                    (_ :
                                      Option.isSome
                                          (Option.join
                                            (get?
                                              (List.map Sum.getLeft
                                                (List.map
                                                    (fun i =>
                                                      Sum.inl
                                                        { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                    (finRange φ_l) ++
                                                  l))
                                              ↑i)) =
                                        true)).fst) =
                          Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                      (Option.get
                          (Option.join
                            (get?
                              (List.map Sum.getLeft
                                (List.map
                                    (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                    (finRange φ_l) ++
                                  l))
                              ↑i))
                          (_ :
                            Option.isSome
                                (Option.join
                                  (get?
                                    (List.map Sum.getLeft
                                      (List.map
                                          (fun i =>
                                            Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                          (finRange φ_l) ++
                                        l))
                                    ↑i)) =
                              true)).snd }
            else default,
            {
              val :=
                drop φ_l
                  (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                      (finRange φ_l) ++
                    l),
              property :=
                (_ :
                  SizeOf.sizeOf
                      (drop φ_l
                        (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                            (finRange φ_l) ++
                          l)) ≤
                    max 1
                      (SizeOf.sizeOf
                        (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                          Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l)))) }).snd =
      l

case h.mk.rel.hc
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ ∀ (i : Fin φ_l),
    Option.isSome
        (Option.join
          (get?
            (List.map Sum.getLeft
              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                  (finRange φ_l) ++
                l))
            ↑i)) =
      true

tactic: rw [dif_pos]
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ (if h' :
              ∀ (i : Fin φ_l),
                (Option.get
                      (Option.join
                        (get?
                          (List.map Sum.getLeft
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l))
                          ↑i))
                      (_ :
                        Option.isSome
                            (Option.join
                              (get?
                                (List.map Sum.getLeft
                                  (List.map
                                      (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                      (finRange φ_l) ++
                                    l))
                                ↑i)) =
                          true)).fst =
                  { fst := φ_n, snd := rel φ_R ts }.fst then
            { fst := { fst := φ_n, snd := rel φ_R ts }.fst,
              snd :=
                rel φ_R fun i =>
                  Eq.mp
                    (_ :
                      Term L
                          (α ⊕
                            Fin
                              (Option.get
                                  (Option.join
                                    (get?
                                      (List.map Sum.getLeft
                                        (List.map
                                            (fun i =>
                                              Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                            (finRange φ_l) ++
                                          l))
                                      ↑i))
                                  (_ :
                                    Option.isSome
                                        (Option.join
                                          (get?
                                            (List.map Sum.getLeft
                                              (List.map
                                                  (fun i =>
                                                    Sum.inl
                                                      { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                  (finRange φ_l) ++
                                                l))
                                            ↑i)) =
                                      true)).fst) =
                        Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                    (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).snd }
          else default,
          {
            val :=
              drop φ_l
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l),
            property :=
              (_ :
                SizeOf.sizeOf
                    (drop φ_l
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l)) ≤
                  max 1
                    (SizeOf.sizeOf
                      (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                        Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l)))) }).fst =
      { fst := φ_n, snd := rel φ_R ts } ∧
    ↑(if h' :
                ∀ (i : Fin φ_l),
                  (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).fst =
                    { fst := φ_n, snd := rel φ_R ts }.fst then
              { fst := { fst := φ_n, snd := rel φ_R ts }.fst,
                snd :=
                  rel φ_R fun i =>
                    Eq.mp
                      (_ :
                        Term L
                            (α ⊕
                              Fin
                                (Option.get
                                    (Option.join
                                      (get?
                                        (List.map Sum.getLeft
                                          (List.map
                                              (fun i =>
                                                Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                              (finRange φ_l) ++
                                            l))
                                        ↑i))
                                    (_ :
                                      Option.isSome
                                          (Option.join
                                            (get?
                                              (List.map Sum.getLeft
                                                (List.map
                                                    (fun i =>
                                                      Sum.inl
                                                        { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                    (finRange φ_l) ++
                                                  l))
                                              ↑i)) =
                                        true)).fst) =
                          Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                      (Option.get
                          (Option.join
                            (get?
                              (List.map Sum.getLeft
                                (List.map
                                    (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                    (finRange φ_l) ++
                                  l))
                              ↑i))
                          (_ :
                            Option.isSome
                                (Option.join
                                  (get?
                                    (List.map Sum.getLeft
                                      (List.map
                                          (fun i =>
                                            Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                          (finRange φ_l) ++
                                        l))
                                    ↑i)) =
                              true)).snd }
            else default,
            {
              val :=
                drop φ_l
                  (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                      (finRange φ_l) ++
                    l),
              property :=
                (_ :
                  SizeOf.sizeOf
                      (drop φ_l
                        (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                            (finRange φ_l) ++
                          l)) ≤
                    max 1
                      (SizeOf.sizeOf
                        (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                          Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l)))) }).snd =
      l

tactic: swap
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ ({ fst := { fst := φ_n, snd := rel φ_R ts }.fst,
            snd :=
              rel φ_R fun i =>
                Eq.mp
                  (_ :
                    Term L
                        (α ⊕
                          Fin
                            (Option.get
                                (Option.join
                                  (get?
                                    (List.map Sum.getLeft
                                      (List.map
                                          (fun i =>
                                            Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                          (finRange φ_l) ++
                                        l))
                                    ↑i))
                                (_ :
                                  Option.isSome
                                      (Option.join
                                        (get?
                                          (List.map Sum.getLeft
                                            (List.map
                                                (fun i =>
                                                  Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                (finRange φ_l) ++
                                              l))
                                          ↑i)) =
                                    true)).fst) =
                      Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                  (Option.get
                      (Option.join
                        (get?
                          (List.map Sum.getLeft
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l))
                          ↑i))
                      (_ :
                        Option.isSome
                            (Option.join
                              (get?
                                (List.map Sum.getLeft
                                  (List.map
                                      (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                      (finRange φ_l) ++
                                    l))
                                ↑i)) =
                          true)).snd },
          {
            val :=
              drop φ_l
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l),
            property :=
              (_ :
                SizeOf.sizeOf
                    (drop φ_l
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l)) ≤
                  max 1
                    (SizeOf.sizeOf
                      (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                        Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l)))) }).fst =
      { fst := φ_n, snd := rel φ_R ts } ∧
    ↑({ fst := { fst := φ_n, snd := rel φ_R ts }.fst,
              snd :=
                rel φ_R fun i =>
                  Eq.mp
                    (_ :
                      Term L
                          (α ⊕
                            Fin
                              (Option.get
                                  (Option.join
                                    (get?
                                      (List.map Sum.getLeft
                                        (List.map
                                            (fun i =>
                                              Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                            (finRange φ_l) ++
                                          l))
                                      ↑i))
                                  (_ :
                                    Option.isSome
                                        (Option.join
                                          (get?
                                            (List.map Sum.getLeft
                                              (List.map
                                                  (fun i =>
                                                    Sum.inl
                                                      { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                  (finRange φ_l) ++
                                                l))
                                            ↑i)) =
                                      true)).fst) =
                        Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                    (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).snd },
            {
              val :=
                drop φ_l
                  (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                      (finRange φ_l) ++
                    l),
              property :=
                (_ :
                  SizeOf.sizeOf
                      (drop φ_l
                        (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                            (finRange φ_l) ++
                          l)) ≤
                    max 1
                      (SizeOf.sizeOf
                        (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                          Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l)))) }).snd =
      l

case h.mk.rel.hc
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ ∀ (i : Fin φ_l),
    (Option.get
          (Option.join
            (get?
              (List.map Sum.getLeft
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l))
              ↑i))
          (_ :
            Option.isSome
                (Option.join
                  (get?
                    (List.map Sum.getLeft
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l))
                    ↑i)) =
              true)).fst =
      { fst := φ_n, snd := rel φ_R ts }.fst

tactic: simp only [Sigma.mk.inj_iff, heq_eq_eq, rel.injEq, true_and]
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ ({ fst := { fst := φ_n, snd := rel φ_R ts }.fst,
            snd :=
              rel φ_R fun i =>
                Eq.mp
                  (_ :
                    Term L
                        (α ⊕
                          Fin
                            (Option.get
                                (Option.join
                                  (get?
                                    (List.map Sum.getLeft
                                      (List.map
                                          (fun i =>
                                            Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                          (finRange φ_l) ++
                                        l))
                                    ↑i))
                                (_ :
                                  Option.isSome
                                      (Option.join
                                        (get?
                                          (List.map Sum.getLeft
                                            (List.map
                                                (fun i =>
                                                  Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                (finRange φ_l) ++
                                              l))
                                          ↑i)) =
                                    true)).fst) =
                      Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                  (Option.get
                      (Option.join
                        (get?
                          (List.map Sum.getLeft
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l))
                          ↑i))
                      (_ :
                        Option.isSome
                            (Option.join
                              (get?
                                (List.map Sum.getLeft
                                  (List.map
                                      (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                      (finRange φ_l) ++
                                    l))
                                ↑i)) =
                          true)).snd },
          {
            val :=
              drop φ_l
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l),
            property :=
              (_ :
                SizeOf.sizeOf
                    (drop φ_l
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l)) ≤
                  max 1
                    (SizeOf.sizeOf
                      (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                        Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l)))) }).fst =
      { fst := φ_n, snd := rel φ_R ts } ∧
    ↑({ fst := { fst := φ_n, snd := rel φ_R ts }.fst,
              snd :=
                rel φ_R fun i =>
                  Eq.mp
                    (_ :
                      Term L
                          (α ⊕
                            Fin
                              (Option.get
                                  (Option.join
                                    (get?
                                      (List.map Sum.getLeft
                                        (List.map
                                            (fun i =>
                                              Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                            (finRange φ_l) ++
                                          l))
                                      ↑i))
                                  (_ :
                                    Option.isSome
                                        (Option.join
                                          (get?
                                            (List.map Sum.getLeft
                                              (List.map
                                                  (fun i =>
                                                    Sum.inl
                                                      { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                                  (finRange φ_l) ++
                                                l))
                                            ↑i)) =
                                      true)).fst) =
                        Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
                    (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).snd },
            {
              val :=
                drop φ_l
                  (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                      (finRange φ_l) ++
                    l),
              property :=
                (_ :
                  SizeOf.sizeOf
                      (drop φ_l
                        (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                            (finRange φ_l) ++
                          l)) ≤
                    max 1
                      (SizeOf.sizeOf
                        (Sum.inr (Sum.inl { fst := φ_l, snd := φ_R }) ::
                          Sum.inr (Sum.inr { fst := φ_n, snd := rel φ_R ts }.fst) ::
                            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                (finRange φ_l) ++
                              l)))) }).snd =
      l

tactic: refine' ⟨funext fun i => _, _⟩
state_before: case h.mk.rel
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ (fun i =>
        Eq.mp
          (_ :
            Term L
                (α ⊕
                  Fin
                    (Option.get
                        (Option.join
                          (get?
                            (List.map Sum.getLeft
                              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                  (finRange φ_l) ++
                                l))
                            ↑i))
                        (_ :
                          Option.isSome
                              (Option.join
                                (get?
                                  (List.map Sum.getLeft
                                    (List.map
                                        (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                        (finRange φ_l) ++
                                      l))
                                  ↑i)) =
                            true)).fst) =
              Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
          (Option.get
              (Option.join
                (get?
                  (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
                  ↑i))
              (_ :
                Option.isSome
                    (Option.join
                      (get?
                        (List.map Sum.getLeft
                          (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
                        ↑i)) =
                  true)).snd) =
      ts ∧
    drop φ_l (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l) = l

tactic: rw [List.drop_append_eq_append_drop, length_map, length_finRange, Nat.sub_self, drop,
  drop_eq_nil_of_le, nil_append]
state_before: case h.mk.rel.refine'_2
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ drop φ_l (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l) = l

tactic: rw [length_map, length_finRange]
state_before: case h.mk.rel.refine'_2
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ length (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l)) ≤ φ_l

tactic: intro i
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }

tactic: simp only [Option.join, map_append, map_map, Option.bind_eq_some, id.def, exists_eq_right,
  get?_eq_some, length_append, length_map, length_finRange]
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
i : Fin φ_l
⊢ Option.join
      (get?
        (List.map Sum.getLeft
          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
            l))
        ↑i) =
    some { fst := φ_n, snd := ts i }

tactic: refine' ⟨lt_of_lt_of_le i.2 le_self_add, _⟩
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
i : Fin φ_l
⊢ ∃ h,
    List.get
        (List.map (Sum.getLeft ∘ fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ List.map Sum.getLeft l)
        { val := ↑i,
          isLt :=
            (_ :
              ↑i <
                length
                  (List.map (Sum.getLeft ∘ fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++
                    List.map Sum.getLeft l)) } =
      some { fst := φ_n, snd := ts i }

tactic: rw [get_append, get_map]
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
i : Fin φ_l
⊢ List.get
      (List.map (Sum.getLeft ∘ fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ List.map Sum.getLeft l)
      { val := ↑i,
        isLt :=
          (_ :
            ↑i <
              length
                (List.map (Sum.getLeft ∘ fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++
                  List.map Sum.getLeft l)) } =
    some { fst := φ_n, snd := ts i }

tactic: simp only [Sum.getLeft, get_finRange, Fin.eta, Function.comp_apply, eq_self_iff_true,
  heq_iff_eq, and_self_iff]
state_before: L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
i : Fin φ_l
⊢ (Sum.getLeft ∘ fun i => Sum.inl { fst := φ_n, snd := ts i })
      (List.get (finRange φ_l)
        { val := ↑{ val := ↑i, isLt := ?h }, isLt := (_ : ↑{ val := ↑i, isLt := ?h } < length (finRange φ_l)) }) =
    some { fst := φ_n, snd := ts i }

tactic: simp only [length_map, length_finRange, is_lt]
state_before: case h
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
i : Fin φ_l
⊢ ↑i < length (List.map (Sum.getLeft ∘ fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l))

tactic: exact fun i => Option.isSome_iff_exists.2 ⟨⟨_, ts i⟩, h i⟩
state_before: case h.mk.rel.hc
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ ∀ (i : Fin φ_l),
    Option.isSome
        (Option.join
          (get?
            (List.map Sum.getLeft
              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                  (finRange φ_l) ++
                l))
            ↑i)) =
      true

tactic: intro i
state_before: case h.mk.rel.hc
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
⊢ ∀ (i : Fin φ_l),
    (Option.get
          (Option.join
            (get?
              (List.map Sum.getLeft
                (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                    (finRange φ_l) ++
                  l))
              ↑i))
          (_ :
            Option.isSome
                (Option.join
                  (get?
                    (List.map Sum.getLeft
                      (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                          (finRange φ_l) ++
                        l))
                    ↑i)) =
              true)).fst =
      { fst := φ_n, snd := rel φ_R ts }.fst

tactic: obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i)
state_before: case h.mk.rel.hc
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
i : Fin φ_l
⊢ (Option.get
        (Option.join
          (get?
            (List.map Sum.getLeft
              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                  (finRange φ_l) ++
                l))
            ↑i))
        (_ :
          Option.isSome
              (Option.join
                (get?
                  (List.map Sum.getLeft
                    (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                        (finRange φ_l) ++
                      l))
                  ↑i)) =
            true)).fst =
    { fst := φ_n, snd := rel φ_R ts }.fst

tactic: rw [h2]
state_before: case h.mk.rel.hc.intro
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
i : Fin φ_l
h1 :
  Option.isSome
      (Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i)) =
    true
h2 :
  Option.get
      (Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i))
      h1 =
    { fst := φ_n, snd := ts i }
⊢ (Option.get
        (Option.join
          (get?
            (List.map Sum.getLeft
              (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                  (finRange φ_l) ++
                l))
            ↑i))
        (_ :
          Option.isSome
              (Option.join
                (get?
                  (List.map Sum.getLeft
                    (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                        (finRange φ_l) ++
                      l))
                  ↑i)) =
            true)).fst =
    { fst := φ_n, snd := rel φ_R ts }.fst

tactic: obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i)
state_before: case h.mk.rel.refine'_1
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
i : Fin φ_l
⊢ Eq.mp
      (_ :
        Term L
            (α ⊕
              Fin
                (Option.get
                    (Option.join
                      (get?
                        (List.map Sum.getLeft
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l))
                        ↑i))
                    (_ :
                      Option.isSome
                          (Option.join
                            (get?
                              (List.map Sum.getLeft
                                (List.map
                                    (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                    (finRange φ_l) ++
                                  l))
                              ↑i)) =
                        true)).fst) =
          Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
      (Option.get
          (Option.join
            (get? (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
              ↑i))
          (_ :
            Option.isSome
                (Option.join
                  (get?
                    (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
                    ↑i)) =
              true)).snd =
    ts i

tactic: rw [eq_mp_eq_cast, cast_eq_iff_heq]
state_before: case h.mk.rel.refine'_1.intro
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
i : Fin φ_l
h1 :
  Option.isSome
      (Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i)) =
    true
h2 :
  Option.get
      (Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i))
      h1 =
    { fst := φ_n, snd := ts i }
⊢ Eq.mp
      (_ :
        Term L
            (α ⊕
              Fin
                (Option.get
                    (Option.join
                      (get?
                        (List.map Sum.getLeft
                          (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                              (finRange φ_l) ++
                            l))
                        ↑i))
                    (_ :
                      Option.isSome
                          (Option.join
                            (get?
                              (List.map Sum.getLeft
                                (List.map
                                    (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i })
                                    (finRange φ_l) ++
                                  l))
                              ↑i)) =
                        true)).fst) =
          Term L (α ⊕ Fin { fst := φ_n, snd := rel φ_R ts }.fst))
      (Option.get
          (Option.join
            (get? (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
              ↑i))
          (_ :
            Option.isSome
                (Option.join
                  (get?
                    (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
                    ↑i)) =
              true)).snd =
    ts i

tactic: exact (Sigma.ext_iff.1 ((Sigma.eta (Option.get _ h1)).trans h2)).2
state_before: case h.mk.rel.refine'_1.intro
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n φ_n φ_l : ℕ
φ_R : Relations L φ_l
ts : Fin φ_l → Term L (α ⊕ Fin φ_n)
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
h :
  ∀ (i : Fin φ_l),
    Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i) =
      some { fst := φ_n, snd := ts i }
i : Fin φ_l
h1 :
  Option.isSome
      (Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i)) =
    true
h2 :
  Option.get
      (Option.join
        (get?
          (List.map Sum.getLeft
            (List.map (fun i => Sum.inl { fst := { fst := φ_n, snd := rel φ_R ts }.fst, snd := ts i }) (finRange φ_l) ++
              l))
          ↑i))
      h1 =
    { fst := φ_n, snd := ts i }
⊢ HEq
    (Option.get
        (Option.join
          (get? (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
            ↑i))
        (_ :
          Option.isSome
              (Option.join
                (get?
                  (List.map Sum.getLeft (List.map (fun i => Sum.inl { fst := φ_n, snd := ts i }) (finRange φ_l) ++ l))
                  ↑i)) =
            true)).snd
    (ts i)

tactic: rw [listEncode, List.append_assoc, cons_append, listDecode]
state_before: case h.mk.imp
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f₁✝ f₂✝ : BoundedFormula L α n✝
ih1 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝, snd := f₁✝ }.snd ++ l)).fst = { fst := n✝, snd := f₁✝ } ∧
      ↑(listDecode (listEncode { fst := n✝, snd := f₁✝ }.snd ++ l)).snd = l
ih2 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝, snd := f₂✝ }.snd ++ l)).fst = { fst := n✝, snd := f₂✝ } ∧
      ↑(listDecode (listEncode { fst := n✝, snd := f₂✝ }.snd ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (listDecode (listEncode { fst := n✝, snd := f₁✝ ⟹ f₂✝ }.snd ++ l)).fst = { fst := n✝, snd := f₁✝ ⟹ f₂✝ } ∧
    ↑(listDecode (listEncode { fst := n✝, snd := f₁✝ ⟹ f₂✝ }.snd ++ l)).snd = l

tactic: simp only [] at *
state_before: case h.mk.imp
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f₁✝ f₂✝ : BoundedFormula L α n✝
ih1 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝, snd := f₁✝ }.snd ++ l)).fst = { fst := n✝, snd := f₁✝ } ∧
      ↑(listDecode (listEncode { fst := n✝, snd := f₁✝ }.snd ++ l)).snd = l
ih2 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝, snd := f₂✝ }.snd ++ l)).fst = { fst := n✝, snd := f₂✝ } ∧
      ↑(listDecode (listEncode { fst := n✝, snd := f₂✝ }.snd ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ ((fun this =>
            (sigmaImp (listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).fst
                (listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).fst,
              { val := ↑(listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).snd,
                property :=
                  (_ :
                    SizeOf.sizeOf ↑(listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).snd ≤
                      max 1 (SizeOf.sizeOf (Sum.inr (Sum.inr 0) :: (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))))) }))
          (_ :
            SizeOf.sizeOf ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd <
              1 + (1 + 1) + SizeOf.sizeOf (listEncode f₁✝ ++ (listEncode f₂✝ ++ l)))).fst =
      { fst := n✝, snd := f₁✝ ⟹ f₂✝ } ∧
    ↑((fun this =>
              (sigmaImp (listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).fst
                  (listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).fst,
                { val := ↑(listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).snd,
                  property :=
                    (_ :
                      SizeOf.sizeOf ↑(listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).snd ≤
                        max 1 (SizeOf.sizeOf (Sum.inr (Sum.inr 0) :: (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))))) }))
            (_ :
              SizeOf.sizeOf ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd <
                1 + (1 + 1) + SizeOf.sizeOf (listEncode f₁✝ ++ (listEncode f₂✝ ++ l)))).snd =
      l

tactic: rw [(ih1 _).1, (ih1 _).2, (ih2 _).1, (ih2 _).2, sigmaImp]
state_before: case h.mk.imp
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f₁✝ f₂✝ : BoundedFormula L α n✝
ih1 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f₁✝ ++ l)).fst = { fst := n✝, snd := f₁✝ } ∧ ↑(listDecode (listEncode f₁✝ ++ l)).snd = l
ih2 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f₂✝ ++ l)).fst = { fst := n✝, snd := f₂✝ } ∧ ↑(listDecode (listEncode f₂✝ ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ sigmaImp (listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).fst
        (listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).fst =
      { fst := n✝, snd := f₁✝ ⟹ f₂✝ } ∧
    ↑(listDecode ↑(listDecode (listEncode f₁✝ ++ (listEncode f₂✝ ++ l))).snd).snd = l

tactic: simp only [dite_true]
state_before: case h.mk.imp
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f₁✝ f₂✝ : BoundedFormula L α n✝
ih1 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f₁✝ ++ l)).fst = { fst := n✝, snd := f₁✝ } ∧ ↑(listDecode (listEncode f₁✝ ++ l)).snd = l
ih2 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f₂✝ ++ l)).fst = { fst := n✝, snd := f₂✝ } ∧ ↑(listDecode (listEncode f₂✝ ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (match { fst := n✝, snd := f₁✝ }, { fst := n✝, snd := f₂✝ } with
      | { fst := m, snd := φ }, { fst := n, snd := ψ } =>
        if h : m = n then { fst := m, snd := φ ⟹ Eq.mp (_ : BoundedFormula L α n = BoundedFormula L α m) ψ }
        else default) =
      { fst := n✝, snd := f₁✝ ⟹ f₂✝ } ∧
    l = l

tactic: exact ⟨rfl, trivial⟩
state_before: case h.mk.imp
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f₁✝ f₂✝ : BoundedFormula L α n✝
ih1 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f₁✝ ++ l)).fst = { fst := n✝, snd := f₁✝ } ∧ ↑(listDecode (listEncode f₁✝ ++ l)).snd = l
ih2 :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f₂✝ ++ l)).fst = { fst := n✝, snd := f₂✝ } ∧ ↑(listDecode (listEncode f₂✝ ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ { fst := n✝, snd := f₁✝ ⟹ Eq.mp (_ : BoundedFormula L α n✝ = BoundedFormula L α n✝) f₂✝ } =
      { fst := n✝, snd := f₁✝ ⟹ f₂✝ } ∧
    True

tactic: rw [listEncode, cons_append, listDecode]
state_before: case h.mk.all
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝ + 1, snd := f✝ }.snd ++ l)).fst = { fst := n✝ + 1, snd := f✝ } ∧
      ↑(listDecode (listEncode { fst := n✝ + 1, snd := f✝ }.snd ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (listDecode (listEncode { fst := n✝, snd := ∀'f✝ }.snd ++ l)).fst = { fst := n✝, snd := ∀'f✝ } ∧
    ↑(listDecode (listEncode { fst := n✝, snd := ∀'f✝ }.snd ++ l)).snd = l

tactic: simp only
state_before: case h.mk.all
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝ + 1, snd := f✝ }.snd ++ l)).fst = { fst := n✝ + 1, snd := f✝ } ∧
      ↑(listDecode (listEncode { fst := n✝ + 1, snd := f✝ }.snd ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (sigmaAll (listDecode (listEncode f✝ ++ l)).fst,
          { val := ↑(listDecode (listEncode f✝ ++ l)).snd,
            property :=
              (_ :
                SizeOf.sizeOf ↑(listDecode (listEncode f✝ ++ l)).snd ≤
                  max 1 (SizeOf.sizeOf (Sum.inr (Sum.inr 1) :: (listEncode f✝ ++ l)))) }).fst =
      { fst := n✝, snd := ∀'f✝ } ∧
    ↑(sigmaAll (listDecode (listEncode f✝ ++ l)).fst,
            { val := ↑(listDecode (listEncode f✝ ++ l)).snd,
              property :=
                (_ :
                  SizeOf.sizeOf ↑(listDecode (listEncode f✝ ++ l)).snd ≤
                    max 1 (SizeOf.sizeOf (Sum.inr (Sum.inr 1) :: (listEncode f✝ ++ l)))) }).snd =
      l

tactic: simp only [] at *
state_before: case h.mk.all
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode { fst := n✝ + 1, snd := f✝ }.snd ++ l)).fst = { fst := n✝ + 1, snd := f✝ } ∧
      ↑(listDecode (listEncode { fst := n✝ + 1, snd := f✝ }.snd ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ sigmaAll (listDecode (listEncode f✝ ++ l)).fst = { fst := n✝, snd := ∀'f✝ } ∧
    ↑(listDecode (listEncode f✝ ++ l)).snd = l

tactic: rw [(ih _).1, (ih _).2, sigmaAll]
state_before: case h.mk.all
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f✝ ++ l)).fst = { fst := n✝ + 1, snd := f✝ } ∧ ↑(listDecode (listEncode f✝ ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ sigmaAll (listDecode (listEncode f✝ ++ l)).fst = { fst := n✝, snd := ∀'f✝ } ∧
    ↑(listDecode (listEncode f✝ ++ l)).snd = l

tactic: exact ⟨rfl, rfl⟩
state_before: case h.mk.all
L : Language
M : Type w
N : Type ?u.139469
P : Type ?u.139472
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List ((n : ℕ) × BoundedFormula L α n)
n n✝ : ℕ
f✝ : BoundedFormula L α (n✝ + 1)
ih :
  ∀ (l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)),
    (listDecode (listEncode f✝ ++ l)).fst = { fst := n✝ + 1, snd := f✝ } ∧ ↑(listDecode (listEncode f✝ ++ l)).snd = l
l : List ((k : ℕ) × Term L (α ⊕ Fin k) ⊕ (n : ℕ) × Relations L n ⊕ ℕ)
⊢ (match { fst := n✝ + 1, snd := f✝ } with
      | { fst := Nat.succ n, snd := φ } => { fst := n, snd := ∀'φ }
      | x => default) =
      { fst := n✝, snd := ∀'f✝ } ∧
    l = l