+
    ÖÇÜhR.  ã                   óì   € R t ^ RIt^ RIt^ RIHtHt ^ RIHtHt ^ RI	H
t
Ht ^ RIHt  ! R R]]4      t ! R R	]]4      tRR
 ltR tR tR tR tR tRRR.3RRR.3.tR t]R8X  d
   ]! 4        R# R# )zA
A model builder that makes use of the external 'Mace4' package.
N)ÚBaseModelBuilderCommandÚModelBuilder)ÚProver9CommandParentÚProver9Parent)Ú
ExpressionÚ	Valuation)Ú	is_indvarc                   ó’   a € ] tR t^t o RtRtRR lt]R 4       tR t	]
R 4       t]
R 4       t]
R 4       tR	 tR
 t. R3R ltRtV tR# )ÚMaceCommandz¨
A ``MaceCommand`` specific to the ``Mace`` model builder.  It contains
a print_assumptions() method that is used to print the list
of assumptions in multiple formats.
Nc                ó„   € Ve   \        V\        4      '       g   Q hM\        V4      p\        P                  ! WW4       R# )aM  
: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 max_models: The maximum number of models that Mace will try before
    simply returning false. (Use 0 for no maximum.)
:type max_models: int
N)Ú
isinstanceÚMacer   Ú__init__)ÚselfÚgoalÚassumptionsÚ
max_modelsÚmodel_builders   &&&&&Ú5/usr/lib/python3/dist-packages/nltk/inference/mace.pyr   ÚMaceCommand.__init__   s7   € ð Ò$Ü˜m¬T×2Ò2Ð2Ñ2ä  Ó,ˆMä×(Ò(¨¸dÖPó    c                ó$   € V P                  R 4      # )Ú	valuation)Úmodel)Úmbcs   &r   r   ÚMaceCommand.valuation1   s   € à�y‰y˜Ó%Ð%r   c                óä  € V P                  VR4      p. pVP                  R4       EF·  pVP                  4       pVP                  R4      '       dC   \	        WUP                  R4      ^,           VP                  R4       P                  4       4      pKm  VP                  R4      '       dØ   VP                  R4      R8X  dÂ   WUP                  R4      ^,           VP                  R4       P                  4       p\        V4      '       d   VP                  4       p\	        WUP                  R4      ^,           VP                  R	4       P                  4       4      pVP                  V\        P                  V4      34       EK[  VP                  R
4      '       g   EKu  WUP                  R4      ^,           R pRV9   d«   VRVP                  R4       P                  4       pWUP                  R4      ^,           VP                  R	4       P                  R4       U	u. uF  p	\	        V	P                  4       4      NK  	  p
p	VP                  V\        P                  XV
4      34       EK@  VRVP                  R4       P                  4       p\	        WUP                  R4      ^,           VP                  R	4       P                  4       4      pVP                  Wx^8H  34       EKº  	  \        V4      # u up	i )z†
Transform the output file into an NLTK-style Valuation.

:return: A model if one is generated; None otherwise.
:rtype: sem.Valuation
ÚstandardFÚinterpretationÚ(Ú,ÚfunctionÚ_Ú[Ú]ÚrelationNéÿÿÿÿ)Ú_transform_outputÚ
splitlinesÚstripÚ
startswithÚintÚindexÚfindr   ÚupperÚappendr
   Ú_make_model_varÚsplitÚ_make_relation_setr   )r   Úvaluation_strÚvaluation_standard_formatÚvalÚlineÚlÚnum_entitiesÚnameÚvalueÚvÚvaluess   &&         r   Ú_convert2valÚMaceCommand._convert2val5   sM  € ð %)×$:Ñ$:¸=È*Ó$UÐ!àˆØ-×8Ñ8¸×?ˆDØ—
‘
“ˆAà�|‰|Ð,×-Ò-ä" 1§W¡W¨S£\°AÕ%5¸¿¹À»Ð#E×#KÑ#KÓ#MÓN’à—‘˜j×)Ò)¨a¯f©f°S«k¸RÔ.?àŸ™ ›¨Õ)¨A¯G©G°C«LÐ9×?Ñ?ÓA�Ü˜T—?’?ØŸ:™:›<�DÜ˜AŸg™g c›l¨QÕ.°·±¸³Ð>×DÑDÓFÓG�Ø—
‘
˜D¤+×"=Ñ"=¸eÓ"DÐE×Fà—‘˜j×)Õ)Ø—g‘g˜c“l QÕ&Ð(Ð)�Ø˜!”8à˜^˜qŸw™w s›|Ð,×2Ñ2Ó4�Dð "#§7¡7¨3£<°!Õ#3°a·g±g¸c³lÐ!C×!IÑ!IÈ#Ô!Nóá!N˜Aô ˜AŸG™G›IžÙ!Nð ð ð —J‘JØœ{×=Ñ=¸lÈFÓSÐT÷ð
 ˜^˜qŸw™w s›|Ð,×2Ñ2Ó4�DÜ §'¡'¨#£,°Õ"2°Q·W±W¸S³\Ð B× HÑ HÓ JÓK�EØ—J‘J ¨q¡jÐ1×2ñ? @ôB ˜‹~Ðùòs   È"K-c           
     óà   € \        4       p\        V4       UUu. uF  w  r4V^8X  g   K  VNK  	  upp F1  pVP                  \        \        P                  WQV 4      4      4       K3  	  V# u uppi )a-  
Convert a Mace4-style relation table into a dictionary.

:param num_entities: the number of entities in the model; determines the row length in the table.
:type num_entities: int
:param values: a list of 1's and 0's that represent whether a relation holds in a Mace4 model.
:type values: list of int
)ÚsetÚ	enumerateÚaddÚtupler
   Ú_make_relation_tuple)r8   r<   ÚrÚposr;   Úpositions   &&    r   r2   ÚMaceCommand._make_relation_setb   sd   € ô ‹EˆÜ-6°vÔ->ÔIÑ->¡ #À!ÀqÁ&Ÿ˜Ñ->ÕIˆHØ�E‰EÜ”k×6Ñ6°xÈÓVÓWöñ Jð ˆùó	 Js
   ™A*©A*c                ó  € \        V4      ^8X  d   . # \        V4      V,          pW,          p\        W,          4      pVWC,          V^,           V,           p\        P                  V4      .\        P	                  WVV4      ,           # )é   )Úlenr+   r
   r0   rD   )rG   r<   r8   Úsublist_sizeÚsublist_startÚsublist_positionÚsublists   &&&    r   rD   Ú MaceCommand._make_relation_tuples   s…   € äˆv‹;˜!ÔØˆIä˜v›;¨,Õ6ˆLØ$Õ4ˆMÜ" 8Õ#:Ó;ÐàØÕ,°ÀÕ0AÀ\Õ/QðˆGô ×+Ñ+¨MÓ:ðä×0Ñ0Ø ¨<óõð r   c                ó`   € . ROV ,          pV ^,          pV^ 8”  d   V\        V4      ,           # T# )z“
Pick an alphabetic character as identifier for an entity in the model.

:param value: where to index into the list of characters
:type value: int
)ÚaÚbÚcÚdÚeÚfÚgÚhÚiÚjÚkr7   ÚmÚnÚoÚpÚqrE   ÚsÚtÚur;   ÚwÚxÚyÚz)Ústr)r:   ÚletterÚnums   &  r   r0   ÚMaceCommand._make_model_var…   s8   € ò
ð6 õ7ˆð8 �r�kˆØ$'¨!¤Gˆvœ˜C›Õ Ð7°Ð7r   c                óh   € V'       g   V# VR8X  d   V P                  V4      # V P                  W4      # )a'  
Print out a Mace4 model using any Mace4 ``interpformat`` format.
See https://www.cs.unm.edu/~mccune/mace4/manual/ for details.

:param valuation_str: str with the model builder's output
:param format: str indicating the format for displaying
models. Defaults to 'standard' format.
:return: str
r   )r=   r'   ©r   r3   Úformats   &&&r   Ú_decorate_modelÚMaceCommand._decorate_model¬   s7   € ÷ Ø Ð Ø�{Ô"Ø×$Ñ$ ]Ó3Ð3à×)Ñ)¨-Ó@Ð@r   c                óX   € VR9   d   V P                  W.4      ^ ,          # \        R4      h)zŠ
Transform the output file into any Mace4 ``interpformat`` format.

:param format: Output format for displaying models.
:type format: str
z#The specified format does not exist)r   Ú	standard2ÚportableÚtabularÚrawÚcookedÚxmlÚtex)Ú_call_interpformatÚLookupErrorrn   s   &&&r   r'   ÚMaceCommand._transform_output½   s7   € ð ð 	
ô 	
ð ×*Ñ*¨=¸(ÓCÀAÕFÐFäÐCÓDÐDr   Fc                ó¬   € V P                   f"   V P                  P                  RV4      V n         V P                  P                  WP                   W#4      # )zä
Call the ``interpformat`` 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``
Úinterpformat)Ú_interpformat_binÚ_modelbuilderÚ_find_binaryÚ_call)r   Ú	input_strÚargsÚverboses   &&&&r   rz   ÚMaceCommand._call_interpformatÒ   sT   € ð ×!Ñ!Ò)Ø%)×%7Ñ%7×%DÑ%DØ ó&ˆDÔ"ð ×!Ñ!×'Ñ'Ø×-Ñ-¨tó
ð 	
r   )r   )NNéô  N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Úpropertyr   r=   Ústaticmethodr2   rD   r0   rp   r'   rz   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r
   r
      sŒ   ø‡ € ñð ÐôQð$ ñ&ó ð&ò+ðZ ñó ðð  ñó ðð" ñ$8ó ð$8òLAò"Eð* 24¸U÷ 
ò 
r   r
   c                   óF   a € ] tR t^åt o RtRR ltRR lt. R3R ltRtV t	R# )	r   Nc                ó   € Wn         R # )N)Ú	_end_size)r   Úend_sizes   &&r   r   ÚMace.__init__è   s   € Ø!Œñ	?r   Fc                ól   € V'       g   . pV P                  V P                  W4      VR7      w  rEV^ 8H  V3# )z€
Use Mace4 to build a first order model.

:return: ``True`` if a model was found (i.e. Mace returns value of 0),
else ``False``
)r…   )Ú_call_mace4Úprover9_input)r   r   r   r…   ÚstdoutÚ
returncodes   &&&&  r   Ú_build_modelÚMace._build_modelí   sE   € ÷ ØˆKà!×-Ñ-Ø×Ñ˜tÓ1¸7ð .ó 
Ñˆð ˜a‘ Ð(Ð(r   c                óî   € V P                   f   V P                  RV4      V n         RpV P                  ^ 8”  d   VRV P                  ,          ,          pWA,          pV P                  W@P                   W#4      # )zÝ
Call the ``mace4`` 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``
Úmace4Ú zassign(end_size, %d).

)Ú
_mace4_binr�   r•   r‚   )r   rƒ   r„   r…   Úupdated_input_strs   &&&& r   r™   ÚMace._call_mace4ü   sh   € ð �?‰?Ò"Ø"×/Ñ/°¸ÓAˆDŒOàÐØ�>‰>˜AÔØÐ!<¸t¿~¹~Õ!MÕMÐØÕ&Ðà�z‰zÐ+¯_©_¸dÓLÐLr   )r•   r¢   )r‡   )NNF)
rˆ   r‰   rŠ   r‹   r¢   r   r�   r™   r�   r�   r‘   s   @r   r   r   å   s'   ø‡ € Ø€Jô?ô
)ð +-°e÷ Mò Mr   r   c                 ó*   € \        R V ,          4       R# )Ú-N)Úprint)rk   s   &r   Úspacerr¨     s   € Ü	ˆ#��)Ör   c                ó    € RRRRRR/V ,          # )za
Decode the result of model_found()

:param found: The output of model_found()
:type found: bool
TzCountermodel foundFzNo countermodel foundNÚNone© )Úfounds   &r   Údecode_resultr­     s#   € ð Ð&¨Ð/FÈÈfÐUØõð r   c           	     ó@  € V  F’  w  r\         P                  ! V4      pV Uu. uF  p\        P                  V4      NK  	  pp\	        W5^2R7      pVP                  4       pV F  p\        RV,          4       K  	  \        RV R\        V4       R24       K”  	  R# u upi )z*
Try some proofs and exhibit the results.
)r   r   ú   %sú|- ú: Ú
N)r   Ú
fromstringÚlpÚparser
   Úbuild_modelr§   r­   )Ú	argumentsr   r   rX   rR   Úalistr]   r¬   s   &       r   Útest_model_foundr¹      sŠ   € ó 'ÑˆÜ×!Ò! $Ó'ˆÙ&1Ó2¡k ”—‘˜!–¡kˆÐ2Ü˜¸Ô<ˆØ—‘“ˆÛˆAÜ�'˜A•+Öñ ä��A�3�bœ uÓ-Ð.¨bÐ1Ö2ó 'ùâ2s   ¢Bc           	     óî  € \         P                  ! R4      pR
 Uu. uF  p\         P                  ! V4      NK  	  pp\        WR7      pVP                  4        \	        4        \        R4       \	        4        V F  p\        RV,          4       K  	  \        RV R\        VP                  4       4       R24       \	        4        \        R4       \	        4        \        VP                  R4       R	# u upi )z(
Try to build a ``nltk.sem.Valuation``.
zall x.man(x)©r   zAssumptions and Goalr¯   r°   r±   r²   r   N)z	man(John)úman(Socrates)z	man(Bill)z,some x.(-(x = John) & man(x) & sees(John,x))zsome x.(-(x = Bill) & man(x))z,all x.some y.(man(x) -> gives(Socrates,x,y)))r   r³   r
   r¶   r¨   r§   r­   r   )r·   rX   rR   r¸   r]   s   &    r   Útest_build_modelr½   .  sÍ   € ô 	×Ò˜nÓ-€Añ
ó
ñ
ˆAô 	×Ò˜aÖ ñ
ð 
ð 
ô 	�AÔ)€AØ‡M�M„OÜ
„HÜ	Ð
 Ô!Ü
„HÛˆÜˆg˜�kÖñ ä	ˆC�ˆs�"”] 1§=¡=£?Ó3Ð4°BÐ
7Ô8Ü
„Hô 
ˆ+ÔÜ
„HÜ	ˆ!�+‰+�tÖùò3
s   ›C2c                óâ  € \         P                  ! V ^ ,          4      pV ^,           Uu. uF  p\        P                  V4      NK  	  pp\	        WR7      pVP                  4        V F  p\        RV,          4       K  	  \        RV RVP                  4        R24       R	 FD  p\        4        \        RV,          4       \        4        \        VP                  VR7      4       KF  	  R# u upi )
zB
Transform the model into various Mace4 ``interpformat`` formats.
r»   r¯   r°   r±   r²   zUsing '%s' format)ro   N)r   rt   rx   rw   )	r   r³   r´   rµ   r
   r¶   r§   r¨   r   )Úargument_pairrX   rR   r¸   r]   ro   s   &     r   Útest_transform_outputrÀ   O  s½   € ô 	×Ò˜m¨AÕ.Ó/€AØ"/°Ö"2Ó3Ñ"2˜QŒR�X‰X�aŽ[Ñ"2€EÐ3Ü�AÔ)€AØ‡M�M„OÛˆÜˆg˜�kÖñ ä	ˆC�ˆs�"�Q—]‘]“_Ð% RÐ
(Ô)Û;ˆÜŒÜÐ! FÕ*Ô+ÜŒÜˆa�g‰g˜VˆgÓ$Ö%ó	 <ùò 4s   ©C,c                  óî   € \        \        P                  ^. ROR7      RR08H  4       \        \        P                  ^. ROR7      R08H  4       \        \        P                  ^. ROR7      R	R
08H  4       R# )é   )r8   r<   N)rJ   é    rJ   )rT   )rR   )	rÃ   rÃ   rÃ   rÃ   rÃ   rÃ   rJ   rÃ   rÃ   )rT   rR   )rÃ   rÃ   rJ   rÃ   rÃ   rÃ   rJ   rÃ   )rR   rS   rR   )rS   rS   rR   )r§   r
   r2   r«   r   r   Útest_make_relation_setrÄ   a  s„   € Ü	Ü×&Ñ&°AºiÐ&ÓHØ�FÐñ	ôô 
Ü×&Ñ&ØÒ#>ð 	'ó 	
ð ˆ<ñ	ôô 
Ü×&Ñ&°AÒ>VÐ&ÓWØ˜_Ð-ñ	.ör   zmortal(Socrates)zall x.(man(x) -> mortal(x))r¼   z(not mortal(Socrates))c                  ón   € \        \        4       \        \        4       \        \        ^,          4       R# )rJ   N)r¹   r·   r½   rÀ   r«   r   r   ÚdemorÆ   x  s   € Ü”YÔÜ”YÔÜœ) A�,Ö'r   Ú__main__)é   )rŒ   ÚosÚtempfileÚnltk.inference.apir   r   Únltk.inference.prover9r   r   Únltk.semr   r   Únltk.sem.logicr   r
   r   r¨   r­   r¹   r½   rÀ   rÄ   r·   rÆ   rˆ   r«   r   r   Ú<module>rÏ      sŸ   ðñó 
Û ç Dß Fß *Ý $ôL
Ð&Ð(?ô L
ô^(Mˆ=˜,ô (MôVò	ò3òòB&ò$ð$ Ð7¸ÐIÐJØÐ =¸ÐOÐPð€	ò(ð ˆzÔÙ†Fñ r   