@[irreducible]
theorem
Chapter5.qsort₀_eq_qsort₁
{a : Type}
[h₁ : LT a]
[h₂ : DecidableRel fun (x1 x2 : a) => x1 < x2]
(xs : List a)
:
partial def
Chapter5.Quicksort.qsort₃
{α : Type u_1}
[LE α]
[DecidableRel fun (x1 x2 : α) => x1 ≤ x2]
(y : List α)
:
List α
partial def
Chapter5.Quicksort.qsort₃.help
{α : Type u_1}
[LE α]
[DecidableRel fun (x1 x2 : α) => x1 ≤ x2]
(x : α)
(ys us vs : List α)
:
List α
partial def
Chapter5.Quicksort.help₄
{α : Type u_1}
[LE α]
[DecidableRel fun (x1 x2 : α) => x1 ≤ x2]
(x : α)
(ys us vs : List α)
:
List α
partial def
Chapter5.Quicksort.qsort₄
{α : Type u_1}
[LE α]
[DecidableRel fun (x1 x2 : α) => x1 ≤ x2]
:
@[irreducible]
def
Chapter5.Quicksort.help₅
{α : Type u_1}
[LE α]
[DecidableEq α]
[DecidableRel LE.le]
(t : ℕ)
(x : α)
(ys us vs : List α)
:
List α
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[irreducible]
def
Chapter5.Quicksort.qsort₅
{α : Type u_1}
[LE α]
[DecidableEq α]
[DecidableRel fun (x1 x2 : α) => x1 ≤ x2]
(n : ℕ)
(ys : List α)
:
List α
Equations
Instances For
@[irreducible]
Equations
- Chapter5.T 0 n = 0
- Chapter5.T m 0 = 0
- Chapter5.T m_2.succ n_2.succ = 1 + max (Chapter5.T m_2 (n_2 + 1)) (Chapter5.T (m_2 + 1) n_2)
Instances For
Equations
Instances For
Equations
- Chapter5.instReprCard = { reprPrec := Chapter5.instReprCard.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
@[irreducible]
Exercise 5.12 #
sortBy é uma função de ordenação de listas parametrizada pela função de comparação. Precisamos adaptar merge para então basicamente renomear S52.msort₃ para sortBy parametrizando pela função de comparação.
Como em Haskell, compare é definida para todo tipo instância de Ord.
A função compareOn é equivalente a comparing do livro.
Equations
- Chapter5.merge₁ f [] x✝ = x✝
- Chapter5.merge₁ f x✝ [] = x✝
- Chapter5.merge₁ f (x_2 :: xs) (y :: ys) = if f x_2 y = Ordering.lt then x_2 :: Chapter5.merge₁ f xs (y :: ys) else y :: Chapter5.merge₁ f (x_2 :: xs) ys
Instances For
Equations
Instances For
Equations
- Chapter5.sortOn₂ f xs = List.map Prod.snd (Chapter5.sortBy (compareOn Prod.fst) ((List.map f xs).zip xs))
Instances For
def
Chapter5.Heapsort.split₁
{a : Type u_1}
[Inhabited a]
[LE a]
[DecidableRel fun (x1 x2 : a) => x1 ≤ x2]
:
Nn split₁ the where makes op visible from outside.
In split, let is defined only in the second equation of
the pattern match. let rec would make op also visible.
If op is not visible, in the split_left_le we would need
lift_lets ; intro op
Equations
Instances For
def
Chapter5.Heapsort.split₁.op
{a : Type u_1}
[LE a]
[DecidableRel fun (x1 x2 : a) => x1 ≤ x2]
(x : a)
(acc : a × List a × List a)
:
Equations
Instances For
partial def
Chapter5.Heapsort.mkHeap
{a : Type}
[Inhabited a]
[LE a]
[DecidableRel fun (x1 x2 : a) => x1 ≤ x2]
:
Equations
- Chapter5.Heapsort.mkTree xs = (Chapter5.Heapsort.mkPair₀ xs.length xs).1
Instances For
Equations
- Chapter5.csort m xs = List.flatMap (Function.uncurry List.replicate) (Chapter3.accumArray Nat.add 0 (0, m) (List.map (fun (x : ℕ) => (x, 1)) xs)).toList
Instances For
Equations
- Chapter5.filter x✝ [] = []
- Chapter5.filter x✝ (x_2 :: xs) = if x✝ x_2 = true then x_2 :: Chapter5.filter x✝ xs else Chapter5.filter x✝ xs
Instances For
Equations
- Chapter5.remove_empty [] = []
- Chapter5.remove_empty ([] :: xs) = Chapter5.remove_empty xs
- Chapter5.remove_empty (x_1 :: xs) = x_1 :: Chapter5.remove_empty xs
Instances For
Equations
- Chapter5.lists_concat [] = []
- Chapter5.lists_concat (x_1 :: xs) = x_1 ++ Chapter5.lists_concat xs
Instances For
Equations
- Chapter5.string_rsort x✝ [] = []
- Chapter5.string_rsort [] x✝ = x✝
- Chapter5.string_rsort (f :: fs) x✝ = Chapter5.lists_concat (Chapter5.string_ptn f (Chapter5.string_rsort fs x✝))
Instances For
Equations
- Chapter5.string_incresing_order x✝ = List.map (fun (x : ℕ) => flip String.get { byteIdx := x }) (List.range x✝)