qp.math.binary_is_independent

binary_is_independent(vector, basis)[source]

Check whether a binary vector, i.e., a bitstring, is linearly independent (over \(\mathbb{Z}_2\)) of a basis of binary vectors, given as column vectors of a matrix.

Parameters:
  • vector (np.ndarray) – Binary vector to check, of shape (r,). Multiple vectors may be checked at once by passing them as the columns of an array of shape (r, k).

  • basis (np.ndarray) – Basis of binary vectors against which vector is checked. It should have shape (r, m) and rank min(r, m). I.e., the columns of basis all need to be linearly independent.

Returns:

Whether vector is linearly independent of basis over \(\mathbb{Z}_2\). This is always a boolean array; for a single vector, it is of shape (), for k vectors it is of shape (k,).

Return type:

np.ndarray

Warning

This function is currently not compatible with JAX.

Example

Consider the basis consisting of the two columns [1, 0, 1] and [0, 1, 0]:

>>> basis = np.array([[1, 0], [0, 1], [1, 0]])

The vector [0, 0, 1] is not in the span of this basis:

>>> qp.math.binary_is_independent(np.array([0, 0, 1]), basis)
np.True_

We may check multiple vectors at once by stacking them as columns. Here we check [0, 0, 1], [1, 1, 1] and [1, 0, 1], of which only the first is independent of basis:

>>> vectors = np.array([[0, 1, 1], [0, 1, 0], [1, 1, 1]])
>>> qp.math.binary_is_independent(vectors, basis)
array([ True, False, False])