@@ -4,41 +4,27 @@ import Fad.«Chapter1-Ex»
44
55namespace Chapter9
66
7- def picks {a : Type } : List a → List (a × List a)
7+ def picks {a : Type } : List a → List (a × List a) -- 1 ou 7
88| [] => []
99| x :: xs =>
1010 (x, xs) :: ((picks xs).map (λ p => (p.1 , x :: p.2 )))
1111
12- def wrap {α : Type } (a : α) : List α := [a]
12+ def wrap {α : Type } (a : α) : List α := [a] -- 1-Ex
1313
14- partial def until' (p: a → Bool) (f: a → a) (x : a) : a :=
14+ partial def until' (p: a → Bool) (f: a → a) (x : a) : a := -- 1
1515 if p x then x
1616 else until ' p f (f x)
1717
18- def foldr1 {a : Type } [Inhabited a] (f : a → a → a) : List a → a
18+ def foldr1 {a : Type } [Inhabited a] (f : a → a → a) : List a → a -- 7
1919 | [] => default
2020 | x::xs => xs.foldr f x
2121
22- def minWith {a b : Type } [LE b] [Inhabited a]
22+ def minWith {a b : Type } [LE b] [Inhabited a] -- 7
2323 [DecidableRel (α := b) (· ≤ ·)]
2424 (f : a → b) (as : List a) : a :=
2525 let smaller f x y := cond (f x ≤ f y) x y
2626 foldr1 (smaller f) as
2727
28-
29- #eval foldr1 (fun a b => a + b ) [1 ,2 ,3 ,4 ,5 ,6 ]
30-
31- def qsort₂ [Ord a] (f : a → a → Ordering) : List a → List a
32- | [] => []
33- | (x :: xs) =>
34- let p := xs.partition (λ z => f z x = Ordering.lt)
35- (qsort₂ f p.1 ) ++ [x] ++ (qsort₂ f p.2 )
36- termination_by xs => xs.length
37- decreasing_by
38- all_goals simp
39- [List.partition_eq_filter_filter,
40- List.length_filter_le, Nat.lt_add_one_of_le]
41-
4228/- 9.1 Graphs and spanning trees -/
4329
4430abbrev Vertex := Nat
0 commit comments