internlm/Lean-Github huggingface dataset:
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
⊢ lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[i] y[2 * i + 2] = false
Tactic:
have ⟨k,hk,hdk,h⟩ := h.exists_get_descendant (2*i+2) hr (.refl _)
Proof state after:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
⊢ lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[i] y[2 * i + 2] = false
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
⊢ lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[i] y[2 * i + 2] = false
Tactic:
rewrite [Subarray.getElem_swap_left, h, Subarray.getElem_swap]
Proof state after:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
⊢ lt x[↑{ val := 2 * i + 2, isLt := hr✝ }]
      (if ↑{ val := 2 * i + 2, isLt := hr✝ } = k then x[↑{ val := i, isLt := hi }]
      else if ↑{ val := i, isLt := hi } = k then x[↑{ val := 2 * i + 2, isLt := hr✝ }] else x[k]) =
    false
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
⊢ lt x[↑{ val := 2 * i + 2, isLt := hr✝ }]
      (if ↑{ val := 2 * i + 2, isLt := hr✝ } = k then x[↑{ val := i, isLt := hi }]
      else if ↑{ val := i, isLt := hi } = k then x[↑{ val := 2 * i + 2, isLt := hr✝ }] else x[k]) =
    false
Tactic:
if hrk : 2*i+2 = k then
  simp only [if_pos hrk]; exact LawfulLTBRel.asymm hx
else
  simp only [if_neg hrk, if_neg <| Nat.ne_of_lt <| trans (lt_child_right i) hdk.le]
  exact heap_right.not_lt_of_descendant k hdk
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
hrk : 2 * i + 2 = k
⊢ lt x[↑{ val := 2 * i + 2, isLt := hr✝ }]
      (if ↑{ val := 2 * i + 2, isLt := hr✝ } = k then x[↑{ val := i, isLt := hi }]
      else if ↑{ val := i, isLt := hi } = k then x[↑{ val := 2 * i + 2, isLt := hr✝ }] else x[k]) =
    false
Tactic:
simp only [if_pos hrk]
Proof state after:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
hrk : 2 * i + 2 = k
⊢ lt x[2 * i + 2] x[i] = false
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
hrk : 2 * i + 2 = k
⊢ lt x[2 * i + 2] x[i] = false
Tactic:
exact LawfulLTBRel.asymm hx
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
hrk : ¬2 * i + 2 = k
⊢ lt x[↑{ val := 2 * i + 2, isLt := hr✝ }]
      (if ↑{ val := 2 * i + 2, isLt := hr✝ } = k then x[↑{ val := i, isLt := hi }]
      else if ↑{ val := i, isLt := hi } = k then x[↑{ val := 2 * i + 2, isLt := hr✝ }] else x[k]) =
    false
Tactic:
simp only [if_neg hrk, if_neg <| Nat.ne_of_lt <| trans (lt_child_right i) hdk.le]
Proof state after:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
hrk : ¬2 * i + 2 = k
⊢ lt x[2 * i + 2] x[k] = false
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = true
h✝ : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * i + 2) y
a_ih✝ :
  ∀
    (hr :
      2 * (2 * i + 2) + 2 < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })),
    IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ }) (2 * (2 * i + 2) + 2) →
      lt y[2 * i + 2] y[2 * (2 * i + 2) + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
k : Nat
hk : k < Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })
hdk : Descendant (2 * i + 2) k
h : y[2 * i + 2] = (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 2, isLt := hr✝ })[k]
hrk : ¬2 * i + 2 = k
⊢ lt x[2 * i + 2] x[k] = false
Tactic:
exact heap_right.not_lt_of_descendant k hdk
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y x : Subarray α
i : Nat
hi : i < Subarray.size x
hl✝ : 2 * i + 1 < Subarray.size x
hr✝ : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = false
hx : lt x[i] x[2 * i + 2] = false
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
⊢ lt x[i] x[2 * i + 2] = false
Tactic:
exact hx
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.not_lt_right
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y x : Subarray α
i : Nat
hl' : 2 * i + 1 ≥ Subarray.size x
hr : 2 * i + 2 < Subarray.size x
heap_right : IsHeap lt x (2 * i + 2)
⊢ lt x[i] x[2 * i + 2] = false
Tactic:
exact absurd hr <| Nat.not_lt_of_le <| trans hl' (2*i+1).le_succ
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.is_heap
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x : Subarray α
i : Nat
y : Subarray α
h : heapifyDown.OpSpec lt x i y
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
⊢ IsHeap lt y i
Tactic:
let _hy_left := fun hl => h.not_lt_left hl heap_left
Proof state after:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x : Subarray α
i : Nat
y : Subarray α
h : heapifyDown.OpSpec lt x i y
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
_hy_left : ∀ (hl : 2 * i + 1 < Subarray.size x), lt y[i] y[2 * i + 1] = false := fun hl => not_lt_left h hl heap_left
⊢ IsHeap lt y i
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.is_heap
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x : Subarray α
i : Nat
y : Subarray α
h : heapifyDown.OpSpec lt x i y
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
_hy_left : ∀ (hl : 2 * i + 1 < Subarray.size x), lt y[i] y[2 * i + 1] = false := fun hl => not_lt_left h hl heap_left
⊢ IsHeap lt y i
Tactic:
let _hy_right := fun hr => h.not_lt_right hr heap_right
Proof state after:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x : Subarray α
i : Nat
y : Subarray α
h : heapifyDown.OpSpec lt x i y
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
_hy_left : ∀ (hl : 2 * i + 1 < Subarray.size x), lt y[i] y[2 * i + 1] = false := fun hl => not_lt_left h hl heap_left
_hy_right : ∀ (hr : 2 * i + 2 < Subarray.size x), lt y[i] y[2 * i + 2] = false := fun hr => not_lt_right h hr heap_right
⊢ IsHeap lt y i
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.is_heap
Proof state before:
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x : Subarray α
i : Nat
y : Subarray α
h : heapifyDown.OpSpec lt x i y
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
_hy_left : ∀ (hl : 2 * i + 1 < Subarray.size x), lt y[i] y[2 * i + 1] = false := fun hl => not_lt_left h hl heap_left
_hy_right : ∀ (hr : 2 * i + 2 < Subarray.size x), lt y[i] y[2 * i + 2] = false := fun hr => not_lt_right h hr heap_right
⊢ IsHeap lt y i
Tactic:
induction h with
| node_next_left x i y hi hl hr hx' hx h IH =>
  refine .node lt y i (h.size_eq ▸ hr) (_hy_left hl) (_hy_right hr) ?_ ?_
  . show IsHeap lt y (2*i+1)
    refine IH ?_ ?_
    . refine heap_left.left.swap _ _ ?_ (lt_child_left (2*i+1))
      exact trans (lt_child_left i) (lt_child_left (2*i+1))
    . refine heap_left.right.swap _ _ ?_ (lt_child_right (2*i+1))
      exact trans (lt_child_left i) (lt_child_right (2*i+1))
  . show IsHeap lt y (2*i+2)
    refine heap_right.of_subext (h.size_eq ▸ .refl) ?_
    intro k hk hdk
    rw [h.get_not_descendant k fun h => Descendant.sibling_not i <| h.ascend_right (.step .refl) hdk, Subarray.getElem_swap_ne]
    . exact Nat.ne_of_lt <| trans (lt_child_right i) hdk.le
    . exact Nat.ne_of_lt <| trans (2*i+1).lt_succ_self hdk.le
| node_end_left x i _ hl hr hx' hx =>
  refine .node lt x i hr hx ?_ heap_left heap_right
  exact LawfulLTBRel.ntrans hx <| LawfulLTBRel.asymm hx'
| node_next_right x i y hi hl hr hx' hx h IH =>
  refine .node lt y i (h.size_eq ▸ hr) (_hy_left hl) (_hy_right hr) ?_ ?_
  . show IsHeap lt y (2*i+1)
    refine heap_left.of_subext (h.size_eq ▸ .refl) ?_
    intro k hk hdk
    rw [h.get_not_descendant k fun h => Descendant.sibling_not i <| hdk.ascend_right (.step .refl) h, Subarray.getElem_swap_ne]
    . exact Nat.ne_of_lt <| trans (lt_child_left i) hdk.le
    . dsimp; intro h; cases h; exact absurd hdk (Descendant.sibling_not i)
  . show IsHeap lt y (2*i+2)
    refine IH ?_ ?_
    . refine heap_right.left.swap _ _ ?_ (lt_child_left (2*i+2))
      exact trans (lt_child_right i) (lt_child_left (2*i+2))
    . refine heap_right.right.swap _ _ ?_ (lt_child_right (2*i+2))
      exact trans (lt_child_right i) (lt_child_right (2*i+2))
| node_end_right x i _ _ hr hx' hx =>
  exact .node lt x i hr (LawfulLTBRel.ntrans hx hx') hx heap_left heap_right
| node_odd_next x i hi hl hr hx =>
  refine .node_odd lt _ i hl hr ?_
  rewrite [Subarray.getElem_swap_left, Subarray.getElem_swap_right]
  exact LawfulLTBRel.asymm hx
| node_odd_end x i _ hl hr hx =>
  exact .node_odd lt x i hl hr hx
| leaf x i hl => exact .leaf lt x i hl
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.is_heap
Proof state before:
case node_next_left.refine_2
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = true
hx : lt x[i] x[2 * i + 1] = true
h : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * i + 1) y
IH :
  ∀
    (heap_left :
      IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * (2 * i + 1) + 1))
    (heap_right :
      IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * (2 * i + 1) + 2)),
    let _hy_left :=
      (_ :
        ∀
          (hl_1 :
            2 * (2 * i + 1) + 1 <
              Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl })),
          lt y[2 * i + 1] y[2 * (2 * i + 1) + 1] = false);
    let _hy_right :=
      (_ :
        ∀
          (hr :
            2 * (2 * i + 1) + 2 <
              Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl })),
          lt y[2 * i + 1] y[2 * (2 * i + 1) + 2] = false);
    IsHeap lt y (2 * i + 1)
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
_hy_left : ∀ (hl_1 : 2 * i + 1 < Subarray.size x), lt y[i] y[2 * i + 1] = false :=
  fun hl_1 => not_lt_left (node_next_left x i y hi hl hr hx' hx h) hl_1 heap_left
_hy_right : ∀ (hr_1 : 2 * i + 2 < Subarray.size x), lt y[i] y[2 * i + 2] = false :=
  fun hr_1 => not_lt_right (node_next_left x i y hi hl hr hx' hx h) hr_1 heap_right
⊢ IsHeap lt y (2 * i + 2)
Tactic:
. show IsHeap lt y (2*i+2)
  refine heap_right.of_subext (h.size_eq ▸ .refl) ?_
  intro k hk hdk
  rw [h.get_not_descendant k fun h => Descendant.sibling_not i <| h.ascend_right (.step .refl) hdk, Subarray.getElem_swap_ne]
  . exact Nat.ne_of_lt <| trans (lt_child_right i) hdk.le
  . exact Nat.ne_of_lt <| trans (2*i+1).lt_succ_self hdk.le
Proof state after:
no goals
Theorem: Algdata.BinaryHeap.heapifyDown.OpSpec.is_heap
Proof state before:
case node_next_left.refine_1.refine_2
α : Type u
lt : α → α → Bool
inst✝ : LawfulLTBRel lt
x✝ : Subarray α
i✝ : Nat
y✝ x : Subarray α
i : Nat
y : Subarray α
hi : i < Subarray.size x
hl : 2 * i + 1 < Subarray.size x
hr : 2 * i + 2 < Subarray.size x
hx' : lt x[2 * i + 2] x[2 * i + 1] = true
hx : lt x[i] x[2 * i + 1] = true
h : heapifyDown.OpSpec lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * i + 1) y
IH :
  ∀
    (heap_left :
      IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * (2 * i + 1) + 1))
    (heap_right :
      IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * (2 * i + 1) + 2)),
    let _hy_left :=
      (_ :
        ∀
          (hl_1 :
            2 * (2 * i + 1) + 1 <
              Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl })),
          lt y[2 * i + 1] y[2 * (2 * i + 1) + 1] = false);
    let _hy_right :=
      (_ :
        ∀
          (hr :
            2 * (2 * i + 1) + 2 <
              Subarray.size (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl })),
          lt y[2 * i + 1] y[2 * (2 * i + 1) + 2] = false);
    IsHeap lt y (2 * i + 1)
heap_left : IsHeap lt x (2 * i + 1)
heap_right : IsHeap lt x (2 * i + 2)
_hy_left : ∀ (hl_1 : 2 * i + 1 < Subarray.size x), lt y[i] y[2 * i + 1] = false :=
  fun hl_1 => not_lt_left (node_next_left x i y hi hl hr hx' hx h) hl_1 heap_left
_hy_right : ∀ (hr_1 : 2 * i + 2 < Subarray.size x), lt y[i] y[2 * i + 2] = false :=
  fun hr_1 => not_lt_right (node_next_left x i y hi hl hr hx' hx h) hr_1 heap_right
⊢ IsHeap lt (Subarray.swap x { val := i, isLt := hi } { val := 2 * i + 1, isLt := hl }) (2 * (2 * i + 1) + 2)
Tactic:
. refine heap_left.right.swap _ _ ?_ (lt_child_right (2*i+1))
  exact trans (lt_child_left i) (lt_child_right (2*i+1))
Proof state after:
no goals