o
    8Vam                     @   sn   d Z ddlmZ edddd  dd Zd	d
 Zdd Zdd Zdd Zdd Z	dd Z
dd Zdd ZdS )z[
Fundamental arithmetic of dense matrices. The dense matrix is stored
as a list of lists.

    )SymPyDeprecationWarningZ
densearithi1  z1.1)ZfeatureZissueZdeprecated_since_versionc                    s    fddt | |D S )a  
    Adds matrices row-wise.

    Examples
    ========

    >>> from sympy.matrices.densearith import add
    >>> from sympy import ZZ
    >>> e = [
    ... [ZZ(12), ZZ(78)],
    ... [ZZ(56), ZZ(79)]]
    >>> f = [
    ... [ZZ(1), ZZ(2)],
    ... [ZZ(3), ZZ(4)]]
    >>> g = [
    ... [ZZ.zero, ZZ.zero],
    ... [ZZ.zero, ZZ.zero]]
    >>> add(e, f, ZZ)
    [[13, 80], [59, 83]]
    >>> add(f, g, ZZ)
    [[1, 2], [3, 4]]

    See Also
    ========

    addrow
    c                    s   g | ]
\}}t || qS  )addrow).0row1row2Kr   ;/usr/lib/python3/dist-packages/sympy/matrices/densearith.py
<listcomp>*   s    zadd.<locals>.<listcomp>zipmatlist1matlist2r	   r   r   r
   add   s   r   c                 C   s   dd t | |D S )ac  
    Adds two rows of a matrix element-wise.

    Examples
    ========

    >>> from sympy.matrices.densearith import addrow
    >>> from sympy import ZZ

    >>> a = [ZZ(12), ZZ(34), ZZ(56)]
    >>> b = [ZZ(14), ZZ(56), ZZ(63)]
    >>> c = [ZZ(0), ZZ(0), ZZ(0)]

    >>> addrow(a, b, ZZ)
    [26, 90, 119]
    >>> addrow(b, c, ZZ)
    [14, 56, 63]

    c                 S   s   g | ]\}}|| qS r   r   )r   Zelement1Zelement2r   r   r
   r   @       zaddrow.<locals>.<listcomp>r   )r   r   r	   r   r   r
   r   ,   s   r   c                 C   s   t | t|||S )a,  
    Subtracts two matrices by first negating the second matrix and
    then adding it to first matrix.

    Examples
    ========

    >>> from sympy.matrices.densearith import sub
    >>> from sympy import ZZ
    >>> e = [
    ... [ZZ(12), ZZ(78)],
    ... [ZZ(56), ZZ(79)]]
    >>> f = [
    ... [ZZ(1), ZZ(2)],
    ... [ZZ(3), ZZ(4)]]
    >>> g = [
    ... [ZZ.zero, ZZ.zero],
    ... [ZZ.zero, ZZ.zero]]
    >>> sub(e, f, ZZ)
    [[11, 76], [53, 75]]
    >>> sub(f, g, ZZ)
    [[1, 2], [3, 4]]

    See Also
    ========

    negate
    negaterow
    )r   negater   r   r   r
   subC   s   r   c                        fdd| D S )a  
    Negates the elements of a matrix row-wise.

    Examples
    ========

    >>> from sympy.matrices.densearith import negate
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(2), ZZ(3)],
    ... [ZZ(4), ZZ(5)]]
    >>> b = [
    ... [ZZ(0), ZZ(0)],
    ... [ZZ(0), ZZ(0)]]
    >>> negate(a, ZZ)
    [[-2, -3], [-4, -5]]
    >>> negate(b, ZZ)
    [[0, 0], [0, 0]]

    See Also
    ========

    negaterow
    c                    s   g | ]}t | qS r   )	negaterowr   rowr   r   r
   r   }   s    znegate.<locals>.<listcomp>r   )matlistr	   r   r   r
   r   d   s   r   c                 C   s   dd | D S )a,  
    Negates a row element-wise.

    Examples
    ========

    >>> from sympy.matrices.densearith import negaterow
    >>> from sympy import ZZ
    >>> a = [ZZ(2), ZZ(3), ZZ(4)]
    >>> b = [ZZ(0), ZZ(0), ZZ(0)]
    >>> negaterow(a, ZZ)
    [-2, -3, -4]
    >>> negaterow(b, ZZ)
    [0, 0, 0]

    c                 S   s   g | ]}| qS r   r   r   elementr   r   r
   r      s    znegaterow.<locals>.<listcomp>r   )r   r	   r   r   r
   r      s   r   c                    s>   dd t | D }g }| D ]| fdd|D  q|S )a  
    Multiplies two matrices by multiplying each row with each column at
    a time. The multiplication of row and column is done with mulrowcol.

    Firstly, the second matrix is converted from a list of rows to a
    list of columns using zip and then multiplication is done.

    Examples
    ========

    >>> from sympy.matrices.densearith import mulmatmat
    >>> from sympy import ZZ
    >>> from sympy.matrices.densetools import eye
    >>> a = [
    ... [ZZ(3), ZZ(4)],
    ... [ZZ(5), ZZ(6)]]
    >>> b = [
    ... [ZZ(1), ZZ(2)],
    ... [ZZ(7), ZZ(8)]]
    >>> c = eye(2, ZZ)
    >>> mulmatmat(a, b, ZZ)
    [[31, 38], [47, 58]]
    >>> mulmatmat(a, c, ZZ)
    [[3, 4], [5, 6]]

    See Also
    ========

    mulrowcol
    c                 S   s   g | ]}t |qS r   )list)r   ir   r   r
   r          zmulmatmat.<locals>.<listcomp>c                    s   g | ]}t | qS r   )	mulrowcol)r   colr	   r   r   r
   r      r   )r   append)r   r   r	   Zmatcolresultr   r!   r
   	mulmatmat   s
   r$   c                    s    fdd| D S )a  
    Performs scaler matrix multiplication one row at at time. The row-scaler
    multiplication is done using mulrowscaler.

    Examples
    ========

    >>> from sympy import ZZ
    >>> from sympy.matrices.densearith import mulmatscaler
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> mulmatscaler(a, ZZ(1), ZZ)
    [[3, 7, 4], [2, 4, 5], [6, 2, 3]]

    See Also
    ========

    mulscalerrow
    c                    s   g | ]}t | qS r   )mulrowscalerr   r	   scalerr   r
   r      r   z mulmatscaler.<locals>.<listcomp>r   )r   r'   r	   r   r&   r
   mulmatscaler   s   r(   c                    r   )a  
    Performs the scaler-row multiplication element-wise.

    Examples
    ========

    >>> from sympy import ZZ
    >>> from sympy.matrices.densearith import mulrowscaler
    >>> a = [ZZ(3), ZZ(4), ZZ(5)]
    >>> mulrowscaler(a, 2, ZZ)
    [6, 8, 10]

    c                    s   g | ]} | qS r   r   r   r'   r   r
   r      r   z mulrowscaler.<locals>.<listcomp>r   )r   r'   r	   r   r)   r
   r%      s   r%   c                 C   s0   |j }tt| D ]}|| | ||  7 }q	|S )aJ  
    Multiplies two lists representing row and column element-wise.

    Gotcha: Here the column is represented as a list contrary to the norm
    where it is represented as a list of one element lists. The reason is
    that the theoretically correct approach is too expensive. This problem
    is expected to be removed later as we have a good data structure to
    facilitate column operations.

    Examples
    ========

    >>> from sympy.matrices.densearith import mulrowcol
    >>> from sympy import ZZ

    >>> a = [ZZ(2), ZZ(4), ZZ(6)]
    >>> mulrowcol(a, a, ZZ)
    56

    )Zzerorangelen)r   r    r	   r#   r   r   r   r
   r      s   r   N)__doc__Zsympy.utilities.exceptionsr   warnr   r   r   r   r   r$   r(   r%   r   r   r   r   r
   <module>   s"    !&