Many typical matrix operations can also be performed on gate matrices, such as obtaining entries, number of rows and columns, transpose, and vertical or horizontal concatenation.
i1 : R = RR[x,y] o1 = R o1 : PolynomialRing |
i2 : M = gateMatrix basis(3, R)
-- warning: experimental computation over inexact field begun
-- results not reliable (one warning given per session)
3 2 2 3
o2 = {{x , x y, x*y , y }}
o2 : GateMatrix
|
i3 : numcols M, numrows M o3 = (4, 1) o3 : Sequence |
Rows or entries can be accessed with _ or #:
i4 : M_0
3 2 2 3
o4 = {x , x y, x*y , y }
o4 : List
|
i5 : M#0
3 2 2 3
o5 = {x , x y, x*y , y }
o5 : List
|
i6 : M#0#0
3
o6 = x
o6 : InputGate
|
i7 : entries M
3 2 2 3
o7 = {{x , x y, x*y , y }}
o7 : List
|
i8 : N = gateMatrix {delete(x^2*y^2, flatten entries basis(4, R))}
4 3 3 4
o8 = {{x , x y, x*y , y }}
o8 : GateMatrix
|
i9 : M | N
3 2 2 3 4 3 3 4
o9 = {{x , x y, x*y , y , x , x y, x*y , y }}
o9 : GateMatrix
|
i10 : M || N
3 2 2 3 4 3 3 4
o10 = {{x , x y, x*y , y }, {x , x y, x*y , y }}
o10 : GateMatrix
|
The determinant of a gate matrix is a DetGate:
i11 : P = transpose M*M
3 3 3 2 3 2 3 3 2 3 2 2 2 2 2 3
o11 = {{((x * x )), ((x * x y)), ((x * x*y )), ((x * y ))}, {((x y * x )), ((x y * x y)), ((x y * x*y )), ((x y * y ))},
---------------------------------------------------------------------------------------------------------------------------
2 3 2 2 2 2 2 3 3 3 3 2 3 2 3 3
{((x*y * x )), ((x*y * x y)), ((x*y * x*y )), ((x*y * y ))}, {((y * x )), ((y * x y)), ((y * x*y )), ((y * y ))}}
o11 : GateMatrix
|
i12 : det P
o12 = det| 3 3 3 2 3 2 3 3 |
| ((x * x )) ((x * x y)) ((x * x*y )) ((x * y )) |
| 2 3 2 2 2 2 2 3 |
| ((x y * x )) ((x y * x y)) ((x y * x*y )) ((x y * y )) |
| 2 3 2 2 2 2 2 3 |
| ((x*y * x )) ((x*y * x y)) ((x*y * x*y )) ((x*y * y )) |
| 3 3 3 2 3 2 3 3 |
| ((y * x )) ((y * x y)) ((y * x*y )) ((y * y )) |
o12 : DetGate
|
The native method substitute has also been overloaded to work with gate matrices: the input should be a list of options of the form "A => B" where A is an InputGate and B is a Gate; and the output is another GateMatrix.