kigubkur.op.minus
Operate: subtraction (applicable to blocks).
minus
(require '[kigubkur.op [minus :refer [minus]]])
With the exception that subtraction is not commutative the applicable cases are basically the same as those described for the plus
operator. Thus,
Note that in (minus A B)
is equal to A “−” B where A is the minuend and B is the subtrahend.
Case 1: scalar s is the minuend or the subtrahend
Case 2: between row r and column c
Case 3: between row r and matrix A
Case 4: between column c and matrix A
Case 5: blocks of same order
Case 6: between different ordered block-row and block-column
Case 6.1; mother of block-column is a column matrix (vector)
Case 6.2; mother of block-column is a matrix
Case 7: between different ordered block-matrix and block-row
Case 8: between different ordered block-matrix and block-column
Examples
Scalar as minuend or subtrahend
Scalar subtracted from scalar
=> (minus 3 2)
1
Scalar subtracted from row matrix
=> (def r1 [[1 2 3 4]])
=> (def r2 [[4 3 2 1]])
=> (view r1)
[1 2 3 4]
Order -> 1 x 4
=> (view (minus r1 2))
[-1 0 1 2]
Order -> 1 x 4
Subtraction is not commutative.
=> (view (minus 2 r1))
[1 0 -1 -2]
Order -> 1 x 4
Scalar subtracted from column matrix
=> (def c1 [[1][2][3][4]])
=> (def c2 [[4][3][2][1]])
=> (view c1)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (view (minus c1 2))
[-1]
[0]
[1]
[2]
Order-> 4 x 1
Subtraction is not commutative.
=> (view (minus 2 c1))
[1]
[0]
[-1]
[-2]
Order -> 4 x 1
Scalar subtracted from matrix
=> (def M1 [[1 2] [3 4]])
=> (def M2 [[4 3] [2 1]])
=> (view M1)
[1 2]
[3 4]
Order -> 2 x 2
=> (view (minus M1 2))
[-1 0]
[1 2]
Order -> 2 x 2
Subtraction is not commutative.
=> (view (minus 2 M1))
[1 0]
[-1 -2]
Order -> 2 x 2
Scalar subtracted from block matrix
(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L1 [[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]])
=> (def B1 (block L1 5))
=> (def L2 [[10 9 8 7 6 5 4 3 2 1]
[10 9 8 7 6 5 4 3 2 1]
[10 9 8 7 6 5 4 3 2 1]
[10 9 8 7 6 5 4 3 2 1]
[10 9 8 7 6 5 4 3 2 1]
[10 9 8 7 6 5 4 3 2 1]
[10 9 8 7 6 5 4 3 2 1]])
=> (def B2 (block L2 5))
=> (pprint B1)
[[{:A11 [[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]],
:A12 [[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]]}]
[{:A22 [[6 7 8 9 10]
[6 7 8 9 10]],
:A21 [[1 2 3 4 5]
[1 2 3 4 5]]}]]
=> (pprint (minus B1 2))
[[{:A11 [[-1 0 1 2 3]
[-1 0 1 2 3]
[-1 0 1 2 3]
[-1 0 1 2 3]
[-1 0 1 2 3]],
:A12 [[4 5 6 7 8]
[4 5 6 7 8]
[4 5 6 7 8]
[4 5 6 7 8]
[4 5 6 7 8]]}]
[{:A22 [[4 5 6 7 8]
[4 5 6 7 8]],
:A21 [[-1 0 1 2 3]
[-1 0 1 2 3]]}]]
Subtraction is not commutative.
=> (pprint (minus 2 B1))
[[{:A11 [[1 0 -1 -2 -3]
[1 0 -1 -2 -3]
[1 0 -1 -2 -3]
[1 0 -1 -2 -3]
[1 0 -1 -2 -3]],
:A12 [[-4 -5 -6 -7 -8]
[-4 -5 -6 -7 -8]
[-4 -5 -6 -7 -8]
[-4 -5 -6 -7 -8]
[-4 -5 -6 -7 -8]]}]
[{:A22 [[-4 -5 -6 -7 -8]
[-4 -5 -6 -7 -8]],
:A21 [[1 0 -1 -2 -3]
[1 0 -1 -2 -3]]}]]
Subtrahend is not a scalar
Row matrix subtracted from row matrix
=> (view r1)
[1 2 3 4]
Order -> 1 x 4
=> (view r2)
[4 3 2 1]
Order -> 1 x 4
=> (view (minus r1 r2))
[-3 -1 1 3]
Order -> 1 x 4
=> (view (minus r2 r1))
[3 1 -1 -3]
Order -> 1 x 4
Row subtracted from matrix or vice versa
=> (view M1)
[1 2]
[3 4]
Order -> 2 x 2
=> (view (minus M1 [[1 2]]))
[0 0]
[2 2]
Order -> 2 x 2
=> (view (minus [[1 2]] M1))
[0 0]
[-2 -2]
Order -> 2 x 2
Column matrix subtracted from column matrix
=> (view c1)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (view c2)
[4]
[3]
[2]
[1]
Order -> 4 x 1
=> (view (minus c1 c2))
[-3]
[-1]
[1]
[3]
Order -> 4 x 1
=> (view (minus c2 c1))
[3]
[1]
[-1]
[-3]
Order -> 4 x 1
Column subtracted from matrix or vice versa
=> (view M2)
[4 3]
[2 1]
Order -> 2 x 2
=> (view (minus M2 [[1][2]]))
[3 2]
[0 -1]
Order -> 2 x 2
=> (view (minus [[1][2]] M2))
[-3 -2]
[0 1]
Order -> 2 x 2
Column matrix subtracted from row matrix or vice versa
=> (view (minus r1 c1))
[0 1 2 3]
[-1 0 1 2]
[-2 -1 0 1]
[-3 -2 -1 0]
Order -> 4 x 4
=> (view (minus c1 r1))
[0 -1 -2 -3]
[1 0 -1 -2]
[2 1 0 -1]
[3 2 1 0]
Order -> 4 x 4
Matrix subtracted from Matrix
=> (view M1)
[1 2]
[3 4]
Order -> 2 x 2
=> (view M2)
[4 3]
[2 1]
Order -> 2 x 2
=> (view (minus M1 M2))
[-3 -1]
[1 3]
Order -> 2 x 2
=> (view (minus M2 M1))
[3 1]
[-1 -3]
Order -> 2 x 2
Block subtracted from block
=> (pprint B1)
[[{:A11 [[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]],
:A12 [[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]]}]
[{:A22 [[6 7 8 9 10]
[6 7 8 9 10]],
:A21 [[1 2 3 4 5]
[1 2 3 4 5]]}]]
=> (pprint B2)
[[{:A11 [[10 9 8 7 6]
[10 9 8 7 6]
[10 9 8 7 6]
[10 9 8 7 6]],
:A12 [[5 4 3 2 1]
[5 4 3 2 1]
[5 4 3 2 1]
[5 4 3 2 1]
[5 4 3 2 1]]}]
[{:A21 [[10 9 8 7 6]
[10 9 8 7 6]],
:A22 [[5 4 3 2 1]
[5 4 3 2 1]]}]]
=> (pprint (minus B1 B2))
[[{:A11 [[-9 -7 -5 -3 -1]
[-9 -7 -5 -3 -1]
[-9 -7 -5 -3 -1]
[-9 -7 -5 -3 -1]
[-9 -7 -5 -3 -1]],
:A12 [[1 3 5 7 9]
[1 3 5 7 9]
[1 3 5 7 9]
[1 3 5 7 9]
[1 3 5 7 9]]}]
[{:A21 [[-9 -7 -5 -3 -1]
[-9 -7 -5 -3 -1]],
:A22 [[1 3 5 7 9]
[1 3 5 7 9]]}]]
=> (pprint (minus B2 B1))
[[{:A11 [[9 7 5 3 1]
[9 7 5 3 1]
[9 7 5 3 1]
[9 7 5 3 1]
[9 7 5 3 1]],
:A12 [[-1 -3 -5 -7 -9]
[-1 -3 -5 -7 -9]
[-1 -3 -5 -7 -9]
[-1 -3 -5 -7 -9]
[-1 -3 -5 -7 -9]]}]
[{:A21 [[9 7 5 3 1]
[9 7 5 3 1]],
:A22 [[-1 -3 -5 -7 -9]
[-1 -3 -5 -7 -9]]}]]
minus
(minus X Y)
Given a scalar, row matrix, column matrix, matrix or a block and a scalar, row matrix, column matrix, matrix or a block, returns element-wise subtraction.
Syntax: (minus X Y)
s.t X
, Y
is a scalar or kigubkur© matrix (or block)
Note:
if xik or yik ∈ {##NaN
, ##Inf
, ##-Inf
}, returns ##NaN
,
otherwise, returns x − y.