
    R jg                     6   S SK r S SKrS SKrS SKrS SKJr  S SKJrJrJ	r	  S SK
JrJr  S SKrS SKJr  S SKJr  S SKJr  S SKJr  S S	KJrJrJr  S S
KJr  S SKJrJr  S SKJr  S SK J!r!  S SK"J#r#  S SK$J%r%  S SK&J'r'  SSK(J)r)J*r*  \(       a  S SKJ+r+  \	" S\S9r,\" S5      r-/ SQr.S\R$                  S\/4S jr0S\\\-   /\,4   S\\\-   /\,\Rb                  -  4   4S jr2S\/S-  S\/S-  S\/S-  4S jr3S \Rh                  S!\Rh                  S\Rh                  4S" jr5 " S# S$\Rl                  5      r7 " S% S&\Rl                  5      r8 " S' S(\Rl                  5      r9 " S) S*\Rl                  5      r: " S+ S,\Rl                  5      r; " S- S.\75      r< " S/ S0\Rl                  5      r= " S1 S2\Rl                  5      r> " S3 S4\Rl                  5      r? " S5 S6\Rl                  5      r@ " S7 S8\Rl                  5      rA " S9 S:\\5      rB " S; S<\B\5      rC " S= S>\B\5      rDS? rES@ rF " SA SB\Rl                  5      rG " SC SD\Rl                  5      rH " SE SF\Rl                  5      rI " SG SH\Rl                  5      rJ " SI SJ\Rl                  5      rK " SK SL\Rl                  5      rL " SM SN\Rl                  5      rM " SO SP\Rl                  5      rN " SQ SR\Rl                  5      rO " SS ST\Rl                  5      rP " SU SV\Rl                  5      rQSW rR\R" SX5      rS\R" SY5      rT\R" SZ5      rU\R" S[5      rV\R" S\5      rW\R" S]5      rX\R" S^5      rY\R" S_5      rZ\R" S`5      r[\R" Sa5      r\\R" Sb5      r]\R" Sc5      r^\R" Sd5      r_\R" Se5      r`Sf ra\a" SgSh5      rb\a" SiSj5      rc\a" SkSl5      rdg)m    N)Callable)SupportsFloatTYPE_CHECKINGTypeVar)TypeVarTupleUnpack)Ssympify)Expr)Application)_torf	fuzzy_andfuzzy_or)equal_valued)	LatticeOpShortCircuit)ordered)walk)
PRECEDENCE)sift)TorchVersion   )int_oois_infinite)Iterable_T)bound_Ts)FloorDivModularIndexingWhere	PythonModModCleanDiv	CeilToInt
FloorToIntCeilDiv
IntTrueDivFloatTrueDivLShiftRShift!IsNonOverlappingAndDenseIndicatorTruncToFloat
TruncToInt
RoundToIntRoundDecimalToFloatFloatPowPowByNaturalIdentityexprreturnc                 d   [        U [        R                  5      =(       a    U R                  =(       a}    [	        U R
                  5      S:H  =(       a^    U R
                  S   R                  =(       a>    U R
                  S   R                  =(       a    U R
                  S   U R
                  S   L$ )N   r   r   )
isinstancesympyr   is_Addlen_args	is_symbol)r6   s    m/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/utils/_sympy/functions.py_is_symbols_binary_summationrA   \   s     	4$ 	/KK	/

Oq 	/ JJqM##	/ JJqM##		/
 JJqMA.    fc                    ^  [         R                  " T 5      S[        [           S[        [
        R                  -  4U 4S jj5       nU$ )Nargsr7   c                     > T" U 6 n[        S U  5       5      (       a>  [        U[        R                  5      (       d  [        R                  " [	        U5      5      nU$ )Nc              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7fN)r:   r;   Float.0as     r@   	<genexpr>-_keep_float.<locals>.inner.<locals>.<genexpr>n   s     84az!U[[))4   '))anyr:   r;   rI   float)rE   rrC   s     r@   inner_keep_float.<locals>.innerk   sM    h84888u{{B
 B
 E!H%ArB   )	functoolswrapsr   r   r   r;   rI   )rC   rS   s   ` r@   _keep_floatrW   h   sB     __QVC[ R%++%5   LrB   xyc                     S X4;   a  g X:H  $ rH    )rX   rY   s     r@   fuzzy_eqr\   x   s    v~6MrB   pqc                   ^^ S[         R                  S[        4S jmS[         R                  S[        4U4S jjn[        R                  " U" U 5      U" U5      5      nX-  X-  p[        [        [         R                  R                  [         R                  R                  U 5      5      5      n[         R                  R                  U5      nU H$  m[        U4S jU 5       5      (       d  M  UT-  nM&     U$ )a  
Fast path for sympy.gcd, using a simple factoring strategy.

We try to rewrite p and q in the form n*e*p1 + n*e*p2 and n*e*q0,
where n is the greatest common integer factor and e is the largest
syntactic common factor (i.e., common sub-expression) in p and q.
Then the gcd returned is n*e, cancelling which we would be left with
p1 + p2 and q0.

Note that further factoring of p1 + p2 and q0 might be possible with
sympy.factor (which uses domain-specific theories). E.g., we are unable
to find that x*y + x + y + 1 is divisible by x + 1. More generally,
when q is of the form q1 + q2 (instead of being already factored) it
might be necessary to fall back on sympy.gcd.
rX   r7   c                    [         R                  R                  U 5       Vs/ s H>  n[        U[        [         R
                  45      (       d  M*  [        [	        U5      5      PM@     nn[        R                  " U5      $ s  snf rH   )	r;   Mul	make_argsr:   intIntegerabsmathprod)rX   arginteger_coefficientss      r@   integer_coefficient0simple_floordiv_gcd.<locals>.integer_coefficient   sg     yy**1-+
-#U]]34 CCM- 	 +

 yy-..+
s   )A?A?r6   c                    > [        T[        R                  R                  U 5      5      n[        R
                  " [        R                  U5      $ rH   )mapr;   Addrb   rU   reducerf   gcd)r6   integer_factorsrj   s     r@   integer_factor+simple_floordiv_gcd.<locals>.integer_factor   s:    ),!4!4T!:*
 /::rB   c              3   .   >#    U  H
  nTU;   v   M     g 7frH   r[   )rK   
base_splitrX   s     r@   rM   &simple_floordiv_gcd.<locals>.<genexpr>   s     =:qJs   )r;   Basicrc   rf   rp   listrm   ra   rb   rn   all)r]   r^   rr   rp   base_splitsdivisor_splitrj   rX   s         @@r@   simple_floordiv_gcdr|   ~   s    "/u{{ /s /;U[[ ;S ; xxq)>!+<=C7AGq15EII!4!4Q!782K .3YY-@-@-CM===='C  JrB   c                   V   \ rS rSr% SrSr\\S4   \S'   Sr	\\S'   Sr
\\S	'   \S
\R                  4S j5       r\S
\R                  4S j5       rS\R"                  R$                  S
\4S jr\S\R,                  S\R,                  S
\R                  S-  4S j5       rS
\S-  4S jrSrg)r       z
We maintain this so that:
1. We can use divisibility guards to simplify FloorDiv(a, b) to a / b.
2. Printing out the expression is nicer (compared to say, representing a//b as (a - a % b) / b)

NB: This is Python-style floor division, round to -Inf
r9   .nargs#   
precedenceT
is_integerr7   c                      U R                   S   $ Nr   rE   selfs    r@   baseFloorDiv.base        yy|rB   c                      U R                   S   $ Nr   r   r   s    r@   divisorFloorDiv.divisor   r   rB   printerc                     UR                  U R                  [        S   S-
  5      nUR                  U R                  [        S   S-
  5      nSU SU S3$ )NAtom      ?(z//))parenthesizer   r   r   r   r   r   r   s       r@   	_sympystrFloorDiv._sympystr   sW    ##DIIz&/AC/GH&&t||Z5G#5MN4&7)1%%rB   r   r   Nc                 	   UR                   (       a  [        S5      e[        U5      (       a   [        U5      (       a  [        R                  $ U[        R                  L d  U[        R                  L a  [        R                  $ UR                   (       a  [        R
                  R                  $ UR                  (       a  [        US5      (       a  U$ UR                  (       a(  [        US5      (       a  [        R                  " US5      $ X:X  a  [        R
                  R                  $ [        U[        R                  5      (       a  [        U[        R                  5      (       a  [        U5      (       d  [        U5      (       a  [        U5      [        U5      -  nU[        R                  :X  a  [         $ U[        R                  * :X  a  [         * $ [        R"                  " U5      (       a  [        R                  $ [        R$                  " [        R&                  " U5      5      $ [        U[        R$                  5      (       aJ  [        U[        R$                  5      (       a+  [        R$                  " [)        U5      [)        U5      -  5      $ [        U[*        5      (       a)  [+        UR,                  S   UR,                  S   U-  5      $ [        U[        R$                  5      (       Ga  Sn/ n[        R.                  R1                  U5       H  nXb-  nS n[        U[        R                  5      (       am  [3        [        R4                  5      [3        S5      :  aG  UR7                  [        R8                  5      n	[;        S U	 5       5      n
UR                  =(       a    U
nOUR                  nU(       d  M  UR=                  U5        XG-  nM     [?        U5      S:w  a&  [+        U[        R.                  " USS06-
  U5      U-   $  [A        X5      n[        US5      (       a5  [        U[        R.                  5      (       a  [        RB                  " X5      n[        US5      (       d8  [+        [        RD                  " X-  5      [        RD                  " X+-  5      5      $  g ! [        RF                   a     g f = f)	Ndivision by zeror   r   z1.15.0c              3   >   #    U  H  oR                   S :H  v   M     g7f)r   N)r^   )rK   rR   s     r@   rM    FloorDiv.eval.<locals>.<genexpr>  s     ,Iy!SSAXys   evaluateF)$is_zeroZeroDivisionErrorr   r;   nanr	   Zeror   r   ra   Oner:   NumberrQ   rf   infr   isnanrd   floorrc   r    rE   rn   rb   r   __version__atomsRationalry   appendr=   r|   rp   simplifyPolynomialError)clsr   r   rR   	quotientstermstermquotientquotient_is_integer	rationalsall_rationals_intsrp   s               r@   evalFloorDiv.eval   sc    ??#$677tW!5!599599599 499<<77<<??|GQ77K??|GR8899T2&&?77;; tU\\**7ELL11T""k'&:&:deGn,ADHH}txxiwAyy }}TZZ]33dEMM**z'5==/Q/Q==Tc'l!:;;dH%%DIIaL$))A,*@AA gu}}--IE		++D1>
 '+#h		22|%%8 *8+ !)u~~ >I),,Iy,I)I&*2*=*=*TBT'*2*=*='&&LL&)I% 2( 5zQ TEIIu$Eu$EEwO 
		%d4CC##
7EII(F(Fii.Q''NN4:.w}0M  (  $$ 		s   BR) )S ?S c                     U R                   S S u  p[        UR                  UR                  UR                  UR                  /5      (       a  gg )Nr9   T)rE   ry   r   is_nonnegativer   r]   r^   s      r@   _eval_is_nonnegativeFloorDiv._eval_is_nonnegative3  sA    yy!}allA,<,<a>N>NOPPrB   r[   )__name__
__module____qualname____firstlineno____doc__r   tuplerc   __annotations__r   r   boolpropertyr;   rw   r   r   printing
StrPrinterstrr   classmethodrd   r   r   __static_attributes__r[   rB   r@   r    r       s     "E5c?!JJekk     &!:!: &s & V V V%++PTBT V VpdTk rB   r    c            
           \ rS rSr% SrSr\\S4   \S'   Sr	\
\S'   Sr\\S	'   \S
\R                  S\R                  S\R                  S\R                  S-  4S j5       rS\
S-  4S jrSrg)r!   i;  zC
ModularIndexing(a, b, c) => (a // b) % c where % is the C modulus
   .r   Tr   r   r   r   r   modulusr7   Nc                    US:X  d  US:X  a  [         R                  R                  $ [        U[         R                  5      (       aE  [        U[         R                  5      (       a&  [        U[         R                  5      (       a  X-  U-  $  US:w  aU  [         R
                  " X5      nUS:w  a9  [        [         R                  " X-  5      [         R                  " X$-  5      U5      $ [        U[         R                  5      (       Ga  / nSnUR                   H  n[         R
                  " XsU-  5      X2-  :w  d  M$  [        U[         R                  5      (       a  US:  d^  [        U[         R                  5      (       aC  [        UR                  S   [         R                  5      (       a  UR                  S   S:  a  Sn  OUR                  U5        M     [        U5      [        UR                  5      :w  a  U(       a  [        [        U5      X#5      $ [        U[        5      (       a*  [        UR                  S   UR                  S   U-  U5      $ g ! [         R                   a     GNf = f)Nr   r   TF)r;   r	   r   r:   rd   rp   r!   r   r   rn   rE   ra   r   r=   sumr    )r   r   r   r   rp   	new_termsall_positiver   s           r@   r   ModularIndexing.evalD  s    19177<<tU]]++7EMM227EMM22Ow..
	!|ii.!8*tz2w}5  dEII&&-/I!%L		99TW#459JJ"477D1H"433&tyy|U]]CC IIaL1, (-!((. "  9~TYY/L&s9~wHHdH%%"499Q<11GQQ9 $$ 		s   AI I-,I-c                 d    U R                   S S u  p[        UR                  UR                  5      $ )Nr9   )rE   r\   r   r   s      r@   r   $ModularIndexing._eval_is_nonnegativex  s,    yy!}((!*:*:;;rB   r[   )r   r   r   r   r   r   r   rc   r   r   r   r   r   r;   rd   rw   r   r   r   r[   rB   r@   r!   r!   ;  s     "E5c?!JJ1==1+0==1CH==1	t	1 1f<dTk <rB   r!   c            
           \ rS rSr% SrSr\\S4   \S'   Sr	\\S'   S\
S	-  4S
 jrS\
S	-  4S jrS\
S	-  4S jr\S\R                   S\R                   S\R                   S\R                   S	-  4S j5       rSrg	)r"   i~  z
Good ol' ternary operator
r   .r   r   r   r7   Nc                     U R                   S   R                  (       a   U R                   S   R                  (       a  S$ S $ Nr   r9   TrE   r   r   s    r@   _eval_is_integerWhere._eval_is_integer  s.    yy|..499Q<3J3JtTPTTrB   c                     U R                   S   R                  (       a   U R                   S   R                  (       a  S$ S $ r   )rE   r   r   s    r@   r   Where._eval_is_nonnegative  s9     yy|**tyy|/J/J 	
 	
rB   c                     U R                   S   R                  (       a   U R                   S   R                  (       a  S$ S $ r   rE   is_positiver   s    r@   _eval_is_positiveWhere._eval_is_positive  s.    yy|//DIIaL4L4LtVRVVrB   cr]   r^   c                 \    U[         R                  :X  a  U$ U[         R                  :X  a  U$ g rH   )r;   truefalse)r   r   r]   r^   s       r@   r   
Where.eval  s&    

?H%++HrB   r[   )r   r   r   r   r   r   r   rc   r   r   r   r   r   r   r   r;   rw   r   r   r[   rB   r@   r"   r"   ~  s     "E5c?!JU$+ U
dTk 
W4$; W U[[ U[[ U[[ U[[SWEW  rB   r"   c                       \ rS rSr% Sr\\S4   \S'   Sr\\S'   Sr	\
\S'   \S	\R                  S
\R                  S\R                  S-  4S j5       rS\
S-  4S jrS\
S-  4S jrS\4S jrSrg)r#   i  r   .r   r   r   Tr   r]   r^   r7   Nc                    UR                   (       a  [        S5      eU[        R                  L d  XU* 4;   d  US:X  a  [        R                  $ UR                  (       a  UR                  (       a  X-  $ UR                  (       aH  US:X  aB  UR
                  (       a  [        R                  $ UR                  (       a  [        R                  $ X-  nUR                  (       a  [        R                  $ X:  nUR                  (       a#  [        U5      (       a  UR                  (       a  U$ [        R                  " X5      S:X  a  [        R                  $ g )NModulo by zeror   r9   r   )r   r   r	   r   	is_Numberis_evenis_oddr   r   
is_Booleanr   r   r;   r$   r   r]   r^   rR   lesss        r@   r   PythonMod.eval  s     99#$455 ;!A2w,!q&66M ;;1;;5L ;;16yyvvxxuu E<<66M
 u??tDzzammH99Q?a66MrB   c                 F    U R                   S   R                  (       a  S$ S $ Nr   Tr   r   s    r@   r   PythonMod._eval_is_nonnegative      yy|//t9T9rB   c                 F    U R                   S   R                  (       a  S$ S $ r   )rE   is_negativer   s    r@   _eval_is_nonpositivePythonMod._eval_is_nonpositive  r   rB   c                 2   UR                  U R                  S   [        S   S-
  5      nUR                  U R                  S   [        S   S-
  5      nU R                  S   R                  (       a  [	        U5      OSU S3nSU SU S	U SU S
U SU SU 3$ )Nr   r   r   r   zabs(r   r   z % z) < 0 ? z + z : )r   rE   r   r   r   )r   r   r]   r^   abs_qs        r@   _ccodePythonMod._ccode  s      1z&/AC/GH  1z&/AC/GH))A,22A$qc1#S8A3c!Cwc!CsCCrB   r[   )r   r   r   r   r   r   rc   r   r   r   r   r   r;   r   r   r   r   r   r   r   r[   rB   r@   r#   r#     s    !E5c?!JJ+UZZ +EJJ +5::3D + +\:dTk ::dTk :D DrB   r#   c                   @    \ rS rSr% SrSr\\S'   SrSr	\
S 5       rSrg)	r$   i  r   r   r   Tc                    UR                   (       a  [        S5      eU[        R                  L d  XU* 4;   d  US:X  a  [        R                  $ UR                  (       a7  UR                  (       a&  US:  a  [        U5      eUS:  a  [        U5      eX-  $ UR                  (       aH  US:X  aB  UR                  (       a  [        R                  $ UR                  (       a  [        R                  $ X-  nUR                  (       a  [        R                  $ X:  nUR                  (       a%  [        U5      (       a  UR                  (       a  U$ g g g )Nr   r   r   r9   )r   r   r	   r   r   AssertionErrorr   r   r   r   r   r   r   r   s        r@   r   Mod.eval  s     99#$455 ;!A2w,!q&66M ;;1;;1u$Q''1u$Q''5L ;;16yyvvxxuu E<<66M
 u??tDzzammH /<z?rB   r[   N)r   r   r   r   r   r   rc   r   r   r   r   r   r   r[   rB   r@   r$   r$     s-    EJJN+ +rB   r$   c                       \ rS rSrSrSrg)r%   i  zN
Div where we can assume no rounding.
This is to enable future optimizations.
r[   N)r   r   r   r   r   r   r[   rB   r@   r%   r%     s    rB   r%   c                   6    \ rS rSrSr\S 5       rS\4S jrSr	g)r&   i"  Tc                 .   U[         R                  [        4;   a  [        $ U[         R                  * [        * 4;   a  [        * $ [        U[         R                  5      (       a3  [         R
                  " [        R                  " [        U5      5      5      $ g rH   )	r;   oor   r:   r   rd   rf   ceilrQ   r   numbers     r@   r   CeilToInt.eval%  sh     ehh''Muxxi&))7Nfell++==5=!9:: ,rB   r7   c                     UR                  U R                  S   U R                  S   R                  S-
  5      nSU S3$ )Nr   r   zceil(r   )r   rE   r   )r   r   r	  s      r@   r   CeilToInt._ccode/  s>    %%diilDIIaL4K4Kc4QRvha  rB   r[   N)
r   r   r   r   r   r   r   r   r   r   r[   rB   r@   r&   r&   "  s%    J; ;! !rB   r&   c                   (    \ rS rSrSr\S 5       rSrg)r'   i5  Tc                 n   U[         R                  [        4;   a  [        $ U[         R                  * [        4;   a  [        * $ [        U[         R                  5      (       a  U$ [        U[         R
                  5      (       a3  [         R                  " [        R                  " [        U5      5      5      $ g rH   )	r;   r  r   r:   rd   r   rf   r   rQ   r  s     r@   r   FloorToInt.eval8  sz    ehh''Muxxi((7Nfemm,,Mfell++==E&M!:;; ,rB   r[   Nr   r   r   r   r   r   r   r   r[   rB   r@   r'   r'   5  s    J< <rB   r'   c                   "    \ rS rSrSrSrS rSrg)r(   iD  z&
Div used in indexing that rounds up.
Tc                     [         R                  " U5      n[         R                  " U5      n[         R                  " X5      U:X  a  [        X5      $ [	        XS-
  -   U5      $ r   )r;   r   rp   r%   r    r   r   r   s      r@   __new__CeilDiv.__new__K  sN    }}T"--(99T#w.D**DaK0'::rB   r[   N)r   r   r   r   r   r   r  r   r[   rB   r@   r(   r(   D  s     J;rB   r(   c                   (    \ rS rSrSr\S 5       rSrg)r+   iT  Tc                 4    US:  a  [        S5      eUSU-  -  $ Nr   znegative shift countr9   )
ValueErrorr   r   shifts      r@   r   LShift.evalW  s#    19344ahrB   r[   Nr  r[   rB   r@   r+   r+   T  s    J rB   r+   c                   (    \ rS rSrSr\S 5       rSrg)r,   i^  Tc                 B    US:  a  [        S5      e[        USU-  5      $ r  )r  r    r  s      r@   r   RShift.evala  s&    19344ah''rB   r[   Nr  r[   rB   r@   r,   r,   ^  s    J( (rB   r,   c                      \ rS rSrS r\S\\R                  R                  R                     S-  4S j5       r\ S&S\\R                  R                  R                     S-  S\\R                  R                  R                     S-  4S jj5       r\S 5       r\S	 5       r\S
 5       rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S r$S  r%S! r&S" r'S# r(S$ r)S%r*g)'
MinMaxBaseih  c                 H   SSK Jn  UR                  SUR                  5      nS U 5       nU(       d  S OU R	                  U5      nU(       aD   [        U R                  U5      5      nUc&  U R                  " U40 UD6nU R                  " U40 UD6n[        U5      nU(       d  U R                  $ [        U5      S:X  a  [        U5      R                  5       $ [        R                  " U /[!        U5      Q70 UD6nXWl        Xgl        U$ ! [         a    U R                  s $ f = f)Nr   )global_parametersr   c              3   8   #    U  H  n[        U5      v   M     g 7frH   r
   )rK   rh   s     r@   rM   %MinMaxBase.__new__.<locals>.<genexpr>m  s     6   r   )sympy.core.parametersr#  popr   "_satisfy_unique_summations_symbols	frozenset_new_args_filterr   zero_collapse_arguments_find_localzerosidentityr=   rx   r   r  r   _argsetunique_summations_symbols)r   original_argsassumptionsr#  r   rE   r1  objs           r@   r  MinMaxBase.__new__i  s   ;??:/@/I/IJ66
  77F 	"   !!5!5d!;< )0..tC{C ++D@K@<<t9>:>>## ll3>>+>(A%
3    xx s   D D! D!r7   Nc                 T   [        U5      S:w  a  g[        US   [        5      (       a
  US   US   4O	US   US   4u  p#[        U5      (       d  g[        U5      (       a  U R	                  U5      $ [        U[        5      (       a#  [        USS5      nUb  U R	                  U/U5      $ g)au  
One common case in some models is building expressions of the form
max(max(max(a+b...), c+d), e+f) which is simplified to max(a+b, c+d, e+f, ...).
For such expressions, we call the Max constructor X times (once for each nested
max) and the expression gets flattened.

An expensive cost in constructing those expressions is running _collapse_arguments
and _find_localzeros. However, those two optimizations are unnecessary when the args
to max are all of the form a+b, c+d, ..etc where each term uses a unique set of symbols.

This function is used to detect such properties of the expressions we are building
and if so inform that we do not need to run those optimizations. To detect those,
we store a property in the expression that tells that this expression is a min/max
operation over terms that use unique symbols "unique_summations_symbols". This property
also memoize the set of symbols used in all the terms to make it faster to detect this
property inductively.

When we apply max to add a new term, all we need to do is check if the new term uses
unique symbols (with respect to existing terms and itself).
Example:
t = Max(a+b, c+d) ==> satisfies the property
Max(t, h+j)       ==> h,j not in [a,b,c,d] => satisfy the property.

The function returns None if the new expression does not satisfy the unique_summations_symbols
property. Otherwise, it returns a new set of unique symbols.
r9   Nr   r   r1  )r=   r:   r!  rA   _unique_symbolsgetattr)r   rE   lhsrhslhs_unique_summations_symbolss        r@   r)  -MinMaxBase._satisfy_unique_summations_symbols  s    < t9> $q':.. !Wd1gq'47# 	 ,C00 (,,&&t,, c:&&,30$-) -8**C52OPPrB   initial_setc                    Uc
  [        5       OUnU Hi  nUR                  5        HR  n[        U[        R                  R
                  R                  5      (       d      gXS;   a      gUR                  U5        MT     Mk     U$ )z
Return seen_symbols if all atoms in all args are all unique symbols,
else returns None. initial_set can be used to represent initial value for seen_symbols
N)setr   r:   r;   coresymbolSymboladd)r   rE   r=  seen_symbolsrh   elements         r@   r7  MinMaxBase._unique_symbols  sk     !, 3suC99;!'5::+<+<+C+CDD, $$W- '  rB   c                 |  ^ ^^ U(       d  U$ [        [        U5      5      nT [        L a  [        mO[        mUS   R                  (       Ga  / / 4=nu  pEU Ha  n[        U[        [        5       HE  nUR                  S   R                  (       d  M#  U[        U[        5         R                  U5        MG     Mc     [        R                  nU H1  nUR                  S   nUR                  (       d  M%  Xx:  S:X  d  M/  UnM3     [        R                  n	U H1  nUR                  S   nUR                  (       d  M%  Xy:  S:X  d  M/  Un	M3     T [        L a)  U H"  n
U
R                  (       d    OCX:  S:X  d  M   U
nM$     O2T [        :X  a(  U H"  n
U
R                  (       d    OX:  S:X  d  M   U
n	M$     SnT [        L a  U[        R                  :w  a  [        mUnOU	[        R                  :w  a  [        mU	nUbg  [        [        U5      5       HO  nX   n[        UT5      (       d  M  UR                  S   nT[        :X  a  X:  OX:  S:X  d  MA  T R                  X'   MQ     U U4S jm[        U5       H(  u  plXS-   S  Vs/ s H  nT" X5      PM     snXS-   S& M*     U U4S jn[        U5      S:  a  U" U5      nU$ s  snf )a  Remove redundant args.

Examples
========

>>> from sympy import Min, Max
>>> from sympy.abc import a, b, c, d, e

Any arg in parent that appears in any
parent-like function in any of the flat args
of parent can be removed from that sub-arg:

>>> Min(a, Max(b, Min(a, c, d)))
Min(a, Max(b, Min(c, d)))

If the arg of parent appears in an opposite-than parent
function in any of the flat args of parent that function
can be replaced with the arg:

>>> Min(a, Max(b, Min(c, d, Max(a, e))))
Min(a, Max(b, Min(a, c, d)))
r   TNc           	      |  > [        U [        [        45      (       d  U $ XR                  ;   nU(       d3  U R                  " U R                   Vs/ s H  nT" X15      PM     snSS06$ [        U T5      (       a:  U R                  " U R                   Vs/ s H  o3U:w  d  M
  T" X15      PM     snSS06$ U$ s  snf s  snf )Nr   F)r:   MinMaxrE   func)airL   condir   dos       r@   rO  *MinMaxBase._collapse_arguments.<locals>.do8  s    b3*--	<Dww277 ;7aA7 ;LeLL"c""ww277 E7a1fA7 EVPUVVH	 !< !Fs   B4	B9B9r   c                   > U4S jn[        XSS9u  p#U(       d  U $ U Vs/ s H  n[        UR                  5      PM     nn[        R                  " U6 nU(       d  U $ [	        U5      nU Vs/ s H  oU-
  PM	     n	n[        U	5      (       a/  U	 V
s/ s H  n
T" U
SS06PM     nn
UR                  T" USS065        T" USS06nX</-   $ s  snf s  snf s  sn
f )Nc                    > [        U T5      $ rH   )r:   )rh   others    r@   <lambda>GMinMaxBase._collapse_arguments.<locals>.factor_minmax.<locals>.<lambda>N  s    :c5#9rB   T)binaryr   F)r   r?  rE   intersectionrx   ry   r   )rE   is_other
other_argsremaining_argsrh   arg_setscommonnew_other_argsarg_setarg_sets_diffsother_args_diffother_args_factoredr   rS  s                r@   factor_minmax5MinMaxBase._collapse_arguments.<locals>.factor_minmaxM  s    9H)-dT)J&J 2<<#CHHH<%%x0F!&\N=EFX'v-XMF =!!FS"Tm5!#<e#<m"T%%c?&KU&KL"'"H%"H!$999 = G
 #Us   C	-CC)rx   r   rI  rJ  	is_numberr   rE   is_comparabler:   r   r/  ranger=   	enumerate)r   rE   r3  siftedminsmaxsrN  vsmallbigrh   TrL   a0rL  rc  rO  rS  s   `               @@r@   r-  MinMaxBase._collapse_arguments  sb   0 KGDM"#:EE
 7"$b&(FZTac*Avvay...z!S1299!< +  LLEFF1I;;;AI$#6E  ,,CFF1I;;;AG#4C  czC==, #	  
 C==	d*!	  
 AczCLL(EA$}s4y)AA!!U++VVAY(-RV26!" '*llDG *		 dODA15!eg?2RY?DQM $	:0 t9q= &DI @s   ;J9c              #   v  #    U H  n[        U[        5      (       a1  UR                  SL d"  UR                  (       a   UR                  (       d  [        SU S35      eX R                  :X  a  [        U5      eX R                  :X  a  M  UR                  U :X  a  UR                   Sh  vN   M  Uv   M     g N7f)z
Generator filtering args.

first standard filter, for cls.zero and cls.identity.
Also reshape ``Max(a, Max(b, c))`` to ``Max(a, b, c)``,
and check arguments for comparability
FzThe argument 'z' is not comparable.N)r:   r   is_extended_realre  rf  r  r,  r   r/  rK  rE   )r   arg_sequencerh   s      r@   r+  MinMaxBase._new_args_filterj  s       C sD))''50MM#*;*; >#6J!KLLhh"3''$S88##	!   $s   B%B9'B7(B9c                     [        5       nSnU Hf  nUR                  (       aA  Uc  UnM  U [        L a  [        XE5      nM1  U [        L a  [        XE5      nMG  [        SU  35      eUR                  U5        Mh     Uc  U$ [        U5      S:X  a  U1$ [        U5      S:X  a^  [        [        U5      5      nUS;   a  UR                  (       a  U [        L a  U$ U1$ US:X  a  UR                  (       a  U [        L a  U$ U1$ UR                  U5        U$ )aV  
Sequentially allocate values to localzeros.

When a value is identified as being more extreme than another member it
replaces that member; if this is never true, then the value is simply
appended to the localzeros.

Unlike the sympy implementation, we only look for zero and one, we don't
do generic is connected test pairwise which is slow
Nzimpossible r   r   )g        r   )r?  r   rJ  maxrI  minr  rC  r=   nextiterr   r   )r   valuesoptionsother_values	num_valuerh   other_values          r@   r.  MinMaxBase._find_localzeros  s    u	C}}$ #Icz$'	$7	$'	$7	,{3%-@AA  %  |!;|!tL12KH$)C)C'*cz|B	{BA~+"9"9'*cz|B	{B#rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_algebraicrK   rN  s     r@   rM   &MinMaxBase.<lambda>.<locals>.<genexpr>       (HAr&  r   rE   r`  s    r@   rT  MinMaxBase.<lambda>      5(H(H#HrB   c                 :    [        S U R                   5       5      $ )Nc              3   :   #    U  H  nUR                   v   M     g 7frH   )is_antihermitianr  s     r@   rM   r          -A 	
   r  r  s    r@   rT  r        u -- (rB   c                 :    [        S U R                   5       5      $ )Nc              3   :   #    U  H  nUR                   v   M     g 7frH   )is_commutativer  s     r@   rM   r          +A 	
r  r  r  s    r@   rT  r        U ++ &rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )
is_complexr  s     r@   rM   r         &DV||Vr&  r  r  s    r@   rT  r        &DQVV&D!DrB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_compositer  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )r   r  s     r@   rM   r         #>v!IIvr&  r  r  s    r@   rT  r        e#>qvv#>>rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )	is_finiter  s     r@   rM   r    s     %B6akk6r&  r  r  s    r@   rT  r    s    %B166%B BrB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_hermitianr  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_imaginaryr  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )r   r  s     r@   rM   r         'Fv!vr&  r  r  s    r@   rT  r        %'Fqvv'F"FrB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )r   r  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_irrationalr  s     r@   rM   r         )J6a//6r&  r  r  s    r@   rT  r        E)J166)J$JrB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r   r  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_nonintegerr  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   :   #    U  H  nUR                   v   M     g 7frH   r   r  s     r@   rM   r    r  r  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   :   #    U  H  nUR                   v   M     g 7frH   )is_nonpositiver  s     r@   rM   r    r  r  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )
is_nonzeror  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )r   r  s     r@   rM   r    s     "<V88Vr&  r  r  s    r@   rT  r    s    U"<QVV"<<rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_polarr  s     r@   rM   r         $@AZZr&  r  r  s    r@   rT  r        u$@$@@rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r   r  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_primer  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_rationalr  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )is_realr  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   :   #    U  H  nUR                   v   M     g 7frH   )rs  r  s     r@   rM   r    r  r  r  r  s    r@   rT  r    r  rB   c                 :    [        S U R                   5       5      $ )Nc              3   :   #    U  H  nUR                   v   M     g 7frH   )is_transcendentalr  s     r@   rM   r    s      .A 	
r  r  r  s    r@   rT  r    s     .. )rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   )r   r  s     r@   rM   r    r  r&  r  r  s    r@   rT  r    r  rB   r[   rH   )+r   r   r   r   r  r   r?  r;   r@  rA  rB  r)  r7  r-  r+  r.  _eval_is_algebraic_eval_is_antihermitian_eval_is_commutative_eval_is_complex_eval_is_composite_eval_is_even_eval_is_finite_eval_is_hermitian_eval_is_imaginary_eval_is_infiniter   _eval_is_irrational_eval_is_negative_eval_is_nonintegerr   r   _eval_is_nonzero_eval_is_odd_eval_is_polarr   _eval_is_prime_eval_is_rational_eval_is_real_eval_is_extended_real_eval_is_transcendental_eval_is_zeror   r[   rB   r@   r!  r!  h  s   +Z 5	UZZ%%	&	-5 5n GK #EJJ$5$5$<$< = D	UZZ%%	&	- $ F FP  4 , ,\ I EH>MBOHHFDJFJ E<L@NF@NF>M ?MrB   r!  c                   Z    \ rS rSrSr\R                  r\R                  r	S r
S rS rSrg)rJ  i  z5
Return, if possible, the maximum value of the list.
c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r  rJ   s     r@   rM   (Max._eval_is_positive.<locals>.<genexpr>       9y!yr&  r   rE   r   s    r@   r   Max._eval_is_positive  s    9tyy999rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r  rJ   s     r@   rM   +Max._eval_is_nonnegative.<locals>.<genexpr>  s     <)Q(()r&  r  r   s    r@   r   Max._eval_is_nonnegative  s    <$))<<<rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r  rJ   s     r@   rM   (Max._eval_is_negative.<locals>.<genexpr>       :	1	r&  r   rE   r   s    r@   r  Max._eval_is_negative  s    :		:::rB   r[   N)r   r   r   r   r   r	   Infinityr,  NegativeInfinityr/  r   r   r  r   r[   rB   r@   rJ  rJ    s,     ::D!!H:=;rB   rJ  c                   Z    \ rS rSrSr\R                  r\R                  r	S r
S rS rSrg)rI  i  z5
Return, if possible, the minimum value of the list.
c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r  rJ   s     r@   rM   (Min._eval_is_positive.<locals>.<genexpr>  r  r&  r  r   s    r@   r   Min._eval_is_positive  s    :		:::rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r  rJ   s     r@   rM   +Min._eval_is_nonnegative.<locals>.<genexpr>  s     =9a))9r&  r  r   s    r@   r   Min._eval_is_nonnegative   s    =499===rB   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frH   r  rJ   s     r@   rM   (Min._eval_is_negative.<locals>.<genexpr>  r  r&  r  r   s    r@   r  Min._eval_is_negative  s    9tyy999rB   r[   N)r   r   r   r   r   r	   r  r,  r  r/  r   r   r  r   r[   rB   r@   rI  rI    s,     DzzH;>:rB   rI  c                 N    SnU S:  a  U * n US-  S:X  a  SOSnU[        X5      -  $ )Nr   r   r9   r   )	_safe_pow)r   expsigns      r@   safe_powr    s6    Daxu!GqLqb)D&&&rB   c                     US:  a  [        S5      eUS:X  a  g[        XS-  5      nU[        L a  [        $ X"-  nU[        R                  :  a  [        $ US-  S:X  a  X0-  nU[        R                  :  a  [        $ U$ )Nr   zExponent must be non-negative.r   r9   )r  r  r   sysmaxsize)r   exponenthalf_expresults       r@   r  r    s~    !|9::1}!m,H6
  F!|qCKKMMrB   c                   8    \ rS rSr% SrSr\\S'   \S 5       r	Sr
g)r4   i+  T2   r   c                    [        U[        R                  5      (       aS  [        U[        R                  5      (       a4  [        X5      nU[        * [        4;   a  U$ [        R                  " U5      $ [        U[        R                  5      (       a  [        R
                  " X5      $ U[        [        R                  4;   a9  UR                  (       a  [        $ UR                  (       a  [        R                  $ g g rH   )
r:   r;   rd   r  r   Powr  r   r   zoo)r   r   r  rR   s       r@   r   PowByNatural.eval0  s    dEMM**z#u}}/M/M#AfWf%%==##c5==)) 99T''6588$$""!!yy  " %rB   r[   N)r   r   r   r   r   r   rc   r   r   r   r   r[   rB   r@   r4   r4   +  s#    JJ! !rB   r4   c                   8    \ rS rSr% SrSr\\S'   \S 5       r	Sr
g)r3   iF  T<   r   c                     [        U[        R                  5      (       aK  [        U[        R                  5      (       a+  [        R                  " [	        U5      [	        U5      -  5      $ g g rH   )r:   r;   r   rI   rQ   )r   r   r  s      r@   r   FloatPow.evalK  sJ     dELL))jell.K.K;;uT{eCj899 /L)rB   r[   Nr   r   r   r   r  r   rc   r   r   r   r   r[   rB   r@   r3   r3   F  s#    GJ: :rB   r3   c                   8    \ rS rSr% SrSr\\S'   \S 5       r	Sr
g)r*   i\  Tr   r   c                    UR                   (       a  [        S5      e[        U[        R                  5      (       aK  [        U[        R                  5      (       a+  [        R
                  " [        U5      [        U5      -  5      $ g g Nr   )r   r   r:   r;   r   rI   rQ   r  s      r@   r   FloatTrueDiv.evala  s]    
 ??#$677dELL))j%,,.O.O;;uT{U7^;<< /P)rB   r[   Nr*  r[   rB   r@   r*   r*   \  s#    GJ= =rB   r*   c                   F    \ rS rSr% SrSr\\S'   \S 5       r	S\
4S jrSrg	)
r)   iu  Tr   r   c                 "   UR                   (       a  [        S5      e[        U[        R                  5      (       aj  [        U[        R                  5      (       aK  [        U5      (       d  [        U5      (       a+  [        R                  " [        U5      [        U5      -  5      $ [        U[        R                  5      (       aK  [        U[        R                  5      (       a+  [        R                  " [        U5      [        U5      -  5      $ g g r-  )
r   r   r:   r;   r   r   rI   rQ   rd   rc   r  s      r@   r   IntTrueDiv.evalz  s    ??#$677 tU\\**7ELL11T""k'&:&: ;;uT{U7^;<<dEMM**z'5==/Q/Q;;s4y3w<788 0R*rB   r7   c                     UR                  U R                  S   [        S   S-
  5      nUR                  U R                  S   [        S   S-
  5      nSU SU S3$ )Nr   r   r   r   z((int)z/(int)r   )r   rE   r   r   s       r@   r   IntTrueDiv._ccode  s_    ##DIIaL*V2Ds2JK&&tyy|Z5G#5MNvVG9A..rB   r[   N)r   r   r   r   r  r   rc   r   r   r   r   r   r   r[   rB   r@   r)   r)   u  s/    GJ9 9/ /rB   r)   c                   (    \ rS rSrSr\S 5       rSrg)r-   i  Tc           
      T   [        U5      S-  S:w  a  [        S[        U5       35      e[        U5      S-  nUSU nXS  nSSKJn  [	        S U 5       5      (       a=  U" U Vs/ s H  n[        U5      PM     snU Vs/ s H  n[        U5      PM     sn5      $ US:X  a<  US   R                  (       a
  US   S:X  a  gUS   R                  (       a
  US   S:  a  g[	        S U 5       5      (       a  US:X  a  [        S5      e[        [        [        X4S	S
9[        R                  " S5      S9SS	06u  px[	        S US S  5       5      (       aE  US S S-   nU" U Vs/ s H  n[        U5      PM     snU Vs/ s H  n[        U5      PM     sn5      $ g s  snf s  snf s  snf s  snf )Nr9   r   z*expected an even number of arguments, got )!eval_is_non_overlapping_and_densec              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frH   r:   r;   rd   rJ   s     r@   rM   9IsNonOverlappingAndDenseIndicator.eval.<locals>.<genexpr>  s     :Tz!U]]++TrO   r   c              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frH   r8  rJ   s     r@   rM   r9    s     =Wz!U]]++WrO   zdim must not be zeroT)strict)keyr;  c              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frH   r8  rJ   s     r@   rM   r9    s     FA:a//rO   r   )*   )r=   r  %torch.fx.experimental.symbolic_shapesr6  ry   rc   r   zipsortedoperator
itemgetter)	r   rE   dimsizesstridesr6  rL   s_sizes	s_stridess	            r@   r   &IsNonOverlappingAndDenseIndicator.eval  s   t9q=A <SYKH  $i1nQst*	
 :T:::4!&'AQ'')B'Q#a&')B  !8qz##
aQx!!eAhl =W===ax$%;<< "%E48h>Q>QRS>TU""G
 F"FFF!#2,. 9%,-WSVW-	/J	1A	/J  K ()BD ./Js   $F?F
F 9F%
r[   Nr  r[   rB   r@   r-   r-     s    J5 5rB   r-   c                   (    \ rS rSrSr\S 5       rSrg)r.   i  Tc                     U[         R                  [         R                  * 4;   a  U$ [        U[         R                  5      (       a3  [         R                  " [
        R                  " [        U5      5      5      $ g rH   )r;   r  r:   r   rI   rf   truncrQ   r  s     r@   r   TruncToFloat.eval  sR    ehh	**Mfell++ ;;tzz%-899	 ,rB   r[   Nr   r   r   r   r  r   r   r   r[   rB   r@   r.   r.     s    G: :rB   r.   c                   (    \ rS rSrSr\S 5       rSrg)r/   i  Tc                 .   U[         R                  [        4;   a  [        $ U[         R                  * [        * 4;   a  [        * $ [        U[         R                  5      (       a3  [         R
                  " [        R                  " [        U5      5      5      $ g rH   )	r;   r  r   r:   r   rd   rf   rL  rQ   r  s     r@   r   TruncToInt.eval  sh     ehh''Muxxi&))7Nfell++==E&M!:;; ,rB   r[   Nr  r[   rB   r@   r/   r/     s    J< <rB   r/   c                   (    \ rS rSrSr\S 5       rSrg)r0   i  Tc                     U[         R                  L a  [        $ U[         R                  * L a  [        * $ [        U[         R                  5      (       a)  [         R
                  " [        [        U5      S5      5      $ g r   )r;   r  r   r:   r   rd   roundrQ   r  s     r@   r   RoundToInt.eval  sZ     UXXMehhY7Nfell++==uV}a!899 ,rB   r[   Nr  r[   rB   r@   r0   r0     s    J: :rB   r0   c                   (    \ rS rSrSr\S 5       rSrg)r1   i  Tc                     [        U[        R                  5      (       aR  [        U[        R                  5      (       a2  [        R                  " [        [        U5      [        U5      5      5      $ g g rH   )r:   r;   r   rd   rI   rT  rQ   rc   )r   r	  ndigitss      r@   r   RoundDecimal.eval  sL     fell++
7EMM0R0R;;uU6]CLABB 1S+rB   r[   NrN  r[   rB   r@   r1   r1     s    GC CrB   r1   c                   (    \ rS rSrSr\S 5       rSrg)r2   i  Tc                 6   U[         R                  [         R                  * 4;   a  U$ [        U[         R                  5      (       a  [         R                  " [        U5      5      $ U[        L a  [         R                  $ U[        * L a  [         R                  * $ g rH   )r;   r  r:   rd   rI   rc   r   r  s     r@   r   ToFloat.eval  sn    ehh	**Mfemm,,;;s6{++V88OfWHH9 rB   r[   NrN  r[   rB   r@   r2   r2     s    G	 	rB   r2   c                      ^  \ rS rSrSrSrS\4S jrS\4S jrS r	S r
\S	 5       r\S
 5       rS rS\4S jrS rU 4S jrU 4S jrU 4S jrU 4S jrS\4S jrSrU =r$ )r5   i,  z,
Prevents expansion and other optimizations

   r7   c                 (    SU R                   S    S3$ )Nz	Identity(r   r   r   r   s    r@   __repr__Identity.__repr__3  s    499Q<.**rB   c                 F    SUR                  U R                  S   5       S3$ )z+Controls how sympy's StrPrinter prints thisr   r   r   )doprintrE   )r   r   s     r@   r   Identity._sympystr7  s%     7??499Q<0133rB   c                 4    U R                   S   R                  $ r   )rE   r  r   s    r@   r  Identity._eval_is_real<  s    yy|###rB   c                 4    U R                   S   R                  $ r   r   r   s    r@   r   Identity._eval_is_integer@  s    yy|&&&rB   c                     [        U R                  S   R                  =(       a    U R                  S   R                  5      $ r   )r   rE   re  rf  r   s    r@   re  Identity.is_numberC  s0    
 DIIaL**Ityy|/I/IJJrB   c                 F    [        U R                  S   R                  5      $ r   )r   rE   rf  r   s    r@   rf  Identity.is_comparableJ  s     DIIaL..//rB   c                      U R                   S   $ r   r   )r   hintss     r@   _eval_expand_identityIdentity._eval_expand_identityP  r   rB   c                 2    [        U R                  S   5      $ r   )rc   rE   r   s    r@   __int__Identity.__int__U  s    499Q<  rB   c                    U R                   S   n[        U[        5      (       a  [        R                  " U5      n[        U[        R
                  5      (       d  gUR                  (       a"  UR                  (       a  UR                  (       d  gUR                  (       a"  UR                  (       a  UR                  (       d  gU" X15      (       a  [        R                  R                  $ [        R                  R                  $ )z
Fast path for comparing wrapped numeric atomics against other numeric atomics.
Keep compound expressions on SymPy's default symbolic path.
r   N)rE   r:   rc   r;   rd   r   is_Atomre  rf  r	   r   r   )r   rS  oprh   s       r@   _identity_atom_compareIdentity._identity_atom_compareY  s    
 iileS!!MM%(E%,,#2C2C%//e6I6I!#~~uww||@577==@rB   c                 R   > U R                  US 5      nUb  U$ [        TU ]	  U5      $ )Nc                 
    X:  $ rH   r[   rL   bs     r@   rT  !Identity.__ge__.<locals>.<lambda>j      afrB   )rw  super__ge__r   rS  out	__class__s      r@   r  Identity.__ge__i  .    ))%1DEos@57>%+@@rB   c                 R   > U R                  US 5      nUb  U$ [        TU ]	  U5      $ )Nc                 
    X:  $ rH   r[   r{  s     r@   rT  !Identity.__gt__.<locals>.<lambda>n      aerB   )rw  r  __gt__r  s      r@   r  Identity.__gt__m  .    ))%1CDos@57>%+@@rB   c                 R   > U R                  US 5      nUb  U$ [        TU ]	  U5      $ )Nc                 
    X:*  $ rH   r[   r{  s     r@   rT  !Identity.__le__.<locals>.<lambda>r  r~  rB   )rw  r  __le__r  s      r@   r  Identity.__le__q  r  rB   c                 R   > U R                  US 5      nUb  U$ [        TU ]	  U5      $ )Nc                 
    X:  $ rH   r[   r{  s     r@   rT  !Identity.__lt__.<locals>.<lambda>v  r  rB   )rw  r  __lt__r  s      r@   r  Identity.__lt__u  r  rB   c                 2    [        U R                  S   5      $ r   )rQ   rE   r   s    r@   	__float__Identity.__float__y  s    TYYq\""rB   r[   )r   r   r   r   r   r   r   r`  r   r  r   r   re  rf  ro  rc   rr  rw  r  r  r  r  rQ   r  r   __classcell__)r  s   @r@   r5   r5   ,  s     J+# +4C 4
$' K K 0 0

! !A AAAA#5 # #rB   r5   c                 b   ^   " U 4S jS[         R                  5      nST -   nX!l        X!l        U$ )Nc                   :   > \ rS rSrSr Y r\r\U 4S j5       r	Sr
g)+make_opaque_unary_fn.<locals>.OpaqueUnaryFni  a  
Unlike the builtin sympy functions on real numbers like sympy.sqrt,
these equivalents do not do any nontrivial reasoning besides
constant propagation.  This helps avoid performing transformations
that are valid for real numbers but are invalid for floating point;
in particular, while we are willing to make optimizations that change
numerics for Tensor compute, we are NOT willing to make optimizations
that change numerics for size compute.
c                   > [        U[        R                  [        R                  45      (       a4   [        R                  " [	        [
        T5      " [        U5      5      5      $ U[        R                  [        R                  * [        R                  [        R                  * [        [        * 4;   ag  U[        L a  [        R                  nU[        * L a  [        R                  * nTS:X  a  [        R                  " US5      $ [	        [        T5      " U5      $ g ! [         a    [	        [        T5      " U5      s $ f = f)Nlog2r9   )r:   r;   rd   rI   r8  rf   rQ   OverflowErrorr  r$  r   log)r   rL   names     r@   r   0make_opaque_unary_fn.<locals>.OpaqueUnaryFn.eval  s    !emmU[[9::3 ;;wtT':58'DEE
 uxx%((EII		z6F7SS;A<	A6> 99Q?*ud+A.. % 3"5$/223s   2D  D?>D?r[   N)r   r   r   r   r   _torch_handler_namemake_opaque_unary_fn_torch_unpicklerr   r   r   )r  s   r@   OpaqueUnaryFnr    s(    	 #/		 
	rB   r  OpaqueUnaryFn_)r;   Functionr   r   )r  r  nms   `  r@   r  r  ~  s2    $ $L 
D	 B!#rB   sqrtcoscoshsinsinhtantanhasinacosatanr  r  asinhr  c                    ^ ^^ T S:X  a
  [         S   mO.T S:X  a
  [         S   mOT S:X  a
  [         S   mO[        ST  35      e " U UU4S jS	[        R                  5      nS
T -   nX2l        X2l        U$ )Nbitwise_and
BitwiseAndbitwise_xor
BitwiseXor
bitwise_or	BitwiseOrzunrecognized c                   h   > \ rS rSr%  Y r Yr\\S'   \R                  " \
 YS9r\U4S j5       rSrg))make_opaque_bitwise_fn.<locals>.BitwiseFni  r   )real_op_namec                 D  > UR                   (       a'  UR                   (       a  [        [        T5      " X5      $ UR                   (       a  [        R                  " U(       a  SOS5      nUR                   (       a  [        R                  " U(       a  SOS5      n[        U[        R                  [        45      (       ab  [        U[        R                  [        45      (       a=  [        R                  " [        [        T5      " [        U5      [        U5      5      5      $ g )Nr   r   )r   r8  rB  r;   rd   r:   rc   )r   rL   r|  r  s      r@   r   .make_opaque_bitwise_fn.<locals>.BitwiseFn.eval  s    ||x6q<<||MMq!a0||MMq!a0!emmS122zEMM3'8 8 }}WX|%DSVSQRV%TUUrB   r[   N)r   r   r   r   r  r   rc   r   rU   partialmake_opaque_bitwise_fnr  r   r   r   )r  precr  s   r@   	BitwiseFnr    s=    "
C$,,"
 
	 
	rB   r  
BitwiseFn_)r   r  r;   r  r   r   )r  r  r  r  r  s   ``  @r@   r  r    s~    },'		,'		+&}TF344 ENN * 
	BrB   r  and_r  or_r  xor)erU   rf   rB  r  collections.abcr   typingr   r   r   typing_extensionsr   r   r;   r	   
sympy.corer   sympy.core.exprr   sympy.core.functionr   sympy.core.logicr   r   r   sympy.core.numbersr   sympy.core.operationsr   r   sympy.core.sortingr   sympy.core.traversalr   sympy.printing.precedencer   sympy.utilities.iterablesr   torch.torch_versionr   numbersr   r   r   r   r   __all__r   rA   rI   rW   r\   rw   r|   r  r    r!   r"   r#   r$   r%   r&   r'   r(   r+   r,   r!  rJ  rI  r  r  r4   r3   r*   r)   r-   r.   r/   r0   r1   r2   r5   r  OpaqueUnaryFn_sqrtOpaqueUnaryFn_cosOpaqueUnaryFn_coshOpaqueUnaryFn_sinOpaqueUnaryFn_sinhOpaqueUnaryFn_tanOpaqueUnaryFn_tanhOpaqueUnaryFn_asinOpaqueUnaryFn_acosOpaqueUnaryFn_atanOpaqueUnaryFn_expOpaqueUnaryFn_logOpaqueUnaryFn_asinhOpaqueUnaryFn_log2r  BitwiseFn_bitwise_andBitwiseFn_bitwise_orBitwiseFn_bitwise_xorr[   rB   r@   <module>r     s      
 $ 8 8 2      + 7 7 + 9 & % 0 * , ( ( T'5B4	uzz 	d 	r!"vc{mR%++--. t t t )5;; )5;; )5;; )||u~~ |~@<enn @<FENN >BD BDL3%.. 3lx ! !&< <;enn ; U^^ (U^^ (w?y w?t;*k ;&:*k :&'4!5>> !6:u~~ :,=5>> =2/ /F9 9z:5>> :< <: :<C5>> Cenn  O#u~~ O#d+^ *&1 (/ )&1 (/ )&1 (/ )&1 )&1 )&1 )&1 (/ (/ *73 )&1 #L /}fE -lEB .}eD rB   