+
    ‹°³j}  ã                   óŒ   € R t ^ RIHt  ! R R4      t ! R R4      t ! R R4      tRR	 ltR
 tR tR t	R t
R tR tR tR tR# )aF  Generic Unification algorithm for expression trees with lists of children

This implementation is a direct translation of

Artificial Intelligence: A Modern Approach by Stuart Russel and Peter Norvig
Second edition, section 9.2, page 276

It is modified in the following ways:

1.  We allow associative and commutative Compound expressions. This results in
    combinatorial blowup.
2.  We explore the tree lazily.
3.  We provide generic interfaces to symbolic algebra libraries in Python.

A more traditional version can be found here
http://aima.cs.berkeley.edu/python/logic.html
)Úkbinsc                   ó<   a € ] tR t^t o RtR tR tR tR tRt	V t
R# )ÚCompoundziA little class to represent an interior node in the tree

This is analogous to SymPy.Basic for non-Atoms
c                ó   € Wn         W n        R # ©N)ÚopÚargs)Úselfr   r   s   &&&ÚQ/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/unify/core.pyÚ__init__ÚCompound.__init__   s   € ØŒØŽ	ó    c                ó²   € \        V 4      \        V4      J ;'       d;    V P                  VP                  8H  ;'       d    V P                  VP                  8H  # r   )Útyper   r   ©r	   Úothers   &&r
   Ú__eq__ÚCompound.__eq__   sJ   € Ü�T“
œd 5›kÐ)÷ (ð (¨d¯g©g¸¿¹Ñ.A÷ (ð (Ø—	‘	˜UŸZ™ZÑ'ð	)r   c                óX   € \        \        V 4      V P                  V P                  34      # r   )Úhashr   r   r   ©r	   s   &r
   Ú__hash__ÚCompound.__hash__"   s    € Ü”T˜$“Z §¡¨$¯)©)Ð4Ó5Ð5r   c                óŠ   € \        V P                  4      : R RP                  \        \         V P                  4      4      : R2# )Ú[z, Ú])Ústrr   ÚjoinÚmapr   r   s   &r
   Ú__str__ÚCompound.__str__%   s)   € Ü˜tŸw™wž<¨¯©´3´s¸D¿I¹IÓ3FÖ)GÐHÐHr   )r   r   N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r
   r   r      s%   ø‡ € ñòò)ò6÷Ið Ir   r   c                   ó<   a € ] tR t^(t o RtR tR tR tR tRt	V t
R# )ÚVariablezA Wild token c                ó   € Wn         R # r   ©Úarg)r	   r/   s   &&r
   r   ÚVariable.__init__*   s   € ØŽr   c                óp   € \        V 4      \        V4      J ;'       d    V P                  VP                  8H  # r   )r   r/   r   s   &&r
   r   ÚVariable.__eq__-   s*   € Ü�D‹zœT %›[Ð(×BÐB¨T¯X©X¸¿¹Ñ-BÐBr   c                óB   € \        \        V 4      V P                  34      # r   )r   r   r/   r   s   &r
   r   ÚVariable.__hash__0   s   € Ü”T˜$“Z §¡Ð*Ó+Ð+r   c                ó:   € R \        V P                  4      ,          # )zVariable(%s)©r   r/   r   s   &r
   r   ÚVariable.__str__3   s   € Ø¤ D§H¡H£Õ-Ð-r   r.   Nr!   r)   s   @r
   r,   r,   (   s"   ø‡ € ÙòòCò,÷.ð .r   r,   c                   ó<   a € ] tR t^6t o RtR tR tR tR tRt	V t
R# )ÚCondVariablezxA wild token that matches conditionally.

arg   - a wild token.
valid - an additional constraining function on a match.
c                ó   € Wn         W n        R # r   ©r/   Úvalid)r	   r/   r<   s   &&&r
   r   ÚCondVariable.__init__<   s   € ØŒØŽ
r   c                ó²   € \        V 4      \        V4      J ;'       d;    V P                  VP                  8H  ;'       d    V P                  VP                  8H  # r   )r   r/   r<   r   s   &&r
   r   ÚCondVariable.__eq__@   sK   € Ü�T“
œd 5›kÐ)÷ *ð *Ø—‘˜EŸI™IÑ%÷*ð *à—
‘
˜eŸk™kÑ)ð	+r   c                óX   € \        \        V 4      V P                  V P                  34      # r   )r   r   r/   r<   r   s   &r
   r   ÚCondVariable.__hash__E   s    € Ü”T˜$“Z §¡¨4¯:©:Ð6Ó7Ð7r   c                ó:   € R \        V P                  4      ,          # )zCondVariable(%s)r6   r   s   &r
   r   ÚCondVariable.__str__H   s   € Ø!¤C¨¯©£MÕ1Ð1r   r;   Nr!   r)   s   @r
   r9   r9   6   s#   ø‡ € ñò
ò+ò
8÷2ð 2r   r9   Nc              +  óŒ  "  € T;'       g    / pW8X  d   Vx € R# \        V \        \        34      '       d   \        WV3/ VB  Rj  x€L
  R# \        V\        \        34      '       d   \        WV3/ VB  Rj  x€L
  R# \        V \        4      '       Edö   \        V\        4      '       Edß   VP                  RR 4      pVP                  RR 4      p\        V P                  VP                  V3/ VB  EF�  pV! V 4      '       Ed#   V! V4      '       Ed   \        V P                  4      \        VP                  4      8  d   W3MW3w  rxV! V 4      '       d1   V! V4      '       d#   \        VP                  VP                  R4      p	M!\        VP                  VP                  R4      p	V	 Fv  w  r«V
 Uu. uF"  p\        \	        VP                  V4      4      NK$  	  ppV Uu. uF"  p\        \	        VP                  V4      4      NK$  	  pp\        WÞV3/ VB  Rj  x€L
  Kx  	  EK5  \        V P                  4      \        VP                  4      8X  g   EKe  \        V P                  VP                  V3/ VB  Rj  x€L
  EK’  	  R# \        V 4      '       dŽ   \        V4      '       d{   \        V 4      \        V4      8X  d`   \        V 4      ^ 8X  d   Vx € R# \        V ^ ,          V^ ,          V3/ VB  F'  p\        V R,          VR,          V3/ VB  Rj  x€L
  K)  	  R# R# R# R#  ELæ EL¶u upi u upi  EL L¾ L%5i)	aÍ  Unify two expressions.

Parameters
==========

    x, y - expression trees containing leaves, Compounds and Variables.
    s    - a mapping of variables to subtrees.

Returns
=======

    lazy sequence of mappings {Variable: subtree}

Examples
========

>>> from sympy.unify.core import unify, Compound, Variable
>>> expr    = Compound("Add", ("x", "y"))
>>> pattern = Compound("Add", ("x", Variable("a")))
>>> next(unify(expr, pattern, {}))
{Variable(a): 'y'}
NÚis_commutativec                 ó   € R # ©F© ©Úxs   &r
   Ú<lambda>Úunify.<locals>.<lambda>k   ó   € ¹Ur   Úis_associativec                 ó   € R # rG   rH   rI   s   &r
   rK   rL   l   rM   r   ÚcommutativeÚassociative:é   NN)Ú
isinstancer,   r9   Ú	unify_varr   ÚgetÚunifyr   Úlenr   ÚallcombinationsÚunpackÚis_args)rJ   ÚyÚsÚfnsrE   rN   ÚsopÚaÚbÚcombsÚaaargsÚbbargsr/   ÚaaÚbbÚsheads   &&&,            r
   rV   rV   K   sw  é € ð. 	
�ˆˆR€Aà„vØŒÜ	�Aœ¤,Ð/×	0Ò	0Ü˜Q 1Ñ,¨Ñ,×,Ò,Ü	�Aœ¤,Ð/×	0Ò	0Ü˜Q 1Ñ,¨Ñ,×,Ò,Ü	�A”x×	 Ó	 ¤Z°´8×%<Ó%<ØŸ™Ð!1±?ÓCˆØŸ™Ð!1±?ÓCˆÜ˜Ÿ™˜qŸt™t QÑ.¨#Õ.ˆCÙ˜a× Ó ¡^°A×%6Ó%6Ü!$ Q§V¡V£¬s°1·6±6«{Ô!:˜‘vÀÀ‘�Ù! !×$Ò$©¸×):Ò):Ü+¨A¯F©F°A·F±F¸MÓJ‘Eä+¨A¯F©F°A·F±F¸MÓJ�EÛ&+‘N�FÙAGÓHÁ¸#œ&¤¨!¯$©$°Ó!4Ö5Á�BÐHÙAGÓHÁ¸#œ&¤¨!¯$©$°Ó!4Ö5Á�BÐHÜ$ R¨SÑ8°CÑ8×8Ò8ô ',ô �Q—V‘V“¤ A§F¡F£×+Ü  §¡¨¯©°Ñ<¸Ñ<×<Ó<ó /ô 
��Šœ Ÿ
š
¤s¨1£v´°Q³Ô'7Üˆq‹6�QŒ;ØŒGä˜q �t Q q¥T¨1Ñ4°Ô4�Ü   2¥¨¨"­¨uÑ<¸Ñ<×<Ò<ó 5ñ	 (8™
‰ò) 	-â,ùò IùÚHÚ8á<ñ =ùsˆ   ‚AMÁL-Á2MÁ:L0Á;BMÄAMÅ*AMÆ8(L3Ç MÇ&(L8ÈMÈ L=È!5MÉ%MÊM ÊBMÌMÌMÌ0MÌ3MÍ MÍMc              +   óD  "  € W9   d   \        W ,          W3/ VB  R j  x€L
  R # \        W4      '       d   R # \        V \        4      '       d(   V P	                  V4      '       d   \        W V4      x € R # \        V \        4      '       d   \        W V4      x € R # R #  L~5ir   )rV   Úoccur_checkrS   r9   r<   Úassocr,   )ÚvarrJ   r\   r]   s   &&&,r
   rT   rT   ‚   sy   é € Ø
„xÜ˜� Ñ-¨Ñ-×-Ò-Ü	�S×	Ò	ÙÜ	�Cœ×	&Ò	&¨3¯9©9°Q¯<ª<Ü�A˜AÓÔÜ	�Cœ×	"Ò	"Ü�A˜AÓÔñ 
#ñ 	.ùs   ‚B ŸB AB Á&9B c                ó  a € S V8X  d   R# \        V\        4      '       d   \        S VP                  4      # \	        V4      '       dC   \
        ;QJ d    V 3R lV 4       F  '       g   K   RM	  RM! V 3R lV 4       4      '       d   R# R# )z"var occurs in subtree owned by x? Tc              3   ó<   <"  € T F  p\        SV4      x € K  	  R # 5ir   )rh   )Ú.0Úxirj   s   & €r
   Ú	<genexpr>Úoccur_check.<locals>.<genexpr>“   s   øé € Ð0©a¨Œ{˜3 ×#Ð#«aùs   ƒF)rS   r   rh   r   rZ   Úany)rj   rJ   s   f&r
   rh   rh   Œ   sZ   ø€ à
ˆa„xÙÜ	�A”x×	 Ò	 Ü˜3 §¡Ó'Ð'Ü	��Šß‹3Ô0©aÓ0�3�3Š3Ô0©aÓ0×0Ò0¹Ùr   c                ó.   € V P                  4       p W V&   V # )z,Return copy of d with key associated to val )Úcopy)ÚdÚkeyÚvals   &&&r
   ri   ri   –   s   € à	�‰‹€AØ€c�FØ€Hr   c                ó<   € \        V 4      \        \        \        39   # )zIs x a traditional iterable? )r   ÚtupleÚlistÚsetrI   s   &r
   rZ   rZ   œ   s   € ä�‹7”uœd¤CÐ(Ñ(Ð(r   c                 óŒ   € \        V \        4      '       d.   \        V P                  4      ^8X  d   V P                  ^ ,          # V # )rR   )rS   r   rW   r   rI   s   &r
   rY   rY       s1   € Ü�!”X×Ò¤3 q§v¡v£;°!Ô#3Ø�v‰v�a�yÐàˆr   c           	   #  óÚ  "  € VR8X  d   ^pVR8X  d   Rp\        V 4      \        V4      8  d   W3MW3w  r4\        \        \        \        V4      4      4      \        V4      VR7       F}  pWA8X  d<   \        ;QJ d    . R V  4       F  NK  	  5M! R V  4       4      \        W4      3x € KD  \        W4      \        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      3x € K  	  R# 5i)a¨  
Restructure A and B to have the same number of elements.

Parameters
==========

ordered must be either 'commutative' or 'associative'.

A and B can be rearranged so that the larger of the two lists is
reorganized into smaller sublists.

Examples
========

>>> from sympy.unify.core import allcombinations
>>> for x in allcombinations((1, 2, 3), (5, 6), 'associative'): print(x)
(((1,), (2, 3)), ((5,), (6,)))
(((1, 2), (3,)), ((5,), (6,)))

>>> for x in allcombinations((1, 2, 3), (5, 6), 'commutative'): print(x)
    (((1,), (2, 3)), ((5,), (6,)))
    (((1, 2), (3,)), ((5,), (6,)))
    (((1,), (3, 2)), ((5,), (6,)))
    (((1, 3), (2,)), ((5,), (6,)))
    (((2,), (1, 3)), ((5,), (6,)))
    (((2, 1), (3,)), ((5,), (6,)))
    (((2,), (3, 1)), ((5,), (6,)))
    (((2, 3), (1,)), ((5,), (6,)))
    (((3,), (1, 2)), ((5,), (6,)))
    (((3, 1), (2,)), ((5,), (6,)))
    (((3,), (2, 1)), ((5,), (6,)))
    (((3, 2), (1,)), ((5,), (6,)))
rP   rQ   N)Úorderedc              3   ó&   "  € T F  q3x € K	  	  R # 5ir   rH   )rm   r_   s   & r
   ro   Ú"allcombinations.<locals>.<genexpr>Ð   s   é € Ð(¡a �£aùó   ‚c              3   ó&   "  € T F  q3x € K	  	  R # 5ir   rH   )rm   r`   s   & r
   ro   r   Ò   s   é € Ð+<¹!°Q­D»!ùr€   )rW   r   ry   Úrangerx   Ú	partition)ÚAÚBr}   ÚsmÚbgÚparts   &&&   r
   rX   rX   ¦   s¹   é € ðF �-ÔØˆØ�-ÔØˆÜ˜1“v¤ A£”ˆa‰V¨Q¨F�F€BÜ”dœ5¤ R£›>Ó*¬C°«G¸W×EˆØŒ7ß”%Ñ(¡aÓ(—%‘%Ñ(¡aÓ(Ó(¬)°AÓ*<Ð<Ô<ä˜AÓ$§e¤eÑ+<¹!Ó+<§e¡eÑ+<¹!Ó+<Ó&<Ð<Ô<ó	 Fùs   ‚A9C+Á<A/C+c           	     ó`   € \        V 4      ! V Uu. uF  p\        W4      NK  	  up4      # u upi )z¾Partition a tuple/list into pieces defined by indices.

Examples
========

>>> from sympy.unify.core import partition
>>> partition((10, 20, 30, 40), [[0, 1, 2], [3]])
((10, 20, 30), (40,))
)r   Úindex)Úitrˆ   Úinds   && r
   rƒ   rƒ   Ô   s)   € ô �Œ8©tÓ4©t¨”U˜2–^©tÑ4Ó5Ð5ùÒ4s   �+c                óZ   € \        V 4      ! V Uu. uF  q V,          NK  	  up4      # u upi )z¤Fancy indexing into an indexable iterable (tuple, list).

Examples
========

>>> from sympy.unify.core import index
>>> index([10, 20, 30], (1, 2, 0))
[20, 30, 10]
)r   )r‹   rŒ   Úis   && r
   rŠ   rŠ   à   s)   € ô �Œ8¡CÓ(¡C˜q˜—U�U¡CÑ(Ó)Ð)ùÒ(s   �(r   )r&   Úsympy.utilities.iterablesr   r   r,   r9   rV   rT   rh   ri   rZ   rY   rX   rƒ   rŠ   rH   r   r
   Ú<module>r�      s^   ðñõ$ ,÷Iñ I÷&.ñ .÷2ñ 2ô*5=ònòòò)òò,=ò\
6ô
*r   