Ë
    çÍ:j‘e  ã                   ó�  — d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZ  G d„ d	e«      Z G d
„ de«      Z G d„ de«      Z G d„ de«      Zd„ Zd„ Zd&d„Zd„ Z d„ Z!d„ Z"d„ Z# G d„ d«      Z$d'd„Z%d„ Z& G d„ de«      Z' G d„ de«      Z( G d„ d «      Z)d!„ Z*d"„ Z+d#„ Z,d$„ Z-e.d%k(  r e-«        yy)(z;
Module for a resolution-based First Order theorem prover.
é    N)Údefaultdict)Úreduce)ÚBaseProverCommandÚProver)Ú	skolemize)ÚAndExpressionÚApplicationExpressionÚEqualityExpressionÚ
ExpressionÚIndividualVariableExpressionÚNegatedExpressionÚOrExpressionÚVariableÚVariableExpressionÚ	is_indvarÚunique_variablec                   ó   — e Zd Zy)ÚProverParseErrorN)Ú__name__Ú
__module__Ú__qualname__© ó    ún/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/inference/resolution.pyr   r   "   s   „ Ør   r   c                   ó"   — e Zd ZdZdZdd„Zd„ Zy)ÚResolutionProverÚANSWERTNc                 ó¨  — |sg }d}	 g }|r|j                  t        | «      «       |D ]  }|j                  t        |«      «       Œ | j                  |«      \  }}|rt        t        j                  |«      «       ||fS # t        $ rH}| j                  rt        |«      j                  d«      rd}g }n|rt        |«       n|‚Y d}~|fS d}~ww xY w)zÜ
        :param goal: Input expression to prove
        :type goal: sem.Expression
        :param assumptions: Input expressions to use as assumptions in the proof
        :type assumptions: list(sem.Expression)
        Nz maximum recursion depth exceededF)
ÚextendÚclausifyÚ_attempt_proofÚprintÚResolutionProverCommandÚ_decorate_clausesÚRuntimeErrorÚ_assume_falseÚstrÚ
startswith)ÚselfÚgoalÚassumptionsÚverboseÚresultÚclausesÚaÚes           r   Ú_provezResolutionProver._prove*   sÝ   € ñ ØˆKàˆð	ØˆGÙØ—‘œx¨¨›Ô/Ø ò ,�Ø—‘œx¨›{Õ+ð,à"×1Ñ1°'Ó:‰OˆF�GÙÜÔ-×?Ñ?ÀÓHÔIð ˜Ð Ð øô ò 
	Ø×!Ò!¤c¨!£f×&7Ñ&7Ø2ô'ð �Ø‘áÜ˜!•Hà�GûØ˜Ð Ð ûð
	ús   ˆA4B  Â 	CÂ	;CÃCc                 ó
  — t        t        «      }d}|t        |«      k  rá||   j                  «       sº||   r||   d   dz   }n|dz   }|t        |«      k  r–||k7  r}|r{||   j                  «       sh||   j	                  |«       ||   j                  ||   «      }|r;|D ]3  }|dz   |dz   f|_        |j	                  |«       t        |«      rŒ/d|fc S  d}n|dz  }|t        |«      k  rŒ–|dz  }|t        |«      k  rŒád|fS )Nr   éÿÿÿÿé   TF)r   ÚlistÚlenÚis_tautologyÚappendÚunifyÚ_parents)r)   r.   ÚtriedÚiÚjÚ
newclausesÚ	newclauses          r   r!   zResolutionProver._attempt_proofK   s)  € äœDÓ!ˆàˆØ”#�g“,ÒØ˜1‘:×*Ñ*Ô,ð ˜’8Ø˜a™ ™ qÑ(‘Aà˜A™�Aàœ#˜g›,Ò&ð ˜A’v¡!¨G°A©J×,CÑ,CÔ,EØ˜a™Ÿ™¨Ô*Ø%,¨Q¡Z×%5Ñ%5°g¸a±jÓ%A˜
Ù%Ø-7ò ; 	Ø67¸!±e¸QÀ¹U°^ 	Ô 2Ø '§¡¨yÔ 9Ü'*¨9¥~Ø,0°'¨?Ò$:ð	;ð
 !#˜AØ!Ø˜‘F�Að œ#˜g›,Ó&ð �‰FˆAð1 ”#�g“,Óð2 �wÐÐr   )NNF)r   r   r   Ú
ANSWER_KEYr&   r1   r!   r   r   r   r   r   &   s   „ Ø€JØ€Mó!óB r   r   c                   ó4   — e Zd Zdd„Zdd„Zdd„Zed„ «       Zy)r#   Nc                 ó~   — |�t        |t        «      sJ ‚t        «       }t        j                  | |||«       d| _        y)zé
        :param goal: Input expression to prove
        :type goal: sem.Expression
        :param assumptions: Input expressions to use as assumptions in
            the proof.
        :type assumptions: list(sem.Expression)
        N)Ú
isinstancer   r   Ú__init__Ú_clauses)r)   r*   r+   Úprovers       r   rD   z ResolutionProverCommand.__init__m   s>   € ð ÐÜ˜fÔ&6Ô7Ð7Ð7ä%Ó'ˆFä×"Ñ" 4¨°°{ÔCØˆ�r   c                 óö   — | j                   €b| j                  j                  | j                  «       | j	                  «       |«      \  | _         }|| _        t        j                  |«      | _        | j                   S )zh
        Perform the actual proof.  Store the result to prevent unnecessary
        re-proving.
        )	Ú_resultÚ_proverr1   r*   r+   rE   r#   r$   Ú_proof)r)   r,   r.   s      r   ÚprovezResolutionProverCommand.prove}   sd   € ð
 �<‰<ÐØ$(§L¡L×$7Ñ$7Ø—	‘	“˜T×-Ñ-Ó/°ó%Ñ!ˆDŒL˜'ð $ˆDŒMÜ1×CÑCÀGÓLˆDŒKØ�|‰|Ðr   c                 ó†  — | j                  |«       t        «       }t        t        t        j
                  «      «      }| j                  D ]t  }t        |«      dk(  sŒt        |d   t        «      sŒ&|d   j                  |k(  sŒ9t        |d   j                  t        «      rŒW|j                  |d   j                  «       Œv |S )Nr4   r   )rK   Úsetr   r   r   r@   rE   r6   rC   r	   ÚfunctionÚargumentr   Úadd)r)   r,   ÚanswersÚ	answer_exÚclauses        r   Úfind_answersz$ResolutionProverCommand.find_answersŠ   s�   € Ø�
‰
�7Ôä“%ˆÜ&¤xÔ0@×0KÑ0KÓ'LÓMˆ	Ø—m‘mò 	0ˆFä�F“˜qÓ Ü˜v a™yÔ*?Õ@Ø˜1‘I×&Ñ&¨)Ó3Ü" 6¨!¡9×#5Ñ#5Ô7SÕTà—‘˜F 1™I×.Ñ.Õ/ð	0ð ˆr   c                 óâ  — d}t        d„ | D «       «      }t        t        t        | «      «      «      }t        t        | «      «      D ]¦  }d}d}| |   j	                  «       rd}| |   j
                  rt        | |   j
                  «      }d|t        t        | |   «      «      z
  dz   z  |z   }d|t        t        |dz   «      «      z
  z  t        |dz   «      z   }|d|› d| |   › d|› d|› d	�	z  }Œ¨ |S )
z,
        Decorate the proof output.
        Ú c              3   óD   K  — | ]  }t        t        |«      «      –— Œ y ­w©N)r6   r'   )Ú.0rS   s     r   ú	<genexpr>z<ResolutionProverCommand._decorate_clauses.<locals>.<genexpr>Ÿ   s   è ø€ ÒD°&œS¤ V£×-ÑDùs   ‚ ÚAÚ	Tautologyú r4   ú[z] ú
)Úmaxr6   r'   Úranger7   r:   )r.   ÚoutÚmax_clause_lenÚmax_seq_lenr<   ÚparentsÚtautÚseqs           r   r$   z)ResolutionProverCommand._decorate_clauses™   s  € ð
 ˆÜÑD¸GÔDÓDˆÜœ#œc '›lÓ+Ó,ˆÜ”s˜7“|Ó$ò 		>ˆAØˆGØˆDØ�q‰z×&Ñ&Ô(Ø"�Ø�q‰z×"Ò"Ü˜g a™j×1Ñ1Ó2�Ø˜^¬c´#°g¸a±j³/Ó.BÑBÀQÑFÑGÈ'ÑQˆGØ˜¤s¬3¨q°1©u«:£Ñ6Ñ7¼#¸aÀ!¹e»*ÑDˆCØ�Q�s�e˜2˜g a™j˜\¨¨7¨)°1°T°F¸"Ð=Ñ=‰Cð		>ð ˆ
r   )NNN)F)r   r   r   rD   rK   rT   Ústaticmethodr$   r   r   r   r#   r#   l   s%   „ óó óð ñó ñr   r#   c                   ó\   — e Zd Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zy)ÚClausec                 óL   — t         j                  | |«       d | _        d | _        y rX   )r5   rD   Ú_is_tautologyr:   )r)   Údatas     r   rD   zClause.__init__¯   s   € Ü�‰�d˜DÔ!Ø!ˆÔØˆ�r   Nc           	      ó´  — |€
t        «       }|€g g f}|€g g f}t        |t        «      rt        |«      }t	        | ||||t
        |«      }g }t        |«      D ]K  \  }}	||vsŒt        |«      D ]3  \  }
}||
k7  sŒ|
|vsŒ|	j                  |«      sŒ#|j                  |
«       Œ5 ŒM g }t        t        |«      «      D ]  }||vsŒ|j                  ||   «       Œ |S )að  
        Attempt to unify this Clause with the other, returning a list of
        resulting, unified, Clauses.

        :param other: ``Clause`` with which to unify
        :param bindings: ``BindingDict`` containing bindings that should be used
            during the unification
        :param used: tuple of two lists of atoms.  The first lists the
            atoms from 'self' that were successfully unified with atoms from
            'other'.  The second lists the atoms from 'other' that were successfully
            unified with atoms from 'self'.
        :param skipped: tuple of two ``Clause`` objects.  The first is a list of all
            the atoms from the 'self' Clause that have not been unified with
            anything on the path.  The second is same thing for the 'other' Clause.
        :param debug: bool indicating whether debug statements should print
        :return: list containing all the resulting ``Clause`` objects that could be
            obtained by unification
        )ÚBindingDictrC   ÚboolÚDebugObjectÚ_iterate_firstÚ_complete_unify_pathÚ	enumerateÚsubsumesr8   ra   r6   )r)   ÚotherÚbindingsÚusedÚskippedÚdebugr>   Úsubsumedr<   Úc1r=   Úc2r-   s                r   r9   zClause.unify´   sü   € ð& ÐÜ"“}ˆHØˆ<Ø˜�8ˆDØˆ?Ø˜2�hˆGÜ�eœTÔ"Ü Ó&ˆEä#Ø�%˜ 4¨Ô2FÈó
ˆ
ð ˆÜ˜zÓ*ò 	+‰EˆAˆrØ˜Ò Ü& zÓ2ò +‘E�A�rØ˜A“v !¨8Ò"3¸¿¹ÀB½Ø Ÿ™¨Õ*ñ+ð	+ð
 ˆÜ”s˜:“Ó'ò 	-ˆAØ˜Ò Ø—‘˜j¨™mÕ,ð	-ð ˆr   c                 ó   — | D ]  }||vsŒ y y)z„
        Return True iff every term in 'self' is a term in 'other'.

        :param other: ``Clause``
        :return: bool
        FTr   ©r)   rv   r/   s      r   Ú
isSubsetOfzClause.isSubsetOfã   s"   € ð ò 	ˆAØ˜Š~Ùð	ð r   c                 ó"  — g }|D ]@  }t        |t        «      r|j                  |j                  «       Œ/|j                  | «       ŒB t	        |«      }t        «       }g g f}g g f}t        d«      }t        t        | ||||t        |«      «      dkD  S )zì
        Return True iff 'self' subsumes 'other', this is, if there is a
        substitution such that every term in 'self' can be unified with a term
        in 'other'.

        :param other: ``Clause``
        :return: bool
        Fr   )
rC   r   r8   Útermrj   ro   rq   r6   rr   Ú_subsumes_finalize)	r)   rv   ÚnegatedotherÚatomÚnegatedotherClauserw   rx   ry   rz   s	            r   ru   zClause.subsumesï   s«   € ð ˆØò 	+ˆDÜ˜$Ô 1Ô2Ø×#Ñ# D§I¡IÕ.à×#Ñ# T EÕ*ð		+ô $ LÓ1Ðä“=ˆØ�BˆxˆØ�r�(ˆÜ˜EÓ"ˆô ÜØØ&ØØØÜ&Øóó
ð ñð	
r   c                 óB   — t        t        j                  | ||«      «      S rX   )rj   r5   Ú__getslice__)r)   ÚstartÚends      r   rˆ   zClause.__getslice__  s   € Ü”d×'Ñ'¨¨e°SÓ9Ó:Ð:r   c                 óH   — t        | D �cg c]	  }||vsŒ|‘Œ c}«      S c c}w rX   )rj   r   s      r   Ú__sub__zClause.__sub__  s!   € Ü $Ö9˜Q¨!°5ª.’qÒ9Ó:Ð:ùÒ9s   Š	”c                 ó@   — t        t        j                  | |«      «      S rX   )rj   r5   Ú__add__)r)   rv   s     r   rŽ   zClause.__add__  s   € Ü”d—l‘l 4¨Ó/Ó0Ð0r   c                 ór  — | j                   �| j                   S t        | «      D ]Š  \  }}t        |t        «      rŒt	        | «      dz
  }||kD  sŒ+| |   }t        |t
        «      r|j                  |k(  r1d| _          yt        |t
        «      r||j                  k(  r	d| _          y|dz  }||kD  rŒ`ŒŒ d| _         y)z›
        Self is a tautology if it contains ground terms P and -P.  The ground
        term, P, must be an exact match, ie, not using unification.
        r4   TF)rl   rt   rC   r
   r6   r   r‚   )r)   r<   r/   r=   Úbs        r   r7   zClause.is_tautology  s¼   € ð
 ×ÑÐ)Ø×%Ñ%Ð%Ü˜d“Oò 	‰DˆAˆqÜ˜aÔ!3Õ4Ü˜“I ‘M�Ø˜!“eØ˜Q™�AÜ! !Ô%6Ô7ØŸ6™6 Qš;Ø15˜DÔ.Ù#'Ü# AÔ'8Ô9Ø §¡š;Ø15˜DÔ.Ù#'Ø˜‘F�Að ˜!”eð	ð #ˆÔØr   c                 óD   — t        t        j                  d„ | D «       «      S )Nc              3   ó^   K  — | ]%  }|j                  «       |j                  «       z  –— Œ' y ­wrX   )ÚfreeÚ	constants)rY   r…   s     r   rZ   zClause.free.<locals>.<genexpr>7  s"   è ø€ Ò$WÈ$ d§i¡i£k°D·N±NÓ4DÕ&DÑ$Wùs   ‚+-)r   ÚoperatorÚor_©r)   s    r   r“   zClause.free6  s   € Ü”h—l‘lÑ$WÐRVÔ$WÓXÐXr   c           	      ó^   — t        | D �cg c]  }|j                  ||«      ‘Œ c}«      S c c}w )z½
        Replace every instance of variable with expression across every atom
        in the clause

        :param variable: ``Variable``
        :param expression: ``Expression``
        )rj   Úreplace)r)   ÚvariableÚ
expressionr…   s       r   r™   zClause.replace9  s(   € ô ÀdÖK¸d�t—|‘| H¨jÕ9ÒKÓLÐLùÒKs   Š*c                 ó\   — t        | D �cg c]  }|j                  |«      ‘Œ c}«      S c c}w )zÃ
        Replace every binding

        :param bindings: A list of tuples mapping Variable Expressions to the
            Expressions to which they are bound.
        :return: ``Clause``
        )rj   Úsubstitute_bindings)r)   rw   r…   s      r   r�   zClause.substitute_bindingsC  s(   € ô ÀdÖK¸d�t×/Ñ/°Õ9ÒKÓLÐLùÒKs   Š)c                 ó>   — ddj                  d„ | D «       «      z   dz   S )Nú{ú, c              3   ó&   K  — | ]	  }d |z  –— Œ y­w)ú%sNr   )rY   Úitems     r   rZ   z!Clause.__str__.<locals>.<genexpr>N  s   è ø€ Ò<¨t˜t d�{Ñ<ùs   ‚ú})Újoinr—   s    r   Ú__str__zClause.__str__M  s!   € Ø�T—Y‘YÑ<°tÔ<Ó<Ñ<¸sÑBÐBr   c                 ó   — d| z  S ©Nr¢   r   r—   s    r   Ú__repr__zClause.__repr__P  ó   € Ø�d‰{Ðr   )NNNF)r   r   r   rD   r9   r€   ru   rˆ   rŒ   rŽ   r7   r“   r™   r�   r¦   r©   r   r   r   rj   rj   ®   sI   „ òó
-ò^
ò$
òL;ò;ò1òò0YòMòMòCór   rj   c                 óÆ  — |j                  d| › d|› d|› �«       t        | «      rt        |«      s || |||||«      S t        | ||||||dz   «      }|d   | d   gz   |d   f}|t        | dd ||||||dz   «      z  }	 t	        | d   |d   ||«      \  }	}
}| dd |d   z   |d   z   }|dd |d   z   |d   z   }|t        |||	|
g g f||dz   «      z  }|S # t
        $ r Y |S w xY w)zF
    This method facilitates movement through the terms of 'self'
    úunify(ú,ú) r4   r   N)Úliner6   Ú_iterate_secondrr   Ú_unify_termsÚBindingException)ÚfirstÚsecondrw   rx   ry   Úfinalize_methodrz   r-   Ú
newskippedÚnewbindingsÚnewusedÚunusedÚnewfirstÚ	newseconds                 r   rr   rr   T  s_  € ð 
‡J�J�˜�w˜a ˜x r¨(¨Ð4Ô5äˆuŒ:œS œ[Ù˜u f¨h¸¸gÀuÓMÐMô !Ø�6˜8 T¨7°OÀUÈQÁYó
ˆð
 ˜a‘j E¨!¡H :Ñ-¨w°q©zÐ:ˆ
Ø”.Ø�!�"ˆI�v˜x¨¨z¸?ÈEÐTUÉIó
ñ 	
ˆð	Ü+7Ø�a‘˜& ™) X¨tó,Ñ(ˆK˜ &ð
 ˜Q˜R�y 7¨1¡:Ñ-°°q±	Ñ9ˆHØ˜q˜r˜
 W¨Q¡ZÑ/°&¸±)Ñ;ˆIØ”nØØØØØ�R�ØØ˜‘	óñ ˆFð ˆøô	  ò 	ààˆð		ús   Á>AC Ã	C ÃC c                 ó˜  — |j                  d| › d|› d|› �«       t        | «      rt        |«      s || |||||«      S |d   |d   |d   gz   f}t        | |dd |||||dz   «      }	 t        | d   |d   ||«      \  }	}
}| dd |d   z   |d   z   }|dd |d   z   |d   z   }|t        |||	|
g g f||dz   «      z  }|S # t        $ r Y |S w xY w)zG
    This method facilitates movement through the terms of 'other'
    r¬   r­   r®   r   r4   N)r¯   r6   r°   r±   r²   )r³   r´   rw   rx   ry   rµ   rz   r¶   r-   r·   r¸   r¹   rº   r»   s                 r   r°   r°   €  s9  € ð 
‡J�J�˜�w˜a ˜x r¨(¨Ð4Ô5äˆuŒ:œS œ[Ù˜u f¨h¸¸gÀuÓMÐMð ˜a‘j '¨!¡*°°q±	¨{Ñ":Ð;ˆ
Ü Ø�6˜!˜"�:˜x¨¨z¸?ÈEÐTUÉIó
ˆð	Ü+7Ø�a‘˜& ™) X¨tó,Ñ(ˆK˜ &ð
 ˜Q˜R�y 7¨1¡:Ñ-°°q±	Ñ9ˆHØ˜q˜r˜
 W¨Q¡ZÑ/°&¸±)Ñ;ˆIØ”oØØØØØ�R�ØØ˜‘	óñ ˆFð ˆøô	  ò 	ààˆð		ús   Á'AB< Â<	C	ÃC	c                 ó
  — t        | t        «      sJ ‚t        |t        «      sJ ‚|€
t        «       }|€g g f}t        | t        «      r>t        |t        «      r.t        | j                  ||«      }|d   | gz   |d   |gz   f}g g f}nût        | t        «      r>t        |t        «      r.t        | |j                  |«      }|d   | gz   |d   |gz   f}g g f}n­t        | t        «      r@t        | j                  j                  | j                  fg«      }|d   | gz   |d   f}g |gf}n]t        |t        «      r@t        |j                  j                  |j                  fg«      }|d   |d   |gz   f}| gg f}nt        | |f«      ‚|||fS )aÑ  
    This method attempts to unify two terms.  Two expressions are unifiable
    if there exists a substitution function S such that S(a) == S(-b).

    :param a: ``Expression``
    :param b: ``Expression``
    :param bindings: ``BindingDict`` a starting set of bindings with which
    the unification must be consistent
    :return: ``BindingDict`` A dictionary of the bindings required to unify
    :raise ``BindingException``: If the terms cannot be unified
    r   r4   )rC   r   ro   r   r	   Úmost_general_unificationr‚   r
   r³   rš   r´   r²   )r/   r�   rw   rx   r·   r¸   r¹   s          r   r±   r±   §  s™  € ô �aœÔ$Ð$Ð$Ü�aœÔ$Ð$Ð$àÐÜ“=ˆØ€|Ø�Bˆxˆô �!Ô&Ô'¬J°qÔ:OÔ,PÜ.¨q¯v©v°q¸(ÓCˆØ˜‘7˜a˜S‘= $ q¡'¨Q¨C¡-Ð0ˆØ�b�‰Ü	�AÔ,Ô	-´*¸QÔ@QÔ2RÜ.¨q°!·&±&¸(ÓCˆØ˜‘7˜a˜S‘= $ q¡'¨Q¨C¡-Ð0ˆØ�b�‰ô 
�AÔ)Ô	*Ü! A§G¡G×$4Ñ$4°a·h±hÐ#?Ð"@ÓAˆØ˜‘7˜a˜S‘= $ q¡'Ð*ˆØ�q�c�‰Ü	�AÔ)Ô	*Ü! A§G¡G×$4Ñ$4°a·h±hÐ#?Ð"@ÓAˆØ˜‘7˜D ™G q c™MÐ*ˆØ�#�r�‰ô   1˜vÓ&Ð&à˜ Ð'Ð'r   c                 ó¼   — |d   s|d   r@t        |d   |d   z   | z   |z   «      }|j                  d|z  «       |j                  |«      gS |j                  d«       g S )Nr   r4   z  -> New Clause: %sz  -> End)rj   r¯   r�   )r³   r´   rw   rx   ry   rz   r?   s          r   rs   rs   Õ  sg   € ØˆA‚w�$�q’'Ü˜7 1™:¨°©
Ñ2°UÑ:¸VÑCÓDˆ	Ø�
‰
Ð(¨9Ñ4Ô5Ø×-Ñ-¨hÓ7Ð8Ð8à�
‰
�:ÔØˆ	r   c                 ó>   — t        |d   «      st        | «      sdgS g S )Nr   T)r6   )r³   r´   rw   rx   ry   rz   s         r   rƒ   rƒ   ß  s!   € Üˆw�q‰zŒ?¤3 u¤:ð ˆvˆàˆ	r   c                 óþ   — g }t        t        | «      «      D ]c  }|j                  «       D ]=  }t        |j                  «      sŒt        t        «       «      }|j                  ||«      }Œ? |j                  |«       Œe |S )zC
    Skolemize, clausify, and standardize the variables apart.
    )	Ú	_clausifyr   r“   r   Únamer   r   r™   r8   )r›   Úclause_listrS   r“   Únewvars        r   r    r    ë  sx   € ð €KÜœI jÓ1Ó2ò #ˆØ—K‘K“Mò 	6ˆDÜ˜Ÿ™Õ#Ü+¬OÓ,=Ó>�ØŸ™¨¨fÓ5‘ð	6ð 	×Ñ˜6Õ"ð#ð Ðr   c                 óˆ  — t        | t        «      r+t        | j                  «      t        | j                  «      z   S t        | t
        «      rVt        | j                  «      }t        | j                  «      }t        |«      dk(  sJ ‚t        |«      dk(  sJ ‚|d   |d   z   gS t        | t        «      rt        | g«      gS t        | t        «      rt        | g«      gS t        | t        «      rNt        | j                  t        «      rt        | g«      gS t        | j                  t        «      rt        | g«      gS t        «       ‚)z;
    :param expression: a skolemized expression in CNF
    r4   r   )rC   r   rÂ   r³   r´   r   r6   r
   rj   r	   r   r‚   r   )r›   r³   r´   s      r   rÂ   rÂ   ù  s  € ô �*œmÔ,Ü˜×)Ñ)Ó*¬Y°z×7HÑ7HÓ-IÑIÐIÜ	�J¤Ô	-Ü˜*×*Ñ*Ó+ˆÜ˜:×,Ñ,Ó-ˆÜ�5‹z˜QŠÐˆÜ�6‹{˜aÒÐÐØ�a‘˜6 !™9Ñ$Ð%Ð%Ü	�JÔ 2Ô	3Ü˜
�|Ó$Ð%Ð%Ü	�JÔ 5Ô	6Ü˜
�|Ó$Ð%Ð%Ü	�JÔ 1Ô	2Ü�j—o‘oÔ'<Ô=Ü˜J˜<Ó(Ð)Ð)Ü˜
Ÿ™Ô);Ô<Ü˜J˜<Ó(Ð)Ð)Ü
Ó
Ðr   c                   ó>   — e Zd Zd
d„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
y)ro   Nc                 ó6   — i | _         |r|D ]
  \  }}|| |<   Œ yy)z‚
        :param binding_list: list of (``AbstractVariableExpression``, ``AtomicExpression``) to initialize the dictionary
        N©Úd)r)   Úbinding_listÚvr�   s       r   rD   zBindingDict.__init__  s/   € ð ˆŒáØ$ò ‘��1Ø��Q’ñð r   c                 ó˜  — t        |t        «      sJ ‚t        |t        «      sJ ‚	 | |   }|r||k(  r|| j                  |<   yt        |t
        «      rJ	 | |j                     }t        |«      }|r||k(  r|| j                  |j                  <   yt        d|z  «      ‚t        d|z  «      ‚# t        $ r d}Y ŒŒw xY w# t        $ r d}Y Œfw xY w)a€  
        A binding is consistent with the dict if its variable is not already bound, OR if its
        variable is already bound to its argument.

        :param variable: ``Variable`` The variable to bind
        :param binding: ``Expression`` The atomic to which 'variable' should be bound
        :raise BindingException: If the variable cannot be bound in this dictionary
        Nz*Variable %s already bound to another value)	rC   r   r   ÚKeyErrorrÊ   r   rš   r   r²   )r)   rš   ÚbindingÚexistingÚbinding2s        r   Ú__setitem__zBindingDict.__setitem__  sí   € ô ˜(¤HÔ-Ð-Ð-Ü˜'¤:Ô.Ð.Ð.ð	Ø˜H‘~ˆHñ ˜7 hÒ.Ø&ˆD�F‰F�8ÒÜ˜Ô!=Ô>ð Ø × 0Ñ 0Ñ1�ô *¨(Ó3ˆHá˜x¨8Ò3Ø+3�—‘�w×'Ñ'Ò(ä&ØCÀxÑPóð ô #Ø?À8ÑLóð øô+ ò 	ØŠHð	ûô ò  Ø’ð ús#   ¦B* ÁB; Â*B8Â7B8Â;C	ÃC	c                 ó”   — t        |t        «      sJ ‚| j                  |   }|r	 | j                  |   }|rŒyy# t        $ r |cY S w xY w)zD
        Return the expression to which 'variable' is bound
        N)rC   r   rÊ   rÎ   )r)   rš   Úintermediates      r   Ú__getitem__zBindingDict.__getitem__C  sT   € ô ˜(¤HÔ-Ð-Ð-à—v‘v˜hÑ'ˆÙð$Ø#Ÿv™v lÑ3�ô øô ò $Ø#Ò#ð$ús   ¥9 ¹AÁAc                 ó   — || j                   v S rX   rÉ   )r)   r£   s     r   Ú__contains__zBindingDict.__contains__P  s   € Ø�t—v‘vˆ~Ðr   c                 óð   — 	 t        «       }| j                  D ]  }| j                  |   ||<   Œ |j                  D ]  }|j                  |   ||<   Œ |S # t        $ r}t        d| ›d|›d�«      |‚d}~ww xY w)a  
        :param other: ``BindingDict`` The dict with which to combine self
        :return: ``BindingDict`` A new dict containing all the elements of both parameters
        :raise BindingException: If the parameter dictionaries are not consistent with each other
        z3Attempting to add two contradicting BindingDicts: 'z' and 'ú'N)ro   rÊ   r²   )r)   rv   ÚcombinedrÌ   r0   s        r   rŽ   zBindingDict.__add__S  s‡   € ð	Ü"“}ˆHØ—V‘Vò (�Ø"Ÿf™f Q™i�˜’ð(à—W‘Wò )�Ø#Ÿg™g a™j�˜’ð)àˆOøÜò 	Ý"â15²uð>óð ðûð	ús   ‚AA Á	A5ÁA0Á0A5c                 ó,   — t        | j                  «      S rX   )r6   rÊ   r—   s    r   Ú__len__zBindingDict.__len__f  s   € Ü�4—6‘6‹{Ðr   c                 óŠ   ‡ — dj                  ˆ fd„t        ‰ j                  j                  «       «      D «       «      }d|z   dz   S )Nr    c              3   óF   •K  — | ]  }|› d ‰j                   |   › �–— Œ y­w)ú: NrÉ   )rY   rÌ   r)   s     €r   rZ   z&BindingDict.__str__.<locals>.<genexpr>j  s$   øè ø€ ÒP°Q ˜s " T§V¡V¨A¡Y KÔ0ÑPùs   ƒ!rŸ   r¤   )r¥   ÚsortedrÊ   Úkeys)r)   Údata_strs   ` r   r¦   zBindingDict.__str__i  s5   ø€ Ø—9‘9ÓP¼&ÀÇÁÇÁÃÓ:OÔPÓPˆØ�X‰~ Ñ#Ð#r   c                 ó   — d| z  S r¨   r   r—   s    r   r©   zBindingDict.__repr__m  rª   r   rX   )r   r   r   rD   rÒ   rÕ   r×   rŽ   rÜ   r¦   r©   r   r   r   ro   ro     s+   „ óò%òN$òòò&ò$ór   ro   c                 ó|  — |€
t        «       }| |k(  r|S t        | t        «      rt        | ||«      S t        |t        «      rt        || |«      S t        | t        «      rSt        |t        «      rCt        | j                  |j                  |«      t        | j                  |j                  |«      z   S t        | |f«      ‚)ah  
    Find the most general unification of the two given expressions

    :param a: ``Expression``
    :param b: ``Expression``
    :param bindings: ``BindingDict`` a starting set of bindings with which the
                     unification must be consistent
    :return: a list of bindings
    :raise BindingException: if the Expressions cannot be unified
    )	ro   rC   r   Ú_mgu_varr	   r¾   rN   rO   r²   )r/   r�   rw   s      r   r¾   r¾   q  s®   € ð ÐÜ“=ˆàˆA‚vØˆÜ	�AÔ3Ô	4Ü˜˜1˜hÓ'Ð'Ü	�AÔ3Ô	4Ü˜˜1˜hÓ'Ð'Ü	�AÔ,Ô	-´*¸QÔ@UÔ2VÜ'Ø�J‰J˜Ÿ
™
 Hó
ä$ Q§Z¡Z°·±¸XÓFñGð 	Gô ˜A˜q˜6Ó
"Ð"r   c                 ó¬   — | j                   |j                  «       |j                  «       z  v rt        | |f«      ‚t	        | j                   |fg«      |z   S rX   )rš   r“   r”   r²   ro   )Úvarr›   rw   s      r   rå   rå   Œ  sO   € Ø
‡|�|�z—‘Ó(¨:×+?Ñ+?Ó+AÑAÑAÜ  ZÐ0Ó1Ð1ä˜SŸ\™\¨:Ð6Ð7Ó8¸8ÑCÐCr   c                   ó   — e Zd Zd„ Zy)r²   c                 ó„   — t        |t        «      rt        j                  | d|z  «       y t        j                  | |«       y )Nz'%s' cannot be bound to '%s')rC   ÚtupleÚ	ExceptionrD   )r)   Úargs     r   rD   zBindingException.__init__”  s2   € Ü�cœ5Ô!Ü×Ñ˜tÐ%CÀcÑ%IÕJä×Ñ˜t SÕ)r   N©r   r   r   rD   r   r   r   r²   r²   “  s   „ ó*r   r²   c                   ó   — e Zd Zd„ Zy)ÚUnificationExceptionc                 ó>   — t         j                  | d|› d|› d�«       y )NrÙ   z' cannot unify with ')rë   rD   )r)   r/   r�   s      r   rD   zUnificationException.__init__œ  s"   € Ü×Ñ˜4 1 Q CÐ'<¸Q¸C¸qÐ!AÕBr   Nrí   r   r   r   rï   rï   ›  s   „ óCr   rï   c                   ó    — e Zd Zdd„Zd„ Zd„ Zy)rq   c                 ó    — || _         || _        y rX   )ÚenabledÚindent)r)   ró   rô   s      r   rD   zDebugObject.__init__¡  s   € ØˆŒØˆ�r   c                 óH   — t        | j                  | j                  |z   «      S rX   )rq   ró   rô   )r)   r<   s     r   rŽ   zDebugObject.__add__¥  s   € Ü˜4Ÿ<™<¨¯©°q©Ó9Ð9r   c                 óT   — | j                   rt        d| j                  z  |z   «       y y )Nz    )ró   r"   rô   )r)   r¯   s     r   r¯   zDebugObject.line¨  s$   € Ø�<Š<Ü�&˜4Ÿ;™;Ñ&¨Ñ-Õ.ð r   N)Tr   )r   r   r   rD   rŽ   r¯   r   r   r   rq   rq      s   „ óò:ó/r   rq   c                  ó   — t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d«       t        d	«       t        d
«       t        j                  d«      } t        j                  d«      }t        j                  d«      }t        | › d|› d|› dt	        «       j                  || |g«      › �«       t        j                  d«      } t        j                  d«      }t        j                  d«      }t        | › d|› d|› dt	        «       j                  || |g«      › �«       t        j                  d«      }t        j                  d«      }t        |› d|› dt	        «       j                  ||g«      › �«       y )Núman(x)z(man(x) -> man(x))z(man(x) -> --man(x))z-(man(x) and -man(x))z(man(x) or -man(x))z(man(x) iff man(x))z-(man(x) iff -man(x))zall x.man(x)z--all x.some y.F(x,y) & some x.all y.(-F(x,y))zsome x.all y.sees(x,y)zall x.(man(x) -> mortal(x))zman(Socrates)zmortal(Socrates)r    z |- rß   zall x.(man(x) -> walks(x))z	man(John)zsome y.walks(y)z5some e1.some e2.(believe(e1,john,e2) & walk(e2,mary))zsome e0.walk(e0,mary))Úresolution_testr   Ú
fromstringr"   r   rK   )Úp1Úp2ÚcÚps       r   ÚtestResolutionProverrÿ   ­  sœ  € Ü�IÔÜÐ)Ô*ÜÐ+Ô,ÜÐ,Ô-ÜÐ*Ô+ÜÐ)Ô*ÜÐ,Ô-ÜÐ*Ô+ÜÐ)Ô*ÜÐ*Ô+ÜÐ,Ô-Ü�NÔ#ÜÐCÔDÜÐ,Ô-ä	×	Ñ	Ð=Ó	>€BÜ	×	Ñ	Ð/Ó	0€BÜ×ÑÐ1Ó2€AÜ	ˆRˆD��2�$�d˜1˜#˜RÔ 0Ó 2× 8Ñ 8¸¸RÀ¸HÓ EÐFÐ
GÔHä	×	Ñ	Ð<Ó	=€BÜ	×	Ñ	˜|Ó	,€BÜ×ÑÐ0Ó1€AÜ	ˆRˆD��2�$�d˜1˜#˜RÔ 0Ó 2× 8Ñ 8¸¸RÀ¸HÓ EÐFÐ
GÔHä×ÑÐVÓW€AÜ×ÑÐ6Ó7€AÜ	ˆQˆCˆt�A�3�bÔ)Ó+×1Ñ1°!°a°SÓ9Ð:Ð
;Õ<r   c                 ó‚   — t        j                  | «      }t        «       j                  |«      }t	        d|› d|› �«       y )Nz|- rß   )r   rú   r   rK   r"   )r0   ÚfÚts      r   rù   rù   Ì  s9   € Ü×Ñ˜aÓ €AÜÓ× Ñ  Ó#€AÜ	ˆC�ˆs�"�Q�Cˆ.Õr   c                  ó˜  — t         j                  } t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d	«      «      «       t        t         | d
«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       t        t         | d«      «      «       y )NzP(x) | Q(x)z(P(x) & Q(x)) | R(x)zP(x) | (Q(x) & R(x))z(P(x) & Q(x)) | (R(x) & S(x))zP(x) | Q(x) | R(x)zP(x) | (Q(x) & R(x)) | S(x)zexists x.P(x) | Q(x)z-(-P(x) & Q(x))zP(x) <-> Q(x)z-(P(x) <-> Q(x))z-(all x.P(x))z-(some x.P(x))zsome x.P(x)zsome x.all y.P(x,y)zall y.some x.P(x,y)zall z.all y.some x.P(x,y,z)z1all x.(all y.P(x,y) -> -all y.(Q(x,y) -> R(x,y))))r   rú   r"   r    )Úlexprs    r   Útest_clausifyr  Ò  sL  € Ü×!Ñ!€Eä	Œ(‘5˜Ó'Ó
(Ô)Ü	Œ(‘5Ð/Ó0Ó
1Ô2Ü	Œ(‘5Ð/Ó0Ó
1Ô2Ü	Œ(‘5Ð8Ó9Ó
:Ô;ä	Œ(‘5Ð-Ó.Ó
/Ô0Ü	Œ(‘5Ð6Ó7Ó
8Ô9ä	Œ(‘5Ð/Ó0Ó
1Ô2ä	Œ(‘5Ð*Ó+Ó
,Ô-Ü	Œ(‘5˜Ó)Ó
*Ô+Ü	Œ(‘5Ð+Ó,Ó
-Ô.Ü	Œ(‘5˜Ó)Ó
*Ô+Ü	Œ(‘5Ð)Ó*Ó
+Ô,ä	Œ(‘5˜Ó'Ó
(Ô)Ü	Œ(‘5Ð.Ó/Ó
0Ô1Ü	Œ(‘5Ð.Ó/Ó
0Ô1Ü	Œ(‘5Ð6Ó7Ó
8Ô9Ü	Œ(‘5ÐLÓMÓ
NÕOr   c                  óÆ   — t        «        t        «        t        «        t        «        t        j                  d«      } t        t        | | g«      j                  «       «       y )Nrø   )r  r"   rÿ   r   rú   r#   rK   )rþ   s    r   Údemor  ì  sB   € Ü„OÜ	„GÜÔÜ	„Gä×Ñ˜hÓ'€AÜ	Ô
! ! a SÓ
)×
/Ñ
/Ó
1Õ2r   Ú__main__)NNrX   )/Ú__doc__r•   Úcollectionsr   Ú	functoolsr   Únltk.inference.apir   r   Únltk.semr   Únltk.sem.logicr   r	   r
   r   r   r   r   r   r   r   r   rë   r   r   r#   r5   rj   rr   r°   r±   rs   rƒ   r    rÂ   ro   r¾   rå   r²   rï   rq   rÿ   rù   r  r  r   r   r   r   ú<module>r     sò   ðñó Ý #Ý ç 8Ý ÷÷ ÷ ñ ô	�yô 	ôC �vô C ôL?Ð/ô ?ôDcˆTô còL)òX$óN+(ò\ò	òò÷0]ñ ]ó@#ò6Dô*�yô *ôC˜9ô C÷

/ñ 
/ò=ò>òPò43ð ˆzÒÙ…Fð r   