+
    ÖÇÜhfc  ã                   óü  € R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
HtHtHtHtHtHtHtHtHtHtHtHtHtHtHt  ! R R]4      t ! R R]4      tR	 tR
 tR tR t  ! R R]!4      t"]PF                  ! R4      t$]PF                  ! R4      t%]PF                  ! R]PL                  4      t'R t(RR lt) ! R R]!4      t* ! R R4      t+^t,RR lt-R R lt.RR lt/RR lt0R!R lt1]2R8X  d   ]1! ^^ R7       R# R# )"zK
This module provides data structures for representing first-order
models.
N©Úpformat)Ú	decorator)ÚAbstractVariableExpressionÚAllExpressionÚAndExpressionÚApplicationExpressionÚEqualityExpressionÚExistsExpressionÚ
ExpressionÚIffExpressionÚImpExpressionÚIndividualVariableExpressionÚIotaExpressionÚLambdaExpressionÚNegatedExpressionÚOrExpressionÚVariableÚ	is_indvarc                   ó   € ] tR t^,tRtR# )ÚError© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    Ú3/usr/lib/python3/dist-packages/nltk/sem/evaluate.pyr   r   ,   ó   † Ûr   r   c                   ó   € ] tR t^0tRtR# )Ú	Undefinedr   Nr   r   r   r   r"   r"   0   r    r   r"   c                 ó  € \         P                  ! V 4      p\        \        V^ ,          V4      4      pVP	                  RR4      '       d4   \        4        VP                  4        F  p\        RV,          4       K  	  V ! V/ VB # )é    ÚtraceNz%s => %s)ÚinspectÚgetfullargspecÚdictÚzipÚpopÚprintÚitems)ÚfÚargsÚkwÚargspecÚdÚitems   &*,   r   r%   r%   4   sh   € Ü×$Ò$ QÓ'€GÜŒS�˜•˜TÓ"Ó#€AØ‡u�uˆW�d×ÒÜŒØ—G‘G–IˆDÜ�*˜tÕ#Ö$ñ áˆdˆ>�b‰>Ðr   c                ó  € \        V 4      ^ 8X  d   R# \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       d.   \        \        V 4      4      \        \        V 4      4      8X  d   R# \	        RV ,          4      h)zˆ
Check whether a set represents a relation (of any arity).

:param s: a set containing tuples of str elements
:type s: set
:rtype: bool
Tc              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5i©N)Ú
isinstanceÚtuple)Ú.0Úels   & r   Ú	<genexpr>Úis_rel.<locals>.<genexpr>J   s   é € Ð/©Q rŒZ˜œE×"Ð"«Qùs   ‚Fz.Set %r contains sequences of different lengths)ÚlenÚallÚmaxÚminÚ
ValueError)Úss   &r   Úis_relrB   >   s^   € ô ˆ1ƒv�„{Ùç	‹Ñ/©QÓ/��ŠÑ/©QÓ/×	/Ò	/´C¼¸A»³KÄ3ÄsÈ1ÃvÃ;Ô4NÙäÐIÈAÕMÓNÐNr   c                ó  € \        4       pV  Fp  p\        V\        4      '       d   VP                  V34       K-  \        V\        4      '       d   VP                  \        V4      4       K_  VP                  V4       Kr  	  V# )a.  
Convert a set containing individuals (strings or numbers) into a set of
unary tuples. Any tuples of strings already in the set are passed through
unchanged.

For example:
  - set(['a', 'b']) => set([('a',), ('b',)])
  - set([3, 27]) => set([('3',), ('27',)])

:type s: set
:rtype: set of tuple of str
)Úsetr6   ÚstrÚaddÚint)rA   ÚnewÚelems   &  r   Úset2relrJ   P   s_   € ô ‹%€CÛˆÜ�dœC× Ò Ø�G‰G�T�GÖÜ˜œc×"Ò"Ø�G‰G”C˜“IÖà�G‰G�DŽMñ ð €Jr   c                ó\   € \        V 4      ^ 8X  d   ^ # \        \        V 4      ^ ,          4      # )zU
Check the arity of a relation.
:type rel: set of tuples
:rtype: int of tuple of str
)r<   Úlist)Úrels   &r   ÚarityrN   h   s%   € ô ˆ3ƒx�1„}ÙÜŒt�C‹y˜�|ÓÐr   c                   ór   a a€ ] tR t^st oRtV 3R ltR tR t]R 4       t	]R 4       t
]R 4       tRtVtV ;t# )	Ú	ValuationaÂ  
A dictionary which represents a model-theoretic Valuation of non-logical constants.
Keys are strings representing the constants to be interpreted, and values correspond
to individuals (represented as strings) and n-ary relations (represented as sets of tuples
of strings).

An instance of ``Valuation`` will raise a KeyError exception (i.e.,
just behave like a standard  dictionary) if indexed with an expression that
is not in its list of symbols.
c                ó:  <€ \         SV `  4        V F…  w  r#\        V\        4      '       g   \        V\        4      '       d   W0V&   K7  \        V\
        4      '       d   \        V4      W&   K\  \        P                  ! RV: RV: 2^BR7      p\        V4      h	  R# )z-
:param xs: a list of (symbol, value) pairs.
z@Error in initializing Valuation. Unrecognized value for symbol 'z':
)ÚwidthN)
ÚsuperÚ__init__r6   rE   ÚboolrD   rJ   ÚtextwrapÚfillr@   )ÚselfÚxsÚsymÚvalÚmsgÚ	__class__s   &&   €r   rT   ÚValuation.__init__   s|   ø€ ô 	‰ÑÔÛ‰HˆCÜ˜#œs×#Ò#¤z°#´t×'<Ò'<Ø�S“	Ü˜C¤×%Ò%Ü# C›L�“	ä—m“mãADÂcðKàô�ô ! “oÐ%ó r   c                ó\   € W9   d   \         P                  W4      # \        R V,          4      h)zUnknown expression: '%s'©r(   Ú__getitem__r"   ©rX   Úkeys   &&r   ra   ÚValuation.__getitem__’   s)   € ØŒ;Ü×#Ñ# DÓ.Ð.äÐ6¸Õ<Ó=Ð=r   c                ó   € \        V 4      # r5   r   ©rX   s   &r   Ú__str__ÚValuation.__str__˜   s   € Ü�t‹}Ðr   c           	     ó8  € . pV P                  4        Ft  p\        V\        4      '       d   VP                  V4       K,  \        V\        4      '       d   KD  TP                  V UUu. uF  q3 F
  qDf   K  VNK  	  K  	  upp4       Kv  	  \        V4      # u uppi )z7Set-theoretic domain of the value-space of a Valuation.)Úvaluesr6   rE   ÚappendrU   ÚextendrD   )rX   Údomr[   Útuple_rI   s   &    r   ÚdomainÚValuation.domain›   sw   € ð ˆØ—;‘;–=ˆCÜ˜#œs×#Ò#Ø—
‘
˜3–Ü ¤T×*Ô*Ø—
‘
Ù(+ÔS©˜fº°—T�T¹‘T©ÒSöñ	 !ô �3‹xˆùó Ts   Á'	BÁ5
Bc                ó4   € \        V P                  4       4      # )z9The non-logical constants which the Valuation recognizes.)ÚsortedÚkeysrf   s   &r   ÚsymbolsÚValuation.symbols¨   s   € ô �d—i‘i“kÓ"Ð"r   c                ó   € \        V4      # r5   )Úread_valuation)ÚclsrA   s   &&r   Ú
fromstringÚValuation.fromstring­   s   € ä˜aÓ Ð r   r   )r   r   r   r   Ú__doc__rT   ra   rg   Úpropertyro   rt   Úclassmethodry   r   Ú__classdictcell__Ú__classcell__©r]   Ú__classdict__s   @@r   rP   rP   s   sZ   ù‡ € ñ	õ&ò&>òð ñ
ó ð
ð ñ#ó ð#ð ñ!ó ÷!ð !r   rP   z	\s*=+>\s*z\s*,\s*zg\s*
                                (\([^)]+\))  # tuple-expression
                                \s*c                óˆ  € \         P                  V 4      pV^ ,          pV^,          pVP                  R4      '       dƒ   V^R p\        P	                  V4      pV'       dA   . pV F7  pV^R p\        \        P                  V4      4      pVP                  V4       K9  	  M\        P                  V4      p\        V4      pW#3# )zð
Read a line in a valuation file.

Lines are expected to be of the form::

  noosa => n
  girl => {g1, g2}
  chase => {(b1, g1), (b2, g1), (g1, d1), (g2, d2)}

:param s: input line
:type s: str
:return: a pair (symbol, value)
:rtype: tuple
Ú{éÿÿÿÿ)	Ú_VAL_SPLIT_REÚsplitÚ
startswithÚ
_TUPLES_REÚfindallr7   Ú_ELEMENT_SPLIT_RErk   rD   )rA   ÚpiecesÚsymbolÚvalueÚtuple_stringsÚset_elementsÚtsÚelements   &       r   Ú_read_valuation_liner’   ¿   s·   € ô × Ñ  Ó#€FØ�A�Y€FØ�1�I€Eà×Ñ˜×ÒØ�a˜�ˆÜ"×*Ñ*¨5Ó1ˆçØˆLÛ#�Ø˜˜"�X�ÜÔ 1× 7Ñ 7¸Ó ;Ó<�Ø×#Ñ# GÖ,ò $ô
 -×2Ñ2°5Ó9ˆLÜ�LÓ!ˆØˆ=Ðr   c                ój  € Ve   V P                  V4      p . p\        V P                  4       4       FP  w  r4VP                  4       pVP	                  R4      '       g   VR8X  d   K5   VP                  \        V4      4       KR  	  \        V4      #   \         d   p\        RT RT 24      ThRp?ii ; i)zä
Convert a valuation string into a valuation.

:param s: a valuation string
:type s: str
:param encoding: the encoding of the input string, if it is binary
:type encoding: str
:return: a ``nltk.sem`` valuation
:rtype: Valuation
NÚ#Ú zUnable to parse line z: )	ÚdecodeÚ	enumerateÚ
splitlinesÚstripr‡   rk   r’   r@   rP   )rA   ÚencodingÚ
statementsÚlinenumÚlineÚes   &&    r   rw   rw   â   s­   € ð ÒØ�H‰H�XÓˆØ€JÜ" 1§<¡<£>Ö2‰ˆØ�z‰z‹|ˆØ�?‰?˜3×Ò 4¨2¤:Ùð	OØ×ÑÔ2°4Ó8Ö9ñ 3ô �ZÓ Ð øô ô 	OÜÐ4°W°I¸RÀ¸vÐFÓGÈQÐNûð	Oús   Á'BÂB2ÂB-Â-B2c                   ób   a a€ ] tR t^ût oRtR
V 3R lltR tR tR
R ltR t	R t
R tR	tVtV ;t# )Ú
AssignmentaÉ  
A dictionary which represents an assignment of values to variables.

An assignment can only assign values from its domain.

If an unknown expression *a* is passed to a model *M*\ 's
interpretation function *i*, *i* will first check whether *M*\ 's
valuation assigns an interpretation to *a* as a constant, and if
this fails, *i* will delegate the interpretation of *a* to
*g*. *g* only assigns values to individual variables (i.e.,
members of the class ``IndividualVariableExpression`` in the ``logic``
module. If a variable is not assigned a value by *g*, it will raise
an ``Undefined`` exception.

A variable *Assignment* is a mapping from individual variables to
entities in the domain. Individual variables are usually indicated
with the letters ``'x'``, ``'y'``, ``'w'`` and ``'z'``, optionally
followed by an integer (e.g., ``'x0'``, ``'y332'``).  Assignments are
created using the ``Assignment`` constructor, which also takes the
domain as a parameter.

    >>> from nltk.sem.evaluate import Assignment
    >>> dom = set(['u1', 'u2', 'u3', 'u4'])
    >>> g3 = Assignment(dom, [('x', 'u1'), ('y', 'u2')])
    >>> g3 == {'x': 'u1', 'y': 'u2'}
    True

There is also a ``print`` format for assignments which uses a notation
closer to that in logic textbooks:

    >>> print(g3)
    g[u1/x][u2/y]

It is also possible to update an assignment using the ``add`` method:

    >>> dom = set(['u1', 'u2', 'u3', 'u4'])
    >>> g4 = Assignment(dom)
    >>> g4.add('x', 'u1')
    {'x': 'u1'}

With no arguments, ``purge()`` is equivalent to ``clear()`` on a dictionary:

    >>> g4.purge()
    >>> g4
    {}

:param domain: the domain of discourse
:type domain: set
:param assign: a list of (varname, value) associations
:type assign: list
c                ó,  <€ \         SV `  4        Wn        V'       d`   V FY  w  r4W@P                  9   g"   Q R P                  VV P                  4      4       h\	        V4      '       g   Q RV,          4       hW@V&   K[  	  RV n        V P                  4        R# )z'{}' is not in the domain: {}ú-Wrong format for an Individual Variable: '%s'N)rS   rT   ro   Úformatr   ÚvariantÚ_addvariant)rX   ro   ÚassignÚvarr[   r]   s   &&&  €r   rT   ÚAssignment.__init__0  sŽ   ø€ Ü‰ÑÔØŒßÛ"‘�ØŸk™kÔ)ð Ð+J×+QÑ+QØØ—K‘Kó,ó Ð)ô ! —~’~ð ØCÀcÕIó�~ð  �S“	ñ #ð ˆŒØ×ÑÖr   c                ó\   € W9   d   \         P                  W4      # \        R V,          4      h)z"Not recognized as a variable: '%s'r`   rb   s   &&r   ra   ÚAssignment.__getitem__@  s)   € ØŒ;Ü×#Ñ# DÓ.Ð.äÐ@À3ÕFÓGÐGr   c                óR   € \        V P                  4      pVP                  V 4       V# r5   )r    ro   Úupdate)rX   rH   s   & r   ÚcopyÚAssignment.copyF  s!   € Ü˜Ÿ™Ó%ˆØ�
‰
�4ÔØˆ
r   c                ó\   € V'       d   W MV P                  4        V P                  4        R# )zœ
Remove one or all keys (i.e. logic variables) from an
assignment, and update ``self.variant``.

:param var: a Variable acting as a key for the assignment.
N)Úclearr¥   )rX   r§   s   &&r   ÚpurgeÚAssignment.purgeK  s$   € ÷ Ø‘	à�J‰JŒLØ×ÑÔÙr   c                ój   € Rp\        V P                  4      pV F  w  r4VRV RV R2,          pK  	  V# )zA
Pretty printing for assignments. {'x', 'u'} appears as 'g[u/x]'
ÚgÚ[Ú/Ú])rr   r¤   )rX   Úgstringr¤   r[   r§   s   &    r   rg   ÚAssignment.__str__Y  sA   € ð ˆä˜Ÿ™Ó&ˆÛ‰HˆCØ˜˜3˜%˜q   QÐ'Õ'ŠGñ  àˆr   c                óŠ   € . pV P                  4        F&  pV^,          V^ ,          3pVP                  V4       K(  	  Wn        R# )z;
Create a more pretty-printable version of the assignment.
N)r,   rk   r¤   )rX   Úlist_r2   Úpairs   &   r   r¥   ÚAssignment._addvariantd  sA   € ð ˆØ—J‘J–LˆDØ˜•G˜T !�WÐ%ˆDØ�L‰L˜Öñ !ð ŒÙr   c                ó¸   € W P                   9   g   Q V RV P                    24       h\        V4      '       g   Q RV,          4       hW V&   V P                  4        V # )zP
Add a new variable-value pair to the assignment, and update
``self.variant``.

z is not in the domain r¢   )ro   r   r¥   )rX   r§   r[   s   &&&r   rF   ÚAssignment.addo  s[   € ð —k‘kÔ!ÐN c UÐ*@ÀÇÁÀÐ#NÓNÐ!Ü˜�~Š~ÐTÐNÐQTÕTÓTˆ~ØˆS‰	Ø×ÑÔØˆr   )ro   r¤   r5   )r   r   r   r   r{   rT   ra   r­   r±   rg   r¥   rF   r   r~   r   r€   s   @@r   r    r    û   s4   ù‡ € ñ2÷hò Hòô
ò	ò	÷
ò 
r   r    c                   ó^   a € ] tR tRt o RtR tR tR tRR ltRR lt	RR	 lt
RR
 ltRtV tR# )ÚModeli|  a/  
A first order model is a domain *D* of discourse and a valuation *V*.

A domain *D* is a set, and a valuation *V* is a map that associates
expressions with values in the model.
The domain of *V* should be a subset of *D*.

Construct a new ``Model``.

:type domain: set
:param domain: A set of entities representing the domain of discourse of the model.
:type valuation: Valuation
:param valuation: the valuation of the model.
:param prop: If this is set, then we are building a propositional    model and don't require the domain of *V* to be subset of *D*.
c                óÊ   € \        V\        4      '       g   Q hWn        W n        VP	                  VP                  4      '       g   \        R VP                  : RV: 24      hR# )zThe valuation domain, z*, must be a subset of the model's domain, N)r6   rD   ro   Ú	valuationÚ
issupersetr   )rX   ro   rÃ   s   &&&r   rT   ÚModel.__init__Ž  sX   € Ü˜&¤#×&Ò&Ð&Ð&ØŒØ"ŒØ× Ñ  ×!1Ñ!1×2Ò2Ýà×#Ô#¢Vð-óð ñ 3r   c                ó@   € R V P                   : RV P                  : R2# )Ú(z, Ú)©ro   rÃ   rf   s   &r   Ú__repr__ÚModel.__repr__˜  s    € Ø�4—;‘;‘/  D§N¡NÑ#5°QÐ7Ð7r   c                ó:   € R V P                    RV P                   2# )z	Domain = z,
Valuation = 
rÉ   rf   s   &r   rg   ÚModel.__str__›  s   € Ø˜4Ÿ;™;˜-Ð'8¸¿¹Ð8HÐIÐIr   Nc                ó  €  \         P                  ! V4      pV P                  WBVR7      pV'       d   \        4        \        RV RV RV 24       V#   \         d(    T'       d   \        4        \        RT RT 24        R# i ; i)a	  
Read input expressions, and provide a handler for ``satisfy``
that blocks further propagation of the ``Undefined`` error.
:param expr: An ``Expression`` of ``logic``.
:type g: Assignment
:param g: an assignment to individual variables.
:rtype: bool or 'Undefined'
©r%   Ú'z' evaluates to z
 under M, z' is undefined under M, r"   )r   ry   Úsatisfyr+   r"   )rX   Úexprr´   r%   Úparsedr�   s   &&&&  r   ÚevaluateÚModel.evaluatež  s�   € ð	Ü×*Ò*¨4Ó0ˆFØ—L‘L °%�LÓ8ˆEßÜ”Ü˜˜$˜˜¨u¨g°ZÀ¸sÐCÔDØˆLøÜô 	ßÜ”Ü˜˜$˜Ð7¸°sÐ;Ô<Úð		ús   ‚AA ÁBÁ&BÂBc                ó|	  a a€ \        V\        4      '       d³   VP                  4       w  rE\        V\        4      '       dK   S P	                  VS4      p\
        ;QJ d    . VV 3R lV 4       F  NK  	  5M! VV 3R lV 4       4      pWv9   # S P	                  VP                  S4      pS P	                  VP                  S4      pWh,          # \        V\        4      '       d"   S P	                  VP                  S4      '       * # \        V\        4      '       dA   S P	                  VP                  S4      ;'       d    S P	                  VP                  S4      # \        V\        4      '       dA   S P	                  VP                  S4      ;'       g    S P	                  VP                  S4      # \        V\        4      '       dF   S P	                  VP                  S4      '       * ;'       g    S P	                  VP                  S4      # \        V\        4      '       d:   S P	                  VP                  S4      S P	                  VP                  S4      8H  # \        V\         4      '       d:   S P	                  VP                  S4      S P	                  VP                  S4      8H  # \        V\"        4      '       dq   SP%                  4       p	S P&                   FN  p
V	P)                  VP*                  P,                  V
4       S P	                  VP                  V	4      '       d   KM   R# 	  R# \        V\.        4      '       dq   SP%                  4       p	S P&                   FN  p
V	P)                  VP*                  P,                  V
4       S P	                  VP                  V	4      '       g   KM   R# 	  R# \        V\0        4      '       dq   SP%                  4       p	S P&                   FN  p
V	P)                  VP*                  P,                  V
4       S P	                  VP                  V	4      '       g   KM   R# 	  R# \        V\2        4      '       d]   / pVP*                  P,                  pS P&                   F2  p
S P	                  VP                  SP)                  WÊ4      4      pWÛV
&   K4  	  V# S P5                  VSV4      # )aÈ  
Recursive interpretation function for a formula of first-order logic.

Raises an ``Undefined`` error when ``parsed`` is an atomic string
but is not a symbol or an individual variable.

:return: Returns a truth value or ``Undefined`` if ``parsed`` is        complex, and calls the interpretation function ``i`` if ``parsed``        is atomic.

:param parsed: An expression of ``logic``.
:type g: Assignment
:param g: an assignment to individual variables.
c              3   óH   <"  € T F  pSP                  VS4      x € K  	  R # 5ir5   )rÑ   )r8   Úargr´   rX   s   & €€r   r:   Ú Model.satisfy.<locals>.<genexpr>É  s   øé € ÐJÁ	¸ §¡¨S°!× 4Ð 4Ã	ùs   ƒ"FT)r6   r   Úuncurryr   rÑ   r7   ÚfunctionÚargumentr   Útermr   ÚfirstÚsecondr   r   r   r	   r   r­   ro   rF   ÚvariableÚnamer
   r   r   Úi)rX   rÓ   r´   r%   rÛ   Ú	argumentsÚfunvalÚargvalsÚargvalÚnew_gÚuÚcfr§   r[   s   f&f&          r   rÑ   ÚModel.satisfy´  s`  ù€ ô  �fÔ3×4Ò4Ø"(§.¡.Ó"2ÑˆHÜ˜(Ô$>×?Ò?àŸ™ h°Ó2�ßœ%ÕJÁ	ÓJŸ%™%ÕJÁ	ÓJÓJ�ØÑ(Ð(ð Ÿ™ f§o¡o°qÓ9�ØŸ™ f§o¡o°qÓ9�Ø•~Ð%Ü˜Ô 1×2Ò2Ø—|‘| F§K¡K°Ó3Ô3Ð3Ü˜¤×.Ò.Ø—<‘< §¡¨aÓ0×SÐS°T·\±\À&Ç-Á-ÐQRÓ5SÐSÜ˜¤×-Ò-Ø—<‘< §¡¨aÓ0×RÐR°D·L±LÀÇÁÐPQÓ4RÐRÜ˜¤×.Ò.ØŸ™ V§\¡\°1Ó5Ô5×XÐX¸$¿,¹,ÀvÇ}Á}ÐVWÓ:XÐXÜ˜¤×.Ò.Ø—<‘< §¡¨aÓ0°D·L±LÀÇÁÐPQÓ4RÑRÐRÜ˜Ô 2×3Ò3Ø—<‘< §¡¨aÓ0°D·L±LÀÇÁÐPQÓ4RÑRÐRÜ˜¤×.Ò.Ø—F‘F“HˆEØ—[”[�Ø—	‘	˜&Ÿ/™/×.Ñ.°Ô2Ø—|‘| F§K¡K°×7Ô7Ú ñ !ñ Ü˜Ô 0×1Ò1Ø—F‘F“HˆEØ—[”[�Ø—	‘	˜&Ÿ/™/×.Ñ.°Ô2Ø—<‘< §¡¨U×3Ô3Úñ !ñ Ü˜¤×/Ò/Ø—F‘F“HˆEØ—[”[�Ø—	‘	˜&Ÿ/™/×.Ñ.°Ô2Ø—<‘< §¡¨U×3Ô3Úñ !ñ Ü˜Ô 0×1Ò1ØˆBØ—/‘/×&Ñ&ˆCØ—[”[�Ø—l‘l 6§;¡;°·±°c³Ó>�ð
 �1“ñ !ð ˆIà—6‘6˜& ! UÓ+Ð+r   c                ó6  € VP                   P                  V P                  P                  9   d(   V P                  VP                   P                  ,          # \	        V\
        4      '       d   W!P                   P                  ,          # \        RV,          4      h)ax  
An interpretation function.

Assuming that ``parsed`` is atomic:

- if ``parsed`` is a non-logical constant, calls the valuation *V*
- else if ``parsed`` is an individual variable, calls assignment *g*
- else returns ``Undefined``.

:param parsed: an ``Expression`` of ``logic``.
:type g: Assignment
:param g: an assignment to individual variables.
:return: a semantic value
zCan't find a value for %s)rà   rá   rÃ   rt   r6   r   r"   )rX   rÓ   r´   r%   s   &&&&r   râ   ÚModel.i   sm   € ð$ �?‰?×Ñ 4§>¡>×#9Ñ#9Ô9Ø—>‘> &§/¡/×"6Ñ"6Õ7Ð7Ü˜Ô <×=Ò=Ø—_‘_×)Ñ)Õ*Ð*ô Ð7¸&Õ@ÓAÐAr   c           
     ó:  € RpWfV,          ,           p. p\        V\        4      '       d   \        V4      p	MTp	W‘P                  4       9   Ed2   V'       d)   \	        4        \	        We,          RV RV 2,           4       V P
                   Fß  p
VP                  4       pVP                  V	P                  V
4       V'       d   V^8”  d   V^,
          pM^ pV P                  WV4      pV'       d   \	        VRV,          ,           4       VR8X  d&   V'       d   \	        VRV RV R2,           4       K§  K©  VP                  V
4       V'       g   KÄ  \	        VRV RV R	V 2,           4       Ká  	  V Uu0 uF  qîkK  	  ppV# \        V	P                   R
V 24      hu upi )a]  
Generate the entities from the model's domain that satisfy an open formula.

:param parsed: an open formula
:type parsed: Expression
:param varex: the relevant free individual variable in ``parsed``.
:type varex: VariableExpression or str
:param g: a variable assignment
:type g:  Assignment
:return: a set of the entities that satisfy ``parsed``.
z   zOpen formula is 'z' with assignment z(trying assignment %s)Fz
value of 'z' under z	 is Falsez is z is not free in )r6   rE   r   Úfreer+   ro   r­   rF   rá   rÑ   rk   r"   )rX   rÓ   Úvarexr´   r%   ÚnestingÚspacerÚindentÚ
candidatesr§   rè   rç   Úlowtracer�   ÚcÚresults   &&&&&&          r   Ú
satisfiersÚModel.satisfiers  sz  € ð ˆØ GÕ+Õ,ˆØˆ
ä�eœS×!Ò!Ü˜5“/‰CàˆCà—+‘+“-ÕßÜ”ÜØÕ%Ø)¨&¨Ð1CÀAÀ3ÐGõHôð —[”[�ØŸ™›�Ø—	‘	˜#Ÿ(™( AÔ&ß˜U QœYØ$ q�y‘Hà �HØŸ™ V°HÓ=�çÜ˜&Ð#;¸eÕ#CÕCÔDð ˜E”>ßÜ˜f¨°F°8¸8ÀEÀ7È)Ð'TÕTÖUñ ð
 ×%Ñ% aÔ(ß‘uÜ˜f¨°F°8¸8ÀEÀ7È$ÈuÈgÐ'VÕVÖWñ+ !ñ. ",Ó,¡˜A’a¡ˆFÐ,ð
 ˆô ˜sŸx™x˜jÐ(8¸¸ÐAÓBÐBùò -s   Å0
FrÉ   r5   )F)Nr$   )r   r   r   r   r{   rT   rÊ   rg   rÔ   rÑ   râ   r÷   r   r~   )r�   s   @r   rÁ   rÁ   |  s6   ø‡ € ñò"ò8òJôô,I,ôXB÷49ò 9r   rÁ   c           
     ó<  € \        . RO4      s\        4       s\	        \        \        4      s\        \        4      s\        4        \        R\        ,          4       \        R4       \        R\        ,          4       \        R4       \        4        \        R\
        4       \        R\        ,          4       . R	OpV F[  pV '       d(   \        4        \
        P                  V\        V 4       K2  \        RV R\
        P                  V\        4       24       K]  	  R# )
z!Example of a propositional model.Ú*zPropositional Formulas Demoz7(Propositional constants treated as nullary predicates)z
Model m1:
úThe value of 'ú' is: N))ÚPT)ÚQT)ÚRF)z(P & Q)z(P & R)z- Pz- Rz- - Pz	- (P & R)z(P | R)z(R | P)z(R | R)z	(- P | R)z	(P | - P)z(P -> Q)z(P -> R)z(R -> P)z	(P <-> P)z	(R <-> R)z	(P <-> R))rP   Úval1rD   Údom1rÁ   Úm1r    Úg1r+   ÚmultrÔ   )r%   Ú	sentencesÚsents   &  r   Úpropdemor  _  sÂ   € ô Ò=Ó>€DÜ‹5€DÜ	Œt”TÓ	€BÜ	”DÓ	€Bä	„GÜ	ˆ#”�*ÔÜ	Ð
'Ô(Ü	ˆ#”�*ÔÜ	Ð
CÔDÜ	„GÜ	ˆ-œÔÜ	ˆ#”�*Ôò€Ió( ˆßÜŒGÜ�K‰K˜œb %Ö(ä�N 4 &¨¬r¯{©{¸4ÄÓ/DÐ.EÐFÖGó r   c           
     ó  € RRRRRR03RRR03RR03R	0 Rm3.s \        \         4      s\        P                  s\        \        \        4      s\        \        RR.4      sV '       EgM   \        4        \        R
\        ,          4       \        R4       \        R
\        ,          4       \        RRR\        4       \        R\        4       . ROpV Uu. uF  p\        P                  ! V4      NK  	  pp\        4        V F/  p \        RV: R\        P                  V\        4      : 24       K1  	  . ROpV Fu  w  rx \        P                  \        P                  ! V4      \        4      p	\        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      p
\        V RV RW©9    24       Kw  	  R# R# u upi   \         d    \        RT,          4        KÛ  i ; i  \         d    \        T RT R24        KÅ  i ; i) zExample of a first-order model.Úb1r  Úd1ÚgirlÚg2ÚboyÚb2ÚdogÚloverú   zModels Demoz
Model m2:
Ú
zVariable assignment = zThe interpretation of 'z' in m2 is z-The interpretation of '%s' in m2 is Undefinedc              3   ó~   "  € T F3  p\         P                  \        P                  ! V4      \        4      x € K5  	  R # 5ir5   )Úm2râ   r   ry   r  )r8   rØ   s   & r   r:   Úfolmodel.<locals>.<genexpr>Â  s+   é € ÐUÑPTÈ¤§¡¤Z×%:Ò%:¸3Ó%?Ä× DÐ DÓPTùs   ‚;=rÇ   z) evaluates to z) evaluates to UndefinedN)Úadamr	  )Úbettyr  )Úfidor
  >   ©r	  r  ©r  r  ©r  r	  ©r  r	  )Úxr	  )Úyr  z--------------)r  r  r  Úwalksr  r  Úz))r  r  )r  )r  )r  )r  r  )r  )r  r  )Úv2rP   Úval2ro   Údom2rÁ   r  r    r  r+   r  r   ry   râ   r"   r7   )Úquietr%   Úexprsrž   Úparsed_exprsrÓ   ÚapplicationsÚfunr.   rä   Úargsvals   &&         r   Úfolmodelr)  �  sÌ  € ð 	ØØØ	�$˜�ÐØ	��t�ÐØ	��ˆØ	ÒIÐJð
€Bô ”R‹=€DÜ�;‰;€DÜ	Œt”TÓ	€BÜ	”D˜;¨Ð4Ó	5€Bçˆ5ÜŒÜˆc”D�jÔÜˆmÔÜˆc”D�jÔÜˆm˜X t¬RÔ0ÜÐ&¬Ô+â?ˆÙ:?Ó@¹%°Qœ
×-Ò-¨aÖ0¹%ˆÐ@äŒÛ"ˆFðPÝãœrŸt™t F¬BÕ/ð1öñ #ò
ˆó &‰IˆCð?ÜŸ™œj×3Ò3°CÓ8¼"Ó=�ßœ%ÑUÑPTÓUŸ%™%ÑUÑPTÓUÓU�Ü˜˜˜Q˜t˜f O°GÑ4EÐ3FÐGÖHó	 &ñ9 ùò Aøô ô PÜÐEÈÕN×OðPûô ô ?Ü˜˜˜Q˜t˜fÐ$<Ð=×>ð?ús+   ÃF5Ä+F:Ä>A/GÆ:GÇGÇG>Ç=G>c           
     ó~  € \        RR7       \        4        \        R\        ,          4       \        R4       \        R\        ,          4       . ROpV Fe  p\        P	                  4        V '       d   \
        P                  V\        V 4       K<  \        RV R\
        P                  V\        4       24       Kg  	  R# )	z>
Interpretation of closed expressions in a first-order model.
T©r#  rú   zFOL Formulas Demorû   rü   N)zlove (adam, betty)z(adam = mia)z\x. (boy(x) | girl(x))z\x. boy(x)(adam)z\x y. love(x, y)z\x y. love(x, y)(adam)(betty)z\x y. love(x, y)(adam, betty)z\x y. (boy(x) & love(x, y))z#\x. exists y. (boy(x) & love(x, y))zexists z1. boy(z1)z!exists x. (boy(x) &  -(x = adam))z&exists x. (boy(x) & all y. love(y, x))zall x. (boy(x) | girl(x))z1all x. (girl(x) -> exists y. boy(y) & love(x, y))z3exists x. (boy(x) & all y. (girl(y) -> love(y, x)))z3exists x. (boy(x) & all y. (girl(y) -> love(x, y)))zall x. (dog(x) -> - girl(x))z-exists x. exists y. (love(x, y) & love(x, y)))r)  r+   r  r  r±   r  rÔ   )r%   ÚformulasÚfmlas   &  r   Úfoldemor.  Ì  s‚   € ô �4Õä	„GÜ	ˆ#”�*ÔÜ	Ð
ÔÜ	ˆ#”�*Ôò€Hó* ˆÜ
�‰Œ
ßÜ�K‰K˜œb %Ö(ä�N 4 &¨¬r¯{©{¸4ÄÓ/DÐ.EÐFÖGó r   c                ó"  € \        4        \        R\        ,          4       \        R4       \        R\        ,          4       \        RR7       . ROpV '       d   \        \        4       V F$  p\        V4       \        P
                  ! V4       K&  	  V Uu. uF  p\        P
                  ! V4      NK  	  ppV FL  p\        P                  4        \        RP                  V\        P                  VR\        V 4      4      4       KN  	  R# u upi )	z5Satisfiers of an open formula in a first order model.rú   zSatisfiers DemoTr+  zThe satisfiers of '{}' are: {}r  N)zboy(x)z(x = x)z(boy(x) | girl(x))z(boy(x) & girl(x))zlove(adam, x)zlove(x, adam)z-(x = adam)zexists z22. love(x, z22)úexists y. love(y, x)zall y. (girl(y) -> love(x, y))zall y. (girl(y) -> love(y, x))z)all y. (girl(y) -> (boy(x) & love(y, x)))z)(boy(x) & all y. (girl(y) -> love(x, y)))z)(boy(x) & all y. (girl(y) -> love(y, x)))z+(boy(x) & exists y. (girl(y) & love(y, x)))z(girl(x) -> dog(x))zall y. (dog(y) -> (x = y))r0  z&exists y. (love(adam, y) & love(y, x)))
r+   r  r)  r  r   ry   r  r±   r£   r÷   )r%   r,  r-  rÓ   Úps   &    r   Úsatdemor2  ø  sÆ   € ô 
„GÜ	ˆ#”�*ÔÜ	Ð
ÔÜ	ˆ#”�*Ôä�4Õò€H÷, ÜŒbŒ	ãˆÜˆdŒÜ×Ò˜dÖ#ñ ñ 7?Ó?±h¨dŒj×#Ò# DÖ)±h€FÐ?ãˆÜ
�‰Œ
ÜØ,×3Ñ3°A´r·}±}ÀQÈÌRÐQVÓ7WÓXö	
ó ùò @s   ÂDc                ó®   € ^\         ^\        ^\        ^\        /p W ,          ! VR7       R#   \         d    T F  p Y ,          ! TR7       K  	   R# i ; i)a/  
Run exists demos.

 - num = 1: propositional logic demo
 - num = 2: first order model demo (only if trace is set)
 - num = 3: first order sentences demo
 - num = 4: satisfaction of open formulas demo
 - any other value: run all the demos

:param trace: trace = 1, or trace = 2 for more verbose tracing
rÏ   N)r  r)  r.  r2  ÚKeyError)Únumr%   Údemoss   && r   Údemor7  (  sL   € ð ”˜!œX q¬'°1´gÐ>€Eð$ØŽ
˜×øÜô $ÛˆCØŽJ˜U×#ô ð$ús   œ- ­#AÁAÚ__main__rÏ   r5   )FN)r$   N)3r{   r&   ÚreÚsysrV   Úpprintr   Únltk.decoratorsr   Únltk.sem.logicr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Ú	Exceptionr   r"   r%   rB   rJ   rN   r(   rP   Úcompiler…   rŠ   ÚVERBOSErˆ   r’   rw   r    rÁ   r  r  r)  r.  r2  r7  r   r   r   r   Ú<module>rA     s  ðñó
 Û 	Û 
Û Ý å %÷÷ ÷ ÷ ó ô(	ˆIô 	ô	�ô 	òòOò$ò0ô<!�ô <!ðD —
’
˜<Ó(€Ø—J’J˜zÓ*Ð Ø�ZŠZð'ð ‡J�Jó	€
ò ôF!ô2~�ô ~÷BWñ Wð| 
€ô
*Hôb5?ôx%HôX-
ô`$ð* ˆzÔÙˆ�!×ñ r   