qml.math.binary_solve_linear_system¶
- binary_solve_linear_system(A, b)[source]¶
Solve the linear system of equations \(Ax=b\) over the Booleans/\(\mathbb{Z}_2\), where \(A\) is assumed to be regular, i.e., non-singular. The implementation is based on Gaussian elimination to bring the augmented matrix \((A|b)\) into (reduced) row echelon form via
binary_finite_reduced_row_echelon().- Parameters:
A (np.ndarray) – Square matrix of the linear system of equations with binary entries.
b (np.ndarray) – Binary coefficient vector with same length as
A.
- Returns:
Binary solution vector with same length as
Aandb.- Return type:
np.ndarray
Warning
This function is currently not compatible with JAX.
Example
Consider a simple regular Boolean matrix
Aand a coefficient vectorb:>>> A = np.array([ ... [1, 0, 0], ... [0, 1, 1], ... [1, 0, 1] ... ]) >>> b = np.array([1, 1, 1])
Then we can solve the system
A@x=bforxover \(\mathbb{Z}_2\):>>> x = qml.math.binary_solve_linear_system(A, b) >>> print(x) [1 1 0]
Internally, this is done with the Gauss-Jordan elimination of the extended matrix
(A | b). Indeed, we can verify thatA @ x = b(over \(\mathbb{Z}_2\)):>>> print(np.allclose((A @ x) % 2, b)) True