
    /he                        S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
  SSKJrJrJrJrJrJrJrJrJrJrJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      rS rS rS&S jrS r S r!S r"S r# " S S5      r$S'S jr%S r& " S S\5      r' " S S\5      r( " S S 5      r)S! r*S" r+S# r,S$ r-\.S%:X  a  \-" 5         gg)(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                       \ rS rSrSrg)ProverParseError"    N)__name__
__module____qualname____firstlineno____static_attributes__r       Q/var/www/auris/envauris/lib/python3.13/site-packages/nltk/inference/resolution.pyr   r   "   s    r   r   c                   ,    \ rS rSrSrSrSS jrS rSrg)	ResolutionProver&   ANSWERTNc                    U(       d  / nSn / nU(       a  UR                  [        U* 5      5        U H  nUR                  [        U5      5        M     U R                  U5      u  pEU(       a  [        [        R                  U5      5        XE4$ ! [         a\  nU R                  (       a*  [        U5      R                  S5      (       a  Sn/ n SnAXE4$ U(       a  [        U5         SnAUW4$ UeSnAff = f)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   _proveResolutionProver._prove*   s     K	Gx/ x{+ !"11':OF-??HI     
	!!c!f&7&72' '    	 !HH    G
	s$   A?B 
C54C0C0.C00C5c                 H   [        [        5      nSnU[        U5      :  a  X   R                  5       (       d  X#   (       a  X#   S   S-   nOUS-   nU[        U5      :  a  X4:w  a  U(       a  X   R                  5       (       dq  X#   R	                  U5        X   R                  X   5      nU(       aB  U H9  nUS-   US-   4Ul        UR	                  U5        [        U5      (       a  M5  SU4s  $    SnOUS-  nU[        U5      :  a  M  US-  nU[        U5      :  a  M  SU4$ )Nr      TF)r   listlenis_tautologyappendunify_parents)r-   r2   triedij
newclauses	newclauses          r   r%   ResolutionProver._attempt_proofK   s   D!#g,:**,, 8q(AAA#g,& v!GJ,C,C,E,E*%,Z%5%5gj%A
%-7	67!eQU^	 2 'y 9'*9~~,0'?$:	 .8
 !#A!FA #g,& FA1 #g,2 wr   r   )NNF)	r   r   r   r   
ANSWER_KEYr*   r5   r%   r   r   r   r   r   r   &   s    JM!B r   r   c                   B    \ rS rSrSS jrS	S jrS	S jr\S 5       rSr	g)
r'   l   Nc                     Ub  [        U[        5      (       d   eO
[        5       n[        R                  " XX5        SU l        g)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   rK    ResolutionProverCommand.__init__m   s=     f&67777%'F""4Cr   c                     U R                   ca  U R                  R                  U R                  5       U R	                  5       U5      u  U l         nX l        [        R                  U5      U l        U R                   $ )zP
Perform the actual proof.  Store the result to prevent unnecessary
re-proving.
)	_result_proverr5   r.   r/   rL   r'   r(   _proof)r-   r0   r2   s      r   proveResolutionProverCommand.prove}   sb    
 <<$(LL$7$7		T--/%!DL' $M1CCGLDK||r   c                    U R                  U5        [        5       n[        [        [        R
                  5      5      nU R                   Hq  nU Hh  n[        U[        5      (       d  M  UR                  U:X  d  M,  [        UR                  [        5      (       a  MM  UR                  UR                  5        Mj     Ms     U$ N)rS   setr   r   r   rF   rL   rJ   r	   functionargumentr   add)r-   r0   answers	answer_exclauseterms         r   find_answers$ResolutionProverCommand.find_answers   s    

7%&x0@0K0K'LM	mmFt%:;;2&t}}6RSSKK.  $ r   c                    Sn[        S U  5       5      n[        [        [        U 5      5      5      n[        [        U 5      5       H  nSnSnX   R	                  5       (       a  SnX   R
                  (       a  [        X   R
                  5      nSU[        [        X   5      5      -
  S-   -  U-   nSU[        [        US-   5      5      -
  -  [        US-   5      -   nUSU SX    SU SU S	3	-  nM     U$ )
z
Decorate the proof output.
 c              3   J   #    U  H  n[        [        U5      5      v   M     g 7frV   )r;   r+   ).0r]   s     r   	<genexpr><ResolutionProverCommand._decorate_clauses.<locals>.<genexpr>   s     DG&SV--Gs   !#A	Tautology r9   [z] 
)maxr;   r+   ranger<   r?   )r2   outmax_clause_lenmax_seq_lenrA   parentstautseqs           r   r(   )ResolutionProverCommand._decorate_clauses   s    
 DGDD#c'l+,s7|$AGDz&&(("z""gj112^c#gj/.BBQFG'QGs3q1u:67#a!e*DCQse2gj\7)1TF"==C % 
r   )rL   rR   rP   )NNN)F)
r   r   r   r   rK   rS   r_   staticmethodr(   r   r   r   r   r'   r'   l   s%       r   r'   c                   f    \ rS rSrS rSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rSrg)Clause   c                 J    [         R                  X5        S U l        S U l        g rV   )r:   rK   _is_tautologyr?   )r-   datas     r   rK   Clause.__init__   s    d!!r   Nc           	         Uc
  [        5       nUc  / / 4nUc  / / 4n[        U[        5      (       a  [        U5      n[	        XX#U[
        U5      n/ n[        U5       HW  u  pX;  d  M  [        U5       H<  u  pX:w  d  M  X;  d  M  U	R                  U5      (       d  M+  UR                  U
5        M>     MY     / n[        [        U5      5       H  nX;  d  M
  UR                  Xh   5        M     U$ )ap  
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
)BindingDictrJ   boolDebugObject_iterate_first_complete_unify_path	enumeratesubsumesr=   rm   r;   )r-   otherbindingsusedskippeddebugrC   subsumedrA   c1rB   c2r1   s                r   r>   Clause.unify   s    & "}H<8D?2hGeT""&E#2F

 z*EA &z2EAv!"3B * 3 +
 s:'A jm, ( r   c                 $    U  H
  nX!;  d  M
    g   g)zd
Return True iff every term in 'self' is a term in 'other'.

:param other: ``Clause``
:return: bool
FTr   r-   r   r3   s      r   
isSubsetOfClause.isSubsetOf   s     A~  r   c                 2   / nU HG  n[        U[        5      (       a  UR                  UR                  5        M5  UR                  U* 5        MI     [	        U5      n[        5       n/ / 4n/ / 4n[        S5      n[        [        U UUUU[        U5      5      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   )
rJ   r   r=   r^   rw   r~   r   r;   r   _subsumes_finalize)	r-   r   negatedotheratomnegatedotherClauser   r   r   r   s	            r   r   Clause.subsumes   s     D$ 122##DII.##TE*	  $L1=Bxr(E" &&
 	
r   c                 @    [        [        R                  XU5      5      $ rV   )rw   r:   __getslice__)r-   startends      r   r   Clause.__getslice__  s    d''S9::r   c                 R    [        U  Vs/ s H  o"U;  d  M
  UPM     sn5      $ s  snf rV   )rw   r   s      r   __sub__Clause.__sub__  s#    $9$Q5.q$9::9s   	$$c                 >    [        [        R                  X5      5      $ rV   )rw   r:   __add__)r-   r   s     r   r   Clause.__add__  s    dll4/00r   c                    U R                   b  U R                   $ [        U 5       H  u  p[        U[        5      (       a  M  [	        U 5      S-
  nX1:  d  M1  X   n[        U[
        5      (       a  UR                  U:X  a	  SU l           gO-[        U[
        5      (       a  X$R                  :X  a	  SU l           gUS-  nX1:  a  Ml  M     SU l         g)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.
r9   TF)rz   r   rJ   r
   r;   r   r^   )r-   rA   r3   rB   bs        r   r<   Clause.is_tautology  s    
 )%%%dODAa!344IMeA!!%67766Q;15D.#' ' $A'899;15D.#'FA e $ #r   c                 D    [        [        R                  S U  5       5      $ )Nc              3   b   #    U  H%  oR                  5       UR                  5       -  v   M'     g 7frV   )free	constants)rd   r   s     r   re   Clause.free.<locals>.<genexpr>7  s"     $WRV$iikDNN4D&DRVs   -/)r   operatoror_r-   s    r   r   Clause.free6  s    hll$WRV$WXXr   c           	      `    [        U  Vs/ s H  o3R                  X5      PM     sn5      $ s  snf )z
Replace every instance of variable with expression across every atom
in the clause

:param variable: ``Variable``
:param expression: ``Expression``
)rw   replace)r-   variable
expressionr   s       r   r   Clause.replace9  s(     dKdd||H9dKLLK   +c                 `    [        U  Vs/ s H  o"R                  U5      PM     sn5      $ s  snf )z
Replace every binding

:param bindings: A list of tuples mapping Variable Expressions to the
    Expressions to which they are bound.
:return: ``Clause``
)rw   substitute_bindings)r-   r   r   s      r   r   Clause.substitute_bindingsC  s*     dKdd//9dKLLKr   c                 >    SSR                  S U  5       5      -   S-   $ )N{, c              3   ,   #    U  H
  nS U-  v   M     g7f)%sNr   )rd   items     r   re   !Clause.__str__.<locals>.<genexpr>N  s     <tttd{ts   })joinr   s    r   __str__Clause.__str__M  s!    TYY<t<<<sBBr   c                     SU -  $ Nr   r   r   s    r   __repr__Clause.__repr__P      d{r   )rz   r?   )NNNF)r   r   r   r   rK   r>   r   r   r   r   r   r<   r   r   r   r   r   r   r   r   r   rw   rw      sI    
-^
$
L;;10YMMCr   rw   c                    UR                  SU  SU SU 35        [        U 5      (       a  [        U5      (       d
  U" XX#XF5      $ [        XX#XEUS-   5      nUS   U S   /-   US   4nU[        U SS XX8XVS-   5      -  n [	        U S   US   X#5      u  pnU SS US   -   US   -   nUSS US   -   US   -   nU[        UUU	U
/ / 4UUS-   5      -  nU$ ! [
         a     U$ f = f)z>
This method facilitates movement through the terms of 'self'
unify(,) r9   r   N)liner;   _iterate_secondr   _unify_termsBindingException)firstsecondr   r   r   finalize_methodr   r1   
newskippednewbindingsnewusedunusednewfirst	newseconds                 r   r   r   T  sM    
JJwaxr(45u::S[[uhgMM !87UQY

 ajE!H:-wqz:
.!"Iv?TUI
 	
	+7a&)X,(K&
 QRy71:-q	9Hqr
WQZ/&);InR	 F 	   			s   ?AC 
C C c                    UR                  SU  SU SU 35        [        U 5      (       a  [        U5      (       d
  U" XX#XF5      $ US   US   US   /-   4n[        XSS X#XuUS-   5      n [        U S   US   X#5      u  pnU SS US   -   US   -   nUSS US   -   US   -   nU[        UUU	U
/ / 4UUS-   5      -  nU$ ! [         a     U$ f = f)z?
This method facilitates movement through the terms of 'other'
r   r   r   r   r9   N)r   r;   r   r   r   )r   r   r   r   r   r   r   r   r1   r   r   r   r   r   s                 r   r   r     s-    
JJwaxr(45u::S[[uhgMM aj'!*q	{":;
 !":xzETUI
	+7a&)X,(K&
 QRy71:-q	9Hqr
WQZ/&);IoR	 F 	   			s   +AB> >
CCc                 X   [        U [        5      (       d   e[        U[        5      (       d   eUc
  [        5       nUc  / / 4n[        U [        5      (       aC  [        U[        5      (       a.  [        U R                  X5      nUS   U /-   US   U/-   4n/ / 4nGO[        U [        5      (       aB  [        U[        5      (       a-  [        XR                  U5      nUS   U /-   US   U/-   4n/ / 4nO[        U [        5      (       a@  [        U R                  R                  U R                  4/5      nUS   U /-   US   4n/ U/4nOa[        U[        5      (       a@  [        UR                  R                  UR                  4/5      nUS   US   U/-   4nU // 4nO[        X45      eXEU4$ )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   r9   )rJ   r   r~   r   r	   most_general_unificationr^   r
   r   r   r   r   )r3   r   r   r   r   r   r   s          r   r   r     s    a$$$$a$$$$=|Bx !&''Jq:O,P,P.qvvqC7aS=$q'QC-0b	A,	-	-*Q@Q2R2R.q&&(C7aS=$q'QC-0b 
A)	*	*!AGG$4$4ahh#?"@A7aS=$q'*qc	A)	*	*!AGG$4$4ahh#?"@A7DGqcM*#r v&&''r   c                     US   (       d
  US   (       a@  [        US   US   -   U -   U-   5      nUR                  SU-  5        UR                  U5      /$ UR                  S5        / $ )Nr   r9   z  -> New Clause: %sz  -> End)rw   r   r   )r   r   r   r   r   r   rD   s          r   r   r     sg    Aw$q'71:
2U:VCD	

(945--h788

:	r   c                 R    [        US   5      (       d  [        U 5      (       d  S/$ / $ )Nr   T)r;   )r   r   r   r   r   r   s         r   r   r     s%    wqz??3u:: v	r   c                    / n[        [        U 5      5       Hk  nUR                  5        HC  n[        UR                  5      (       d  M  [        [        5       5      nUR                  X45      nME     UR                  U5        Mm     U$ )z;
Skolemize, clausify, and standardize the variables apart.
)		_clausifyr   r   r   namer   r   r   r=   )r   clause_listr]   r   newvars        r   r$   r$     so     KIj12KKMD##+O,=>5 " 	6" 3 r   c                    [        U [        5      (       a+  [        U R                  5      [        U R                  5      -   $ [        U [
        5      (       aX  [        U R                  5      n[        U R                  5      n[        U5      S:X  d   e[        U5      S:X  d   eUS   US   -   /$ [        U [        5      (       a  [        U /5      /$ [        U [        5      (       a  [        U /5      /$ [        U [        5      (       aX  [        U R                  [        5      (       a  [        U /5      /$ [        U R                  [        5      (       a  [        U /5      /$ [        5       e)z3
:param expression: a skolemized expression in CNF
r9   r   )rJ   r   r   r   r   r   r;   r
   rw   r	   r   r^   r   )r   r   r   s      r   r   r     s.    *m,,))*Yz7H7H-III	J	-	-***+:,,-5zQ6{aa6!9$%%	J 2	3	3
|$%%	J 5	6	6
|$%%	J 1	2	2joo'<==J<())
);<<J<())

r   c                   H    \ rS rSrSS jrS rS rS rS rS r	S	 r
S
 rSrg)r~   i  Nc                 @    0 U l         U(       a  U H	  u  p#X0U'   M     gg)zr
:param binding_list: list of (``AbstractVariableExpression``, ``AtomicExpression``) to initialize the dictionary
Nd)r-   binding_listvr   s       r   rK   BindingDict.__init__  s&     $Q % r   c                    [        U[        5      (       d   e[        U[        5      (       d   e X   nU(       a  X#:X  a  X R                  U'   g[        U[
        5      (       aM   XR                     n[        U5      nU(       a  XC:X  a  X@R                  UR                  '   g[        SU-  5      e[        SU-  5      e! [         a    Sn Nf = f! [         a    Sn Nlf = f)aP  
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)	rJ   r   r   KeyErrorr   r   r   r   r   )r-   r   bindingexistingbinding2s        r   __setitem__BindingDict.__setitem__  s     (H----':....	~H 7.&FF8!=>>  0 01 *(3Hx3+3w''(&CxP  #?8L +  	H	    s#   B? %C ?CCC C c                     [        U[        5      (       d   eU R                  U   nU(       a   U R                  U   nU(       a  M  gg! [         a    Us $ f = f)z4
Return the expression to which 'variable' is bound
N)rJ   r   r   r   )r-   r   intermediates      r   __getitem__BindingDict.__getitem__C  sY     (H----vvh'$#vvl3 l  $##$s   A	 	AAc                     XR                   ;   $ rV   r   )r-   r   s     r   __contains__BindingDict.__contains__P  s    vv~r   c                      [        5       nU R                   H  nU R                  U   X#'   M     UR                   H  nUR                  U   X#'   M     U$ ! [         a  n[        SU < SU< S35      UeSnAff = f)z
: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)r~   r   r   )r-   r   combinedr   r4   s        r   r   BindingDict.__add__S  sy    	"}HVV"ffQi WW#ggaj O 	"15u> 	s   AA 
A: A55A:c                 ,    [        U R                  5      $ rV   )r;   r   r   s    r   __len__BindingDict.__len__f  s    466{r   c                    ^  SR                  U 4S j[        T R                  R                  5       5       5       5      nSU-   S-   $ )Nr   c              3   J   >#    U  H  o S TR                   U    3v   M     g7f): Nr   )rd   r   r-   s     r   re   &BindingDict.__str__.<locals>.<genexpr>j  s$     P:OQs"TVVAYK0:Os    #r   r   )r   sortedr   keys)r-   data_strs   ` r   r   BindingDict.__str__i  s5    99P&:OPPX~##r   c                     SU -  $ r   r   r   s    r   r   BindingDict.__repr__m  r   r   r   rV   )r   r   r   r   rK   r   r   r   r   r   r   r   r   r   r   r   r~   r~     s+    %N$&$r   r~   c                    Uc
  [        5       nX:X  a  U$ [        U [        5      (       a  [        XU5      $ [        U[        5      (       a  [        XU5      $ [        U [        5      (       aX  [        U[        5      (       aC  [        U R                  UR                  U5      [        U R                  UR                  U5      -   $ [        X45      e)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
)	r~   rJ   r   _mgu_varr	   r   rX   rY   r   )r3   r   r   s      r   r   r   q  s     =v	A3	4	4h''	A3	4	4h''	A,	-	-*Q@U2V2V'JJ

H
$QZZXFG 	G A6
""r   c                     U R                   UR                  5       UR                  5       -  ;   a  [        X45      e[	        U R                   U4/5      U-   $ rV   )r   r   r   r   r~   )varr   r   s      r   r  r    sM    
||z(:+?+?+AAA011S\\:6788CCr   c                       \ rS rSrS rSrg)r   i  c                     [        U[        5      (       a  [        R                  U SU-  5        g [        R                  X5        g )Nz'%s' cannot be bound to '%s')rJ   tuple	ExceptionrK   )r-   args     r   rK   BindingException.__init__  s3    c5!!t%Cc%IJt)r   r   Nr   r   r   r   rK   r   r   r   r   r   r     s    *r   r   c                       \ rS rSrS rSrg)UnificationExceptioni  c                 >    [         R                  U SU SU S35        g )Nr   z' cannot unify with ')r  rK   )r-   r3   r   s      r   rK   UnificationException.__init__  s"    41QC'<QCq!ABr   r   Nr  r   r   r   r  r    s    Cr   r  c                   *    \ rS rSrSS jrS rS rSrg)r   i  c                     Xl         X l        g rV   enabledindent)r-   r  r  s      r   rK   DebugObject.__init__  s    r   c                 H    [        U R                  U R                  U-   5      $ rV   )r   r  r  )r-   rA   s     r   r   DebugObject.__add__  s    4<<q99r   c                 ^    U R                   (       a  [        SU R                  -  U-   5        g g )Nz    )r  r&   r  )r-   r   s     r   r   DebugObject.line  s$    <<&4;;&-. r   r  N)Tr   )r   r   r   r   rK   r   r   r   r   r   r   r   r     s    :/r   r   c                     [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S	5        [        S
5        [        R                  " S5      n [        R                  " S5      n[        R                  " S5      n[        U  SU SU S[	        5       R                  X U/5       35        [        R                  " S5      n [        R                  " S5      n[        R                  " S5      n[        U  SU SU S[	        5       R                  X U/5       35        [        R                  " S5      n[        R                  " S5      n[        U SU S[	        5       R                  X#/5       35        g )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   rS   )p1p2cps       r   testResolutionProverr+    s   I)*+,,-*+)*,-*+)**+,-N#CD,-			=	>B			/	0B12A	RD2$d1#R 0 2 8 8H EF
GH			<	=B			|	,B01A	RD2$d1#R 0 2 8 8H EF
GHVWA67A	QCtA3b)+11!S9:
;<r   c                     [         R                  " U 5      n[        5       R                  U5      n[	        SU SU 35        g )Nz|- r  )r   r&  r   rS   r&   )r4   fts      r   r%  r%    s9    a A  #A	Cs"QC.r   c                     [         R                  n [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S	5      5      5        [        [        U " S
5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        [        [        U " S5      5      5        g )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_clausifyr1    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                      [        5         [        5         [        5         [        5         [        R                  " S5      n [        [        X /5      R                  5       5        g )Nr$  )r1  r&   r+  r   r&  r'   rS   )r*  s    r   demor3    s@    O	G	Gh'A	
!!S
)
/
/
12r   __main__)NNrV   )/__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'   r:   rw   r   r   r   r   r   r$   r   r~   r   r  r   r  r   r+  r%  r1  r3  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   