o
    §ƒðjö  ã                   @   s¾   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ de
d	efd
d„Zdee
ef d	efdd„Zde
d	efdd„Zde
d	dfdd„Zde
d	dfdd„ZdS )é    ©ÚEq)ÚExpr)ÚInteger)ÚBooleanÚAnd)Ú
MatrixExpr)Ú
ShapeError)ÚUnionÚargsÚreturnc                  G   sh   t dd„ | D ƒŽ \}}tg dd„ t |dd… |dd… ƒD ƒ¢dd„ t |dd… |dd… ƒD ƒ¢R Ž S )aõ  Return the symbolic condition how ``MatAdd``, ``HadamardProduct``
    makes sense.

    Parameters
    ==========

    args
        The list of arguments of matrices to be tested for.

    Examples
    ========

    >>> from sympy import MatrixSymbol, symbols
    >>> from sympy.matrices.expressions._shape import is_matadd_valid

    >>> m, n, p, q = symbols('m n p q')
    >>> A = MatrixSymbol('A', m, n)
    >>> B = MatrixSymbol('B', p, q)
    >>> is_matadd_valid(A, B)
    Eq(m, p) & Eq(n, q)
    c                 s   ó   � | ]}|j V  qd S ©N©Úshape©Ú.0Úarg© r   ú£/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/matrices/expressions/_shape.pyÚ	<genexpr>    ó   € z"is_matadd_valid.<locals>.<genexpr>c                 s   ó   � | ]
\}}t ||ƒV  qd S r   r   ©r   ÚiÚjr   r   r   r   "   ó   € Néÿÿÿÿé   c                 s   r   r   r   r   r   r   r   r   #   r   ©Úzipr   ©r   ÚrowsÚcolsr   r   r   Úis_matadd_valid
   s   "ÿ"þr$   c                  G   s>   t dd„ | D ƒŽ \}}tdd„ t |dd… |dd… ƒD ƒŽ S )aï  Return the symbolic condition how ``MatMul`` makes sense

    Parameters
    ==========

    args
        The list of arguments of matrices and scalar expressions to be tested
        for.

    Examples
    ========

    >>> from sympy import MatrixSymbol, symbols
    >>> from sympy.matrices.expressions._shape import is_matmul_valid

    >>> m, n, p, q = symbols('m n p q')
    >>> A = MatrixSymbol('A', m, n)
    >>> B = MatrixSymbol('B', p, q)
    >>> is_matmul_valid(A, B)
    Eq(n, p)
    c                 s   s    � | ]}t |tƒr|jV  qd S r   )Ú
isinstancer   r   r   r   r   r   r   =   s   € z"is_matmul_valid.<locals>.<genexpr>c                 s   r   r   r   r   r   r   r   r   >   r   Nr   r   r   r!   r   r   r   Úis_matmul_valid'   s   (r&   r   c                C   s   t | j| jƒS )a‡  Return the symbolic condition how the matrix is assumed to be square

    Parameters
    ==========

    arg
        The matrix to be tested for.

    Examples
    ========

    >>> from sympy import MatrixSymbol, symbols
    >>> from sympy.matrices.expressions._shape import is_square

    >>> m, n = symbols('m n')
    >>> A = MatrixSymbol('A', m, n)
    >>> is_square(A)
    Eq(m, n)
    )r   r"   r#   )r   r   r   r   Ú	is_squareA   s   r'   Nc                  G   sj   t dd„ | D ƒŽ \}}tttdd„ |ƒƒƒdkrtd|› �ƒ‚tttdd„ |ƒƒƒdkr3td|› �ƒ‚dS )	z:Validate matrix shape for addition only for integer valuesc                 s   r   r   r   )r   Úxr   r   r   r   Z   r   z*validate_matadd_integer.<locals>.<genexpr>c                 S   ó   t | ttfƒS r   ©r%   Úintr   ©r(   r   r   r   Ú<lambda>[   ó    z)validate_matadd_integer.<locals>.<lambda>r   z!Matrices have mismatching shape: c                 S   r)   r   r*   r,   r   r   r   r-   ]   r.   N)r    ÚlenÚsetÚfilterr	   r!   r   r   r   Úvalidate_matadd_integerX   s   ÿr2   c                  G   sf   t | dd… | dd… ƒD ]#\}}|j|j}}t|ttfƒr0t|ttfƒr0||kr0td||ƒ‚qdS )z@Validate matrix shape for multiplication only for integer valuesNr   r   zMatrices are not aligned)r    r#   r"   r%   r+   r   r	   )r   ÚAÚBr   r   r   r   r   Úvalidate_matmul_integera   s   "$€ýr5   )Úsympy.core.relationalr   Úsympy.core.exprr   Úsympy.core.numbersr   Úsympy.logic.boolalgr   r   Ú"sympy.matrices.expressions.matexprr   Úsympy.matrices.exceptionsr	   Útypingr
   r$   r&   r'   r2   r5   r   r   r   r   Ú<module>   s    	