
    \h                         S r SSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
Jr  SSKJrJrJrJrJrJr  SSKJrJr  SS	/r " S
 S\5      r " S S	\5      rg)z
General binary relations.
    )Optional)S)AppliedPredicateask	PredicateQ)BooleanKind)EqNeGtLtGeLe)	conjunctsNotBinaryRelationAppliedBinaryRelationc                   x    \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   S r
\S 5       r\S 5       rS	 rSS
 jrSrg)r      a  
Base class for all binary relational predicates.

Explanation
===========

Binary relation takes two arguments and returns ``AppliedBinaryRelation``
instance. To evaluate it to boolean value, use :obj:`~.ask()` or
:obj:`~.refine()` function.

You can add support for new types by registering the handler to dispatcher.
See :obj:`~.Predicate()` for more information about predicate dispatching.

Examples
========

Applying and evaluating to boolean value:

>>> from sympy import Q, ask, sin, cos
>>> from sympy.abc import x
>>> Q.eq(sin(x)**2+cos(x)**2, 1)
Q.eq(sin(x)**2 + cos(x)**2, 1)
>>> ask(_)
True

You can define a new binary relation by subclassing and dispatching.
Here, we define a relation $R$ such that $x R y$ returns true if
$x = y + 1$.

>>> from sympy import ask, Number, Q
>>> from sympy.assumptions import BinaryRelation
>>> class MyRel(BinaryRelation):
...     name = "R"
...     is_reflexive = False
>>> Q.R = MyRel()
>>> @Q.R.register(Number, Number)
... def _(n1, n2, assumptions):
...     return ask(Q.zero(n1 - n2 - 1), assumptions)
>>> Q.R(2, 1)
Q.R(2, 1)

Now, we can use ``ask()`` to evaluate it to boolean value.

>>> ask(Q.R(2, 1))
True
>>> ask(Q.R(1, 2))
False

``Q.R`` returns ``False`` with minimum cost if two arguments have same
structure because it is antireflexive relation [1] by
``is_reflexive = False``.

>>> ask(Q.R(x, x))
False

References
==========

.. [1] https://en.wikipedia.org/wiki/Reflexive_relation
Nis_reflexiveis_symmetricc                 f    [        U5      S:X  d  [        S[        U5      -  5      e[        U /UQ76 $ )N   z0Binary relation takes two arguments, but got %s.)len
ValueErrorr   )selfargss     Y/var/www/auris/envauris/lib/python3.13/site-packages/sympy/assumptions/relation/binrel.py__call__BinaryRelation.__call__P   s5    4yA~ORUVZR[[\\$T1D11    c                 *    U R                   (       a  U $ g N)r   r   s    r   reversedBinaryRelation.reversedU   s    Kr!   c                     g r#    r$   s    r   negatedBinaryRelation.negated[   s    r!   c                     U[         R                  L d  U[         R                  L a  g U R                  nUc   g U(       a  X:X  a  gU(       d  X:X  a  gg )NTF)r   NaNr   )r   lhsrhs	reflexives       r   _compare_reflexive!BinaryRelation._compare_reflexive_   sN     !%%<3!%%<%%	
 	 CJ
r!   c                 F   U R                   " U6 nUb  U$ Uu  pEU R                  XEUS9nUb  U$ U R                  (       ab  [        U5      [        U5      4nU R                  R                  " U6 U R                  R                  " [        U5      6 La  U R                  XTUS9nU$ )N)assumptions)r0   handlerr   typedispatchr%   )r   r   r3   retr-   r.   typess          r   evalBinaryRelation.evalq   s    %%t,?J ll3l=?J #YS	*E||$$e,DLL4I4I8TY?4[[ll3lE
r!   r(   )T)__name__
__module____qualname____firstlineno____doc__r   r   bool__annotations__r   r   propertyr%   r)   r0   r9   __static_attributes__r(   r!   r   r   r      s]    ;z $(L(4.'#'L(4.'2
  
  $r!   c                   t    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
S rS	 rS
rg)r      zX
The class of expressions resulting from applying ``BinaryRelation``
to the arguments.

c                      U R                   S   $ )z#The left-hand side of the relation.r   	argumentsr$   s    r   r-   AppliedBinaryRelation.lhs        ~~a  r!   c                      U R                   S   $ )z$The right-hand side of the relation.   rG   r$   s    r   r.   AppliedBinaryRelation.rhs   rJ   r!   c                 r    U R                   R                  nUc  U $ U" U R                  U R                  5      $ )z5
Try to return the relationship with sides reversed.
)functionr%   r.   r-   r   revfuncs     r   r%   AppliedBinaryRelation.reversed   s2    
 --((?Ktxx**r!   c                     U R                   R                  nUc  U $ [        S U R                   5       5      (       d  U" U R                  * U R
                  * 5      $ U $ )z5
Try to return the relationship with signs reversed.
c              3   D   #    U  H  oR                   [        L v   M     g 7fr#   )kindr	   ).0sides     r   	<genexpr>5AppliedBinaryRelation.reversedsign.<locals>.<genexpr>   s     G99+s    )rO   r%   anyrH   r-   r.   rP   s     r   reversedsign"AppliedBinaryRelation.reversedsign   sP    
 --((?KGGGGDHH9txxi00r!   c                 f    U R                   R                  nUc
  [        U SS9$ U" U R                  6 $ )NFevaluate)rO   r)   r   rH   )r   neg_rels     r   r)   AppliedBinaryRelation.negated   s2    --''?te,,''r!   c                   ^ [        5       m[        [        R                  [        [        R
                  [        [        R                  [        [        R                  [        [        R                  [        [        R                  0n[        U5       HP  nUR                  U;   a,  TR!                  U[#        U5         " UR$                  6 5        M?  TR!                  U5        MR     ['        U4S jX R(                  4 5       5      (       a  gU R*                  U R(                  R*                  [-        U SS9[-        U R(                  SS94n['        U4S jU 5       5      (       a  gU R.                  R1                  U R2                  U5      nUb  U$ [5        S U R2                   5       5      nU R.                  R1                  Xa5      $ )Nc              3   ,   >#    U  H	  oT;   v   M     g 7fr#   r(   rV   relconj_assumpss     r   rX   2AppliedBinaryRelation._eval_ask.<locals>.<genexpr>   s     D.Csl".C   TFr^   c              3   ,   >#    U  H	  oT;   v   M     g 7fr#   r(   rd   s     r   rX   rg      s     7hsl"hrh   c              3   @   #    U  H  oR                  5       v   M     g 7fr#   )simplify)rV   as     r   rX   rg      s     :>aZZ\\>s   )setr
   r   eqr   ner   gtr   ltr   ger   ler   funcaddr5   r   rZ   r%   r)   r   rO   r9   rH   tuple)r   r3   binrelpredsrl   neg_relsr7   r   rf   s          @r   	_eval_askAppliedBinaryRelation._eval_ask   s<   u144QTT2qttRr144QTTR;'Avv$  T!W!5qvv!>?  #	 ( Dt]].CDDDLL$--"7"7TE9R.07h777 mm  =?J :4>>::}}!!$44r!   c                 >    [        U 5      nUc  [        SU -  5      eU$ )Nz"Cannot determine truth value of %s)r   	TypeError)r   r7   s     r   __bool__AppliedBinaryRelation.__bool__   s&    $i;@4GHH
r!   r(   N)r;   r<   r=   r>   r?   rB   r-   r.   r%   r[   r)   ry   r}   rC   r(   r!   r   r   r      su     ! ! ! ! + + 	 	 ( (56r!   N)r?   typingr   sympy.core.singletonr   sympy.assumptionsr   r   r   r   sympy.core.kindr	   sympy.core.relationalr
   r   r   r   r   r   sympy.logic.boolalgr   r   __all__r   r   r(   r!   r   <module>r      sM     " A A ' 8 8 .4
5uY upM, Mr!   