The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V33. Data structures and computation

Mathlib.Data.Ordmap.Ordset

97 declarations. Mathlib docs · Source

theorem Ordnode.Bounded.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : Ordnode α → WithBot α → WithTop α → Sort u_2) (x : Ordnode α) (x_1 : WithBot α)
  (x_2 : WithTop α) (h_1 : (a b : α) → motive Ordnode.nil (some a) (some b))
  (h_2 : (x : WithBot α) → (x_3 : WithTop α) → motive Ordnode.nil x x_3)
  (h_3 :
    (size : ℕ) →
      (l : Ordnode α) →
        (x : α) → (r : Ordnode α) → (o₁ : WithBot α) → (o₂ : WithTop α) → motive (Ordnode.node size l x r) o₁ o₂)
  (a b : α),
  x = Ordnode.nil →
    x_1 = some a →
      x_2 = some b →
        (match x, x_1, x_2 with
          | Ordnode.nil, some a, some b => h_1 a b
          | Ordnode.nil, x, x_3 => h_2 x x_3
          | Ordnode.node size l x r, o₁, o₂ => h_3 size l x r o₁ o₂) ≍
          h_1 a b

theorem Ordnode.adjustWith.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : Ordnode α → Sort u_2) (x : Ordnode α) (h_1 : Unit → motive Ordnode.nil)
  (h_2 :
    (_t : Ordnode α) →
      (sz : ℕ) →
        (l : Ordnode α) → (y : α) → (r : Ordnode α) → _t = Ordnode.node sz l y r → motive (Ordnode.node sz l y r))
  (sz : ℕ) (l : Ordnode α) (y : α) (r : Ordnode α),
  x = Ordnode.node sz l y r →
    (match x with
      | Ordnode.nil => h_1 ()
      | _t@h:(Ordnode.node sz l y r) => h_2 _t sz l y r h) ≍
      h_2 (Ordnode.node sz l y r) sz l y r ⋯

theorem Ordnode.Bounded.match_1.congr_eq_3 E1 #

∀ {α : Type u_1} (motive : Ordnode α → WithBot α → WithTop α → Sort u_2) (x : Ordnode α) (x_1 : WithBot α)
  (x_2 : WithTop α) (h_1 : (a b : α) → motive Ordnode.nil (some a) (some b))
  (h_2 : (x : WithBot α) → (x_3 : WithTop α) → motive Ordnode.nil x x_3)
  (h_3 :
    (size : ℕ) →
      (l : Ordnode α) →
        (x : α) → (r : Ordnode α) → (o₁ : WithBot α) → (o₂ : WithTop α) → motive (Ordnode.node size l x r) o₁ o₂)
  (size : ℕ) (l : Ordnode α) (x_3 : α) (r : Ordnode α) (o₁ : WithBot α) (o₂ : WithTop α),
  x = Ordnode.node size l x_3 r →
    x_1 = o₁ →
      x_2 = o₂ →
        (match x, x_1, x_2 with
          | Ordnode.nil, some a, some b => h_1 a b
          | Ordnode.nil, x, x_4 => h_2 x x_4
          | Ordnode.node size l x r, o₁, o₂ => h_3 size l x r o₁ o₂) ≍
          h_3 size l x_3 r o₁ o₂

theorem Ordnode.adjustWith.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : Ordnode α → Sort u_2) (x : Ordnode α) (h_1 : Unit → motive Ordnode.nil)
  (h_2 :
    (_t : Ordnode α) →
      (sz : ℕ) →
        (l : Ordnode α) → (y : α) → (r : Ordnode α) → _t = Ordnode.node sz l y r → motive (Ordnode.node sz l y r)),
  x = Ordnode.nil →
    (match x with
      | Ordnode.nil => h_1 ()
      | _t@h:(Ordnode.node sz l y r) => h_2 _t sz l y r h) ≍
      h_1 ()

theorem Ordnode.Bounded.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : Ordnode α → WithBot α → WithTop α → Sort u_2) (x : Ordnode α) (x_1 : WithBot α)
  (x_2 : WithTop α) (h_1 : (a b : α) → motive Ordnode.nil (some a) (some b))
  (h_2 : (x : WithBot α) → (x_3 : WithTop α) → motive Ordnode.nil x x_3)
  (h_3 :
    (size : ℕ) →
      (l : Ordnode α) →
        (x : α) → (r : Ordnode α) → (o₁ : WithBot α) → (o₂ : WithTop α) → motive (Ordnode.node size l x r) o₁ o₂)
  (x_3 : WithBot α) (x_4 : WithTop α),
  x = Ordnode.nil →
    x_1 = x_3 →
      x_2 = x_4 →
        (∀ (a b : α), x_3 = some a → x_4 = some b → False) →
          (match x, x_1, x_2 with
            | Ordnode.nil, some a, some b => h_1 a b
            | Ordnode.nil, x, x_6 => h_2 x x_6
            | Ordnode.node size l x r, o₁, o₂ => h_3 size l x r o₁ o₂) ≍
            h_2 x_3 x_4

theorem Ordnode.mem.congr_simp E1 #

∀ {α : Type u_1} [inst : LE α] {inst_1 : DecidableLE α} [inst_2 : DecidableLE α] (x x_1 : α),
  x = x_1 → ∀ (a a_1 : Ordnode α), a = a_1 → Ordnode.mem x a = Ordnode.mem x_1 a_1

structure Ordnode.Valid' E1 #

{α : Type u_1} → [Preorder α] → WithBot α → Ordnode α → WithTop α → Prop

The validity predicate for an Ordnode subtree. This asserts that the size fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. This version of Valid also puts all elements in the tree in the interval (lo, hi).

ctor Ordnode.Valid'.mk E0 #

∀ {α : Type u_1} [inst : Preorder α] {lo : WithBot α} {t : Ordnode α} {hi : WithTop α},
  t.Bounded lo hi → t.Sized → t.Balanced → Ordnode.Valid' lo t hi

theorem Ordnode.Valid'.ord E1 #

∀ {α : Type u_1} [inst : Preorder α] {lo : WithBot α} {t : Ordnode α} {hi : WithTop α},
  Ordnode.Valid' lo t hi → t.Bounded lo hi

theorem Ordnode.Valid'.sz E1 #

∀ {α : Type u_1} [inst : Preorder α] {lo : WithBot α} {t : Ordnode α} {hi : WithTop α}, Ordnode.Valid' lo t hi → t.Sized

theorem Ordnode.Valid'.bal E1 #

∀ {α : Type u_1} [inst : Preorder α] {lo : WithBot α} {t : Ordnode α} {hi : WithTop α},
  Ordnode.Valid' lo t hi → t.Balanced

def Ordnode.Valid E1 #

{α : Type u_1} → [Preorder α] → Ordnode α → Prop

The validity predicate for an Ordnode subtree. This asserts that the size fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering.

theorem Ordnode.Valid'.mono_left E1 #

∀ {α : Type u_1} [inst : Preorder α] {x y : α},
  x ≤ y → ∀ {t : Ordnode α} {o : WithTop α}, Ordnode.Valid' (↑y) t o → Ordnode.Valid' (↑x) t o

theorem Ordnode.Valid'.mono_right E1 #

∀ {α : Type u_1} [inst : Preorder α] {x y : α},
  x ≤ y → ∀ {t : Ordnode α} {o : WithBot α}, Ordnode.Valid' o t ↑x → Ordnode.Valid' o t ↑y

theorem Ordnode.Valid'.trans_left E1 #

∀ {α : Type u_1} [inst : Preorder α] {t₁ t₂ : Ordnode α} {x : α} {o₁ : WithBot α} {o₂ : WithTop α},
  t₁.Bounded o₁ ↑x → Ordnode.Valid' (↑x) t₂ o₂ → Ordnode.Valid' o₁ t₂ o₂

theorem Ordnode.Valid'.trans_right E1 #

∀ {α : Type u_1} [inst : Preorder α] {t₁ t₂ : Ordnode α} {x : α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ t₁ ↑x → t₂.Bounded (↑x) o₂ → Ordnode.Valid' o₁ t₁ o₂

theorem Ordnode.Valid'.of_lt E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α} {x : α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ t o₂ → Ordnode.nil.Bounded o₁ ↑x → Ordnode.All (fun x_1 ↦ x_1 < x) t → Ordnode.Valid' o₁ t ↑x

theorem Ordnode.Valid'.of_gt E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α} {x : α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ t o₂ → Ordnode.nil.Bounded (↑x) o₂ → Ordnode.All (fun x_1 ↦ x_1 > x) t → Ordnode.Valid' (↑x) t o₂

theorem Ordnode.Valid'.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α}, Ordnode.Valid' o₁ t o₂ → t.Valid

theorem Ordnode.valid'_nil E1 #

∀ {α : Type u_1} [inst : Preorder α] {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.nil.Bounded o₁ o₂ → Ordnode.Valid' o₁ Ordnode.nil o₂

theorem Ordnode.valid_nil E1 #

∀ {α : Type u_1} [inst : Preorder α], Ordnode.nil.Valid

theorem Ordnode.Valid'.node E1 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      Ordnode.BalancedSz l.size r.size → s = l.size + r.size + 1 → Ordnode.Valid' o₁ (Ordnode.node s l x r) o₂

theorem Ordnode.Valid'.dual E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ t o₂ → Ordnode.Valid' o₂ t.dual o₁

theorem Ordnode.Valid'.dual_iff E0 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ t o₂ ↔ Ordnode.Valid' o₂ t.dual o₁

theorem Ordnode.Valid.dual E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α}, t.Valid → t.dual.Valid

theorem Ordnode.Valid.dual_iff E0 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α}, t.Valid ↔ t.dual.Valid

theorem Ordnode.Valid'.left E1 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ (Ordnode.node s l x r) o₂ → Ordnode.Valid' o₁ l ↑x

theorem Ordnode.Valid'.right E1 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ (Ordnode.node s l x r) o₂ → Ordnode.Valid' (↑x) r o₂

theorem Ordnode.Valid.left E1 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α},
  (Ordnode.node s l x r).Valid → l.Valid

theorem Ordnode.Valid.right E1 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α},
  (Ordnode.node s l x r).Valid → r.Valid

theorem Ordnode.Valid.size_eq E0 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α},
  (Ordnode.node s l x r).Valid → (Ordnode.node s l x r).size = l.size + r.size + 1

theorem Ordnode.Valid'.node' E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ → Ordnode.BalancedSz l.size r.size → Ordnode.Valid' o₁ (l.node' x r) o₂

theorem Ordnode.valid'_singleton E1 #

∀ {α : Type u_1} [inst : Preorder α] {x : α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.nil.Bounded o₁ ↑x → Ordnode.nil.Bounded (↑x) o₂ → Ordnode.Valid' o₁ {x} o₂

theorem Ordnode.valid_singleton E1 #

∀ {α : Type u_1} [inst : Preorder α] {x : α}, {x}.Valid

theorem Ordnode.Valid'.node3L E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {m : Ordnode α} {y : α} {r : Ordnode α} {o₁ : WithBot α}
  {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) m ↑y →
      Ordnode.Valid' (↑y) r o₂ →
        Ordnode.BalancedSz l.size m.size →
          Ordnode.BalancedSz (l.size + m.size + 1) r.size → Ordnode.Valid' o₁ (l.node3L x m y r) o₂

theorem Ordnode.Valid'.node3R E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {m : Ordnode α} {y : α} {r : Ordnode α} {o₁ : WithBot α}
  {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) m ↑y →
      Ordnode.Valid' (↑y) r o₂ →
        Ordnode.BalancedSz l.size (m.size + r.size + 1) →
          Ordnode.BalancedSz m.size r.size → Ordnode.Valid' o₁ (l.node3R x m y r) o₂

theorem Ordnode.Valid'.node4L_lemma₁ E1 #

∀ {a b c d : ℕ}, 3 * (b + c + 1 + d) ≤ 16 * a + 9 → b + c + 1 ≤ 3 * d → b ≤ 3 * c → b < 3 * a + 1

theorem Ordnode.Valid'.node4L_lemma₂ E1 #

∀ {b c d : ℕ}, b + c + 1 ≤ 3 * d → c ≤ 3 * d

theorem Ordnode.Valid'.node4L_lemma₃ E1 #

∀ {b c d : ℕ}, 2 * d ≤ b + c + 1 → b ≤ 3 * c → d ≤ 3 * c

theorem Ordnode.Valid'.node4L_lemma₄ E1 #

∀ {a b c d : ℕ}, 3 * a ≤ b + c + 1 + d → b + c + 1 ≤ 3 * d → b ≤ 3 * c → a + b + 1 ≤ 3 * (c + d + 1)

theorem Ordnode.Valid'.node4L_lemma₅ E1 #

∀ {a b c d : ℕ}, 3 * (b + c + 1 + d) ≤ 16 * a + 9 → 2 * d ≤ b + c + 1 → c ≤ 3 * b → c + d + 1 ≤ 3 * (a + b + 1)

theorem Ordnode.Valid'.node4L E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {m : Ordnode α} {y : α} {r : Ordnode α} {o₁ : WithBot α}
  {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) m ↑y →
      Ordnode.Valid' (↑y) r o₂ →
        0 < m.size →
          l.size = 0 ∧ m.size = 1 ∧ r.size ≤ 1 ∨
              0 < l.size ∧
                Ordnode.ratio * r.size ≤ m.size ∧
                  Ordnode.delta * l.size ≤ m.size + r.size ∧
                    3 * (m.size + r.size) ≤ 16 * l.size + 9 ∧ m.size ≤ Ordnode.delta * r.size →
            Ordnode.Valid' o₁ (l.node4L x m y r) o₂

theorem Ordnode.Valid'.rotateL_lemma₁ E1 #

∀ {a b c : ℕ}, 3 * a ≤ b + c → c ≤ 3 * b → a ≤ 3 * b

theorem Ordnode.Valid'.rotateL_lemma₂ E1 #

∀ {a b c : ℕ}, 2 * (b + c) ≤ 9 * a + 3 → b < 2 * c → b < 3 * a + 1

theorem Ordnode.Valid'.rotateL_lemma₃ E1 #

∀ {a b c : ℕ}, 3 * a ≤ b + c → b < 2 * c → a + b < 3 * c

theorem Ordnode.Valid'.rotateL_lemma₄ E1 #

∀ {a b : ℕ}, 2 * b ≤ 9 * a + 3 → 3 * b ≤ 16 * a + 9

theorem Ordnode.Valid'.rotateL E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      ¬l.size + r.size ≤ 1 →
        Ordnode.delta * l.size < r.size →
          2 * r.size ≤ 9 * l.size + 5 ∨ r.size ≤ 3 → Ordnode.Valid' o₁ (l.rotateL x r) o₂

theorem Ordnode.Valid'.rotateR E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      ¬l.size + r.size ≤ 1 →
        Ordnode.delta * r.size < l.size →
          2 * l.size ≤ 9 * r.size + 5 ∨ l.size ≤ 3 → Ordnode.Valid' o₁ (l.rotateR x r) o₂

theorem Ordnode.Valid'.balance'_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      2 * r.size ≤ 9 * l.size + 5 ∨ r.size ≤ 3 →
        2 * l.size ≤ 9 * r.size + 5 ∨ l.size ≤ 3 → Ordnode.Valid' o₁ (l.balance' x r) o₂

theorem Ordnode.Valid'.balance'_lemma E1 #

∀ {α : Type u_2} {l : Ordnode α} {l' : ℕ} {r : Ordnode α} {r' : ℕ},
  Ordnode.BalancedSz l' r' →
    l.size.dist l' ≤ 1 ∧ r.size = r' ∨ r.size.dist r' ≤ 1 ∧ l.size = l' → 2 * r.size ≤ 9 * l.size + 5 ∨ r.size ≤ 3

theorem Ordnode.Valid'.balance' E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      (∃ l' r', Ordnode.BalancedSz l' r' ∧ (l.size.dist l' ≤ 1 ∧ r.size = r' ∨ r.size.dist r' ≤ 1 ∧ l.size = l')) →
        Ordnode.Valid' o₁ (l.balance' x r) o₂

theorem Ordnode.Valid'.balance E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      (∃ l' r', Ordnode.BalancedSz l' r' ∧ (l.size.dist l' ≤ 1 ∧ r.size = r' ∨ r.size.dist r' ≤ 1 ∧ l.size = l')) →
        Ordnode.Valid' o₁ (l.balance x r) o₂

theorem Ordnode.Valid'.balanceL_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      (l.size = 0 → r.size ≤ 1) →
        (1 ≤ l.size → 1 ≤ r.size → r.size ≤ Ordnode.delta * l.size) →
          2 * l.size ≤ 9 * r.size + 5 ∨ l.size ≤ 3 → Ordnode.Valid' o₁ (l.balanceL x r) o₂

theorem Ordnode.Valid'.balanceL E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      ((∃ l', Ordnode.Raised l' l.size ∧ Ordnode.BalancedSz l' r.size) ∨
          ∃ r', Ordnode.Raised r.size r' ∧ Ordnode.BalancedSz l.size r') →
        Ordnode.Valid' o₁ (l.balanceL x r) o₂

theorem Ordnode.Valid'.balanceR_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      (r.size = 0 → l.size ≤ 1) →
        (1 ≤ r.size → 1 ≤ l.size → l.size ≤ Ordnode.delta * r.size) →
          2 * r.size ≤ 9 * l.size + 5 ∨ r.size ≤ 3 → Ordnode.Valid' o₁ (l.balanceR x r) o₂

theorem Ordnode.Valid'.balanceR E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      ((∃ l', Ordnode.Raised l.size l' ∧ Ordnode.BalancedSz l' r.size) ∨
          ∃ r', Ordnode.Raised r' r.size ∧ Ordnode.BalancedSz l.size r') →
        Ordnode.Valid' o₁ (l.balanceR x r) o₂

theorem Ordnode.Valid'.eraseMax_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ (Ordnode.node s l x r) o₂ →
    Ordnode.Valid' o₁ (l.node' x r).eraseMax ↑(Ordnode.findMax' x r) ∧
      (l.node' x r).size = (l.node' x r).eraseMax.size + 1

theorem Ordnode.Valid'.eraseMin_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {s : ℕ} {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ (Ordnode.node s l x r) o₂ →
    Ordnode.Valid' (↑(l.findMin' x)) (l.node' x r).eraseMin o₂ ∧ (l.node' x r).size = (l.node' x r).eraseMin.size + 1

theorem Ordnode.eraseMin.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α}, t.Valid → t.eraseMin.Valid

theorem Ordnode.eraseMax.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] {t : Ordnode α}, t.Valid → t.eraseMax.Valid

theorem Ordnode.Valid'.glue_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {l r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l o₂ →
    Ordnode.Valid' o₁ r o₂ →
      Ordnode.All (fun x ↦ Ordnode.All (fun y ↦ x < y) r) l →
        Ordnode.BalancedSz l.size r.size → Ordnode.Valid' o₁ (l.glue r) o₂ ∧ (l.glue r).size = l.size + r.size

theorem Ordnode.Valid'.glue E1 #

∀ {α : Type u_1} [inst : Preorder α] {l : Ordnode α} {x : α} {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l ↑x →
    Ordnode.Valid' (↑x) r o₂ →
      Ordnode.BalancedSz l.size r.size → Ordnode.Valid' o₁ (l.glue r) o₂ ∧ (l.glue r).size = l.size + r.size

theorem Ordnode.Valid'.merge_lemma E1 #

∀ {a b c : ℕ}, 3 * a < b + c + 1 → b ≤ 3 * c → 2 * (a + b) ≤ 9 * c + 5

theorem Ordnode.Valid'.merge_aux₁ E1 #

∀ {α : Type u_1} [inst : Preorder α] {o₁ : WithBot α} {o₂ : WithTop α} {ls : ℕ} {ll : Ordnode α} {lx : α}
  {lr : Ordnode α} {rs : ℕ} {rl : Ordnode α} {rx : α} {rr t : Ordnode α},
  Ordnode.Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
    Ordnode.Valid' o₁ (Ordnode.node rs rl rx rr) o₂ →
      Ordnode.delta * ls < rs →
        Ordnode.Valid' o₁ t ↑rx →
          t.size = ls + rl.size → Ordnode.Valid' o₁ (t.balanceL rx rr) o₂ ∧ (t.balanceL rx rr).size = ls + rs

theorem Ordnode.Valid'.merge_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {l r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
  Ordnode.Valid' o₁ l o₂ →
    Ordnode.Valid' o₁ r o₂ →
      Ordnode.All (fun x ↦ Ordnode.All (fun y ↦ x < y) r) l →
        Ordnode.Valid' o₁ (l.merge r) o₂ ∧ (l.merge r).size = l.size + r.size

theorem Ordnode.Valid.merge E1 #

∀ {α : Type u_1} [inst : Preorder α] {l r : Ordnode α},
  l.Valid → r.Valid → Ordnode.All (fun x ↦ Ordnode.All (fun y ↦ x < y) r) l → (l.merge r).Valid

theorem Ordnode.insertWith.valid_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] [Std.Total fun x1 x2 ↦ x1 ≤ x2] [inst_2 : DecidableLE α] (f : α → α) (x : α),
  (∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) →
    ∀ {t : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
      Ordnode.Valid' o₁ t o₂ →
        Ordnode.nil.Bounded o₁ ↑x →
          Ordnode.nil.Bounded (↑x) o₂ →
            Ordnode.Valid' o₁ (Ordnode.insertWith f x t) o₂ ∧ Ordnode.Raised t.size (Ordnode.insertWith f x t).size

theorem Ordnode.insertWith.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] [Std.Total fun x1 x2 ↦ x1 ≤ x2] [inst_2 : DecidableLE α] (f : α → α) (x : α),
  (∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) → ∀ {t : Ordnode α}, t.Valid → (Ordnode.insertWith f x t).Valid

theorem Ordnode.insert_eq_insertWith E1 #

∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLE α] (x : α) (t : Ordnode α),
  Ordnode.insert x t = Ordnode.insertWith (fun x_1 ↦ x) x t

theorem Ordnode.insert.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] [Std.Total fun x1 x2 ↦ x1 ≤ x2] [inst_2 : DecidableLE α] (x : α) {t : Ordnode α},
  t.Valid → (Ordnode.insert x t).Valid

theorem Ordnode.insert'_eq_insertWith E1 #

∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLE α] (x : α) (t : Ordnode α),
  Ordnode.insert' x t = Ordnode.insertWith id x t

theorem Ordnode.insert'.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] [Std.Total fun x1 x2 ↦ x1 ≤ x2] [inst_2 : DecidableLE α] (x : α) {t : Ordnode α},
  t.Valid → (Ordnode.insert' x t).Valid

theorem Ordnode.Valid'.map_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] {β : Type u_2} [inst_1 : Preorder β] {f : α → β},
  StrictMono f →
    ∀ {t : Ordnode α} {a₁ : WithBot α} {a₂ : WithTop α},
      Ordnode.Valid' a₁ t a₂ →
        Ordnode.Valid' (Option.map f a₁) (Ordnode.map f t) (Option.map f a₂) ∧ (Ordnode.map f t).size = t.size

theorem Ordnode.map.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] {β : Type u_2} [inst_1 : Preorder β] {f : α → β},
  StrictMono f → ∀ {t : Ordnode α}, t.Valid → (Ordnode.map f t).Valid

theorem Ordnode.Valid'.erase_aux E0 #

∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLE α] (x : α) {t : Ordnode α} {a₁ : WithBot α} {a₂ : WithTop α},
  Ordnode.Valid' a₁ t a₂ → Ordnode.Valid' a₁ (Ordnode.erase x t) a₂ ∧ Ordnode.Raised (Ordnode.erase x t).size t.size

theorem Ordnode.erase.valid E1 #

∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLE α] (x : α) {t : Ordnode α},
  t.Valid → (Ordnode.erase x t).Valid

theorem Ordnode.size_erase_of_mem E1 #

∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLE α] {x : α} {t : Ordnode α} {a₁ : WithBot α} {a₂ : WithTop α},
  Ordnode.Valid' a₁ t a₂ → x ∈ t → (Ordnode.erase x t).size = t.size - 1

def Ordset E3 #

(α : Type u_2) → [Preorder α] → Type (max 0 u_2)

An Ordset α is a finite set of values, represented as a tree. The operations on this type maintain that the tree is balanced and correctly stores subtree sizes at each level. The correctness property of the tree is baked into the type, so all operations on this type are correct by construction.

def Ordset.nil E1 #

{α : Type u_1} → [inst : Preorder α] → Ordset α

O(1). The empty set.

def Ordset.size E1 #

{α : Type u_1} → [inst : Preorder α] → Ordset α → ℕ

O(1). Get the size of the set.

def Ordset.singleton E1 #

{α : Type u_1} → [inst : Preorder α] → α → Ordset α

O(1). Construct a singleton set containing value a.

instance Ordset.instEmptyCollection E0 #

{α : Type u_1} → [inst : Preorder α] → EmptyCollection (Ordset α)

instance Ordset.instInhabited E0 #

{α : Type u_1} → [inst : Preorder α] → Inhabited (Ordset α)

instance Ordset.instSingleton E0 #

{α : Type u_1} → [inst : Preorder α] → Singleton α (Ordset α)

def Ordset.Empty E1 #

{α : Type u_1} → [inst : Preorder α] → Ordset α → Prop

O(1). Is the set empty?

theorem Ordset.empty_iff E0 #

∀ {α : Type u_1} [inst : Preorder α] {s : Ordset α}, s = ∅ ↔ (↑s).empty = true

instance Ordset.Empty.instDecidablePred E0 #

{α : Type u_1} → [inst : Preorder α] → DecidablePred Ordset.Empty

def Ordset.insert E1 #

{α : Type u_1} → [inst : Preorder α] → [Std.Total fun x1 x2 ↦ x1 ≤ x2] → [DecidableLE α] → α → Ordset α → Ordset α

O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, this replaces it.

instance Ordset.instInsert E0 #

{α : Type u_1} → [inst : Preorder α] → [Std.Total fun x1 x2 ↦ x1 ≤ x2] → [DecidableLE α] → Insert α (Ordset α)

def Ordset.insert' E1 #

{α : Type u_1} → [inst : Preorder α] → [Std.Total fun x1 x2 ↦ x1 ≤ x2] → [DecidableLE α] → α → Ordset α → Ordset α

O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, the set is returned as is.

def Ordset.mem E1 #

{α : Type u_1} → [inst : Preorder α] → [DecidableLE α] → α → Ordset α → Bool

O(log n). Does the set contain the element x? That is, is there an element that is equivalent to x in the order?

def Ordset.find E1 #

{α : Type u_1} → [inst : Preorder α] → [DecidableLE α] → α → Ordset α → Option α

O(log n). Retrieve an element in the set that is equivalent to x in the order, if it exists.

instance Ordset.instMembership E0 #

{α : Type u_1} → [inst : Preorder α] → [DecidableLE α] → Membership α (Ordset α)

instance Ordset.mem.decidable E0 #

{α : Type u_1} → [inst : Preorder α] → [inst_1 : DecidableLE α] → (x : α) → (s : Ordset α) → Decidable (x ∈ s)

theorem Ordset.pos_size_of_mem E1 #

∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLE α] {x : α} {t : Ordset α}, x ∈ t → 0 < t.size

def Ordset.erase E1 #

{α : Type u_1} → [inst : Preorder α] → [DecidableLE α] → α → Ordset α → Ordset α

O(log n). Remove an element from the set equivalent to x. Does nothing if there is no such element.

def Ordset.map E1 #

{α : Type u_1} →
  [inst : Preorder α] → {β : Type u_2} → [inst_1 : Preorder β] → (f : α → β) → StrictMono f → Ordset α → Ordset β

O(n). Map a function across a tree, without changing the structure.