kigubkur.op.plus

Operate: addition (applicable to blocks).

  • plus
(require '[kigubkur.op [plus :refer [plus]]])

Including the linear algebra definition which requires that both augend and addend must have the same order, that is,

(plus A B) is

This is equal to A “+” B where A is the augend and B is the addend. The kigubkur©’s plus operator is also defined for some special cases outside linear algebra.

Case 1

For scalar s such that

Case 2

For row and column matrices

Addition between them is commutative and defined as

Case 3

Case 4

Operation in blocks

plus operator is also defined for blocks with the general condition that the blocks must

  • have the equal blocking size, i.e., (= (:blockingsize (meta B1)) (:blockingsize (meta B2)))
  • addition must be defined on the mother of the blocks, i.e., the above conditions must be satisfied.

Case 5

It is defined for the obvious case of addition among blocks of the same order.

where

  • the order of the blocks themselves are not only equal but so are the order of their mother matrices from which the blocks were built.
  • consequently, the number of keys among the blocks must be equal.

Case 6: Sum of different ordered block-row and block-column

For the case of addition between a block-row and a block-column

  • the order of the blocks are unequal
  • for mother of the block-column that is a matrix (not a column)
  • the number of columns of the mothers for both the blocks must be equal

These are illustrated as follows

Case 6.1

Assuming that the (:blockingsize (meta B)) for both blocks is equal to k such that

Then,

Case 6.2

If the mother of the block-column is not a column matrix (vector) but a matrix such as

the number of columns in the elements of the block-column must be equal to the (:blockingsize (meta Bc)) otherwise the block will not be a block-column but a block-matrix

Then, for the addition operation between the block-column and the block-row to be applicable the block-row must be such that its mother is a row with same number of columns (as the mother of the block-column), i.e., it is equal to the (:blockingsize (meta Br)) [Note that (= (:blockingsize (meta Br)) (:blockingsize (meta Br))) is true]

Thus,

Notice that for a block-column whose mother is a matrix the block-row as its augend (or addend) will not only contain a single element which is a row matrix but this row matrix will have the number of columns that is equal to the blocksize. Therefore, the number of columns of the mother of the block-column must also be equal to the blocksize. If this condition is not met the addition operation is no longer between a block-column and a block-row.

Case 7: Sum of different ordered block-matrix and block-row

For the addition between a block-matrix and a block-row

  • the orders of the blocks are unequal (and consequently unequal number of keys)
  • the number of columns in the mother of the block-matrix must be equal to those of the block-row.

Hence for blocksize k < m and k < n

Then,

Case 8: Sum of different ordered block-matrix and block-column

For the addition between a block-matrix and a block-column

  • the orders of the blocks are unequal (and consequently unequal number of keys)
  • the number of rows in the mother of the block-matrix must be equal to those of the block-column.

For blocksize k < m and k < n

Then,

Note that in the above cases no.7 and no.8 the mothers of the block-row and the block-column are row and column matrix respectively.

Examples

Addend is a scalar

Scalar added to scalar

=> (plus 3 2)
5

Scalar added to row matrix

=> (def r [[1 2 3 4]])
=> (view r)
[1 2 3 4]
Order -> 1 x 4
=> (view (plus r 2))
[3 4 5 6]
Order -> 1 x 4

Scalar added to column matrix

=> (def c [[1][2][3][4]])
=> (view c)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (view (plus c 2))
[3]
[4]
[5]
[6]
Order -> 4 x 1

Scalar added to matrix

=> (def M [[1 2] [3 4]])
=> (view M)
[1 2]
[3 4]
Order -> 2 x 2
=> (view (plus M 2))
[3 4]
[5 6]
Order -> 2 x 2

Scalar added to block matrix

(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[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 B (block L 5))
=> (pprint B)
[[{: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 (plus B 2))
[[{:A11 [[3 4 5 6 7]
         [3 4 5 6 7]
         [3 4 5 6 7]
         [3 4 5 6 7]
         [3 4 5 6 7]],
   :A12 [[8 9 10 11 12]
         [8 9 10 11 12]
         [8 9 10 11 12]
         [8 9 10 11 12]
         [8 9 10 11 12]]}]
 [{:A22 [[8 9 10 11 12]
         [8 9 10 11 12]],
   :A21 [[3 4 5 6 7]
         [3 4 5 6 7]]}]]

Addend is not a scalar

Row matrix added to row matrix

=> (view r)
[1 2 3 4]
Order -> 1 x 4
=> (view (plus r r))
[2 4 6 8]
Order -> 1 x 4

Column matrix added to column matrix

=> (view c)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (view (plus c c))
[2]
[4]
[6]
[8]
Order -> 4 x 1

Column matrix added to row matrix is commutative

=> (view (plus r c))
[2 3 4 5]
[3 4 5 6]
[4 5 6 7]
[5 6 7 8]
Order -> 4 x 4
=> (view (plus c r))
[2 3 4 5]
[3 4 5 6]
[4 5 6 7]
[5 6 7 8]
Order -> 4 x 4

Matrix added to Matrix

=> (view M)
[1 2]
[3 4]
Order -> 2 x 2
=> (view (plus M M))
[2 4]
[6 8]
Order -> 2 x 2

Matrix added to column is commutative

=> (view (plus M [[1][2]]))
[2 3]
[5 6]
Order -> 2 x 2
=> (view (plus [[1][2]] M))
[2 3]
[5 6]
Order -> 2 x 2

Matrix added to row is commutative

=> (view (plus M [[1 2]]))
[2 4]
[4 6]
Order -> 2 x 2
=> (view (plus [[1 2]] M))
[2 4]
[4 6]
Order -> 2 x 2

Block plus block

=> (pprint B)
  [[{: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 (plus B B))
[[{:A11 [[2 4 6 8 10]
         [2 4 6 8 10]
         [2 4 6 8 10]
         [2 4 6 8 10]
         [2 4 6 8 10]],
   :A12 [[12 14 16 18 20]
         [12 14 16 18 20]
         [12 14 16 18 20]
         [12 14 16 18 20]
         [12 14 16 18 20]]}]
 [{:A22 [[12 14 16 18 20]
         [12 14 16 18 20]],
   :A21 [[2 4 6 8 10]
         [2 4 6 8 10]]}]]

plus

(plus 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 addition.

Syntax: (plus 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.