
    Qdh                        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-             dS dS )(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dS )ProverParseErrorN)__name__
__module____qualname__     9lib/python3.11/site-packages/nltk/inference/resolution.pyr   r   "   s        Dr   r   c                   $    e Zd ZdZdZddZd ZdS )ResolutionProverANSWERTNFc                    |sg }d}	 g }|r#|                     t          |                      |D ]$}|                     t          |                     %|                     |          \  }}|r't          t                              |                     nY# t          $ rL}| j        r't          |          	                    d          rd}g }n|rt          |           n|Y d}~nd}~ww xY w||fS )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 0x///  , ,x{{++++"11'::OFG J-??HHIII 
	 
	 
	! 	c!ff&7&72' ' 	  !HHHHG
	   s   BB 
C."AC))C.c                    t          t                    }d}|t          |          k     r||                                         s||         r||         d         dz   }n|dz   }|t          |          k     r||k    r|r||                                         s||                             |           ||                             ||                   }|rA|D ];}|dz   |dz   f|_        |                    |           t          |          sd|fc S <d}n|dz  }|t          |          k     |dz  }|t          |          k     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(AAAA#g,,&& Avv!vGAJ,C,C,E,Eva***%,QZ%5%5gaj%A%A
% "-7 ; ;	67!eQU^	 2 'y 9 9 9'*9~~ !;,0'?$:$:$:!; "A!FA #g,,&& FA1 #g,,2 wr   )NNF)r   r   r   
ANSWER_KEYr&   r1   r!   r   r   r   r   r   &   sB        JM! ! ! !B         r   r   c                   <    e Zd ZddZddZddZed             ZdS )	r#   Nc                     |t          |t                    sJ nt                      }t          j        | |||           d| _        dS )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   sQ     f&6777777%''F"4{CCCr   Fc                     | j         n| j                            |                                 |                                 |          \  | _         }|| _        t                              |          | _        | 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}   sk    
 <$(L$7$7		T--//% %!DL' $DM1CCGLLDK|r   c                 ^   |                      |           t                      }t          t          t          j                            }| j        D ][}|D ]V}t          |t                    r?|j	        |k    r4t          |j
        t                    s|                    |j
                   W\|S N)rK   setr   r   r   r@   rE   rC   r	   functionargumentr   add)r)   r,   answers	answer_exclauseterms         r   find_answersz$ResolutionProverCommand.find_answers   s    

7%%&x0@0K'L'LMM	m 	/ 	/F / /t%:;;/22&t}6RSS 3 KK.../ r   c                 V   d}t          d | D                       }t          t          t          |                               }t          t          |                     D ]}d}d}| |                                         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   N   K   | ] }t          t          |                    V  !d S rM   )r6   r'   ).0rT   s     r   	<genexpr>z<ResolutionProverCommand._decorate_clauses.<locals>.<genexpr>   s0      DD&SV--DDDDDDr   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   s9   
 DDGDDDDD#c'll++,,s7||$$ 		> 		>AGDqz&&(( #"qz" 3gaj122^c#gaj//.B.BBQFG'QGs3q1u::67#a!e**DC=s==gaj==7==T====CC
r   )NNN)F)r   r   r   rD   rK   rV   staticmethodr$   r   r   r   r#   r#   l   sk                     \  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dS )Clausec                 X    t                               | |           d | _        d | _        d S rM   )r5   rD   _is_tautologyr:   )r)   datas     r   rD   zClause.__init__   s)    dD!!!!r   NFc           	         |t                      }|g g f}|g g f}t          |t                    rt          |          }t	          | ||||t
          |          }g }t          |          D ]R\  }}	||vrIt          |          D ]9\  }
}||
k    r.|
|vr*|	                    |          r|                    |
           :Sg }t          t          |                    D ]!}||vr|                    ||                    "|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   rb   r6   )r)   otherbindingsusedskippeddebugr>   subsumedr<   c1r=   c2r-   s                r   r9   zClause.unify   s4   & "}}H<8D?2hGeT"" 	'&&E#%42F
 

 z** 	+ 	+EAr  &z22 + +EArAvv!8"3"3B"3 ***s:'' 	- 	-A  jm,,,r   c                     | D ]	}||vr dS 
dS )z
        Return True iff every term in 'self' is a term in 'other'.

        :param other: ``Clause``
        :return: bool
        FTr   )r)   rw   r/   s      r   
isSubsetOfzClause.isSubsetOf   s-      	 	A~~uu tr   c                 Z   g }|D ]H}t          |t                    r|                    |j                   2|                    |            It	          |          }t                      }g g f}g g f}t          d          }t          t          | ||||t          |                    dk    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   rU   rk   rp   rr   r6   rs   _subsumes_finalize)	r)   rw   negatedotheratomnegatedotherClauserx   ry   rz   r{   s	            r   rv   zClause.subsumes   s      	+ 	+D$ 122 +##DI....##TE****#L11==Bxr(E"" && 
 
 	
r   c                 T    t          t                              | ||                    S rM   )rk   r5   __getslice__)r)   startends      r   r   zClause.__getslice__  s"    d''eS99:::r   c                 :    t          fd| D                       S )Nc                     g | ]}|v|	S r   r   )rZ   r/   rw   s     r   
<listcomp>z"Clause.__sub__.<locals>.<listcomp>  s    999Q!5..q...r   rk   r)   rw   s    `r   __sub__zClause.__sub__  s&    9999$999:::r   c                 R    t          t                              | |                    S rM   )rk   r5   __add__r   s     r   r   zClause.__add__  s    dll4//000r   c                    | j         | j         S t          |           D ]\  }}t          |t                    st	          |           dz
  }||k    rh| |         }t          |t
                    r|j        |k    r
d| _          dS n*t          |t
                    r||j        k    r
d| _          dS |dz  }||k    hd| _         dS )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.
        Nr4   TF)rm   ru   rC   r
   r6   r   rU   )r)   r<   r/   r=   bs        r   r7   zClause.is_tautology  s    
 )%%dOO 	 	DAqa!344 IIM!eeQA!!%677 (6Q;;15D.#'44 ' $A'899 (;;15D.#'44FA !ee #ur   c                 J    t          t          j        d | D                       S )Nc              3   h   K   | ]-}|                                 |                                z  V  .d S rM   )free	constants)rZ   r   s     r   r[   zClause.free.<locals>.<genexpr>7  s9      $W$W$diikkDNN4D4D&D$W$W$W$W$W$Wr   )r   operatoror_r)   s    r   r   zClause.free6  s$    hl$W$WRV$W$W$WXXXr   c                 >    t          fd| D                       S )z
        Replace every instance of variable with expression across every atom
        in the clause

        :param variable: ``Variable``
        :param expression: ``Expression``
        c                 <    g | ]}|                               S r   )replace)rZ   r   
expressionvariables     r   r   z"Clause.replace.<locals>.<listcomp>A  s'    KKKdt||Hj99KKKr   r   )r)   r   r   s    ``r   r   zClause.replace9  s,     KKKKKdKKKLLLr   c                 :    t          fd| D                       S )z
        Replace every binding

        :param bindings: A list of tuples mapping Variable Expressions to the
            Expressions to which they are bound.
        :return: ``Clause``
        c                 :    g | ]}|                               S r   )substitute_bindings)rZ   r   rx   s     r   r   z.Clause.substitute_bindings.<locals>.<listcomp>K  s'    KKKdt//99KKKr   r   )r)   rx   s    `r   r   zClause.substitute_bindingsC  s(     KKKKdKKKLLLr   c                 L    dd                     d | D                       z   dz   S )N{, c              3       K   | ]	}d |z  V  
dS )%sNr   )rZ   items     r   r[   z!Clause.__str__.<locals>.<genexpr>N  s&      <<ttd{<<<<<<r   })joinr   s    r   __str__zClause.__str__M  s-    TYY<<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   rv   r   r   r   r7   r   r   r   r   r   r   r   r   rk   rk      s          
- - - -^
 
 
$
 $
 $
L; ; ;; ; ;1 1 1  0Y Y YM M MM M MC C C    r   rk   c                 Z   |                     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  }n# t
          $ r Y nw xY w|S )zF
    This method facilitates movement through the terms of 'self'
    unify(,) r4   r   N)liner6   _iterate_secondrs   _unify_termsBindingException)firstsecondrx   ry   rz   finalize_methodr{   r-   
newskippednewbindingsnewusedunusednewfirst	newseconds                 r   rs   rs   T  s    
JJ44444(44555u:: #S[[ #ufhguMMM !68T7OUQY
 

 ajE!H:-wqz:
.!""Ivxz?ETUI
 
 	
	+7a&)Xt, ,(K&
 QRRy71:-q	9Hqrr
WQZ/&);InR	  FF   	 	 	D	 s   #A7D 
D('D(c                 $   |                     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  }n# t          $ r Y nw xY w|S )zG
    This method facilitates movement through the terms of 'other'
    r   r   r   r   r4   N)r   r6   r   r   r   )r   r   rx   ry   rz   r   r{   r   r-   r   r   r   r   r   s                 r   r   r     sx    
JJ44444(44555u:: S[[ ufhguMMM aj'!*q	{":;
 6!"":xz?ETUI
 
	+7a&)Xt, ,(K&
 QRRy71:-q	9Hqrr
WQZ/&);IoR	  FF   	 	 	D	 s   A7D   
DDc                 l   t          | t                    sJ t          |t                    sJ |t                      }|g g f}t          | t                    rIt          |t                    r4t          | j        ||          }|d         | gz   |d         |gz   f}g g f}nt          | t                    rHt          |t                    r3t          | |j        |          }|d         | gz   |d         |gz   f}g g f}nt          | t                    r;t          | j        j	        | j
        fg          }|d         | gz   |d         f}g |gf}nat          |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
    Nr   r4   )rC   r   rp   r   r	   most_general_unificationrU   r
   r   r   r   r   )r/   r   rx   ry   r   r   r   s          r   r   r     s    a$$$$$a$$$$$==|Bx !&'' 'Jq:O,P,P '.qvq(CC7aS=$q'QC-0b	A,	-	- '*Q@Q2R2R '.q!&(CC7aS=$q'QC-0b 
A)	*	* 
'!AG$4ah#?"@AA7aS=$q'*qc	A)	*	* '!AG$4ah#?"@AA7DGqcM*#r 1v&&&''r   c                     |d         s|d         rRt          |d         |d         z   | z   |z             }|                    d|z             |                    |          gS |                    d           g S )Nr   r4   z  -> New Clause: %sz  -> End)rk   r   r   )r   r   rx   ry   rz   r{   r?   s          r   rt   rt     s    Aw $q' 71:
2U:VCDD	

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

:	r   c                 T    t          |d                   st          |           sdgS g S )Nr   T)r6   )r   r   rx   ry   rz   r{   s         r   r   r     s/    wqz?? 3u::  v	r   c                 *   g }t          t          |                     D ]s}|                                D ]G}t          |j                  r1t          t                                }|                    ||          }H|                    |           t|S )zC
    Skolemize, clausify, and standardize the variables apart.
    )		_clausifyr   r   r   namer   r   r   r8   )r   clause_listrT   r   newvars        r   r    r      s     KIj1122 # #KKMM 	6 	6D## 6+O,=,=>>f556""""r   c                    t          | t                    r)t          | j                  t          | j                  z   S t          | t
                    rdt          | 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                    rVt          | 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
   rk   r	   r   rU   r   )r   r   r   s      r   r   r     sd    *m,, *)**Yz7H-I-III	J	-	- ***++:,--5zzQ6{{aa6!9$%%	J 2	3	3 *
|$$%%	J 5	6	6 *
|$$%%	J 1	2	2 *jo'<== 	*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
dS )rp   Nc                 6    i | _         |r|D ]\  }}|| |<   dS dS )z
        :param binding_list: list of (``AbstractVariableExpression``, ``AtomicExpression``) to initialize the dictionary
        Nd)r)   binding_listvr   s       r   rD   zBindingDict.__init__  sE      	&  AQ	 	 r   c                    t          |t                    sJ t          |t                    sJ 	 | |         }n# t          $ r d}Y nw xY w|r||k    r|| j        |<   dS t          |t
                    r[	 | |j                 }n# t          $ r d}Y nw xY wt          |          }|r||k    r|| j        |j        <   dS t          d|z            t          d|z            )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__  sA    (H-----':.....	H~HH 	 	 	HHH	  	7h..&DF8!=>> 	  01        *(33H x833+3w'(((&CxP   #?8L  s!   9 AA5B BBc                     t          |t                    sJ | j        |         }|r%	 | j        |         }n# t          $ r |cY S w xY w|#dS dS )zD
        Return the expression to which 'variable' is bound
        N)rC   r   r   r   )r)   r   intermediates      r   __getitem__zBindingDict.__getitem__C  s     (H-----vh' 	$$#vl3 $ $ $####$  	$ 	$ 	$ 	$ 	$s   6 AAc                     || j         v S rM   r   )r)   r   s     r   __contains__zBindingDict.__contains__P  s    tv~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)rp   r   r   )r)   rw   combinedr   r0   s        r   r   zBindingDict.__add__S  s    	"}}HV ( ("fQiW ) )#gajO 	 	 	""15uuu>  	s   AA 
A,A''A,c                 *    t          | j                  S rM   )r6   r   r   s    r   __len__zBindingDict.__len__f  s    46{{r   c                      d                      fdt           j                                                  D                       }d|z   dz   S )Nr   c              3   <   K   | ]}| d j         |          V  dS ): Nr   )rZ   r   r)   s     r   r[   z&BindingDict.__str__.<locals>.<genexpr>j  s7      PPQ00TVAY00PPPPPPr   r   r   )r   sortedr   keys)r)   data_strs   ` r   r   zBindingDict.__str__i  sJ    99PPPP&:O:OPPPPPX~##r   c                     d| z  S r   r   r   s    r   r   zBindingDict.__repr__m  r   r   rM   )r   r   r   rD   r   r   r   r   r   r   r   r   r   r   rp   rp     s           % % %N$ $ $    &  $ $ $    r   rp   c                    |t                      }| |k    r|S t          | t                    rt          | ||          S t          |t                    rt          || |          S t          | t                    rLt          |t                    r7t          | 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
    )	rp   rC   r   _mgu_varr	   r   rO   rP   r   )r/   r   rx   s      r   r   r   q  s     ==Avv	A3	4	4 G1h'''	A3	4	4 G1h'''	A,	-	- G*Q@U2V2V G'J
H
 
$QZXFFG 	G Aq6
"
""r   c                     | j         |                                |                                z  v rt          | |f          t	          | j         |fg          |z   S rM   )r   r   r   r   rp   )varr   rx   s      r   r   r     sZ    
|z((:+?+?+A+AAAAZ0111S\:67888CCr   c                       e Zd Zd ZdS )r   c                     t          |t                    r t                              | d|z             d S t                              | |           d S )Nz'%s' cannot be bound to '%s')rC   tuple	ExceptionrD   )r)   args     r   rD   zBindingException.__init__  sR    c5!! 	*t%Cc%IJJJJJtS)))))r   Nr   r   r   rD   r   r   r   r   r     s#        * * * * *r   r   c                       e Zd Zd ZdS )UnificationExceptionc                 J    t                               | d| d| d           d S )Nr   z' cannot unify with ')r   rD   )r)   r/   r   s      r   rD   zUnificationException.__init__  s2    4!AQ!A!AQ!A!A!ABBBBBr   Nr   r   r   r   r   r     s(        C C C C Cr   r   c                   "    e Zd ZddZd Zd ZdS )rr   Tr   c                 "    || _         || _        d S rM   )enabledindent)r)   r   r   s      r   rD   zDebugObject.__init__  s    r   c                 <    t          | j        | j        |z             S rM   )rr   r   r   )r)   r<   s     r   r   zDebugObject.__add__  s    4<q999r   c                 L    | j         rt          d| j        z  |z              d S d S )Nz    )r   r"   r   )r)   r   s     r   r   zDebugObject.line  s6    < 	/&4;&-.....	/ 	/r   N)Tr   )r   r   r   rD   r   r   r   r   r   rr   rr     sF           : : :/ / / / /r   rr   c                  J   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	                                          || |g                      t          j        d          } t          j        d          }t          j        d          }t          |  d| d| dt	                                          || |g                      t          j        d          }t          j        d          }t          | d| dt	                                          ||g                      d S )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DD,---		=	>	>B		/	0	0B122A	R
G
G2
G
G1
G
G 0 2 2 8 8RH E E
G
GHHH		<	=	=B		|	,	,B011A	R
G
G2
G
G1
G
G 0 2 2 8 8RH E E
G
GHHHVWWA677A	Q
;
;A
;
;)++11!aS99
;
;<<<<<r   c                     t          j        |           }t                                          |          }t	          d| d|            d S )Nz|- r   )r   r   r   rK   r"   )r0   fts      r   r   r     sK    a  A  ##A	...Q..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                               d S )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
    s=   !E	(55''
(
()))	(55/00
1
1222	(55/00
1
1222	(55899
:
:;;;	(55-..
/
/000	(55677
8
8999	(55/00
1
1222	(55*++
,
,---	(55))
*
*+++	(55+,,
-
-...	(55))
*
*+++	(55)**
+
+,,,	(55''
(
()))	(55.//
0
0111	(55.//
0
0111	(55677
8
8999	(55LMM
N
NOOOOOr   c                      t                       t                       t                       t                       t          j        d          } t          t          | | g                                                     d S )Nr   )r
  r"   r  r   r   r#   rK   )r  s    r   demor    sf    OOO	GGG	GGGh''A	
!!aS
)
)
/
/
1
122222r   __main__)NNrM   )/__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   rk   rs   r   r   rt   r   r    r   rp   r   r   r   r   rr   r  r   r
  r  r   r   r   r   <module>r     sU     # # # # # #       8 8 8 8 8 8 8 8                               	 	 	 	 	y 	 	 	C  C  C  C  C v C  C  C L? ? ? ? ?/ ? ? ?Dc c c c cT c c cL) ) )X$ $ $N+( +( +( +(\  	 	 	    0] ] ] ] ] ] ] ]@# # # #6D D D* * * * *y * * *C C C C C9 C C C

/ 
/ 
/ 
/ 
/ 
/ 
/ 
/= = =>  P P P43 3 3 zDFFFFF r   