Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding check for linear independence. #324

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
toqito.matrix\_props.is\_linearly\_independent
==============================================

.. currentmodule:: toqito.matrix_props

.. autofunction:: is_linearly_independent
6 changes: 6 additions & 0 deletions docs/_autosummary/toqito.matrix_props.is_totally_positive.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
toqito.matrix\_props.is\_totally\_positive
==========================================

.. currentmodule:: toqito.matrix_props

.. autofunction:: is_totally_positive
6 changes: 6 additions & 0 deletions docs/_autosummary/toqito.states.bb84.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
toqito.states.bb84
==================

.. currentmodule:: toqito.states

.. autofunction:: bb84
6 changes: 6 additions & 0 deletions docs/_autosummary/toqito.states.mutually_unbiased_basis.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
toqito.states.mutually\_unbiased\_basis
=======================================

.. currentmodule:: toqito.states

.. autofunction:: mutually_unbiased_basis
6 changes: 6 additions & 0 deletions docs/_autosummary/toqito.states.trine.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
toqito.states.trine
===================

.. currentmodule:: toqito.states

.. autofunction:: trine
9 changes: 9 additions & 0 deletions docs/articles.bib
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,15 @@ @misc{WikiInnerProd

}


@misc{WikiLinearIndependence,
author = "Wikipedia",
title = "Linear independence",
howpublished = {https://en.wikipedia.org/wiki/Linear_independence}

}


@misc{WikiNeg,
author = "Wikipedia",
title = "Negativity",
Expand Down
2 changes: 2 additions & 0 deletions docs/matrices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Properties of Matrices and Vectors
toqito.matrix_props.is_hermitian
toqito.matrix_props.is_idempotent
toqito.matrix_props.is_identity
toqito.matrix_props.is_linearly_independent
toqito.matrix_props.is_normal
toqito.matrix_props.is_orthonormal
toqito.matrix_props.is_permutation
Expand All @@ -63,6 +64,7 @@ Properties of Matrices and Vectors
toqito.matrix_props.is_projection
toqito.matrix_props.is_square
toqito.matrix_props.is_symmetric
toqito.matrix_props.is_totally_positive
toqito.matrix_props.is_unitary
toqito.matrix_props.kp_norm
toqito.matrix_props.majorizes
Expand Down
4 changes: 4 additions & 0 deletions docs/states.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Properties of Quantum States
toqito.state_props.entanglement_of_formation
toqito.state_props.has_symmetric_extension
toqito.state_props.in_separable_ball
toqito.state_props.is_antidistinguishable
toqito.state_props.is_ensemble
toqito.state_props.is_mixed
toqito.state_props.is_mutually_orthogonal
Expand All @@ -93,6 +94,7 @@ Quantum States
:toctree: _autosummary

toqito.states.basis
toqito.states.bb84
toqito.states.bell
toqito.states.brauer
toqito.states.breuer
Expand All @@ -105,7 +107,9 @@ Quantum States
toqito.states.isotropic
toqito.states.max_entangled
toqito.states.max_mixed
toqito.states.mutually_unbiased_basis
toqito.states.singlet
toqito.states.tile
toqito.states.trine
toqito.states.w_state
toqito.states.werner
4 changes: 2 additions & 2 deletions toqito/matrix_ops/vectors_to_gram_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def vectors_to_gram_matrix(vectors: list[np.ndarray]) -> np.ndarray:

Examples
========
# Example with real vectors:
>>> # Example with real vectors:
>>> vectors = [np.array([1, 2]), np.array([3, 4])]
>>> gram_matrix = vectors_to_gram_matrix(vectors)
>>> gram_matrix
array([[ 5., 11.],
[11., 25.]])

# Example with complex vectors:
>>> # Example with complex vectors:
>>> vectors = [np.array([1+1j, 2+2j]), np.array([3+3j, 4+4j])]
>>> gram_matrix = vectors_to_gram_matrix(vectors)
>>> gram_matrix
Expand Down
1 change: 1 addition & 0 deletions toqito/matrix_props/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
from toqito.matrix_props.trace_norm import trace_norm
from toqito.matrix_props.is_diagonally_dominant import is_diagonally_dominant
from toqito.matrix_props.is_totally_positive import is_totally_positive
from toqito.matrix_props.is_linearly_independent import is_linearly_independent
44 changes: 44 additions & 0 deletions toqito/matrix_props/is_linearly_independent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Is linearly independent."""
import numpy as np


def is_linearly_independent(vectors: list[np.ndarray]) -> bool:
r"""Check if set of vectors are linearly independent :cite:`WikiLinearIndependence`.

Examples
==========

The following vectors are an example of a linearly independent set of vectors in :math:`\mathbb{R}^3`.

.. math::
\begin{pmatrix}
1 \\ 0 \\ 1
\end{pmatrix}, \quad
\begin{pmatrix}
1 \\ 1 \\ 0
\end{pmatrix}, \quad \text{and} \quad
\begin{pmatrix}
0 \\ 0 \\ 1
\end{pmatrix}

We can see that these are linearly independent:

>>> import numpy as np
>>> from toqito.matrix_props import is_linearly_independent
>>>
>>> v_1 = np.array([[1], [0], [1]])
>>> v_2 = np.array([[1], [1], [0]])
>>> v_3 = np.array([[0], [0], [1]])
>>> is_linearly_independent([v_1, v_2, v_3])
True

References
==========
.. bibliography::
:filter: docname in docnames

:param vectors: Vectors to check the linear independence of.
:return: Return :code:`True` if vectors are linearly independent :code:`False` otherwise.
"""
# Check if the rank of the matrix equals the number of vectors.
return np.linalg.matrix_rank(np.column_stack(vectors)) == len(vectors)
2 changes: 1 addition & 1 deletion toqito/matrix_props/is_totally_positive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def is_totally_positive(mat: np.ndarray, tol: float = 1e-6, sub_sizes: list | No

Examples
========

Consider the matrix

.. math::
\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}

To determine if this matrix is totally positive, we need to check the positivity of all of its minors. The 1x1
minors are simply the individual entries of the matrix. For :math:`X`, these are

Expand Down
14 changes: 14 additions & 0 deletions toqito/matrix_props/tests/test_is_linearly_independent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test is_linearly_independent."""
import numpy as np
import pytest

from toqito.matrix_props import is_linearly_independent


@pytest.mark.parametrize("vectors, expected_result", [
([np.array([[1], [0], [1]]), np.array([[1], [1], [0]]), np.array([[0], [0], [1]])], True),
([np.array([[0], [1], [2]]), np.array([[1], [2], [3]]), np.array([[3], [5], [7]])], False),
])
def test_is_linearly_independent(vectors, expected_result):
"""Test for linear independence/dependence of vectors."""
np.testing.assert_equal(is_linearly_independent(vectors), expected_result)
2 changes: 1 addition & 1 deletion toqito/state_opt/tests/test_ppt_distinguishability.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_ppt_distinguishability_four_bell_states():

The resource state is defined by

..math::
.. math::
|\tau_{\epsilon} \rangle = \sqrt{\frac{1+\epsilon}{2}} +
|0\rangle | 0\rangle +
\sqrt{\frac{1-\epsilon}{2}} |1 \rangle |1 \rangle
Expand Down
4 changes: 2 additions & 2 deletions toqito/states/mutually_unbiased_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def mutually_unbiased_basis(dim: int) -> list[np.ndarray]:

References
==========
.. [WikiMUB] Wikipedia: Mutually unbiased bases
https://en.wikipedia.org/wiki/Mutually_unbiased_bases
.. bibliography::
:filter: docname in docnames

:param dim: The dimension of the mutually unbiased bases to produce.
:return: The set of mutually unbiased bases of dimension :code:`dim` (if known).
Expand Down