− (minus)
The minus sign is used for several different operations on various kinds of operands and has two distinct syntactic forms:
-
As a binary operator,
−
is typically used for mathematical subtraction. -
As a unary operator,
−
is typically used to denote the opposite number, vector, or matrix.
Syntax
-
a − b
-
applicable to several different kinds of operands
a
andb
-
-
−a
-
a
is a number, vector, or matrix
-
Description and examples
Binary operator: subtraction
Subtraction of numbers
If a
and b
are numbers (integers, rational numbers, real number, or complex numbers), a − b
is the mathematical difference of a
and b
. The type of the difference is the most specific type possible.
Some examples:
-
If
a
andb
are both integers, so isa − b
if no integer overflow occurs; in that case, the result is a real number. -
If
a
is an integer andb
a rational number,a − b
is a rational number. -
If
a
is an integer andb
a real number,a − b
is a real number. -
If
a
is an integer andb
a complex number,a − b
is a complex number. -
If
a
is a real number andb
a complex number,a − b
is a complex number. -
If
a
is a rational number andb
a complex number,a − b
is a complex number.
π − e
0.423310825131
3/7 − 2/5
1/35 (=0.0285714285714)
Vector subtraction
If u
and v
are vectors, u − v
is the vector difference between u
and v
. u − v
is a complex vector if at least one of u
and v
is complex; otherwise, u − v
is a real vector.
u
and v
must be of the same dimension.
u ≔ ❨2, 1, 3❩; v ≔ ❨0, 2, 1❩; u − v
⎛2 ⎞ e⎜−1⎟ ⎝2 ⎠
Matrix subtraction
If A
and B
are matrices, A − B
is the matrix difference between A
and B
. A − B
is a complex matrix if at least one of A
and B
is complex; otherwise, A − B
is a real matrix.
A
and B
must be of the same size.
A ≔ ❨❨1, 3❩, ❨−i, 1❩❩; B ≔ ❨❨2, 1❩, ❨0, −1❩❩; A − B
⎛−1 2⎞ ⎝−i 2⎠
Subtracting a scalar from a vector
If v
is a vector and x
a number, then v − x
is the vector obtained from v
by subtracting x
from each component. If either v
or x
is complex, v − x
is a complex vector. Otherwise, v − x
is a real vector.
❨1, 5, 2❩ − i
⎛1 − i⎞ e⎜5 − i⎟ ⎝2 − i⎠
Subtracting a scalar from a matrix
If A
is a matrix and x
a number, then A − x
is the matrix obtained from A
by subtracting x
from each entry. If either A
or x
is complex, A − x
is a complex matrix. Otherwise, A − x
is a real matrix.
ZeroMatrix(4) − 1
⎛−1 −1 −1 −1⎞ ⎜−1 −1 −1 −1⎟ ⎜−1 −1 −1 −1⎟ ⎝−1 −1 −1 −1⎠
Superposing two sounds by samplewise subtraction
If s
and t
are two sounds, s − t
is the superposed sound obtained by samplewise subtraction.
SineTone(100, 0.1, 1) − SineTone(400, 0.1, 1)
A 1-second 32-bit 48000 Hz 1-channel sound.
SineTone(100, 0.1, 1) − SineTone(100, 0.1, 1)
A 1-second 32-bit 48000 Hz 1-channel sound.
SoundMax(ans)
0
Unary operator
If x
is a number, vector, or matrix, −x
is the opposite number, vector, or matrix, that is, 0 − x
where 0
stands for the suitable zero object.
−π
−3.14159265359 (=−π)
−❨1, 0, 0❩
⎛−1⎞ e⎜0 ⎟ ⎝0 ⎠
−IdentityMatrix(3)
⎛−1 0 0⎞ ⎜ 0 −1 0⎟ ⎝ 0 0 −1⎠
Notes
-
The binary operator
−
is mapped to thesubtract
function. -
The unary operator
−
is mapped to thenegative
function.