+
    ‹°³jˆ"  ã                   óp   € ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
HtHtHtHt  ! R R]4      tR	# )
é    )Úpermutedims)ÚNumber)ÚS)ÚSymbol)Úsympify)ÚTensorÚTensExprÚTensAddÚTensMulc                   ó¤   a € ] tR t^	t o RtR t]R 4       t]R 4       t]	R 4       t
R tR tR tR	 tR
 tR t]R 4       t]R 4       tR tRtV tR# )ÚPartialDerivativea…	  
Partial derivative for tensor expressions.

Examples
========

>>> from sympy.tensor.tensor import TensorIndexType, TensorHead
>>> from sympy.tensor.toperators import PartialDerivative
>>> from sympy import symbols
>>> L = TensorIndexType("L")
>>> A = TensorHead("A", [L])
>>> B = TensorHead("B", [L])
>>> i, j, k = symbols("i j k")

>>> expr = PartialDerivative(A(i), A(j))
>>> expr
PartialDerivative(A(i), A(j))

The ``PartialDerivative`` object behaves like a tensorial expression:

>>> expr.get_indices()
[i, -j]

Notice that the deriving variables have opposite valence than the
printed one: ``A(j)`` is printed as covariant, but the index of the
derivative is actually contravariant, i.e. ``-j``.

Indices can be contracted:

>>> expr = PartialDerivative(A(i), A(i))
>>> expr
PartialDerivative(A(L_0), A(L_0))
>>> expr.get_indices()
[L_0, -L_0]

The method ``.get_indices()`` always returns all indices (even the
contracted ones). If only uncontracted indices are needed, call
``.get_free_indices()``:

>>> expr.get_free_indices()
[]

Nested partial derivatives are flattened:

>>> expr = PartialDerivative(PartialDerivative(A(i), A(j)), A(k))
>>> expr
PartialDerivative(A(i), A(j), A(k))
>>> expr.get_indices()
[i, -j, -k]

Replace a derivative with array values:

>>> from sympy.abc import x, y
>>> from sympy import sin, log
>>> compA = [sin(x), log(x)*y**3]
>>> compB = [x, y]
>>> expr = PartialDerivative(A(i), B(j))
>>> expr.replace_with_arrays({A(i): compA, B(i): compB})
[[cos(x), 0], [y**3/x, 3*y**2*log(x)]]

The returned array is indexed by `(i, -j)`.

Be careful that other SymPy modules put the indices of the deriving
variables before the indices of the derivand in the derivative result.
For example:

>>> expr.get_free_indices()
[i, -j]

>>> from sympy import Matrix, Array
>>> Matrix(compA).diff(Matrix(compB)).reshape(2, 2)
[[cos(x), y**3/x], [0, 3*y**2*log(x)]]
>>> Array(compA).diff(Array(compB))
[[cos(x), y**3/x], [0, 3*y**2*log(x)]]

These are the transpose of the result of ``PartialDerivative``,
as the matrix and the array modules put the index `-j` before `i` in the
derivative result. An array read with index order `(-j, i)` is indeed the
transpose of the same array read with index order `(i, -j)`. By specifying
the index order to ``.replace_with_arrays`` one can get a compatible
expression:

>>> expr.replace_with_arrays({A(i): compA, B(i): compB}, [-j, i])
[[cos(x), y**3/x], [0, 3*y**2*log(x)]]
c                ó   € \        V\        4      '       d    VP                  V,           pVP                  pV P	                  \        V4      V4      w  r4rV\        P                  ! V .VO5!  pWGn        WWn	        Wgn
        V# ©N)Ú
isinstancer   Ú	variablesÚexprÚ _contract_indices_for_derivativer   r	   Ú__new__Ú_indicesÚ_freeÚ_dum)Úclsr   r   ÚargsÚindicesÚfreeÚdumÚobjs   &&*     ÚX/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/tensor/toperators.pyr   ÚPartialDerivative.__new__`   sr   € ô �dÔ-×.Ò.ØŸ™¨Õ2ˆIØ—9‘9ˆDà#&×#GÑ#GÜˆd‹G�Yó$ Ñ ˆ�tô ×Ò˜sÐ* TÓ*ˆàŒØŒ	ØŒØˆ
ó    c                ó"   € \         P                  # r   )r   ÚOne©Úselfs   &r   ÚcoeffÚPartialDerivative.coeffq   s   € ä�u‰uˆr    c                ó   € V # r   © r#   s   &r   ÚnocoeffÚPartialDerivative.nocoeffu   s   € àˆr    c           
     óv  € . pV F…  p\        V\        4      '       dD   VP                  4       pTP                  TP	                  V Uu/ uF  qfV) bK  	  up4      4       K\  \        V\
        4      '       g   Kt  VP                  V4       K‡  	  \        P                  ! V.V,           R R7      w  rxrš\        ^\        V4      4       Fc  pWt,          p\        V\        4      '       g   K#  Wt,          P                  4       pWt,          P	                  V Uu/ uF  qfV) bK  	  up4      Wt&   Ke  	  WxWš3# u upi u upi )T)Úreplace_indices)
r   r   Úget_free_indicesÚappendÚxreplacer   r   Ú_tensMul_contract_indicesÚrangeÚlen)r   r   r   Úvariables_opposite_valenceÚiÚi_free_indicesÚkr   r   r   r   Úargs_iÚ	i_indicess   &&&          r   r   Ú2PartialDerivative._contract_indices_for_derivativey   s  € à%'Ð"ãˆAÜ˜!œV×$Ò$Ø!"×!3Ñ!3Ó!5�Ø*×1Ñ1ØŸ
™
±>Ó#B±>¨a¨ r¢E±>Ñ#BÓCöEä˜Aœv×&Ô&Ø*×1Ñ1°!Ö4ñ ô $+×#DÒ#DØˆFÐ/Õ/Àô$GÑ ˆ�tô �qœ#˜d›)Ö$ˆAØ•WˆFÜ˜&¤&×)Ô)Ø �G×4Ñ4Ó6�	Ø�'×*Ñ*¹9Ó+E¹9°a°¨rªE¹9Ñ+EÓF�“ñ	 %ð ˜dÐ'Ð'ùò $Cùò ,Fs   ÁD1ÄD6
c                óœ   € V P                  V P                  V P                  4      w  r#rEV P                  ! V!  pW6n        WFn        WVn        V# r   )r   r   r   Úfuncr   r   r   )r$   Úhintsr   r   r   r   r   s   &,     r   ÚdoitÚPartialDerivative.doit�   sF   € Ø#'×#HÑ#HÈÏÉÐTX×TbÑTbÓ#cÑ ˆ�tà�iŠi˜ÑˆØŒØŒ	ØŒàˆ
r    c           	     óÂ  € V P                  V P                  V P                  4      w  rr4V P                  ! V!  pW%n        W5n        WEn        TpV^ ,          P                  '       g   \        P                  # \        VP                  \        4      '       dk   VP                  P                  ! VP                  P                   Uu. uF/  pV P                  ! V.VP                  O5!  P                  4       NK1  	  up!  pV# \        VP                  \        4      '       Ed9   \        VP                  4      ^8X  dá   . p\!        VP                  P                  4      p	\#        \        V	4      4       F�  p
\        \%        Wš,          4      \&        4      '       d   K*  V P                  ! Wš,          .VP                  O5!  P                  4       pVP)                  \        V	RV
 V.,           Wš^,           R ,           !  4       K‘  	  \        P*                  ! V4      pV# VP                  pVP                   F"  pV P                  Wl4      P                  4       pK$  	  V# u upi )r   N)r   r   r   r;   r   r   r   Úfree_symbolsr   ÚZeror   r
   r   Ú_expand_partial_derivativer   r2   Úlistr1   r   r   r.   Úfromiter)r$   r   r   r   r   r   ÚresultÚaÚtermsÚmulargsÚindÚdÚvs   &            r   rB   Ú,PartialDerivative._expand_partial_derivativeš   sÝ  € Ø#'×#HÑ#HÈÏÉÐTX×TbÑTbÓ#cÑ ˆ�tà�iŠi˜ÑˆØŒØŒ	ØŒàˆà�A�w×#×#Ð#Ü—6‘6ˆMÜ˜Ÿ™¤'×*Ò*à—X‘X—]’]à#Ÿ[™[×-Ò-ó%/á-˜ð —I’I˜aÐ0 #§-¡-Ó0×KÑKÖMÙ-ñ%/ñ 0ˆFð8 ˆô3 ˜Ÿ™¤'×*Ó*ä�3—=‘=Ó! QÔ&à�Ü˜sŸx™xŸ}™}Ó-�Ü ¤ W£Ö.�CÜ%¤g¨g­lÓ&;¼V×DÔDð !ŸIšI g¥lÐC°S·]±]ÓC×^Ñ^Ó`˜ØŸ™¤W¨w°t¸¨}Ø23°õ05à18À½'¸Ð1Dõ0Eñ &Gö Hñ /ô !×)Ò)¨%Ó0�ð ˆð Ÿ™�ØŸœ�AØ!ŸY™Y vÓ1×LÑLÓN’Fñ 'ð ˆùò9%/s   Ã5Ic                ó   € V P                   pV P                   Fa  p\        V\        4      '       d   VP	                  V4      pK,  VP
                  '       d   VP                  V4      pKQ  \        P                  pKc  	  V# r   )	r   r   r   r	   Ú_eval_partial_derivativeÚ	_diff_wrtÚ_eval_derivativer   rA   )r$   rE   rK   s   &  r   Ú_perform_derivativeÚ%PartialDerivative._perform_derivativeÆ   s_   € Ø—‘ˆØ—”ˆAÜ˜&¤(×+Ò+Ø×8Ñ8¸Ó;’à—;—;�;Ø#×4Ñ4°QÓ7’FäŸV™V’Fñ  ð ˆr    c                ó   € V P                   # r   )r   r#   s   &r   Úget_indicesÚPartialDerivative.get_indicesÒ   s   € Ø�}‰}Ðr    c                ól   € \        V P                  R  R7      pV Uu. uF  q"^ ,          NK  	  up# u upi )c                 ó   € V ^,          # )é   r(   )Úxs   &r   Ú<lambda>Ú4PartialDerivative.get_free_indices.<locals>.<lambda>Ö   s   € °°!¶r    )Úkey)Úsortedr   )r$   r   r4   s   &  r   r-   Ú"PartialDerivative.get_free_indicesÕ   s.   € Ü�d—j‘j¡nÔ5ˆÙ"Ó#™d˜�!—�™dÑ#Ð#ùÒ#s   �1c                ó  € V P                   P                  V4      pVP                  4        UUu/ uF
  w  r4V) V) bK  	  pppV P                   Uu. uF  qfP                  V4      NK  	  ppV P                  ! V.VO5!  # u uppi u upi r   )r   r/   Úitemsr   r;   )r$   Úreplr   r6   rK   Úmirroredr4   r   s   &&      r   Ú_replace_indicesÚ"PartialDerivative._replace_indicesÙ   su   € Ø�y‰y×!Ñ! $Ó'ˆØ'+§z¡z¤|Ô4¡|™t˜q�Q�B˜˜’F¡|ˆÑ4Ø37·>²>ÓB±>¨a—Z‘Z Ö)±>ˆ	ÐBØ�yŠy˜Ð* 	Ó*Ð*ùó 5ùÚBs   ¯A?ÁBc                ó(   € V P                   ^ ,          # )r   ©r   r#   s   &r   r   ÚPartialDerivative.exprß   s   € à�y‰y˜�|Ðr    c                ó(   € V P                   R ,          # ):rX   NNrf   r#   s   &r   r   ÚPartialDerivative.variablesã   s   € à�y‰y˜�}Ðr    c           
     óä  € ^RI HpHp V P                  P	                  V4      w  rEV P
                   EF¤  pVP	                  V4      w  rxV U	u. uF  q™) NK  	  pp	\        V U	u. uF  q™P                  4       NK  	  up	!  w  r¨\        VP                  4      pV! WX4      p\        VP                  4      pWË,
          p\        T\        V4       U	u. uF  q™V,           NK  	  up	\        \        V4      4      ,           4      pVP                  4       pV^ ,          p^ .\        \        V4      4       U	u. uF  p	\        R4      NK  	  up	,           p\        V
4       F(  w  p	pWŸ^ &   V\!        V4      ;;,          V,          uu&   K*  	  V) V9   d9   VP#                  V) 4      pV! V^ V^,           34      pVP%                  V4       EK“  VP'                  V4       EK§  	  WE3# u up	i u up	i u up	i u up	i )rX   )Úderive_by_arrayÚtensorcontractionN)Úarrayrk   rl   r   Ú_extract_datar   ÚzipÚas_coeff_Mulr2   Úshaper   r1   rC   Ú
as_mutableÚsliceÚ	enumerateÚtupleÚindexÚpopr.   )r$   Úreplacement_dictrk   rl   r   rm   ÚvariableÚvar_indicesÚ	var_arrayr4   Úcoeff_arrayÚ
dim_beforeÚ	dim_afterÚdim_increaseÚvarindexÚcoeff_indexr%   Úposs   &&                r   rn   ÚPartialDerivative._extract_dataç   s±  € ß=ØŸ™×0Ñ0Ð1AÓB‰ˆØŸ�ˆHØ%-×%;Ñ%;Ð<LÓ%MÑ"ˆKÙ'2Ó3¡{ !›2¡{ˆKÐ3Ü%(ÁYÓ*OÁYÀ¯>©>Ö+;ÁYÑ*OÑ%PÑ"ˆKÜ˜UŸ[™[Ó)ˆJÙ# EÓ5ˆEÜ˜EŸK™KÓ(ˆIØ$Õ1ˆLÜ Ä%È
ÔBSÓ'TÑBS¸Q¨L×(8Ð(8ÑBSÑ'TÔW[Ô\aÐbnÓ\oÓWpÕ'pÓqˆEØ×$Ñ$Ó&ˆEØ" 1•~ˆHà˜#´e¼CÀ»LÔ6IÓ JÑ6I°¤ t¦Ñ6IÑ JÕJˆKÜ% kÖ2‘��5Ø!"˜A‘Ø”e˜KÓ(×)¨UÕ2Õ)ñ 3ð ˆy˜GÔ#Ø—m‘m X IÓ.�Ù)¨%°!°S¸µU°Ó<�Ø—‘˜C× à—‘˜x×(ñ+ 'ð, ˆ~Ðùò) 4ùÚ*Oùò
 (Uùò !Ks   ÁGÁ#G#
ÃG(Ä1G-r(   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úpropertyr%   r)   Úclassmethodr   r=   rB   rQ   rT   r-   rc   r   r   rn   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r   	   sž   ø‡ € ñTòlð" ñó ðð ñó ðð ñ(ó ð(ò,ò*òX
òò$ò+ð ñó ðð ñó ð÷ð r    r   N)Úsympyr   Úsympy.core.numbersr   Úsympy.core.singletonr   Úsympy.core.symbolr   Úsympy.core.sympifyr   Úsympy.tensor.tensorr   r	   r
   r   r   r(   r    r   Ú<module>r”      s(   ðÝ Ý %Ý "Ý $Ý &ß BÓ Bôw˜ö wr    