o
    Zh                     @   s   d dl mZ ddlmZ ddlmZ e ZeZG dd dZdd Z	d	d
 Z
eedd Ze eedd Zedd ZdS )    )contextmanager   )dispatch)hashablec                   @   s8   e Zd ZdZdZdd Zdd ZeZdd Zd	d
 Z	dS )VarzLogic Variabler   c                 G   sP   t |dkrdtj }t jd7  _n
t |dkr|d }t| }||_|S )Nr   _r   )lenr   _idobject__new__token)clsr   obj r   Y/var/www/auris/lib/python3.10/site-packages/torch/fx/experimental/unification/variable.pyr      s   
zVar.__new__c                 C   s   dt | j S )N~)strr   selfr   r   r   __str__   s   zVar.__str__c                 C   s   t | t |ko| j|jkS N)typer   )r   otherr   r   r   __eq__!   s   z
Var.__eq__c                 C   s   t t| | jfS r   )hashr   r   r   r   r   r   __hash__$   s   zVar.__hash__N)
__name__
__module____qualname____doc__r	   r   r   __repr__r   r   r   r   r   r   r      s    r   c                   C      dd S )Nc                  W   s   t |  S r   )r   )argsr   r   r   <lambda>)   s    zvar.<locals>.<lambda>r   r   r   r   r   var(      r$   c                   C   r!   )Nc                 S   s   dd t | D S )Nc                 S   s   g | ]}t  qS r   )r$   ).0ir   r   r   
<listcomp>-       z*vars.<locals>.<lambda>.<locals>.<listcomp>)range)nr   r   r   r#   -   r)   zvars.<locals>.<lambda>r   r   r   r   r   vars,   r%   r,   c                 C   s   dS )NTr   )vr   r   r   isvar0   s   r.   c                 C   s   t   ot| o| t v S r   )_glvr   )or   r   r   r.   8   s   c               	   g   sL    t  }t t|  zdV  W t   t | dS t   t | w )a  
    Context manager for logic variables

    Example:
        >>> # xdoctest: +SKIP("undefined vars")
        >>> from __future__ import with_statement
        >>> with variables(1):
        ...     print(isvar(1))
        True
        >>> print(isvar(1))
        False
        >>> # Normal approach
        >>> from unification import unify
        >>> x = var("x")
        >>> unify(x, 1)
        {~x: 1}
        >>> # Context Manager approach
        >>> with variables("x"):
        ...     print(unify("x", 1))
        {'x': 1}
    N)_global_logic_variablescopyupdatesetclear)	variablesZold_global_logic_variablesr   r   r   r6   =   s   r6   N)
contextlibr   r   utilsr   r4   r1   r/   r   r$   r,   r.   r
   r6   r   r   r   r   <module>   s   

