� ��g#���dZddlmZmZmZmZmZddlmZddl m Z ddl m Z d�Z dd �Zd �Zdd �Zdd �ZGd �d��ZGd�de��ZdS)z Inference in propositional logic�)�And�Not� conjuncts�to_cnf�BooleanFunction)�ordered)�sympify)� import_modulec��|dus|dur|S|jr|S|jrt|jd��St 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 TFrz#Argument must be a boolean literal.)� is_Symbol�is_Not�literal_symbol�args� ValueError)�literals �e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/logic/inference.pyrr s[�� �$���'�U�*�*��� � �@��� ��@��g�l�1�o�.�.�.��>�?�?�?�NFc� �|r|�|dkrtd|�d����d}|�|dkr+td��}|�d}n|dkrtd���d}|dkrtd��}|�d}|d krtd ��}|�d}|d krd d lm}||��S|dkrd d lm}||||� ��S|dkrd dlm} | ||��S|dkrd dlm } | |||��S|d krd dl m } | ||��St�)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.�pycosatzpycosat module is not present� minisat22�pysat�z3�dpllr)�dpll_satisfiable)�use_lra_theory)�pycosat_satisfiable)�minisat22_satisfiable)�z3_satisfiable) rr � 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�minimalrrrrrrrrs 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�/�/�/� �rc�<�tt|���� 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-zs��*�3�t�9�9�%�%� %�%rc������ddlm�d����fd��|�vr|St|��}�|��std|z���|si}�fd�|���D��}|�|��}|�vrt |��S|r`t�|� ��d��}t||��rt|��rdSnt|��sdSd 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|�vrdSt|t��sdSt�fd�|jD����S)NTFc3�.�K�|]}�|��V��dS�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 ���rr6zpl_true.<locals>._validate�s^��� �d�F� #� #� �t�w����4��$��0�0� ��5��7�7�7�7�T�Y�7�7�7�7�7�7rz$%s is not a valid boolean expressionc�$��i|] \}}|�v� ||�� Sr3r3)r4�k�vr:s �r� <dictcomp>zpl_true.<locals>.<dictcomp>�s$��� <� <� <�d�a��q�G�|�|�Q��|�|�|rTFN) �sympy.core.symbolr/r r�items�subs�bool�dict�fromkeys�atoms�pl_truer-r+)r'�model�deep�resultr/r6r:s @@@rrFrF�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� �4rc��|rt|��}ng}|�t|����tt |��� 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�appendrr+r)r'� formula_sets r�entailsrN�sP��2���;�'�'� � �� ����s�4�y�y�!�!�!��3� �,�-�-� -�-rc�B�eZdZdZdd�Zd�Zd�Zd�Zed���Z dS) �KBz"Base class for all knowledge basesNc�^�t��|_|r|�|��dSdSr2)�set�clauses_�tell��self�sentences r�__init__z KB.__init__�s7������ � � � �I�I�h� � � � � � � rc��t�r2�r&rUs rrTzKB.tell���!�!rc��t�r2rZ�rV�querys r�askzKB.askr[rc��t�r2rZrUs r�retractz KB.retract r[rc�D�tt|j����Sr2)rKrrS)rVs r�clausesz KB.clauses s���G�D�M�*�*�+�+�+rr2) �__name__� __module__� __qualname__�__doc__rXrTr_ra�propertyrcr3rrrPrP�sv������,�,� � � � � "�"�"�"�"�"�"�"�"��,�,��X�,�,�,rrPc�$�eZdZdZd�Zd�Zd�ZdS)�PropKBz=A KB for Propositional Logic. Inefficient, with no indexing.c�x�tt|����D]}|j�|���dS)aiAdd 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)rrrS�add�rVrW�cs rrTz PropKB.tellsF��*�6�(�+�+�,�,� !� !�A� �M� � �a� � � � � !� !rc�,�t||j��S)a8Checks 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 )rNrSr]s rr_z PropKB.ask,s�� �u�d�m�,�,�,rc�x�tt|����D]}|j�|���dS)amRemove 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)rrrS�discardrms rrazPropKB.retract>sF��*�6�(�+�+�,�,� %� %�A� �M� !� !�!� $� $� $� $� %� %rN)rdrerfrgrTr_rar3rrrjrjsG������G�G�!�!�!�0-�-�-�$%�%�%�%�%rrj)NFFF)NFr2)rg�sympy.logic.boolalgrrrrr�sympy.core.sortingr�sympy.core.sympifyr �sympy.external.importtoolsr rr+r-rFrNrPrjr3rr�<module>rvs9��&�&�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
Memory