B
    [  ใ               @   sz   d Z ddlm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.

้    )ฺrange)ฺSymPyDeprecationWarningZ
densearithi1  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   ๚8lib/python3.7/site-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   A   s    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   ฺnegate)r   r   r	   r   r   r
   ฺsubD   s    r   c                s    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   ฺrow)r	   r   r
   r   ~   s    znegate.<locals>.<listcomp>r   )ฺmatlistr	   r   )r	   r
   r   e   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                sB   dd t | D }g }x&| D ]|  fdd|D ก qW |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   ด   s    zmulmatmat.<locals>.<listcomp>c                s   g | ]}t | qS r   )ฺ	mulrowcol)r   ฺcol)r	   r   r   r
   r   ท   s    )r   ฺappend)r   r   r	   Zmatcolฺresultr   )r	   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   )ฺmulrowscaler)r   r   )r	   ฺscalerr   r
   r   ั   s    z mulmatscaler.<locals>.<listcomp>r   )r   r   r	   r   )r	   r   r
   ฺmulmatscalerป   s    r   c                s    fdd| D S )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   โ   s    z mulrowscaler.<locals>.<listcomp>r   )r   r   r	   r   )r   r
   r   ิ   s    r   c             C   s4   |j }x(tt| D ]}|| | ||  7 }qW |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zeror   ฺlen)r   r   r	   r   r   r   r   r
   r   ๅ   s    r   N)ฺ__doc__Zsympy.core.compatibilityr   Zsympy.utilities.exceptionsr   ฺwarnr   r   r   r   r   r   r   r   r   r   r   r   r
   ฺ<module>   s   !&