Ë
    7^(h#  ã                   ó–   — d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ d„ Zdd„Zd	„ Zdd
„Zdd„Z G d„ d«      Z G d„ de«      Zy)z Inference in propositional logicé    )ÚAndÚNotÚ	conjunctsÚto_cnfÚBooleanFunction)Úordered)Úsympify)Úimport_modulec                 ó�   — | du s| du r| S | j                   r| S | j                  rt        | j                  d   «      S t	        d«      ‚)zó
    The symbol in this literal (without the negation).

    Examples
    ========

    >>> from sympy.abc import A
    >>> from sympy.logic.inference import literal_symbol
    >>> literal_symbol(A)
    A
    >>> literal_symbol(~A)
    A

    TFr   z#Argument must be a boolean literal.)Ú	is_SymbolÚis_NotÚliteral_symbolÚargsÚ
ValueError)Úliterals    úS/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/logic/inference.pyr   r   	   sK   € ð  �$�˜' UÑ*ØˆØ	×	Ò	ØˆØ	�ŠÜ˜gŸl™l¨1™oÓ.Ð.äÐ>Ó?Ð?ó    Nc                 ó°  — |r|�|dk7  rt        d|› d�«      ‚d}|�|dk(  r"t        d«      }|�d}n|dk(  rt        d«      ‚d}|dk(  rt        d«      }|€d}|dk(  rt        d«      }|€d}|d	k(  rd
dlm}  || «      S |dk(  rd
dlm}  || ||¬«      S |dk(  rd
dlm}	  |	| |«      S |dk(  rd
dlm	}
  |
| ||«      S |dk(  rd
dl
m}  || |«      S t        ‚)aÚ  
    Check satisfiability of a propositional sentence.
    Returns a model when it succeeds.
    Returns {true: true} for trivially true expressions.

    On setting all_models to True, if given expr is satisfiable then
    returns a generator of models. However, if expr is unsatisfiable
    then returns a generator containing the single element False.

    Examples
    ========

    >>> from sympy.abc import A, B
    >>> from sympy.logic.inference import satisfiable
    >>> satisfiable(A & ~B)
    {A: True, B: False}
    >>> satisfiable(A & ~A)
    False
    >>> satisfiable(True)
    {True: True}
    >>> next(satisfiable(A & ~A, all_models=True))
    False
    >>> models = satisfiable((A >> B) & B, all_models=True)
    >>> next(models)
    {A: False, B: True}
    >>> next(models)
    {A: True, B: True}
    >>> def use_models(models):
    ...     for model in models:
    ...         if model:
    ...             # Do something with the model.
    ...             print(model)
    ...         else:
    ...             # Given expr is unsatisfiable.
    ...             print("UNSAT")
    >>> use_models(satisfiable(A >> ~A, all_models=True))
    {A: False}
    >>> use_models(satisfiable(A ^ A, all_models=True))
    UNSAT

    Údpll2z2Currently only dpll2 can handle using lra theory. z is not handled.Úpycosatzpycosat module is not presentÚ	minisat22ÚpysatÚz3Údpllr   )Údpll_satisfiable)Úuse_lra_theory)Úpycosat_satisfiable)Úminisat22_satisfiable)Úz3_satisfiable)r   r
   ÚImportErrorÚsympy.logic.algorithms.dpllr   Úsympy.logic.algorithms.dpll2Ú&sympy.logic.algorithms.pycosat_wrapperr   Ú(sympy.logic.algorithms.minisat22_wrapperr   Ú!sympy.logic.algorithms.z3_wrapperr   ÚNotImplementedError)ÚexprÚ	algorithmÚ
all_modelsÚminimalr   r   r   r   r   r   r   r   s               r   Úsatisfiabler+   #   s&  € ñT ØÐ  Y°'Ò%9ÜÐQÐR[ÐQ\Ð\lÐmÓnÐnØˆ	àÐ˜I¨Ò2Ü 	Ó*ˆØÐØ!‰Ià˜IÒ%Ü!Ð"AÓBÐBð  ˆIà�+ÒÜ˜gÓ&ˆØˆ=ØˆIà�$‚Ü˜4Ó ˆØˆ:ØˆIà�FÒÝ@Ù Ó%Ð%Ø	�gÒ	ÝAÙ  jÀÔPÐPØ	�iÒ	ÝNÙ" 4¨Ó4Ð4Ø	�kÒ	!ÝRÙ$ T¨:°wÓ?Ð?Ø	�dÒ	ÝDÙ˜d JÓ/Ð/ä
Ðr   c                 ó,   — t        t        | «      «       S )ax  
    Check validity of a propositional sentence.
    A valid propositional sentence is True under every assignment.

    Examples
    ========

    >>> from sympy.abc import A, B
    >>> from sympy.logic.inference import valid
    >>> valid(A | ~A)
    True
    >>> valid(A | B)
    False

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Validity

    )r+   r   )r'   s    r   Úvalidr-   z   s   € ô* œ3˜t›9Ó%Ð%Ð%r   c                 ó°  ‡‡‡— ddl mŠ dŠˆˆˆfd„Š| ‰v r| S t        | «      }  ‰| «      st        d| z  «      ‚|si }|j	                  «       D ��ci c]  \  }}|‰v sŒ||“Œ }}}| j                  |«      }|‰v rt        |«      S |rIt        j                  |j                  «       d«      }t        ||«      rt        |«      ryyt        |«      syyc c}}w )	a+  
    Returns whether the given assignment is a model or not.

    If the assignment does not specify the value for every proposition,
    this may return None to indicate 'not obvious'.

    Parameters
    ==========

    model : dict, optional, default: {}
        Mapping of symbols to boolean values to indicate assignment.
    deep: boolean, optional, default: False
        Gives the value of the expression under partial assignments
        correctly. May still return None to indicate 'not obvious'.


    Examples
    ========

    >>> from sympy.abc import A, B
    >>> from sympy.logic.inference import pl_true
    >>> pl_true( A & B, {A: True, B: True})
    True
    >>> pl_true(A & B, {A: False})
    False
    >>> pl_true(A & B, {A: True})
    >>> pl_true(A & B, {A: True}, deep=True)
    >>> pl_true(A >> (B >> A))
    >>> pl_true(A >> (B >> A), deep=True)
    True
    >>> pl_true(A & ~A)
    >>> pl_true(A & ~A, deep=True)
    False
    >>> pl_true(A & B & (~A | ~B), {A: True})
    >>> pl_true(A & B & (~A | ~B), {A: True}, deep=True)
    False

    r   )ÚSymbol)TFc                 ó„   •— t        | ‰«      s| ‰v ryt        | t        «      syt        ˆfd„| j                  D «       «      S )NTFc              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­w©N© )Ú.0ÚargÚ	_validates     €r   ú	<genexpr>z-pl_true.<locals>._validate.<locals>.<genexpr>Ã   s   øè ø€ Ò7 c‘9˜S—>Ñ7ùs   ƒ)Ú
isinstancer   Úallr   )r'   r/   r6   Úbooleans    €€€r   r6   zpl_true.<locals>._validate¾   s8   ø€ Ü�d˜FÔ# t¨w¡ØÜ˜$¤Ô0ØÜÓ7¨T¯Y©YÔ7Ó7Ð7r   z$%s is not a valid boolean expressionTFN)Úsympy.core.symbolr/   r	   r   ÚitemsÚsubsÚboolÚdictÚfromkeysÚatomsÚpl_truer-   r+   )	r'   ÚmodelÚdeepÚkÚvÚresultr/   r6   r:   s	         @@@r   rB   rB   ’   sØ   ú€ õP )à€Gö8ð ˆw�ØˆÜ�4‹=€DÙ�TŒ?ÜÐ?À$ÑFÓGÐGÙØˆØ#Ÿk™k›m×<‘d�a˜¨q°Gª|ˆQ�‰TÐ<€EÑ<Ø�Y‰Y�uÓ€FØ�ÑÜ�F‹|ÐÙÜ—‘˜fŸl™l›n¨dÓ3ˆÜ�6˜5Ô!Ü�VŒ}Øð ô ˜vÔ&ØØùó =s   ÁCÁCc                 óz   — |rt        |«      }ng }|j                  t        | «      «       t        t	        |Ž «       S )aø  
    Check whether the given expr_set entail an expr.
    If formula_set is empty then it returns the validity of expr.

    Examples
    ========

    >>> from sympy.abc import A, B, C
    >>> from sympy.logic.inference import entails
    >>> entails(A, [A >> B, B >> C])
    False
    >>> entails(C, [A >> B, B >> C, A])
    True
    >>> entails(A >> B)
    False
    >>> entails(A >> (B >> A))
    True

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Logical_consequence

    )ÚlistÚappendr   r+   r   )r'   Úformula_sets     r   ÚentailsrL   Û   s;   € ñ2 Ü˜;Ó'‰àˆØ×Ñ”s˜4“yÔ!Üœ3 Ð,Ó-Ð-Ð-r   c                   ó:   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zed„ «       Z	y)	ÚKBz"Base class for all knowledge basesNc                 óJ   — t        «       | _        |r| j                  |«       y y r2   )ÚsetÚclauses_Útell©ÚselfÚsentences     r   Ú__init__zKB.__init__þ   s   € Ü›ˆŒÙØ�I‰I�hÕð r   c                 ó   — t         ‚r2   ©r&   rS   s     r   rR   zKB.tell  ó   € Ü!Ð!r   c                 ó   — t         ‚r2   rX   ©rT   Úquerys     r   ÚaskzKB.ask  rY   r   c                 ó   — t         ‚r2   rX   rS   s     r   Úretractz
KB.retract	  rY   r   c                 ó>   — t        t        | j                  «      «      S r2   )rI   r   rQ   )rT   s    r   Úclausesz
KB.clauses  s   € ä”G˜DŸM™MÓ*Ó+Ð+r   r2   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rV   rR   r]   r_   Úpropertyra   r3   r   r   rN   rN   ü   s-   „ Ù,ó ò
"ò"ò"ð ñ,ó ñ,r   rN   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚPropKBz=A KB for Propositional Logic.  Inefficient, with no indexing.c                 ól   — t        t        |«      «      D ]  }| j                  j                  |«       Œ y)ai  Add the sentence's clauses to the KB

        Examples
        ========

        >>> from sympy.logic.inference import PropKB
        >>> from sympy.abc import x, y
        >>> l = PropKB()
        >>> l.clauses
        []

        >>> l.tell(x | y)
        >>> l.clauses
        [x | y]

        >>> l.tell(y)
        >>> l.clauses
        [y, x | y]

        N)r   r   rQ   Úadd©rT   rU   Úcs      r   rR   zPropKB.tell  s/   € ô* œ6 (Ó+Ó,ò 	!ˆAØ�M‰M×Ñ˜aÕ ñ	!r   c                 ó.   — t        || j                  «      S )a8  Checks if the query is true given the set of clauses.

        Examples
        ========

        >>> from sympy.logic.inference import PropKB
        >>> from sympy.abc import x, y
        >>> l = PropKB()
        >>> l.tell(x & ~y)
        >>> l.ask(x)
        True
        >>> l.ask(y)
        False

        )rL   rQ   r[   s     r   r]   z
PropKB.ask,  s   € ô  �u˜dŸm™mÓ,Ð,r   c                 ól   — t        t        |«      «      D ]  }| j                  j                  |«       Œ y)am  Remove the sentence's clauses from the KB

        Examples
        ========

        >>> from sympy.logic.inference import PropKB
        >>> from sympy.abc import x, y
        >>> l = PropKB()
        >>> l.clauses
        []

        >>> l.tell(x | y)
        >>> l.clauses
        [x | y]

        >>> l.retract(x | y)
        >>> l.clauses
        []

        N)r   r   rQ   Údiscardrk   s      r   r_   zPropKB.retract>  s/   € ô* œ6 (Ó+Ó,ò 	%ˆAØ�M‰M×!Ñ! !Õ$ñ	%r   N)rb   rc   rd   re   rR   r]   r_   r3   r   r   rh   rh     s   „ ÙGò!ò0-ó$%r   rh   )NFFF)NFr2   )re   Úsympy.logic.boolalgr   r   r   r   r   Úsympy.core.sortingr   Úsympy.core.sympifyr	   Úsympy.external.importtoolsr
   r   r+   r-   rB   rL   rN   rh   r3   r   r   ú<module>rt      sN   ðÙ &ç LÕ LÝ &Ý &Ý 4ò@ó4Tòn&ó0FóR.÷B,ñ ,ô*C%ˆRõ C%r   