The BMat8 class
Fast boolean matrices of dimension up to 8 x 8.
Instance of this class represent 8 x 8 matrices over the boolean semiring. The
functions for these small matrices are more optimised than the generic
functions for boolean matrices. Note that all BMat8
are represented
internally as an 8 x 8 matrix; any entries not defined by the user are taken to
be 0
. This does not affect the results of any calculations.
There are numerous functions for computing things about BMat8
objects in
the submodule bmat8
.
>>> from libsemigroups_pybind11 import BMat8
>>> x = BMat8([[0, 1], [1, 0]])
>>> x[1, 1] = 1
>>> x
BMat8([[0, 1],
[1, 1]])
>>> x[0, 1]
True
>>> x[1, 1]
True
>>> x * x
BMat8([[1, 1],
[1, 1]])
>>> x < x * x
True
>>> x *= x
>>> x
BMat8([[1, 1],
[1, 1]])
>>> x.to_int()
13889101250810609664
>>> bin(x.to_int())
'0b1100000011000000000000000000000000000000000000000000000000000000'
>>> x == BMat8([[1, 1, 0], [1, 1, 0], [0, 0, 0]]) # All BMat8's are really 8x8!
True
>>> y = BMat8([[1, 0, 1], [0, 1, 0], [0, 0, 0]])
>>> y[0] # The first row
[True, False, True, False, False, False, False, False]
>>> x + y
BMat8([[1, 1, 1],
[1, 1, 0],
[0, 0, 0]])
>>> x += y
>>> x
BMat8([[1, 1, 1],
[1, 1, 0],
[0, 0, 0]])
>>> 1 * x == x
True
>>> x * 0
BMat8(0)
BMat8
objects can be used with the following algorithms in
libsemigroups_pybind11
Contents
Fast boolean matrices of dimension up to 8 x 8. |
|
|
Copy a BMat8. |
|
Returns the degree of self. |
|
Swaps self with that. |
|
Returns the integer representation of a |
Full API
- class BMat8
- __init__(*args, **kwargs)
Overloaded function.
- __init__(self: BMat8) None
Default constructor.
There is no guarantee about the contents of the matrix constructed.
- Complexity:
Constant.
- __init__(self: BMat8, val: int) None
Construct from
int
.This constructor initializes a
BMat8
to have rows equal to the 8 chunks, of 8 bits each, of the binary representation ofmat
.- Parameters:
val (int) – the integer representation of the matrix being constructed.
- Complexity:
Constant.
- __init__(self: BMat8, rows: list[list[bool]]) None
Construct from list of rows.
This constructor initializes a matrix where the rows of the matrix are the lists in rows.
- Parameters:
rows (list[list[bool]]) – the list of rows of the matrix being constructed.
- Raises:
LibsemigroupsError – if rows has 0 rows.
LibsemigroupsError – if rows has more than 8 rows.
LibsemigroupsError – if the rows of rows are not all of the same length.
- Complexity:
Constant.
- degree(self: BMat8) int
Returns the degree of self.
This function always returns
8
.- Returns:
The degree of the matrisx,
8
.- Return type:
- swap(self: BMat8, that: BMat8) None
Swaps self with that.
This function swaps the values of self and that.
>>> from libsemigroups_pybind11 import BMat8 >>> x = BMat8([[0, 1], [1, 0]]) >>> y = BMat8([[1, 1], [0, 0]]) >>> BMat8.swap(x,y) >>> x BMat8([[1, 1], [0, 0]]) >>> y BMat8([[0, 1], [1, 0]])
- to_int(self: BMat8) int
Returns the integer representation of a
BMat8
.Returns a non-negative integer obtained by interpreting an 8 x 8
BMat8
as a sequence of 64 bits (reading rows left to right, from top to bottom) and then realising this sequence as an unsigned int.- Returns:
The integer value of the matrix.
- Return type:
- Complexity:
Constant.
>>> from libsemigroups_pybind11 import BMat8 >>> x = BMat8([[0, 1], [1, 0]]) >>> x.to_int() 4647714815446351872 >>> bin(x.to_int()) '0b100000010000000000000000000000000000000000000000000000000000000'