+
    ‹°³jæ/  ã                   ó˜   € ^ RI t ^ RIt^ RIHtHt ^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt  ! R R	]4      tR
 t ! R R]4      tR# )é    N)Ú_sympifyÚsympify)ÚExpr)ÚBasicÚTuple)ÚImmutableDenseNDimArray)ÚSymbol)ÚIntegerc                   óô   a € ] tR t^
t o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       t]R	 4       t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V tR# )ÚArrayComprehensionaÏ  
Generate a list comprehension.

Explanation
===========

If there is a symbolic dimension, for example, say [i for i in range(1, N)] where
N is a Symbol, then the expression will not be expanded to an array. Otherwise,
calling the doit() function will launch the expansion.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a
ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.doit()
[[11, 12, 13], [21, 22, 23], [31, 32, 33], [41, 42, 43]]
>>> b = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, k))
>>> b.doit()
ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, k))
c                ó   € \         ;QJ d    R  V 4       F  '       g   K   RM	  RM! R  V 4       4      '       d   \        R4      h\        V4      .pVP                  V P	                  W4      4       \
        P                  ! V .VO5/ VB pVP                  R,          Vn        V P                  VP                  4      Vn
        \        VP                  4      Vn        V P                  VP                  4      Vn        V# )c              3   óR   "  € T F  p\        V4      ^8g  ;'       g    Rx € K  	  R# 5i©é   N©Úlen©Ú.0Úls   & Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/tensor/array/array_comprehension.pyÚ	<genexpr>Ú-ArrayComprehension.__new__.<locals>.<genexpr>%   ó#   é € Ð4©G qŒs�1‹v˜‰{×"Ð"˜dÔ"«Gùó   ‚'œ'TFúKArrayComprehension requires values lower and upper bound for the expression:é   NN)ÚanyÚ
ValueErrorr   ÚextendÚ_check_limits_validityr   Ú__new__Ú_argsÚ_limitsÚ_calculate_shape_from_limitsÚ_shaper   Ú_rankÚ_calculate_loop_sizeÚ
_loop_size©ÚclsÚfunctionÚsymbolsÚassumptionsÚarglistÚobjs   &&*,  r   r!   ÚArrayComprehension.__new__$   sÀ   € ß‹3Ñ4©GÓ4�3�3Š3Ñ4©GÓ4×4Ò4Üð 4ó 5ð 5ä˜8Ó$Ð%ˆØ�‰�s×1Ñ1°(ÓDÔEÜ�mŠm˜CÐ9 'Ò9¨[Ñ9ˆØ—i‘i •mˆŒØ×5Ñ5°c·k±kÓBˆŒ
Ü˜Ÿ
™
“OˆŒ	Ø×1Ñ1°#·*±*Ó=ˆŒØˆ
ó    c                ó(   € V P                   ^ ,          # )zùThe function applied across limits.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j = symbols('i j')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.function
10*i + j
)r"   ©Úselfs   &r   r+   ÚArrayComprehension.function1   s   € ð �z‰z˜!�}Ðr1   c                ó   € V P                   # )a%  
The list of limits that will be applied while expanding the array.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j = symbols('i j')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.limits
((i, 1, 4), (j, 1, 3))
©r#   r3   s   &r   ÚlimitsÚArrayComprehension.limitsA   s   € ð �|‰|Ðr1   c                óì   € V P                   P                  pV P                   FM  w  r#pVP                  V4       VP                  P	                  VP                  4      pVP	                  V4      pKO  	  V# )a±  
The set of the free_symbols in the array.
Variables appeared in the bounds are supposed to be excluded
from the free symbol set.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.free_symbols
set()
>>> b = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, k+3))
>>> b.free_symbols
{k}
)r+   Úfree_symbolsr#   ÚdiscardÚunion)r4   Úexpr_free_symÚvarÚinfÚsupÚcurr_free_symss   &     r   r;   ÚArrayComprehension.free_symbolsR   sg   € ð( Ÿ™×2Ñ2ˆØ!Ÿ\œ\‰MˆC�cØ×!Ñ! #Ô&Ø ×-Ñ-×3Ñ3°C×4DÑ4DÓEˆNØ)×/Ñ/°Ó?ŠMñ *ð Ðr1   c                óP   € V P                    Uu. uF  q^ ,          NK  	  up# u upi )a  The tuples of the variables in the limits.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.variables
[i, j]
r7   ©r4   r   s   & r   Ú	variablesÚArrayComprehension.variablesm   s$   € ð #ŸlšlÓ+™l˜�!—�™lÑ+Ð+ùÒ+s   �#c                óv   € V P                    Uu. uF  p\        V4      ^8w  g   K  V^ ,          NK   	  up# u upi )z—The list of dummy variables.

Note
====

Note that all variables are dummy variables since a limit without
lower bound or upper bound is not accepted.
)r#   r   rE   s   & r   Úbound_symbolsÚ ArrayComprehension.bound_symbols}   s2   € ð #ŸlšlÓ:™l˜¬c°!«f¸©k”��!—�™lÑ:Ð:ùÒ:s   �6¦6c                ó   € V P                   # )a½  
The shape of the expanded array, which may have symbols.

Note
====

Both the lower and the upper bounds are included while
calculating the shape.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.shape
(4, 3)
>>> b = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, k+3))
>>> b.shape
(4, k + 3)
)r%   r3   s   &r   ÚshapeÚArrayComprehension.shape‰   s   € ð0 �{‰{Ðr1   c                ó€   € V P                    F-  w  rp\        W#4      P                  \        4      '       g   K,   R# 	  R# )aˆ  
Test if the array is shape-numeric which means there is no symbolic
dimension.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.is_shape_numeric
True
>>> b = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, k+3))
>>> b.is_shape_numeric
False
FT)r#   r   Úatomsr	   )r4   Ú_r@   rA   s   &   r   Úis_shape_numericÚ#ArrayComprehension.is_shape_numeric£   s3   € ð&  Ÿ<œ<‰KˆA�CÜ�S‹×$Ñ$¤V×,Ô,Úñ (ñ r1   c                ó   € V P                   # )zñThe rank of the expanded array.

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.rank()
2
)r&   r3   s   &r   ÚrankÚArrayComprehension.rank»   s   € ð �z‰zÐr1   c                óh   € V P                   P                  '       d   \        R4      hV P                   # )ad  
The length of the expanded array which means the number
of elements in the array.

Raises
======

ValueError : When the length of the array is symbolic

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j = symbols('i j')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> len(a)
12
z Symbolic length is not supported)r(   r;   r   r3   s   &r   Ú__len__ÚArrayComprehension.__len__Ê   s*   € ð( �?‰?×'×'Ð'ÜÐ?Ó@Ð@Ø�‰Ðr1   c                óæ  € . pV Fè  w  rEp\        V4      p\        V4      p\        V\        4      '       d   \        V!  pM\        V4      pVP	                  \        WEV4      4       \
        ;QJ d    R  WV3 4       F  '       g   K   RM	  RM! R  WV3 4       4      '       d   \        R4      hWV8„  R8X  d   \        R4      hWEP                  9   g   WFP                  9   g   Kß  \        R4      h	  V# )c              3   ó²   "  € T FM  p\        V\        4      '       * ;'       g,    VP                  \        \        4      VP                  4       8g  x € KO  	  R # 5i©N)Ú
isinstancer   rO   r	   r
   )r   Úis   & r   r   Ú<ArrayComprehension._check_limits_validity.<locals>.<genexpr>ð   sC   é € ð UÙISÀAô # 1¤dÓ+Ô+×UÐU°·±¼ÄÓ0HÈAÏGÉGËIÑ0UÔUÛISùs
   ‚ A£4ATFzABounds should be an Expression(combination of Integer and Symbol)z-Lower bound should be inferior to upper boundz)Variable should not be part of its bounds)	r   r\   Úlistr   Úappendr   Ú	TypeErrorr   r;   )r*   r+   r8   Ú
new_limitsr?   r@   rA   s   &&&    r   r    Ú)ArrayComprehension._check_limits_validityâ   så   € ð ˆ
Û#‰MˆC�cÜ˜3“-ˆCÜ˜3“-ˆCô ˜#œt×$Ò$Ü˜S‘k‘ä˜s“m�Ø×Ñœe C¨cÓ2Ô3ß‹sñ UØJMÉóU�s�sŠsñ UØJMÉóU÷ Uò UäÐ cÓdÐdØ‘	˜dÔ"Ü Ð!PÓQÐQØ×&Ñ&Ô&¨#×1AÑ1AÖ*AÜ Ð!LÓMÐMñ! $ð" Ðr1   c           
     ón   € \        V UUUu. uF  w  r#qDV,
          ^,           NK  	  uppp4      # u upppi ©r   )Útuple)r*   r8   rP   r@   rA   s   &&   r   r$   Ú/ArrayComprehension._calculate_shape_from_limitsù   s+   € ä±vÕ>±v©¨°˜C•i !—m�m±vÓ>Ó?Ð?ùÔ>s   Œ0c                ó@   € V'       g   ^ # ^pV F  pW#,          pK  	  V# ©r   © )r*   rL   Ú	loop_sizer   s   &&  r   r'   Ú'ArrayComprehension._calculate_loop_sizeý   s&   € çÙØˆ	ÛˆAØ!�ŠIñ ð Ðr1   c                óJ   € V P                   '       g   V # V P                  4       # r[   )rQ   Ú_expand_array)r4   Úhintss   &,r   ÚdoitÚArrayComprehension.doit  s"   € Ø×$×$Ð$ØˆKà×!Ñ!Ó#Ð#r1   c                ó  € . p\         P                  ! V P                   UUUu. uF  w  r#p\        W4^,           4      NK  	  uppp!   F#  pVP	                  V P                  V4      4       K%  	  \        WP                  4      # u upppi re   )Ú	itertoolsÚproductr#   Úranger`   Ú_get_elementr   rL   )r4   Úresr?   r@   rA   Úvaluess   &     r   rn   Ú ArrayComprehension._expand_array  sz   € ØˆÜ×'Ò'à+/¯<ª<õ*9á+7ñ -:¨C°cô +0°¸µUÖ*;á+7ó*9ô :ˆFð �J‰J�t×(Ñ(¨Ó0Ö1ñ:ô
 ' s¯J©JÓ7Ð7ùô*9s   £Bc                ó~   € V P                   p\        V P                  V4       F  w  r4VP                  W44      pK  	  V# r[   )r+   ÚziprF   Úsubs)r4   rx   Útempr?   Úvals   &&   r   rv   ÚArrayComprehension._get_element  s5   € Ø�}‰}ˆÜ˜DŸN™N¨FÖ3‰HˆCØ—9‘9˜SÓ&ŠDñ 4àˆr1   c                óx   € V P                   '       d   V P                  4       P                  4       # \        R4      h)am  Transform the expanded array to a list.

Raises
======

ValueError : When there is a symbolic dimension

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j = symbols('i j')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.tolist()
[[11, 12, 13], [21, 22, 23], [31, 32, 33], [41, 42, 43]]
z-A symbolic array cannot be expanded to a list)rQ   rn   Útolistr   r3   s   &r   r�   ÚArrayComprehension.tolist  s4   € ð$ × × Ð Ø×%Ñ%Ó'×.Ñ.Ó0Ð0äÐHÓIÐIr1   c                óÈ   € ^ RI Hp V P                  '       g   \        R4      hV P                  ^8w  d   \        R4      hV! V P                  4       P                  4       4      # )a½  Transform the expanded array to a matrix.

Raises
======

ValueError : When there is a symbolic dimension
ValueError : When the rank of the expanded array is not equal to 2

Examples
========

>>> from sympy.tensor.array import ArrayComprehension
>>> from sympy import symbols
>>> i, j = symbols('i j')
>>> a = ArrayComprehension(10*i + j, (i, 1, 4), (j, 1, 3))
>>> a.tomatrix()
Matrix([
[11, 12, 13],
[21, 22, 23],
[31, 32, 33],
[41, 42, 43]])
)ÚMatrixz/A symbolic array cannot be expanded to a matrixzDimensions must be of size of 2)Úsympy.matricesr„   rQ   r   r&   rn   Útomatrix)r4   r„   s   & r   r†   ÚArrayComprehension.tomatrix3  sS   € õ. 	*à×$×$Ð$ÜÐNÓOÐOØ�:‰:˜Œ?ÜÐ>Ó?Ð?á�d×(Ñ(Ó*×3Ñ3Ó5Ó6Ð6r1   rj   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r!   Úpropertyr+   r8   r;   rF   rI   rL   rQ   rT   rW   Úclassmethodr    r$   r'   rp   rn   rv   r�   r†   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r   
   s  ø‡ € ñò2ð ñó ðð ñó ðð  ñó ðð4 ñ,ó ð,ð ñ	;ó ð	;ð ñó ðð2 ñó ðò.òð0 ñó ðð, ñ@ó ð@ð ñó ðò$ò8òòJ÷.7ð 7r1   r   c                 ót   € R  p\        V \        V4      4      ;'       d    V P                  VP                  8H  # )c                  ó   € ^ # ri   rj   rj   r1   r   Ú<lambda>ÚisLambda.<locals>.<lambda>U  s   € ‘Qr1   )r\   Útyperˆ   )ÚvÚLAMBDAs   & r   ÚisLambdarš   T  s-   € Ù€FÜ�aœ˜f›Ó&×HÐH¨1¯:©:¸¿¹Ñ+HÐHr1   c                   ó@   a € ] tR tRt o RtR t]R 4       tR tRt	V t
R# )ÚArrayComprehensionMapiX  a  
A subclass of ArrayComprehension dedicated to map external function lambda.

Notes
=====

Only the lambda function is considered.
At most one argument in lambda function is accepted in order to avoid ambiguity
in value assignment.

Examples
========

>>> from sympy.tensor.array import ArrayComprehensionMap
>>> from sympy import symbols
>>> i, j, k = symbols('i j k')
>>> a = ArrayComprehensionMap(lambda: 1, (i, 1, 4))
>>> a.doit()
[1, 1, 1, 1]
>>> b = ArrayComprehensionMap(lambda a: a+1, (j, 1, 4))
>>> b.doit()
[2, 3, 4, 5]

c                ó   € \         ;QJ d    R  V 4       F  '       g   K   RM	  RM! R  V 4       4      '       d   \        R4      h\        V4      '       g   \        R4      hV P                  W4      p\        P
                  ! V .VO5/ VB pVP                  Vn        V P                  VP                  4      Vn	        \        VP                  4      Vn        V P                  VP                  4      Vn        Wn        V# )c              3   óR   "  € T F  p\        V4      ^8g  ;'       g    Rx € K  	  R# 5ir   r   r   s   & r   r   Ú0ArrayComprehensionMap.__new__.<locals>.<genexpr>r  r   r   TFr   zData type not supported)r   r   rš   r    r   r!   r"   r#   r$   r%   r   r&   r'   r(   Ú_lambdar)   s   &&*,  r   r!   ÚArrayComprehensionMap.__new__q  sÆ   € ß‹3Ñ4©GÓ4�3�3Š3Ñ4©GÓ4×4Ò4Üð 4ó 5ð 5ô ˜×!Ò!ÜÐ6Ó7Ð7à×,Ñ,¨XÓ?ˆÜ�mŠm˜CÐ9 'Ò9¨[Ñ9ˆØ—i‘iˆŒØ×5Ñ5°c·k±kÓBˆŒ
Ü˜Ÿ
™
“OˆŒ	Ø×1Ñ1°#·*±*Ó=ˆŒØŒØˆ
r1   c                ó,   a €  ! V 3R  lR\         4      pV# )c                   ó.   <a € ] tR tRt o V3R ltRtV tR# )Ú%ArrayComprehensionMap.func.<locals>._i„  c                ó6   <€ \        SP                  .VO5/ VB # r[   )rœ   r    )r*   ÚargsÚkwargsr4   s   &*,€r   r!   Ú-ArrayComprehensionMap.func.<locals>._.__new__…  s   ø€ Ü,¨T¯\©\ÐK¸DÒKÀFÑKÐKr1   rj   N)rˆ   r‰   rŠ   r‹   r!   r�   r�   )r’   r4   s   @€r   rP   r¤   „  s   ù‡ € ÷Ló Lr1   rP   )rœ   )r4   rP   s   f r   ÚfuncÚArrayComprehensionMap.func‚  s   ø€ ÷	LÔ%ô 	Lð ˆr1   c                ó   € V P                   pV P                   P                  P                  ^ 8X  d
   V! 4       pV# V P                   P                  P                  ^8X  d   V! \        P                  ! R V4      4      pV# )r   c                 ó   € W,          # r[   rj   )ÚaÚbs   &&r   r•   Ú4ArrayComprehensionMap._get_element.<locals>.<lambda>Ž  s   € °a¶cr1   )r    Ú__code__Úco_argcountÚ	functoolsÚreduce)r4   rx   r}   s   && r   rv   Ú"ArrayComprehensionMap._get_element‰  sh   € Ø�|‰|ˆØ�<‰<× Ñ ×,Ñ,°Ô1Ù“6ˆDð ˆð �\‰\×"Ñ"×.Ñ.°!Ô3Ùœ	×(Ò(Ñ)9¸6ÓBÓCˆDØˆr1   rj   N)rˆ   r‰   rŠ   r‹   rŒ   r!   r�   r©   rv   r�   r�   r‘   s   @r   rœ   rœ   X  s-   ø‡ € ñò0ð" ñó ð÷ð r1   rœ   )r²   rs   Úsympy.core.sympifyr   r   Úsympy.core.exprr   Ú
sympy.corer   r   Úsympy.tensor.arrayr   Úsympy.core.symbolr	   Úsympy.core.numbersr
   r   rš   rœ   rj   r1   r   Ú<module>r»      s<   ðß ß 0Ý  ß #Ý 6Ý $Ý &ôG7˜ô G7òT
Iô7Ð.ö 7r1   