§
    OŠtj#  ã                   ó¤   — 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dS )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/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/logic/inference.pyr   r   	   s[   € ð  �$€€˜' UÐ*Ð*ØˆØ	Ô	ð @ØˆØ	Œð @Ý˜gœl¨1œoÑ.Ô.Ð.åÐ>Ñ?Ô?Ð?ó    NFc                 ó  — |r|�|dk    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

    NÚ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Ð%9ÝÐmÐR[ÐmÐmÐmÑnÔnÐnØˆ	àÐ˜I¨Ò2Ð2Ý 	Ñ*Ô*ˆØÐØ!ˆIˆIà˜IÒ%Ð%Ý!Ð"AÑBÔBÐBð  ˆIà�+ÒÐÝ˜gÑ&Ô&ˆØˆ=ØˆIà�$‚€Ý˜4Ñ Ô ˆØˆ:ØˆIà�FÒÐØ@Ð@Ð@Ð@Ð@Ð@ØÐ Ñ%Ô%Ð%Ø	�gÒ	Ð	ØAÐAÐAÐAÐAÐAØÐ  jÀÐPÑPÔPÐPØ	�iÒ	Ð	ØNÐNÐNÐNÐNÐNØ"Ð" 4¨Ñ4Ô4Ð4Ø	�kÒ	!Ð	!ØRÐRÐRÐRÐRÐRØ$Ð$ T¨:°wÑ?Ô?Ð?Ø	�dÒ	Ð	ØDÐDÐDÐDÐ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œ9Ñ%Ô%Ð%Ð%r   c                 óê  ‡‡‡— ddl mŠ dŠˆˆˆfd„Š| ‰v r| S t          | ¦  «        }  ‰| ¦  «        st          d| z  ¦  «        ‚|si }ˆfd„|                     ¦   «         D ¦   «         }|                      |¦  «        }|‰v rt          |¦  «        S |r`t                               | 	                    ¦   «         d¦  «        }t          ||¦  «        rt          |¦  «        rdS nt          |¦  «        sdS d	S )
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dS t          | t          ¦  «        sdS t          ˆfd„| j        D ¦   «         ¦  «        S )NTFc              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S ©N© )Ú.0ÚargÚ	_validates     €r   ú	<genexpr>z-pl_true.<locals>._validate.<locals>.<genexpr>Ã   s+   øè è € Ð7Ð7 c�9�9˜S‘>”>Ð7Ð7Ð7Ð7Ð7Ð7r   )Ú
isinstancer   Úallr   )r'   r/   r6   Úbooleans    €€€r   r6   zpl_true.<locals>._validate¾   s^   ø€ Ý�d˜FÑ#Ô#ð 	 t¨w  Ø�4Ý˜$¥Ñ0Ô0ð 	Ø�5ÝÐ7Ð7Ð7Ð7¨T¬YÐ7Ñ7Ô7Ñ7Ô7Ð7r   z$%s is not a valid boolean expressionc                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS r3   r3   )r4   ÚkÚvr:   s      €r   ú
<dictcomp>zpl_true.<locals>.<dictcomp>Ì   s$   ø€ Ð<Ð<Ð<‘d�a˜¨q°G¨|¨|ˆQ�¨|¨|¨|r   TFN)Úsympy.core.symbolr/   r	   r   ÚitemsÚsubsÚboolÚdictÚfromkeysÚatomsÚpl_truer-   r+   )r'   ÚmodelÚdeepÚresultr/   r6   r:   s       @@@r   rF   rF   ’   sA  øøø€ ðP )Ð(Ð(Ð(Ð(Ð(à€Gð8ð 8ð 8ð 8ð 8ð 8ð 8ð ˆw€€ØˆÝ�4‰=Œ=€DØˆ9�T‰?Œ?ð HÝÐ?À$ÑFÑGÔGÐGØð ØˆØ<Ð<Ð<Ð<˜eŸkšk™mœmÐ<Ñ<Ô<€EØ�YŠY�uÑÔ€FØ�ÐÐÝ�F‰|Œ|ÐØð Ý—’˜fŸlšl™nœn¨dÑ3Ô3ˆÝ�6˜5Ñ!Ô!ð 	Ý�V‰}Œ}ð Ø�tðõ ˜vÑ&Ô&ð Ø�uØˆ4r   c                 óœ   — |rt          |¦  «        }ng }|                     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   ÚentailsrN   Û   sP   € ð2 ð Ý˜;Ñ'Ô'ˆˆàˆØ×Ò•s˜4‘y”yÑ!Ô!Ð!Ý�3 Ð,Ñ-Ô-Ð-Ð-r   c                   óB   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zed„ ¦   «         Z	dS )	ÚKBz"Base class for all knowledge basesNc                 ó^   — t          ¦   «         | _        |r|                      |¦  «         d S d S r2   )ÚsetÚclauses_Útell©ÚselfÚsentences     r   Ú__init__zKB.__init__þ   s7   € Ý™œˆŒØð 	 Ø�IŠI�hÑÔÐÐÐð	 ð 	 r   c                 ó   — t           ‚r2   ©r&   rU   s     r   rT   zKB.tell  ó   € Ý!Ð!r   c                 ó   — t           ‚r2   rZ   ©rV   Úquerys     r   ÚaskzKB.ask  r[   r   c                 ó   — t           ‚r2   rZ   rU   s     r   Úretractz
KB.retract	  r[   r   c                 óD   — t          t          | j        ¦  «        ¦  «        S r2   )rK   r   rS   )rV   s    r   Úclausesz
KB.clauses  s   € å•G˜DœMÑ*Ô*Ñ+Ô+Ð+r   r2   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rX   rT   r_   ra   Úpropertyrc   r3   r   r   rP   rP   ü   sv   € € € € € Ø,Ð,ð ð  ð  ð  ð
"ð "ð "ð"ð "ð "ð"ð "ð "ð ð,ð ,ñ „Xð,ð ,ð ,r   rP   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚPropKBz=A KB for Propositional Logic.  Inefficient, with no indexing.c                 óx   — t          t          |¦  «        ¦  «        D ]}| j                             |¦  «         ŒdS )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   rS   Úadd©rV   rW   Úcs      r   rT   zPropKB.tell  sF   € õ* �6 (Ñ+Ô+Ñ,Ô,ð 	!ð 	!ˆAØŒ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

        )rN   rS   r]   s     r   r_   z
PropKB.ask,  s   € õ  �u˜dœmÑ,Ô,Ð,r   c                 óx   — t          t          |¦  «        ¦  «        D ]}| j                             |¦  «         ŒdS )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   rS   Údiscardrm   s      r   ra   zPropKB.retract>  sF   € õ* �6 (Ñ+Ô+Ñ,Ô,ð 	%ð 	%ˆAØŒM×!Ò! !Ñ$Ô$Ð$Ð$ð	%ð 	%r   N)rd   re   rf   rg   rT   r_   ra   r3   r   r   rj   rj     sG   € € € € € ØGÐGð!ð !ð !ð0-ð -ð -ð$%ð %ð %ð %ð %r   rj   )NFFF)NFr2   )rg   Úsympy.logic.boolalgr   r   r   r   r   Úsympy.core.sortingr   Úsympy.core.sympifyr	   Úsympy.external.importtoolsr
   r   r+   r-   rF   rN   rP   rj   r3   r   r   ú<module>rv      s9  ðØ &Ð &à LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LØ &Ð &Ð &Ð &Ð &Ð &Ø &Ð &Ð &Ð &Ð &Ð &Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4ð@ð @ð @ð4Tð Tð Tð Tðn&ð &ð &ð0Fð Fð Fð FðR.ð .ð .ð .ðB,ð ,ð ,ð ,ð ,ñ ,ô ,ð ,ð*C%ð C%ð C%ð C%ð C%ˆRñ C%ô C%ð C%ð C%ð C%r   