o
    9ô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©ÚsimplifyÚwith_pivotsc                    ó   g | ]}ˆ   |¡‘qS © )Úcol©Ú.0Úi©ÚMr   úi/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/sympy/matrices/subspaces.pyÚ
<listcomp>#   ó    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 ](}ˆ jgˆ j }ˆ j||< tˆƒD ]\}}	||	  |||f 8  < q+| |¡ q‡ 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 | ]}|ˆ v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    )ÚrrefÚranger   ÚzeroÚoneÚ	enumerateÚappend)
r   r   r   r   Ú	free_varsÚbasisZfree_varÚvecÚpiv_rowÚ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                    r   r   )Úrowr	   ©r   r   r   r   f   r   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�\}}|r2|jt|ƒk r2tdƒ‚g }	t|jƒD ]}
|rI| |dd…|
f jƒ}n
| |dd…|
f ƒ}|	 	|¡ q9|	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)
Údecompositionsr+   ÚrowsÚhstackr   r'   Ú
ValueErrorr   ÚTr   )Úclsr)   r*   Úvecsr+   Zall_row_vecsr   ÚQÚRÚretr   r   r   r   r   Ú_orthogonalizei   s    0
r8   N)F)Ú	utilitiesr   r   r$   r(   r8   r   r   r   r   Ú<module>   s
    
"
-