Skip to content

Commit f67be45

Browse files
committed
Add dot product method
1 parent 95376d2 commit f67be45

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

M2/Macaulay2/m2/modules.m2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Vector / Number := Vector / RingElement := Vector => (v,r) -> vector(v#0 / r)
138138
Vector + Vector := Vector => (v,w) -> vector(v#0+w#0)
139139
Vector - Vector := Vector => (v,w) -> vector(v#0-w#0)
140140
Vector ** Vector := Vector => (v,w) -> vector(v#0**w#0)
141+
Vector · Vector := (v,w) -> (transpose matrix v * matrix w)_(0,0)
141142

142143
Vector == Vector := (v,w) -> v === w
143144

M2/Macaulay2/packages/Macaulay2Doc/doc_module.m2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ document {
192192
TO (entries, Vector),
193193
TO (symbol **, Vector, Vector),
194194
TO (symbol ||, Vector, Vector),
195+
TO (symbol ·, Vector, Vector),
195196
},
196197
}
197198

M2/Macaulay2/packages/Macaulay2Doc/operators/times.m2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,26 @@ doc ///
214214
toggle the input method using @KBD "C-\\"@ or
215215
@KBD "M-x toggle-input-method"@.
216216
///
217+
218+
doc ///
219+
Key
220+
(symbol ·, Vector, Vector)
221+
Headline
222+
dot product
223+
Usage
224+
v · w
225+
Inputs
226+
v:Vector
227+
w:Vector
228+
Outputs
229+
:{Number, RingElement}
230+
Description
231+
Text
232+
This function computes the dot product of two elements of a free module.
233+
In particular, if $v,w\in R^n$ are represented as $n\times 1$ matrices,
234+
then $v\cdot w$ is the sole entry of the $1\times 1$ matrix $v^Tw$.
235+
Example
236+
v = vector {1, 2, 3}
237+
w = vector {4, 5, 6}
238+
v · w
239+
///

M2/Macaulay2/tests/normal/vector.m2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ assert Equation(v / 2, vector(N, {1/2, 1, 3/2}))
3333
v = vector {x, y, z}
3434
kk = frac R
3535
assert Equation(v / x, vector map(kk^3, kk^{-1}, {{1}, {y/x}, {z/x}}))
36+
37+
w = vector {y, z, x}
38+
assert Equation(v · w, x*y + x*z + y*z)

0 commit comments

Comments
 (0)