ó
    ‹*£h4  ã                   ób   • S r SSKJr  SSKJr  \4S jrS r\4S jrS rS	 r	S
 r
\4S jrS rg)zOGeneric Rules for SymPy

This file assumes knowledge of Basic and little else.
é    )Úsifté   )Únewc                 ó   ^ ^• U U4S jnU$ )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           	      ój  >• [        [        TU R                  5      5      n[        U5      S:X  a  U $ [        U5      [	        U5      :w  aE  T" U R
                  /[        U R                  U5       VVs/ s H  u  p#U(       a  M  UPM     snnQ76 $ T" U R
                  U R                  S   5      $ s  snnf )zRemove identities r   )ÚlistÚmapÚargsÚsumÚlenÚ	__class__Úzip)ÚexprÚidsÚargÚxÚisidr   s       €€ÚP/home/mande/repo/quber/.venv/lib/python3.13/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   Á1B/ÂB/© )r   r   r   s   `` r   Úrm_idr   
   s   ù€ ö&	5ð Ðó    c                 ó   ^ ^^• UUU 4S jnU$ )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                 ó~  >• [        U R                  T
5      nUR                  5        VVs0 s H  u  p#U[        [	        T	U5      5      _M     nnnUR                  5        VVs/ s H  u  pVT" Xe5      PM     nnn[        U5      [        U R                  5      :w  a  [        [        U 5      /UQ76 $ U $ s  snnf s  snnf )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   ``` r   Úglomr*   +   s   ú€ ÷6ð Ðr   c                 ó   ^ ^• U U4S jnU$ )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                 óN   >• T" U R                   /[        U R                  TS9Q76 $ )N)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   `` r   Úsortr0   S   s   ù€ ö@à€Nr   c                 ó   ^ ^• U U4S jnU$ )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           
      ó$  >• [        U R                  5       Hp  u  p[        UT5      (       d  M  U R                  S U U R                  U   U R                  US-   S  pTnT" UR                   Vs/ s H  nT" X24-   U-   6 PM     sn6 s  $    U $ s  snf )Nr   )Ú	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   Á.B
r   )r9   r:   r;   s   `` r   Ú
distributer=   e   s   ù€ ö ð Ðr   c                 ó   ^ ^• U U4S jnU$ )zReplace expressions exactly c                 ó   >• U T:X  a  T$ U $ )Nr   )r   Úar7   s    €€r   Úsubs_rlÚsubs.<locals>.subs_rl€   s   ø€ Ø�1‹9ØˆHàˆKr   r   )r@   r7   rA   s   `` r   ÚsubsrC   ~   s   ù€ öð
 €Nr   c                 óV   • [        U R                  5      S:X  a  U R                  S   $ U $ )z€Rule to unpack singleton args

>>> from sympy.strategies import unpack
>>> from sympy import Basic, S
>>> unpack(Basic(S(2)))
2
r   r   )r   r
   ©r   s    r   ÚunpackrF   ‰   s'   € ô ˆ4�9‰9ƒ~˜ÓØ�y‰y˜‰|Ðàˆr   c                 óæ   • U R                   n/ nU R                   HA  nUR                   U:X  a  UR                  UR                  5        M0  UR                  U5        MC     U" U R                   /UQ76 $ )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   ÚflattenrK   —   s\   € à
�.‰.€CØ€DØ�yŒyˆØ�=‰=˜CÓØ�K‰K˜Ÿ™Ö!à�K‰K˜Öñ	 ñ
 ˆt�~‰~Ð% Ò%Ð%r   c                 óˆ   • U R                   (       a  U $ U R                  " [        [        [        U R
                  5      5      6 $ )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
   rE   s    r   rO   rO   £   s/   € ð ‡|‡|Øˆà�yŠyœ$œs¤7¨D¯I©IÓ6Ó7Ð8Ð8r   N)Ú__doc__Úsympy.utilities.iterablesr   Úutilr   r   r*   r0   r=   rC   rF   rK   rO   r   r   r   Ú<module>rS      sK   ðñõ +Ý ð ô òB%ðP ô ò$ò2òð ô 	&ó9r   