l3lab/ntp-mathlib huggingface dataset:
theorem listDecode_encode_list (l : List (L.Term α)) :
    listDecode (l.bind listEncode) = l.map Option.some := by
  suffices h : ∀ (t : L.Term α) (l : List (Sum α (Σi, L.Functions i))),
      listDecode (t.listEncode ++ l) = some t::listDecode l
  · induction' l with t l lih
    · rfl
    · rw [cons_bind, h t (l.bind listEncode), lih, List.map]
  · intro t
    induction' t with a n f ts ih <;> intro l
    · rw [listEncode, singleton_append, listDecode]
    · rw [listEncode, cons_append, listDecode]
      have h : listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l) =
          (finRange n).map (Option.some ∘ ts) ++ listDecode l := by
        induction' finRange n with i l' l'ih
        · rfl
        · rw [cons_bind, List.append_assoc, ih, map_cons, l'ih, cons_append, Function.comp]
      have h' : ∀ i : Fin n,
          (listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l)).get? ↑i =
            some (some (ts i)) := by
        intro i
        rw [h, get?_append, get?_map]
        · simp only [Option.map_eq_some', Function.comp_apply, get?_eq_some]
          refine' ⟨i, ⟨lt_of_lt_of_le i.2 (ge_of_eq (length_finRange _)), _⟩, rfl⟩
          rw [get_finRange, Fin.eta]
        · refine' lt_of_lt_of_le i.2 _
          simp
      refine' (dif_pos fun i => Option.isSome_iff_exists.2 ⟨ts i, _⟩).trans _
      · rw [Option.join_eq_some, h']
      refine' congr (congr rfl (congr rfl (congr rfl (funext fun i => Option.get_of_mem _ _)))) _
      · simp [h']
      · 

Proof state:
case h.func.refine'_2.refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List (Term L α)
n : ℕ
f : Functions L n
ts : Fin n → Term L α
ih :
  ∀ (a : Fin n) (l : List (α ⊕ (i : ℕ) × Functions L i)),
    listDecode (listEncode (ts a) ++ l) = some (ts a) :: listDecode l
l : List (α ⊕ (i : ℕ) × Functions L i)
h :
  listDecode ((List.bind (finRange n) fun i => listEncode (ts i)) ++ l) =
    List.map (some ∘ ts) (finRange n) ++ listDecode l
h' : ∀ (i : Fin n), get? (listDecode ((List.bind (finRange n) fun i => listEncode (ts i)) ++ l)) ↑i = some (some (ts i))
⊢ drop n (listDecode ((List.bind (finRange n) fun i => listEncode (ts i)) ++ l)) = listDecode l

Next tactic:
rw [h, drop_left']
theorem listDecode_encode_list (l : List (L.Term α)) :
    listDecode (l.bind listEncode) = l.map Option.some := by
  suffices h : ∀ (t : L.Term α) (l : List (Sum α (Σi, L.Functions i))),
      listDecode (t.listEncode ++ l) = some t::listDecode l
  · induction' l with t l lih
    · rfl
    · rw [cons_bind, h t (l.bind listEncode), lih, List.map]
  · intro t
    induction' t with a n f ts ih <;> intro l
    · rw [listEncode, singleton_append, listDecode]
    · rw [listEncode, cons_append, listDecode]
      have h : listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l) =
          (finRange n).map (Option.some ∘ ts) ++ listDecode l := by
        induction' finRange n with i l' l'ih
        · rfl
        · rw [cons_bind, List.append_assoc, ih, map_cons, l'ih, cons_append, Function.comp]
      have h' : ∀ i : Fin n,
          (listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l)).get? ↑i =
            some (some (ts i)) := by
        intro i
        rw [h, get?_append, get?_map]
        · simp only [Option.map_eq_some', Function.comp_apply, get?_eq_some]
          refine' ⟨i, ⟨lt_of_lt_of_le i.2 (ge_of_eq (length_finRange _)), _⟩, rfl⟩
          rw [get_finRange, Fin.eta]
        · refine' lt_of_lt_of_le i.2 _
          simp
      refine' (dif_pos fun i => Option.isSome_iff_exists.2 ⟨ts i, _⟩).trans _
      · rw [Option.join_eq_some, h']
      refine' congr (congr rfl (congr rfl (congr rfl (funext fun i => Option.get_of_mem _ _)))) _
      · simp [h']
      · rw [h, drop_left']
        

Proof state:
case h.func.refine'_2.refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
l✝ : List (Term L α)
n : ℕ
f : Functions L n
ts : Fin n → Term L α
ih :
  ∀ (a : Fin n) (l : List (α ⊕ (i : ℕ) × Functions L i)),
    listDecode (listEncode (ts a) ++ l) = some (ts a) :: listDecode l
l : List (α ⊕ (i : ℕ) × Functions L i)
h :
  listDecode ((List.bind (finRange n) fun i => listEncode (ts i)) ++ l) =
    List.map (some ∘ ts) (finRange n) ++ listDecode l
h' : ∀ (i : Fin n), get? (listDecode ((List.bind (finRange n) fun i => listEncode (ts i)) ++ l)) ↑i = some (some (ts i))
⊢ length (List.map (some ∘ ts) (finRange n)) = n

Next tactic:
rw [length_map, length_finRange]
/-- An encoding of terms as lists. -/
@[simps]
protected def encoding : Encoding (L.Term α) where
  Γ := Sum α (Σi, L.Functions i)
  encode := listEncode
  decode l := (listDecode l).head?.join
  decode_encode t := by
    

Proof state:
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
t : Term L α
⊢ (fun l => Option.join (head? (listDecode l))) (listEncode t) = some t

Next tactic:
have h := listDecode_encode_list [t]
/-- An encoding of terms as lists. -/
@[simps]
protected def encoding : Encoding (L.Term α) where
  Γ := Sum α (Σi, L.Functions i)
  encode := listEncode
  decode l := (listDecode l).head?.join
  decode_encode t := by
    have h := listDecode_encode_list [t]
    

Proof state:
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
t : Term L α
h : listDecode (List.bind [t] listEncode) = List.map some [t]
⊢ (fun l => Option.join (head? (listDecode l))) (listEncode t) = some t

Next tactic:
rw [bind_singleton] at h
/-- An encoding of terms as lists. -/
@[simps]
protected def encoding : Encoding (L.Term α) where
  Γ := Sum α (Σi, L.Functions i)
  encode := listEncode
  decode l := (listDecode l).head?.join
  decode_encode t := by
    have h := listDecode_encode_list [t]
    rw [bind_singleton] at h
    

Proof state:
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
t : Term L α
h : listDecode (listEncode t) = List.map some [t]
⊢ (fun l => Option.join (head? (listDecode l))) (listEncode t) = some t

Next tactic:
simp only [h, Option.join, head?, List.map, Option.some_bind, id.def]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  

Proof state:
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ #((n : ℕ) × Term L (α ⊕ Fin n)) = max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
refine' le_antisymm _ _
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · 

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ #((n : ℕ) × Term L (α ⊕ Fin n)) ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
rw [mk_sigma]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ (Cardinal.sum fun i => #(Term L (α ⊕ Fin i))) ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
refine' (sum_le_iSup_lift _).trans _
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ lift.{max u u', 0} #ℕ * ⨆ i, #(Term L (α ⊕ Fin i)) ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · 

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ ℵ₀ ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i) ∧ ∀ (i : ℕ), #(Term L (α ⊕ Fin i)) ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
i : ℕ
⊢ max ℵ₀ #((α ⊕ Fin i) ⊕ (i : ℕ) × Functions L i) ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
refine' max_le (le_max_left _ _) _
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
i : ℕ
⊢ #((α ⊕ Fin i) ⊕ (i : ℕ) × Functions L i) ≤ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i)

Next tactic:
rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
i : ℕ
⊢ ↑i + (lift.{u, u'} #α + lift.{u', u} #((i : ℕ) × Functions L i)) ≤
    ℵ₀ + (lift.{u, u'} #α + lift.{u', u} #((i : ℕ) × Functions L i))

Next tactic:
exact add_le_add_right (nat_lt_aleph0 _).le _
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · 

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ ⨆ i, #(Term L (α ⊕ Fin i)) ≠ 0

Next tactic:
rw [← one_le_iff_ne_zero]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ 1 ≤ ⨆ i, #(Term L (α ⊕ Fin i))

Next tactic:
refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ 1 ≤ #(Term L (α ⊕ Fin 1))

Next tactic:
rw [one_le_iff_ne_zero, mk_ne_zero_iff]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      

Proof state:
case refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ Nonempty (Term L (α ⊕ Fin 1))

Next tactic:
exact ⟨var (Sum.inr 0)⟩
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · 

Proof state:
case refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ max ℵ₀ #(α ⊕ (i : ℕ) × Functions L i) ≤ #((n : ℕ) × Term L (α ⊕ Fin n))

Next tactic:
rw [max_le_iff, ← infinite_iff]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · rw [max_le_iff, ← infinite_iff]
    

Proof state:
case refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ Infinite ((n : ℕ) × Term L (α ⊕ Fin n)) ∧ #(α ⊕ (i : ℕ) × Functions L i) ≤ #((n : ℕ) × Term L (α ⊕ Fin n))

Next tactic:
refine' ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => _, _⟩
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · rw [max_le_iff, ← infinite_iff]
    refine' ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => _, _⟩
    · 

Proof state:
case refine'_2.refine'_1
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
i j : ℕ
ij : (fun i => { fst := i + 1, snd := var (Sum.inr ↑i) }) i = (fun i => { fst := i + 1, snd := var (Sum.inr ↑i) }) j
⊢ i = j

Next tactic:
cases ij
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · rw [max_le_iff, ← infinite_iff]
    refine' ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => _, _⟩
    · cases ij
      

Proof state:
case refine'_2.refine'_1.refl
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
i : ℕ
⊢ i = i

Next tactic:
rfl
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · rw [max_le_iff, ← infinite_iff]
    refine' ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => _, _⟩
    · cases ij
      rfl
    · 

Proof state:
case refine'_2.refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ #(α ⊕ (i : ℕ) × Functions L i) ≤ #((n : ℕ) × Term L (α ⊕ Fin n))

Next tactic:
rw [Cardinal.le_def]
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · rw [max_le_iff, ← infinite_iff]
    refine' ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => _, _⟩
    · cases ij
      rfl
    · rw [Cardinal.le_def]
      

Proof state:
case refine'_2.refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ Nonempty (α ⊕ (i : ℕ) × Functions L i ↪ (n : ℕ) × Term L (α ⊕ Fin n))

Next tactic:
refine' ⟨⟨Sum.elim (fun i => ⟨0, var (Sum.inl i)⟩)
        fun F => ⟨1, func F.2 fun _ => var (Sum.inr 0)⟩, _⟩⟩
theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by
  refine' le_antisymm _ _
  · rw [mk_sigma]
    refine' (sum_le_iSup_lift _).trans _
    rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
      ciSup_le_iff' (bddAbove_range _)]
    · refine' ⟨le_max_left _ _, fun i => card_le.trans _⟩
      refine' max_le (le_max_left _ _) _
      rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
        add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
      exact add_le_add_right (nat_lt_aleph0 _).le _
    · rw [← one_le_iff_ne_zero]
      refine' _root_.trans _ (le_ciSup (bddAbove_range _) 1)
      rw [one_le_iff_ne_zero, mk_ne_zero_iff]
      exact ⟨var (Sum.inr 0)⟩
  · rw [max_le_iff, ← infinite_iff]
    refine' ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => _, _⟩
    · cases ij
      rfl
    · rw [Cardinal.le_def]
      refine' ⟨⟨Sum.elim (fun i => ⟨0, var (Sum.inl i)⟩)
        fun F => ⟨1, func F.2 fun _ => var (Sum.inr 0)⟩, _⟩⟩
      · 

Proof state:
case refine'_2.refine'_2
L : Language
M : Type w
N : Type u_1
P : Type u_2
inst✝² : Structure L M
inst✝¹ : Structure L N
inst✝ : Structure L P
α : Type u'
β : Type v'
⊢ Function.Injective
    (Sum.elim (fun i => { fst := 0, snd := var (Sum.inl i) }) fun F =>
      { fst := 1, snd := func F.snd fun x => var (Sum.inr 0) })

Next tactic:
rintro (a | a) (b | b) h