+
    
þÎjä#  ã                   ó˜   € R t ^ RIHt ^ RIHtHtHtHtHtH	t	H
t
 ^ RIHt ^ RIHtHt R tR tR t/ 3R ltR	 tR
 tR tR tR tR tR# )a&  Implementation of DPLL algorithm

Further improvements: eliminate calls to pl_true, implement branching rules,
efficient unit propagation.

References:
  - https://en.wikipedia.org/wiki/DPLL_algorithm
  - https://www.researchgate.net/publication/242384772_Implementations_of_the_DPLL_Algorithm
)Údefault_sort_key)ÚOrÚNotÚ	conjunctsÚ	disjunctsÚto_cnfÚto_int_reprÚ_find_predicates)ÚCNF)Úpl_trueÚliteral_symbolc                ó¨  € \        V \        4      '       g   \        \        V 4      4      pMV P                  pRV9   d   R# \        \        V 4      \        R7      p\        \        ^\        V4      ^,           4      4      p\        W4      p\        WC/ 4      pV'       g   V# / pV F)  pVP                  W'^,
          ,          WW,          /4       K+  	  V# )a  
Check satisfiability of a propositional sentence.
It returns a model rather than True when it succeeds

>>> from sympy.abc import A, B
>>> from sympy.logic.algorithms.dpll import dpll_satisfiable
>>> dpll_satisfiable(A & ~B)
{A: True, B: False}
>>> dpll_satisfiable(A & ~A)
False

F)Úkey)Ú
isinstancer
   r   r   ÚclausesÚsortedr	   r   ÚsetÚrangeÚlenr   Údpll_int_reprÚupdate)Úexprr   ÚsymbolsÚsymbols_int_reprÚclauses_int_reprÚresultÚoutputr   s   &       ÚQ/opt/data/home/.local/lib/python3.14/site-packages/sympy/logic/algorithms/dpll.pyÚdpll_satisfiabler      s¯   € ô �dœC× Ò ÜœF 4›LÓ)‰à—,‘,ˆØ�ÔÙÜÔ% dÓ+Ô1AÔB€GÜœ5 ¤C¨£L°1Õ$4Ó5Ó6ÐÜ" 7Ó4ÐÜÐ+¸rÓB€FßØˆØ€FÛˆØ�‰�w Q�wÕ'¨­Ð5Ö6ñ à€Mó    c                ó$  € \        W4      w  r4V'       dI   VP                  W4/4       VP                  V4       V'       g   V( p\        W4      p \        W4      w  r4KP  \	        W4      w  r4V'       dI   VP                  W4/4       VP                  V4       V'       g   V( p\        W4      p \	        W4      w  r4KP  . pV  F0  p\        Wb4      pVRJ d    R# VRJg   K  VP                  V4       K2  	  V'       g   V# V '       g   V# VP                  4       pVP                  4       pVP                  VR/4       VP                  VR/4       VR,          p	\        \        WS4      W4      ;'       g     \        \        V\        V4      4      W˜4      # )zÑ
Compute satisfiability in a partial model.
Clauses is an array of conjuncts.

>>> from sympy.abc import A, B, D
>>> from sympy.logic.algorithms.dpll import dpll
>>> dpll([A, B, D], [A, B], {D: False})
False

FT:NNN)Úfind_unit_clauser   ÚremoveÚunit_propagateÚfind_pure_symbolr   ÚappendÚpopÚcopyÚdpllr   ©
r   r   ÚmodelÚPÚvalueÚunknown_clausesÚcÚvalÚ
model_copyÚsymbols_copys
   &&&       r   r(   r(   1   s[  € ô   Ó/�H€Aß
Ø�‰�a�ZÔ Ø�‰�qÔßØ�ˆAÜ  Ó,ˆÜ# GÓ3‰ˆ‰5Ü Ó1�H€Aß
Ø�‰�a�ZÔ Ø�‰�qÔßØ�ˆAÜ  Ó,ˆÜ# GÓ5‰ˆ‰5à€OÛˆÜ�aÓˆØ�%‹<ÚØ�d�?Ø×"Ñ" 1Ö%ñ ÷ ØˆßØˆØ�‰‹€AØ—‘“€JØ	‡L�L�!�T�ÔØ×Ñ�q˜%�jÔ!Ø˜1•:€LÜ” Ó3°WÓD÷ Tð TÜ” ´°Q³Ó8¸,ÓSðUr   c                ó  € \        W4      w  r4V'       dI   VP                  W4/4       VP                  V4       V'       g   V) p\        W4      p \        W4      w  r4KP  \	        W4      w  r4V'       dI   VP                  W4/4       VP                  V4       V'       g   V) p\        W4      p \	        W4      w  r4KP  . pV  F0  p\        Wb4      pVRJ d    R# VRJg   K  VP                  V4       K2  	  V'       g   V# VP                  4       pVP                  4       pVP                  VR/4       VP                  VR/4       VP                  4       p	\        \        WS4      W4      ;'       g    \        \        WS) 4      W˜4      # )zÜ
Compute satisfiability in a partial model.
Arguments are expected to be in integer representation

>>> from sympy.logic.algorithms.dpll import dpll_int_repr
>>> dpll_int_repr([{1}, {2}, {3}], {1, 2}, {3: False})
False

FT)
Úfind_unit_clause_int_reprr   r"   Úunit_propagate_int_reprÚfind_pure_symbol_int_reprÚpl_true_int_reprr%   r&   r'   r   r)   s
   &&&       r   r   r   b   sS  € ô )¨Ó8�H€Aß
Ø�‰�a�ZÔ Ø�‰�qÔßØ�ˆAÜ)¨'Ó5ˆÜ,¨WÓ<‰ˆ‰5Ü(¨Ó:�H€Aß
Ø�‰�a�ZÔ Ø�‰�qÔßØ�ˆAÜ)¨'Ó5ˆÜ,¨WÓ>‰ˆ‰5à€OÛˆÜ˜qÓ(ˆØ�%‹<ÚØ�d�?Ø×"Ñ" 1Ö%ñ ÷ ØˆØ�‰‹€AØ—‘“€JØ	‡L�L�!�T�ÔØ×Ñ�q˜%�jÔ!Ø—<‘<“>€LÜÔ1°/ÓEÀwÓV÷ bð bÜÔ1°/À2ÓFÈÓaðcr   c                óª   € RpV  FJ  pV^ 8  d   VP                  V) 4      pVe   V'       * pMVP                  V4      pVRJ d    R# Ve   KH  RpKL  	  V# )aF  
Lightweight version of pl_true.
Argument clause represents the set of args of an Or clause. This is used
inside dpll_int_repr, it is not meant to be used directly.

>>> from sympy.logic.algorithms.dpll import pl_true_int_repr
>>> pl_true_int_repr({1, 2}, {1: False})
>>> pl_true_int_repr({1, 2}, {1: False, 2: False})
False

FNT)Úget)Úclauser*   r   ÚlitÚps   &&   r   r6   r6   ’   s^   € ð €FÛˆØ�Œ7Ø—	‘	˜3˜$“ˆAØŠ}Ø”E�øà—	‘	˜#“ˆAØ�‹9ÚØŒYØŠFñ ð €Mr   c                óZ  € . pV  F�  pVP                   \        8w  d   VP                  V4       K+  VP                   FQ  pWA( 8X  d?   TP                  \        VP                   Uu. uF  qUV( 8w  g   K  VNK  	  up!  4        K  WA8X  g   KP   KŠ  	  VP                  V4       KŸ  	  V# u upi )aÅ  
Returns an equivalent set of clauses
If a set of clauses contains the unit clause l, the other clauses are
simplified by the application of the two following rules:

  1. every clause containing l is removed
  2. in every clause that contains ~l this literal is deleted

Arguments are expected to be in CNF.

>>> from sympy.abc import A, B, D
>>> from sympy.logic.algorithms.dpll import unit_propagate
>>> unit_propagate([A | B, D | ~B, B], B)
[D, B]

)Úfuncr   r%   Úargs)r   Úsymbolr   r.   ÚargÚxs   &&    r   r#   r#   ­   s”   € ð" €FÛˆØ�6‰6”RŒ<Ø�M‰M˜!ÔÙØ—6”6ˆCØ�gŒ~Ø—‘œb¨a¯fªfÓ"E©f¨¸f¸W¹§1 1©fÑ"EÑFÔGÚØŽ}Úñ ð �M‰M˜!Öñ ð €Mùò #Fs   Á$	B(Á2B(c                óT   € V) 0pV  Uu. uF  q1V9  g   K  W2,
          NK  	  up# u upi )z×
Same as unit_propagate, but arguments are expected to be in integer
representation

>>> from sympy.logic.algorithms.dpll import unit_propagate_int_repr
>>> unit_propagate_int_repr([{1, 2}, {3, -2}, {2}], 2)
[{3}]

© )r   ÚsÚnegatedr9   s   &&  r   r4   r4   Î   s2   € ð ˆrˆd€GÙ+2ÓF©7 ¸v±oÔˆF×Ð©7ÑFÐFùÒFs   ‰%–%c                óÈ   € V  F[  pRRrCV FD  pV'       g   V\        V4      9   d   RpV'       d   K'  \        V4      \        V4      9   g   KB  RpKF  	  W48w  g   KX  W#3u # 	  R# )a  
Find a symbol and its value if it appears only as a positive literal
(or only as a negative) in clauses.

>>> from sympy.abc import A, B, D
>>> from sympy.logic.algorithms.dpll import find_pure_symbol
>>> find_pure_symbol([A, B, D], [A|~B,~B|~D,D|A])
(A, True)

FT©NN)r   r   )r   r-   ÚsymÚ	found_posÚ	found_negr.   s   &&    r   r$   r$   Ü   sc   € ó ˆØ$ e�9Û ˆAß ¬	°!«Ô!4Ø �	ß‘9¤ S£¬Y°q«\Ö!9Ø ’	ñ	 !ð
 Ö!Ø�>Ò!ñ ð Ðr   c                ó  € \        4       P                  ! V!  pVP                  V 4      pTP                  V  Uu. uF  qD) NK  	  up4      pV F  pV) V9  g   K  VR3u # 	  V F  pV) V9  g   K  V) R3u # 	  R# u upi )zô
Same as find_pure_symbol, but arguments are expected
to be in integer representation

>>> from sympy.logic.algorithms.dpll import find_pure_symbol_int_repr
>>> find_pure_symbol_int_repr({1,2,3},
...     [{1, -2}, {-2, -3}, {3, 1}])
(1, True)

TFrG   )r   ÚunionÚintersection)r   r-   Úall_symbolsrI   rD   rJ   r;   s   &&     r   r5   r5   ó   s�   € ô “%—+’+˜Ñ/€KØ×(Ñ(¨Ó1€IØ×(Ñ(±gÓ)>±g°«"±gÑ)>Ó?€IÛˆØˆ2�YÖØ�d�7ŠNñ ó ˆØˆ2�YÖØ�2�u�9Òñ ð Ðùò *?s   ¹A<c                ó¾   € V  FV  p^ p\        V4       F5  p\        V4      pWQ9  g   K  V^,          pT\        V\        4      '       * rvK7  	  V^8X  g   KR  XX3u # 	  R# )zë
A unit clause has only 1 variable that is not bound in the model.

>>> from sympy.abc import A, B, D
>>> from sympy.logic.algorithms.dpll import find_unit_clause
>>> find_unit_clause([A | B | D, B | ~D, A | ~B], {A:True})
(B, False)

rG   )r   r   r   r   )r   r*   r9   Únum_not_in_modelÚliteralrH   r+   r,   s   &&      r   r!   r!   
  sj   € ó ˆØÐÜ  Ö(ˆGÜ  Ó)ˆCØÖØ  AÕ%Ð Ø¤J¨w¼Ó$<Ô <’5ñ	 )ð
 ˜qÖ Ø�e�8ŠOñ ð Ðr   c                óÞ   € \        V4      V Uu0 uF  q") kK  	  up,          pV  F?  pWC,
          p\        V4      ^8X  g   K  VP                  4       pV^ 8  d   V) R3u # VR3u # 	  R# u upi )zú
Same as find_unit_clause, but arguments are expected to be in
integer representation.

>>> from sympy.logic.algorithms.dpll import find_unit_clause_int_repr
>>> find_unit_clause_int_repr([{1, 2, 3},
...     {2, -3}, {1, -2}], {1: True})
(2, False)

FTrG   )r   r   r&   )r   r*   rH   Úboundr9   Úunboundr;   s   &&     r   r3   r3      sr   € ô �‹J©%Ó0©% 3›$©%Ñ0Õ0€EÛˆØ•.ˆÜˆw‹<˜1ÖØ—‘“ˆAØ�1ŒuØ�r˜5�yÒ à˜$�w’ñ ð Ðùò 1s   �A*N)Ú__doc__Úsympy.core.sortingr   Úsympy.logic.boolalgr   r   r   r   r   r   r	   Úsympy.assumptions.cnfr
   Úsympy.logic.inferencer   r   r   r(   r   r6   r#   r4   r$   r5   r!   r3   rC   r   r   Ú<module>rZ      sa   ðñõ 0÷"÷ "ñ "å %ß 9òò>.Uòb+cð` $&ô ò6òBGòò.ò.ô,r   