-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.v
105 lines (85 loc) · 2.25 KB
/
vector.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#[global]
Set Primitive Projections.
#[global]
Unset Printing Primitive Projection Parameters.
#[global]
Set Universe Polymorphism.
#[global]
Set Default Goal Selector "!".
Require Import Coq.Unicode.Utf8.
Require Import Coq.Program.Tactics.
Require Import Coq.Strings.String.
Require Import Coq.Lists.List.
Require Import Coq.Vectors.VectorDef.
Require Coq.Vectors.Fin.
Import IfNotations.
Import ListNotations.
#[universes(cumulative)]
Record vec N := {
pos: Type;
dir: pos → N ;
}.
Arguments pos {N}.
Arguments dir {N}.
Definition K {N} (c: Type): vec N := {| dir (xy: c * N) := snd xy ; |}.
Inductive fiber {N} (v: vec N): N → Type :=
| sup ii: fiber v (dir v ii).
Infix "!" := fiber (at level 30).
#[universes(cumulative)]
Record mat M N := {
val: Type ;
i: val → M ;
j: val → N ;
}.
Arguments val {M N}.
Arguments i {M N}.
Arguments j {M N}.
Definition outer {A} (f: vec A) (g: vec A): mat A A :=
{|
val := pos f * pos g ;
i '(x, y) := dir f x ;
j '(x, y) := dir g y ;
|}.
Infix "⊗" := outer (at level 30).
Definition I N: mat N N := {|
val := { '(x, y) | x = y } ;
i xy := fst (proj1_sig xy) ;
j xy := snd (proj1_sig xy) ;
|}.
Definition compose {A B C} (f: mat B C) (g: mat A B): mat A C :=
{|
val := { '(x, y) | i f x = j g y } ;
i xy := i g (snd (proj1_sig xy)) ;
j xy := j f (fst (proj1_sig xy)) ;
|}.
Infix "∘" := compose (at level 30).
Definition kronecker {A B C D} (f: mat A B) (g: mat C D): mat (A * C) (B * D) :=
{|
val := val f * val g ;
i '(x, y) := (i f x, i g y) ;
j '(x, y) := (j f x, j g y) ;
|}.
Infix "×" := kronecker (at level 30).
Definition trace {A} (f: mat A A) := { x | i f x = j f x }.
Definition inner {A} (f: vec A) (g: vec A) := trace (f ⊗ g).
Infix "·" := inner (at level 30).
Fixpoint sum (l: list Type): Type :=
match l with
| [] => Empty_set
| H :: T => H + sum T
end.
Definition oflist (l: list Type): sum l → Fin.t (length l).
Proof.
induction l.
- cbn.
contradiction.
- cbn.
intros [x|y].
+ constructor.
+ apply Fin.FS.
apply IHl.
apply y.
Defined.
Definition mkvec (l: list Type): vec (Fin.t (length l)) := {| dir := oflist l |}.
#[program]
Definition foo: mkvec [ bool ; unit ; unit ] · mkvec [ nat ; unit ; unit ] := (inl false, inl 0).