+
    i#                         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   &       Y/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/logic/algorithms/dpll.pydpll_satisfiabler      s     dC  F4L),,%d+1ABG5CL1$456"74+rBFFwQw'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      W4      # )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[     /HA
aZ qA ,#G351HA
aZ qA ,#G55Oa%<d?""1%  AJ	LL!Tq%j!1:L3W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      W4      # )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    )8HA
aZ qA)'5,W<5(:HA
aZ qA)'5,W>5Oq(%<d?""1%  AJ	LL!Tq%j!<<>L1/Ew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66R<MM!66Cg~baff"EffW11f"EFG}  MM!  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     rdG+2F7vo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     $e9 A	!!4 	9SYq\!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((1I((g)>g"g)>?I2Yd7N  2Y2u9   *?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% Jw$< <5	 )
 q e8O  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0E.w<1A1ur5y $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   