ó
    ´OÂf‹=  ã                   óÌ  • S r SSKrSSKrSSKrSSKJrJr  SSKJrJ	r	J
r
JrJrJrJrJrJr  SSSSS	S
SSSS.	r " S S5      r " S S\\5      r " S S5      rS rS r " S S\\5      r " S S\5      r " S S\5      r " S S\5      rS rS  rS! rS"/ 4S#/ 4S$/ 4S%/ 4S&/ 4S#/ 4S$/ 4S&/ 4S'/ 4S(/ 4S)S*S+/4S,/ 4S-/ 4S./ 4S/S0/4S1S0/4/r/ S2Qr S6S3 jr!S4 r"\#S5:X  a  \"" 5         gg)7zD
A theorem prover that makes use of the external 'Prover9' package.
é    N)ÚBaseProverCommandÚProver)	ÚAllExpressionÚAndExpressionÚEqualityExpressionÚExistsExpressionÚ
ExpressionÚIffExpressionÚImpExpressionÚNegatedExpressionÚOrExpressionTz(FATAL)Fz
(MAX_MEGS)z(MAX_SECONDS)z(MAX_GIVEN)z
(MAX_KEPT)z(ACTION)z	(SIGSEGV))	r   é   é   é   é   é   é   é   ée   c                   ó"   • \ rS rSrSrSS jrSrg)ÚProver9CommandParenté/   zÄ
A common base class used by both ``Prover9Command`` and ``MaceCommand``,
which is responsible for maintaining a goal and a set of assumptions,
and generating prover9-style input files from them.
c                 ó  • UR                  5       S:X  a#  U R                  5        H  n[        U5        M     gUR                  5       S:X  a,  [        U R                  5       5       H  n[        U5        M     g[	        SU-  5      e)z,
Print the list of the current assumptions.
ÚnltkÚprover9z*Unrecognized value for 'output_format': %sN)ÚlowerÚassumptionsÚprintÚconvert_to_prover9Ú	NameError)ÚselfÚoutput_formatÚas      Ú8/usr/lib/python3/dist-packages/nltk/inference/prover9.pyÚprint_assumptionsÚ&Prover9CommandParent.print_assumptions6   sv   € ð ×ÑÓ  FÓ*Ø×%Ñ%Ö'�Ü�a–ò (à× Ñ Ó" iÓ/Ü'¨×(8Ñ(8Ó(:Ö;�Ü�a–ò <ô Ø<¸}ÑLóð ó    © N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r%   Ú__static_attributes__r(   r'   r$   r   r   /   s   † ñ÷r'   r   c                   ó,   • \ rS rSrSrSS jrSS jrSrg)	ÚProver9CommandéF   zª
A ``ProverCommand`` specific to the ``Prover9`` prover.  It contains
the a print_assumptions() method that is used to print the list
of assumptions in multiple formats.
Nc                 ó�   • U(       d  / nUb  [        U[        5      (       d   eO[        U5      n[        R                  " XX5        g)al  
: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)
:param timeout: number of seconds before timeout; set to 0 for
    no timeout.
:type timeout: int
:param prover: a prover.  If not set, one will be created.
:type prover: Prover9
N)Ú
isinstanceÚProver9r   Ú__init__)r!   Úgoalr   ÚtimeoutÚprovers        r$   r5   ÚProver9Command.__init__M   s?   € ö ØˆKàÑÜ˜f¤g×.Ñ.Ð.Ñ.ä˜WÓ%ˆFä×"Ò" 4°ÕCr'   c                 óŒ   • U(       a.  U R                   R                  US/5      S   R                  5       $ UR                  5       $ )z)
:see BaseProverCommand.decorate_proof()
Ústriplabelsr   )Ú_proverÚ_call_prooftransÚrstrip)r!   Úproof_stringÚsimplifys      r$   Údecorate_proofÚProver9Command.decorate_proofd   sB   € ö Ø—<‘<×0Ñ0°À¸ÓOØñç‰f‹hðð  ×&Ñ&Ó(Ð(r'   r(   )NNé<   N)T)r)   r*   r+   r,   r-   r5   rA   r.   r(   r'   r$   r0   r0   F   s   † ñôD÷.	)r'   r0   c                   óJ   • \ rS rSrSrSrSS jrS rS rSS jr	/ S4S	 jr
S
rg)ÚProver9Parentép   z°
A common class extended by both ``Prover9`` and ``Mace <mace.Mace>``.
It contains the functionality required to convert NLTK-style
expressions into Prover9-style expressions.
NFc           	      óö   • Uc  S U l         S U l        g Sn[        R                  R	                  UUS/SX3S-   /US9U l        U R                  R                  [        R                  R                  S5      U l         g )Nr   ÚPROVER9ú'https://www.cs.unm.edu/~mccune/prover9/ú.exe)Úpath_to_binÚenv_varsÚurlÚbinary_namesÚverboser   )	Ú_binary_locationÚ_prover9_binr   Ú	internalsÚfind_binaryÚrsplitÚosÚpathÚsep)r!   Úbinary_locationrO   Únames       r$   Úconfig_prover9ÚProver9Parent.config_prover9y   sy   € ØÑ"Ø$(ˆDÔ!Ø $ˆDÕàˆDÜ $§¡× :Ñ :ØØ+Ø#˜Ø=Ø"¨6¡MÐ2Øð !;ð !ˆDÔð %)×$5Ñ$5×$<Ñ$<¼R¿W¹W¿[¹[È!Ó$LˆDÕ!r'   c                 ó¤   • SnU(       a$  US-  n[        U5       H  nUSU-  -  nM     US-  nU(       a  US-  nUS[        U5      -  -  nUS-  nU$ )z«
:return: The input string that should be provided to the
    prover9 binary.  This string is formed based on the goal,
    assumptions, and timeout value of this object.
Ú zformulas(assumptions).
z    %s.
zend_of_list.

zformulas(goals).
)r   )r!   r6   r   ÚsÚp9_assumptions        r$   Úprover9_inputÚProver9Parent.prover9_input‰   st   € ð ˆæØÐ+Ñ+ˆAÜ!3°KÖ!@�Ø�[ =Ñ0Ñ0’ñ "AàÐ#Ñ#ˆAæØÐ%Ñ%ˆAØ�Ô1°$Ó7Ñ7Ñ7ˆAØÐ#Ñ#ˆAàˆr'   c                 ó
   • / SQ$ )z¡
A list of directories that should be searched for the prover9
executables.  This list is used by ``config_prover9`` when searching
for the prover9 executables.
)z/usr/local/bin/prover9z/usr/local/bin/prover9/binz/usr/local/binz/usr/binz/usr/local/prover9z/usr/local/share/prover9r(   )r!   s    r$   Úbinary_locationsÚProver9Parent.binary_locationsž   s   € ò
ð 	
r'   c           	      ó¨   • U R                  5       nU R                  b  X0R                  /-  n[        R                  R	                  UUS/SXS-   /US9$ )NrH   rI   rJ   )Ú
searchpathrL   rM   rN   rO   )rc   rP   r   rR   rS   )r!   rY   rO   rc   s       r$   Ú_find_binaryÚProver9Parent._find_binary­   sf   € Ø×0Ñ0Ó2ÐØ× Ñ Ñ,Ø×!6Ñ!6Ð 7Ñ7ÐÜ�~‰~×)Ñ)ØØ'Ø�[Ø9Ø v¡Ð.Øð *ð 
ð 	
r'   c                 ó  • U(       a%  [        SU5        [        SU5        [        SUS5        U/U-   n UR                  S5      n[        R                  " U[        R
                  [        R                  [        R
                  S9nUR                  US9u  pxU(       a>  [        SUR                  5        U(       a  [        S	US5        U(       a  [        S
US5        UR                  S5      UR                  4$ ! [         a     NÀf = f)a  
Call the binary with the given input.

:param input_str: A string whose contents are used as stdin.
:param binary: The location of the binary to call
:param args: A list of command-line arguments.
:return: A tuple (stdout, returncode)
:see: ``config_prover9``
zCalling:zArgs:zInput:
Ú
Úutf8)ÚstdoutÚstderrÚstdin)ÚinputzReturn code:zstdout:
zstderr:
zutf-8)
r   ÚencodeÚAttributeErrorÚ
subprocessÚPopenÚPIPEÚSTDOUTÚcommunicateÚ
returncodeÚdecode)	r!   Ú	input_strÚbinaryÚargsrO   ÚcmdÚprl   rm   s	            r$   Ú_callÚProver9Parent._callº   sâ   € ö Ü�*˜fÔ%Ü�'˜4Ô Ü�*˜i¨Ô.ð ˆh˜‰oˆð	Ø!×(Ñ(¨Ó0ˆIô ×ÒØœ
Ÿ™´
×0AÑ0AÌÏÉñ
ˆð Ÿ=™=¨y˜=Ð9ÑˆæÜ�. !§,¡,Ô/ÞÜ�k 6¨4Ô0ÞÜ�k 6¨4Ô0à—‘˜gÓ&¨¯©Ð5Ð5øô ó 	Ùð	ús   ´C9 Ã9
DÄD)rP   rQ   )F)r)   r*   r+   r,   r-   rP   rZ   r`   rc   rg   r~   r.   r(   r'   r$   rE   rE   p   s0   † ñð ÐôMò ò*
ô
ð -/¸÷ !6r'   rE   c                 ó  • [        U [        5      (       a6  / nU  H,  n UR                  [        UR	                  5       5      5        M.     U$  [        U R	                  5       5      $ !   [        SU -  5        e = f!   [        SU -  5        e = f)z3
Convert a ``logic.Expression`` to Prover9 format.
z4input %s cannot be converted to Prover9 input syntax)r3   ÚlistÚappendÚ_convert_to_prover9r@   r   )ro   Úresultr^   s      r$   r   r   Þ   sŠ   € ô �%œ×ÑØˆÛˆAðØ—‘Ô1°!·*±*³,Ó?Ö@ñ ð ˆð	Ü& u§~¡~Ó'7Ó8Ð8øðÜÐLÈuÑTÔUØûð
	ÜÐHÈ5ÑPÔQØús   ž(A&ÁA: Á&A7Á:Bc                 ój  • [        U [        5      (       a1  S[        U R                  5      -   S-   [	        U R
                  5      -   $ [        U [        5      (       a1  S[        U R                  5      -   S-   [	        U R
                  5      -   $ [        U [        5      (       a  S[	        U R
                  5      -   S-   $ [        U [        5      (       a4  S[	        U R                  5      -   S-   [	        U R                  5      -   S-   $ [        U [        5      (       a4  S[	        U R                  5      -   S-   [	        U R                  5      -   S-   $ [        U [        5      (       a4  S[	        U R                  5      -   S	-   [	        U R                  5      -   S-   $ [        U [        5      (       a4  S[	        U R                  5      -   S
-   [	        U R                  5      -   S-   $ [        U [        5      (       a4  S[	        U R                  5      -   S-   [	        U R                  5      -   S-   $ [        U 5      $ )z;
Convert ``logic.Expression`` to Prover9 formatted string.
zexists Ú zall z-(Ú)Ú(z & z | z -> z <-> z = )r3   r   ÚstrÚvariablerƒ   Útermr   r   r   ÚfirstÚsecondr   r   r
   r   )Ú
expressions    r$   rƒ   rƒ   ó   sW  € ô �*Ô.×/Ñ/àÜ�*×%Ñ%Ó&ñ'àñô " *§/¡/Ó2ñ3ð	
ô 
�J¤×	.Ñ	.àÜ�*×%Ñ%Ó&ñ'àñô " *§/¡/Ó2ñ3ð	
ô 
�JÔ 1×	2Ñ	2ØÔ)¨*¯/©/Ó:Ñ:¸SÑ@Ð@Ü	�J¤×	.Ñ	.àÜ! *×"2Ñ"2Ó3ñ4àñô " *×"3Ñ"3Ó4ñ5ð ñ	ð	
ô 
�J¤×	-Ñ	-àÜ! *×"2Ñ"2Ó3ñ4àñô " *×"3Ñ"3Ó4ñ5ð ñ	ð	
ô 
�J¤×	.Ñ	.àÜ! *×"2Ñ"2Ó3ñ4àñô " *×"3Ñ"3Ó4ñ5ð ñ	ð	
ô 
�J¤×	.Ñ	.àÜ! *×"2Ñ"2Ó3ñ4àñô " *×"3Ñ"3Ó4ñ5ð ñ	ð	
ô 
�JÔ 2×	3Ñ	3àÜ! *×"2Ñ"2Ó3ñ4àñô " *×"3Ñ"3Ó4ñ5ð ñ	ð	
ô �:‹Ðr'   c                   óR   • \ rS rSrSrSrS
S jrSS jrS r/ S4S jr	/ S4S jr
S	rg)r4   i3  Nc                 ó   • Xl         g )N)Ú_timeout)r!   r7   s     r$   r5   ÚProver9.__init__7  s   € ØŒð	&r'   Fc                 ód   • U(       d  / nU R                  U R                  X5      US9u  pEUS:H  U4$ )zÉ
Use Prover9 to prove a theorem.
:return: A pair whose first element is a boolean indicating if the
proof was successful (i.e. returns value of 0) and whose second element
is the output of the prover.
)rO   r   )Ú_call_prover9r`   )r!   r6   r   rO   rl   rw   s         r$   Ú_proveÚProver9._prove=  sE   € ö ØˆKà!×/Ñ/Ø×Ñ˜tÓ1¸7ð 0ð 
Ñˆð ˜a‘ Ð(Ð(r'   c                 ó8   • SnU[         R                  XU5      -   $ )z#
:see: Prover9Parent.prover9_input
zclear(auto_denials).
)rE   r`   )r!   r6   r   r^   s       r$   r`   ÚProver9.prover9_inputL  s!   € ð %ˆØ”=×.Ñ.¨t¸;ÓGÑGÐGr'   c                 óz  • U R                   c  U R                  SU5      U l         SnU R                  S:”  a  USU R                  -  -  nXA-  nU R                  X@R                   X#5      u  pVUS;  aI  SnXu;   a$  UR	                  U5      nXXS R                  5       n	OSn	US;   a  [        Xi5      e[        Xi5      eXV4$ )	zß
Call the ``prover9`` binary with the given input.

:param input_str: A string whose contents are used as stdin.
:param args: A list of command-line arguments.
:return: A tuple (stdout, returncode)
:see: ``config_prover9``
Nr   r]   r   zassign(max_seconds, %d).

)r   r   z%%ERROR:)r   r   r   r   )rQ   rg   r‘   r~   ÚindexÚstripÚProver9LimitExceededExceptionÚProver9FatalException)
r!   ry   r{   rO   Úupdated_input_strrl   rw   ÚerrormsgprefixÚmsgstartÚerrormsgs
             r$   r”   ÚProver9._call_prover9S  sÓ   € ð ×ÑÑ$Ø $× 1Ñ 1°)¸WÓ EˆDÔàÐØ�=‰=˜1ÓØÐ!?À$Ç-Á-Ñ!OÑOÐØÑ&Ðà!ŸZ™ZØ×0Ñ0°$ó
Ñˆð ˜VÓ#Ø'ˆNØÓ'Ø!Ÿ<™<¨Ó7�Ø! )Ð,×2Ñ2Ó4‘à�Ø˜\Ó)Ü3°JÓIÐIä+¨JÓAÐAàÐ!Ð!r'   c                 ó‚   • U R                   c  U R                  SU5      U l         U R                  XR                   X#5      $ )zâ
Call the ``prooftrans`` binary with the given input.

:param input_str: A string whose contents are used as stdin.
:param args: A list of command-line arguments.
:return: A tuple (stdout, returncode)
:see: ``config_prover9``
Ú
prooftrans)Ú_prooftrans_binrg   r~   )r!   ry   r{   rO   s       r$   r=   ÚProver9._call_prooftransv  s<   € ð ×ÑÑ'Ø#'×#4Ñ#4°\À7Ó#KˆDÔ à�z‰z˜)×%9Ñ%9¸4ÓIÐIr'   )r¥   rQ   r‘   )rC   )NNF)r)   r*   r+   r,   rQ   r¥   r5   r•   r`   r”   r=   r.   r(   r'   r$   r4   r4   3  s6   † Ø€LØ€Oô&ô)òHð -/¸ô !"ðF 02¸5÷ Jr'   r4   c                   ó   • \ rS rSrS rSrg)ÚProver9Exceptioni…  c                 ó^   • [         U   nU(       a  USU-  -  n[        R                  X5        g )Nz
%s)Úp9_return_codesÚ	Exceptionr5   )r!   rw   ÚmessageÚmsgs       r$   r5   ÚProver9Exception.__init__†  s,   € Ü˜jÑ)ˆÞØ�6˜GÑ#Ñ#ˆCÜ×Ñ˜4Õ%r'   r(   N)r)   r*   r+   r,   r5   r.   r(   r'   r$   r¨   r¨   …  s   † õ&r'   r¨   c                   ó   • \ rS rSrSrg)r�   i�  r(   N©r)   r*   r+   r,   r.   r(   r'   r$   r�   r�   �  ó   † Úr'   r�   c                   ó   • \ rS rSrSrg)rœ   i‘  r(   Nr°   r(   r'   r$   rœ   rœ   ‘  r±   r'   rœ   c                  ó  • [         R                  " S5      n [         R                  " S5      n[        X/S9nS Ul        / Ul        UR                  5         [        UR                  5       5        [        UR                  5       5        g )Nz(walk(j) & sing(j))zwalk(j)©r   )r	   Ú
fromstringr0   Ú_executable_pathÚprover9_searchÚprover   Úproof)r#   Úgr}   s      r$   Útest_configr»   š  sd   € Ü×ÒÐ3Ó4€AÜ×Ò˜iÓ(€AÜ�q cÑ*€AØ€AÔØ€AÔØ‡G�G„Iä	ˆ!�'‰'‹)ÔÜ	ˆ!�'‰'‹)Õr'   c                 ój   • U  H-  n[         R                  " U5      n[        [        U5      5        M/     g)z
Test that parsing works OK.
N)r	   rµ   r   r   )ÚexprÚtÚes      r$   Útest_convert_to_prover9rÀ   ¦  s,   € ó ˆÜ×!Ò! !Ó$ˆÜÔ  Ó#Ö$ò r'   c                 ó  • U  H�  u  p[         R                  " U5      nU Vs/ s H  n[         R                  " U5      PM     nn[        X5S9R                  5       nU H  n[	        SU-  5        M     [	        SU SU S35        Mƒ     gs  snf )z*
Try some proofs and exhibit the results.
r´   z   %sz|- z: rj   N)r	   rµ   r0   r¸   r   )Ú	argumentsr6   r   rº   r#   Úalistr}   s          r$   Ú
test_proverÄ   ¯  sƒ   € ó 'ÑˆÜ×!Ò! $Ó'ˆÙ3>Ó?²;¨a”×&Ò& qÖ)±;ˆÐ?Ü˜1Ñ0×6Ñ6Ó8ˆÛˆAÜ�'˜A‘+Öñ ä��A�3�b˜˜˜2ÐÖò 'ùâ?s   ¢ B	z(man(x) <-> (not (not man(x))))z(not (man(x) & (not man(x))))z(man(x) | (not man(x)))z(man(x) & (not man(x)))z(man(x) -> man(x))z(man(x) <-> man(x))z(not (man(x) <-> (not man(x))))zmortal(Socrates)zall x.(man(x) -> mortal(x))zman(Socrates)zA((all x.(man(x) -> walks(x)) & man(Socrates)) -> some y.walks(y))z(all x.man(x) -> all x.man(x))zsome x.all y.sees(x,y)z#some e3.(walk(e3) & subj(e3, mary))zWsome e1.(see(e1) & subj(e1, john) & some e2.(pred(e1, e2) & walk(e2) & subj(e2, mary)))zVsome x e1.(see(e1) & subj(e1, x) & some e2.(pred(e1, e2) & walk(e2) & subj(e2, mary))))zsome x y.sees(x,y)zsome x.(man(x) & walks(x))z\x.(man(x) & walks(x))z\x y.sees(x,y)zwalks(john)z\x.big(x, \y.mouse(y))z/(walks(x) & (runs(x) & (threes(x) & fours(x))))z(walks(x) -> runs(x))zsome x.(PRO(x) & sees(John, x))z some x.(man(x) & (not walks(x)))zall x.(man(x) -> walks(x))c                 ó    • [        SU -  5        g )NÚ-)r   )Únums    r$   ÚspacerrÈ   è  s   € Ü	ˆ#�‰)Õr'   c                  óú   • [        S5        [        5         [        5         [        5         [        S5        [        5         [        [        5        [        5         [        S5        [        5         [        [        5        g )NzTesting configurationz$Testing conversion to Prover9 formatzTesting proofs)r   rÈ   r»   rÀ   ÚexpressionsrÄ   rÂ   r(   r'   r$   ÚdemorË   ì  sK   € Ü	Ð
!Ô"Ü
„HÜ„MÜ	„GÜ	Ð
0Ô1Ü
„HÜœKÔ(Ü	„GÜ	Ð
ÔÜ
„HÜŒyÕr'   Ú__main__)é-   )$r-   rU   rr   r   Únltk.inference.apir   r   Únltk.sem.logicr   r   r   r   r	   r
   r   r   r   rª   r   r0   rE   r   rƒ   r4   r«   r¨   r�   rœ   r»   rÀ   rÄ   rÂ   rÊ   rÈ   rË   r)   r(   r'   r$   Ú<module>rÐ      s�  ðñó 
Û ã ß 8÷
÷ 
õ 
ð  ØØàØØØØØ	ñ€÷ñ ô.')Ð)Ð+<ô ')÷Tk6ñ k6ò\ò*=ô@OJˆm˜Vô OJôd&�yô &ô	Ð,ô 	ô	Ð$4ô 	ò	ò%ò
 ð '¨Ð+Ø$ bÐ)Ø Ð#Ø Ð#Ø˜2ÐØ$ bÐ)Ø Ð#Ø˜2ÐØ˜BÐØ&¨Ð+ØÐ7¸ÐIÐJØHÈ"ÐMØ% rÐ*Ø˜rÐ"à-àeð	
ðð 	aàeð	
ðð+€	ò:€ôòð ˆzÓÙ…Fð r'   