
    JThT                        S SK r S SKrS SKrS SKrS SKJrJrJr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(  \(       a  S SK)J*r*  \	" S\S9r+\" S5      r,/ SQr-S\R&                  S\.4S jr/S\\\,   /\+4   S\\\,   /\
\+\R`                  4   4   4S jr1S\\.   S\\.   S\\.   4S jr2S\Rf                  S\Rf                  S\Rf                  4S  jr4 " S! S"\Rj                  5      r6 " S# S$\Rj                  5      r7 " S% S&\Rj                  5      r8 " S' S(\Rj                  5      r9 " S) S*\Rj                  5      r: " S+ S,\65      r; " S- S.\Rj                  5      r< " S/ S0\Rj                  5      r= " S1 S2\Rj                  5      r> " S3 S4\Rj                  5      r? " S5 S6\Rj                  5      r@ " S7 S8\\5      rA " S9 S:\A\5      rB " S; S<\A\5      rCS= rDS> rE " S? S@\Rj                  5      rF " SA SB\Rj                  5      rG " SC SD\Rj                  5      rH " SE SF\Rj                  5      rI " SG SH\Rj                  5      rJ " SI SJ\Rj                  5      rK " SK SL\Rj                  5      rL " SM SN\Rj                  5      rM " SO SP\Rj                  5      rN " SQ SR\Rj                  5      rO " SS ST\Rj                  5      rPSU rQ\Q" SV5      rR\Q" SW5      rS\Q" SX5      rT\Q" SY5      rU\Q" SZ5      rV\Q" S[5      rW\Q" S\5      rX\Q" S]5      rY\Q" S^5      rZ\Q" S_5      r[\Q" S`5      r\\Q" Sa5      r]\Q" Sb5      r^\Q" Sc5      r_Sd r`\`" SeSf5      ra\`" SgSh5      rbg)i    N)CallableOptionalSupportsFloatTYPE_CHECKINGTypeVarUnion)TypeVarTupleUnpack)Ssympify)Expr)Application)_torf	fuzzy_andfuzzy_or)equal_valued)	LatticeOpShortCircuit)ordered)walk)
PRECEDENCE)sift   )int_oo)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                 "   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   )is_Addlen_args	is_symbol)r6   s    T/var/www/auris/envauris/lib/python3.13/site-packages/torch/utils/_sympy/functions.py_is_symbols_binary_summationr?   Y   sr     	 	/

Oq 	/JJqM##	/ JJqM##	/ JJqMA.    fc                    ^  [         R                  " T 5      S[        [           S[        [
        [        R                  4   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)
isinstancesympyFloat.0as     r>   	<genexpr>-_keep_float.<locals>.inner.<locals>.<genexpr>j   s     84az!U[[))4   '))anyrG   rH   rI   float)rC   rrA   s     r>   inner_keep_float.<locals>.innerg   sM    $%tH84888u{{B
 B
 E!H%Ar@   )	functoolswrapsr
   r   r   r   rH   rI   )rA   rS   s   ` r>   _keep_floatrW   d   sF     __QVC[ U2u{{?%;   Lr@   xyc                     S X4;   a  g X:H  $ rF    )rX   rY   s     r>   fuzzy_eqr\   s   s    v~6Mr@   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 rF   )	rH   Mul	make_argsrG   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      $ rF   )maprH   Addrb   rU   reducerf   gcd)r6   integer_factorsrj   s     r>   integer_factor+simple_floordiv_gcd.<locals>.integer_factor   s:    ),!4!4T!:*
 /::r@   c              3   .   >#    U  H
  nTU;   v   M     g 7frF   r[   )rK   
base_splitrX   s     r>   rM   &simple_floordiv_gcd.<locals>.<genexpr>   s     =:qJs   )rH   Basicrc   rf   rp   listrm   ra   rb   rn   all)r]   r^   rr   rp   base_splitsdivisor_splitrj   rX   s         @@r>   simple_floordiv_gcdr|   y   s    "/u{{ /s /;U[[ ;S ; xxq)>!+<=C7AGq15EII!4!4Q!782K .3YY-@-@-CM===='C  Jr@   c            	       L   \ 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   4S j5       rS 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   rC   selfs    r>   baseFloorDiv.base       yy|r@   c                      U R                   S   $ Nr   r   r   s    r>   divisorFloorDiv.divisor   r   r@   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%%r@   r   r   Nc                 *	   UR                   (       a  [        S5      eU[        [        * [        R                  [        R                  * 4;   a@  U[        [        * [        R                  [        R                  * 4;   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      $ [        U[        R                  5      (       Ga"  [        U[        R                  5      (       Ga  U[        [        * [        R                  [        R                  * 4;   d0  U[        [        * [        R                  [        R                  * 4;   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      (       a  Sn/ n[        R,                  R/                  U5       H/  nXb-  nUR                  (       d  M  UR1                  U5        XG-  nM1     [3        U5      S:w  a&  [)        U[        R,                  " USS06-
  U5      U-   $  [5        X5      n[        US5      (       a5  [        U[        R,                  5      (       a  [        R6                  " X5      n[        US5      (       d8  [)        [        R8                  " X-  5      [        R8                  " X(-  5      5      $  g ! [        R:                   a     g f = f)Ndivision by zeror   r   evaluateF)is_zeroZeroDivisionErrorr   rH   oonanr   Zeror   r   ra   rG   NumberrQ   rf   infisnanrd   floorrc   r    rC   rn   rb   appendr;   r|   rp   simplifyPolynomialError)	clsr   r   rR   	quotientstermstermquotientrp   s	            r>   evalFloorDiv.eval   s1    ??#$677FVGUXXy99gGHHXXI	J
 ?
 99599599 499<<77<<??|GQ77K??|GR8899T2&&tU\\**7ELL11&%((UXXI>>vw588)DD 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>&&&LL&)I 2 5zQ TEIIu$Eu$EEwO 
		%d4CC##
7EII(F(Fii.Q''NN4:.w}0M  (  $$ 		s   BQ; ;RRc                     UR                  U R                  [        S   S-
  5      nUR                  U R                  [        S   S-
  5      nSU SU S3$ )Nr   r   zfloor(/r   r   r   s       r>   _ccodeFloorDiv._ccode&  sW    ##DIIz&/AC/GH&&t||Z5G#5MNvQwiq))r@   r[   )__name__
__module____qualname____firstlineno____doc__r   tuplerc   __annotations__r   r   boolpropertyrH   rw   r   r   printing
StrPrinterstrr   classmethodrd   r   r   r   __static_attributes__r[   r@   r>   r    r       s     "E5c?!JJekk     &!:!: &s & P==P+0==P	u{{D 	!P Pd*r@   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                      4S j5       rS\\
   4S jr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   c                    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)rH   r   r   rG   rd   rp   r!   r   r   rn   rC   ra   r   r;   sumr    )r   r   r   r   rp   	new_termsall_positiver   s           r>   r   ModularIndexing.eval5  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   )rC   r\   is_nonnegativer   r]   r^   s      r>   _eval_is_nonnegative$ModularIndexing._eval_is_nonnegativej  s,    yy!}((!*:*:;;r@   c                 d    U R                   S S u  p[        UR                  UR                  5      $ r   )rC   r\   is_positiver   s      r>   _eval_is_positive!ModularIndexing._eval_is_positiven  s(    yy!}q}}55r@   r[   N)r   r   r   r   r   r   r   rc   r   r   r   r   r   rH   rd   r   rw   r   r   r   r   r[   r@   r>   r!   r!   ,  s     "E5c?!JJ2==2+0==2CH==2	%++	2 2h<htn <68D> 6r@   r!   c            
           \ rS rSr% SrSr\\S4   \S'   Sr	\\S'   S\
\   4S	 jrS\
\   4S
 jrS\
\   4S jr\S\R"                  S\R"                  S\R"                  S\
\R"                     4S j5       rSrg)r"   is  z
Good ol' ternary operator
r   .r   r   r   r7   c                     U R                   S   R                  (       a   U R                   S   R                  (       a  S$ S $ Nr   r9   TrC   r   r   s    r>   _eval_is_integerWhere._eval_is_integer{  s.    yy|..499Q<3J3JtTPTTr@   c                     U R                   S   R                  (       a   U R                   S   R                  (       a  S$ S $ r   )rC   r   r   s    r>   r   Where._eval_is_nonnegative~  s9     yy|**tyy|/J/J 	
 	
r@   c                     U R                   S   R                  (       a   U R                   S   R                  (       a  S$ S $ r   rC   r   r   s    r>   r   Where._eval_is_positive  s.    yy|//DIIaL4L4LtVRVVr@   cr]   r^   c                 \    U[         R                  :X  a  U$ U[         R                  :X  a  U$ g rF   )rH   truefalse)r   r   r]   r^   s       r>   r   
Where.eval  s(     

?H%++Hr@   r[   N)r   r   r   r   r   r   r   rc   r   r   r   r   r   r   r   r   rH   rw   r   r   r[   r@   r>   r"   r"   s  s     "E5c?!JU(4. U
htn 
W8D> W  %05	%++	 r@   r"   c                       \ rS rSr% Sr\\S4   \S'   Sr\\S'   Sr	\
\S'   \S	\R                  S
\R                  S\\R                     4S j5       rS\\
   4S jrS\\
   4S jrSrg)r#   i  r   .r   r   r   Tr   r]   r^   r7   c                    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_oddOner   
is_Booleanr   r   rH   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r@   c                 F    U R                   S   R                  (       a  S$ S $ Nr   Tr   r   s    r>   r   PythonMod._eval_is_nonnegative      yy|//t9T9r@   c                 F    U R                   S   R                  (       a  S$ S $ r   )rC   is_negativer   s    r>   _eval_is_nonpositivePythonMod._eval_is_nonpositive  r   r@   r[   N)r   r   r   r   r   r   rc   r   r   r   r   r   rH   r   r   r   r   r   r   r[   r@   r>   r#   r#     s    !E5c?!JJ*UZZ *EJJ *8EJJ3G * *Z:htn ::htn :r@   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                  (       a/  UR                  (       a  US:  d   U5       eUS:  d   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   r   r   r   r   r   r   r   r   s        r>   r   Mod.eval  s     99#$455 ;!A2w,!q&66M ;;1;;6166165L ;;16yyvvxxuu E<<66M
 u??tDzzammH /<z?r@   r[   N)r   r   r   r   r   r   rc   r   r   r   r   r   r   r[   r@   r>   r$   r$     s-    EJJN) )r@   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[   r@   r>   r%   r%     s    r@   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 rF   )	rH   r   r   rG   r   rd   rf   ceilrQ   r   numbers     r>   r   CeilToInt.eval  sh     ehh''Muxxi&))7Nfell++==5=!9:: ,r@   r[   Nr   r   r   r   r   r   r   r   r[   r@   r>   r&   r&     s    J; ;r@   r&   c                   (    \ rS rSrSr\S 5       rSrg)r'   i  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 rF   )	rH   r   r   rG   rd   r   rf   r   rQ   r  s     r>   r   FloorToInt.eval  sz    ehh''Muxxi((7Nfemm,,Mfell++==E&M!:;; ,r@   r[   Nr  r[   r@   r>   r'   r'     s    J< <r@   r'   c                   "    \ rS rSrSrSrS rSrg)r(   i*  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   )rH   r   rp   r%   r    r   r   r   s      r>   __new__CeilDiv.__new__1  sN    }}T"--(99T#w.D**DaK0'::r@   r[   N)r   r   r   r   r   r   r  r   r[   r@   r>   r(   r(   *  s     J;r@   r(   c                   (    \ rS rSrSr\S 5       rSrg)r+   i:  Tc                 4    US:  a  [        S5      eUSU-  -  $ Nr   znegative shift countr9   )
ValueErrorr   r   shifts      r>   r   LShift.eval=  s#    19344ahr@   r[   Nr  r[   r@   r>   r+   r+   :  s    J r@   r+   c                   (    \ rS rSrSr\S 5       rSrg)r,   iD  Tc                 B    US:  a  [        S5      e[        USU-  5      $ r  )r  r    r  s      r>   r   RShift.evalG  s&    19344ah''r@   r[   Nr  r[   r@   r>   r,   r,   D  s    J( (r@   r,   c                      \ rS rSrS r\S\\\R                  R                  R                        4S j5       r\ S&S\\\R                  R                  R                        S\\\R                  R                  R                        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)'
MinMaxBaseiN  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rF   r   )rK   rh   s     r>   rM   %MinMaxBase.__new__.<locals>.<genexpr>S  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   rC   r(  objs           r>   r  MinMaxBase.__new__O  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   c                 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   r(  )r;   rG   r  r?   _unique_symbolsgetattr)r   rC   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r@   N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)setatomsrG   rH   coresymbolSymboladd)r   rC   r4  seen_symbolsrh   elements         r>   r.  MinMaxBase._unique_symbols  sk     !, 3suC99;!'5::+<+<+C+CDD, $$W- '  r@   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)rG   MinMaxrC   func)airL   condir   dos       r>   rG  *MinMaxBase._collapse_arguments.<locals>.do  s    b3*--	<Dww277 ;7aA7 ;LeLL"c""ww277 E7a1fA7 EVPUVVH !< Es   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      $ rF   )rG   )rh   others    r>   <lambda>GMinMaxBase._collapse_arguments.<locals>.factor_minmax.<locals>.<lambda>3  s    :c5#9r@   T)binaryr   F)r   r6  rC   intersectionrx   ry   r   )rC   is_other
other_argsremaining_argsrh   arg_setscommonnew_other_argsarg_setarg_sets_diffsother_args_diffother_args_factoredr   rK  s                r>   factor_minmax5MinMaxBase._collapse_arguments.<locals>.factor_minmax2  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   rA  rB  	is_numberr   rC   is_comparablerG   r   r&  ranger;   	enumerate)r   rC   r*  siftedminsmaxsrF  vsmallbigrh   TrL   a0rD  r[  rG  rK  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)rG   r   is_extended_realr]  r^  r  r#  r   r&  rC  rC   )r   arg_sequencerh   s      r>   r"  MinMaxBase._new_args_filterO  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   )r6  r   rB  maxrA  minAssertionErrorr;  r;   nextiterr   r   )r   valuesoptionsother_values	num_valuerh   other_values          r>   r%  MinMaxBase._find_localzerosj  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#r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_algebraicrK   rF  s     r>   rM   &MinMaxBase.<lambda>.<locals>.<genexpr>       (HAr  r   rC   rX  s    r>   rL  MinMaxBase.<lambda>      5(H(H#Hr@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_antihermitianr}  s     r>   rM   r~          -$*qFr  r  r  s    r>   rL  r        u -$%FF- (r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_commutativer}  s     r>   rM   r~          +"(Q&r  r  r  s    r>   rL  r        U +"#&&+ &r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )
is_complexr}  s     r>   rM   r~         &DV||Vr  r  r  s    r>   rL  r        &DQVV&D!Dr@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_compositer}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )r   r}  s     r>   rM   r~         #>v!IIvr  r  r  s    r>   rL  r        e#>qvv#>>r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )	is_finiter}  s     r>   rM   r~    s     %B6akk6r  r  r  s    r>   rL  r    s    %B166%B Br@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_hermitianr}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_imaginaryr}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_infiniter}  s     r>   rM   r~         'Fv!vr  r  r  s    r>   rL  r        %'Fqvv'F"Fr@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )r   r}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_irrationalr}  s     r>   rM   r~         )J6a//6r  r  r  s    r>   rL  r        E)J166)J$Jr@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   r   r}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_nonintegerr}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   r   r}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_nonpositiver}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )
is_nonzeror}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )r   r}  s     r>   rM   r~    s     "<V88Vr  r  r  s    r>   rL  r    s    U"<QVV"<<r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_polarr}  s     r>   rM   r~         $@AZZr  r  r  s    r>   rL  r        u$@$@@r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   r   r}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_primer}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_rationalr}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_realr}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )rk  r}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )is_transcendentalr}  s     r>   rM   r~    s      .%+Vr  r  r  s    r>   rL  r    s     .%&VV. )r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   )r   r}  s     r>   rM   r~    r  r  r  r  s    r>   rL  r    r  r@   r[   rF   ),r   r   r   r   r  r   r   r6  rH   r8  r9  r:  r   r.  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[   r@   r>   r  r  N  s   +Z 5	#ejj''../	05 5n JN (UZZ->->-E-E)F G	#ejj''../	0 $ E EN  4 , ,\ I EH>MBOHHFDJFJ E<L@NF@NF>M ?Mr@   r  c                   Z    \ rS rSrSr\R                  r\R                  r	S r
S rS rSrg)rB  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rF   r  rJ   s     r>   rM   (Max._eval_is_positive.<locals>.<genexpr>       9y!yr  r   rC   r   s    r>   r   Max._eval_is_positive      9tyy999r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   r  rJ   s     r>   rM   +Max._eval_is_nonnegative.<locals>.<genexpr>  s     <)Q(()r  r  r   s    r>   r   Max._eval_is_nonnegative  s    <$))<<<r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   r  rJ   s     r>   rM   (Max._eval_is_negative.<locals>.<genexpr>       :	1	r  r   rC   r   s    r>   r  Max._eval_is_negative      :		:::r@   r[   N)r   r   r   r   r   r   Infinityr#  NegativeInfinityr&  r   r   r  r   r[   r@   r>   rB  rB    s,     ::D!!H:=;r@   rB  c                   Z    \ rS rSrSr\R                  r\R                  r	S r
S rS rSrg)rA  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rF   r  rJ   s     r>   rM   (Min._eval_is_positive.<locals>.<genexpr>  r  r  r  r   s    r>   r   Min._eval_is_positive  r   r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   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===r@   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frF   r  rJ   s     r>   rM   (Min._eval_is_negative.<locals>.<genexpr>  r  r  r  r   s    r>   r  Min._eval_is_negative  r  r@   r[   N)r   r   r   r   r   r   r  r#  r  r&  r   r   r  r   r[   r@   r>   rA  rA    s,     DzzH;>:r@   rA  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&&&r@   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Mr@   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 rF   )
rG   rH   rd   r  r   Powr   r   r   zoo)r   r   r  rR   s       r>   r   PowByNatural.eval  s    dEMM**z#u}}/M/M#AfWf%%==##c5==)) 99T''6588$$""!!yy  " %r@   r[   N)r   r   r   r   r   r   rc   r   r   r   r   r[   r@   r>   r4   r4     s#    JJ! !r@   r4   c                   8    \ rS rSr% SrSr\\S'   \S 5       r	Sr
g)r3   i#  T<   r   c                     [        U[        R                  5      (       aK  [        U[        R                  5      (       a+  [        R                  " [	        U5      [	        U5      -  5      $ g g rF   )rG   rH   r   rI   rQ   )r   r   r  s      r>   r   FloatPow.eval(  sJ     dELL))jell.K.K;;uT{eCj899 /L)r@   r[   Nr   r   r   r   r  r   rc   r   r   r   r   r[   r@   r>   r3   r3   #  s#    GJ: :r@   r3   c                   8    \ rS rSr% SrSr\\S'   \S 5       r	Sr
g)r*   i9  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   rG   rH   r   rI   rQ   r
  s      r>   r   FloatTrueDiv.eval>  s]    
 ??#$677dELL))j%,,.O.O;;uT{U7^;<< /P)r@   r[   Nr%  r[   r@   r>   r*   r*   9  s#    GJ= =r@   r*   c                   8    \ rS rSr% SrSr\\S'   \S 5       r	Sr
g)r)   iR  Tr   r   c                    UR                   (       a  [        S5      e[        U[        R                  5      (       a  [        U[        R                  5      (       a  U[
        [
        * [        R                  [        R                  * 4;   d0  U[
        [
        * [        R                  [        R                  * 4;   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   rG   rH   r   r   r   rI   rQ   rd   rc   r
  s      r>   r   IntTrueDiv.evalW  s    ??#$677 tU\\**7ELL11&%((UXXI>>vw588)DD
 ;;uT{U7^;<<dEMM**z'5==/Q/Q;;s4y3w<788 0R*r@   r[   Nr%  r[   r@   r>   r)   r)   R  s#    GJ9 9r@   r)   c                   (    \ rS rSrSr\S 5       rSrg)r-   iq  Tc           	         [        U5      S-  S:X  d   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:w  d   e[        [        [        X45      [        R                  " S5      S9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   )!eval_is_non_overlapping_and_densec              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frF   rG   rH   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rF   r1  rJ   s     r>   rM   r2    s     =Wz!U]]++WrO   )keyc              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frF   r1  rJ   s     r>   rM   r2    s     FA:a//rO   r   )*   )
r;   %torch.fx.experimental.symbolic_shapesr/  ry   rc   r   zipsortedoperator
itemgetter)	r   rC   dimsizesstridesr/  rL   s_sizes	s_stridess	            r>   r   &IsNonOverlappingAndDenseIndicator.evalt  s   4y1}!!!$i1nQst*	
 :T:::4!&'AQ'')B'Q#a&')B  !8qz##
aQx!!eAhl =W===!8O8 "%E+1D1DQ1GH"G F"FFF!#2,. 9%,-WSVW-	/J	1A	/J  G ()B@ ./Js   E6*E;
>F F
r[   Nr  r[   r@   r>   r-   r-   q  s    J0 0r@   r-   c                   (    \ rS rSrSr\S 5       rSrg)r.   i  Tc                     [        U[        R                  5      (       a3  [        R                  " [        R
                  " [        U5      5      5      $ g rF   )rG   rH   r   rI   rf   truncrQ   r  s     r>   r   TruncToFloat.eval  s8     fell++ ;;tzz%-899	 ,r@   r[   Nr   r   r   r   r  r   r   r   r[   r@   r>   r.   r.     s    G: :r@   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 rF   )	rH   r   r   rG   r   rd   rf   rD  rQ   r  s     r>   r   TruncToInt.eval  sh     ehh''Muxxi&))7Nfell++==E&M!:;; ,r@   r[   Nr  r[   r@   r>   r/   r/     s    J< <r@   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   )rH   r   r   rG   r   rd   roundrQ   r  s     r>   r   RoundToInt.eval  sZ     UXXMehhY7Nfell++==uV}a!899 ,r@   r[   Nr  r[   r@   r>   r0   r0     s    J: :r@   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 rF   )rG   rH   r   rd   rI   rL  rQ   rc   )r   r  ndigitss      r>   r   RoundDecimal.eval  sL     fell++
7EMM0R0R;;uU6]CLABB 1S+r@   r[   NrF  r[   r@   r>   r1   r1     s    GC Cr@   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 rF   )rH   r   rG   rd   rI   rc   r   r  s     r>   r   ToFloat.eval  sn    ehh	**Mfemm,,;;s6{++V88OfWHH9 r@   r[   NrF  r[   r@   r>   r2   r2     s    G	 	r@   r2   c                   4    \ rS rSrSrSrS rS rS rS r	Sr
g	)
r5   i  z,
Prevents expansion and other optimizations

   c                 (    SU R                   S    S3$ )Nz	Identity(r   r   r   r   s    r>   __repr__Identity.__repr__  s    499Q<.**r@   c                 4    U R                   S   R                  $ r   )rC   r  r   s    r>   r  Identity._eval_is_real  s    yy|###r@   c                 4    U R                   S   R                  $ r   r   r   s    r>   r   Identity._eval_is_integer  s    yy|&&&r@   c                      U R                   S   $ r   r   )r   hintss     r>   _eval_expand_identityIdentity._eval_expand_identity  r   r@   r[   N)r   r   r   r   r   r   rX  r  r   r`  r   r[   r@   r>   r5   r5     s"     J+$'r@   r5   c                 b   ^   " U 4S jS[         R                  5      nST -   nX!l        X!l        U$ )Nc                   6   > \ rS rSrSr Y 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 optimziations
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   )rG   rH   rd   rI   r/  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_namer   r   r   )ri  s   r>   OpaqueUnaryFnrd    s"    	 #		 
	r@   rl  OpaqueUnaryFn_)rH   Functionr   r   )ri  rl  nms   `  r>   make_opaque_unary_fnrp    s2    # #J 
D	 B!#r@   sqrtcoscoshsinsinhtantanhasinacosatanr  rh  asinhrf  c                    ^ ^^ 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 -   Ul        U$ )	Nbitwise_and
BitwiseAnd
bitwise_or	BitwiseOrzunrecognized c                   D   > \ rS rSr%  Y r Yr\\S'   \U4S j5       r	Sr
g))make_opaque_bitwise_fn.<locals>.BitwiseFniY  r   c                 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   r/  r:  rH   rd   rG   rc   )r   rL   breal_op_names      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r@   r[   N)r   r   r   r   rk  r   rc   r   r   r   r   )ri  precr  s   r>   	BitwiseFnr  Y  s%    "
C		 
	r@   r  
BitwiseFn_)r   rq  rH   rn  r   )ri  r  r  r  s   `` @r>   make_opaque_bitwise_fnr  Q  sc    },'		+&}TF344 ENN $ &,Ir@   r}  and_r  or_)crU   rf   r:  r  typingr   r   r   r   r   r   typing_extensionsr	   r
   rH   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   numbersr   collections.abcr   r   r   __all__r   r?   rI   rW   r\   rw   r|   rn  r    r!   r"   r#   r$   r%   r&   r'   r(   r+   r,   r  rB  rA  r  r  r4   r3   r*   r)   r-   r.   r/   r0   r1   r2   r5   rp  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_orr[   r@   r>   <module>r     st      
 S S 2      + 7 7 + 9 & % 0 *  ( T'5B4uzz d r!"vc{mU2u{{?334 8D> htn )5;; )5;; )5;; )|r*u~~ r*jD6enn D6NENN B8: 8:x1%.. 1hx ; ;< <;enn ; U^^ (U^^ (p?y p?f;*k ;$:*k :$'4!5>> !6:u~~ :,=5>> =29 9>4 4p
:5>> 
:< <: :<C5>> Cenn  u~~ **\ *&1 (/ )&1 (/ )&1 (/ )&1 )&1 )&1 )&1 (/ (/ *73 )&1 < /}fE -lEB r@   