
    \h                        S SK JrJrJrJrJr  S SKJrJr  S SK	J
r
  S SK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Jr  S SKJr  S SKJrJr  S S	KJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)  S S
K*J+r+J,r,J-r-  S SK.J/r/J0r0  S SK1J2r2  \Rf                  r4 " S S\5      r5 " S S\
5      r6SS jr7S r8S r9S r:S r;S r<S r=S r>SSS.S jr?g)    )SdiffTupleDummyMul)Basicas_Basic)DefinedFunction)RationalNumberSymbol_illegal)global_parameters)LtGtEqNe
Relational
_canonical_canonical_coeff)ordered)MaxMin)AndBooleandistribute_and_over_orNottruefalseOrITEsimplify_logicto_cnfdistribute_or_over_and)uniqsiftcommon_prefix)
filldedent	func_name)productc                   Z    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	S r
S rS	rg
)ExprCondPair   z)Represents an expression, condition pair.c                    [        U5      nUS:X  a  [        R                  " X[        5      $ US:X  a  [        R                  " X[        5      $ [        U[        5      (       aO  UR                  [        5      (       a5  [        U5      n[        U[        5      (       a  UR                  [        5      n[        U[        5      (       d   [        [        S[        U5      -  5      5      e[        R                  " XU5      $ )NTFzL
                Second argument must be a Boolean,
                not `%s`)r	   r   __new__r   r   
isinstancer   has	Piecewisepiecewise_foldrewriter    r   	TypeErrorr'   r(   )clsexprconds      \/var/www/auris/envauris/lib/python3.13/site-packages/sympy/functions/elementary/piecewise.pyr.   ExprCondPair.__new__   s    ~4<==D11U]==E22e$$))<)<!$'D$	**||C($((J ('o(. / 0 0 }}S--    c                      U R                   S   $ )z&
Returns the expression of this pair.
r   argsselfs    r8   r6   ExprCondPair.expr'       
 yy|r:   c                      U R                   S   $ )z%
Returns the condition of this pair.
   r<   r>   s    r8   r7   ExprCondPair.cond.   rA   r:   c                 .    U R                   R                  $ N)r6   is_commutativer>   s    r8   rG   ExprCondPair.is_commutative5   s    yy'''r:   c              #   D   #    U R                   v   U R                  v   g 7frF   )r6   r7   r>   s    r8   __iter__ExprCondPair.__iter__9   s     iiiis    c           
      ~    U R                   " U R                   Vs/ s H  o"R                  " S0 UD6PM     sn6 $ s  snf )N )funcr=   simplify)r?   kwargsas      r8   _eval_simplifyExprCondPair._eval_simplify=   s1    yyCA:://CDDCs   :rM   N)__name__
__module____qualname____firstlineno____doc__r.   propertyr6   r7   rG   rJ   rR   __static_attributes__rM   r:   r8   r+   r+      sQ    3."     ( (Er:   r+   c                   d  ^  \ rS rSrSrSrSrS r\S 5       r	S r
S rS	 rS
 rS rS rS rS rS rS rS3S jrS3U 4S jjrS4S jrS5S jrS rS rS rS rS rS rS rS rS r S r!S r"S  r#S! r$S" r%S# r&S$ r'S% r(S& r)S' r*S( r+S) r,S* r-S+ r.S, r/S- r0\S. 5       r1S6S/ jr2S0 r3S1 r4S2r5U =r6$ )7r1   A   a  
Represents a piecewise function.

Usage:

  Piecewise( (expr,cond), (expr,cond), ... )
    - Each argument is a 2-tuple defining an expression and condition
    - The conds are evaluated in turn returning the first that is True.
      If any of the evaluated conds are not explicitly False,
      e.g. ``x < 1``, the function is returned in symbolic form.
    - If the function is evaluated at a place where all conditions are False,
      nan will be returned.
    - Pairs where the cond is explicitly False, will be removed and no pair
      appearing after a True condition will ever be retained. If a single
      pair with a True condition remains, it will be returned, even when
      evaluation is False.

Examples
========

>>> from sympy import Piecewise, log, piecewise_fold
>>> from sympy.abc import x, y
>>> f = x**2
>>> g = log(x)
>>> p = Piecewise((0, x < -1), (f, x <= 1), (g, True))
>>> p.subs(x,1)
1
>>> p.subs(x,5)
log(5)

Booleans can contain Piecewise elements:

>>> cond = (x < y).subs(x, Piecewise((2, x < 0), (3, True))); cond
Piecewise((2, x < 0), (3, True)) < y

The folded version of this results in a Piecewise whose
expressions are Booleans:

>>> folded_cond = piecewise_fold(cond); folded_cond
Piecewise((2 < y, x < 0), (3 < y, True))

When a Boolean containing Piecewise (like cond) or a Piecewise
with Boolean expressions (like folded_cond) is used as a condition,
it is converted to an equivalent :class:`~.ITE` object:

>>> Piecewise((1, folded_cond))
Piecewise((1, ITE(x < 0, y > 2, y > 3)))

When a condition is an ``ITE``, it will be converted to a simplified
Boolean expression:

>>> piecewise_fold(_)
Piecewise((1, ((x >= 0) | (y > 2)) & ((y > 3) | (x < 0))))

See Also
========

piecewise_fold
piecewise_exclusive
ITE
NTc                    [        U5      S:X  a  [        S5      e/ nU HI  n[        [        USU5      6 nUR                  nU[
        L a  M-  UR                  U5        U[        L d  MI    O   UR                  S[        R                  5      nU(       a  U R                  " U6 nUb  U$ O1[        U5      S:X  a"  US   R                  S:X  a  US   R                  $ [        R                  " U /UQ70 UD6$ )Nr   z(At least one (expr, cond) pair expected.r=   evaluaterC   T)lenr4   r+   getattrr7   r   appendr   popr   r^   evalr6   r   r.   )	r5   r=   optionsnewargsecpairr7   rc   rs	            r8   r.   Piecewise.__new__   s    t9>FGGBVR!89D99Du}NN4 t|  {{:'8'A'AB'"A} \Q71:??d#:1:??"}}S676g66r:   c                 :   U(       d  [         $ [        U5      S:X  a  US   S   S:X  a  US   S   $ [        U5      n[        U5      [        U5      :g  n[        S [	        X!5       5       5      nU(       d  [        [        S5      5      eU(       d  U(       d  U " U6 $ g)a  Either return a modified version of the args or, if no
modifications were made, return None.

Modifications that are made here:

1. relationals are made canonical
2. any False conditions are dropped
3. any repeat of a previous condition is ignored
4. any args past one with a true condition are dropped

If there are no args left, nan will be returned.
If there is a single arg with a True condition, its
corresponding expression will be returned.

EXAMPLES
========

>>> from sympy import Piecewise
>>> from sympy.abc import x
>>> cond = -x < -1
>>> args = [(1, cond), (4, cond), (3, False), (2, True), (5, x < 1)]
>>> Piecewise(*args, evaluate=False)
Piecewise((1, -x < -1), (4, -x < -1), (2, True))
>>> Piecewise(*args)
Piecewise((1, x > 1), (2, True))
rC   r   Tc              3   .   #    U  H  u  pX:H  v   M     g 7frF   rM   ).0rQ   bs      r8   	<genexpr>!Piecewise.eval.<locals>.<genexpr>   s     :&9da16&9s   z
                There are no conditions (or none that
                are not trivially false) to define an
                expression.N)	Undefinedr_   _piecewise_collapse_argumentsallzip
ValueErrorr'   )r5   _argsre   missingsames        r8   rc   Piecewise.eval   s    8 u:?uQx|t38A;/6 g,#e*,:c'&9:: Z )   ! ! $=  r:   c                 J   / nU R                    H  u  p4UR                  SS5      (       aU  [        U[        5      (       a  UR                  " S0 UD6nXP:w  a  Un[        U[        5      (       a  UR                  " S0 UD6nUR                  X445        M     U R                  " U6 $ )z#
Evaluate this piecewise function.
deepTrM   )r=   getr/   r   doitra   rN   )r?   hintsre   ecnewes         r8   r}   Piecewise.doit   s     IIDAyy&&a''66?E?D| a''ANNA6"  yy'""r:   c                     [        U 40 UD6$ rF   )piecewise_simplify)r?   rP   s     r8   rR   Piecewise._eval_simplify   s    !$1&11r:   c                     U R                    H4  u  pEUS:X  d  UR                  US5      S:X  d  M#  UR                  U5      s  $    g )NTr   )r=   subsas_leading_term)r?   xlogxcdirr   r   s         r8   _eval_as_leading_termPiecewise._eval_as_leading_term   s;    IIDADyAFF1aLD0((++ r:   c                     U R                   " U R                   VVs/ s H  u  pUR                  5       U4PM     snn6 $ s  snnf rF   )rN   r=   adjointr?   r   r   s      r8   _eval_adjointPiecewise._eval_adjoint   s4    yy		B	AIIK+	BCCB   ?
c                     U R                   " U R                   VVs/ s H  u  pUR                  5       U4PM     snn6 $ s  snnf rF   )rN   r=   	conjugater   s      r8   _eval_conjugatePiecewise._eval_conjugate   4    yy$))D)$!AKKM1-)DEEDr   c           
          U R                   " U R                   VVs/ s H  u  p#[        X!5      U4PM     snn6 $ s  snnf rF   )rN   r=   r   )r?   r   r   r   s       r8   _eval_derivativePiecewise._eval_derivative   s1    yytyyAytqDJ?yABBAs   :
c           	          U R                   " U R                   VVs/ s H  u  p#UR                  U5      U4PM     snn6 $ s  snnf rF   )rN   r=   _evalf)r?   precr   r   s       r8   _eval_evalfPiecewise._eval_evalf   s6    yy499E941AHHTNA.9EFFEs   A 
c                    UR                   (       d  g U R                   Hb  u  p4UR                  X5      nUR                  (       a    g X$R	                  5       R
                  ;   a    g U(       d  MQ  UR                  X5      s  $    g rF   )is_realr=   r   is_Relationalas_setboundary_eval_is_meromorphic)r?   r   rQ   r   r   r7   s         r8   r   Piecewise._eval_is_meromorphic   sd     yy IIDA66!<D!!HHJ'''t--a33 r:   c                     SSK Jn  U R                  " U R                   VVs/ s H  u  pEU" XA40 UD6U4PM     snn6 $ s  snnf )a+  Return the Piecewise with each expression being
replaced with its antiderivative. To obtain a continuous
antiderivative, use the :func:`~.integrate` function or method.

Examples
========

>>> from sympy import Piecewise
>>> from sympy.abc import x
>>> p = Piecewise((0, x < 0), (1, x < 1), (2, True))
>>> p.piecewise_integrate(x)
Piecewise((0, x < 0), (x, x < 1), (2*x, True))

Note that this does not give a continuous function, e.g.
at x = 1 the 3rd condition applies and the antiderivative
there is 2*x so the value of the antiderivative is 2:

>>> anti = _
>>> anti.subs(x, 1)
2

The continuous derivative accounts for the integral *up to*
the point of interest, however:

>>> p.integrate(x)
Piecewise((0, x < 0), (x, x < 1), (2*x - 1, True))
>>> _.subs(x, 1)
1

See Also
========
Piecewise._eval_integral
r   	integrate)sympy.integralsr   rN   r=   )r?   r   rP   r   r   r   s         r8   piecewise_integratePiecewise.piecewise_integrate  s>    D 	.yydiiPidaIa5f5q9iPQQPs   >
c                    U R                  [        5      n[        [        U Vs/ s H<  oAUR                  ;  d  M  U[
        R                  [
        R                  4;  d  M:  UPM>     sn5      5      nU(       Ga  0 n/ n[        S[        U5      S9 GHC  n[        [        XX5      5      n	SU;  a  Sn
O|[        U	 Vs/ s H  oU   (       d  M  UPM     sn6 n[        UR                  5      n[        U5      S:X  a  SSKJnJn   U" XS   5      nO[%        U6 nU[
        R                  L a  M  Un
U" U R'                  U	5      5      n[)        UU R*                  5      (       a<  [        UR,                  5      S:X  a#  UR,                  S   u  nn[%        UU
c  SOU
5      n
U
c  GM  UR/                  U/ 5      R1                  U
5        UR1                  U5        GMF     U H  n[3        UU   6 UU'   M     [5        U5       Vs/ s H
  nUUU   4PM     nnUR1                  WS45        [7        U6 $ gs  snf s  snf ! [         ["        4 a,    [%        U Vs/ s H  nU" UUS   SS9PM     Os  snf sn6 n GNZf = fs  snf )	a'  Return either None (if the conditions of self depend only on x) else
a Piecewise expression whose expressions (handled by the handler that
was passed) are paired with the governing x-independent relationals,
e.g. Piecewise((A, a(x) & b(y)), (B, c(x) | c(y)) ->
Piecewise(
    (handler(Piecewise((A, a(x) & True), (B, c(x) | True)), b(y) & c(y)),
    (handler(Piecewise((A, a(x) & True), (B, c(x) | False)), b(y)),
    (handler(Piecewise((A, a(x) & False), (B, c(x) | True)), c(y)),
    (handler(Piecewise((A, a(x) & False), (B, c(x) | False)), True))
)rC   r   )repeatrC   Nr   )reduce_inequalities_solve_inequalityT)linear)atomsr   listr   free_symbolsr   r   r   r)   r_   dictrt   r   sympy.solvers.inequalitiesr   r   ru   NotImplementedErrorr   xreplacer/   rN   r=   
setdefaultra   r   r$   r1   )r?   r   handlerrelrh   irelr=   exprinordertruthrepsr7   iandargsfreer   r   trQ   r6   econdkr   s                         r8   _handle_irelPiecewise._handle_irel*  sP    jj$G ,1/FQ!&&!''**  , - .DK D	:C,- E>D#%AAaa%ABG 4 45D4yA~D3 3G!W EA  MAGG| Dt}}T23dDII..3tyy>Q3F"&))A,KD%udldED
 #OOD"-44T:  &&t,O ;R d1g,Q  +/{*;<*;QQQL*;D<KKt%d##e , &B !+,?@ 3 #)0&2)0A '8 !474'9)0&2 !3A38 =s@   H,"H,!H,;H1
H1
H6=I56I2I%$
I21I2c           	        ^ ^^ SSK Jn  U(       a  UU U4S jnT R                  TU5      nUb  U$ T R                  T5      u  pxU(       d  SSK Jn	  U	" T T5      $ U V
VVs/ s H
  u  p  oU4PM     nnn
n[
        R                  nU* US4/n[        U5       H  u  nnUU* U4:X  a)  [        U5       H  u  nu  pnUS:X  d  M  XU4UU'   M       OT[        U5      S-
  n[        [        U5      5       H*  u  nu  pnUS:X  d  M  UU-
  n[        UX4U5      UUUS-   & M,     M     U V
VVs/ s H  u  pnX:w  d  M  XU4PM     nnn
n[        S U 5       5      (       a  UR                  U* U[        S45        / nSnU H  u  pnU" UU   S	   T40 TD6nUc  UnO]UR                  TU
5      nUR                  TU
T5      nUR                   " ["        6 (       d  UR                   " ["        6 (       a  UnOUU-  nU[
        R                  L a  S
nO>T R$                  UU   S      R&                  R                  TU5      S:X  a  TU:  nOTU:*  nUR                  UU45        M     [)        U6 $ s  snnn
f s  snnn
f )ak  Return the indefinite integral of the
Piecewise such that subsequent substitution of x with a
value will give the value of the integral (not including
the constant of integration) up to that point. To only
integrate the individual parts of Piecewise, use the
``piecewise_integrate`` method.

Examples
========

>>> from sympy import Piecewise
>>> from sympy.abc import x
>>> p = Piecewise((0, x < 0), (1, x < 1), (2, True))
>>> p.integrate(x)
Piecewise((0, x < 0), (x, x < 1), (2*x - 1, True))
>>> p.piecewise_integrate(x)
Piecewise((0, x < 0), (x, x < 1), (2*x, True))

See Also
========
Piecewise.piecewise_integrate
r   r   c                    > [        U TR                  5      (       a  U R                  " T4SS0TD6$ U R                  " T40 TD6$ )N_firstF)r/   rN   _eval_integralr   )ipwrP   r?   r   s    r8   r   )Piecewise._eval_integral.<locals>.handler  sC    c499----aHHHH==5f55r:   NIntegralrk   rC   c              3   0   #    U  H  u  po3S :H  v   M     g7f)rk   NrM   )rm   rQ   rn   r   s       r8   ro   +Piecewise._eval_integral.<locals>.<genexpr>  s     -9A!Bw   TF)sympy.integrals.integralsr   r   
_intervalsr   r   Infinity	enumerater_   reversed_clipanyra   rq   r   _eval_intervalr0   r   r=   r7   r1   )r?   r   r   rP   r   r   irvokabeir   rQ   rn   _piecesoodoner   pjr   Nr=   sumantir   r7   s   `` `                      r8   r   Piecewise._eval_integralm  ss   . 	86
 ##Aw/C
 ??1%:D!$$+/04ZQ1aa&40ZZb"f%DAqbS"I~$-dOLAyaBw"#'Q %4 D	AA )(4. 99A!7AA%*1qfa%8DAEN !: & *.8gaA	q	8 ----KK"b)R01 GA!T!WR[!6v6D{hhq!n''1a077H%)9C1HC AJJ472;',,11!Q75@AQKKd$' ( $[ 1 9s   I'(I.8I.c           	      	  >^ ^^^ Ub  Uc  [         T T ]  XU5      $ [        [        XU45      u  mmmU(       Ga  UUU U4S jnT R	                  TU5      nUb  U$ TT:  [
        R                  L d&  T[
        R                  L d  T[
        R                  L aX  T R                  TTTSS9n[        U[        5      (       a,  [        UR                   VV	s/ s H
  u  pU* U	4PM     sn	n6 nU$ U* nU$ TT:  [
        R                  L d&  T[
        R                  L d  T[
        R                  L a  GO[        S5      n
[        S5      nTR                  (       a  TOU
nTR                  (       a  TOUnT R                  TX#SS9nX*:X  a0  X;:X  a+  UR                  U
TUT05      * UR                  U
TUT05      pO'T R                  TTTSS9* UR                  U
TUT05      p[        SSS	9nTR                   (       aU  UR                  TTU-
  05      R                  UTT-
  05      nUR                  TTU-   05      R                  UTT-
  05      nOeTR                   (       aT  UR                  TTU-   05      R                  UTT-
  05      nUR                  TTU-
  05      R                  UTT-
  05      nS
 nU" U5      nU" U5      nX*:X  a  [        UTT:  4US45      nO[        UTT:  4US45      nU["        :X  a  [%        S5      e['        S X4 5       5      (       a  [)        U5      nU$ T R+                  T5      u  nnU(       d!  SSKJn  U" T R1                  T5      TTT45      $ U VVVs/ s H
  u  p#  nX#4PM     nnnnTTS4/n[
        R                  n[3        U5       H  u  nnUSS U* U4:X  a)  [3        U5       H  u  nu  p#nUS:X  d  M  X#U4UU'   M       OT[5        U5      S-
  n[3        [7        U5      5       H*  u  nu  p#nUS:X  d  M  UU-
  n[9        XU4U5      UUUS-   & M,     M     U VVVs/ s H  u  p#nX#:w  d  M  X#U4PM     nnnn[
        R:                  nSnU HM  u  p#nUS:X  a$  Uc  ["        s  $ [        UTU:*  4["        S45      s  $ UUU   S   R                  TX#5      -  nUnMO     U$ s  sn	nf s  snnnf s  snnnf )z?Evaluates the function along the sym in a given interval [a, b]Nc                    > [        U TR                  5      (       a  U R                  TTTS S9$ U R                  TTT5      $ )Nr   )r/   rN   r   )r   hilor?   r   s    r8   r   )Piecewise._eval_interval.<locals>.handler  sC    c499----aR-EE--aR88r:   Fr   r   r    T)positivec                 *    U R                  S S 5      $ )Nc                 .    [        U [        [        45      $ rF   )r/   r   r   r   s    r8   <lambda><Piecewise._eval_interval.<locals>.<lambda>.<locals>.<lambda>  s    jS#J7r:   c                 4    U R                   " U R                  6 $ rF   rN   r=   r   s    r8   r   r     s    affaffor:   )replacer   s    r8   r   *Piecewise._eval_interval.<locals>.<lambda>  s    !))7-#/r:   z(Can't integrate across undefined region.c              3   B   #    U  H  n[        U[        5      v   M     g 7frF   )r/   r1   )rm   r   s     r8   ro   +Piecewise._eval_interval.<locals>.<genexpr>  s     DAz!Y//s   r   r   rk      rC   r   )superr   mapr	   r   r   r   r   NegativeInfinityr/   r1   r=   r   r   is_comparabler   	is_Symbolrq   ru   r   r2   r   r   r   r   r   r_   r   r   Zero)!r?   symrQ   rn   r   r   r   rvr   r   _a_bposnegr   touchr   r   r   r   r   r   r   r   r   r   r   r   uptor   r   r   	__class__s!   `                            @@@r8   r   Piecewise._eval_interval  s    9	7)#!44Hsqk2IAr29 9
 ##Aw/C
RAGG#!**$a.@.@(@((B5(Ab),,"$Aqb!W$ABB 	 B	RAFF"!**$a.@.@(@4[4[**B**B))!Q%)@7qw "%r2r2.>!? ?b"b"%56  "&!4!4QBu!4!M Mb"b"%56  "t,<<,,BF|4==q"r'lKC,,BF|4==q"r'lKC\\,,BF|4==q"r'lKC,,BF|4==q"r'lKC/ CjCj 7"G% "#B #G% "#B ?$%OPPD#DDD'+B	 ??1%D: DIIaL1b"+66+/04ZQ1a1&40R~ZZf%DAq!u"b	!$-dOLAyaBw"#'Q %4 D	AA )(4. 99A!7AA%*1!fa%8DAEN !: & *.8gaA	q	8 ffGA!Bw<$$ #rTz!2Y4EFF472;--a66CD  
I %BP 1 9s   R7
)R=4SSc                 
  ^^^ SSK Jm  [        U [        5      (       d   eU4S jmUUU4S jn[	        U R
                  5      nU R                  [        5      n0 nU H  nU" U5      u  pUS:w  a  SU4s  $ XU'   M     U R
                   V
s/ s H  oR                  U5      PM     nn
/ nS=p[        U5       GH'  u  n
u  pU[        R                  L a  M  U[        R                  L a  UnU
n  O[        U[        5      (       a  U(       a	  SSU-  4s  $ M^  [        U5      n[        U[        5      (       a  [!        U5      n[        U["        5      (       aG  UR%                  UR
                   Vs/ s H  n[        U[        5      (       a  M  XU4PM      sn5        M  U[        R                  La  UR'                  XU45        GM  U[        R                  L d  GM$  UnU
n  O   / nU GH  u  np[        U[        5      (       Ga  [        R(                  n[        R*                  n/ nUR
                   H  n[        U[        5      (       d      g	[        U[        5      (       a  UnU(       a      g
  O[        U[,        5      (       aM  UR
                  u  nnUT:X  a  UR'                  U5        O$UT:X  a  UR'                  U5        OT" U5      s  s  $ M  UR.                  T:X  a  [1        UR2                  U5      nM  UR2                  T:X  a  [5        UR.                  U5      nM  T" U5      s  s  $    U(       a  [	        [7        U5      5      n/ n[        U5       HZ  u  n
nUUs=:  a  S:X  d  O  UUs=:  a  S:X  a  O  OM'  U(       d  UR'                  SU45        UR'                  US   S   U45        M\     UR'                  US   S   U45        UR9                  S5        UR%                  U V
s/ s H  n
UU[        U
S   T:  TU
S   :  5      4PM      sn
5        GM7  O[        U[        5      (       at  UR:                  S:w  ad  UR.                  UR2                  nnUR.                  T:X  a  [        R(                  nO4UR2                  T:X  a  [        R*                  nOT" U5      s  $ SSU-  4s  $ [5        UU5      nU(       a  UU:X  a    gUU:  [        R                  Ld  GM  UR'                  UUUU45        GM     Ub0  UR'                  [        R(                  [        R*                  X45        S[	        [=        U5      5      4$ s  sn
f s  snf s  sn
f )a  Return a bool and a message (when bool is False), else a
list of unique tuples, (a, b, e, i), where a and b
are the lower and upper bounds in which the expression e of
argument i in self is defined and $a < b$ (when involving
numbers) or $a \le b$ when involving symbols.

If there are any relationals not involving sym, or any
relational cannot be solved for sym, the bool will be False
a message be given as the second return value. The calling
routine should have removed such relationals before calling
this routine.

The evaluated conditions will be returned as ranges.
Discontinuous ranges will be returned separately with
identical expressions. The first condition that evaluates to
True will be returned as the last tuple with a, b = -oo, oo.
r   )r   c                 .   > S[        ST< SU < 35      4$ )NFz;
                A condition not involving
                z appeared: )r'   )r7   r  s    r8   
nonsymfail(Piecewise._intervals.<locals>.nonsymfail^  s!    *&)4&1 2 2 2r:   c                   > TU R                   ;  a  T" U 5      $  T" U T5      n[        U[        5      (       a  UR                  S   R                   nUR                  S   T:w  d  TU;   a  SSU < ST< S34$ UR
                  S:X  a  [        R                  nS	U4$ UR
                  S:X  a+   [        TUR                  :  TUR                  :  5      nS	U4$  S	U4$ U[        R                  T:  T[        R                  :  -  :X  a  [        R                  nS	U4$ ! [         a    SSU < ST< S34s $ f = f! [         a    [        R                  n S	U4$ f = f)
NFzUnable to solve relational z for .rC   r   z==!=T)r   r   r/   r   r=   rel_opr   r   r   rhsr4   r   r  r   )rh   r  r   r   r  r  s      r8   _solve_relational/Piecewise._intervals.<locals>._solve_relationalc  s\   !..(!!}$Q&q#. "j))wwqz..771:$t QPS"TTT99$ B 8O YY$&$bffcBFFl; 8O ' 8O **S0S1::5EFFVV8O+ ' QCPPPQ  % $VV 8O$s#   	D -&D8 D54D58EETFNzencountered Eq condition: %s)Fzexpecting only Relationals)Fz"encountered secondary Eq conditionrk   rC   r  zunrecognized condition: %s)Fzencountered Eq condition)r   r   r/   r1   r   r=   r   r   r   r   r   r   r   r   r"   r   r#   r   extendra   r  r   r   ltsr   gtsr   r   rb   r  r$   )r?   r  	err_on_Eqr  r=   keysr   rh   r   sr   	expr_conddefaultidefaultr6   r7   oint_expriarglowerupperexcludecond2lnewcondr   r   r  s    `                        @@r8   r   Piecewise._intervalsH  s   $ 	A$	****	2
	8 DIIzz*%A%a(EBTzby G	  +/))4)Q

4 )4 	!!(OA|qwwqvv~$##  "@4"GGG$<D$$$-d3$##  +/99 .9a%a, "aq\9 ./ QWW$  !417  /<  )D$$$$**

!YYE%eZ88B!%,, %$#N#E2..$zz18#NN1-#X#NN1-#-e#44 c) #EIIu 5c) #EIIu 5)%00- '. "77#34G G )' 21u,,E0AT0A$&#NND%=9A':; !3 NNGBKNE#:;KKN$$Y`%aY`TUtT3qtcz31:3N&OY`%ab  D*--$++2E#xxu88s?..EXX_JJE%d++:TAAAu%EUe^8qvv-tT :;q !*t OO##QZZCE T$x.)))E 52.d &bs   U	/U
U
0%U
c                     U R                    Vs/ s H*  oUR                  R                  XU5      UR                  4PM,     nnU R                  " U6 $ s  snf rF   )r=   r6   _eval_nseriesr7   rN   )r?   r   nr   r   rf   r=   s          r8   r.  Piecewise._eval_nseries  sG    GKyyQy&&qT2BGG<yQyy$ Rs   1Ac                 r    U R                   " U R                   VVs/ s H  u  p#X!-  U4PM     snn6 $ s  snnf rF   r   )r?   r  r   r   s       r8   _eval_powerPiecewise._eval_power  s/    yy;AD!9;<<;s   3
c                 
   [        U R                  5      nSn[        U5       H?  u  nu  pgUR                  X5      nUS:w  a  SnUR                  X5      nXg4X5'   US:X  d  M?    O   U(       d	  [        S44nU R
                  " U6 $ )NFT)r   r=   r   _subsrq   rN   )r?   oldnewr=   
args_existr   r   r   s           r8   
_eval_subsPiecewise._eval_subs  s     DII
"4IAv!AEz!
GGC%fDGDy ) %'Dyy$r:   c                     U R                   " U R                   VVs/ s H  u  pUR                  5       U4PM     snn6 $ s  snnf rF   )rN   r=   	transposer   s      r8   _eval_transposePiecewise._eval_transpose	  r   r   c                 n    S nU R                    H"  u  p4[        X15      nUc    g Uc  UnM  X%Ld  M"    g    U$ rF   )r=   r`   )r?   is_attrrn   r6   r   rQ   s         r8   _eval_template_is_attr Piecewise._eval_template_is_attr  sB    yyGD&Ayy ! r:   c                 $    U R                  S5      $ )N	is_finiterA  r>   s    r8   r   Piecewise.<lambda>  s    4#>#>$r:   c                 $    U R                  S5      $ )N
is_complexrE  r>   s    r8   r   rF        D$?$?$Mr:   c                 $    U R                  S5      $ )Nis_evenrE  r>   s    r8   r   rF        !<!<Y!Gr:   c                 $    U R                  S5      $ )Nis_imaginaryrE  r>   s    r8   r   rF    s    d&A&A'r:   c                 $    U R                  S5      $ )N
is_integerrE  r>   s    r8   r   rF    rI  r:   c                 $    U R                  S5      $ )Nis_irrationalrE  r>   s    r8   r   rF    s    t'B'B(r:   c                 $    U R                  S5      $ )Nis_negativerE  r>   s    r8   r   rF  !      T%@%@%Or:   c                 $    U R                  S5      $ )Nis_nonnegativerE  r>   s    r8   r   rF  "      (C(C)r:   c                 $    U R                  S5      $ )Nis_nonpositiverE  r>   s    r8   r   rF  $  rX  r:   c                 $    U R                  S5      $ )N
is_nonzerorE  r>   s    r8   r   rF  &  s    D$?$?%r:   c                 $    U R                  S5      $ )Nis_oddrE  r>   s    r8   r   rF  (  s     ; ;H Er:   c                 $    U R                  S5      $ )Nis_polarrE  r>   s    r8   r   rF  )  s    $"="=j"Ir:   c                 $    U R                  S5      $ )Nis_positiverE  r>   s    r8   r   rF  *  rU  r:   c                 $    U R                  S5      $ )Nis_extended_realrE  r>   s    r8   r   rF  +  s    $*E*E+ r:   c                 $    U R                  S5      $ )Nis_extended_positiverE  r>   s    r8   r   rF  -      d.I.I"/$r:   c                 $    U R                  S5      $ )Nis_extended_negativerE  r>   s    r8   r   rF  /  rg  r:   c                 $    U R                  S5      $ )Nis_extended_nonzerorE  r>   s    r8   r   rF  1  s    T-H-H!.#r:   c                 $    U R                  S5      $ )Nis_extended_nonpositiverE  r>   s    r8   r   rF  3      1L1L%2'r:   c                 $    U R                  S5      $ )Nis_extended_nonnegativerE  r>   s    r8   r   rF  5  rn  r:   c                 $    U R                  S5      $ )Nr   rE  r>   s    r8   r   rF  7  rL  r:   c                 $    U R                  S5      $ )Nis_zerorE  r>   s    r8   r   rF  8  s    !<!<"r:   c                     US:X  a  g[        U[        5      (       a8   UR                  UR                  -
  nUR                  (       a  UR
                  $ gg! [         a     gf = f)z(Return the truth value of the condition.TN)r/   r   lhsr  rG   rs  r4   )r5   r7   r   s      r8   __eval_condPiecewise.__eval_cond;  sc     4<dBxx$((*&&<<' '  
  s   5A 
A#"A#c                 V   Uc  [         R                  n/ nUnUR                  [         R                  5      (       + n[        5       nU R                   H  u  pgXWR
                  -  n[        U5      S:  a  [        [        S5      5      eU(       aK  UR                  [        5       H2  n[        U[        [        45      (       a  M   [        [        S5      5      e   UR                  UR!                  5       5      n	X9-
  nU	[         R"                  :w  d  M  UR%                  Xi45        M     U$ )a  Return tuples for each argument of self that give
the expression and the interval in which it is valid
which is contained within the given domain.
If a condition cannot be converted to a set, an error
will be raised. The variable of the conditions is
assumed to be real; sets of real values are returned.

Examples
========

>>> from sympy import Piecewise, Interval
>>> from sympy.abc import x
>>> p = Piecewise(
...     (1, x < 2),
...     (2,(x > 0) & (x < 4)),
...     (3, True))
>>> p.as_expr_set_pairs()
[(1, Interval.open(-oo, 2)),
 (2, Interval.Ropen(2, 4)),
 (3, Interval(4, oo))]
>>> p.as_expr_set_pairs(Interval(0, 3))
[(1, Interval.Ropen(0, 2)),
 (2, Interval(2, 3))]
rC   z=
                    multivariate conditions are not handled.z
                            Inequalities in the complex domain are
                            not supported. Try the real domain by
                            setting domain=S.Reals)r   Reals	is_subsetsetr=   r   r_   r   r'   r   r   r/   r   r   ru   	intersectr   EmptySetra   )
r?   domainexp_setsUcomplex	cond_freer6   r7   r   cond_ints
             r8   as_expr_set_pairsPiecewise.as_expr_set_pairsH  s    2 >WWF&&qww//E	))JD***I9~!)* 6@ +A B BJ/A%a"b22( 56 *7 8 8 0 {{4;;=1HA1::% 01 $  r:   c           	         0 n[        U5      n[        S U 5       5      n[        U5       GH  u  nu  pg[        U[        5      (       d&  US:w  a   [        [        S[        U5      -  5      5      eUS:X  a    O[        U[        5      (       a  UR                  OU/ H  nUR                  nUR                  5       n	 UR                  U	[        R                  5      R                  UR!                  5       5      X9'   X9   [        R$                  [        R&                  4;   d  M  [        X   5      X'   S=oqU   S'     O   US:X  d  GM    O   WS:w  a  [)        [        S5      5      eUW   u  p[+        US U 5       H  u  p[-        X|U
5      n
M     [/        U
5      $ ! ["         a!    U(       d  [#        [        SU-  5      5      e Nf = f)Nc              3   0   #    U  H  u  pUS :H  v   M     g7f)TNrM   )rm   rn   r   s      r8   ro   1Piecewise._eval_rewrite_as_ITE.<locals>.<genexpr>|  s     1DDAa4iDr   TzP
                    Expecting Boolean or bool but got `%s`
                    a  
                            A method to determine whether a multivariate
                            conditional is consistent with a complete coverage
                            of all variables has not been implemented so the
                            rewrite is being stopped after encountering `%s`.
                            This error would not occur if a default expression
                            like `(foo, True)` were given.
                            rC   z
                Conditions must cover all reals or a final default
                condition `(foo, True)` must be given.
                )r   r   r   r/   r   r4   r'   r(   r   r=   r   rb   r   r   r}  unionr   r   UniversalSetry  ru   r   r    r   )r?   r=   rP   byfreer!  r   rn   r   r   r   lastr   rQ   s                r8   _eval_rewrite_as_ITEPiecewise._eval_rewrite_as_ITEy  s   Dz1D11"4IAva))a4i
 ,#A,,' !( ) ) Dy)!R00QVVqc9~~HHJ& & 1 11::!'',uQXXZ'8 I 9 99"47mDG%))AQ
) :* Dy= )> 9Z )    q'T"1X&DAqT?D '$3 + 	&"1* >  #$>$ 3% & & #	&s   ;?F(GGc                   ^	^
^^ SSK Jm	  [        SS/[        SS/[        SS/[
        S S /[        S S /0m " S S[        5      m
U	U
UU4S jm/ nS nU HD  u  pV[        U5      T;   a  UR                  XV45        M(  U[        R                  L a	  Uc  UnMB  MD    g    Ub+  UnUS S S2    H  u  pV T" U5      nX-  S	U-
  U-  -   nM     U$ g ! T
 a       g f = f)
Nr   )KroneckerDeltaFTc                       \ rS rSrSrg)HPiecewise._eval_rewrite_as_KroneckerDelta.<locals>.UnrecognizedConditioni  rM   N)rT   rU   rV   rW   rZ   rM   r:   r8   UnrecognizedConditionr    s    r:   r  c           	        > [        U [        5      (       a  T" U R                  6 $ [        U [        5      (       a  ST" U R                  6 -
  $ [	        U 5      U R                  p!UT
;  a  T" U5      eT
U   u  p4U(       a"  [        U Vs/ s H  nST	" U5      -
  PM     sn6 O[        U Vs/ s H  nT	" U5      PM     sn6 nU(       a  SU-
  $ U$ s  snf s  snf )NrC   )r/   r   r=   r   typer   )r7   r5   r=   b1b2r   r   r  r  r3   ruless          r8   r3   :Piecewise._eval_rewrite_as_KroneckerDelta.<locals>.rewrite  s    $##%tyy11$##>499555T
DII%+C003ZFB8:d3da'!*nd34Z^E_Z^UVgajZ^E_@`A1uH	 4E_s   C*Crk   rC   )(sympy.functions.special.tensor_functionsr  r   r   r   r   r   	Exceptionr  ra   r   r   )r?   r=   rP   
conditions
true_valuevaluer7   resultr   r  r  r3   r  s            @@@@r8   _eval_rewrite_as_KroneckerDelta)Piecewise._eval_rewrite_as_KroneckerDelta  s   K %t$tt
	I 		 	" 

KEDzU"!!5-0%!&J &    !F)$B$/AY!a%6)99F  0 M " - s   .C

CCrM   T)F)r   rF   )7rT   rU   rV   rW   rX   nargsis_Piecewiser.   classmethodrc   r}   rR   r   r   r   r   r   r   r   r   r   r   r   r.  r2  r9  r=  rA  _eval_is_finite_eval_is_complex_eval_is_even_eval_is_imaginary_eval_is_integer_eval_is_irrational_eval_is_negative_eval_is_nonnegative_eval_is_nonpositive_eval_is_nonzero_eval_is_odd_eval_is_polar_eval_is_positive_eval_is_extended_real_eval_is_extended_positive_eval_is_extended_negative_eval_is_extended_nonzero_eval_is_extended_nonpositive_eval_is_extended_nonnegative_eval_is_real_eval_is_zero_Piecewise__eval_condr  r  r  rZ   __classcell__)r  s   @r8   r1   r1   A   sT   <| EL72 /! /!b# 2,
DFCG4&#RJA$FW r@Dd*L = (F
OMGMMOELINO "$"$!#%'!%'!GMM 
 
/b+ Z4 4r:   r1   Tc                 	   [        U [        5      (       a  U R                  [        5      (       d  U $ / n[        U [        [        45      (       a  U R
                   H  u  p4[        U[        5      (       d  [        U5      nUR                  [        5      (       a   e[        U[        5      (       a  UR                  5       n[        USS9n[        U[        5      (       aF  UR                  UR
                   VVs/ s H  u  pV[        U5      [        Xd5      4PM     snn5        M  UR                  X445        M     GOU R                  (       d$  U R                  (       Ga  U R                  (       Ga  [!        U R
                  S SS9u  px[!        US 5      n	[#        [%        U	5      5       GH  n['        X   5      S:  Gaj  X    V
s/ s H  n
[#        U
R
                  5      PM     nn
[)        U VV
s/ s H  o V
s/ s H  oR*                  PM     sn
PM      sn
n6 n['        U5      n/ n[-        U5       HC  n
UR                  U R.                  " U Vs/ s H  nUU
   R0                  PM     sn6 X   45        ME     / nU Hd  nU['        U5      :X  a  M  UU   R*                  S:X  a   UR                  UU   R0                  5        MG  UR                  [        UUS S	S
065        Mf     U(       a   UR                  U R.                  " U6 S45        UR                  [        US	S
065        GM  UR                  X   5        GM     OU R
                  n[#        [3        [        U5      5      n[5        U V
s/ s H-  n
[        U
[        5      (       a  U
R
                  OU
[6        4/PM/     sn
6  H3  n[9        U6 u  p4UR                  U R.                  " U6 [        U6 45        M5     UcV  [#        [;        [;        U5       VVs0 s H  u  p4XC_M	     snnR=                  5        VVs/ s H  u  pCX44PM
     snn5      5      n[        US	U06nUcO  ['        UR
                  5      S:X  a6  UR
                  S   R*                  S:X  a  UR
                  S   R0                  $ [?        S URA                  [        5       5       5      (       a  [        U5      $ U$ s  snnf s  sn
f s  sn
f s  sn
nf s  snf s  sn
f s  snnf s  snnf )a  
Takes an expression containing a piecewise function and returns the
expression in piecewise form. In addition, any ITE conditions are
rewritten in negation normal form and simplified.

The final Piecewise is evaluated (default) but if the raw form
is desired, send ``evaluate=False``; if trivial evaluation is
desired, send ``evaluate=None`` and duplicate conditions and
processing of True and False will be handled.

Examples
========

>>> from sympy import Piecewise, piecewise_fold, S
>>> from sympy.abc import x
>>> p = Piecewise((x, x < 1), (1, S(1) <= x))
>>> piecewise_fold(x*p)
Piecewise((x**2, x < 1), (x, True))

See Also
========

Piecewise
piecewise_exclusive
cnf)formc                     U R                   $ rF   )r  r   s    r8   r    piecewise_fold.<locals>.<lambda>  s    r:   Tbinaryc                 b    [        U R                   VVs/ s H  u  pUPM	     snn5      $ s  snnf rF   )tupler=   )r   r   r   s      r8   r   r    s!    5qvv)>v!v)>#?)>s   +
rC   Nr^   Fr   c              3      #    U  H6  oR                     H#  o"R                  R                  [        5      v   M%     M8     g 7frF   )r=   r6   r0   r1   )rm   r   r  s      r8   ro   !piecewise_fold.<locals>.<genexpr>G  s+     
N*=Qvv!66::i  v *=s   >A )!r/   r   r0   r1   r+   r=   r2   r    to_nnfr!   r  r   ra   is_Addis_MulrG   r%   r   r   r_   r&   r7   rangerN   r6   r   r)   r   rt   r   itemsr   r   )r6   r^   new_argsr   r   eicir   r=   pcr   pargsr   comr/  	collectedairemainsrQ   foldedrf   r  s                         r8   r2   r2     s3   4 dE""$((9*=*=H$y122IIDAa++"1% uuY''''!S!!HHJ"151!Y''"#&&!*"( #1"4c"j!A"(!* + ' : ;;$+++$*=*=*=499&>tLGAa?@B'"+&ru:>35595aT!&&\5E9'5:*<5:+A+U*< =CCA "I"1X!(( IIU'CUr1

U'CDF*$ % & !G"A;$Q499,#NN1Q4995#NN )1QR5 A5 AC # !(($))W*=t)DEKK	9 Eu EFBE"3 '6 99Dc.$/0'-/'-! &a33d)'-/ 0B 8DAOOTYY]CG45	0 %h/61/TQAD/611669 ": 69TQ1& 69 ": ; <	H	0x	0BCLA-"''!*//T2Iwwqz

N"((9*=
NNNb!!IE!*. : ,*< (D(/61 ":s<   :"SS3	S<SSS%34S*=S/ S5Sc                 r   Uu  p4U u  pV[        [        XS5      U5      [        [        Xc5      U5      pe[        X45      n/ nX5:w  a  UR                  X5S45        O XV:w  a  UR                  XVU45        O XF:w  a>  Xe:X  a#  U(       a  US   S   S:X  a  US   S   US4US'   U$ UR                  XdS45         U$  U$ )a  Return interval B as intervals that are covered by A (keyed
to k) and all other intervals of B not covered by A keyed to -1.

The reference point of each interval is the rhs; if the lhs is
greater than the rhs then an interval of zero width interval will
result, e.g. (4, 1) is treated like (1, 1).

Examples
========

>>> from sympy.functions.elementary.piecewise import _clip
>>> from sympy import Tuple
>>> A = Tuple(1, 3)
>>> B = Tuple(2, 4)
>>> _clip(A, B, 0)
[(2, 3, 0), (3, 4, -1)]

Interpretation: interval portion (2, 3) of interval (2, 4) is
covered by interval (1, 3) and is keyed to 0 as requested;
interval (3, 4) was not covered by (1, 3) and is keyed to -1.
rk   r   )r   r   ra   )ABr   rQ   rn   r   dr   s           r8   r   r   L  s    , DADAs1y!c#a)Q/qA	A
Av	!v	!v6aAbE"IObE!HaOAbE H	 HHaBZ  H 	Hr:   c                    SSK Jn  U R                  S   R                  R                  nS n[        U5      S:X  Ga  U R                  [        5      (       Gd  UR                  5       nU R                  USS9u  pgS nU(       Ga`  / n[        R                  n	SSKJn
  U GH  u  ppU R                  U   R                  nU" XU5      nU" XU5      nU
" XU(       + U(       + 5      nUU	-
  nU(       d  MT   UR                  nU" XU5      nU(       a  U(       a  UR                   (       a"  UR                   (       a  [        R"                  nOUR                   (       a  X;   a  X[:  OX[:  nOUR                   (       a  X\:*  nOX;   a  [%        X:  X\:*  5      nO[%        X:*  X\:*  5      nOU(       a=  UR                   (       a  X\:  nOoX;   a  [%        X:  X\:  5      nOY[%        X:*  X\:  5      nOHU(       a'  UR                   (       a  X[:  nO+[%        X:  X\:*  5      nOX;   a  X\:  nO[%        X:  X\:  5      nU	U-  n	U[        R&                  L a  U(       a  U	[        R&                  1-  n	U[        R(                  L a  U(       a  U	[        R(                  1-  n	UR+                  X45        GM	     [        R,                  R/                  U	5      (       d  UR+                  [0        S45        UcY  [3        U R                  5      n[5        [        U5      5       H,  nXN   u  p[7        U[8        5      (       a	  U" U40 UD6nX4XN'   M.     UR                  SS 5      n[5        [        U5      5       H6  nXN   u  p[7        U[8        5      (       a  U" U4SS	0UD6nUU:w  a  UnX4XN'   M8     Ub  UUS'   [;        U6 $ ! [         a     GNf = f)
Nr   )rO   rC   T)r  c                 L     U R                  X5      S:H  $ ! [         a     gf = f)z/return True if c.subs(x, a) is True, else FalseTF)r   r4   )r   r   rQ   s      r8   include-piecewise_simplify_arguments.<locals>.include  s,    vva|t++ s    
##)Intervalr}   F)sympy.simplify.simplifyrO   r=   r7   r   r_   r   r   rb   r   r   r}  sympy.sets.setsr  infr   is_infiniter   r   r  r   ra   ry  rz  rq   r   r  r/   r   r1   )r6   rP   rO   f1r=   r   r   abe_r  coveredr  rQ   rn   r   r   r   incl_aincl_bivcsetr}   r   s                         r8   piecewise_simplify_argumentsr  z  s0   0 
1			'	'BD
2w!|DJJrNNFFH ??1?5	 DjjG0"
aIIaL%% q) q)aJF
;G|.A %Q1-Ff}}FF'(|QU!&Vqv./}}Uqu-.}}Uqv.|Uqu-2***v 2 233G

?v

|+GQF#_ #` 77$$W--Y-.|DIIs4y!AGDA!U##Q)&)fDG	 " ::fd#D3t9a A4E4V4Dqy&  vdA + s   3N00
N>=N>c                    / n[        5       nU  GHq  u  p4UR                  S [        5      n[        U[        5      (       a`  / n[        UR                  5       HE  u  nu  pxX;   a  M  X:X  a  US:w  a  U(       a  [	        XWU4/-   6 nOUn  OUR                  Xx45        MG     Sn	U/[        U[        5      (       a  [        UR                  5      O/ -    H  nXb;   d  M
  Sn	  O   U	(       a  M  [        U[        5      (       a  / n
UR                   Ht  n[        U[        5      (       aK  UR                  R                  U;   a  M4  [        U[        [        45      (       a  UR                  U;   a  Sn  OdU
R                  U5        Mv     UR                   " U
6 nO?[        U[        5      (       a*  UR                  R                  U;   a  ["        R$                  nUR'                  U5        U(       ax  US   R(                  U:X  aO  [+        XAS   R,                  5      n[        U[        [*        45      (       a  [/        U5      n[1        X;5      US'   GMA  US   R,                  U:X  a  GMW  UR                  [1        X45      5        GMt     U$ )Nc                     U R                   $ rF   )r   r   s    r8   r   /_piecewise_collapse_arguments.<locals>.<lambda>  s    aoor:   TFrk   )r{  r   r   r/   r1   r   r=   ra   r   r   r   negated	canonicalr   r   weakrN   r   r   addr6   r   r7   r   r+   )rv   re   current_condr6   r7   
unmatchingr   r   r   gotnonredundantorconds               r8   rr   rr     s6   G5L
||%'79 dI&&J&tyy1	6A$9Dy
 &#, *!fX 5$8D $%D%%qf-# 2(  &&0s&;&;4		?A    dC  LYYa,,yy**l:  "!b"X..,.$##A&  yy,/j))||%%5vv r{4'D"+"2"23fsBi003F;F*48!!T)|D/0o p Nr:   c                     [        U R                  SS5      =(       a>    [        U R                  SS 5      =(       d     [        U R                  [        [
        45      $ )N	_diff_wrtF)r`   ru  r  r/   r   r   )r   s    r8   r   r   ;  sC    WQUUK7 1AEE;% 0quux./1r:   c                     [        U 40 UD6n [        U [        5      (       d  U $ [        U R                  5      n[        U5      n[        U5      n[        U6 $ rF   )r  r/   r1   r   r=   _piecewise_simplify_eq_and)_piecewise_simplify_equal_to_next_segment)r6   rP   r=   s      r8   r   r   @  sO    '77DdI&&		?D%d+D4T:Ddr:   c                 X   Sn[        [        [        U 5      5      5       GH  u  nu  p4Ub  [        U[        5      (       a  [        UR                  S SS9u  pVO[        U[        5      (       a  U// peO/ =pVUnUnU(       aw  U(       dp  [        [        U5      5      nU HV  n	[        U 5      S:X  d  [        U	5      (       d  M$  UR                  " U	R                  6 nUR                  " U	R                  6 nMX     Xx:X  a   X   R                  XS-      S   U5      X'   M  UnGM  UnGM     U $ )z
See if expressions valid for an Equal expression happens to evaluate
to the same function as in the next piecewise segment, see:
https://github.com/sympy/sympy/issues/8458
Nc                 "    [        U [        5      $ rF   r/   r   r   s    r8   r   ;_piecewise_simplify_equal_to_next_segment.<locals>.<lambda>V  s    Jq",=r:   Tr  r   rC   r   )r   r   r   r/   r   r%   r=   r   r   r_   _blessedr   rN   )
r=   prevexprr   r6   r7   eqsother	_prevexpr_exprr   s
             r8   r  r  K  s    H#D4$9:<D$$$!$))"=dL
UD"%%"VRU   IE573<(A 4yA~!$-NNAFF$;	 %

AFF 3  ! ',,tE{1~t<  H= ;> Kr:   c                    [        U 5       GH*  u  nu  p#[        U[        5      (       a  [        UR                  S SS9u  pEO[        U[
        5      (       a  U// pTO/ =pEU(       d  M]  [        [        U5      5      n[        U5       H  u  pg[        U5      (       d  M  UR                  " UR                  6 nXFS-   S  Vs/ s H  oR                  " UR                  6 PM     snXFS-   S& U Vs/ s H  oR                  " UR                  6 PM     nnM     [        XE-   6 nX   R                  X#5      X'   GM-     U $ s  snf s  snf )z
Try to simplify conditions and the expression for
equalities that are part of the condition, e.g.
Piecewise((n, And(Eq(n,0), Eq(n + m, 0))), (1, True))
-> Piecewise((0, And(Eq(n, 0), Eq(m, 0))), (1, True))
c                 "    [        U [        5      $ rF   r  r   s    r8   r   ,_piecewise_simplify_eq_and.<locals>.<lambda>~  s    
1b(9r:   Tr  rC   N)r   r/   r   r%   r=   r   r   r   r  r   rN   )	r=   r   r6   r7   r  r  r   r   r  s	            r8   r  r  t  s    %T?<DdC  dii9$HJCb!!C3ws|$C!# A;;99aff-D>Aa%&k"Jk77AFF#3k"JCAK8=>"WWaff-E>E ' &Dgll4.DG% +& K	 #K>s   "D=/"EF)skip_nanr{   c                   ^ U4S jnU(       a  U R                  [        U5      $ [        U [        5      (       a  U" U R                  6 $ U $ )a  
Rewrite :class:`Piecewise` with mutually exclusive conditions.

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

SymPy represents the conditions of a :class:`Piecewise` in an
"if-elif"-fashion, allowing more than one condition to be simultaneously
True. The interpretation is that the first condition that is True is the
case that holds. While this is a useful representation computationally it
is not how a piecewise formula is typically shown in a mathematical text.
The :func:`piecewise_exclusive` function can be used to rewrite any
:class:`Piecewise` with more typical mutually exclusive conditions.

Note that further manipulation of the resulting :class:`Piecewise`, e.g.
simplifying it, will most likely make it non-exclusive. Hence, this is
primarily a function to be used in conjunction with printing the Piecewise
or if one would like to reorder the expression-condition pairs.

If it is not possible to determine that all possibilities are covered by
the different cases of the :class:`Piecewise` then a final
:class:`~sympy.core.numbers.NaN` case will be included explicitly. This
can be prevented by passing ``skip_nan=True``.

Examples
========

>>> from sympy import piecewise_exclusive, Symbol, Piecewise, S
>>> x = Symbol('x', real=True)
>>> p = Piecewise((0, x < 0), (S.Half, x <= 0), (1, True))
>>> piecewise_exclusive(p)
Piecewise((0, x < 0), (1/2, Eq(x, 0)), (1, x > 0))
>>> piecewise_exclusive(Piecewise((2, x > 1)))
Piecewise((2, x > 1), (nan, x <= 1))
>>> piecewise_exclusive(Piecewise((2, x > 1)), skip_nan=True)
Piecewise((2, x > 1))

Parameters
==========

expr: a SymPy expression.
    Any :class:`Piecewise` in the expression will be rewritten.
skip_nan: ``bool`` (default ``False``)
    If ``skip_nan`` is set to ``True`` then a final
    :class:`~sympy.core.numbers.NaN` case will not be included.
deep:  ``bool`` (default ``True``)
    If ``deep`` is ``True`` then :func:`piecewise_exclusive` will rewrite
    any :class:`Piecewise` subexpressions in ``expr`` rather than just
    rewriting ``expr`` itself.

Returns
=======

An expression equivalent to ``expr`` but where all :class:`Piecewise` have
been rewritten with mutually exclusive conditions.

See Also
========

Piecewise
piecewise_fold
c                    > [         n/ nU S S  HS  u  p4[        U[        U5      5      R                  5       n[	        XA5      R                  5       nUR                  X545        MU     U S   u  pg[        U[        U5      5      R                  5       nUR                  Xh45        T	(       dP  [	        Xq5      R                  5       nU[        La.  UR                  [        [        U5      R                  5       45        [        USS06$ )Nrk   r^   F)	r   r   r   rO   r   ra   r   rq   r1   )
pwargscumcondre   expr_icond_icancondexpr_ncond_n	cancond_nr  s
            r8   make_exclusive+piecewise_exclusive.<locals>.make_exclusive  s     %SbkNF&#g,/88:G)224GNNF,- *  G-668	*+)224Gd"	3w<+@+@+BCD'2E22r:   )r   r1   r/   r=   )r6   r  r{   r  s    `  r8   piecewise_exclusiver    s@    @3. ||I~66	D)	$	$tyy))r:   Nr  )@
sympy.corer   r   r   r   r   sympy.core.basicr   r	   sympy.core.functionr
   sympy.core.numbersr   r   r   sympy.core.parametersr   sympy.core.relationalr   r   r   r   r   r   r   sympy.core.sortingr   (sympy.functions.elementary.miscellaneousr   r   sympy.logic.boolalgr   r   r   r   r   r   r   r    r!   r"   r#   sympy.utilities.iterablesr$   r%   r&   sympy.utilities.miscr'   r(   	itertoolsr)   NaNrq   r+   r1   r2   r   r  rr   r  r   r  r  r  rM   r:   r8   <module>r&     s    1 1 , / ? ? 3" " " & =J J J J ? ? 6 EE	+E5 +E\Y Yxl^+\`F[|1
&R: +0d \r:   