+
    i                         ^ RI Ht ^ RIHt ^ RIHtHtHt ^ RIH	t	 ^ RI
Ht  ! R R]4      t ! R R	]4      t ! R
 R]4      tR tR# )    )_sympify)
MatrixExpr)SEqGe)Mul)KroneckerDeltac                   ^   a  ] tR t^	t o Rt]! R 4      t]! R 4      t]R 4       tR t	Rt
V tR# )DiagonalMatrixa  DiagonalMatrix(M) will create a matrix expression that
behaves as though all off-diagonal elements,
`M[i, j]` where `i != j`, are zero.

Examples
========

>>> from sympy import MatrixSymbol, DiagonalMatrix, Symbol
>>> n = Symbol('n', integer=True)
>>> m = Symbol('m', integer=True)
>>> D = DiagonalMatrix(MatrixSymbol('x', 2, 3))
>>> D[1, 2]
0
>>> D[1, 1]
x[1, 1]

The length of the diagonal -- the lesser of the two dimensions of `M` --
is accessed through the `diagonal_length` property:

>>> D.diagonal_length
2
>>> DiagonalMatrix(MatrixSymbol('x', n + 1, n)).diagonal_length
n

When one of the dimensions is symbolic the other will be treated as
though it is smaller:

>>> tall = DiagonalMatrix(MatrixSymbol('x', n, 3))
>>> tall.diagonal_length
3
>>> tall[10, 1]
0

When the size of the diagonal is not known, a value of None will
be returned:

>>> DiagonalMatrix(MatrixSymbol('x', n, m)).diagonal_length is None
True

c                (    V P                   ^ ,          # r   argsselfs   &ڃ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/matrices/expressions/diagonal.py<lambda>DiagonalMatrix.<lambda>2       		!    c                .    V P                   P                  # N)argshaper   s   &r   r   r   4   s    $((..r   c                x   V P                   w  rVP                  '       d    VP                  '       d   \        W4      pV# VP                  '       d   VP                  '       g   TpV# VP                  '       d   VP                  '       g   TpV# W8X  d   TpV#  \        W4      pV#   \         d    R p T# i ; ir   )r   
is_Integermin	TypeErrorr   rcms   &   r   diagonal_lengthDiagonalMatrix.diagonal_length6   s    zz<<<ALLLA	A  \\\!,,,A  \\\!,,,A  VA 	I   s   B( (B98B9c                   V P                   eo   \        WP                   4      \        P                  J d   \        P                  # \        W P                   4      \        P                  J d   \        P                  # \        W4      pV\        P                  J d   V P                  W3,          # V\        P                  J d   \        P                  # V P                  W3,          \        W4      ,          # r   )	r#   r   r   trueZeror   r   falser	   )r   ijkwargseqs   &&&, r   _entryDiagonalMatrix._entryH   s    +!))*aff4vvA++,6vvX<88AD>!177]66Mxx~nQ222r    N__name__
__module____qualname____firstlineno____doc__propertyr   r   r#   r-   __static_attributes____classdictcell____classdict__s   @r   r   r   	   s?     'P ,
-C01E "3 3r   r   c                   \   a  ] tR t^Vt o Rt]! R 4      t]R 4       t]R 4       tR t	Rt
V tR# )
DiagonalOfa  DiagonalOf(M) will create a matrix expression that
is equivalent to the diagonal of `M`, represented as
a single column matrix.

Examples
========

>>> from sympy import MatrixSymbol, DiagonalOf, Symbol
>>> n = Symbol('n', integer=True)
>>> m = Symbol('m', integer=True)
>>> x = MatrixSymbol('x', 2, 3)
>>> diag = DiagonalOf(x)
>>> diag.shape
(2, 1)

The diagonal can be addressed like a matrix or vector and will
return the corresponding element of the original matrix:

>>> diag[1, 0] == diag[1] == x[1, 1]
True

The length of the diagonal -- the lesser of the two dimensions of `M` --
is accessed through the `diagonal_length` property:

>>> diag.diagonal_length
2
>>> DiagonalOf(MatrixSymbol('x', n + 1, n)).diagonal_length
n

When only one of the dimensions is symbolic the other will be
treated as though it is smaller:

>>> dtall = DiagonalOf(MatrixSymbol('x', n, 3))
>>> dtall.diagonal_length
3

When the size of the diagonal is not known, a value of None will
be returned:

>>> DiagonalOf(MatrixSymbol('x', n, m)).diagonal_length is None
True

c                (    V P                   ^ ,          # r   r   r   s   &r   r   DiagonalOf.<lambda>   r   r   c                   V P                   P                  w  rVP                  '       d   VP                  '       d   \        W4      pMcVP                  '       d   VP                  '       g   TpM<VP                  '       d   VP                  '       g   TpMW8X  d   TpM \        W4      pV\
        P                  3#   \         d    R p L!i ; ir   )r   r   r   r   r   r   Oner   s   &   r   r   DiagonalOf.shape   s    xx~~<<<ALLLA	A\\\!,,,A\\\!,,,AVAI !%%x  s   !B> >CCc                (    V P                   ^ ,          # r   )r   r   s   &r   r#   DiagonalOf.diagonal_length   s    zz!}r   c                <    V P                   P                  ! W3/ VB # r   )r   r-   )r   r)   r*   r+   s   &&&,r   r-   DiagonalOf._entry   s    xxq.v..r   r/   Nr0   r9   s   @r   r<   r<   V   sH     *V ,
-C "  / /r   r<   c                   R   a  ] tR t^t o RtR t]R 4       tR tR t	R t
R tRtV tR	# )

DiagMatrixz'
Turn a vector into a diagonal matrix.
c                
   \        V4      p\        P                  ! W4      pVP                  pV^ ,          ^8X  d
   V^,          MV^ ,          pVP                  ^ ,          ^8w  d	   RVn        MRVn        WD3Vn        Wn        V# )r   TF)r   r   __new__r   	_iscolumn_shape_vector)clsvectorobjr   dims   &&   r   rI   DiagMatrix.__new__   so    &!  -(a-eAhU1X<<?a CM!CMZ

r   c                    V P                   # r   )rK   r   s   &r   r   DiagMatrix.shape   s    {{r   c                    V P                   '       d    V P                  P                  ! V^ 3/ VB pMV P                  P                  ! ^ V3/ VB pW8w  d   V\        W4      ,          pV# r   )rJ   rL   r-   r	   )r   r)   r*   r+   results   &&&, r   r-   DiagMatrix._entry   sZ    >>>\\((A88F\\((A88F6nQ**Fr   c                    V # r   r/   r   s   &r   _eval_transposeDiagMatrix._eval_transpose   s    r   c                \    ^ RI Hp V! \        V P                  P	                  4       4      !  # )r   )diag)sympy.matrices.denser[   listrL   as_explicit)r   r[   s   & r   r^   DiagMatrix.as_explicit   s"    -T$,,224566r   c                L   ^ RI HpHp ^ RIHp ^ RIHp ^ RIHp ^ RI	H
p V P                  pV! VP                  V4      4      '       d   V# \        W4      '       d\   V! \        VP                  4      4      p	\!        V	P                  ^ ,          4       F  p
W,          WV
3&   K  	  \#        V4      ! V	4      # VP$                  '       d   VP&                   Uu. uF  qP(                  '       g   K  VNK  	  ppVP&                   Uu. uF  qV9  g   K  VNK  	  ppV'       dR   \*        P,                  ! V4      \/        VP-                  V4      P1                  4       4      P1                  4       ,          # \        W4      '       d   VP2                  p\/        V4      # u upi u upi )r   )askQ)MatMul)	Transpose)eye)
MatrixBase)sympy.assumptionsra   rb   !sympy.matrices.expressions.matmulrc   $sympy.matrices.expressions.transposerd   r\   re   sympy.matrices.matrixbaserf   rL   diagonal
isinstancemaxr   rangetype	is_MatMulr   	is_Matrixr   fromiterrG   doitr   )r   hintsra   rb   rc   rd   re   rf   rN   retr)   r   matricesscalarss   &,            r   rs   DiagMatrix.doit   s,   ,<B,8qzz&!""Mf))c&,,'(C399Q<("IqD	 )<$$'-{{D{mm{HD&,kkIks5HsskGI||G,Z8Q8V8V8X-Y-^-^-```f((ZZF&!! EIs   F0FF!F!r/   N)r1   r2   r3   r4   r5   rI   r6   r   r-   rX   r^   rs   r7   r8   r9   s   @r   rG   rG      s<       7" "r   rG   c                 4    \        V 4      P                  4       # r   )rG   rs   )rN   s   &r   diagonalize_vectorrz      s    f""$$r   N)sympy.core.sympifyr   sympy.matrices.expressionsr   
sympy.corer   r   r   sympy.core.mulr   (sympy.functions.special.tensor_functionsr	   r   r<   rG   rz   r/   r   r   <module>r      sG    ' 1      CJ3Z J3ZD/ D/N;" ;"|%r   