2015-08-12 22:05:14 +00:00
|
|
|
import data.examples.vector
|
2014-11-16 02:49:17 +00:00
|
|
|
open nat
|
|
|
|
|
|
|
|
namespace vector
|
|
|
|
|
|
|
|
definition diag {A} {n} : vector (vector A n) n → vector A n :=
|
|
|
|
nat.rec_on n
|
|
|
|
(λv, nil)
|
|
|
|
(λn₁ (r : vector (vector A n₁) n₁ → vector A n₁) (v : vector (vector A (succ n₁)) (succ n₁)),
|
|
|
|
let h₁ : A := head (head v) in
|
|
|
|
let t₁ : vector (vector A n₁) n₁ := map tail (tail v) in
|
|
|
|
h₁ :: r t₁)
|
|
|
|
|
2015-10-13 22:39:03 +00:00
|
|
|
example : diag ((1 :: 2 :: 3 :: nil) :: (4 :: 5 :: 6 :: nil) :: (7 :: 8 :: 9 :: nil) :: nil) = (1 :: 5 :: 9 :: nil : vector num 3) :=
|
2014-11-16 02:49:17 +00:00
|
|
|
rfl
|
|
|
|
|
|
|
|
end vector
|