-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbasic-operations.Rmd
149 lines (103 loc) · 3.9 KB
/
basic-operations.Rmd
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#### Scalar product
A dot product of two vectors - traditionally: $\vec{v} \cdot \vec{u}$ or in quantum mechanics $\langle u | v \rangle$.
<div id="einsumindl11" class="equation">
<div class="eq-diagram"></div>
<div class="eq-elem">$$\hspace{0.3cm}=\hspace{0.3cm}\sum_{i}$$</div>
<div class="eq-elem tensor-eq-a">$$a_{i}$$</div>
<div class="eq-elem tensor-eq-b">$$b_{i}$$</div>
</div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("u", "start", [], ["i"])
.addTensor("v", "right", ["i"], [])
.addContraction(0, 1, "i")
.setSize(100, 120)
.draw("#einsumindl11");
```
#### Matrix-vector multiplication
A vector transformed by a matrix, traditionally $A \vec{u}$ or in quanutm mechanics $A | v \rangle$.
<div id="einsumindl9" class="equation">
<div class="eq-diagram"></div>
<div class="eq-elem">$$\hspace{0.3cm}=\hspace{0.3cm}\sum_{j}$$</div>
<div class="eq-elem tensor-eq-A">$$A_{ij}$$</div>
<div class="eq-elem tensor-eq-b">$$v_{j}$$</div>
</div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("A", {x: 1, y: 0}, ["i"], ["j"])
.addTensor("v", "right", ["j"], [])
.addContraction(0, 1, "j")
.setSize(160, 120)
.draw("#einsumindl9");
```
#### Matrix-matrix multiplication
Multiply matrix by matrix, traditionally: $A B$.
<div id="einsumindl10" class="equation">
<div class="eq-diagram"></div>
<div class="eq-elem">$$\hspace{0.3cm}=\hspace{0.3cm}\sum_{k}$$</div>
<div class="eq-elem tensor-eq-A">$$A_{ik}$$</div>
<div class="eq-elem tensor-eq-B">$$B_{kj}$$</div>
</div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("A", {x: 1, y: 0}, ["i"], ["j"])
.addTensor("B", "right", ["j"], ["k"])
.addContraction(0, 1, "j")
.setSize(220, 120)
.draw("#einsumindl10");
```
#### Outer product
An outer product between two vectors. In it commonly used in quantum mechanics and written as $| u \rangle \langle v |$. In particular for $| u \rangle = | v \rangle$, we get a projection operator $| v \rangle \langle v |$.
<div id="einsumindl14_1" class="equation">
<div class="eq-diagram"></div>
<div class="eq-elem">$$\hspace{0.3cm}=\hspace{0.3cm}$$</div>
<div class="eq-elem tensor-eq-a">$$a_{i}$$</div>
<div class="eq-elem tensor-eq-b">$$b_{j}$$</div>
</div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("u", {x: 1, y: 0}, ["i"], [])
.addTensor("v", {x: 2, y: 0}, [], ["j"])
.setSize(220, 120)
.draw("#einsumindl14_1");
```
#### Tensor product
TODO
#### Expected value
$\sum_{ij} v_i M_{ij} v_j$ (or in the context of quantum: $\langle v | M | v \rangle$)
<div id="example6" class="equation"></div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("v", {x: 0, y: 0}, [], ["i"])
.addTensor("M", {x: 1, y: 0}, ["i"], ["j"])
.addTensor("v", {x: 2, y: 0}, ["j"], [])
.addContraction(0, 1, "i")
.addContraction(1, 2, "j")
.setSize(160, 120)
.draw("#example6");
```
#### Trace
TODO
#### Matrix transpose
TO FIX
<div id="einsumindl5_1" class="equation">
<div class="eq-diagram"></div>
<div class="eq-elem">$$\hspace{0.3cm}=\hspace{0.3cm}$$</div>
<div class="eq-elem tensor-eq-B">$$B_{ji}$$</div>
</div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("B", {x: 1, y: 0}, ["j"], ["i"])
.setSize(160, 110)
.draw("#einsumindl5_1");
```
#### Matrix is diagonal
<div id="example8" class="equation"></div>
```{js, results='asis', echo=FALSE, message=FALSE}
TensorDiagram.new()
.addTensor("dot", {x: 1, y: 0}, ["i"], ["j"], [], ["k"], { shape:"dot", showLabel: false })
.addTensor("S", {x: 1, y: 1}, [], [], ["k"], [], { labelPos: "left"} )
.addContraction(0, 1, "k")
.setSize(160, 150)
.draw("#example8");
```