kigubkur.op.epower

Operate: element-wise exponentiation (applicable to blocks).

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

The application scenarios for element-wise power/exponentiation operator epower is similar to those as for subtraction. Thus,

Note that in (epower 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 exponent or base

Scalar as exponent of base scalar

=> (epower 3 2)
 9.0

Scalar as exponent of base 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 (epower r1 2))
 [1.0 4.0 9.0 16.0]
Order -> 1 x 4

Scalar as the base while row is the exponent

=> (view (epower 2 r1))
 [2.0 4.0 8.0 16.0]
Order -> 1 x 4

Scalar as exponent of base 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 (epower c1 2))
 [1.0]
 [4.0]
 [9.0]
 [16.0]
Order-> 4 x 1

Scalar as the base while column is the exponent

=> (view (epower 2 c1))
 [2.0]
 [4.0]
 [8.0]
 [16.0]
Order -> 4 x 1

Scalar as exponent of base matrix

=> (def M1 [[1 2] [3 4]])
=> (def M2 [[4 3] [2 1]])
=> (view M1)
 [1 2]
 [3 4]
Order -> 2 x 2
=> (view (epower M1 2))
 [1.0 4.0]
 [9.0 16.0]
Order -> 2 x 2

Scalar as the base while matrix is the exponent

=> (view (epower 2 M1))
 [2.0 4.0]
 [8.0 16.0]
Order -> 2 x 2

Scalar as exponent of base 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 (epower B1 2))
 [[{:A11 [[1.0 4.0 9.0 16.0 25.0]
          [1.0 4.0 9.0 16.0 25.0]
          [1.0 4.0 9.0 16.0 25.0]
          [1.0 4.0 9.0 16.0 25.0]
          [1.0 4.0 9.0 16.0 25.0]],
    :A12 [[36.0 49.0 64.0 81.0 100.0]
          [36.0 49.0 64.0 81.0 100.0]
          [36.0 49.0 64.0 81.0 100.0]
          [36.0 49.0 64.0 81.0 100.0]
          [36.0 49.0 64.0 81.0 100.0]]}]
  [{:A22 [[36.0 49.0 64.0 81.0 100.0] [36.0 49.0 64.0 81.0 100.0]],
    :A21 [[1.0 4.0 9.0 16.0 25.0] [1.0 4.0 9.0 16.0 25.0]]}]]

Scalar as the base while block is the exponent

=> (pprint (epower 2 B1))
 [[{:A11 [[2.0 4.0 8.0 16.0 32.0]
          [2.0 4.0 8.0 16.0 32.0]
          [2.0 4.0 8.0 16.0 32.0]
          [2.0 4.0 8.0 16.0 32.0]
          [2.0 4.0 8.0 16.0 32.0]],
    :A12 [[64.0 128.0 256.0 512.0 1024.0]
          [64.0 128.0 256.0 512.0 1024.0]
          [64.0 128.0 256.0 512.0 1024.0]
          [64.0 128.0 256.0 512.0 1024.0]
          [64.0 128.0 256.0 512.0 1024.0]]}]
  [{:A22 [[64.0 128.0 256.0 512.0 1024.0] [64.0 128.0 256.0 512.0 1024.0]],
    :A21 [[2.0 4.0 8.0 16.0 32.0] [2.0 4.0 8.0 16.0 32.0]]}]]

Exponent is not a scalar

Row matrix as exponent of row matrix

=> (view r1)
 [1 2 3 4]
Order -> 1 x 4
=> (view r2)
 [4 3 2 1]
Order -> 1 x 4
=> (view (epower r1 r2))
 [1.0 8.0 9.0 4.0]
Order -> 1 x 4
=> (view (epower r2 r1))
 [4.0 9.0 8.0 1.0]
Order -> 1 x 4

Row as exponent of base matrix or vice versa

=> (view M1)
 [1 2]
 [3 4]
Order -> 2 x 2
=> (view (epower M1 [[1 2]]))
 [1.0 4.0]
 [3.0 16.0]
Order -> 2 x 2
=> (view (epower [[1 2]] M1))
 [1.0 4.0]
 [1.0 16.0]
Order -> 2 x 2

Column matrix as exponent of column matrix

=> (view c1)
 [1]
 [2]
 [3]
 [4]
Order -> 4 x 1
=> (view c2)
 [4]
 [3]
 [2]
 [1]
Order -> 4 x 1
=> (view (epower c1 c2))
 [1.0]
 [8.0]
 [9.0]
 [4.0]
Order -> 4 x 1
=> (view (epower c2 c1))
 [4.0]
 [9.0]
 [8.0]
 [1.0]
Order -> 4 x 1

Column as exponent of base matrix or vice versa

=> (view M2)
 [4 3]
 [2 1]
Order -> 2 x 2
=> (view (epower M2 [[1][2]]))
 [4.0 3.0]
 [4.0 1.0]
Order -> 2 x 2
=> (view (epower [[1][2]] M2))
 [1.0 1.0]
 [4.0 2.0]
Order -> 2 x 2

Column matrix as exponent of base row matrix or vice versa

=> (view (epower r1 c1))
 [1.0 2.0 3.0 4.0]
 [1.0 4.0 9.0 16.0]
 [1.0 8.0 27.0 64.0]
 [1.0 16.0 81.0 256.0]
Order -> 4 x 4
=> (view (epower c1 r1))
 [1.0 1.0 1.0 1.0]
 [2.0 4.0 8.0 16.0]
 [3.0 9.0 27.0 81.0]
 [4.0 16.0 64.0 256.0]
Order -> 4 x 4

Matrix as exponent of Matrix

=> (view M1)
 [1 2]
 [3 4]
Order -> 2 x 2
=> (view M2)
 [4 3]
 [2 1]
Order -> 2 x 2
=> (view (epower M1 M2))
 [1.0 8.0]
 [9.0 4.0]
Order -> 2 x 2
=> (view (epower M2 M1))
 [4.0 9.0]
 [8.0 1.0]
Order -> 2 x 2

Block as exponent of 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 (epower B1 B2))
[[{:A11 [[1.0 512.0 6561.0 16384.0 15625.0]
         [1.0 512.0 6561.0 16384.0 15625.0]
         [1.0 512.0 6561.0 16384.0 15625.0]
         [1.0 512.0 6561.0 16384.0 15625.0]
         [1.0 512.0 6561.0 16384.0 15625.0]],
   :A12 [[7776.0 2401.0 512.0 81.0 10.0]
         [7776.0 2401.0 512.0 81.0 10.0]
         [7776.0 2401.0 512.0 81.0 10.0]
         [7776.0 2401.0 512.0 81.0 10.0]
         [7776.0 2401.0 512.0 81.0 10.0]]}]
 [{:A22 [[7776.0 2401.0 512.0 81.0 10.0]
         [7776.0 2401.0 512.0 81.0 10.0]],
   :A21 [[1.0 512.0 6561.0 16384.0 15625.0]
         [1.0 512.0 6561.0 16384.0 15625.0]]}]]
=> (pprint (epower B2 B1))
[[{:A11 [[10.0 81.0 512.0 2401.0 7776.0]
         [10.0 81.0 512.0 2401.0 7776.0]
         [10.0 81.0 512.0 2401.0 7776.0]
         [10.0 81.0 512.0 2401.0 7776.0]
         [10.0 81.0 512.0 2401.0 7776.0]],
   :A12 [[15625.0 16384.0 6561.0 512.0 1.0]
         [15625.0 16384.0 6561.0 512.0 1.0]
         [15625.0 16384.0 6561.0 512.0 1.0]
         [15625.0 16384.0 6561.0 512.0 1.0]
         [15625.0 16384.0 6561.0 512.0 1.0]]}]
 [{:A22 [[15625.0 16384.0 6561.0 512.0 1.0]
         [15625.0 16384.0 6561.0 512.0 1.0]],
   :A21 [[10.0 81.0 512.0 2401.0 7776.0]
         [10.0 81.0 512.0 2401.0 7776.0]]}]]

epower

(epower 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 exponentiation.

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