+
    i/                         ^ 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   & d/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/tensor/array/array_comprehension.py	<genexpr>-ArrayComprehension.__new__.<locals>.<genexpr>%   #     4Gqs1v{""d"G   ''TFKArrayComprehension 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4G43334G444 4 5 58$%s11(DEmmC9'9[9iim55ckkB


O	11#**=
    c                (    V P                   ^ ,          # )zThe 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     zz!}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!\\MCc!!#& --33C4D4DEN)//?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$     #ll+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 )zThe 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     #ll: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    &  <<KACS$$V,, ( r1   c                    V P                   # )zThe 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     zz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ISA #1d++UU0HAGGI0UUISs
    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     
#MCc3-C3-C #t$$SksmeCc23s UJMUsss UJMU U U cdd	d" !PQQ&&&#1A1A*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Ci!mmv>??>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 -:Cc +0U*;+7*9 :F JJt((01:
 'sJJ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    }}DNNF3HC99S&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H1::+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4G43334G444 4 5 5 !!677,,X?mmC9'9[9ii55ckk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\\KDKF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    acr1   )r   __code__co_argcount	functoolsreduce)r4   rx   r}   s   && r   rv   "ArrayComprehensionMap._get_element  sh    ||<<  ,,16D  \\""..!3	(()96BCD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7T
I7. 7r1   