+
    =åûj4  ã                   ód   € R t ^ RIHt ^RIHt ]3R ltR t]3R ltR tR t	R t
]3R	 ltR
 tR# )zOGeneric Rules for SymPy

This file assumes knowledge of Basic and little else.
)Úsift)Únewc                ó   a a€ V V3R lpV# )a�  Create a rule to remove identities.

isid - fn :: x -> Bool  --- whether or not this element is an identity.

Examples
========

>>> from sympy.strategies import rm_id
>>> from sympy import Basic, S
>>> remove_zeros = rm_id(lambda x: x==0)
>>> remove_zeros(Basic(S(1), S(0), S(2)))
Basic(1, 2)
>>> remove_zeros(Basic(S(0), S(0))) # If only identities then we keep one
Basic(0)

See Also:
    unpack
c           	     óx  <€ \        \        SV P                  4      4      p\        V4      ^ 8X  d   V # \        V4      \	        V4      8w  dG   S! V P
                  .\        V P                  V4       UUu. uF  w  r#V'       d   K  VNK  	  uppO5!  # S! V P
                  V P                  ^ ,          4      # u uppi )zRemove identities )ÚlistÚmapÚargsÚsumÚlenÚ	__class__Úzip)ÚexprÚidsÚargÚxÚisidr   s   &   €€ÚOC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\sympy\strategies\rl.pyÚident_removeÚrm_id.<locals>.ident_remove   s™   ø€ ä”3�t˜TŸY™YÓ'Ó(ˆÜˆs‹8�qŒ=ØˆKÜ�‹Xœ˜S›Ô!Ù�t—~‘~ð JÜ+.¨t¯y©y¸#Ô+>ÔHÑ+>¡ ÄaŸ˜Ñ+>ÒHóJð Jñ �t—~‘~ t§y¡y°¥|Ó4Ð4ùó Is   Á3B6ÂB6© )r   r   r   s   ff r   Úrm_idr   
   s   ù€ ö&	5ð Ðó    c                ó   a aa€ VVV 3R lpV# )aé  Create a rule to conglomerate identical args.

Examples
========

>>> from sympy.strategies import glom
>>> from sympy import Add
>>> from sympy.abc import x

>>> key     = lambda x: x.as_coeff_Mul()[1]
>>> count   = lambda x: x.as_coeff_Mul()[0]
>>> combine = lambda cnt, arg: cnt * arg
>>> rl = glom(key, count, combine)

>>> rl(Add(x, -x, 3*x, 2, 3, evaluate=False))
3*x + 5

Wait, how are key, count and combine supposed to work?

>>> key(2*x)
x
>>> count(2*x)
2
>>> combine(2, x)
2*x
c                ó~  <€ \        V P                  S
4      pVP                  4        UUu/ uF  w  r#V\        \	        S	V4      4      bK  	  pppVP                  4        UUu. uF  w  rVS! We4      NK  	  ppp\        V4      \        V P                  4      8w  d   \        \        V 4      .VO5!  # V # u uppi u uppi )z1Conglomerate together identical args x + x -> 2x )r   r   Úitemsr	   r   Úsetr   Útype)r   ÚgroupsÚkr   ÚcountsÚmatÚcntÚnewargsÚcombineÚcountÚkeys   &       €€€r   ÚconglomerateÚglom.<locals>.conglomerateF   s—   ø€ ä�d—i‘i Ó%ˆØ:@¿,¹,¼.ÔI¹.©w¨q�!”Sœ˜U DÓ)Ó*Ò*¹.ˆÑIØ5;·\±\´^ÔD±^©¨‘7˜3Ö$±^ˆÑDÜˆw‹<œ3˜tŸy™y›>Ô)Ü”t˜D“zÐ, GÓ,Ð,àˆKùó JùÛDs   «!B3Á"B9r   )r%   r$   r#   r&   s   fff r   Úglomr(   +   s   ú€ ÷6ð Ðr   c                ó   a a€ V V3R lpV# )zÎCreate a rule to sort by a key function.

Examples
========

>>> from sympy.strategies import sort
>>> from sympy import Basic, S
>>> sort_rl = sort(str)
>>> sort_rl(Basic(S(3), S(1), S(2)))
Basic(1, 2, 3)
c                 óV   <€ S! V P                   .\        V P                  SR 7      O5!  # ))r%   )r   Úsortedr   )r   r%   r   s   &€€r   Úsort_rlÚsort.<locals>.sort_rl`   s"   ø€ Ù�4—>‘>Ð?¤F¨4¯9©9¸#Ô$>Ó?Ð?r   r   )r%   r   r,   s   ff r   Úsortr.   S   s   ù€ ö@à€Nr   c                ó   a a€ V V3R lpV# )a*  Turns an A containing Bs into a B of As

where A, B are container types

>>> from sympy.strategies import distribute
>>> from sympy import Add, Mul, symbols
>>> x, y = symbols('x,y')
>>> dist = distribute(Mul, Add)
>>> expr = Mul(2, x+y, evaluate=False)
>>> expr
2*(x + y)
>>> dist(expr)
2*x + 2*y
c           
      óH  <€ \        V P                  4       F‚  w  r\        VS4      '       g   K  V P                  R V V P                  V,          V P                  V^,           R  rTpS! VP                   Uu. uF  pS! W23,           V,           !  NK  	  up!  u # 	  V # u upi ©N)Ú	enumerater   Ú
isinstance)r   Úir   ÚfirstÚbÚtailÚAÚBs   &     €€r   Údistribute_rlÚ!distribute.<locals>.distribute_rlu   sŠ   ø€ Ü §	¡	Ö*‰FˆAÜ˜#˜q×!Ô!Ø!%§¡¨2¨A °·	±	¸!µ¸d¿i¹iÈÈAÍÈÐ>O˜$�ÙÀ!Ç&Â&ÓIÁ&¸3™1˜u v�~°Õ4Ô6Á&ÑIÑJÒJñ +ð ˆùò Js   Á7B
r   )r8   r9   r:   s   ff r   Ú
distributer<   e   s   ù€ ö ð Ðr   c                ó   a a€ V V3R lpV# )zReplace expressions exactly c                 ó   <€ V S8X  d   S# V # r1   r   )r   Úar6   s   &€€r   Úsubs_rlÚsubs.<locals>.subs_rl€   s   ø€ Ø�1Œ9ØˆHàˆKr   r   )r?   r6   r@   s   ff r   ÚsubsrB   ~   s   ù€ öð
 €Nr   c                ó`   € \        V P                  4      ^8X  d   V P                  ^ ,          # V # )z€Rule to unpack singleton args

>>> from sympy.strategies import unpack
>>> from sympy import Basic, S
>>> unpack(Basic(S(2)))
2
)r
   r   ©r   s   &r   ÚunpackrE   ‰   s'   € ô ˆ4�9‰9ƒ~˜ÔØ�y‰y˜�|Ðàˆr   c                óê   € V P                   p. pV P                   FB  pVP                   V8X  d   VP                  VP                  4       K1  VP                  V4       KD  	  V! V P                   .VO5!  # )z8Flatten T(a, b, T(c, d), T2(e)) to T(a, b, c, d, T2(e)) )r   r   ÚextendÚappend)r   r   Úclsr   r   s   &&   r   ÚflattenrJ   —   s\   € à
�.‰.€CØ€DØ�yŒyˆØ�=‰=˜CÔØ�K‰K˜Ÿ™Ö!à�K‰K˜Öñ	 ñ
 ˆt�~‰~Ð% Ó%Ð%r   c                óŒ   € V P                   '       d   V # V P                  ! \        \        \        V P
                  4      4      !  # )zÎRebuild a SymPy tree.

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

This function recursively calls constructors in the expression tree.
This forces canonicalization and removes ugliness introduced by the use of
Basic.__new__
)Úis_AtomÚfuncr   r   Úrebuildr   rD   s   &r   rN   rN   £   s1   € ð ‡|‡|€|Øˆà�yŠyœ$œs¤7¨D¯I©IÓ6Ó7Ñ8Ð8r   N)Ú__doc__Úsympy.utilities.iterablesr   Úutilr   r   r(   r.   r<   rB   rE   rJ   rN   r   r   r   Ú<module>rR      sK   ðñõ +Ý ð ô òB%ðP ô ò$ò2òð ô 	&ô9r   