U
    ZÊ¹j±  ã                   @   sB   d dl mZ ddd„Zdefdd„Zddd„Zddd	œd
d„ZdS )é   )Ú_iszeroFc                    s$   ˆ j |dd�\}}‡ fdd„|D ƒS )a±  Returns a list of vectors (Matrix objects) that span columnspace of ``M``

    Examples
    ========

    >>> from sympy import Matrix
    >>> M = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
    >>> M
    Matrix([
    [ 1,  3, 0],
    [-2, -6, 0],
    [ 3,  9, 6]])
    >>> M.columnspace()
    [Matrix([
    [ 1],
    [-2],
    [ 3]]), Matrix([
    [0],
    [0],
    [6]])]

    See Also
    ========

    nullspace
    rowspace
    T©ÚsimplifyZwith_pivotsc                    s   g | ]}ˆ   |¡‘qS © )Úcol©Ú.0Úi©ÚMr   úW/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/matrices/subspaces.pyÚ
<listcomp>#   s     z _columnspace.<locals>.<listcomp>)Úechelon_form)r   r   ÚreducedÚpivotsr   r
   r   Ú_columnspace   s    r   c           
         s–   ˆ j ||d�\}‰‡fdd„tˆ jƒD ƒ}g }|D ]P}ˆ jgˆ j }ˆ j||< tˆƒD ] \}}	||	  |||f 8  < qV| |¡ q2‡ fdd„|D ƒS )a‡  Returns list of vectors (Matrix objects) that span nullspace of ``M``

    Examples
    ========

    >>> from sympy import Matrix
    >>> M = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
    >>> M
    Matrix([
    [ 1,  3, 0],
    [-2, -6, 0],
    [ 3,  9, 6]])
    >>> M.nullspace()
    [Matrix([
    [-3],
    [ 1],
    [ 0]])]

    See Also
    ========

    columnspace
    rowspace
    )Ú
iszerofuncr   c                    s   g | ]}|ˆ kr|‘qS r   r   r   )r   r   r   r   B   s      z_nullspace.<locals>.<listcomp>c                    s   g | ]}ˆ   ˆ jd |¡‘qS )r   )Ú_newÚcols)r   Úbr
   r   r   r   P   s     )ZrrefÚranger   ÚzeroÚoneÚ	enumerateÚappend)
r   r   r   r   Z	free_varsZbasisZfree_varÚvecZpiv_rowZpiv_colr   )r   r   r   Ú
_nullspace&   s    
r   c                    s,   | j |dd�\‰ }‡ fdd„tt|ƒƒD ƒS )aD  Returns a list of vectors that span the row space of ``M``.

    Examples
    ========

    >>> from sympy import Matrix
    >>> M = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
    >>> M
    Matrix([
    [ 1,  3, 0],
    [-2, -6, 0],
    [ 3,  9, 6]])
    >>> M.rowspace()
    [Matrix([[1, 3, 0]]), Matrix([[0, 0, 6]])]
    Tr   c                    s   g | ]}ˆ   |¡‘qS r   )Úrowr   ©r   r   r   r   f   s     z_rowspace.<locals>.<listcomp>)r   r   Úlen)r   r   r   r   r   r   Ú	_rowspaceS   s    r    )Ú	normalizeÚ	rankcheckc                G   s¶   ddl m} |sg S |d jdk}dd„ |D ƒ}| j|Ž }|||d�\}}|rd|jt|ƒk rdtdƒ‚g }	t|jƒD ]>}
|r’| |dd…|
f jƒ}n| |dd…|
f ƒ}|	 	|¡ qr|	S )	a´  Apply the Gram-Schmidt orthogonalization procedure
    to vectors supplied in ``vecs``.

    Parameters
    ==========

    vecs
        vectors to be made orthogonal

    normalize : bool
        If ``True``, return an orthonormal basis.

    rankcheck : bool
        If ``True``, the computation does not stop when encountering
        linearly dependent vectors.

        If ``False``, it will raise ``ValueError`` when any zero
        or linearly dependent vectors are found.

    Returns
    =======

    list
        List of orthogonal (or orthonormal) basis vectors.

    Examples
    ========

    >>> from sympy import I, Matrix
    >>> v = [Matrix([1, I]), Matrix([1, -I])]
    >>> Matrix.orthogonalize(*v)
    [Matrix([
    [1],
    [I]]), Matrix([
    [ 1],
    [-I]])]

    See Also
    ========

    MatrixBase.QRdecomposition

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
    r   )Ú_QRdecomposition_optionalé    c                 S   s   g | ]}|  ¡ ‘qS r   )r   )r   Úxr   r   r   r       s     z"_orthogonalize.<locals>.<listcomp>)r!   z0GramSchmidt: vector set not linearly independentN)
Zdecompositionsr#   ÚrowsZhstackr   r   Ú
ValueErrorr   ÚTr   )Úclsr!   r"   Zvecsr#   Zall_row_vecsr   ÚQÚRÚretr	   r   r   r   r   Ú_orthogonalizei   s     0
r-   N)F)F)Z	utilitiesr   r   r   r    r-   r   r   r   r   Ú<module>   s   
"-
