RepLAB provides the following multi-dimensional array types as an extension to the types provided by MATLAB/Octave.
cyclotomic
implements exact computation on the cyclotomic field. This enables RepLAB to handle any irreducible representation of a finite group, if care is taken to express it over the cyclotomics (which is always possible).
H
implements matrices of quaternions using a pair of complex matrices. Quaternion matrices are used to decompose real representations of quaternion-type.
Multidimensional array with elements in the cyclotomic field
Requires Java and the cyclolab support library.
The implementation is pretty slow, but values are exact.
We can construct cyclotomic arrays in various ways.
They can be constructed from double floating-point arrays. Note that only fractions with a power-of-two denominator can be represented exactly.
Example
>>> replab.cyclotomic(1/2) % doctest: +cyclotomic
1/2
>>> replab.cyclotomic(1/3)
6004799503160661/18014398509481984
Note that passing a cyclotomic array as a parameter is the identity operation. This is useful when converting number types.
Example
>>> c = replab.cyclotomic(1) % doctest: +cyclotomic
1
>>> replab.cyclotomic(c)
1
Cyclotomics can also be constructed from vpis:
Example
>>> c = replab.cyclotomic(vpi('100000000000000')) % doctest: +cyclotomic
100000000000000
They can also be constructed from strings. A vector/matrix syntax is also available, but row coefficients must always be separated by commas.
Example
>>> replab.cyclotomic('2/3') % doctest: +cyclotomic
2/3
>>> replab.cyclotomic('[1, 0; 0, 1]')
1 0
0 1
The string syntax accepts:
integers,
the four operations +
, -
, *
, /
,
powers ^
with integer exponents,
parentheses,
roots of unity as in Gap System (E(n)
is exp(2*i*pi/n)
),
square roots of rational numbers,
sines and cosines of rational multiples of pi
.
Example
>>> replab.cyclotomic('sqrt(2)') % doctest: +cyclotomic
E(8)-E(8)^3
>>> replab.cyclotomic('cos(-pi/3)') % doctest: +cyclotomic
-1/2
>>> replab.cyclotomic('(3 + 2/3)^3') % doctest: +cyclotomic
1331/27
>>> replab.cyclotomic('E(3)^2') % doctest: +cyclotomic
E(3)^2
Finally, the constructor also accepts heterogenous cell arrays, where the types above can be mixed and matched (except that strings must represent scalars, not matrices/vectors).
Example
>>> replab.cyclotomic({'1' vpi(2); '1/2' 1}) % doctest: +cyclotomic
1 2
1/2 1
A variety of static methods is available.
Example
>>> I = replab.cyclotomic.eye(3) % doctest: +cyclotomic
1 0 0
0 1 0
0 0 1
Class members list
Properties
Standard MATLAB methods
E
– Returns roots of unity
eye
– Constructs the n x n
identity matrix (incomplete)
ones
– Constructs a cyclotomic array filled with ones
rand
– Random cyclotomic matrix
sparse
– Constructs a 2D cyclotomic array using sparse matrix syntax (incomplete)
zeros
– Constructs a cyclotomic array filled with zeros
Cyclotomic constructions
approximate
– Constructs the simplest rational approximation within an interval, for coefficients of a matrix
fromRationals
– Constructs a cyclotomic matrix of rational numbers
sqrtRational
– Returns the square root of a rational number
Matrix concatenation
blkdiag
– Block diagonal concatenation of matrix input arguments
horzcat
– Horizontal concatenation (incomplete)
vertcat
– Vertical concatenation
General
cyclo
– Returns the cyclo.Cyclo object at the given index in this multidimensional array
cyclotomic
– Constructs a cyclotomic array from an array of coefficients
data
– Returns the java array containing the flat data of this array
full
– Placeholder as cyclotomic arrays are always dense
toCellOfStrings
– Returns a multi-dimensional cell array of strings corresponding to this cyclotomic array
Involutions
conj
– Complex conjugation
ctranspose
– Complex conjugate transpose
inv
– Matrix inverse
transpose
– Transpose
uminus
– Unary minus
Shape
diag
– Diagonal matrices and diagonals of a matrix
ipermute
– Inverse permute array dimensions
permute
– Permute array dimensions
reshape
– Reshape array
Display
Binary operations
dot
– Vector dot product (incomplete)
eq
– Equality test, returns a multidimensional array
galois
– Action of the Galois group
isequal
– Equality test, returns a scalar
isequaln
– Equality test, returns a scalar
kron
–
minus
– Standard -
operator
mpower
– Matrix power
mrdivide
– Division
mtimes
– Matrix multiplication
ne
– (Non-)equality test
plus
– Standard +
operator
rdivide
– Pointwise /
operator
times
– Pointwise *
operator
Element-by-element computations
double
– Conversion to floating-point double
doubleApproximation
– Conversion to floating-point double with estimation of the error
hash
– Returns a multidimensional array of hash codes
sqrt
– Square root
Indexing
Standard MATLAB properties
imag
– Returns the imaginary part
isempty
–
isrational
– Returns which coefficients are rational
isreal
–
isscalar
–
isvector
–
iswhole
– Returns which coefficients are integers
length
– Length of vector
ndims
– Number of dimensions
numel
– Number of elements
real
– Returns the real part
size
– Size of array (incomplete)
Matrix decompositions
ldl
–
lu
– Returns the LU decomposition of this matrix
null
– Computes the null space of a cyclotomic matrix
rref
– Computes the row reduced echelon form
Contractions
Inherited elements
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
1D array of cyclotomic numbers, elements are stored as in array(:)
cyclo.Cyclo[]
Shape
integer(1,*)
Returns roots of unity
n (integer(*,*)
) – Root orders
The value exp(2i*pi/n)
Constructs the simplest rational approximation within an interval, for coefficients of a matrix
Example
>>> replab.cyclotomic.approximate(3.141592, 3.141593) % doctest: +cyclotomic
355/113
lowerBounds (double(...)
) – Interval lower bounds
upperBounds (double(...)
) – Interval upper bounds
The simplest rational approximation, coefficient by coefficient
Block diagonal concatenation of matrix input arguments
Compatible with MATLAB’s blkdiag
Complex conjugation
Fully compatible with MATLAB’s conj
Complex conjugate transpose
Fully compatible with MATLAB’s ctranspose
Returns the cyclo.Cyclo object at the given index in this multidimensional array
Arguments are integer indices, as passed to subsref
Constructs a cyclotomic array from an array of coefficients
array – Coefficients
Returns the java array containing the flat data of this array
Diagonal matrices and diagonals of a matrix
Fully compatible with MATLAB’s diag
Standard display method
Vector dot product (incomplete)
Only supports the case where both lhs
and rhs
are vectors, and does not accept a dim
argument.
Conversion to floating-point double
Conversion to floating-point double with estimation of the error
Equality test, returns a multidimensional array
Constructs the n x n
identity matrix (incomplete)
Does not support the syntax with two arguments.
n (integer
) – Matrix size
The constructed matrix
Find indices of nonzero elements
Compatible with MATLAB’s find
Constructs a cyclotomic matrix of rational numbers
Example
>>> replab.cyclotomic.fromRationals([1 1; 1 1], [2 3; 3 2]) % doctest: +cyclotomic
1/2 1/3
1/3 1/2
numerators (double(*,*)
) – Coefficient numerators
denominators (double(*,*)
) – Coefficient denominators
The constructed matrix
Placeholder as cyclotomic arrays are always dense
Action of the Galois group
Returns a multidimensional array of hash codes
Example
>>> hash(replab.cyclotomic.zeros(1)) == -1579025880 % doctest: +cyclotomic
1
Integer array of hash codes
integer(…)
Horizontal concatenation (incomplete)
Incomplete implementation: only works on vectors and matrices
Returns the imaginary part
Matrix inverse
Requires that the matrix is full rank
Inverse permute array dimensions
Fully compatible with MATLAB’s permute
Equality test, returns a scalar
Equality test, returns a scalar
Same as isequal as we do not have NaN
Returns which coefficients are rational
Returns which coefficients are integers
Length of vector
Equivalent to max(size(X))
if isempty(X)
is false, otherwise 0
.
Example
>>> length(replab.cyclotomic.zeros(10)) % doctest: +cyclotomic
10
Vector length
integer
Returns the LU decomposition of this matrix
The m x n
matrix must have m >= n
.
It returns triangular matrices L
, U
and a permutation vector p
such that L*U == self(:,p)
L (cyclotomic
(*,*)) – Lower triangular matrix
U (cyclotomic
(*,*)) – Upper triangular matrix
p (integer(1,*)) – Permutation vector
Standard -
operator
Matrix power
Division
Only supports the case where the right hand side is scalar
Matrix multiplication
Support both m x n
by n x p
matrix multiplication, and the case where one of the arguments is a scalar
Number of dimensions
Number of dimensions
integer
(Non-)equality test
Computes the null space of a cyclotomic matrix
Example
>>> M = replab.cyclotomic([1 3 0; -2 -6 0; 3 9 6]); % doctest: +cyclotomic
>>> null(M)'
-3 1 0
The matrix null space
Conversion to string (incomplete)
Only supports matrices or vectors.
Does not support format specifiers or a specified precision.
Possibly multiline string representation of the matrix
charstring
Number of elements
Number of elements
integer
Constructs a cyclotomic array filled with ones
The constructed matrix
Permute array dimensions
Fully compatible with MATLAB’s permute
Standard +
operator
Product of elements (incomplete)
Does not support arrays with more than two dimensions, and does not support extra options (type, nanflag).
Random cyclotomic matrix
maximalNumberOfTerms – Maximal number of terms
field – Whether to sample from real or complex cyclotomics
maximalOrder – Maximal root-of-unity order
maximalDenominator – Largest denominator for rational numbers
maximalAbsoluteValue – Approximate largest absolute value
integer
‘R’, ‘C’, ‘Q’
integer
integer
integer
Pointwise /
operator
Returns the real part
Reshape array
Fully compatible with MATLAB’s reshape
Computes the row reduced echelon form
The row reduced echelon form
Size of array (incomplete)
Incomplete implementation: only supports the forms s = size(array)
and s = size(array, i)
where
i
is an integer scalar.
Example
>>> size(replab.cyclotomic.eye(2)) % doctest: +cyclotomic
2 2
dim (integer, optional
) – Dimension(s) to get the size of
Size
integer or integer(1,*)
Constructs a 2D cyclotomic array using sparse matrix syntax (incomplete)
Only supports the five argument syntax
The constructed matrix
Square root
Requires that the argument contains rational coefficients, otherwise compatible with MATLAB’s sqrt
Returns the square root of a rational number
Example
>>> replab.cyclotomic.sqrtRational(2) % doctest: +cyclotomic
E(8)-E(8)^3
>>> replab.cyclotomic.sqrtRational(1,2)
E(8)/2-E(8)^3/2
num (integer
) – Numerator
den (integer, optional
) – Denominator, default value 1
The value sqrt(num/den)
Assignment
Compatible with MATLAB’s subsasgn
Indexing
Compatible with MATLAB’s subsref
Sum of elements (incomplete)
Does not support arrays with more than two dimensions, and does not support extra options (type, nanflag).
Pointwise *
operator
Returns a multi-dimensional cell array of strings corresponding to this cyclotomic array
Sum of diagonal elements
Fully compatible with MATLAB’s trace
Transpose
Fully compatible with MATLAB’s transpose
Unary minus
Vertical concatenation
Constructs a cyclotomic array filled with zeros
The constructed matrix
Quaternion matrix type
A quaternion matrix can be expressed using four real matrices A, B, C and D:
\(Q = A + B i + C j + D k\) where \(i^2 = j^2 = k^2 = i j k = -1\) and \(i j = k\), \(j k = i\) and \(k i = j\).
We choose to encode our quaternions using two matrices \(X = A + B i\) and \(Y = C + D i\), where we now identify \(i\) with the complex imaginary unit.
Thus \(Q = X + Y j\).
The class supports sparse components for efficiency.
Class members list
Properties
General
H
– Quaternion constructor
abs
– Computes the absolute value, array coefficient by coefficient
abs2
– Computes the square of the absolute value, array coefficient by coefficient
blkdiag
–
conj
–
decode
– Decodes the given complex matrix into a quaternion matrix
decompose
– Decomposes the first and second part from the given matrix, interpreted as a quaternion matrix
diag
–
disp
– Standard display method
encode
– Encodes the given matrix, interpreted as a quaternion, into a complex matrix
end
–
eps
– Computes the spacing of floating point numbers
eq
–
horzcat
–
i
– Quaternion unit i
inv
–
isscalar
–
j
– Quaternion unit j
k
– Quaternion unit k
kron
–
minus
–
mldivide
– Backslash or left matrix divide
mrdivide
– Slash or right matrix divide
mtimes
–
ne
–
norm
–
part1
– Returns the real part of the quaternion
parti
– Returns the i
part of the quaternion
partj
– Returns the j
part of the quaternion
partk
– Returns the k
part of the quaternion
plus
–
randn
– Returns a normally distributed quaternion multidimensional array
rdivide
–
real
–
sign
–
size
–
sqrt
– Quaternion element-by-element square root
subsasgn
–
subsref
–
times
–
toStringCell
– Computes a string representation of the elements of the array
trace
–
uminus
–
uplus
–
vertcat
–
Inherited elements
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
No documentation
First part
Second part
Quaternion constructor
Constructs a quaternion as:
`` Q = M1 + Mi * i + Mj * j + Mk * k `` where i
, j
, k
are the quaternion units.
Some matrices can be complex, in which case the complex imaginary unit is identified with i
.
M1 (double(d1,d2)
) – Must be provided
Mi (double(d1,d2) or []
) – Matrix to be multiplied by i
Mj (double(d1,d2) or []
) – Matrix to be multiplied by j
Mk (double(d1,d2) or []
) – Matrix to be multiplied by k
Computes the absolute value, array coefficient by coefficient
Magnitude of each quaternion coefficient
double
Computes the square of the absolute value, array coefficient by coefficient
Square of the magnitude of each quaternion coefficient
double
Decodes the given complex matrix into a quaternion matrix
Decomposes the first and second part from the given matrix, interpreted as a quaternion matrix
The result of this call is equivalent to tmp = replab.H(Q); X = tmp.X; Y = tmp.Y
, but it
avoids unnecessary construction of temporary objects.
Q (replab.H
or double multidimensional array) – Quaternion to decompose
X (double multidimensional array) – First part of the quaternion matrix
Y (double multidimensional array) – Second part of the quaternion matrix
Standard display method
Encodes the given matrix, interpreted as a quaternion, into a complex matrix
Uses the encoding of a quaternion q = a + b i + c j + d k
as [a + i*b, c + i*d; -c + i*d, a - i*b]
Q (H
) – Quaternion matrix
Complex matrix encoding the given quaternion matrix
double(*,*)
Computes the spacing of floating point numbers
Backslash or left matrix divide
Slash or right matrix divide
Returns the real part of the quaternion
Real part
double(…)
Returns the i
part of the quaternion
Part
double(…)
Returns the j
part of the quaternion
Part
double(…)
Returns the k
part of the quaternion
Part
double(…)
Returns a normally distributed quaternion multidimensional array
varargin – Arguments passed to randn
Quaternion multidimensional array
Quaternion element-by-element square root
See https://math.stackexchange.com/questions/382431/square-roots-of-quaternions
Computes a string representation of the elements of the array
String representation
cell(…) of charstring