formal
stringlengths
41
427k
informal
stringclasses
1 value
Array.size_ofFn_go ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α ⊢ size (ofFn.go f i acc) = size acc + (n - i) ** if hin : i < n then unfold ofFn.go have : 1 + (n - (i + 1)) = n - i := Nat.sub_sub .. ▸ Nat.add_sub_cancel' (Nat.le_sub_of_add_le (Nat.add_comm .. ▸ hin)) rw [dif_pos hin, size_ofFn_go f (i+1), size_push, Nat.add_assoc, this] else have : n - i = 0 := Nat.sub_eq_zero_of_le (Nat.le_of_not_lt hin) unfold ofFn.go simp [hin, this] ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α hin : i < n ⊢ size (ofFn.go f i acc) = size acc + (n - i) ** unfold ofFn.go ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α hin : i < n ⊢ size (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc) = size acc + (n - i) ** have : 1 + (n - (i + 1)) = n - i := Nat.sub_sub .. ▸ Nat.add_sub_cancel' (Nat.le_sub_of_add_le (Nat.add_comm .. ▸ hin)) ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α hin : i < n this : 1 + (n - (i + 1)) = n - i ⊢ size (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc) = size acc + (n - i) ** rw [dif_pos hin, size_ofFn_go f (i+1), size_push, Nat.add_assoc, this] ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α hin : ¬i < n ⊢ size (ofFn.go f i acc) = size acc + (n - i) ** have : n - i = 0 := Nat.sub_eq_zero_of_le (Nat.le_of_not_lt hin) ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α hin : ¬i < n this : n - i = 0 ⊢ size (ofFn.go f i acc) = size acc + (n - i) ** unfold ofFn.go ** α : Type u_1 n : Nat f : Fin n → α i : Nat acc : Array α hin : ¬i < n this : n - i = 0 ⊢ size (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc) = size acc + (n - i) ** simp [hin, this] ** Qed
Array.size_ofFn ** n : Nat α : Type u_1 f : Fin n → α ⊢ size (ofFn f) = n ** simp [ofFn] ** Qed
Array.getElem_ofFn_go ** n : Nat α : Type ?u.103683 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } this : size acc + (n - size acc) = n ⊢ k < size (ofFn.go f i acc) ** simp [*] ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } ⊢ (ofFn.go f i acc)[k] = f { val := k, isLt := hki } ** unfold ofFn.go ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } ⊢ (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc)[k] = f { val := k, isLt := hki } ** if hin : i < n then have : 1 + (n - (i + 1)) = n - i := Nat.sub_sub .. ▸ Nat.add_sub_cancel' (Nat.le_sub_of_add_le (Nat.add_comm .. ▸ hin)) simp only [dif_pos hin] rw [getElem_ofFn_go f (i+1) _ hin (by simp [*]) (fun j hj => ?hacc)] cases (Nat.lt_or_eq_of_le <| Nat.le_of_lt_succ (by simpa using hj)) with | inl hj => simp [get_push, hj, hacc j hj] | inr hj => simp [get_push, *] else simp [hin, hacc k (Nat.lt_of_lt_of_le hki (Nat.le_of_not_lt (hi ▸ hin)))] ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n ⊢ (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc)[k] = f { val := k, isLt := hki } ** have : 1 + (n - (i + 1)) = n - i := Nat.sub_sub .. ▸ Nat.add_sub_cancel' (Nat.le_sub_of_add_le (Nat.add_comm .. ▸ hin)) ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i ⊢ (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc)[k] = f { val := k, isLt := hki } ** simp only [dif_pos hin] ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i ⊢ (ofFn.go f (i + 1) (push acc (f { val := i, isLt := hin })))[k] = f { val := k, isLt := hki } ** rw [getElem_ofFn_go f (i+1) _ hin (by simp [*]) (fun j hj => ?hacc)] ** case hacc n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i j : Nat hj : j < size (push acc (f { val := i, isLt := hin })) ⊢ (push acc (f { val := i, isLt := hin }))[j] = f { val := j, isLt := (_ : j < n) } ** cases (Nat.lt_or_eq_of_le <| Nat.le_of_lt_succ (by simpa using hj)) with | inl hj => simp [get_push, hj, hacc j hj] | inr hj => simp [get_push, *] ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i ⊢ i + 1 = size (push acc (f { val := i, isLt := hin })) ** simp [*] ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i j : Nat hj : j < size (push acc (f { val := i, isLt := hin })) ⊢ ?m.105816 < Nat.succ ?m.105817 ** simpa using hj ** case hacc.inl n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i j : Nat hj✝ : j < size (push acc (f { val := i, isLt := hin })) hj : j < size acc ⊢ (push acc (f { val := i, isLt := hin }))[j] = f { val := j, isLt := (_ : j < n) } ** simp [get_push, hj, hacc j hj] ** case hacc.inr n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : i < n this : 1 + (n - (i + 1)) = n - i j : Nat hj✝ : j < size (push acc (f { val := i, isLt := hin })) hj : j = size acc ⊢ (push acc (f { val := i, isLt := hin }))[j] = f { val := j, isLt := (_ : j < n) } ** simp [get_push, *] ** n : Nat α : Type u_1 f : Fin n → α i : Nat acc : Array α k : Nat hki : k < n hin✝ : i ≤ n hi : i = size acc hacc : ∀ (j : Nat) (hj : j < size acc), acc[j] = f { val := j, isLt := (_ : j < n) } hin : ¬i < n ⊢ (if h : i < n then ofFn.go f (i + 1) (push acc (f { val := i, isLt := h })) else acc)[k] = f { val := k, isLt := hki } ** simp [hin, hacc k (Nat.lt_of_lt_of_le hki (Nat.le_of_not_lt (hi ▸ hin)))] ** Qed
Std.BinomialHeap.Imp.Heap.realSize_merge ** α : Type u_1 le : α → α → Bool s₁ s₂ : Heap α ⊢ realSize (merge le s₁ s₂) = realSize s₁ + realSize s₂ ** unfold merge ** α : Type u_1 le : α → α → Bool s₁ s₂ : Heap α ⊢ realSize (match s₁, s₂ with | nil, h => h | h, nil => h | s₁@h:(cons r₁ a₁ n₁ t₁), s₂@h_1:(cons r₂ a₂ n₂ t₂) => if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ s₂) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le s₁ t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize s₁ + realSize s₂ ** split ** case h_1 α : Type u_1 le : α → α → Bool s₂ x✝¹ x✝ : Heap α ⊢ realSize s₂ = realSize nil + realSize s₂ ** simp ** case h_2 α : Type u_1 le : α → α → Bool s₁ x✝² x✝¹ : Heap α x✝ : s₁ = nil → False ⊢ realSize s₁ = realSize s₁ + realSize nil ** simp ** α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α ⊢ realSize (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** have IH₁ r a n := realSize_merge le t₁ (cons r a n t₂) ** α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) ⊢ realSize (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** have IH₂ r a n := realSize_merge le (cons r a n t₁) t₂ ** α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ ⊢ realSize (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** have IH₃ := realSize_merge le t₁ t₂ ** α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ ⊢ realSize (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** split ** case inr α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝ : ¬r₁ < r₂ ⊢ realSize (if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** split ** case inr.inr α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ ⊢ realSize (match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** split ** case inr.inr α : Type u_1 le : α → α → Bool x✝² x✝¹ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ x✝ : α × HeapNode α a✝ : α n✝ : HeapNode α heq✝ : combine le a₁ a₂ n₁ n₂ = (a✝, n✝) ⊢ realSize (let r := r₁ + 1; if rankGT t₁ r then if rankGT t₂ r then cons r a✝ n✝ (merge le t₁ t₂) else merge le (cons r a✝ n✝ t₁) t₂ else if rankGT t₂ r then merge le t₁ (cons r a✝ n✝ t₂) else cons r a✝ n✝ (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** simp only ** case inr.inr α : Type u_1 le : α → α → Bool x✝² x✝¹ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ x✝ : α × HeapNode α a✝ : α n✝ : HeapNode α heq✝ : combine le a₁ a₂ n₁ n₂ = (a✝, n✝) ⊢ realSize (if rankGT t₁ (r₁ + 1) then if rankGT t₂ (r₁ + 1) then cons (r₁ + 1) a✝ n✝ (merge le t₁ t₂) else merge le (cons (r₁ + 1) a✝ n✝ t₁) t₂ else if rankGT t₂ (r₁ + 1) then merge le t₁ (cons (r₁ + 1) a✝ n✝ t₂) else cons (r₁ + 1) a✝ n✝ (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** rename_i a n eq ** case inr.inr α : Type u_1 le : α → α → Bool x✝² x✝¹ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ x✝ : α × HeapNode α a : α n : HeapNode α eq : combine le a₁ a₂ n₁ n₂ = (a, n) ⊢ realSize (if rankGT t₁ (r₁ + 1) then if rankGT t₂ (r₁ + 1) then cons (r₁ + 1) a n (merge le t₁ t₂) else merge le (cons (r₁ + 1) a n t₁) t₂ else if rankGT t₂ (r₁ + 1) then merge le t₁ (cons (r₁ + 1) a n t₂) else cons (r₁ + 1) a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** have : n.realSize = n₁.realSize + 1 + n₂.realSize := by rw [combine] at eq; split at eq <;> cases eq <;> simp [Nat.add_assoc, Nat.add_left_comm, Nat.add_comm] ** case inr.inr α : Type u_1 le : α → α → Bool x✝² x✝¹ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ x✝ : α × HeapNode α a : α n : HeapNode α eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.realSize n = HeapNode.realSize n₁ + 1 + HeapNode.realSize n₂ ⊢ realSize (if rankGT t₁ (r₁ + 1) then if rankGT t₂ (r₁ + 1) then cons (r₁ + 1) a n (merge le t₁ t₂) else merge le (cons (r₁ + 1) a n t₁) t₂ else if rankGT t₂ (r₁ + 1) then merge le t₁ (cons (r₁ + 1) a n t₂) else cons (r₁ + 1) a n (merge le t₁ t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** split <;> split <;> simp [IH₁, IH₂, IH₃, this, Nat.add_assoc, Nat.add_left_comm] ** case inl α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝ : r₁ < r₂ ⊢ realSize (cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂))) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** simp [IH₁, Nat.add_assoc] ** case inr.inl α : Type u_1 le : α → α → Bool x✝¹ x✝ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : r₂ < r₁ ⊢ realSize (cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂)) = realSize (cons r₁ a₁ n₁ t₁) + realSize (cons r₂ a₂ n₂ t₂) ** simp [IH₂, Nat.add_assoc, Nat.add_left_comm] ** α : Type u_1 le : α → α → Bool x✝² x✝¹ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ x✝ : α × HeapNode α a : α n : HeapNode α eq : combine le a₁ a₂ n₁ n₂ = (a, n) ⊢ HeapNode.realSize n = HeapNode.realSize n₁ + 1 + HeapNode.realSize n₂ ** rw [combine] at eq ** α : Type u_1 le : α → α → Bool x✝² x✝¹ : Heap α r₁ : Nat a₁ : α n₁ : HeapNode α t₁ : Heap α r₂ : Nat a₂ : α n₂ : HeapNode α t₂ : Heap α IH₁ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le t₁ (cons r a n t₂)) = realSize t₁ + realSize (cons r a n t₂) IH₂ : ∀ (r : Nat) (a : α) (n : HeapNode α), realSize (merge le (cons r a n t₁) t₂) = realSize (cons r a n t₁) + realSize t₂ IH₃ : realSize (merge le t₁ t₂) = realSize t₁ + realSize t₂ h✝¹ : ¬r₁ < r₂ h✝ : ¬r₂ < r₁ x✝ : α × HeapNode α a : α n : HeapNode α eq : (if le a₁ a₂ = true then (a₁, HeapNode.node a₂ n₂ n₁) else (a₂, HeapNode.node a₁ n₁ n₂)) = (a, n) ⊢ HeapNode.realSize n = HeapNode.realSize n₁ + 1 + HeapNode.realSize n₂ ** split at eq <;> cases eq <;> simp [Nat.add_assoc, Nat.add_left_comm, Nat.add_comm] ** Qed
Std.BinomialHeap.Imp.Heap.realSize_findMin ** α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) ⊢ Std.BinomialHeap.Imp.FindMin.HasSize (findMin le k (cons r a c s) res) n ** simp [findMin] ** α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) ⊢ Std.BinomialHeap.Imp.FindMin.HasSize (findMin le (k ∘ cons r a c) s (if le res.val a = true then res else { before := k, val := a, node := c, next := s })) n ** refine realSize_findMin (m + c.realSize + 1) (by simp [hk, Nat.add_assoc]) (by simp [eq, Nat.add_assoc]) ?_ ** α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) ⊢ Std.BinomialHeap.Imp.FindMin.HasSize (if le res.val a = true then res else { before := k, val := a, node := c, next := s }) n ** split ** α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) ⊢ ∀ (s : Heap α), realSize ((k ∘ cons r a c) s) = m + HeapNode.realSize c + 1 + realSize s ** simp [hk, Nat.add_assoc] ** α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) ⊢ n = m + HeapNode.realSize c + 1 + realSize s ** simp [eq, Nat.add_assoc] ** case inl α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) h✝ : le res.val a = true ⊢ Std.BinomialHeap.Imp.FindMin.HasSize res n ** exact hres ** case inr α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) h✝ : ¬le res.val a = true ⊢ Std.BinomialHeap.Imp.FindMin.HasSize { before := k, val := a, node := c, next := s } n ** exact ⟨m, hk, by simp [eq, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm]⟩ ** α : Type u_1 k : Heap α → Heap α n : Nat le : α → α → Bool res : FindMin α s✝ : Heap α m : Nat hk : ∀ (s : Heap α), realSize (k s) = m + realSize s hres : Std.BinomialHeap.Imp.FindMin.HasSize res n r : Nat a : α c : HeapNode α s : Heap α eq : n = m + realSize (cons r a c s) h✝ : ¬le res.val a = true ⊢ n = m + HeapNode.realSize { before := k, val := a, node := c, next := s }.node + realSize { before := k, val := a, node := c, next := s }.next + 1 ** simp [eq, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] ** Qed
Std.BinomialHeap.Imp.HeapNode.realSize_toHeap ** α : Type u_1 s✝ : HeapNode α n : Nat res : Heap α a : α c s : HeapNode α ⊢ Heap.realSize (toHeap.go (node a c s) n res) = realSize (node a c s) + Heap.realSize res ** simp [toHeap.go, go, Nat.add_assoc, Nat.add_left_comm] ** Qed
Std.BinomialHeap.Imp.Heap.WF.merge' ** α✝ : Type u_1 le : α✝ → α✝ → Bool s₁ s₂ : Heap α✝ n : Nat h₁ : WF le n s₁ h₂ : WF le n s₂ ⊢ WF le n (merge le s₁ s₂) ∧ ((Heap.rankGT s₁ n ↔ Heap.rankGT s₂ n) → Heap.rankGT (merge le s₁ s₂) n) ** unfold merge ** α✝ : Type u_1 le : α✝ → α✝ → Bool s₁ s₂ : Heap α✝ n : Nat h₁ : WF le n s₁ h₂ : WF le n s₂ ⊢ WF le n (match s₁, s₂ with | Heap.nil, h => h | h, Heap.nil => h | s₁@h:(cons r₁ a₁ n₁ t₁), s₂@h_1:(cons r₂ a₂ n₂ t₂) => if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ s₂) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le s₁ t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT s₁ n ↔ Heap.rankGT s₂ n) → Heap.rankGT (match s₁, s₂ with | Heap.nil, h => h | h, Heap.nil => h | s₁@h:(cons r₁ a₁ n₁ t₁), s₂@h_1:(cons r₂ a₂ n₂ t₂) => if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ s₂) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le s₁ t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** split ** case h_1 α✝ : Type u_1 le : α✝ → α✝ → Bool s₂ : Heap α✝ n : Nat h₂ : WF le n s₂ x✝¹ x✝ : Heap α✝ h₁ : WF le n Heap.nil ⊢ WF le n s₂ ∧ ((Heap.rankGT Heap.nil n ↔ Heap.rankGT s₂ n) → Heap.rankGT s₂ n) ** exact ⟨h₂, fun h => h.1 h₁⟩ ** case h_2 α✝ : Type u_1 le : α✝ → α✝ → Bool s₁ : Heap α✝ n : Nat h₁ : WF le n s₁ x✝² x✝¹ : Heap α✝ x✝ : s₁ = Heap.nil → False h₂ : WF le n Heap.nil ⊢ WF le n s₁ ∧ ((Heap.rankGT s₁ n ↔ Heap.rankGT Heap.nil n) → Heap.rankGT s₁ n) ** exact ⟨h₁, fun h => h.2 h₂⟩ ** case h_3 α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁✝ : Nat a₁✝ : α✝ n₁✝ : HeapNode α✝ t₁✝ : Heap α✝ r₂✝ : Nat a₂✝ : α✝ n₂✝ : HeapNode α✝ t₂✝ : Heap α✝ h₁ : WF le n (cons r₁✝ a₁✝ n₁✝ t₁✝) h₂ : WF le n (cons r₂✝ a₂✝ n₂✝ t₂✝) ⊢ WF le n (if r₁✝ < r₂✝ then cons r₁✝ a₁✝ n₁✝ (merge le t₁✝ (cons r₂✝ a₂✝ n₂✝ t₂✝)) else if r₂✝ < r₁✝ then cons r₂✝ a₂✝ n₂✝ (merge le (cons r₁✝ a₁✝ n₁✝ t₁✝) t₂✝) else match combine le a₁✝ a₂✝ n₁✝ n₂✝ with | (a, n) => let r := r₁✝ + 1; if Heap.rankGT t₁✝ r then if Heap.rankGT t₂✝ r then cons r a n (merge le t₁✝ t₂✝) else merge le (cons r a n t₁✝) t₂✝ else if Heap.rankGT t₂✝ r then merge le t₁✝ (cons r a n t₂✝) else cons r a n (merge le t₁✝ t₂✝)) ∧ ((Heap.rankGT (cons r₁✝ a₁✝ n₁✝ t₁✝) n ↔ Heap.rankGT (cons r₂✝ a₂✝ n₂✝ t₂✝) n) → Heap.rankGT (if r₁✝ < r₂✝ then cons r₁✝ a₁✝ n₁✝ (merge le t₁✝ (cons r₂✝ a₂✝ n₂✝ t₂✝)) else if r₂✝ < r₁✝ then cons r₂✝ a₂✝ n₂✝ (merge le (cons r₁✝ a₁✝ n₁✝ t₁✝) t₂✝) else match combine le a₁✝ a₂✝ n₁✝ n₂✝ with | (a, n) => let r := r₁✝ + 1; if Heap.rankGT t₁✝ r then if Heap.rankGT t₂✝ r then cons r a n (merge le t₁✝ t₂✝) else merge le (cons r a n t₁✝) t₂✝ else if Heap.rankGT t₂✝ r then merge le t₁✝ (cons r a n t₂✝) else cons r a n (merge le t₁✝ t₂✝)) n) ** rename_i r₁ a₁ n₁ t₁ r₂ a₂ n₂ t₂ ** case h_3 α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) ⊢ WF le n (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** let ⟨hr₁, hn₁, ht₁⟩ := h₁ ** case h_3 α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ ⊢ WF le n (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** let ⟨hr₂, hn₂, ht₂⟩ := h₂ ** case h_3 α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ ⊢ WF le n (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (if r₁ < r₂ then cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂)) else if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** split <;> rename_i lt₁ ** case h_3.inr α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ lt₁ : ¬r₁ < r₂ ⊢ WF le n (if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (if r₂ < r₁ then cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂) else match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** split <;> rename_i lt₂ ** case h_3.inr.inr α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ lt₁ : ¬r₁ < r₂ lt₂ : ¬r₂ < r₁ ⊢ WF le n (match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** cases Nat.le_antisymm (Nat.ge_of_not_lt lt₂) (Nat.ge_of_not_lt lt₁) ** case h_3.inr.inr.refl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n (cons r₁ a₂ n₂ t₂) hr₂ : n ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ ⊢ WF le n (match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n) → Heap.rankGT (match combine le a₁ a₂ n₁ n₂ with | (a, n) => let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n) ** split ** case h_3.inr.inr.refl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n (cons r₁ a₂ n₂ t₂) hr₂ : n ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a✝ : α✝ n✝ : HeapNode α✝ heq✝ : combine le a₁ a₂ n₁ n₂ = (a✝, n✝) ⊢ WF le n (let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a✝ n✝ (merge le t₁ t₂) else merge le (cons r a✝ n✝ t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a✝ n✝ t₂) else cons r a✝ n✝ (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n) → Heap.rankGT (let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a✝ n✝ (merge le t₁ t₂) else merge le (cons r a✝ n✝ t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a✝ n✝ t₂) else cons r a✝ n✝ (merge le t₁ t₂)) n) ** rename_i a n eq ** case h_3.inr.inr.refl α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) ⊢ WF le n✝ (let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (let r := r₁ + 1; if Heap.rankGT t₁ r then if Heap.rankGT t₂ r then cons r a n (merge le t₁ t₂) else merge le (cons r a n t₁) t₂ else if Heap.rankGT t₂ r then merge le t₁ (cons r a n t₂) else cons r a n (merge le t₁ t₂)) n✝) ** simp only ** case h_3.inr.inr.refl α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) ⊢ WF le n✝ (if Heap.rankGT t₁ (r₁ + 1) then if Heap.rankGT t₂ (r₁ + 1) then cons (r₁ + 1) a n (merge le t₁ t₂) else merge le (cons (r₁ + 1) a n t₁) t₂ else if Heap.rankGT t₂ (r₁ + 1) then merge le t₁ (cons (r₁ + 1) a n t₂) else cons (r₁ + 1) a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (if Heap.rankGT t₁ (r₁ + 1) then if Heap.rankGT t₂ (r₁ + 1) then cons (r₁ + 1) a n (merge le t₁ t₂) else merge le (cons (r₁ + 1) a n t₁) t₂ else if Heap.rankGT t₂ (r₁ + 1) then merge le t₁ (cons (r₁ + 1) a n t₂) else cons (r₁ + 1) a n (merge le t₁ t₂)) n✝) ** split <;> split <;> rename_i hl₁ hl₂ ** case h_3.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ lt₁ : r₁ < r₂ ⊢ WF le n (cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂))) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂))) n) ** refine ⟨⟨hr₁, hn₁, And.left (merge' ht₁ ⟨lt₁, hn₂, ht₂⟩)⟩, fun h => ?_⟩ ** case h_3.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ lt₁ : r₁ < r₂ h : Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n ⊢ Heap.rankGT (cons r₁ a₁ n₁ (merge le t₁ (cons r₂ a₂ n₂ t₂))) n ** exact h.2 <| Nat.lt_of_le_of_lt hr₁ lt₁ ** case h_3.inr.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ lt₁ : ¬r₁ < r₂ lt₂ : r₂ < r₁ ⊢ WF le n (cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n) → Heap.rankGT (cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂)) n) ** refine ⟨⟨hr₂, hn₂, And.left (merge' ⟨lt₂, hn₁, ht₁⟩ ht₂)⟩, fun h => ?_⟩ ** case h_3.inr.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝¹ x✝ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ r₂ : Nat a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) h₂ : WF le n (cons r₂ a₂ n₂ t₂) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ hr₂ : n ≤ r₂ hn₂ : HeapNode.WF le a₂ n₂ r₂ ht₂ : WF le (r₂ + 1) t₂ lt₁ : ¬r₁ < r₂ lt₂ : r₂ < r₁ h : Heap.rankGT (cons r₁ a₁ n₁ t₁) n ↔ Heap.rankGT (cons r₂ a₂ n₂ t₂) n ⊢ Heap.rankGT (cons r₂ a₂ n₂ (merge le (cons r₁ a₁ n₁ t₁) t₂)) n ** exact h.1 <| Nat.lt_of_le_of_lt hr₂ lt₂ ** α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) ⊢ HeapNode.WF le a n (r₁ + 1) ** unfold combine at eq ** α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : (if le a₁ a₂ = true then (a₁, HeapNode.node a₂ n₂ n₁) else (a₂, HeapNode.node a₁ n₁ n₂)) = (a, n) ⊢ HeapNode.WF le a n (r₁ + 1) ** split at eq <;> cases eq <;> rename_i h ** case inl.refl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n (cons r₁ a₂ n₂ t₂) hr₂ : n ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ h : le a₁ a₂ = true ⊢ HeapNode.WF le a₁ (HeapNode.node a₂ n₂ n₁) (r₁ + 1) ** exact ⟨r₁, rfl, h, hn₂, hn₁⟩ ** case inr.refl α✝ : Type u_1 le : α✝ → α✝ → Bool n : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n (cons r₁ a₁ n₁ t₁) hr₁ : n ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n (cons r₁ a₂ n₂ t₂) hr₂ : n ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ h : ¬le a₁ a₂ = true ⊢ HeapNode.WF le a₂ (HeapNode.node a₁ n₁ n₂) (r₁ + 1) ** exact ⟨r₁, rfl, TotalBLE.total.resolve_left h, hn₁, hn₂⟩ ** case h_3.inr.inr.refl.inl.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : Heap.rankGT t₁ (r₁ + 1) hl₂ : Heap.rankGT t₂ (r₁ + 1) ⊢ WF le n✝ (cons (r₁ + 1) a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (cons (r₁ + 1) a n (merge le t₁ t₂)) n✝) ** exact ⟨⟨Nat.le_succ_of_le hr₁, this, (merge' (ht₁.of_rankGT hl₁) (ht₂.of_rankGT hl₂)).1⟩, fun _ => Nat.lt_succ_of_le hr₁⟩ ** case h_3.inr.inr.refl.inl.inr α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : Heap.rankGT t₁ (r₁ + 1) hl₂ : ¬Heap.rankGT t₂ (r₁ + 1) ⊢ WF le n✝ (merge le (cons (r₁ + 1) a n t₁) t₂) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (merge le (cons (r₁ + 1) a n t₁) t₂) n✝) ** let ⟨ih₁, ih₂⟩ := merge' (s₁ := .cons ..) ⟨Nat.le_succ_of_le hr₁, this, ht₁.of_rankGT hl₁⟩ (ht₂.of_le (Nat.le_succ_of_le hr₁)) ** case h_3.inr.inr.refl.inl.inr α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : Heap.rankGT t₁ (r₁ + 1) hl₂ : ¬Heap.rankGT t₂ (r₁ + 1) ih₁ : WF le n✝ (merge le (cons (Nat.succ r₁) a n t₁) t₂) ih₂ : (Heap.rankGT (cons (Nat.succ r₁) a n t₁) n✝ ↔ Heap.rankGT t₂ n✝) → Heap.rankGT (merge le (cons (Nat.succ r₁) a n t₁) t₂) n✝ ⊢ WF le n✝ (merge le (cons (r₁ + 1) a n t₁) t₂) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (merge le (cons (r₁ + 1) a n t₁) t₂) n✝) ** exact ⟨ih₁, fun _ => ih₂ ⟨fun _ => ht₂.rankGT.of_le hr₁, fun h => Nat.lt_succ_of_le hr₁⟩⟩ ** case h_3.inr.inr.refl.inr.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : ¬Heap.rankGT t₁ (r₁ + 1) hl₂ : Heap.rankGT t₂ (r₁ + 1) ⊢ WF le n✝ (merge le t₁ (cons (r₁ + 1) a n t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (merge le t₁ (cons (r₁ + 1) a n t₂)) n✝) ** let ⟨ih₁, ih₂⟩ := merge' (s₂ := .cons ..) (ht₁.of_le (Nat.le_succ_of_le hr₁)) ⟨Nat.le_succ_of_le hr₁, this, ht₂.of_rankGT hl₂⟩ ** case h_3.inr.inr.refl.inr.inl α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : ¬Heap.rankGT t₁ (r₁ + 1) hl₂ : Heap.rankGT t₂ (r₁ + 1) ih₁ : WF le n✝ (merge le t₁ (cons (Nat.succ r₁) a n t₂)) ih₂ : (Heap.rankGT t₁ n✝ ↔ Heap.rankGT (cons (Nat.succ r₁) a n t₂) n✝) → Heap.rankGT (merge le t₁ (cons (Nat.succ r₁) a n t₂)) n✝ ⊢ WF le n✝ (merge le t₁ (cons (r₁ + 1) a n t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (merge le t₁ (cons (r₁ + 1) a n t₂)) n✝) ** exact ⟨ih₁, fun _ => ih₂ ⟨fun h => Nat.lt_succ_of_le hr₁, fun _ => ht₁.rankGT.of_le hr₁⟩⟩ ** case h_3.inr.inr.refl.inr.inr α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : ¬Heap.rankGT t₁ (r₁ + 1) hl₂ : ¬Heap.rankGT t₂ (r₁ + 1) ⊢ WF le n✝ (cons (r₁ + 1) a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (cons (r₁ + 1) a n (merge le t₁ t₂)) n✝) ** let ⟨ih₁, ih₂⟩ := merge' ht₁ ht₂ ** case h_3.inr.inr.refl.inr.inr α✝ : Type u_1 le : α✝ → α✝ → Bool n✝ : Nat x✝² x✝¹ : Heap α✝ r₁ : Nat a₁ : α✝ n₁ : HeapNode α✝ t₁ : Heap α✝ a₂ : α✝ n₂ : HeapNode α✝ t₂ : Heap α✝ h₁ : WF le n✝ (cons r₁ a₁ n₁ t₁) hr₁ : n✝ ≤ r₁ hn₁ : HeapNode.WF le a₁ n₁ r₁ ht₁ : WF le (r₁ + 1) t₁ h₂ : WF le n✝ (cons r₁ a₂ n₂ t₂) hr₂ : n✝ ≤ r₁ hn₂ : HeapNode.WF le a₂ n₂ r₁ ht₂ : WF le (r₁ + 1) t₂ lt₁ lt₂ : ¬r₁ < r₁ x✝ : α✝ × HeapNode α✝ a : α✝ n : HeapNode α✝ eq : combine le a₁ a₂ n₁ n₂ = (a, n) this : HeapNode.WF le a n (r₁ + 1) hl₁ : ¬Heap.rankGT t₁ (r₁ + 1) hl₂ : ¬Heap.rankGT t₂ (r₁ + 1) ih₁ : WF le (r₁ + 1) (merge le t₁ t₂) ih₂ : (Heap.rankGT t₁ (r₁ + 1) ↔ Heap.rankGT t₂ (r₁ + 1)) → Heap.rankGT (merge le t₁ t₂) (r₁ + 1) ⊢ WF le n✝ (cons (r₁ + 1) a n (merge le t₁ t₂)) ∧ ((Heap.rankGT (cons r₁ a₁ n₁ t₁) n✝ ↔ Heap.rankGT (cons r₁ a₂ n₂ t₂) n✝) → Heap.rankGT (cons (r₁ + 1) a n (merge le t₁ t₂)) n✝) ** exact ⟨⟨Nat.le_succ_of_le hr₁, this, ih₁.of_rankGT (ih₂ (iff_of_false hl₁ hl₂))⟩, fun _ => Nat.lt_succ_of_le hr₁⟩ ** Qed
Std.BinomialHeap.Imp.HeapNode.WF.toHeap ** α : Type u_1 le : α → α → Bool a✝ : α n✝ : Nat s✝ : HeapNode α h✝ : WF le a✝ s✝ n✝ res : Heap α a : α c s : HeapNode α n : Nat left✝ : ∀ [inst : TotalBLE le], le a✝ a = true h : WF le a c n h' : WF le a✝ s n hr : Heap.WF le (rank (node a c s)) res ⊢ WF le a c (rank (node a c s) - 1) ** rw [← h'.rank_eq] at h ** α : Type u_1 le : α → α → Bool a✝ : α n✝ : Nat s✝ : HeapNode α h✝ : WF le a✝ s✝ n✝ res : Heap α a : α c s : HeapNode α n : Nat left✝ : ∀ [inst : TotalBLE le], le a✝ a = true h : WF le a c (rank s) h' : WF le a✝ s n hr : Heap.WF le (rank (node a c s)) res ⊢ WF le a c (rank (node a c s) - 1) ** exact h ** Qed
Std.BinomialHeap.Imp.Heap.WF.tail? ** α : Type u_1 s : Heap α le : α → α → Bool n : Nat tl : Heap α hwf : WF le n s ⊢ Heap.tail? le s = some tl → WF le 0 tl ** simp only [Heap.tail?] ** α : Type u_1 s : Heap α le : α → α → Bool n : Nat tl : Heap α hwf : WF le n s ⊢ Option.map (fun x => x.snd) (Heap.deleteMin le s) = some tl → WF le 0 tl ** intro eq ** α : Type u_1 s : Heap α le : α → α → Bool n : Nat tl : Heap α hwf : WF le n s eq : Option.map (fun x => x.snd) (Heap.deleteMin le s) = some tl ⊢ WF le 0 tl ** match eq₂ : s.deleteMin le, eq with | some (a, tl), rfl => exact hwf.deleteMin eq₂ ** α : Type u_1 s : Heap α le : α → α → Bool n : Nat tl✝ : Heap α hwf : WF le n s eq : Option.map (fun x => x.snd) (Heap.deleteMin le s) = some tl✝ a : α tl : Heap α eq₂ : Heap.deleteMin le s = some (a, tl) ⊢ WF le 0 ((fun x => x.snd) (a, tl)) ** exact hwf.deleteMin eq₂ ** Qed
Nat.succ_sub ** m n : Nat h : n ≤ m ⊢ succ m - n = succ (m - n) ** let ⟨k, hk⟩ := Nat.le.dest h ** m n : Nat h : n ≤ m k : Nat hk : n + k = m ⊢ succ m - n = succ (m - n) ** rw [← hk, Nat.add_sub_cancel_left, ← add_succ, Nat.add_sub_cancel_left] ** Qed
Nat.sub_lt_left_of_lt_add ** n k m : Nat H : n ≤ k h : k < n + m ⊢ k - n < m ** have := Nat.sub_le_sub_right (succ_le_of_lt h) n ** n k m : Nat H : n ≤ k h : k < n + m this : succ k - n ≤ n + m - n ⊢ k - n < m ** rwa [Nat.add_sub_cancel_left, Nat.succ_sub H] at this ** Qed
Nat.min_comm ** a b : Nat ⊢ min a b = min b a ** simp [Nat.min_def] ** a b : Nat ⊢ (if a ≤ b then a else b) = if b ≤ a then b else a ** split <;> split <;> try simp [*] ** case inr.inl a b : Nat h✝¹ : ¬a ≤ b h✝ : b ≤ a ⊢ b = b ** simp [*] ** case inl.inl a b : Nat h✝¹ : a ≤ b h✝ : b ≤ a ⊢ a = b ** next h₁ h₂ => exact Nat.le_antisymm h₁ h₂ ** a b : Nat h₁ : a ≤ b h₂ : b ≤ a ⊢ a = b ** exact Nat.le_antisymm h₁ h₂ ** case inr.inr a b : Nat h✝¹ : ¬a ≤ b h✝ : ¬b ≤ a ⊢ b = a ** next h₁ h₂ => cases not_or_intro h₁ h₂ <| Nat.le_total .. ** a b : Nat h₁ : ¬a ≤ b h₂ : ¬b ≤ a ⊢ b = a ** cases not_or_intro h₁ h₂ <| Nat.le_total .. ** Qed
Nat.min_le_right ** a b : Nat ⊢ min a b ≤ b ** rw [Nat.min_def] ** a b : Nat ⊢ (if a ≤ b then a else b) ≤ b ** split <;> simp [*] ** Qed
Nat.max_comm ** a b : Nat ⊢ max a b = max b a ** simp only [Nat.max_def] ** a b : Nat ⊢ (if a ≤ b then b else a) = if b ≤ a then a else b ** by_cases h₁ : a ≤ b <;> by_cases h₂ : b ≤ a <;> simp [h₁, h₂] ** case pos a b : Nat h₁ : a ≤ b h₂ : b ≤ a ⊢ b = a ** exact Nat.le_antisymm h₂ h₁ ** case neg a b : Nat h₁ : ¬a ≤ b h₂ : ¬b ≤ a ⊢ a = b ** cases not_or_intro h₁ h₂ <| Nat.le_total .. ** Qed
Nat.le_max_left ** a b : Nat ⊢ a ≤ max a b ** rw [Nat.max_def] ** a b : Nat ⊢ a ≤ if a ≤ b then b else a ** split <;> simp [*] ** Qed
Nat.pow_two_pos ** w : Nat ⊢ 0 < 2 ** decide ** Qed
Sum.liftRel_inl_inl ** α✝ : Type u_1 γ✝ : Type u_2 r : α✝ → γ✝ → Prop β✝ : Type u_3 δ✝ : Type u_4 s : β✝ → δ✝ → Prop a : α✝ c : γ✝ h : LiftRel r s (inl a) (inl c) ⊢ r a c ** cases h ** case inl α✝ : Type u_1 γ✝ : Type u_2 r : α✝ → γ✝ → Prop β✝ : Type u_3 δ✝ : Type u_4 s : β✝ → δ✝ → Prop a : α✝ c : γ✝ a✝ : r a c ⊢ r a c ** assumption ** Qed
Sum.liftRel_inr_inr ** α✝ : Type u_1 γ✝ : Type u_2 r : α✝ → γ✝ → Prop β✝ : Type u_3 δ✝ : Type u_4 s : β✝ → δ✝ → Prop b : β✝ d : δ✝ h : LiftRel r s (inr b) (inr d) ⊢ s b d ** cases h ** case inr α✝ : Type u_1 γ✝ : Type u_2 r : α✝ → γ✝ → Prop β✝ : Type u_3 δ✝ : Type u_4 s : β✝ → δ✝ → Prop b : β✝ d : δ✝ a✝ : s b d ⊢ s b d ** assumption ** Qed
Sum.lex_inl_inl ** α✝ : Type u_1 r : α✝ → α✝ → Prop β✝ : Type u_2 s : β✝ → β✝ → Prop a₁ a₂ : α✝ h : Lex r s (inl a₁) (inl a₂) ⊢ r a₁ a₂ ** cases h ** case inl α✝ : Type u_1 r : α✝ → α✝ → Prop β✝ : Type u_2 s : β✝ → β✝ → Prop a₁ a₂ : α✝ h✝ : r a₁ a₂ ⊢ r a₁ a₂ ** assumption ** Qed
Sum.lex_inr_inr ** α✝ : Type u_1 r : α✝ → α✝ → Prop β✝ : Type u_2 s : β✝ → β✝ → Prop b₁ b₂ : β✝ h : Lex r s (inr b₁) (inr b₂) ⊢ s b₁ b₂ ** cases h ** case inr α✝ : Type u_1 r : α✝ → α✝ → Prop β✝ : Type u_2 s : β✝ → β✝ → Prop b₁ b₂ : β✝ h✝ : s b₁ b₂ ⊢ s b₁ b₂ ** assumption ** Qed
Std.RBNode.All_and ** α : Type u_1 p q : α → Prop t : RBNode α ⊢ All (fun a => p a ∧ q a) t ↔ All p t ∧ All q t ** induction t <;> simp [*, and_assoc, and_left_comm] ** Qed
Std.RBNode.Ordered.balance1 ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (balance1 l v r) ** unfold balance1 ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (match l, v, r with | node red (node red a x b) y c, z, d => node red (node black a x b) y (node black c z d) | node red a x (node red b y c), z, d => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝³ : RBNode α x✝² : α x✝¹ a✝ : RBNode α x✝ : α b✝ : RBNode α y✝ : α c✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red (node red a✝ x✝ b✝) y✝ c✝) hl : Ordered cmp (node red (node red a✝ x✝ b✝) y✝ c✝) ⊢ Ordered cmp (node red (node black a✝ x✝ b✝) y✝ (node black c✝ v r)) ** next a x b y c => have ⟨yv, _, cv⟩ := lv; have ⟨xy, yc, hx, hc⟩ := hl exact ⟨xy, ⟨yv, yc, yv.trans_l vr⟩, hx, cv, vr, hc, hr⟩ ** α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝² : RBNode α x✝¹ : α x✝ a : RBNode α x : α b : RBNode α y : α c : RBNode α lv : All (fun x => cmpLT cmp x v) (node red (node red a x b) y c) hl : Ordered cmp (node red (node red a x b) y c) ⊢ Ordered cmp (node red (node black a x b) y (node black c v r)) ** have ⟨yv, _, cv⟩ := lv ** α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝² : RBNode α x✝¹ : α x✝ a : RBNode α x : α b : RBNode α y : α c : RBNode α lv : All (fun x => cmpLT cmp x v) (node red (node red a x b) y c) hl : Ordered cmp (node red (node red a x b) y c) yv : (fun x => cmpLT cmp x v) y left✝ : All (fun x => cmpLT cmp x v) (node red a x b) cv : All (fun x => cmpLT cmp x v) c ⊢ Ordered cmp (node red (node black a x b) y (node black c v r)) ** have ⟨xy, yc, hx, hc⟩ := hl ** α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝² : RBNode α x✝¹ : α x✝ a : RBNode α x : α b : RBNode α y : α c : RBNode α lv : All (fun x => cmpLT cmp x v) (node red (node red a x b) y c) hl : Ordered cmp (node red (node red a x b) y c) yv : (fun x => cmpLT cmp x v) y left✝ : All (fun x => cmpLT cmp x v) (node red a x b) cv : All (fun x => cmpLT cmp x v) c xy : All (fun x => cmpLT cmp x y) (node red a x b) yc : All (fun x => cmpLT cmp y x) c hx : Ordered cmp (node red a x b) hc : Ordered cmp c ⊢ Ordered cmp (node red (node black a x b) y (node black c v r)) ** exact ⟨xy, ⟨yv, yc, yv.trans_l vr⟩, hx, cv, vr, hc, hr⟩ ** case h_2 α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝⁴ : RBNode α x✝³ : α x✝² a✝ : RBNode α x✝¹ : α b✝ : RBNode α y✝ : α c✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝ = node red a x b → False lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ (node red b✝ y✝ c✝)) hl : Ordered cmp (node red a✝ x✝¹ (node red b✝ y✝ c✝)) ⊢ Ordered cmp (node red (node black a✝ x✝¹ b✝) y✝ (node black c✝ v r)) ** next a x b y c _ => have ⟨_, _, yv, _, cv⟩ := lv; have ⟨ax, ⟨xy, xb, _⟩, ha, by_, yc, hb, hc⟩ := hl exact ⟨⟨xy, xy.trans_r ax, by_⟩, ⟨yv, yc, yv.trans_l vr⟩, ⟨ax, xb, ha, hb⟩, cv, vr, hc, hr⟩ ** α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝³ : RBNode α x✝² : α x✝¹ a : RBNode α x : α b : RBNode α y : α c : RBNode α x✝ : ∀ (a_1 : RBNode α) (x : α) (b : RBNode α), a = node red a_1 x b → False lv : All (fun x => cmpLT cmp x v) (node red a x (node red b y c)) hl : Ordered cmp (node red a x (node red b y c)) ⊢ Ordered cmp (node red (node black a x b) y (node black c v r)) ** have ⟨_, _, yv, _, cv⟩ := lv ** α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝³ : RBNode α x✝² : α x✝¹ a : RBNode α x : α b : RBNode α y : α c : RBNode α x✝ : ∀ (a_1 : RBNode α) (x : α) (b : RBNode α), a = node red a_1 x b → False lv : All (fun x => cmpLT cmp x v) (node red a x (node red b y c)) hl : Ordered cmp (node red a x (node red b y c)) left✝² : (fun x => cmpLT cmp x v) x left✝¹ : All (fun x => cmpLT cmp x v) a yv : (fun x => cmpLT cmp x v) y left✝ : All (fun x => cmpLT cmp x v) b cv : All (fun x => cmpLT cmp x v) c ⊢ Ordered cmp (node red (node black a x b) y (node black c v r)) ** have ⟨ax, ⟨xy, xb, _⟩, ha, by_, yc, hb, hc⟩ := hl ** α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝³ : RBNode α x✝² : α x✝¹ a : RBNode α x : α b : RBNode α y : α c : RBNode α x✝ : ∀ (a_1 : RBNode α) (x : α) (b : RBNode α), a = node red a_1 x b → False lv : All (fun x => cmpLT cmp x v) (node red a x (node red b y c)) hl : Ordered cmp (node red a x (node red b y c)) left✝² : (fun x => cmpLT cmp x v) x left✝¹ : All (fun x => cmpLT cmp x v) a yv : (fun x => cmpLT cmp x v) y left✝ : All (fun x => cmpLT cmp x v) b cv : All (fun x => cmpLT cmp x v) c ax : All (fun x_1 => cmpLT cmp x_1 x) a xy : (fun x_1 => cmpLT cmp x x_1) y xb : All (fun x_1 => cmpLT cmp x x_1) b right✝ : All (fun x_1 => cmpLT cmp x x_1) c ha : Ordered cmp a by_ : All (fun x => cmpLT cmp x y) b yc : All (fun x => cmpLT cmp y x) c hb : Ordered cmp b hc : Ordered cmp c ⊢ Ordered cmp (node red (node black a x b) y (node black c v r)) ** exact ⟨⟨xy, xy.trans_r ax, by_⟩, ⟨yv, yc, yv.trans_l vr⟩, ⟨ax, xb, ha, hb⟩, cv, vr, hc, hr⟩ ** case h_3 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r x✝⁴ : RBNode α x✝³ : α x✝² : RBNode α x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red (node red a x b) y c → False x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red a x (node red b y c) → False ⊢ Ordered cmp (node black l v r) ** exact ⟨lv, vr, hl, hr⟩ ** Qed
Std.RBNode.balance1_All ** α : Type u_1 p : α → Prop l : RBNode α v : α r : RBNode α ⊢ All p (balance1 l v r) ↔ p v ∧ All p l ∧ All p r ** unfold balance1 ** α : Type u_1 p : α → Prop l : RBNode α v : α r : RBNode α ⊢ All p (match l, v, r with | node red (node red a x b) y c, z, d => node red (node black a x b) y (node black c z d) | node red a x (node red b y c), z, d => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) ↔ p v ∧ All p l ∧ All p r ** split <;> simp [and_assoc, and_left_comm] ** Qed
Std.RBNode.Ordered.balance2 ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (balance2 l v r) ** unfold balance2 ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (match l, v, r with | a, x, node red (node red b y c) z d => node red (node black a x b) y (node black c z d) | a, x, node red b y (node red c z d) => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝² : RBNode α x✝¹ : α x✝ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node red b✝ y✝ c✝) z✝ d✝) hr : Ordered cmp (node red (node red b✝ y✝ c✝) z✝ d✝) ⊢ Ordered cmp (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) ** next b y c z d => have ⟨_, ⟨vy, vb, _⟩, _⟩ := vr; have ⟨⟨yz, _, cz⟩, zd, ⟨by_, yc, hy, hz⟩, hd⟩ := hr exact ⟨⟨vy, vy.trans_r lv, by_⟩, ⟨yz, yc, yz.trans_l zd⟩, ⟨lv, vb, hl, hy⟩, cz, zd, hz, hd⟩ ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝² : RBNode α x✝¹ : α x✝ b : RBNode α y : α c : RBNode α z : α d : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node red b y c) z d) hr : Ordered cmp (node red (node red b y c) z d) ⊢ Ordered cmp (node red (node black l v b) y (node black c z d)) ** have ⟨_, ⟨vy, vb, _⟩, _⟩ := vr ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝² : RBNode α x✝¹ : α x✝ b : RBNode α y : α c : RBNode α z : α d : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node red b y c) z d) hr : Ordered cmp (node red (node red b y c) z d) left✝ : (fun x => cmpLT cmp v x) z vy : (fun x => cmpLT cmp v x) y vb : All (fun x => cmpLT cmp v x) b right✝¹ : All (fun x => cmpLT cmp v x) c right✝ : All (fun x => cmpLT cmp v x) d ⊢ Ordered cmp (node red (node black l v b) y (node black c z d)) ** have ⟨⟨yz, _, cz⟩, zd, ⟨by_, yc, hy, hz⟩, hd⟩ := hr ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝² : RBNode α x✝¹ : α x✝ b : RBNode α y : α c : RBNode α z : α d : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node red b y c) z d) hr : Ordered cmp (node red (node red b y c) z d) left✝¹ : (fun x => cmpLT cmp v x) z vy : (fun x => cmpLT cmp v x) y vb : All (fun x => cmpLT cmp v x) b right✝¹ : All (fun x => cmpLT cmp v x) c right✝ : All (fun x => cmpLT cmp v x) d yz : (fun x => cmpLT cmp x z) y left✝ : All (fun x => cmpLT cmp x z) b cz : All (fun x => cmpLT cmp x z) c zd : All (fun x => cmpLT cmp z x) d by_ : All (fun x => cmpLT cmp x y) b yc : All (fun x => cmpLT cmp y x) c hy : Ordered cmp b hz : Ordered cmp c hd : Ordered cmp d ⊢ Ordered cmp (node red (node black l v b) y (node black c z d)) ** exact ⟨⟨vy, vy.trans_r lv, by_⟩, ⟨yz, yc, yz.trans_l zd⟩, ⟨lv, vb, hl, hy⟩, cz, zd, hz, hd⟩ ** case h_2 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝³ : RBNode α x✝² : α x✝¹ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), b✝ = node red b y c → False vr : All (fun x => cmpLT cmp v x) (node red b✝ y✝ (node red c✝ z✝ d✝)) hr : Ordered cmp (node red b✝ y✝ (node red c✝ z✝ d✝)) ⊢ Ordered cmp (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) ** next a x b y c _ => have ⟨vx, va, _⟩ := vr; have ⟨ax, xy, ha, hy⟩ := hr exact ⟨⟨vx, vx.trans_r lv, ax⟩, xy, ⟨lv, va, hl, ha⟩, hy⟩ ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝³ : RBNode α x✝² : α x✝¹ a : RBNode α x : α b : RBNode α y : α c : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), a = node red b y c → False vr : All (fun x => cmpLT cmp v x) (node red a x (node red b y c)) hr : Ordered cmp (node red a x (node red b y c)) ⊢ Ordered cmp (node red (node black l v a) x (node black b y c)) ** have ⟨vx, va, _⟩ := vr ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝³ : RBNode α x✝² : α x✝¹ a : RBNode α x : α b : RBNode α y : α c : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), a = node red b y c → False vr : All (fun x => cmpLT cmp v x) (node red a x (node red b y c)) hr : Ordered cmp (node red a x (node red b y c)) vx : (fun x => cmpLT cmp v x) x va : All (fun x => cmpLT cmp v x) a right✝ : All (fun x => cmpLT cmp v x) (node red b y c) ⊢ Ordered cmp (node red (node black l v a) x (node black b y c)) ** have ⟨ax, xy, ha, hy⟩ := hr ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝³ : RBNode α x✝² : α x✝¹ a : RBNode α x : α b : RBNode α y : α c : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), a = node red b y c → False vr : All (fun x => cmpLT cmp v x) (node red a x (node red b y c)) hr : Ordered cmp (node red a x (node red b y c)) vx : (fun x => cmpLT cmp v x) x va : All (fun x => cmpLT cmp v x) a right✝ : All (fun x => cmpLT cmp v x) (node red b y c) ax : All (fun x_1 => cmpLT cmp x_1 x) a xy : All (fun x_1 => cmpLT cmp x x_1) (node red b y c) ha : Ordered cmp a hy : Ordered cmp (node red b y c) ⊢ Ordered cmp (node red (node black l v a) x (node black b y c)) ** exact ⟨⟨vx, vx.trans_r lv, ax⟩, xy, ⟨lv, va, hl, ha⟩, hy⟩ ** case h_3 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r x✝⁴ : RBNode α x✝³ : α x✝² : RBNode α x✝¹ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False ⊢ Ordered cmp (node black l v r) ** exact ⟨lv, vr, hl, hr⟩ ** Qed
Std.RBNode.balance2_All ** α : Type u_1 p : α → Prop l : RBNode α v : α r : RBNode α ⊢ All p (balance2 l v r) ↔ p v ∧ All p l ∧ All p r ** unfold balance2 ** α : Type u_1 p : α → Prop l : RBNode α v : α r : RBNode α ⊢ All p (match l, v, r with | a, x, node red (node red b y c) z d => node red (node black a x b) y (node black c z d) | a, x, node red b y (node red c z d) => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) ↔ p v ∧ All p l ∧ All p r ** split <;> simp [and_assoc, and_left_comm] ** Qed
Std.RBNode.Ordered.setBlack ** α : Type u_1 cmp : α → α → Ordering t : RBNode α ⊢ Ordered cmp (setBlack t) ↔ Ordered cmp t ** unfold setBlack ** α : Type u_1 cmp : α → α → Ordering t : RBNode α ⊢ Ordered cmp (match t with | nil => nil | node c l v r => node black l v r) ↔ Ordered cmp t ** split <;> simp [Ordered] ** Qed
Std.RBNode.setBlack_idem ** α : Type u_1 t : RBNode α ⊢ setBlack (setBlack t) = setBlack t ** cases t <;> rfl ** Qed
Std.RBNode.insert_setBlack ** α : Type u_1 cmp : α → α → Ordering v : α t : RBNode α ⊢ setBlack (insert cmp t v) = setBlack (ins cmp v t) ** unfold insert ** α : Type u_1 cmp : α → α → Ordering v : α t : RBNode α ⊢ setBlack (match isRed t with | red => setBlack (ins cmp v t) | black => ins cmp v t) = setBlack (ins cmp v t) ** split <;> simp [setBlack_idem] ** Qed
Std.RBNode.All.ins ** α : Type u_1 p : α → Prop cmp : α → α → Ordering x : α t : RBNode α h₁ : p x h₂ : All p t ⊢ All p (ins cmp x t) ** induction t <;> unfold ins <;> try simp [*] ** case node α : Type u_1 p : α → Prop cmp : α → α → Ordering x : α h₁ : p x c✝ : RBColor l✝ : RBNode α v✝ : α r✝ : RBNode α l_ih✝ : All p l✝ → All p (ins cmp x l✝) r_ih✝ : All p r✝ → All p (ins cmp x r✝) h₂ : All p (node c✝ l✝ v✝ r✝) ⊢ All p (match node c✝ l✝ v✝ r✝ with | nil => node red nil x nil | node red a y b => match cmp x y with | Ordering.lt => node red (ins cmp x a) y b | Ordering.gt => node red a y (ins cmp x b) | Ordering.eq => node red a x b | node black a y b => match cmp x y with | Ordering.lt => balance1 (ins cmp x a) y b | Ordering.gt => balance2 a y (ins cmp x b) | Ordering.eq => node black a x b) ** split <;> cases ‹_=_› <;> split <;> simp at h₂ <;> simp [*] ** case nil α : Type u_1 p : α → Prop cmp : α → α → Ordering x : α h₁ : p x h₂ : All p nil ⊢ All p (node red nil x nil) ** simp [*] ** Qed
Std.RBNode.Ordered.ins ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b ⊢ Ordered cmp (ins cmp x (node red a y b)) ** unfold ins ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b ⊢ Ordered cmp (match cmp x y with | Ordering.lt => node red (ins cmp x a) y b | Ordering.gt => node red a y (ins cmp x b) | Ordering.eq => node red a x b) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cmp x y = Ordering.lt ⊢ Ordered cmp (node red (ins cmp x a) y b) ** next h => exact ⟨ay.ins ⟨h⟩, yb, ha.ins, hb⟩ ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering h : cmp x y = Ordering.lt ⊢ Ordered cmp (node red (ins cmp x a) y b) ** exact ⟨ay.ins ⟨h⟩, yb, ha.ins, hb⟩ ** case h_2 α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cmp x y = Ordering.gt ⊢ Ordered cmp (node red a y (ins cmp x b)) ** next h => exact ⟨ay, yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩, ha, hb.ins⟩ ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering h : cmp x y = Ordering.gt ⊢ Ordered cmp (node red a y (ins cmp x b)) ** exact ⟨ay, yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩, ha, hb.ins⟩ ** case h_3 α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cmp x y = Ordering.eq ⊢ Ordered cmp (node red a x b) ** next h => exact (⟨ ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩, yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩) ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering h : cmp x y = Ordering.eq ⊢ Ordered cmp (node red a x b) ** exact (⟨ ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩, yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩) ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b ⊢ Ordered cmp (ins cmp x (node black a y b)) ** unfold ins ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b ⊢ Ordered cmp (match cmp x y with | Ordering.lt => balance1 (ins cmp x a) y b | Ordering.gt => balance2 a y (ins cmp x b) | Ordering.eq => node black a x b) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cmp x y = Ordering.lt ⊢ Ordered cmp (balance1 (ins cmp x a) y b) ** next h => exact ha.ins.balance1 (ay.ins ⟨h⟩) yb hb ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering h : cmp x y = Ordering.lt ⊢ Ordered cmp (balance1 (ins cmp x a) y b) ** exact ha.ins.balance1 (ay.ins ⟨h⟩) yb hb ** case h_2 α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cmp x y = Ordering.gt ⊢ Ordered cmp (balance2 a y (ins cmp x b)) ** next h => exact ha.balance2 ay (yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩) hb.ins ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering h : cmp x y = Ordering.gt ⊢ Ordered cmp (balance2 a y (ins cmp x b)) ** exact ha.balance2 ay (yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩) hb.ins ** case h_3 α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cmp x y = Ordering.eq ⊢ Ordered cmp (node black a x b) ** next h => exact (⟨ ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩, yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩) ** α : Type u_1 cmp : α → α → Ordering x : α a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering h : cmp x y = Ordering.eq ⊢ Ordered cmp (node black a x b) ** exact (⟨ ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩, yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩) ** Qed
Std.RBNode.Ordered.insert ** α✝ : Type u_1 cmp : α✝ → α✝ → Ordering t : RBNode α✝ v : α✝ h : Ordered cmp t ⊢ Ordered cmp (insert cmp t v) ** unfold RBNode.insert ** α✝ : Type u_1 cmp : α✝ → α✝ → Ordering t : RBNode α✝ v : α✝ h : Ordered cmp t ⊢ Ordered cmp (match isRed t with | red => setBlack (ins cmp v t) | black => ins cmp v t) ** split <;> simp [Ordered.setBlack, h.ins (x := v)] ** Qed
Std.RBNode.RedRed.balance1 ** α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n ⊢ ∃ c, Balanced (balance1 l v r) c (n + 1) ** unfold balance1 ** α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n ⊢ ∃ c, Balanced (match l, v, r with | node red (node red a x b) y c, z, d => node red (node black a x b) y (node black c z d) | node red a x (node red b y c), z, d => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) c (n + 1) ** split ** case h_1 α : Type u_1 p : Prop n : Nat c : RBColor v : α r : RBNode α hr : Balanced r c n x✝³ : RBNode α x✝² : α x✝¹ a✝ : RBNode α x✝ : α b✝ : RBNode α y✝ : α c✝ : RBNode α hl : RedRed p (node red (node red a✝ x✝ b✝) y✝ c✝) n ⊢ ∃ c, Balanced (node red (node black a✝ x✝ b✝) y✝ (node black c✝ v r)) c (n + 1) ** have .redred _ (.red ha hb) hc := hl ** case h_1 α : Type u_1 p : Prop n : Nat c : RBColor v : α r : RBNode α hr : Balanced r c n x✝³ : RBNode α x✝² : α x✝¹ a✝¹ : RBNode α x✝ : α b✝ : RBNode α y✝ : α c✝ : RBNode α hl : RedRed p (node red (node red a✝¹ x✝ b✝) y✝ c✝) n c₂✝ : RBColor a✝ : p ha : Balanced a✝¹ black n hb : Balanced b✝ black n hc : Balanced c✝ c₂✝ n ⊢ ∃ c, Balanced (node red (node black a✝¹ x✝ b✝) y✝ (node black c✝ v r)) c (n + 1) ** exact ⟨_, .red (.black ha hb) (.black hc hr)⟩ ** case h_2 α : Type u_1 p : Prop n : Nat c : RBColor v : α r : RBNode α hr : Balanced r c n x✝⁴ : RBNode α x✝³ : α x✝² a✝ : RBNode α x✝¹ : α b✝ : RBNode α y✝ : α c✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝ = node red a x b → False hl : RedRed p (node red a✝ x✝¹ (node red b✝ y✝ c✝)) n ⊢ ∃ c, Balanced (node red (node black a✝ x✝¹ b✝) y✝ (node black c✝ v r)) c (n + 1) ** have .redred _ ha (.red hb hc) := hl ** case h_2 α : Type u_1 p : Prop n : Nat c : RBColor v : α r : RBNode α hr : Balanced r c n x✝⁴ : RBNode α x✝³ : α x✝² a✝¹ : RBNode α x✝¹ : α b✝ : RBNode α y✝ : α c✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝¹ = node red a x b → False hl : RedRed p (node red a✝¹ x✝¹ (node red b✝ y✝ c✝)) n c₁✝ : RBColor a✝ : p ha : Balanced a✝¹ c₁✝ n hb : Balanced b✝ black n hc : Balanced c✝ black n ⊢ ∃ c, Balanced (node red (node black a✝¹ x✝¹ b✝) y✝ (node black c✝ v r)) c (n + 1) ** exact ⟨_, .red (.black ha hb) (.black hc hr)⟩ ** case h_3 α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n x✝⁴ : RBNode α x✝³ : α x✝² : RBNode α x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red (node red a x b) y c → False x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red a x (node red b y c) → False ⊢ ∃ c, Balanced (node black l v r) c (n + 1) ** next H1 H2 => match hl with | .balanced hl => exact ⟨_, .black hl hr⟩ | .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black (.red ha hb) hr⟩ | .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl | .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl ** α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n x✝² : RBNode α x✝¹ : α x✝ : RBNode α H1 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red (node red a x b) y c → False H2 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red a x (node red b y c) → False ⊢ ∃ c, Balanced (node black l v r) c (n + 1) ** match hl with | .balanced hl => exact ⟨_, .black hl hr⟩ | .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black (.red ha hb) hr⟩ | .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl | .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl ** α : Type u_1 p : Prop n : Nat c : RBColor l✝ : RBNode α v : α r : RBNode α hl✝ : RedRed p l✝ n hr : Balanced r c n x✝² : RBNode α x✝¹ : α x✝ l : RBNode α c✝ : RBColor hl : Balanced l c✝ n H1 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red (node red a x b) y c → False H2 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red a x (node red b y c) → False ⊢ ∃ c, Balanced (node black l v r) c (n + 1) ** exact ⟨_, .black hl hr⟩ ** α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n x✝³ : RBNode α x✝² : α x✝¹ a✝¹ b✝ : RBNode α x✝ : α a✝ : p ha : Balanced a✝¹ black n hb : Balanced b✝ black n H1 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), node red a✝¹ x✝ b✝ = node red (node red a x b) y c → False H2 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), node red a✝¹ x✝ b✝ = node red a x (node red b y c) → False ⊢ ∃ c, Balanced (node black (node red a✝¹ x✝ b✝) v r) c (n + 1) ** exact ⟨_, .black (.red ha hb) hr⟩ ** α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n x✝³ : RBNode α x✝² : α x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α c₂✝ : RBColor x✝ : α a✝³ : p a✝² : Balanced l✝ black n a✝¹ : Balanced r✝ black n a✝ : Balanced b✝ c₂✝ n H1 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), node red (node red l✝ v✝ r✝) x✝ b✝ = node red (node red a x b) y c → False H2 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), node red (node red l✝ v✝ r✝) x✝ b✝ = node red a x (node red b y c) → False ⊢ ∃ c, Balanced (node black (node red (node red l✝ v✝ r✝) x✝ b✝) v r) c (n + 1) ** cases H1 _ _ _ _ _ rfl ** α : Type u_1 p : Prop n : Nat c : RBColor l : RBNode α v : α r : RBNode α hl : RedRed p l n hr : Balanced r c n x✝³ : RBNode α x✝² : α x✝¹ a✝⁴ : RBNode α c₁✝ : RBColor l✝ : RBNode α v✝ : α r✝ : RBNode α x✝ : α a✝³ : p a✝² : Balanced a✝⁴ c₁✝ n a✝¹ : Balanced l✝ black n a✝ : Balanced r✝ black n H1 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), node red a✝⁴ x✝ (node red l✝ v✝ r✝) = node red (node red a x b) y c → False H2 : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), node red a✝⁴ x✝ (node red l✝ v✝ r✝) = node red a x (node red b y c) → False ⊢ ∃ c, Balanced (node black (node red a✝⁴ x✝ (node red l✝ v✝ r✝)) v r) c (n + 1) ** cases H2 _ _ _ _ _ rfl ** Qed
Std.RBNode.RedRed.balance2 ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n ⊢ ∃ c, Balanced (balance2 l v r) c (n + 1) ** unfold balance2 ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n ⊢ ∃ c, Balanced (match l, v, r with | a, x, node red (node red b y c) z d => node red (node black a x b) y (node black c z d) | a, x, node red b y (node red c z d) => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) c (n + 1) ** split ** case h_1 α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α hl : Balanced l c n x✝² : RBNode α x✝¹ : α x✝ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α hr : RedRed p (node red (node red b✝ y✝ c✝) z✝ d✝) n ⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1) ** have .redred _ (.red ha hb) hc := hr ** case h_1 α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α hl : Balanced l c n x✝² : RBNode α x✝¹ : α x✝ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α hr : RedRed p (node red (node red b✝ y✝ c✝) z✝ d✝) n c₂✝ : RBColor a✝ : p ha : Balanced b✝ black n hb : Balanced c✝ black n hc : Balanced d✝ c₂✝ n ⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1) ** exact ⟨_, .red (.black hl ha) (.black hb hc)⟩ ** case h_2 α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α hl : Balanced l c n x✝³ : RBNode α x✝² : α x✝¹ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), b✝ = node red b y c → False hr : RedRed p (node red b✝ y✝ (node red c✝ z✝ d✝)) n ⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1) ** have .redred _ ha (.red hb hc) := hr ** case h_2 α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α hl : Balanced l c n x✝³ : RBNode α x✝² : α x✝¹ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), b✝ = node red b y c → False hr : RedRed p (node red b✝ y✝ (node red c✝ z✝ d✝)) n c₁✝ : RBColor a✝ : p ha : Balanced b✝ c₁✝ n hb : Balanced c✝ black n hc : Balanced d✝ black n ⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1) ** exact ⟨_, .red (.black hl ha) (.black hb hc)⟩ ** case h_3 α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n x✝⁴ : RBNode α x✝³ : α x✝² : RBNode α x✝¹ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False ⊢ ∃ c, Balanced (node black l v r) c (n + 1) ** next H1 H2 => match hr with | .balanced hr => exact ⟨_, .black hl hr⟩ | .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black hl (.red ha hb)⟩ | .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl | .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n x✝² : RBNode α x✝¹ : α x✝ : RBNode α H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False ⊢ ∃ c, Balanced (node black l v r) c (n + 1) ** match hr with | .balanced hr => exact ⟨_, .black hl hr⟩ | .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black hl (.red ha hb)⟩ | .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl | .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r✝ : RBNode α hl : Balanced l c n hr✝ : RedRed p r✝ n x✝² : RBNode α x✝¹ : α x✝ r : RBNode α c✝ : RBColor hr : Balanced r c✝ n H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False ⊢ ∃ c, Balanced (node black l v r) c (n + 1) ** exact ⟨_, .black hl hr⟩ ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n x✝³ : RBNode α x✝² : α x✝¹ a✝¹ b✝ : RBNode α x✝ : α a✝ : p ha : Balanced a✝¹ black n hb : Balanced b✝ black n H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), node red a✝¹ x✝ b✝ = node red (node red b y c) z d → False H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), node red a✝¹ x✝ b✝ = node red b y (node red c z d) → False ⊢ ∃ c, Balanced (node black l v (node red a✝¹ x✝ b✝)) c (n + 1) ** exact ⟨_, .black hl (.red ha hb)⟩ ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n x✝³ : RBNode α x✝² : α x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α c₂✝ : RBColor x✝ : α a✝³ : p a✝² : Balanced l✝ black n a✝¹ : Balanced r✝ black n a✝ : Balanced b✝ c₂✝ n H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), node red (node red l✝ v✝ r✝) x✝ b✝ = node red (node red b y c) z d → False H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), node red (node red l✝ v✝ r✝) x✝ b✝ = node red b y (node red c z d) → False ⊢ ∃ c, Balanced (node black l v (node red (node red l✝ v✝ r✝) x✝ b✝)) c (n + 1) ** cases H1 _ _ _ _ _ rfl ** α : Type u_1 c : RBColor n : Nat p : Prop l : RBNode α v : α r : RBNode α hl : Balanced l c n hr : RedRed p r n x✝³ : RBNode α x✝² : α x✝¹ a✝⁴ : RBNode α c₁✝ : RBColor l✝ : RBNode α v✝ : α r✝ : RBNode α x✝ : α a✝³ : p a✝² : Balanced a✝⁴ c₁✝ n a✝¹ : Balanced l✝ black n a✝ : Balanced r✝ black n H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), node red a✝⁴ x✝ (node red l✝ v✝ r✝) = node red (node red b y c) z d → False H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), node red a✝⁴ x✝ (node red l✝ v✝ r✝) = node red b y (node red c z d) → False ⊢ ∃ c, Balanced (node black l v (node red a✝⁴ x✝ (node red l✝ v✝ r✝))) c (n + 1) ** cases H2 _ _ _ _ _ rfl ** Qed
Std.RBNode.balance1_eq ** α : Type u_1 c : RBColor n : Nat l : RBNode α v : α r : RBNode α hl : Balanced l c n ⊢ balance1 l v r = node black l v r ** unfold balance1 ** α : Type u_1 c : RBColor n : Nat l : RBNode α v : α r : RBNode α hl : Balanced l c n ⊢ (match l, v, r with | node red (node red a x b) y c, z, d => node red (node black a x b) y (node black c z d) | node red a x (node red b y c), z, d => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) = node black l v r ** split <;> first | rfl | match hl with. ** case h_3 α : Type u_1 c : RBColor n : Nat l : RBNode α v : α r : RBNode α hl : Balanced l c n x✝⁴ : RBNode α x✝³ : α x✝² : RBNode α x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red (node red a x b) y c → False x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α) (y : α) (c : RBNode α), l = node red a x (node red b y c) → False ⊢ node black l v r = node black l v r ** rfl ** case h_2 α : Type u_1 c : RBColor n : Nat v : α r x✝⁴ : RBNode α x✝³ : α x✝² a✝ : RBNode α x✝¹ : α b✝ : RBNode α y✝ : α c✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝ = node red a x b → False hl : Balanced (node red a✝ x✝¹ (node red b✝ y✝ c✝)) c n ⊢ node red (node black a✝ x✝¹ b✝) y✝ (node black c✝ v r) = node black (node red a✝ x✝¹ (node red b✝ y✝ c✝)) v r ** match hl with. ** Qed
Std.RBNode.balance2_eq ** α : Type u_1 c : RBColor n : Nat l : RBNode α v : α r : RBNode α hr : Balanced r c n ⊢ balance2 l v r = node black l v r ** unfold balance2 ** α : Type u_1 c : RBColor n : Nat l : RBNode α v : α r : RBNode α hr : Balanced r c n ⊢ (match l, v, r with | a, x, node red (node red b y c) z d => node red (node black a x b) y (node black c z d) | a, x, node red b y (node red c z d) => node red (node black a x b) y (node black c z d) | a, x, b => node black a x b) = node black l v r ** split <;> first | rfl | match hr with. ** case h_3 α : Type u_1 c : RBColor n : Nat l : RBNode α v : α r : RBNode α hr : Balanced r c n x✝⁴ : RBNode α x✝³ : α x✝² : RBNode α x✝¹ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False ⊢ node black l v r = node black l v r ** rfl ** case h_2 α : Type u_1 c : RBColor n : Nat l : RBNode α v : α x✝³ : RBNode α x✝² : α x✝¹ b✝ : RBNode α y✝ : α c✝ : RBNode α z✝ : α d✝ : RBNode α x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), b✝ = node red b y c → False hr : Balanced (node red b✝ y✝ (node red c✝ z✝ d✝)) c n ⊢ node red (node black l v b✝) y✝ (node black c✝ z✝ d✝) = node black l v (node red b✝ y✝ (node red c✝ z✝ d✝)) ** match hr with. ** Qed
Std.RBNode.Balanced.ins ** case nil α : Type u_1 c : RBColor n : Nat cmp : α → α → Ordering v : α t : RBNode α ⊢ RedRed (isRed nil = red) (ins cmp v nil) 0 ** exact .balanced (.red .nil .nil) ** case red α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n ⊢ RedRed (isRed (node red a x b) = red) (ins cmp v (node red a x b)) n ** unfold ins ** case red α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n ⊢ RedRed (isRed (node red a x b) = red) (match cmp v x with | Ordering.lt => node red (ins cmp v a) x b | Ordering.gt => node red a x (ins cmp v b) | Ordering.eq => node red a v b) n ** split ** case red.h_1 α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.lt ⊢ RedRed (isRed (node red a x b) = red) (node red (ins cmp v a) x b) n ** match ins cmp v a, ihl with | _, .balanced .nil => exact .balanced (.red .nil hr) | _, .balanced (.red ha hb) => exact .redred rfl (.red ha hb) hr | _, .balanced (.black ha hb) => exact .balanced (.red (.black ha hb) hr) | _, .redred h .. => cases hl <;> cases h ** α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α ihl : RedRed (isRed a = red) (ins cmp v a) n x✝ : Ordering heq✝ : cmp v x = Ordering.lt hl : Balanced a black 0 hr : Balanced b black 0 ihr : RedRed (isRed b = red) (ins cmp v b) 0 ⊢ RedRed (isRed (node red a x b) = red) (node red nil x b) 0 ** exact .balanced (.red .nil hr) ** α : Type u_1 c : RBColor n✝¹ : Nat cmp : α → α → Ordering v : α t a : RBNode α n✝ : Nat b : RBNode α x : α ihl : RedRed (isRed a = red) (ins cmp v a) n✝ x✝ : Ordering heq✝ : cmp v x = Ordering.lt n : Nat l✝ : RBNode α v✝ : α r✝ : RBNode α ha : Balanced l✝ black n hb : Balanced r✝ black n hl : Balanced a black n hr : Balanced b black n ihr : RedRed (isRed b = red) (ins cmp v b) n ⊢ RedRed (isRed (node red a x b) = red) (node red (node red l✝ v✝ r✝) x b) n ** exact .redred rfl (.red ha hb) hr ** α : Type u_1 c : RBColor n✝¹ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α ihl : RedRed (isRed a = red) (ins cmp v a) n x✝ : Ordering heq✝ : cmp v x = Ordering.lt l✝ : RBNode α v✝ : α r✝ : RBNode α n✝ : Nat c₁✝ c₂✝ : RBColor ha : Balanced l✝ c₁✝ n✝ hb : Balanced r✝ c₂✝ n✝ hl : Balanced a black (n✝ + 1) hr : Balanced b black (n✝ + 1) ihr : RedRed (isRed b = red) (ins cmp v b) (n✝ + 1) ⊢ RedRed (isRed (node red a x b) = red) (node red (node black l✝ v✝ r✝) x b) (n✝ + 1) ** exact .balanced (.red (.black ha hb) hr) ** α : Type u_1 c : RBColor n✝¹ : Nat cmp : α → α → Ordering v : α t a : RBNode α n✝ : Nat b : RBNode α x : α ihl : RedRed (isRed a = red) (ins cmp v a) n✝ x✝¹ : Ordering heq✝ : cmp v x = Ordering.lt n : Nat a✝² : RBNode α c₁✝ : RBColor b✝ : RBNode α c₂✝ : RBColor x✝ : α h : isRed a = red a✝¹ : Balanced a✝² c₁✝ n a✝ : Balanced b✝ c₂✝ n hl : Balanced a black n hr : Balanced b black n ihr : RedRed (isRed b = red) (ins cmp v b) n ⊢ RedRed (isRed (node red a x b) = red) (node red (node red a✝² x✝ b✝) x b) n ** cases hl <;> cases h ** case red.h_2 α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.gt ⊢ RedRed (isRed (node red a x b) = red) (node red a x (ins cmp v b)) n ** match ins cmp v b, ihr with | _, .balanced .nil => exact .balanced (.red hl .nil) | _, .balanced (.red ha hb) => exact .redred rfl hl (.red ha hb) | _, .balanced (.black ha hb) => exact .balanced (.red hl (.black ha hb)) | _, .redred h .. => cases hr <;> cases h ** α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.gt hl : Balanced a black 0 hr : Balanced b black 0 ihl : RedRed (isRed a = red) (ins cmp v a) 0 ⊢ RedRed (isRed (node red a x b) = red) (node red a x nil) 0 ** exact .balanced (.red hl .nil) ** α : Type u_1 c : RBColor n✝¹ : Nat cmp : α → α → Ordering v : α t a : RBNode α n✝ : Nat b : RBNode α x : α ihr : RedRed (isRed b = red) (ins cmp v b) n✝ x✝ : Ordering heq✝ : cmp v x = Ordering.gt n : Nat l✝ : RBNode α v✝ : α r✝ : RBNode α ha : Balanced l✝ black n hb : Balanced r✝ black n hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ⊢ RedRed (isRed (node red a x b) = red) (node red a x (node red l✝ v✝ r✝)) n ** exact .redred rfl hl (.red ha hb) ** α : Type u_1 c : RBColor n✝¹ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.gt l✝ : RBNode α v✝ : α r✝ : RBNode α n✝ : Nat c₁✝ c₂✝ : RBColor ha : Balanced l✝ c₁✝ n✝ hb : Balanced r✝ c₂✝ n✝ hl : Balanced a black (n✝ + 1) hr : Balanced b black (n✝ + 1) ihl : RedRed (isRed a = red) (ins cmp v a) (n✝ + 1) ⊢ RedRed (isRed (node red a x b) = red) (node red a x (node black l✝ v✝ r✝)) (n✝ + 1) ** exact .balanced (.red hl (.black ha hb)) ** α : Type u_1 c : RBColor n✝¹ : Nat cmp : α → α → Ordering v : α t a : RBNode α n✝ : Nat b : RBNode α x : α ihr : RedRed (isRed b = red) (ins cmp v b) n✝ x✝¹ : Ordering heq✝ : cmp v x = Ordering.gt n : Nat a✝² : RBNode α c₁✝ : RBColor b✝ : RBNode α c₂✝ : RBColor x✝ : α h : isRed b = red a✝¹ : Balanced a✝² c₁✝ n a✝ : Balanced b✝ c₂✝ n hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ⊢ RedRed (isRed (node red a x b) = red) (node red a x (node red a✝² x✝ b✝)) n ** cases hr <;> cases h ** case red.h_3 α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α n : Nat b : RBNode α x : α hl : Balanced a black n hr : Balanced b black n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.eq ⊢ RedRed (isRed (node red a x b) = red) (node red a v b) n ** exact .balanced (.red hl hr) ** case black α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α ca : RBColor n : Nat b : RBNode α cb : RBColor x : α hl : Balanced a ca n hr : Balanced b cb n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n ⊢ RedRed (isRed (node black a x b) = red) (ins cmp v (node black a x b)) (n + 1) ** unfold ins ** case black α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α ca : RBColor n : Nat b : RBNode α cb : RBColor x : α hl : Balanced a ca n hr : Balanced b cb n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n ⊢ RedRed (isRed (node black a x b) = red) (match cmp v x with | Ordering.lt => balance1 (ins cmp v a) x b | Ordering.gt => balance2 a x (ins cmp v b) | Ordering.eq => node black a v b) (n + 1) ** split ** case black.h_1 α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α ca : RBColor n : Nat b : RBNode α cb : RBColor x : α hl : Balanced a ca n hr : Balanced b cb n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.lt ⊢ RedRed (isRed (node black a x b) = red) (balance1 (ins cmp v a) x b) (n + 1) ** exact have ⟨c, h⟩ := ihl.balance1 hr; .balanced h ** case black.h_2 α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α ca : RBColor n : Nat b : RBNode α cb : RBColor x : α hl : Balanced a ca n hr : Balanced b cb n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.gt ⊢ RedRed (isRed (node black a x b) = red) (balance2 a x (ins cmp v b)) (n + 1) ** exact have ⟨c, h⟩ := ihr.balance2 hl; .balanced h ** case black.h_3 α : Type u_1 c : RBColor n✝ : Nat cmp : α → α → Ordering v : α t a : RBNode α ca : RBColor n : Nat b : RBNode α cb : RBColor x : α hl : Balanced a ca n hr : Balanced b cb n ihl : RedRed (isRed a = red) (ins cmp v a) n ihr : RedRed (isRed b = red) (ins cmp v b) n x✝ : Ordering heq✝ : cmp v x = Ordering.eq ⊢ RedRed (isRed (node black a x b) = red) (node black a v b) (n + 1) ** exact .balanced (.black hl hr) ** Qed
Std.RBNode.Balanced.insert ** α : Type u_1 c : RBColor n : Nat cmp : α → α → Ordering v : α t : RBNode α h : Balanced t c n ⊢ ∃ c' n', Balanced (RBNode.insert cmp t v) c' n' ** unfold insert ** α : Type u_1 c : RBColor n : Nat cmp : α → α → Ordering v : α t : RBNode α h : Balanced t c n ⊢ ∃ c' n', Balanced (match isRed t with | red => setBlack (ins cmp v t) | black => ins cmp v t) c' n' ** match ins cmp v t, h.ins cmp v with | _, .balanced h => split <;> [exact ⟨_, h.setBlack⟩; exact ⟨_, _, h⟩] | _, .redred _ ha hb => have .node red .. := t; exact ⟨_, _, .black ha hb⟩ ** α : Type u_1 c : RBColor n : Nat cmp : α → α → Ordering v : α t : RBNode α h✝ : Balanced t c n x✝ : RBNode α c✝ : RBColor h : Balanced x✝ c✝ n ⊢ ∃ c' n', Balanced (match isRed t with | red => setBlack x✝ | black => x✝) c' n' ** split <;> [exact ⟨_, h.setBlack⟩; exact ⟨_, _, h⟩] ** α : Type u_1 c : RBColor n : Nat cmp : α → α → Ordering v : α t : RBNode α h : Balanced t c n a✝¹ : RBNode α c₁✝ : RBColor b✝ : RBNode α c₂✝ : RBColor x✝ : α a✝ : isRed t = red ha : Balanced a✝¹ c₁✝ n hb : Balanced b✝ c₂✝ n ⊢ ∃ c' n', Balanced (match isRed t with | red => setBlack (node red a✝¹ x✝ b✝) | black => node red a✝¹ x✝ b✝) c' n' ** have .node red .. := t ** α : Type u_1 c : RBColor n : Nat cmp : α → α → Ordering v : α t a✝¹ : RBNode α c₁✝ : RBColor b✝ : RBNode α c₂✝ : RBColor x✝ : α ha : Balanced a✝¹ c₁✝ n hb : Balanced b✝ c₂✝ n l✝ : RBNode α v✝ : α r✝ : RBNode α h : Balanced (node red l✝ v✝ r✝) c n a✝ : isRed (node red l✝ v✝ r✝) = red ⊢ ∃ c' n', Balanced (match isRed (node red l✝ v✝ r✝) with | red => setBlack (node red a✝¹ x✝ b✝) | black => node red a✝¹ x✝ b✝) c' n' ** exact ⟨_, _, .black ha hb⟩ ** Qed
Std.RBNode.All.setRed ** α : Type u_1 p : α → Prop t : RBNode α h : All p t ⊢ All p (setRed t) ** unfold setRed ** α : Type u_1 p : α → Prop t : RBNode α h : All p t ⊢ All p (match t with | node c a v b => node red a v b | nil => nil) ** split <;> simp_all ** Qed
Std.RBNode.Ordered.setRed ** α : Type u_1 cmp : α → α → Ordering t : RBNode α ⊢ Ordered cmp (setRed t) ↔ Ordered cmp t ** unfold setRed ** α : Type u_1 cmp : α → α → Ordering t : RBNode α ⊢ Ordered cmp (match t with | node c a v b => node red a v b | nil => nil) ↔ Ordered cmp t ** split <;> simp [Ordered] ** Qed
Std.RBNode.All.balLeft ** α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ r : RBNode α✝ hl : All p l hv : p v hr : All p r ⊢ All p (balLeft l v r) ** unfold balLeft ** α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ r : RBNode α✝ hl : All p l hv : p v hr : All p r ⊢ All p (match l with | node red a x b => node red (node black a x b) v r | l => match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) ** split <;> (try simp_all) ** case h_2 α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ r : RBNode α✝ hl : All p l hv : p v hr : All p r l✝ : RBNode α✝ x✝ : ∀ (a : RBNode α✝) (x : α✝) (b : RBNode α✝), l = node red a x b → False ⊢ All p (match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) ** split <;> simp_all [All.setRed] ** case h_1 α✝ : Type u_1 p : α✝ → Prop v : α✝ r : RBNode α✝ hv : p v hr : All p r l✝ a✝ : RBNode α✝ x✝ : α✝ b✝ : RBNode α✝ hl : All p (node red a✝ x✝ b✝) ⊢ All p (node red (node black a✝ x✝ b✝) v r) ** try simp_all ** case h_1 α✝ : Type u_1 p : α✝ → Prop v : α✝ r : RBNode α✝ hv : p v hr : All p r l✝ a✝ : RBNode α✝ x✝ : α✝ b✝ : RBNode α✝ hl : All p (node red a✝ x✝ b✝) ⊢ All p (node red (node black a✝ x✝ b✝) v r) ** simp_all ** Qed
Std.RBNode.Ordered.balLeft ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (balLeft l v r) ** unfold balLeft ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (match l with | node red a x b => node red (node black a x b) v r | l => match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) ** split ** case h_2 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), l = node red a x b → False ⊢ Ordered cmp (match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) ⊢ Ordered cmp (node red (node black a✝ x✝ b✝) v r) ** exact ⟨lv, vr, hl, hr⟩ ** case h_2.h_1 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), l = node red a x b → False r✝ a✝ : RBNode α y✝ : α b✝ : RBNode α vr : All (fun x => cmpLT cmp v x) (node black a✝ y✝ b✝) hr : Ordered cmp (node black a✝ y✝ b✝) ⊢ Ordered cmp (balance2 l v (node red a✝ y✝ b✝)) ** exact hl.balance2 lv vr hr ** case h_2.h_2 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), l = node red a x b → False r✝ a✝ : RBNode α y✝ : α b✝ : RBNode α z✝ : α c✝ : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node black a✝ y✝ b✝) z✝ c✝) hr : Ordered cmp (node red (node black a✝ y✝ b✝) z✝ c✝) ⊢ Ordered cmp (node red (node black l v a✝) y✝ (balance2 b✝ z✝ (setRed c✝))) ** have ⟨vy, va, _⟩ := vr.2.1 ** case h_2.h_2 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), l = node red a x b → False r✝ a✝ : RBNode α y✝ : α b✝ : RBNode α z✝ : α c✝ : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node black a✝ y✝ b✝) z✝ c✝) hr : Ordered cmp (node red (node black a✝ y✝ b✝) z✝ c✝) vy : (fun x => cmpLT cmp v x) y✝ va : All (fun x => cmpLT cmp v x) a✝ right✝ : All (fun x => cmpLT cmp v x) b✝ ⊢ Ordered cmp (node red (node black l v a✝) y✝ (balance2 b✝ z✝ (setRed c✝))) ** have ⟨⟨yz, _, bz⟩, zc, ⟨ay, yb, ha, hb⟩, hc⟩ := hr ** case h_2.h_2 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), l = node red a x b → False r✝ a✝ : RBNode α y✝ : α b✝ : RBNode α z✝ : α c✝ : RBNode α vr : All (fun x => cmpLT cmp v x) (node red (node black a✝ y✝ b✝) z✝ c✝) hr : Ordered cmp (node red (node black a✝ y✝ b✝) z✝ c✝) vy : (fun x => cmpLT cmp v x) y✝ va : All (fun x => cmpLT cmp v x) a✝ right✝ : All (fun x => cmpLT cmp v x) b✝ yz : (fun x => cmpLT cmp x z✝) y✝ left✝ : All (fun x => cmpLT cmp x z✝) a✝ bz : All (fun x => cmpLT cmp x z✝) b✝ zc : All (fun x => cmpLT cmp z✝ x) c✝ ay : All (fun x => cmpLT cmp x y✝) a✝ yb : All (fun x => cmpLT cmp y✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hc : Ordered cmp c✝ ⊢ Ordered cmp (node red (node black l v a✝) y✝ (balance2 b✝ z✝ (setRed c✝))) ** exact ⟨⟨vy, vy.trans_r lv, ay⟩, balance2_All.2 ⟨yz, yb, (yz.trans_l zc).setRed⟩, ⟨lv, va, hl, ha⟩, hb.balance2 bz zc.setRed (Ordered.setRed.2 hc)⟩ ** case h_2.h_3 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r l✝ : RBNode α x✝² : ∀ (a : RBNode α) (x : α) (b : RBNode α), l = node red a x b → False r✝ : RBNode α x✝¹ : ∀ (a : RBNode α) (y : α) (b : RBNode α), r = node black a y b → False x✝ : ∀ (a : RBNode α) (y : α) (b : RBNode α) (z : α) (c : RBNode α), r = node red (node black a y b) z c → False ⊢ Ordered cmp (node red l v r) ** exact ⟨lv, vr, hl, hr⟩ ** Qed
Std.RBNode.Balanced.balLeft ** α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cr : RBColor n : Nat hl : RedRed True l n hr : Balanced r cr (n + 1) ⊢ RedRed (cr = red) (balLeft l v r) (n + 1) ** unfold balLeft ** α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cr : RBColor n : Nat hl : RedRed True l n hr : Balanced r cr (n + 1) ⊢ RedRed (cr = red) (match l with | node red a x b => node red (node black a x b) v r | l => match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) (n + 1) ** split ** case h_1 α✝ : Type u_1 v : α✝ r : RBNode α✝ cr : RBColor n : Nat hr : Balanced r cr (n + 1) l✝ a✝ : RBNode α✝ x✝ : α✝ b✝ : RBNode α✝ hl : RedRed True (node red a✝ x✝ b✝) n ⊢ RedRed (cr = red) (node red (node black a✝ x✝ b✝) v r) (n + 1) ** next a x b => exact let ⟨ca, cb, ha, hb⟩ := hl.of_red match cr with | red => .redred rfl (.black ha hb) hr | black => .balanced (.red (.black ha hb) hr) ** α✝ : Type u_1 v : α✝ r : RBNode α✝ cr : RBColor n : Nat hr : Balanced r cr (n + 1) l✝ a : RBNode α✝ x : α✝ b : RBNode α✝ hl : RedRed True (node red a x b) n ⊢ RedRed (cr = red) (node red (node black a x b) v r) (n + 1) ** exact let ⟨ca, cb, ha, hb⟩ := hl.of_red match cr with | red => .redred rfl (.black ha hb) hr | black => .balanced (.red (.black ha hb) hr) ** case h_2 α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cr : RBColor n : Nat hl : RedRed True l n hr : Balanced r cr (n + 1) l✝ : RBNode α✝ x✝ : ∀ (a : RBNode α✝) (x : α✝) (b : RBNode α✝), l = node red a x b → False ⊢ RedRed (cr = red) (match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) (n + 1) ** next H => exact match hl with | .redred .. => nomatch H _ _ _ rfl | .balanced hl => match hr with | .black ha hb => let ⟨c, h⟩ := RedRed.balance2 hl (.redred trivial ha hb); .balanced h | .red (.black ha hb) (.black hc hd) => let ⟨c, h⟩ := RedRed.balance2 hb (.redred trivial hc hd); .redred rfl (.black hl ha) h ** α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cr : RBColor n : Nat hl : RedRed True l n hr : Balanced r cr (n + 1) l✝ : RBNode α✝ H : ∀ (a : RBNode α✝) (x : α✝) (b : RBNode α✝), l = node red a x b → False ⊢ RedRed (cr = red) (match r with | node black a y b => balance2 l v (node red a y b) | node red (node black a y b) z c => node red (node black l v a) y (balance2 b z (setRed c)) | r => node red l v r) (n + 1) ** exact match hl with | .redred .. => nomatch H _ _ _ rfl | .balanced hl => match hr with | .black ha hb => let ⟨c, h⟩ := RedRed.balance2 hl (.redred trivial ha hb); .balanced h | .red (.black ha hb) (.black hc hd) => let ⟨c, h⟩ := RedRed.balance2 hb (.redred trivial hc hd); .redred rfl (.black hl ha) h ** Qed
Std.RBNode.All.balRight ** α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ r : RBNode α✝ hl : All p l hv : p v hr : All p r ⊢ All p (balRight l v r) ** unfold balRight ** α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ r : RBNode α✝ hl : All p l hv : p v hr : All p r ⊢ All p (match r with | node red b y c => node red l v (node black b y c) | r => match l with | node black a x b => balance1 (node red a x b) v r | node red a x (node black b y c) => node red (balance1 (setRed a) x b) y (node black c v r) | l => node red l v r) ** split <;> (try simp_all) ** case h_2 α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ r : RBNode α✝ hl : All p l hv : p v hr : All p r l✝ : RBNode α✝ x✝ : ∀ (a : RBNode α✝) (x : α✝) (b : RBNode α✝), r = node red a x b → False ⊢ All p (match l with | node black a x b => balance1 (node red a x b) v r | node red a x (node black b y c) => node red (balance1 (setRed a) x b) y (node black c v r) | l => node red l v r) ** split <;> simp_all [All.setRed] ** case h_1 α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ hl : All p l hv : p v l✝ a✝ : RBNode α✝ x✝ : α✝ b✝ : RBNode α✝ hr : All p (node red a✝ x✝ b✝) ⊢ All p (node red l v (node black a✝ x✝ b✝)) ** try simp_all ** case h_1 α✝ : Type u_1 p : α✝ → Prop l : RBNode α✝ v : α✝ hl : All p l hv : p v l✝ a✝ : RBNode α✝ x✝ : α✝ b✝ : RBNode α✝ hr : All p (node red a✝ x✝ b✝) ⊢ All p (node red l v (node black a✝ x✝ b✝)) ** simp_all ** Qed
Std.RBNode.Balanced.balRight ** α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cl : RBColor n : Nat hl : Balanced l cl (n + 1) hr : RedRed True r n ⊢ RedRed (cl = red) (balRight l v r) (n + 1) ** unfold balRight ** α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cl : RBColor n : Nat hl : Balanced l cl (n + 1) hr : RedRed True r n ⊢ RedRed (cl = red) (match r with | node red b y c => node red l v (node black b y c) | r => match l with | node black a x b => balance1 (node red a x b) v r | node red a x (node black b y c) => node red (balance1 (setRed a) x b) y (node black c v r) | l => node red l v r) (n + 1) ** split ** case h_1 α✝ : Type u_1 l : RBNode α✝ v : α✝ cl : RBColor n : Nat hl : Balanced l cl (n + 1) l✝ a✝ : RBNode α✝ x✝ : α✝ b✝ : RBNode α✝ hr : RedRed True (node red a✝ x✝ b✝) n ⊢ RedRed (cl = red) (node red l v (node black a✝ x✝ b✝)) (n + 1) ** next b y c => exact let ⟨cb, cc, hb, hc⟩ := hr.of_red match cl with | red => .redred rfl hl (.black hb hc) | black => .balanced (.red hl (.black hb hc)) ** α✝ : Type u_1 l : RBNode α✝ v : α✝ cl : RBColor n : Nat hl : Balanced l cl (n + 1) l✝ b : RBNode α✝ y : α✝ c : RBNode α✝ hr : RedRed True (node red b y c) n ⊢ RedRed (cl = red) (node red l v (node black b y c)) (n + 1) ** exact let ⟨cb, cc, hb, hc⟩ := hr.of_red match cl with | red => .redred rfl hl (.black hb hc) | black => .balanced (.red hl (.black hb hc)) ** case h_2 α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cl : RBColor n : Nat hl : Balanced l cl (n + 1) hr : RedRed True r n l✝ : RBNode α✝ x✝ : ∀ (a : RBNode α✝) (x : α✝) (b : RBNode α✝), r = node red a x b → False ⊢ RedRed (cl = red) (match l with | node black a x b => balance1 (node red a x b) v r | node red a x (node black b y c) => node red (balance1 (setRed a) x b) y (node black c v r) | l => node red l v r) (n + 1) ** next H => exact match hr with | .redred .. => nomatch H _ _ _ rfl | .balanced hr => match hl with | .black hb hc => let ⟨c, h⟩ := RedRed.balance1 (.redred trivial hb hc) hr; .balanced h | .red (.black ha hb) (.black hc hd) => let ⟨c, h⟩ := RedRed.balance1 (.redred trivial ha hb) hc; .redred rfl h (.black hd hr) ** α✝ : Type u_1 l : RBNode α✝ v : α✝ r : RBNode α✝ cl : RBColor n : Nat hl : Balanced l cl (n + 1) hr : RedRed True r n l✝ : RBNode α✝ H : ∀ (a : RBNode α✝) (x : α✝) (b : RBNode α✝), r = node red a x b → False ⊢ RedRed (cl = red) (match l with | node black a x b => balance1 (node red a x b) v r | node red a x (node black b y c) => node red (balance1 (setRed a) x b) y (node black c v r) | l => node red l v r) (n + 1) ** exact match hr with | .redred .. => nomatch H _ _ _ rfl | .balanced hr => match hl with | .black hb hc => let ⟨c, h⟩ := RedRed.balance1 (.redred trivial hb hc) hr; .balanced h | .red (.black ha hb) (.black hc hd) => let ⟨c, h⟩ := RedRed.balance1 (.redred trivial ha hb) hc; .redred rfl h (.black hd hr) ** Qed
Std.RBNode.Ordered.append ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (append l r) ** unfold append ** α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α r : RBNode α lv : All (fun x => cmpLT cmp x v) l vr : All (fun x => cmpLT cmp v x) r hl : Ordered cmp l hr : Ordered cmp r ⊢ Ordered cmp (match l, r with | nil, x => x | x, nil => x | node red a x b, node red c y d => match append b c with | node red b' z c' => node red (node red a x b') z (node red c' y d) | bc => node red a x (node red bc y d) | node black a x b, node black c y d => match append b c with | node red b' z c' => node red (node black a x b') z (node black c' y d) | bc => balLeft a x (node black bc y d) | a@h:(node black l v r), node red b x c => node red (append a b) x c | node red a x b, c@h:(node black l v r) => node red a x (append b c)) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering v : α r : RBNode α vr : All (fun x => cmpLT cmp v x) r hr : Ordered cmp r x✝¹ x✝ : RBNode α lv : All (fun x => cmpLT cmp x v) nil hl : Ordered cmp nil ⊢ Ordered cmp r ** exact hr ** case h_2 α : Type u_1 cmp : α → α → Ordering l : RBNode α v : α lv : All (fun x => cmpLT cmp x v) l hl : Ordered cmp l x✝² x✝¹ : RBNode α x✝ : l = nil → False vr : All (fun x => cmpLT cmp v x) nil hr : Ordered cmp nil ⊢ Ordered cmp l ** exact hl ** case h_3 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) ** have ⟨xv, _, bv⟩ := lv ** case h_3 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) ** have ⟨ax, xb, ha, hb⟩ := hl ** case h_3 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) ** have ⟨vy, vc, _⟩ := vr ** case h_3 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) ** have ⟨cy, yd, hc, hd⟩ := hr ** case h_3 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) ** have : _ ∧ _ ∧ _ := ⟨hb.append bv vc hc, xb.append (xv.trans_l vc), (vy.trans_r bv).append cy⟩ ** case h_3 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) ** split ** case h_3.h_1 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node red a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α heq✝ : append b✝¹ c✝ = node red a✝ x✝ b✝ ⊢ Ordered cmp (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) ** next H => have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this have az := xz.trans_r ax; have zd := zy.trans_l yd exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩ ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node red a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ ⊢ Ordered cmp (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) ** have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node red a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝¹ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝¹ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ b'z : All (fun x => cmpLT cmp x x✝) a✝ c'z : All (fun x => cmpLT cmp x✝ x) b✝ hb' : Ordered cmp a✝ hc' : Ordered cmp b✝ xz : (fun x => cmpLT cmp x✝¹ x) x✝ xb' : All (fun x => cmpLT cmp x✝¹ x) a✝ right✝ : All (fun x => cmpLT cmp x✝¹ x) b✝ zy : (fun x => cmpLT cmp x y✝) x✝ left✝ : All (fun x => cmpLT cmp x y✝) a✝ c'y : All (fun x => cmpLT cmp x y✝) b✝ ⊢ Ordered cmp (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) ** have az := xz.trans_r ax ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node red a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝¹ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝¹ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ b'z : All (fun x => cmpLT cmp x x✝) a✝ c'z : All (fun x => cmpLT cmp x✝ x) b✝ hb' : Ordered cmp a✝ hc' : Ordered cmp b✝ xz : (fun x => cmpLT cmp x✝¹ x) x✝ xb' : All (fun x => cmpLT cmp x✝¹ x) a✝ right✝ : All (fun x => cmpLT cmp x✝¹ x) b✝ zy : (fun x => cmpLT cmp x y✝) x✝ left✝ : All (fun x => cmpLT cmp x y✝) a✝ c'y : All (fun x => cmpLT cmp x y✝) b✝ az : All (fun x => cmpLT cmp x x✝) a✝¹ ⊢ Ordered cmp (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) ** have zd := zy.trans_l yd ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node red a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝¹ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝¹ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ b'z : All (fun x => cmpLT cmp x x✝) a✝ c'z : All (fun x => cmpLT cmp x✝ x) b✝ hb' : Ordered cmp a✝ hc' : Ordered cmp b✝ xz : (fun x => cmpLT cmp x✝¹ x) x✝ xb' : All (fun x => cmpLT cmp x✝¹ x) a✝ right✝ : All (fun x => cmpLT cmp x✝¹ x) b✝ zy : (fun x => cmpLT cmp x y✝) x✝ left✝ : All (fun x => cmpLT cmp x y✝) a✝ c'y : All (fun x => cmpLT cmp x y✝) b✝ az : All (fun x => cmpLT cmp x x✝) a✝¹ zd : All (fun x => cmpLT cmp x✝ x) d✝ ⊢ Ordered cmp (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) ** exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩ ** case h_3.h_2 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝ : RBNode α x✝¹ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ b✝) hl : Ordered cmp (node red a✝ x✝¹ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), append b✝ c✝ = node red a x b → False ⊢ Ordered cmp (node red a✝ x✝¹ (node red (append b✝ c✝) y✝ d✝)) ** have ⟨hbc, xbc, bcy⟩ := this ** case h_3.h_2 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝ : RBNode α x✝¹ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ b✝) hl : Ordered cmp (node red a✝ x✝¹ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), append b✝ c✝ = node red a x b → False hbc : Ordered cmp (append b✝ c✝) xbc : All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) bcy : All (fun x => cmpLT cmp x y✝) (append b✝ c✝) ⊢ Ordered cmp (node red a✝ x✝¹ (node red (append b✝ c✝) y✝ d✝)) ** have xy := xv.trans vy ** case h_3.h_2 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝ : RBNode α x✝¹ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝¹ b✝) hl : Ordered cmp (node red a✝ x✝¹ b✝) vr : All (fun x => cmpLT cmp v x) (node red c✝ y✝ d✝) hr : Ordered cmp (node red c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), append b✝ c✝ = node red a x b → False hbc : Ordered cmp (append b✝ c✝) xbc : All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) bcy : All (fun x => cmpLT cmp x y✝) (append b✝ c✝) xy : cmpLT cmp x✝¹ y✝ ⊢ Ordered cmp (node red a✝ x✝¹ (node red (append b✝ c✝) y✝ d✝)) ** exact ⟨ax, ⟨xy, xbc, xy.trans_l yd⟩, ha, bcy, yd, hbc, hd⟩ ** case h_4 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝ b✝) hl : Ordered cmp (node black a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) ** have ⟨xv, _, bv⟩ := lv ** case h_4 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝ b✝) hl : Ordered cmp (node black a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) ** have ⟨ax, xb, ha, hb⟩ := hl ** case h_4 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝ b✝) hl : Ordered cmp (node black a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) ** have ⟨vy, vc, _⟩ := vr ** case h_4 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝ b✝) hl : Ordered cmp (node black a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) ** have ⟨cy, yd, hc, hd⟩ := hr ** case h_4 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝ b✝) hl : Ordered cmp (node black a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) ** have : _ ∧ _ ∧ _ := ⟨hb.append bv vc hc, xb.append (xv.trans_l vc), (vy.trans_r bv).append cy⟩ ** case h_4 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝ b✝) hl : Ordered cmp (node black a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) ⊢ Ordered cmp (match append b✝ c✝ with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) ** split ** case h_4.h_1 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node black a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α heq✝ : append b✝¹ c✝ = node red a✝ x✝ b✝ ⊢ Ordered cmp (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) ** next H => have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this have az := xz.trans_r ax; have zd := zy.trans_l yd exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩ ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node black a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ ⊢ Ordered cmp (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) ** have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node black a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝¹ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝¹ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ b'z : All (fun x => cmpLT cmp x x✝) a✝ c'z : All (fun x => cmpLT cmp x✝ x) b✝ hb' : Ordered cmp a✝ hc' : Ordered cmp b✝ xz : (fun x => cmpLT cmp x✝¹ x) x✝ xb' : All (fun x => cmpLT cmp x✝¹ x) a✝ right✝ : All (fun x => cmpLT cmp x✝¹ x) b✝ zy : (fun x => cmpLT cmp x y✝) x✝ left✝ : All (fun x => cmpLT cmp x y✝) a✝ c'y : All (fun x => cmpLT cmp x y✝) b✝ ⊢ Ordered cmp (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) ** have az := xz.trans_r ax ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node black a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝¹ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝¹ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ b'z : All (fun x => cmpLT cmp x x✝) a✝ c'z : All (fun x => cmpLT cmp x✝ x) b✝ hb' : Ordered cmp a✝ hc' : Ordered cmp b✝ xz : (fun x => cmpLT cmp x✝¹ x) x✝ xb' : All (fun x => cmpLT cmp x✝¹ x) a✝ right✝ : All (fun x => cmpLT cmp x✝¹ x) b✝ zy : (fun x => cmpLT cmp x y✝) x✝ left✝ : All (fun x => cmpLT cmp x y✝) a✝ c'y : All (fun x => cmpLT cmp x y✝) b✝ az : All (fun x => cmpLT cmp x x✝) a✝¹ ⊢ Ordered cmp (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) ** have zd := zy.trans_l yd ** α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b✝¹ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝¹ x✝¹ b✝¹) hl : Ordered cmp (node black a✝¹ x✝¹ b✝¹) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝¹ : All (fun x => cmpLT cmp x v) a✝¹ bv : All (fun x => cmpLT cmp x v) b✝¹ ax : All (fun x => cmpLT cmp x x✝¹) a✝¹ xb : All (fun x => cmpLT cmp x✝¹ x) b✝¹ ha : Ordered cmp a✝¹ hb : Ordered cmp b✝¹ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝¹ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝¹ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝¹ c✝) l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α H : append b✝¹ c✝ = node red a✝ x✝ b✝ b'z : All (fun x => cmpLT cmp x x✝) a✝ c'z : All (fun x => cmpLT cmp x✝ x) b✝ hb' : Ordered cmp a✝ hc' : Ordered cmp b✝ xz : (fun x => cmpLT cmp x✝¹ x) x✝ xb' : All (fun x => cmpLT cmp x✝¹ x) a✝ right✝ : All (fun x => cmpLT cmp x✝¹ x) b✝ zy : (fun x => cmpLT cmp x y✝) x✝ left✝ : All (fun x => cmpLT cmp x y✝) a✝ c'y : All (fun x => cmpLT cmp x y✝) b✝ az : All (fun x => cmpLT cmp x x✝) a✝¹ zd : All (fun x => cmpLT cmp x✝ x) d✝ ⊢ Ordered cmp (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) ** exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩ ** case h_4.h_2 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝ : RBNode α x✝¹ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝¹ b✝) hl : Ordered cmp (node black a✝ x✝¹ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), append b✝ c✝ = node red a x b → False ⊢ Ordered cmp (balLeft a✝ x✝¹ (node black (append b✝ c✝) y✝ d✝)) ** have ⟨hbc, xbc, bcy⟩ := this ** case h_4.h_2 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝ : RBNode α x✝¹ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝¹ b✝) hl : Ordered cmp (node black a✝ x✝¹ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), append b✝ c✝ = node red a x b → False hbc : Ordered cmp (append b✝ c✝) xbc : All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) bcy : All (fun x => cmpLT cmp x y✝) (append b✝ c✝) ⊢ Ordered cmp (balLeft a✝ x✝¹ (node black (append b✝ c✝) y✝ d✝)) ** have xy := xv.trans vy ** case h_4.h_2 α : Type u_1 cmp : α → α → Ordering v : α x✝³ x✝² a✝ : RBNode α x✝¹ : α b✝ c✝ : RBNode α y✝ : α d✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black a✝ x✝¹ b✝) hl : Ordered cmp (node black a✝ x✝¹ b✝) vr : All (fun x => cmpLT cmp v x) (node black c✝ y✝ d✝) hr : Ordered cmp (node black c✝ y✝ d✝) xv : (fun x => cmpLT cmp x v) x✝¹ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ vy : (fun x => cmpLT cmp v x) y✝ vc : All (fun x => cmpLT cmp v x) c✝ right✝ : All (fun x => cmpLT cmp v x) d✝ cy : All (fun x => cmpLT cmp x y✝) c✝ yd : All (fun x => cmpLT cmp y✝ x) d✝ hc : Ordered cmp c✝ hd : Ordered cmp d✝ this : Ordered cmp (append b✝ c✝) ∧ All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) ∧ All (fun x => cmpLT cmp x y✝) (append b✝ c✝) l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), append b✝ c✝ = node red a x b → False hbc : Ordered cmp (append b✝ c✝) xbc : All (fun x => cmpLT cmp x✝¹ x) (append b✝ c✝) bcy : All (fun x => cmpLT cmp x y✝) (append b✝ c✝) xy : cmpLT cmp x✝¹ y✝ ⊢ Ordered cmp (balLeft a✝ x✝¹ (node black (append b✝ c✝) y✝ d✝)) ** exact ha.balLeft ax ⟨xy, xbc, xy.trans_l yd⟩ ⟨bcy, yd, hbc, hd⟩ ** case h_5 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black l✝ v✝ r✝) hl : Ordered cmp (node black l✝ v✝ r✝) vr : All (fun x => cmpLT cmp v x) (node red b✝ x✝ c✝) hr : Ordered cmp (node red b✝ x✝ c✝) ⊢ Ordered cmp (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) ** have ⟨vx, vb, _⟩ := vr ** case h_5 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black l✝ v✝ r✝) hl : Ordered cmp (node black l✝ v✝ r✝) vr : All (fun x => cmpLT cmp v x) (node red b✝ x✝ c✝) hr : Ordered cmp (node red b✝ x✝ c✝) vx : (fun x => cmpLT cmp v x) x✝ vb : All (fun x => cmpLT cmp v x) b✝ right✝ : All (fun x => cmpLT cmp v x) c✝ ⊢ Ordered cmp (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) ** have ⟨bx, yc, hb, hc⟩ := hr ** case h_5 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node black l✝ v✝ r✝) hl : Ordered cmp (node black l✝ v✝ r✝) vr : All (fun x => cmpLT cmp v x) (node red b✝ x✝ c✝) hr : Ordered cmp (node red b✝ x✝ c✝) vx : (fun x => cmpLT cmp v x) x✝ vb : All (fun x => cmpLT cmp v x) b✝ right✝ : All (fun x => cmpLT cmp v x) c✝ bx : All (fun x => cmpLT cmp x x✝) b✝ yc : All (fun x => cmpLT cmp x✝ x) c✝ hb : Ordered cmp b✝ hc : Ordered cmp c✝ ⊢ Ordered cmp (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) ** exact ⟨(vx.trans_r lv).append bx, yc, hl.append lv vb hb, hc⟩ ** case h_6 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black l✝ v✝ r✝) hr : Ordered cmp (node black l✝ v✝ r✝) ⊢ Ordered cmp (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) ** have ⟨xv, _, bv⟩ := lv ** case h_6 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black l✝ v✝ r✝) hr : Ordered cmp (node black l✝ v✝ r✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ⊢ Ordered cmp (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) ** have ⟨ax, xb, ha, hb⟩ := hl ** case h_6 α : Type u_1 cmp : α → α → Ordering v : α x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α lv : All (fun x => cmpLT cmp x v) (node red a✝ x✝ b✝) hl : Ordered cmp (node red a✝ x✝ b✝) vr : All (fun x => cmpLT cmp v x) (node black l✝ v✝ r✝) hr : Ordered cmp (node black l✝ v✝ r✝) xv : (fun x => cmpLT cmp x v) x✝ left✝ : All (fun x => cmpLT cmp x v) a✝ bv : All (fun x => cmpLT cmp x v) b✝ ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ ⊢ Ordered cmp (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) ** exact ⟨ax, xb.append (xv.trans_l vr), ha, hb.append bv vr hr⟩ ** Qed
Std.RBNode.Balanced.append ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor l r : RBNode α hl : Balanced l c₁ n hr : Balanced r c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) (append l r) n ** unfold append ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor l r : RBNode α hl : Balanced l c₁ n hr : Balanced r c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) (match l, r with | nil, x => x | x, nil => x | node red a x b, node red c y d => match append b c with | node red b' z c' => node red (node red a x b') z (node red c' y d) | bc => node red a x (node red bc y d) | node black a x b, node black c y d => match append b c with | node red b' z c' => node red (node black a x b') z (node black c' y d) | bc => balLeft a x (node black bc y d) | a@h:(node black l v r), node red b x c => node red (append a b) x c | node red a x b, c@h:(node black l v r) => node red a x (append b c)) n ** split ** case h_1 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor r : RBNode α hr : Balanced r c₂ n x✝¹ x✝ : RBNode α hl : Balanced nil c₁ n ⊢ RedRed (c₁ = black → c₂ ≠ black) r n ** exact .balanced hr ** case h_2 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor l : RBNode α hl : Balanced l c₁ n x✝² x✝¹ : RBNode α x✝ : l = nil → False hr : Balanced nil c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) l n ** exact .balanced hl ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝ x✝ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) (match append b c with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) n ** have .red ha hb := hl ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝ x✝ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝ black n hb : Balanced b black n ⊢ RedRed (red = black → c₂ ≠ black) (match append b c with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) n ** have .red hc hd := hr ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝ x✝ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n w✝ : RBColor IH : Balanced (append b c) w✝ n ⊢ RedRed (red = black → red ≠ black) (match append b c with | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝) | bc => node red a✝ x✝ (node red bc y✝ d✝)) n ** split ** case h_1 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝¹ x✝¹ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝¹ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n w✝ : RBColor IH : Balanced (append b c) w✝ n l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α heq✝ : append b c = node red a✝ x✝ b✝ ⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n ** next e => have .red hb' hc' := e ▸ IH exact .redred (fun.) (.red ha hb') (.red hc' hd) ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝¹ x✝¹ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝¹ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n w✝ : RBColor IH : Balanced (append b c) w✝ n l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α e : append b c = node red a✝ x✝ b✝ ⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n ** have .red hb' hc' := e ▸ IH ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝¹ x✝¹ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝¹ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α e : append b c = node red a✝ x✝ b✝ hb' : Balanced a✝ black n hc' : Balanced b✝ black n IH : Balanced (append b c) red n ⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n ** exact .redred (fun.) (.red ha hb') (.red hc' hd) ** case h_2 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝ x✝¹ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n w✝ : RBColor IH : Balanced (append b c) w✝ n l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False ⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝¹ (node red (append b c) y✝ d✝)) n ** next bcc _ H => match bcc, append b c, IH, H with | black, _, IH, _ => exact .redred (fun.) ha (.red IH hd) | red, _, .red .., H => cases H _ _ _ rfl ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝ x✝ b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n bcc : RBColor IH : Balanced (append b c) bcc n l✝ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False ⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝ (node red (append b c) y✝ d✝)) n ** match bcc, append b c, IH, H with | black, _, IH, _ => exact .redred (fun.) ha (.red IH hd) | red, _, .red .., H => cases H _ _ _ rfl ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝⁴ x✝³ a✝ : RBNode α x✝² : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node red a✝ x✝² b) c₁ n hr : Balanced (node red c y✝ d✝) c₂ n ha : Balanced a✝ black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n bcc : RBColor IH✝ : Balanced (append b c) bcc n l✝ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False x✝¹ : RBNode α IH : Balanced x✝¹ black n x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), x✝¹ = node red a x b → False ⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝² (node red x✝¹ y✝ d✝)) n ** exact .redred (fun.) ha (.red IH hd) ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝² : RBNode α x✝¹ : α b c : RBNode α y✝¹ : α d✝ : RBNode α hl : Balanced (node red a✝² x✝¹ b) c₁ n hr : Balanced (node red c y✝¹ d✝) c₂ n ha : Balanced a✝² black n hb : Balanced b black n hc : Balanced c black n hd : Balanced d✝ black n bcc : RBColor IH : Balanced (append b c) bcc n l✝ : RBNode α H✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False x✝ y✝ : RBNode α v✝ : α a✝¹ : Balanced x✝ black n a✝ : Balanced y✝ black n H : ∀ (a : RBNode α) (x : α) (b : RBNode α), node red x✝ v✝ y✝ = node red a x b → False ⊢ RedRed (red = black → red ≠ black) (node red a✝² x✝¹ (node red (node red x✝ v✝ y✝) y✝¹ d✝)) n ** cases H _ _ _ rfl ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝ b) c₁ n hr : Balanced (node black c y✝ d✝) c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) (match append b c with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) n ** have .black ha hb := hl ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝ b) c₁ n c₁✝ : RBColor n✝ : Nat c₂✝ : RBColor ha : Balanced a✝ c₁✝ n✝ hb : Balanced b c₂✝ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) ⊢ RedRed (black = black → c₂ ≠ black) (match append b c with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) (n✝ + 1) ** have .black hc hd := hr ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝ b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ ⊢ RedRed (black = black → black ≠ black) (match append b c with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) (n✝ + 1) ** have IH := hb.append hc ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝ b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ ⊢ RedRed (black = black → black ≠ black) (match append b c with | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝) | bc => balLeft a✝ x✝ (node black bc y✝ d✝)) (n✝ + 1) ** split ** case h_1 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝¹ x✝¹ b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝¹ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α heq✝ : append b c = node red a✝ x✝ b✝ ⊢ RedRed (black = black → black ≠ black) (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) (n✝ + 1) ** next e => match e ▸ IH with | .balanced (.red hb' hc') | .redred _ hb' hc' => exact .balanced (.red (.black ha hb') (.black hc' hd)) ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝¹ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝¹ x✝¹ b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝¹ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α e : append b c = node red a✝ x✝ b✝ ⊢ RedRed (black = black → black ≠ black) (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) (n✝ + 1) ** match e ▸ IH with | .balanced (.red hb' hc') | .redred _ hb' hc' => exact .balanced (.red (.black ha hb') (.black hc' hd)) ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝² : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝² x✝¹ b) c₁ n c₁✝² : RBColor n✝ : Nat c₂✝² : RBColor ha : Balanced a✝² c₁✝² n✝ hb : Balanced b c₂✝² n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝¹ c₂✝¹ : RBColor hc : Balanced c c₁✝¹ n✝ hd : Balanced d✝ c₂✝¹ n✝ IH : RedRed (c₂✝² = black → c₁✝¹ ≠ black) (append b c) n✝ l✝ a✝¹ : RBNode α x✝ : α b✝ : RBNode α e : append b c = node red a✝¹ x✝ b✝ c₁✝ c₂✝ : RBColor a✝ : c₂✝² = black → c₁✝¹ ≠ black hb' : Balanced a✝¹ c₁✝ n✝ hc' : Balanced b✝ c₂✝ n✝ ⊢ RedRed (black = black → black ≠ black) (node red (node black a✝² x✝¹ a✝¹) x✝ (node black b✝ y✝ d✝)) (n✝ + 1) ** exact .balanced (.red (.black ha hb') (.black hc' hd)) ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝¹ b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False bc : RBNode α c✝ : RBColor hbc : Balanced bc c✝ n✝ x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False ⊢ RedRed (black = black → black ≠ black) (balLeft a✝ x✝¹ (node black bc y✝ d✝)) (n✝ + 1) ** unfold balLeft ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝¹ b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False bc : RBNode α c✝ : RBColor hbc : Balanced bc c✝ n✝ x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False ⊢ RedRed (black = black → black ≠ black) (match a✝ with | node red a x b => node red (node black a x b) x✝¹ (node black bc y✝ d✝) | l => match node black bc y✝ d✝ with | node black a y b => balance2 l x✝¹ (node red a y b) | node red (node black a y b) z c => node red (node black l x✝¹ a) y (balance2 b z (setRed c)) | r => node red l x✝¹ r) (n✝ + 1) ** split ** case h_1 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝⁴ x✝³ : RBNode α x✝² : α b c : RBNode α y✝ : α d✝ : RBNode α c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝¹ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False bc : RBNode α c✝ : RBColor hbc : Balanced bc c✝ n✝ x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α hl : Balanced (node black (node red a✝ x✝ b✝) x✝² b) c₁ n ha : Balanced (node red a✝ x✝ b✝) c₁✝¹ n✝ ⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1) ** have .red ha' hb' := ha ** case h_1 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝⁴ x✝³ : RBNode α x✝² : α b c : RBNode α y✝ : α d✝ : RBNode α c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝¹ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False bc : RBNode α c✝ : RBColor hbc : Balanced bc c✝ n✝ x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False l✝ a✝ : RBNode α x✝ : α b✝ : RBNode α hl : Balanced (node black (node red a✝ x✝ b✝) x✝² b) c₁ n ha : Balanced (node red a✝ x✝ b✝) c₁✝¹ n✝ ha' : Balanced a✝ black n✝ hb' : Balanced b✝ black n✝ ⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1) ** exact .balanced (.red (.black ha' hb') (.black hbc hd)) ** case h_2 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝⁴ x✝³ a✝ : RBNode α x✝² : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝ x✝² b) c₁ n c₁✝¹ : RBColor n✝ : Nat c₂✝¹ : RBColor ha : Balanced a✝ c₁✝¹ n✝ hb : Balanced b c₂✝¹ n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝ c₂✝ : RBColor hc : Balanced c c₁✝ n✝ hd : Balanced d✝ c₂✝ n✝ IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝ l✝¹ : RBNode α H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False bc : RBNode α c✝ : RBColor hbc : Balanced bc c✝ n✝ x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False l✝ : RBNode α x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝ = node red a x b → False ⊢ RedRed (black = black → black ≠ black) (match node black bc y✝ d✝ with | node black a y b => balance2 a✝ x✝² (node red a y b) | node red (node black a y b) z c => node red (node black a✝ x✝² a) y (balance2 b z (setRed c)) | r => node red a✝ x✝² r) (n✝ + 1) ** exact have ⟨c, h⟩ := RedRed.balance2 ha (.redred trivial hbc hd); .balanced h ** α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝³ x✝² a✝⁴ : RBNode α x✝¹ : α b c : RBNode α y✝ : α d✝ : RBNode α hl : Balanced (node black a✝⁴ x✝¹ b) c₁ n c₁✝² : RBColor n✝ : Nat c₂✝² : RBColor ha : Balanced a✝⁴ c₁✝² n✝ hb : Balanced b c₂✝² n✝ hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1) c₁✝¹ c₂✝¹ : RBColor hc : Balanced c c₁✝¹ n✝ hd : Balanced d✝ c₂✝¹ n✝ IH : RedRed (c₂✝² = black → c₁✝¹ ≠ black) (append b c) n✝ l✝ : RBNode α H✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False a✝³ : RBNode α c₁✝ : RBColor b✝ : RBNode α c₂✝ : RBColor x✝ : α a✝² : c₂✝² = black → c₁✝¹ ≠ black a✝¹ : Balanced a✝³ c₁✝ n✝ a✝ : Balanced b✝ c₂✝ n✝ H : ∀ (a : RBNode α) (x : α) (b : RBNode α), node red a✝³ x✝ b✝ = node red a x b → False ⊢ RedRed (black = black → black ≠ black) (balLeft a✝⁴ x✝¹ (node black (node red a✝³ x✝ b✝) y✝ d✝)) (n✝ + 1) ** cases H _ _ _ rfl ** case h_5 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α hl : Balanced (node black l✝ v✝ r✝) c₁ n hr : Balanced (node red b✝ x✝ c✝) c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) n ** have .red hc hd := hr ** case h_5 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α hl : Balanced (node black l✝ v✝ r✝) c₁ n hr : Balanced (node red b✝ x✝ c✝) c₂ n hc : Balanced b✝ black n hd : Balanced c✝ black n ⊢ RedRed (c₁ = black → red ≠ black) (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) n ** have IH := hl.append hc ** case h_5 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α hl : Balanced (node black l✝ v✝ r✝) c₁ n hr : Balanced (node red b✝ x✝ c✝) c₂ n hc : Balanced b✝ black n hd : Balanced c✝ black n IH : RedRed (c₁ = black → black ≠ black) (append (node black l✝ v✝ r✝) b✝) n ⊢ RedRed (c₁ = black → red ≠ black) (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) n ** have .black ha hb := hl ** case h_5 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ l✝ : RBNode α v✝ : α r✝ b✝ : RBNode α x✝ : α c✝ : RBNode α hl : Balanced (node black l✝ v✝ r✝) c₁ n c₁✝ : RBColor n✝ : Nat c₂✝ : RBColor ha : Balanced l✝ c₁✝ n✝ hb : Balanced r✝ c₂✝ n✝ hr : Balanced (node red b✝ x✝ c✝) c₂ (n✝ + 1) hc : Balanced b✝ black (n✝ + 1) hd : Balanced c✝ black (n✝ + 1) IH✝ : RedRed (black = black → black ≠ black) (append (node black l✝ v✝ r✝) b✝) (n✝ + 1) c : RBColor IH : Balanced (append (node black l✝ v✝ r✝) b✝) c (n✝ + 1) ⊢ RedRed (black = black → red ≠ black) (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) (n✝ + 1) ** exact .redred (fun.) IH hd ** case h_6 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α hl : Balanced (node red a✝ x✝ b✝) c₁ n hr : Balanced (node black l✝ v✝ r✝) c₂ n ⊢ RedRed (c₁ = black → c₂ ≠ black) (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) n ** have .red ha hb := hl ** case h_6 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α hl : Balanced (node red a✝ x✝ b✝) c₁ n hr : Balanced (node black l✝ v✝ r✝) c₂ n ha : Balanced a✝ black n hb : Balanced b✝ black n ⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) n ** have IH := hb.append hr ** case h_6 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α hl : Balanced (node red a✝ x✝ b✝) c₁ n hr : Balanced (node black l✝ v✝ r✝) c₂ n ha : Balanced a✝ black n hb : Balanced b✝ black n IH : RedRed (black = black → c₂ ≠ black) (append b✝ (node black l✝ v✝ r✝)) n ⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) n ** have .black hc hd := hr ** case h_6 α : Type u_1 c₁ : RBColor n : Nat c₂ : RBColor x✝² x✝¹ a✝ : RBNode α x✝ : α b✝ l✝ : RBNode α v✝ : α r✝ : RBNode α hr : Balanced (node black l✝ v✝ r✝) c₂ n c₁✝ : RBColor n✝ : Nat c₂✝ : RBColor hc : Balanced l✝ c₁✝ n✝ hd : Balanced r✝ c₂✝ n✝ hl : Balanced (node red a✝ x✝ b✝) c₁ (n✝ + 1) ha : Balanced a✝ black (n✝ + 1) hb : Balanced b✝ black (n✝ + 1) IH✝ : RedRed (black = black → black ≠ black) (append b✝ (node black l✝ v✝ r✝)) (n✝ + 1) c : RBColor IH : Balanced (append b✝ (node black l✝ v✝ r✝)) c (n✝ + 1) ⊢ RedRed (red = black → black ≠ black) (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) (n✝ + 1) ** exact .redred (fun.) ha IH ** Qed
Std.RBNode.DelProp.redred ** c : RBColor α✝ : Type u_1 t : RBNode α✝ n : Nat h : DelProp c t n ⊢ ∃ n', RedRed (c = black) t n' ** unfold DelProp at h ** c : RBColor α✝ : Type u_1 t : RBNode α✝ n : Nat h : match c with | black => ∃ n', n = n' + 1 ∧ RedRed True t n' | red => ∃ c, Balanced t c n ⊢ ∃ n', RedRed (c = black) t n' ** exact match c, h with | red, ⟨_, h⟩ => ⟨_, .balanced h⟩ | black, ⟨_, _, h⟩ => ⟨_, h.imp fun _ => rfl⟩ ** Qed
Std.RBNode.All.del ** α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ ⊢ All p (del cut (node c✝ a✝² a✝¹ a✝)) ** unfold del ** α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ ⊢ All p (match cut a✝¹ with | Ordering.lt => match isBlack a✝² with | black => balLeft (del cut a✝²) a✝¹ a✝ | red => node red (del cut a✝²) a✝¹ a✝ | Ordering.gt => match isBlack a✝ with | black => balRight a✝² a✝¹ (del cut a✝) | red => node red a✝² a✝¹ (del cut a✝) | Ordering.eq => append a✝² a✝) ** split ** case h_1 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝ : Ordering heq✝ : cut a✝¹ = Ordering.lt ⊢ All p (match isBlack a✝² with | black => balLeft (del cut a✝²) a✝¹ a✝ | red => node red (del cut a✝²) a✝¹ a✝) ** split ** case h_1.h_1 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝¹ : Ordering heq✝¹ : cut a✝¹ = Ordering.lt x✝ : RBColor heq✝ : isBlack a✝² = black ⊢ All p (balLeft (del cut a✝²) a✝¹ a✝) ** exact ha.del.balLeft hy hb ** case h_1.h_2 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝¹ : Ordering heq✝¹ : cut a✝¹ = Ordering.lt x✝ : RBColor heq✝ : isBlack a✝² = red ⊢ All p (node red (del cut a✝²) a✝¹ a✝) ** exact ⟨hy, ha.del, hb⟩ ** case h_2 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝ : Ordering heq✝ : cut a✝¹ = Ordering.gt ⊢ All p (match isBlack a✝ with | black => balRight a✝² a✝¹ (del cut a✝) | red => node red a✝² a✝¹ (del cut a✝)) ** split ** case h_2.h_1 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝¹ : Ordering heq✝¹ : cut a✝¹ = Ordering.gt x✝ : RBColor heq✝ : isBlack a✝ = black ⊢ All p (balRight a✝² a✝¹ (del cut a✝)) ** exact ha.balRight hy hb.del ** case h_2.h_2 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝¹ : Ordering heq✝¹ : cut a✝¹ = Ordering.gt x✝ : RBColor heq✝ : isBlack a✝ = red ⊢ All p (node red a✝² a✝¹ (del cut a✝)) ** exact ⟨hy, ha, hb.del⟩ ** case h_3 α : Type u_1 p : α → Prop cut : α → Ordering c✝ : RBColor a✝² : RBNode α a✝¹ : α a✝ : RBNode α hy : p a✝¹ ha : All p a✝² hb : All p a✝ x✝ : Ordering heq✝ : cut a✝¹ = Ordering.eq ⊢ All p (append a✝² a✝) ** exact ha.append hb ** Qed
Std.RBNode.Ordered.del ** α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b ⊢ Ordered cmp (del cut (node c✝ a y b)) ** unfold del ** α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b ⊢ Ordered cmp (match cut y with | Ordering.lt => match isBlack a with | black => balLeft (del cut a) y b | red => node red (del cut a) y b | Ordering.gt => match isBlack b with | black => balRight a y (del cut b) | red => node red a y (del cut b) | Ordering.eq => append a b) ** split ** case h_1 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cut y = Ordering.lt ⊢ Ordered cmp (match isBlack a with | black => balLeft (del cut a) y b | red => node red (del cut a) y b) ** split ** case h_1.h_1 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝¹ : Ordering heq✝¹ : cut y = Ordering.lt x✝ : RBColor heq✝ : isBlack a = black ⊢ Ordered cmp (balLeft (del cut a) y b) ** exact ha.del.balLeft ay.del yb hb ** case h_1.h_2 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝¹ : Ordering heq✝¹ : cut y = Ordering.lt x✝ : RBColor heq✝ : isBlack a = red ⊢ Ordered cmp (node red (del cut a) y b) ** exact ⟨ay.del, yb, ha.del, hb⟩ ** case h_2 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cut y = Ordering.gt ⊢ Ordered cmp (match isBlack b with | black => balRight a y (del cut b) | red => node red a y (del cut b)) ** split ** case h_2.h_1 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝¹ : Ordering heq✝¹ : cut y = Ordering.gt x✝ : RBColor heq✝ : isBlack b = black ⊢ Ordered cmp (balRight a y (del cut b)) ** exact ha.balRight ay yb.del hb.del ** case h_2.h_2 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝¹ : Ordering heq✝¹ : cut y = Ordering.gt x✝ : RBColor heq✝ : isBlack b = red ⊢ Ordered cmp (node red a y (del cut b)) ** exact ⟨ay, yb.del, ha, hb.del⟩ ** case h_3 α : Type u_1 cmp : α → α → Ordering cut : α → Ordering c✝ : RBColor a : RBNode α y : α b : RBNode α ay : All (fun x => cmpLT cmp x y) a yb : All (fun x => cmpLT cmp y x) b ha : Ordered cmp a hb : Ordered cmp b x✝ : Ordering heq✝ : cut y = Ordering.eq ⊢ Ordered cmp (append a b) ** exact ha.append ay yb hb ** Qed
Std.RBNode.Balanced.del ** case nil α : Type u_1 c : RBColor n : Nat cut : α → Ordering t : RBNode α ⊢ DelProp (isBlack nil) (del cut nil) 0 ** exact ⟨_, .nil⟩ ** case black α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α c₁✝ : RBColor n : Nat b : RBNode α c₂✝ : RBColor v✝ : α ha : Balanced a c₁✝ n hb : Balanced b c₂✝ n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n ⊢ DelProp (isBlack (node black a v✝ b)) (del cut (node black a v✝ b)) (n + 1) ** refine ⟨_, rfl, ?_⟩ ** case black α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α c₁✝ : RBColor n : Nat b : RBNode α c₂✝ : RBColor v✝ : α ha : Balanced a c₁✝ n hb : Balanced b c₂✝ n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n ⊢ RedRed True (del cut (node black a v✝ b)) n ** unfold del ** case black α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α c₁✝ : RBColor n : Nat b : RBNode α c₂✝ : RBColor v✝ : α ha : Balanced a c₁✝ n hb : Balanced b c₂✝ n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n ⊢ RedRed True (match cut v✝ with | Ordering.lt => match isBlack a with | black => balLeft (del cut a) v✝ b | red => node red (del cut a) v✝ b | Ordering.gt => match isBlack b with | black => balRight a v✝ (del cut b) | red => node red a v✝ (del cut b) | Ordering.eq => append a b) n ** split ** case black.h_1 α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α c₁✝ : RBColor n : Nat b : RBNode α c₂✝ : RBColor v✝ : α ha : Balanced a c₁✝ n hb : Balanced b c₂✝ n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n x✝ : Ordering heq✝ : cut v✝ = Ordering.lt ⊢ RedRed True (match isBlack a with | black => balLeft (del cut a) v✝ b | red => node red (del cut a) v✝ b) n ** exact match a, n, iha with | .nil, _, ⟨c, ha⟩ | .node red .., _, ⟨c, ha⟩ => .redred ⟨⟩ ha hb | .node black .., _, ⟨n, rfl, ha⟩ => (hb.balLeft ha).imp fun _ => ⟨⟩ ** case black.h_2 α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α c₁✝ : RBColor n : Nat b : RBNode α c₂✝ : RBColor v✝ : α ha : Balanced a c₁✝ n hb : Balanced b c₂✝ n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n x✝ : Ordering heq✝ : cut v✝ = Ordering.gt ⊢ RedRed True (match isBlack b with | black => balRight a v✝ (del cut b) | red => node red a v✝ (del cut b)) n ** exact match b, n, ihb with | .nil, _, ⟨c, hb⟩ | .node .red .., _, ⟨c, hb⟩ => .redred ⟨⟩ ha hb | .node black .., _, ⟨n, rfl, hb⟩ => (ha.balRight hb).imp fun _ => ⟨⟩ ** case black.h_3 α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α c₁✝ : RBColor n : Nat b : RBNode α c₂✝ : RBColor v✝ : α ha : Balanced a c₁✝ n hb : Balanced b c₂✝ n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ RedRed True (append a b) n ** exact (ha.append hb).imp fun _ => ⟨⟩ ** case red α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α n : Nat b : RBNode α v✝ : α ha : Balanced a black n hb : Balanced b black n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n ⊢ DelProp (isBlack (node red a v✝ b)) (del cut (node red a v✝ b)) n ** unfold del ** case red α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α n : Nat b : RBNode α v✝ : α ha : Balanced a black n hb : Balanced b black n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n ⊢ DelProp (isBlack (node red a v✝ b)) (match cut v✝ with | Ordering.lt => match isBlack a with | black => balLeft (del cut a) v✝ b | red => node red (del cut a) v✝ b | Ordering.gt => match isBlack b with | black => balRight a v✝ (del cut b) | red => node red a v✝ (del cut b) | Ordering.eq => append a b) n ** split ** case red.h_1 α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α n : Nat b : RBNode α v✝ : α ha : Balanced a black n hb : Balanced b black n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n x✝ : Ordering heq✝ : cut v✝ = Ordering.lt ⊢ DelProp (isBlack (node red a v✝ b)) (match isBlack a with | black => balLeft (del cut a) v✝ b | red => node red (del cut a) v✝ b) n ** exact match a, n, iha with | .nil, _, _ => ⟨_, .red ha hb⟩ | .node black .., _, ⟨n, rfl, ha⟩ => (hb.balLeft ha).of_false (fun.) ** case red.h_2 α : Type u_1 c : RBColor n✝ : Nat cut : α → Ordering t a : RBNode α n : Nat b : RBNode α v✝ : α ha : Balanced a black n hb : Balanced b black n iha : DelProp (isBlack a) (del cut a) n ihb : DelProp (isBlack b) (del cut b) n x✝ : Ordering heq✝ : cut v✝ = Ordering.gt ⊢ DelProp (isBlack (node red a v✝ b)) (match isBlack b with | black => balRight a v✝ (del cut b) | red => node red a v✝ (del cut b)) n ** exact match b, n, ihb with | .nil, _, _ => ⟨_, .red ha hb⟩ | .node black .., _, ⟨n, rfl, hb⟩ => (ha.balRight hb).of_false (fun.) ** Qed
Rat.maybeNormalize_eq ** num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) ⊢ maybeNormalize num den g den_nz reduced = mk' (Int.div num ↑g) (den / g) ** unfold maybeNormalize ** num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) ⊢ (if hg : g = 1 then mk' num den else mk' (Int.div num ↑g) (den / g)) = mk' (Int.div num ↑g) (den / g) ** split ** case inl num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) h✝ : g = 1 ⊢ mk' num den = mk' (Int.div num ↑g) (den / g) ** subst g ** case inl num : Int den : Nat den_nz : den / 1 ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑1)) (den / 1) ⊢ mk' num den = mk' (Int.div num ↑1) (den / 1) ** simp ** case inr num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) h✝ : ¬g = 1 ⊢ mk' (Int.div num ↑g) (den / g) = mk' (Int.div num ↑g) (den / g) ** rfl ** Qed
Rat.normalize_zero ** d : Nat nz : d ≠ 0 ⊢ normalize 0 d = 0 ** simp [normalize, Int.zero_div, Int.natAbs_zero, Nat.div_self (Nat.pos_of_ne_zero nz)] ** d : Nat nz : d ≠ 0 ⊢ mk' 0 1 = 0 ** rfl ** Qed
Rat.mk_eq_normalize ** num : Int den : Nat nz : den ≠ 0 c : Nat.Coprime (Int.natAbs num) den ⊢ mk' num den = normalize num den ** simp [normalize_eq, c.gcd_eq_one] ** Qed
Rat.normalize_mul_left ** d : Nat n : Int a : Nat d0 : d ≠ 0 a0 : a ≠ 0 ⊢ normalize (↑a * n) (a * d) = normalize n d ** simp [normalize_eq, mk'.injEq, Int.natAbs_mul, Nat.gcd_mul_left, Nat.mul_div_mul_left _ _ (Nat.pos_of_ne_zero a0), Int.ofNat_mul, Int.mul_ediv_mul_of_pos _ _ (Int.ofNat_pos.2 <| Nat.pos_of_ne_zero a0)] ** Qed
Rat.normalize_mul_right ** d : Nat n : Int a : Nat d0 : d ≠ 0 a0 : a ≠ 0 ⊢ normalize (n * ↑a) (d * a) = normalize n d ** rw [← normalize_mul_left (d0 := d0) a0] ** d : Nat n : Int a : Nat d0 : d ≠ 0 a0 : a ≠ 0 ⊢ normalize (n * ↑a) (d * a) = normalize (↑a * n) (a * d) ** congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm] ** Qed
Rat.maybeNormalize_eq_normalize ** num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) hn : ↑g ∣ num hd : g ∣ den ⊢ maybeNormalize num den g den_nz reduced = normalize num den ** simp only [maybeNormalize_eq, mk_eq_normalize, Int.div_eq_ediv_of_dvd hn] ** num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) hn : ↑g ∣ num hd : g ∣ den this : g ≠ 0 ⊢ normalize (num / ↑g) (den / g) = normalize num den ** rw [← normalize_mul_right _ this, Int.ediv_mul_cancel hn] ** num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) hn : ↑g ∣ num hd : g ∣ den this : g ≠ 0 ⊢ normalize num (den / g * g) = normalize num den ** congr 1 ** case e_den num : Int den g : Nat den_nz : den / g ≠ 0 reduced : Nat.Coprime (Int.natAbs (Int.div num ↑g)) (den / g) hn : ↑g ∣ num hd : g ∣ den this : g ≠ 0 ⊢ den / g * g = den ** exact Nat.div_mul_cancel hd ** Qed
Rat.normalize_num_den' ** num : Int den : Nat nz : den ≠ 0 ⊢ ∃ d, d ≠ 0 ∧ num = (normalize num den).num * ↑d ∧ den = (normalize num den).den * d ** refine ⟨num.natAbs.gcd den, Nat.gcd_ne_zero_right nz, ?_⟩ ** num : Int den : Nat nz : den ≠ 0 ⊢ num = (normalize num den).num * ↑(Nat.gcd (Int.natAbs num) den) ∧ den = (normalize num den).den * Nat.gcd (Int.natAbs num) den ** simp [normalize_eq, Int.ediv_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] ** Qed
Rat.normalize_eq_mkRat ** num : Int den : Nat den_nz : den ≠ 0 ⊢ normalize num den = mkRat num den ** simp [mkRat, den_nz] ** Qed
Rat.mkRat_self ** a : Rat ⊢ mkRat a.num a.den = a ** rw [← normalize_eq_mkRat a.den_nz, normalize_self] ** Qed
Rat.mk_eq_mkRat ** num : Int den : Nat nz : den ≠ 0 c : Nat.Coprime (Int.natAbs num) den ⊢ mk' num den = mkRat num den ** simp [mk_eq_normalize, normalize_eq_mkRat] ** Qed
Rat.zero_mkRat ** n : Nat ⊢ mkRat 0 n = 0 ** simp [mkRat_def] ** n : Nat ⊢ (if h : n = 0 then 0 else 0) = 0 ** apply ite_self ** Qed
Rat.mkRat_zero ** n : Int ⊢ mkRat n 0 = 0 ** simp [mkRat_def] ** Qed
Rat.mkRat_eq_zero ** d : Nat n : Int d0 : d ≠ 0 ⊢ mkRat n d = 0 ↔ n = 0 ** simp [mkRat_def, d0] ** Qed
Rat.mkRat_mul_left ** n : Int d a : Nat a0 : a ≠ 0 ⊢ mkRat (↑a * n) (a * d) = mkRat n d ** if d0 : d = 0 then simp [d0] else rw [← normalize_eq_mkRat d0, ← normalize_mul_left d0 a0, normalize_eq_mkRat] ** n : Int d a : Nat a0 : a ≠ 0 d0 : d = 0 ⊢ mkRat (↑a * n) (a * d) = mkRat n d ** simp [d0] ** n : Int d a : Nat a0 : a ≠ 0 d0 : ¬d = 0 ⊢ mkRat (↑a * n) (a * d) = mkRat n d ** rw [← normalize_eq_mkRat d0, ← normalize_mul_left d0 a0, normalize_eq_mkRat] ** Qed
Rat.mkRat_eq_iff ** d₁ d₂ : Nat n₁ n₂ : Int z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 ⊢ mkRat n₁ d₁ = mkRat n₂ d₂ ↔ n₁ * ↑d₂ = n₂ * ↑d₁ ** rw [← normalize_eq_mkRat z₁, ← normalize_eq_mkRat z₂, normalize_eq_iff] ** Qed
Rat.divInt_ofNat ** num : Int den : Nat ⊢ num /. ↑den = mkRat num den ** simp [divInt, normalize_eq_mkRat] ** Qed
Rat.divInt_self ** a : Rat ⊢ a.num /. ↑a.den = a ** rw [divInt_ofNat, mkRat_self] ** Qed
Rat.zero_divInt ** n : Int ⊢ 0 /. n = 0 ** cases n <;> simp [divInt] ** Qed
Rat.neg_divInt_neg ** num den : Int ⊢ -num /. -den = num /. den ** match den with | Nat.succ n => simp [divInt, Int.neg_ofNat_succ, normalize_eq_mkRat, Int.neg_neg] | 0 => rfl | Int.negSucc n => simp [divInt, Int.neg_negSucc, normalize_eq_mkRat, Int.neg_neg] ** num den : Int n : Nat ⊢ -num /. -↑(Nat.succ n) = num /. ↑(Nat.succ n) ** simp [divInt, Int.neg_ofNat_succ, normalize_eq_mkRat, Int.neg_neg] ** num den : Int ⊢ -num /. -0 = num /. 0 ** rfl ** num den : Int n : Nat ⊢ -num /. -Int.negSucc n = num /. Int.negSucc n ** simp [divInt, Int.neg_negSucc, normalize_eq_mkRat, Int.neg_neg] ** Qed
Rat.divInt_neg' ** num den : Int ⊢ num /. -den = -num /. den ** rw [← neg_divInt_neg, Int.neg_neg] ** Qed
Rat.divInt_eq_iff ** d₁ d₂ n₁ n₂ : Int z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 ⊢ n₁ /. d₁ = n₂ /. d₂ ↔ n₁ * d₂ = n₂ * d₁ ** rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;> rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;> simp_all [divInt_neg', Int.ofNat_eq_zero, Int.neg_eq_zero, mkRat_eq_iff, Int.neg_mul, Int.mul_neg, Int.eq_neg_comm, eq_comm] ** Qed
Rat.divInt_num_den ** d n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' z : d ≠ 0 h : n /. d = mk' n' d' ⊢ ∃ m, m ≠ 0 ∧ n = n' * m ∧ d = ↑d' * m ** rcases Int.eq_nat_or_neg d with ⟨_, rfl | rfl⟩ <;> simp_all [divInt_neg', Int.ofNat_eq_zero, Int.neg_eq_zero] ** case intro.inl n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat n w✝ = mk' n' d' ⊢ ∃ m, ¬m = 0 ∧ n = n' * m ∧ ↑w✝ = ↑d' * m ** have ⟨m, h₁, h₂⟩ := mkRat_num_den z h ** case intro.inl n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat n w✝ = mk' n' d' m : Nat h₁ : m ≠ 0 h₂ : n = n' * ↑m ∧ w✝ = d' * m ⊢ ∃ m, ¬m = 0 ∧ n = n' * m ∧ ↑w✝ = ↑d' * m ** exists m ** case intro.inl n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat n w✝ = mk' n' d' m : Nat h₁ : m ≠ 0 h₂ : n = n' * ↑m ∧ w✝ = d' * m ⊢ ¬↑m = 0 ∧ n = n' * ↑m ∧ ↑w✝ = ↑d' * ↑m ** simp [Int.ofNat_eq_zero, Int.ofNat_mul, h₁, h₂] ** case intro.inr n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat (-n) w✝ = mk' n' d' ⊢ ∃ m, ¬m = 0 ∧ n = n' * m ∧ -↑w✝ = ↑d' * m ** have ⟨m, h₁, h₂⟩ := mkRat_num_den z h ** case intro.inr n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat (-n) w✝ = mk' n' d' m : Nat h₁ : m ≠ 0 h₂ : -n = n' * ↑m ∧ w✝ = d' * m ⊢ ∃ m, ¬m = 0 ∧ n = n' * m ∧ -↑w✝ = ↑d' * m ** exists -m ** case intro.inr n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat (-n) w✝ = mk' n' d' m : Nat h₁ : m ≠ 0 h₂ : -n = n' * ↑m ∧ w✝ = d' * m ⊢ ¬-↑m = 0 ∧ n = n' * -↑m ∧ -↑w✝ = ↑d' * -↑m ** rw [← Int.neg_inj, Int.neg_neg] at h₂ ** case intro.inr n n' : Int d' : Nat z' : d' ≠ 0 c : Nat.Coprime (Int.natAbs n') d' w✝ : Nat z : ¬w✝ = 0 h : mkRat (-n) w✝ = mk' n' d' m : Nat h₁ : m ≠ 0 h₂ : n = -(n' * ↑m) ∧ w✝ = d' * m ⊢ ¬-↑m = 0 ∧ n = n' * -↑m ∧ -↑w✝ = ↑d' * -↑m ** simp [Int.ofNat_eq_zero, Int.ofNat_mul, h₁, h₂, Int.mul_neg, Int.neg_eq_zero] ** Qed
Rat.add_def ** a b : Rat ⊢ a + b = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** show Rat.add .. = _ ** a b : Rat ⊢ Rat.add a b = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** delta Rat.add ** a b : Rat ⊢ (let g := Nat.gcd a.den b.den; if hg : g = 1 then let_fun den_nz := (_ : a.den * b.den ≠ 0); let_fun reduced := (_ : Nat.gcd (Int.natAbs (a.num * ↑b.den + b.num * ↑a.den)) (a.den * b.den) = 1); mk' (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) else let den := a.den / g * b.den; let num := a.num * ↑(b.den / g) + b.num * ↑(a.den / g); let g1 := Nat.gcd (Int.natAbs num) g; let_fun den_nz := (_ : a.den / Nat.gcd a.den b.den * b.den ≠ 0); let_fun e := (_ : let den := a.den / Nat.gcd a.den b.den * b.den; let num := a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den); Nat.gcd (Int.natAbs num) (Nat.gcd a.den b.den) = Nat.gcd (Int.natAbs num) den); maybeNormalize num den g1 (_ : den / g1 ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div num ↑g1)) (den / g1))) = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** dsimp only ** a b : Rat ⊢ (if hg : Nat.gcd a.den b.den = 1 then mk' (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) else maybeNormalize (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den) (Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)) (_ : a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den) ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) ↑(Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) (a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** split ** case inl a b : Rat h✝ : Nat.gcd a.den b.den = 1 ⊢ mk' (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** exact (normalize_self _).symm ** case inr a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 ⊢ maybeNormalize (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den) (Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)) (_ : a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den) ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) ↑(Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) (a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den))) = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** have : a.den.gcd b.den ≠ 0 := Nat.gcd_ne_zero_left a.den_nz ** case inr a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ maybeNormalize (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den) (Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)) (_ : a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den) ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) ↑(Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) (a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den))) = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** rw [maybeNormalize_eq_normalize _ _ (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..) (Nat.dvd_trans (Nat.gcd_dvd_right ..) <| Nat.dvd_trans (Nat.gcd_dvd_right ..) (Nat.dvd_mul_left ..)), ← normalize_mul_right _ this] ** case inr a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ normalize ((a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) * ↑(Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den * Nat.gcd a.den b.den) = normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** congr 1 ** case inr.e_num a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ (a.num * ↑(b.den / Nat.gcd a.den b.den) + b.num * ↑(a.den / Nat.gcd a.den b.den)) * ↑(Nat.gcd a.den b.den) = a.num * ↑b.den + b.num * ↑a.den ** simp only [Int.add_mul, Int.mul_assoc, Int.ofNat_mul_ofNat, Nat.div_mul_cancel (Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] ** case inr.e_den a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ a.den / Nat.gcd a.den b.den * b.den * Nat.gcd a.den b.den = a.den * b.den ** rw [Nat.mul_right_comm, Nat.div_mul_cancel (Nat.gcd_dvd_left ..)] ** Qed
Rat.add_def' ** a b : Rat ⊢ a + b = mkRat (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ** rw [add_def, normalize_eq_mkRat] ** Qed
Rat.normalize_add_normalize ** n₁ n₂ : Int d₁ d₂ : Nat z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 ⊢ normalize n₁ d₁ + normalize n₂ d₂ = normalize (n₁ * ↑d₂ + n₂ * ↑d₁) (d₁ * d₂) ** cases e₁ : normalize n₁ d₁ z₁ ** case mk' n₁ n₂ : Int d₁ d₂ : Nat z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ e₁ : normalize n₁ d₁ = mk' num✝ den✝ ⊢ mk' num✝ den✝ + normalize n₂ d₂ = normalize (n₁ * ↑d₂ + n₂ * ↑d₁) (d₁ * d₂) ** rcases normalize_num_den e₁ with ⟨g₁, zg₁, rfl, rfl⟩ ** case mk'.intro.intro.intro n₂ : Int d₂ : Nat z₂ : d₂ ≠ 0 num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝ * g₁ ≠ 0 e₁ : normalize (num✝ * ↑g₁) (den✝ * g₁) = mk' num✝ den✝ ⊢ mk' num✝ den✝ + normalize n₂ d₂ = normalize (num✝ * ↑g₁ * ↑d₂ + n₂ * ↑(den✝ * g₁)) (den✝ * g₁ * d₂) ** cases e₂ : normalize n₂ d₂ z₂ ** case mk'.intro.intro.intro.mk' n₂ : Int d₂ : Nat z₂ : d₂ ≠ 0 num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ e₂ : normalize n₂ d₂ = mk' num✝ den✝ ⊢ mk' num✝¹ den✝¹ + mk' num✝ den✝ = normalize (num✝¹ * ↑g₁ * ↑d₂ + n₂ * ↑(den✝¹ * g₁)) (den✝¹ * g₁ * d₂) ** rcases normalize_num_den e₂ with ⟨g₂, zg₂, rfl, rfl⟩ ** case mk'.intro.intro.intro.mk'.intro.intro.intro num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ mk' num✝¹ den✝¹ + mk' num✝ den✝ = normalize (num✝¹ * ↑g₁ * ↑(den✝ * g₂) + num✝ * ↑g₂ * ↑(den✝¹ * g₁)) (den✝¹ * g₁ * (den✝ * g₂)) ** simp only [add_def] ** case mk'.intro.intro.intro.mk'.intro.intro.intro num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ normalize (num✝¹ * ↑den✝ + num✝ * ↑den✝¹) (den✝¹ * den✝) = normalize (num✝¹ * ↑g₁ * ↑(den✝ * g₂) + num✝ * ↑g₂ * ↑(den✝¹ * g₁)) (den✝¹ * g₁ * (den✝ * g₂)) ** rw [← normalize_mul_right _ (Nat.mul_ne_zero zg₁ zg₂)] ** case mk'.intro.intro.intro.mk'.intro.intro.intro num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ normalize ((num✝¹ * ↑den✝ + num✝ * ↑den✝¹) * ↑(g₁ * g₂)) (den✝¹ * den✝ * (g₁ * g₂)) = normalize (num✝¹ * ↑g₁ * ↑(den✝ * g₂) + num✝ * ↑g₂ * ↑(den✝¹ * g₁)) (den✝¹ * g₁ * (den✝ * g₂)) ** congr 1 ** case mk'.intro.intro.intro.mk'.intro.intro.intro.e_num num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ (num✝¹ * ↑den✝ + num✝ * ↑den✝¹) * ↑(g₁ * g₂) = num✝¹ * ↑g₁ * ↑(den✝ * g₂) + num✝ * ↑g₂ * ↑(den✝¹ * g₁) ** rw [Int.add_mul] ** case mk'.intro.intro.intro.mk'.intro.intro.intro.e_num num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ num✝¹ * ↑den✝ * ↑(g₁ * g₂) + num✝ * ↑den✝¹ * ↑(g₁ * g₂) = num✝¹ * ↑g₁ * ↑(den✝ * g₂) + num✝ * ↑g₂ * ↑(den✝¹ * g₁) ** simp [Int.ofNat_mul, Int.mul_assoc, Int.mul_left_comm, Int.mul_comm] ** case mk'.intro.intro.intro.mk'.intro.intro.intro.e_den num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ den✝¹ * den✝ * (g₁ * g₂) = den✝¹ * g₁ * (den✝ * g₂) ** simp [Nat.mul_left_comm, Nat.mul_comm] ** Qed
Rat.divInt_add_divInt ** n₁ n₂ d₁ d₂ : Int z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 ⊢ n₁ /. d₁ + n₂ /. d₂ = (n₁ * d₂ + n₂ * d₁) /. (d₁ * d₂) ** rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;> rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;> simp_all [-Int.natCast_mul, Int.ofNat_eq_zero, Int.neg_eq_zero, divInt_neg', Int.mul_neg, Int.ofNat_mul_ofNat, Int.neg_add, Int.neg_mul, mkRat_add_mkRat] ** Qed
Rat.neg_normalize ** n : Int d : Nat z : d ≠ 0 ⊢ -normalize n d = normalize (-n) d ** simp [normalize, maybeNormalize_eq] ** n : Int d : Nat z : d ≠ 0 ⊢ -mk' (Int.div n ↑(Nat.gcd (Int.natAbs n) d)) (d / Nat.gcd (Int.natAbs n) d) = mk' (-Int.div n ↑(Nat.gcd (Int.natAbs n) d)) (d / Nat.gcd (Int.natAbs n) d) ** ext <;> simp [Int.neg_div] ** Qed
Rat.sub_def ** a b : Rat ⊢ a - b = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** show Rat.sub .. = _ ** a b : Rat ⊢ Rat.sub a b = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** delta Rat.sub ** a b : Rat ⊢ (let g := Nat.gcd a.den b.den; if hg : g = 1 then let_fun den_nz := (_ : a.den * b.den ≠ 0); let_fun reduced := (_ : Nat.gcd (Int.natAbs (a.num * ↑b.den - b.num * ↑a.den)) (a.den * b.den) = 1); mk' (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) else let den := a.den / g * b.den; let num := a.num * ↑(b.den / g) - b.num * ↑(a.den / g); let g1 := Nat.gcd (Int.natAbs num) g; let_fun den_nz := (_ : a.den / Nat.gcd a.den b.den * b.den ≠ 0); let_fun e := (_ : let den := a.den / Nat.gcd a.den b.den * b.den; let num := a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den); Nat.gcd (Int.natAbs num) (Nat.gcd a.den b.den) = Nat.gcd (Int.natAbs num) den); maybeNormalize num den g1 (_ : den / g1 ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div num ↑g1)) (den / g1))) = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** dsimp only ** a b : Rat ⊢ (if hg : Nat.gcd a.den b.den = 1 then mk' (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) else maybeNormalize (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den) (Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)) (_ : a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den) ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) ↑(Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) (a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** split ** case inl a b : Rat h✝ : Nat.gcd a.den b.den = 1 ⊢ mk' (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** exact (normalize_self _).symm ** case inr a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 ⊢ maybeNormalize (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den) (Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)) (_ : a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den) ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) ↑(Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) (a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den))) = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** have : a.den.gcd b.den ≠ 0 := Nat.gcd_ne_zero_left a.den_nz ** case inr a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ maybeNormalize (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den) (Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)) (_ : a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den) ≠ 0) (_ : Nat.Coprime (Int.natAbs (Int.div (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) ↑(Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den)))) (a.den / Nat.gcd a.den b.den * b.den / Nat.gcd (Int.natAbs (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den))) (Nat.gcd a.den b.den))) = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** rw [maybeNormalize_eq_normalize _ _ (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..) (Nat.dvd_trans (Nat.gcd_dvd_right ..) <| Nat.dvd_trans (Nat.gcd_dvd_right ..) (Nat.dvd_mul_left ..)), ← normalize_mul_right _ this] ** case inr a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ normalize ((a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) * ↑(Nat.gcd a.den b.den)) (a.den / Nat.gcd a.den b.den * b.den * Nat.gcd a.den b.den) = normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** congr 1 ** case inr.e_num a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ (a.num * ↑(b.den / Nat.gcd a.den b.den) - b.num * ↑(a.den / Nat.gcd a.den b.den)) * ↑(Nat.gcd a.den b.den) = a.num * ↑b.den - b.num * ↑a.den ** simp only [Int.sub_mul, Int.mul_assoc, Int.ofNat_mul_ofNat, Nat.div_mul_cancel (Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] ** case inr.e_den a b : Rat h✝ : ¬Nat.gcd a.den b.den = 1 this : Nat.gcd a.den b.den ≠ 0 ⊢ a.den / Nat.gcd a.den b.den * b.den * Nat.gcd a.den b.den = a.den * b.den ** rw [Nat.mul_right_comm, Nat.div_mul_cancel (Nat.gcd_dvd_left ..)] ** Qed
Rat.sub_def' ** a b : Rat ⊢ a - b = mkRat (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ** rw [sub_def, normalize_eq_mkRat] ** Qed
Rat.sub_eq_add_neg ** a b : Rat ⊢ a - b = a + -b ** simp [add_def, sub_def, Int.neg_mul, Int.sub_eq_add_neg] ** Qed
Rat.mul_def ** a b : Rat ⊢ a * b = normalize (a.num * b.num) (a.den * b.den) ** show Rat.mul .. = _ ** a b : Rat ⊢ Rat.mul a b = normalize (a.num * b.num) (a.den * b.den) ** delta Rat.mul ** a b : Rat ⊢ (let g1 := Nat.gcd (Int.natAbs a.num) b.den; let g2 := Nat.gcd (Int.natAbs b.num) a.den; mk' (Int.div a.num ↑g1 * Int.div b.num ↑g2) (a.den / g2 * (b.den / g1))) = normalize (a.num * b.num) (a.den * b.den) ** dsimp only ** a b : Rat ⊢ mk' (Int.div a.num ↑(Nat.gcd (Int.natAbs a.num) b.den) * Int.div b.num ↑(Nat.gcd (Int.natAbs b.num) a.den)) (a.den / Nat.gcd (Int.natAbs b.num) a.den * (b.den / Nat.gcd (Int.natAbs a.num) b.den)) = normalize (a.num * b.num) (a.den * b.den) ** have H1 : a.num.natAbs.gcd b.den ≠ 0 := Nat.gcd_ne_zero_right b.den_nz ** a b : Rat H1 : Nat.gcd (Int.natAbs a.num) b.den ≠ 0 ⊢ mk' (Int.div a.num ↑(Nat.gcd (Int.natAbs a.num) b.den) * Int.div b.num ↑(Nat.gcd (Int.natAbs b.num) a.den)) (a.den / Nat.gcd (Int.natAbs b.num) a.den * (b.den / Nat.gcd (Int.natAbs a.num) b.den)) = normalize (a.num * b.num) (a.den * b.den) ** have H2 : b.num.natAbs.gcd a.den ≠ 0 := Nat.gcd_ne_zero_right a.den_nz ** a b : Rat H1 : Nat.gcd (Int.natAbs a.num) b.den ≠ 0 H2 : Nat.gcd (Int.natAbs b.num) a.den ≠ 0 ⊢ mk' (Int.div a.num ↑(Nat.gcd (Int.natAbs a.num) b.den) * Int.div b.num ↑(Nat.gcd (Int.natAbs b.num) a.den)) (a.den / Nat.gcd (Int.natAbs b.num) a.den * (b.den / Nat.gcd (Int.natAbs a.num) b.den)) = normalize (a.num * b.num) (a.den * b.den) ** rw [mk_eq_normalize, ← normalize_mul_right _ (Nat.mul_ne_zero H1 H2)] ** a b : Rat H1 : Nat.gcd (Int.natAbs a.num) b.den ≠ 0 H2 : Nat.gcd (Int.natAbs b.num) a.den ≠ 0 ⊢ normalize (Int.div a.num ↑(Nat.gcd (Int.natAbs a.num) b.den) * Int.div b.num ↑(Nat.gcd (Int.natAbs b.num) a.den) * ↑(Nat.gcd (Int.natAbs a.num) b.den * Nat.gcd (Int.natAbs b.num) a.den)) (a.den / Nat.gcd (Int.natAbs b.num) a.den * (b.den / Nat.gcd (Int.natAbs a.num) b.den) * (Nat.gcd (Int.natAbs a.num) b.den * Nat.gcd (Int.natAbs b.num) a.den)) = normalize (a.num * b.num) (a.den * b.den) ** congr 1 ** case e_num a b : Rat H1 : Nat.gcd (Int.natAbs a.num) b.den ≠ 0 H2 : Nat.gcd (Int.natAbs b.num) a.den ≠ 0 ⊢ Int.div a.num ↑(Nat.gcd (Int.natAbs a.num) b.den) * Int.div b.num ↑(Nat.gcd (Int.natAbs b.num) a.den) * ↑(Nat.gcd (Int.natAbs a.num) b.den * Nat.gcd (Int.natAbs b.num) a.den) = a.num * b.num ** rw [Int.ofNat_mul, ← Int.mul_assoc, Int.mul_right_comm (Int.div ..), Int.div_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..), Int.mul_assoc, Int.div_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..)] ** case e_den a b : Rat H1 : Nat.gcd (Int.natAbs a.num) b.den ≠ 0 H2 : Nat.gcd (Int.natAbs b.num) a.den ≠ 0 ⊢ a.den / Nat.gcd (Int.natAbs b.num) a.den * (b.den / Nat.gcd (Int.natAbs a.num) b.den) * (Nat.gcd (Int.natAbs a.num) b.den * Nat.gcd (Int.natAbs b.num) a.den) = a.den * b.den ** rw [← Nat.mul_assoc, Nat.mul_right_comm, Nat.mul_right_comm (_/_), Nat.div_mul_cancel (Nat.gcd_dvd_right ..), Nat.mul_assoc, Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] ** Qed
Rat.mul_comm ** a b : Rat ⊢ a * b = b * a ** simp [mul_def, normalize_eq_mkRat, Int.mul_comm, Nat.mul_comm] ** Qed
Rat.zero_mul ** a : Rat ⊢ 0 * a = 0 ** simp [mul_def] ** Qed
Rat.mul_zero ** a : Rat ⊢ a * 0 = 0 ** simp [mul_def] ** Qed
Rat.one_mul ** a : Rat ⊢ 1 * a = a ** simp [mul_def, normalize_self] ** Qed
Rat.mul_one ** a : Rat ⊢ a * 1 = a ** simp [mul_def, normalize_self] ** Qed
Rat.normalize_mul_normalize ** n₁ n₂ : Int d₁ d₂ : Nat z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 ⊢ normalize n₁ d₁ * normalize n₂ d₂ = normalize (n₁ * n₂) (d₁ * d₂) ** cases e₁ : normalize n₁ d₁ z₁ ** case mk' n₁ n₂ : Int d₁ d₂ : Nat z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ e₁ : normalize n₁ d₁ = mk' num✝ den✝ ⊢ mk' num✝ den✝ * normalize n₂ d₂ = normalize (n₁ * n₂) (d₁ * d₂) ** rcases normalize_num_den e₁ with ⟨g₁, zg₁, rfl, rfl⟩ ** case mk'.intro.intro.intro n₂ : Int d₂ : Nat z₂ : d₂ ≠ 0 num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝ * g₁ ≠ 0 e₁ : normalize (num✝ * ↑g₁) (den✝ * g₁) = mk' num✝ den✝ ⊢ mk' num✝ den✝ * normalize n₂ d₂ = normalize (num✝ * ↑g₁ * n₂) (den✝ * g₁ * d₂) ** cases e₂ : normalize n₂ d₂ z₂ ** case mk'.intro.intro.intro.mk' n₂ : Int d₂ : Nat z₂ : d₂ ≠ 0 num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ e₂ : normalize n₂ d₂ = mk' num✝ den✝ ⊢ mk' num✝¹ den✝¹ * mk' num✝ den✝ = normalize (num✝¹ * ↑g₁ * n₂) (den✝¹ * g₁ * d₂) ** rcases normalize_num_den e₂ with ⟨g₂, zg₂, rfl, rfl⟩ ** case mk'.intro.intro.intro.mk'.intro.intro.intro num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ mk' num✝¹ den✝¹ * mk' num✝ den✝ = normalize (num✝¹ * ↑g₁ * (num✝ * ↑g₂)) (den✝¹ * g₁ * (den✝ * g₂)) ** simp only [mul_def] ** case mk'.intro.intro.intro.mk'.intro.intro.intro num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ normalize (num✝¹ * num✝) (den✝¹ * den✝) = normalize (num✝¹ * ↑g₁ * (num✝ * ↑g₂)) (den✝¹ * g₁ * (den✝ * g₂)) ** rw [← normalize_mul_right _ (Nat.mul_ne_zero zg₁ zg₂)] ** case mk'.intro.intro.intro.mk'.intro.intro.intro num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ normalize (num✝¹ * num✝ * ↑(g₁ * g₂)) (den✝¹ * den✝ * (g₁ * g₂)) = normalize (num✝¹ * ↑g₁ * (num✝ * ↑g₂)) (den✝¹ * g₁ * (den✝ * g₂)) ** congr 1 ** case mk'.intro.intro.intro.mk'.intro.intro.intro.e_num num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ num✝¹ * num✝ * ↑(g₁ * g₂) = num✝¹ * ↑g₁ * (num✝ * ↑g₂) ** simp [Int.ofNat_mul, Int.mul_assoc, Int.mul_left_comm] ** case mk'.intro.intro.intro.mk'.intro.intro.intro.e_den num✝¹ : Int den✝¹ : Nat den_nz✝¹ : den✝¹ ≠ 0 reduced✝¹ : Nat.Coprime (Int.natAbs num✝¹) den✝¹ g₁ : Nat zg₁ : g₁ ≠ 0 z₁ : den✝¹ * g₁ ≠ 0 e₁ : normalize (num✝¹ * ↑g₁) (den✝¹ * g₁) = mk' num✝¹ den✝¹ num✝ : Int den✝ : Nat den_nz✝ : den✝ ≠ 0 reduced✝ : Nat.Coprime (Int.natAbs num✝) den✝ g₂ : Nat zg₂ : g₂ ≠ 0 z₂ : den✝ * g₂ ≠ 0 e₂ : normalize (num✝ * ↑g₂) (den✝ * g₂) = mk' num✝ den✝ ⊢ den✝¹ * den✝ * (g₁ * g₂) = den✝¹ * g₁ * (den✝ * g₂) ** simp [Nat.mul_left_comm, Nat.mul_comm] ** Qed
Rat.divInt_mul_divInt ** n₁ n₂ d₁ d₂ : Int z₁ : d₁ ≠ 0 z₂ : d₂ ≠ 0 ⊢ n₁ /. d₁ * (n₂ /. d₂) = n₁ * n₂ /. (d₁ * d₂) ** rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;> rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;> simp_all [-Int.natCast_mul, divInt_neg', Int.mul_neg, Int.ofNat_mul_ofNat, Int.neg_mul, mkRat_mul_mkRat] ** Qed
Rat.inv_def ** a : Rat ⊢ Rat.inv a = ↑a.den /. a.num ** unfold Rat.inv ** a : Rat ⊢ (if h : a.num < 0 then mk' (-↑a.den) (Int.natAbs a.num) else if h : a.num > 0 then mk' (↑a.den) (Int.natAbs a.num) else a) = ↑a.den /. a.num ** split ** case inr a : Rat h✝ : ¬a.num < 0 ⊢ (if h : a.num > 0 then mk' (↑a.den) (Int.natAbs a.num) else a) = ↑a.den /. a.num ** split ** case inl a : Rat h✝ : a.num < 0 ⊢ mk' (-↑a.den) (Int.natAbs a.num) = ↑a.den /. a.num ** next h => rw [mk_eq_divInt, ← Int.natAbs_neg, Int.natAbs_of_nonneg (Int.le_of_lt <| Int.neg_pos_of_neg h), neg_divInt_neg] ** a : Rat h : a.num < 0 ⊢ mk' (-↑a.den) (Int.natAbs a.num) = ↑a.den /. a.num ** rw [mk_eq_divInt, ← Int.natAbs_neg, Int.natAbs_of_nonneg (Int.le_of_lt <| Int.neg_pos_of_neg h), neg_divInt_neg] ** case inr.inl a : Rat h✝¹ : ¬a.num < 0 h✝ : a.num > 0 ⊢ mk' (↑a.den) (Int.natAbs a.num) = ↑a.den /. a.num ** next h => rw [mk_eq_divInt, Int.natAbs_of_nonneg (Int.le_of_lt h)] ** a : Rat h✝ : ¬a.num < 0 h : a.num > 0 ⊢ mk' (↑a.den) (Int.natAbs a.num) = ↑a.den /. a.num ** rw [mk_eq_divInt, Int.natAbs_of_nonneg (Int.le_of_lt h)] ** case inr.inr a : Rat h✝¹ : ¬a.num < 0 h✝ : ¬a.num > 0 ⊢ a = ↑a.den /. a.num ** next h₁ h₂ => apply (divInt_self _).symm.trans simp [Int.le_antisymm (Int.not_lt.1 h₂) (Int.not_lt.1 h₁)] ** a : Rat h₁ : ¬a.num < 0 h₂ : ¬a.num > 0 ⊢ a = ↑a.den /. a.num ** apply (divInt_self _).symm.trans ** a : Rat h₁ : ¬a.num < 0 h₂ : ¬a.num > 0 ⊢ a.num /. ↑a.den = ↑a.den /. a.num ** simp [Int.le_antisymm (Int.not_lt.1 h₂) (Int.not_lt.1 h₁)] ** Qed
Rat.inv_zero ** ⊢ Rat.inv 0 = 0 ** unfold Rat.inv ** ⊢ (if h : 0.num < 0 then mk' (-↑0.den) (Int.natAbs 0.num) else if h : 0.num > 0 then mk' (↑0.den) (Int.natAbs 0.num) else 0) = 0 ** simp ** Qed
Rat.ofScientific_true_def ** m e : Nat ⊢ Rat.ofScientific m true e = mkRat (↑m) (10 ^ e) ** unfold Rat.ofScientific ** m e : Nat ⊢ (if true = true then normalize (↑m) (10 ^ e) else ↑↑(m * 10 ^ e)) = mkRat (↑m) (10 ^ e) ** rw [normalize_eq_mkRat] ** m e : Nat ⊢ (if true = true then mkRat (↑m) (10 ^ e) else ↑↑(m * 10 ^ e)) = mkRat (↑m) (10 ^ e) ** rfl ** Qed
Rat.ofScientific_false_def ** m e : Nat ⊢ Rat.ofScientific m false e = ↑↑(m * 10 ^ e) ** unfold Rat.ofScientific ** m e : Nat ⊢ (if false = true then normalize (↑m) (10 ^ e) else ↑↑(m * 10 ^ e)) = ↑↑(m * 10 ^ e) ** rfl ** Qed
Rat.ofScientific_def ** m : Nat s : Bool e : Nat ⊢ Rat.ofScientific m s e = if s = true then mkRat (↑m) (10 ^ e) else ↑↑(m * 10 ^ e) ** cases s ** case false m e : Nat ⊢ Rat.ofScientific m false e = if false = true then mkRat (↑m) (10 ^ e) else ↑↑(m * 10 ^ e) case true m e : Nat ⊢ Rat.ofScientific m true e = if true = true then mkRat (↑m) (10 ^ e) else ↑↑(m * 10 ^ e) ** exact ofScientific_false_def ** case true m e : Nat ⊢ Rat.ofScientific m true e = if true = true then mkRat (↑m) (10 ^ e) else ↑↑(m * 10 ^ e) ** exact ofScientific_true_def ** Qed
Rat.intCast_add ** a b : Int ⊢ ↑(a + b) = ↑a + ↑b ** rw [add_def] ** a b : Int ⊢ ↑(a + b) = normalize ((↑a).num * ↑(↑b).den + (↑b).num * ↑(↑a).den) ((↑a).den * (↑b).den) ** ext <;> simp [normalize_eq] ** Qed
Rat.intCast_neg ** a : Int ⊢ ↑(-a) = -↑a ** ext <;> simp [normalize_eq] ** Qed
Rat.intCast_sub ** a b : Int ⊢ ↑(a - b) = ↑a - ↑b ** rw [sub_def] ** a b : Int ⊢ ↑(a - b) = normalize ((↑a).num * ↑(↑b).den - (↑b).num * ↑(↑a).den) ((↑a).den * (↑b).den) ** ext <;> simp [normalize_eq] ** Qed
Rat.intCast_mul ** a b : Int ⊢ ↑(a * b) = ↑a * ↑b ** rw [mul_def] ** a b : Int ⊢ ↑(a * b) = normalize ((↑a).num * (↑b).num) ((↑a).den * (↑b).den) ** ext <;> simp [normalize_eq] ** Qed
Nat.gcd_rec ** m n : Nat ⊢ gcd 0 n = gcd (n % 0) 0 ** have := (mod_zero n).symm ** m n : Nat this : n = n % 0 ⊢ gcd 0 n = gcd (n % 0) 0 ** rwa [gcd_zero_right] ** m n n✝ : Nat ⊢ gcd (n✝ + 1) n = gcd (n % (n✝ + 1)) (n✝ + 1) ** simp [gcd_succ] ** Qed
Nat.gcd_dvd ** m n : Nat ⊢ gcd m n ∣ m ∧ gcd m n ∣ n ** induction m, n using gcd.induction with | H0 n => rw [gcd_zero_left]; exact ⟨Nat.dvd_zero n, Nat.dvd_refl n⟩ | H1 m n _ IH => rw [← gcd_rec] at IH; exact ⟨IH.2, (dvd_mod_iff IH.2).1 IH.1⟩ ** case H0 n : Nat ⊢ gcd 0 n ∣ 0 ∧ gcd 0 n ∣ n ** rw [gcd_zero_left] ** case H0 n : Nat ⊢ n ∣ 0 ∧ n ∣ n ** exact ⟨Nat.dvd_zero n, Nat.dvd_refl n⟩ ** case H1 m n : Nat a✝ : 0 < m IH : gcd (n % m) m ∣ n % m ∧ gcd (n % m) m ∣ m ⊢ gcd m n ∣ m ∧ gcd m n ∣ n ** rw [← gcd_rec] at IH ** case H1 m n : Nat a✝ : 0 < m IH : gcd m n ∣ n % m ∧ gcd m n ∣ m ⊢ gcd m n ∣ m ∧ gcd m n ∣ n ** exact ⟨IH.2, (dvd_mod_iff IH.2).1 IH.1⟩ ** Qed
Nat.dvd_gcd ** k m n : Nat ⊢ k ∣ m → k ∣ n → k ∣ gcd m n ** induction m, n using gcd.induction with intro km kn | H0 n => rw [gcd_zero_left]; exact kn | H1 n m _ IH => rw [gcd_rec]; exact IH ((dvd_mod_iff km).2 kn) km ** case H0 k n : Nat km : k ∣ 0 kn : k ∣ n ⊢ k ∣ gcd 0 n ** rw [gcd_zero_left] ** case H0 k n : Nat km : k ∣ 0 kn : k ∣ n ⊢ k ∣ n ** exact kn ** case H1 k n m : Nat a✝ : 0 < n IH : k ∣ m % n → k ∣ n → k ∣ gcd (m % n) n km : k ∣ n kn : k ∣ m ⊢ k ∣ gcd n m ** rw [gcd_rec] ** case H1 k n m : Nat a✝ : 0 < n IH : k ∣ m % n → k ∣ n → k ∣ gcd (m % n) n km : k ∣ n kn : k ∣ m ⊢ k ∣ gcd (m % n) n ** exact IH ((dvd_mod_iff km).2 kn) km ** Qed