Ë
    çÍ:jŸ=  ã                   óÈ  — d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZ ddddd	d
ddddœ	Z G d„ d«      Z G d„ dee«      Z G d„ d«      Zd„ Zd„ Z G d„ dee«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Zd„ Zd „ Zd!„ Zd"g fd#g fd$g fd%g fd&g fd#g fd$g fd&g fd'g fd(g fd)d*d+gfd,g fd-g fd.g fd/d0gfd1d0gfgZg d2¢Z d6d3„Z!d4„ Z"e#d5k(  r e"«        yy)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                   ó   — e Zd ZdZdd„Zy)ÚProver9CommandParentzÔ
    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                 ó   — |j                  «       dk(  r!| j                  «       D ]  }t        |«       Œ y|j                  «       dk(  r*t        | j                  «       «      D ]  }t        |«       Œ yt	        d|z  «      ‚)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      úk/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/inference/prover9.pyÚprint_assumptionsz&Prover9CommandParent.print_assumptions6   s€   € ð ×ÑÓ  FÒ*Ø×%Ñ%Ó'ò �Ü�a•ñà× Ñ Ó" iÒ/Ü'¨×(8Ñ(8Ó(:Ó;ò �Ü�a•ñô Ø<¸}ÑLóð ó    N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   © r%   r#   r   r   /   s   „ ñôr%   r   c                   ó    — e Zd ZdZdd„Zdd„Zy)ÚProver9Commandzº
    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                 óz   — |sg }|�t        |t        «      sJ ‚t        |«      }t        j                  | |||«       y)aÄ  
        :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#   r0   zProver9Command.__init__M   s@   € ñ ØˆKàÐÜ˜f¤gÔ.Ð.Ð.ä˜WÓ%ˆFä×"Ñ" 4¨°°{ÕCr%   c                 ó‚   — |r.| j                   j                  |dg«      d   j                  «       S |j                  «       S )z9
        :see BaseProverCommand.decorate_proof()
        Ústriplabelsr   )Ú_proverÚ_call_prooftransÚrstrip)r    Úproof_stringÚsimplifys      r#   Údecorate_proofzProver9Command.decorate_proofd   sB   € ñ Ø—<‘<×0Ñ0°À¸ÓOØñç‰f‹hðð  ×&Ñ&Ó(Ð(r%   )NNé<   N)T)r&   r'   r(   r)   r0   r;   r*   r%   r#   r,   r,   F   s   „ ñóDô.	)r%   r,   c                   ó<   — e Zd ZdZdZd	d„Zd„ Zd„ Zd	d„Zg dfd„Z	y)
ÚProver9ParentzÀ
    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           	      óü   — |€d | _         d | _        y d}t        j                  j	                  ||dgd||dz   g|¬«      | _        | j                  j                  t        j                  j                  d«      | _         y )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_locationrG   Únames       r#   Úconfig_prover9zProver9Parent.config_prover9y   s{   € ØÐ"Ø$(ˆDÔ!Ø $ˆDÕàˆDÜ $§¡× :Ñ :ØØ+Ø#˜Ø=Ø" D¨6¡MÐ2Øð !;ó !ˆDÔð %)×$5Ñ$5×$<Ñ$<¼R¿W¹W¿[¹[È!Ó$LˆDÕ!r%   c                 óŒ   — d}|r"|dz  }t        |«      D ]
  }|d|z  z  }Œ |dz  }|r|dz  }|dt        |«      z  z  }|dz  }|S )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    r1   r   ÚsÚp9_assumptions        r#   Úprover9_inputzProver9Parent.prover9_input‰   sx   € ð ˆáØÐ+Ñ+ˆAÜ!3°KÓ!@ò 1�Ø�[ =Ñ0Ñ0‘ð1àÐ#Ñ#ˆAáØÐ%Ñ%ˆAØ�Ô1°$Ó7Ñ7Ñ7ˆAØÐ#Ñ#ˆAàˆr%   c                 ó
   — g d¢S )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_locationszProver9Parent.binary_locationsž   s   € ò
ð 	
r%   c           	      ó°   — | j                  «       }| j                  �|| j                  gz  }t        j                  j	                  ||dgd||dz   g|¬«      S )Nr@   rA   rB   )Ú
searchpathrD   rE   rF   rG   )rY   rH   r   rJ   rK   )r    rQ   rG   rY   s       r#   Ú_find_binaryzProver9Parent._find_binary­   sj   € Ø×0Ñ0Ó2ÐØ× Ñ Ð,Ø ×!6Ñ!6Ð 7Ñ7ÐÜ�~‰~×)Ñ)ØØ'Ø�[Ø9Ø  v¡Ð.Øð *ó 
ð 	
r%   c                 óô  — |r%t        d|«       t        d|«       t        d|d«       |g|z   }	 |j                  d«      }t        j                  |t        j
                  t        j                  t        j
                  ¬«      }|j                  |¬«      \  }}|r4t        d|j                  «       |rt        d	|d«       |rt        d
|d«       |j                  d«      |j                  fS # t        $ r Y Œ¶w xY w)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ÚargsrG   ÚcmdÚpr`   ra   s	            r#   Ú_callz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   ¯C+ Ã+	C7Ã6C7)F)
r&   r'   r(   r)   rH   rR   rW   rY   r\   rr   r*   r%   r#   r>   r>   p   s0   „ ñð ÐóMò ò*
ó
ð -/¸ô !6r%   r>   c                 ó.  — t        | t        «      r4g }| D ]+  }	 |j                  t        |j	                  «       «      «       Œ- |S 	 t        | j	                  «       «      S # t
        $ r t        d| z  «       ‚ w xY w# t
        $ r t        d| z  «       ‚ w xY w)z;
    Convert a ``logic.Expression`` to Prover9 format.
    z4input %s cannot be converted to Prover9 input syntax)r.   ÚlistÚappendÚ_convert_to_prover9r:   Ú	Exceptionr   )rc   ÚresultrU   s      r#   r   r   Þ   s    € ô �%œÔØˆØò 	ˆAðØ—‘Ô1°!·*±*³,Ó?Õ@ð	ð ˆð	Ü& u§~¡~Ó'7Ó8Ð8øô ò ÜÐLÈuÑTÔUØðûô ò 	ÜÐHÈ5ÑPÔQØð	ús   ™(AÁA; ÁA8Á;Bc                 ó  — t        | t        «      r1dt        | j                  «      z   dz   t	        | j
                  «      z   S t        | t        «      r1dt        | j                  «      z   dz   t	        | j
                  «      z   S t        | t        «      rdt	        | j
                  «      z   dz   S t        | t        «      r4dt	        | j                  «      z   dz   t	        | j                  «      z   dz   S t        | t        «      r4dt	        | j                  «      z   dz   t	        | j                  «      z   dz   S t        | t        «      r4dt	        | j                  «      z   d	z   t	        | j                  «      z   dz   S t        | t        «      r4dt	        | j                  «      z   d
z   t	        | j                  «      z   dz   S t        | t        «      r4dt	        | j                  «      z   dz   t	        | j                  «      z   dz   S t        | «      S )zC
    Convert ``logic.Expression`` to Prover9 formatted string.
    zexists ú zall z-(ú)ú(z & z | z -> z <-> z = )r.   r   ÚstrÚvariablerv   Útermr   r   r   ÚfirstÚsecondr   r   r
   r   )Ú
expressions    r#   rv   rv   ó   s?  € ô �*Ô.Ô/àÜ�*×%Ñ%Ó&ñ'àñô " *§/¡/Ó2ñ3ð	
ô 
�J¤Ô	.àÜ�*×%Ñ%Ó&ñ'àñô " *§/¡/Ó2ñ3ð	
ô 
�JÔ 1Ô	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àÜ! *×"2Ñ"2Ó3ñ4àñô " *×"3Ñ"3Ó4ñ5ð ñ	ð	
ô �:‹Ðr%   c                   óB   — e Zd ZdZdZdd„Zd	d„Zd„ Zg dfd„Zg dfd„Z	y)
r/   Nc                 ó   — || _         y )N)Ú_timeout)r    r2   s     r#   r0   zProver9.__init__7  s   € ØˆŒð	&r%   Fc                 ód   — |sg }| j                  | j                  ||«      |¬«      \  }}|dk(  |fS )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.
        )rG   r   )Ú_call_prover9rW   )r    r1   r   rG   r`   rk   s         r#   Ú_provezProver9._prove=  sI   € ñ ØˆKà!×/Ñ/Ø×Ñ˜t [Ó1¸7ð 0ó 
Ñˆ�
ð ˜a‘ Ð(Ð(r%   c                 ó:   — d}|t         j                  | ||«      z   S )z3
        :see: Prover9Parent.prover9_input
        zclear(auto_denials).
)r>   rW   )r    r1   r   rU   s       r#   rW   zProver9.prover9_inputL  s#   € ð %ˆØ”=×.Ñ.¨t°T¸;ÓGÑGÐGr%   c                 ó|  — | j                   €| j                  d|«      | _         d}| j                  dkD  r|d| j                  z  z  }||z  }| j                  || j                   ||«      \  }}|dvrId}||v r%|j	                  |«      }||d j                  «       }	nd}	|dv rt        ||	«      ‚t        ||	«      ‚||fS )	a  
        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   rT   r   zassign(max_seconds, %d).

)r   r   z%%ERROR:)r   r   r   r   )rI   r\   r…   rr   ÚindexÚstripÚProver9LimitExceededExceptionÚProver9FatalException)
r    rm   ro   rG   Úupdated_input_strr`   rk   ÚerrormsgprefixÚmsgstartÚerrormsgs
             r#   r‡   zProver9._call_prover9S  så   € ð ×ÑÐ$Ø $× 1Ñ 1°)¸WÓ EˆDÔàÐØ�=‰=˜1ÒØÐ!?À$Ç-Á-Ñ!OÑOÐØ˜YÑ&Ðà!ŸZ™ZØ˜t×0Ñ0°$¸ó
Ñˆ�
ð ˜VÑ#Ø'ˆNØ Ñ'Ø!Ÿ<™<¨Ó7�Ø! ( )Ð,×2Ñ2Ó4‘à�Ø˜\Ñ)Ü3°JÀÓIÐIä+¨J¸ÓAÐAà�zÐ!Ð!r%   c                 ó„   — | j                   €| j                  d|«      | _         | j                  || j                   ||«      S )a  
        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_binr\   rr   )r    rm   ro   rG   s       r#   r7   zProver9._call_prooftransv  s@   € ð ×ÑÐ'Ø#'×#4Ñ#4°\À7Ó#KˆDÔ à�z‰z˜) T×%9Ñ%9¸4ÀÓIÐIr%   )r<   )NNF)
r&   r'   r(   rI   r•   r0   rˆ   rW   r‡   r7   r*   r%   r#   r/   r/   3  s6   „ Ø€LØ€Oó&ó)òHð -/¸ó !"ðF 02¸5ô Jr%   r/   c                   ó   — e Zd Zd„ Zy)ÚProver9Exceptionc                 óV   — t         |   }|r|d|z  z  }t        j                  | |«       y )Nz
%s)Úp9_return_codesrw   r0   )r    rk   ÚmessageÚmsgs       r#   r0   zProver9Exception.__init__†  s.   € Ü˜jÑ)ˆÙØ�6˜GÑ#Ñ#ˆCÜ×Ñ˜4 Õ%r%   N)r&   r'   r(   r0   r*   r%   r#   r—   r—   …  s   „ ó&r%   r—   c                   ó   — e Zd Zy)rŽ   N©r&   r'   r(   r*   r%   r#   rŽ   rŽ   �  ó   „ Ør%   rŽ   c                   ó   — e Zd Zy)r�   Nr�   r*   r%   r#   r�   r�   ‘  rž   r%   r�   c                  ó  — t        j                  d«      } t        j                  d«      }t        || g¬«      }d |_        g |_        |j                  «        t        |j                  «       «       t        |j                  «       «       y )Nz(walk(j) & sing(j))zwalk(j)©r   )r	   Ú
fromstringr,   Ú_executable_pathÚprover9_searchÚprover   Úproof)r"   Úgrq   s      r#   Útest_configr¨   š  sf   € Ü×ÑÐ3Ó4€AÜ×Ñ˜iÓ(€AÜ�q q cÔ*€AØ€AÔØ€AÔØ‡G�G„Iä	ˆ!�'‰'‹)ÔÜ	ˆ!�'‰'‹)Õr%   c                 ód   — | D ]+  }t        j                  |«      }t        t        |«      «       Œ- y)z%
    Test that parsing works OK.
    N)r	   r¢   r   r   )ÚexprÚtÚes      r#   Útest_convert_to_prover9r­   ¦  s1   € ð ò %ˆÜ×!Ñ! !Ó$ˆÜÔ  Ó#Õ$ñ%r%   c                 ó  — | D ]~  \  }}t        j                  |«      }|D �cg c]  }t        j                  |«      ‘Œ }}t        ||¬«      j                  «       }|D ]  }t	        d|z  «       Œ t	        d|› d|› d�«       Œ€ yc c}w )z2
    Try some proofs and exhibit the results.
    r¡   z   %sz|- z: r^   N)r	   r¢   r,   r¥   r   )Ú	argumentsr1   r   r§   r"   Úalistrq   s          r#   Ú
test_prover±   ¯  s�   € ð 'ò  ÑˆˆkÜ×!Ñ! $Ó'ˆØ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                 ó    — t        d| z  «       y )Nú-)r   )Únums    r#   Úspacerrµ   è  s   € Ü	ˆ#�‰)Õr%   c                  óú   — t        d«       t        «        t        «        t        «        t        d«       t        «        t        t        «       t        «        t        d«       t        «        t        t        «       y )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)   rM   rf   r   Únltk.inference.apir   r   Únltk.sem.logicr   r   r   r   r	   r
   r   r   r   r™   r   r,   r>   r   rv   r/   rw   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%   