
    gr                        d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2  ed          Z3 ed          Z4d Z5d Z6d Z7d Z8d Z9d Z:d Z;d Z<d Z=d Z>d Z?d Z@d ZAd  ZBd! ZCd" ZDd# ZEd$ ZFd% ZGd& ZHe!d'             ZId(S ))    )randint)Function)Mul)IRationaloo)Eq)S)Dummysymbols)explog)tanh)sqrt)sin)Poly)ratsimp)checkodesol)slow)riccati_normalriccati_inverse_normalriccati_reducedmatch_riccatiinverse_transform_polylimit_at_infcheck_necessary_conds
val_at_infconstruct_c_case_1construct_c_case_2construct_c_case_3construct_d_case_4construct_d_case_5construct_d_case_6rational_laurent_seriessolve_riccatifxc                 \    t          t          |  |           t          d|                     S )N   )r   r   )maxints    `/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/solvers/ode/tests/test_riccati.pyrand_rationalr,      s(    GVGV,,ga.@.@AAA    c                 \    t          fdt          |dz             D             |           S )Nc                 .    g | ]}t                    S  )r,   ).0_r*   s     r+   
<listcomp>zrand_poly.<locals>.<listcomp>"   s!    @@@1v&&@@@r-   r)   )r   range)r'   degreer*   s     `r+   	rand_polyr6   !   s2    @@@@fQh@@@!DDDr-   c                    t          d|          }t          d|          }t          | ||          }t          | ||          }|t          d|           k    r%t          | ||          }|t          d|           k    %||z  S )Nr)   r   )r   r6   r   )r'   r5   r*   degnumdegdennumdens          r+   rand_rational_functionr<   %   s    QFQF
Avv
&
&C
Avv
&
&C
a

66** a

9r-   c                    | }|                     |          }t          |dd          }t          |dd          }|dk    rt          |dd          }|dk    t          |||z  z
  ||dz  z  z
            }t          |                                 |||z  z   ||dz  z  z             }t          ||          }	t	          ||	          dk    sJ ||||fS )Nr)      r      )Tr   )diffr<   r   r	   r   )
ratfuncr'   yfyypq1q2q0eqsols
             r+   find_riccati_oderJ   /   s    A	
B	1a	(	(B	1a	(	(B
''#Aq!,, ''	bdR1W$	%	%B	BGGIIrBrEzBr1uH,	-	-B
R))Cr39,,,,r2r>r-   c                  
   t           t           dz
  z  t           dz  dz   dz  t           z  t           t           dz   t           dz
  z  t           t           dz  dz  t          d          dz  z   z  dz  z
  ddt           z  z  z
  fdt           z  dz   dt           z  dz   z  ddt           z  z
  t           dz   z  dt           z  dt           z  dt           z  dz   z  dt           z  dz   z  ddt           z  z
  t          dt           dz   d          z  z
  ddt           z  z  z
  fd	dt           dz  z  dz
  z  d
dt           z
  dt           z  dz
  z  dt           z
  dt           z  dz
  dt           dz  z  dz
  z  z  dt           z  dz
  t          ddt           z
  d          dt           z  dz
  dz  z  ddt           z  dz
  z  z
  z  t          ddt           z
  d          z  z
  ft           dt           z  dz
  dt           z  dz   z  t           dz  dt           z  dz
  z  t           dz   dt           z  dz
  z  dt           z  dz
  t          ddt           z  dz   d          z  z
  dt           z  dz
  dt           dz  z  dt           z  dz
  dz  z  dt           dz  z  dt           z  dz
  z  z   z  dt           dz  z  z  z
  fg} | D ]S\  }}}}|t          |t           ||          k    sJ |t	          |t           ||                                          k    sJ Tdt           z  dz
  dt           dz  z  dt           z  z   dz
  z  dt           z  t            dz
  dt           z  z  dt           dz  z  ddt           z  z  t            dz
  dt           dz  z  z  z   z  t            dz
  dz  z  dt            dz
  z  z   dt           z  d	dt           z  z  t            dz
  dt           dz  z  z  z
  z  t            dz
  z  dt           z  dz
  t            dz
  z  dt           z  dt           dz  z  dt           z  z   dz
  z  z  z
  dt           z  z   fddt           dz  z  z  dt           z  t            dz
  dt           z  z  dt           dz  z  ddt           z  z  t            dz
  dt           dz  z  z  z   z  t            dz
  dz  z  dt            dz
  z  z   dt           z  d	dt           z  z  t            dz
  dt           dz  z  z  z
  z  t            dz
  z  dt           z  z   t          dt            dz
  d          dt           dz  z  z  z
  fg} | D ]U\  }}}}}|t          |t           ||          k    sJ |t	          |t           |||                                          k    sJ VdS )ar  
    This function tests the transformation of the
    solution of a Riccati ODE to the solution of
    its corresponding normal Riccati ODE.

    Each test case 4 values -

    1. w - The solution to be transformed
    2. b1 - The coefficient of f(x) in the ODE.
    3. b2 - The coefficient of f(x)**2 in the ODE.
    4. y - The solution to the normal Riccati ODE.
    r)   r?      r>      Fevaluater            	      N)r'   r
   r   r   r   cancel)testswb1b2rC   bps         r+   test_riccati_transformationr`   ?   s    	
1q5		
A1Q		
Aq1u1a46AaDDF?+A--1Q37	 
1q1Q37	
QqS1q5	!
1acAg!a A!Gc!QUU.K.K.K#LLqRSTURUwV	 	AadFQJ		
Q1q	
Q!A#'AadFQJ'(AaC!Gc"a!ee6T6T6TVWXYVY	W
V 71Q377 ,!!QUU;;;,= 	=	 	
	
1rBqD1H	1acAg	
AqsQw1Q38c!RTAX&F&F&FGG1Q3QR7UWXY[\X\U\^_`a^a
_^ VAqD&!A#'"V# K$%&q!tVK- 	-	)E6  B B2r1N1aR000000*1aR88??AAAAAAA
 
AAadFQqSL1$%
1
a!A#	!Q$1Q3A26AadF++,qb1fq[81qb1f:E
1b!A#h1"q&1QT6**+aR!V41qA267JAaCQRSTVWSWQWZ[\]Z]Q]
R M 8 	!	 	
1QT6

1
a!A#	!Q$1Q3A26AadF++,qb1fq[81qb1f:E
1b!A#h1"q&1QT6**+aR!V4qs:SQBFUZ=[=[=[]^_`bc_c]c=ddE  " F F2r2qN1aR000000*1aR<<CCEEEEEEEF Fr-   c                     t          t                                        t                    t          dz  z
  t          t          t                    z  z
  t          t          t                    dz  z  z
  t          t                                        t                    t          t                    dz  z   t          dz  z   t          dz  dz  z
  ddt          dz  z  z  z
  fdt          z  dt          z  dz   z  t          t                                        t                    z   t          dz   t          t                    dz  z  t          z  z
  dt          dz  z  dt          z  t           dz
  t          dz  z  z   dz  z  dt           dz
  dz  z  z  t          dt           dz
  d	          dt          z  dz   z  z   t          t                    dz  z   t          t                                        t                    z   d
t          dz   t          z  z   t          t           dz
  z  z  z
  ft          t                    dz  t          t                                        t                    z   t          dz
  t          t                    z  t           t	          d          dz  z
  z  z
  dt          z  dz
  dz   ddt          z  dz   dz  z  z  dt          z  dz
  dt          z  dz   dz  z  z   t          t                    dz  z   t          t                                        t                    z   ddt          z  dz   z  z
  ft          t                                        t                    t          t                    dz  t          z  z
  t          t                    dz  t          t                                        t                    z   ddt          dz  z  z  z   fdt          dz   t          z
  dz   z  t          dz  dt          z  z   dz   z  t          t                                        t                    z   t          t                    dz  t          z  z   t          t                    dz  t          t                                        t                    z   dt          dz  z  t          dz  dt          z  z   dz   z  dt          z  t          dz  dt          z  z   dz   z  z   dt          dz  dt          z  z   dz   z  z
  t          z  z   ddt          dz  z  z  z   fdt          z  dt          z  dz   z  t          t                                        t                    z   t          dz   t          t                    z  t          z  z
  dft          t                    t          t                                        t                    z  dt          z  z
  t          t                    dz  z   t          t                    dz  t          dz  dz
  z  z   dfg} | D ]&\  }}|t          |t           t                    k    sJ 'dS )z
    This function tests the transformation of a
    Riccati ODE to its normal Riccati ODE.

    Each test case 2 values -

    1. eq - A Riccati ODE.
    2. normal_eq - The normal Riccati ODE of eq.
    r?   r>   rR   rW   rV   r)   FrO   rQ   N)r&   r'   r@   r   r
   r   )r[   rH   	normal_eqs      r+   test_riccati_reducedrd      s    	
!		!q!ta!f$q1qy0	!		!qttQwA%1Q.AadF; 	
!QqS1W!		!$AqttQwq'88
1a41Q1}$q((!aR!VaK-83q	
Q<  <  < !"1q<* 	*,-aDD!G	467ddiill	CQ	>ArAvJ
'	( 	
!a!A$$))A,,!a%1rAaDDF{!;;
A#'Aq!A#'A~&!A#'AaC!Ga<)??	!a	A$$))A,,	!"AaC!G	- 	
!		!qttQwqy 	!a!A$$))A,,AadF+ 	QTEAIMAqD1Q3JN+addiill:QqTT1WQYF	!a!A$$))A,,!AqD&!Q$1*q."9AaCA
A#BB = #1qs
Q'#()*"+ 	+-.!Q$Z	8 	
!QqS1W!		!$Aqtt|A~5 	
!QqTTYYq\\AaC!A$$q&(1Q447AqD1H+==G'EP  6 6IOB155555556 6r-   c                     t          t                                        t                    dt          dz  z  dt          dz  z  z
  dt          z  z
  dz   dt          dz  z  d	t          dz  z  z
  d
t          dz  z  z   dt          z  z   dz
  z  z
  dz
  t          t                    dz  dt          z  dz   z  z
  t          d          dz  t          z
  t          t                    z  t          d          dz  dt          z  dz  z
  z  z
  ddt          dz  z  dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          z  z   dz
  z  dt          dz  z  dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          z  z   dz
  z  z
  dt          z  dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          z  z   dz
  z  z
  dz   ddt          dz  z  d	t          dz  z  z
  d
t          dz  z  z   dt          z  z   dz
  z  z   t	          dddt          z  z
  d          d t          z  dz
  z  ddt          z  dz   z  ft          t                                        t                    dt          z  dz  z   t          dz  dz
  t          t                    dz  z  z
  dt          z  dz  dz   t          t                    z  dt          z  dz   z  z
  t          d!          dz  z
  d"t          dz  z  d#t          z  z   d$z   d%t          dz  z  d&t          dz  z  z   z  z
  dd't          z  dz  t          d!          dz  z   ddt          dz  z  dt          dz  z  z   z  z   d(d)t          dz  z  dt          z  z   z  z   d"d%t          z  d&z   z  z   t	          dd*t          z  dz
  d          d t          z  dz   z  t          dz  dz
  ft          t                                        t                    d+t          d,z  z  d-t          dz  z  z
  d.t          dz  z  z   d/t          dz  z  z
  d0t          z  z   d1z
  d)t          dz  z  d&t          d,z  z  z
  d2t          dz  z  z   d3t          dz  z  z
  d4t          dz  z  z   d1t          z  z
  z  z
  t          d5          d z  z
  t          t          d          dz  z
  t          t                    z  t          dz  t          d          dz  z
  z  z
  t          dz  dz
  t          t                    dz  z  dt          z  z  z
  dd+t          dz  z  d)t          d,z  z  d&t          dz  z  z
  d2t          dz  z  z   d3t          dz  z  z
  d4t          z  z   d1z
  z  d-t          dz  z  d)t          d,z  z  d&t          dz  z  z
  d2t          dz  z  z   d3t          dz  z  z
  d4t          z  z   d1z
  z  z
  d.t          dz  z  d)t          d,z  z  d&t          dz  z  z
  d2t          dz  z  z   d3t          dz  z  z
  d4t          z  z   d1z
  z  z   d6t          z  d7t          d,z  z  dt          dz  z  z
  d8t          dz  z  z   d9t          dz  z  z
  d:t          z  z   d)z
  z  z
  t          d5          d z  z   d7dt          dz  z  dt          d,z  z  z
  d;t          dz  z  z   d<t          dz  z  z
  d=t          dz  z  z   d7t          z  z
  z  z
  d>dt          d,z  z  dt          dz  z  z
  d;t          dz  z  z   d<t          dz  z  z
  d=t          z  z   d7z
  z  z   t	          dddt          z  z
  d          t          dz
  z  t	          dd t          z
  d          d t          z  z  ft          t                                        t                    t          t          d          dz  z  t          t          d          dz  z  dz
  z  z
  t          dz  t          t                    z  z   t          t          t                    dz  z  t          t          d          dz  z  z  z   dd?d?d?ft          t                                        t                    t          t          dz            z
  t          t                    t          t                    z  z   t          t                    t          t                    dz  z  z   dd?d?d?ft          t                                        t                    t          t          t          t                    z             z
  t          t                    z   t          dz  t          t                    dz  z  z   dd?d?d?fdt          dz  z
  t          t                                        t          d          z  dt          z  t          t                                        t                    z  z
  dt          t                    z  z   dd?d?d?ft          t                                        t                    t          dz  z
  t          dz  t          t                    z  z   t          dz  t          dz   z  t          t                    dz  z  z   dd?d?d?ft          t                                        t                    t          t                    dz  z  t          dz  dz
  t          dz  dz   z  t          t                    z  z   ddt          z  dz   z  z   t          t                    dz  z   dd?d?d?fg	} | D ];\  }}}}}t          |t           t                    \  }}||k    sJ |r|||g|k    sJ <d@S )Aa  
    This function tests if an ODE is Riccati or not.

    Each test case has 5 values -

    1. eq - The Riccati ODE.
    2. match - Boolean indicating if eq is a Riccati ODE.
    3. b0 -
    4. b1 - Coefficient of f(x) in eq.
    5. b2 - Coefficient of f(x)**2 in eq.
    i  r>   ir  r?   N   \      rR   i  iN     H   r)   T-      i   ^      rT   b      Q   ;  i  <      rQ   rW   FrO   rV   
   i	  i     iD     rS   /   $   rY   i0  rM   i  iw  il     l   i  i7  ih     i$  rU         x   5   ?   (      r   N)r&   r'   r@   r
   r   r   r   r   r   r   r   )r[   rH   resb0r]   r^   matchfuncss           r+   test_match_riccatir      sh
    	
!		!AqD3q!t8+bd2R7#ad(
ad(;AX; #A;&(*;+ , 	,./	023A$$'1Q372C	DQ446A:qtt
QqTT!Vac!e^
,	- 	
1a4AqD3q!t8#bAg-14q89Bq!tG	AqD3q!t8	bAg	%1	,q	0=2 	246qD"QT'AqD;q!t8; d;#%';( 5)	)+,	-/13q!t8c!Q$h3F
ad(4U44  0!	!
 	BAaC%(((!A#'2	1Q37" 	
!		!qs2v1q!A$$' 11QqSU	6
Q4451q5 	bEE"H	%(+AqD3q5(83(>
ad(SAX
(	 	
1R!B%%(Q!Q$1a4002r!Q$w
Q$8 4 	s1us{#	$ 	B1q5)))1Q373	!a 	
!		!AqD3q!t8+c!Q$h6QTA
a%1a4#ad(*SAX5AqD@AqDq5 	bEE!G	$'(1Q446z1Q44&71	!Q: '	 Q37AaDD!G#QqS)	*
 	AqD"QT'C1H$s1a4x/#ad(:SUB 	1a4xAqD3q!t8+c!Q$h6QTAA 	1a4xAqD3q!t8!3c!Q$h!>	1B "1u"" 	 "!eR1Wr!Q$w%6QT%AAqD&q5&& 	 "#2q		) ,.qAv1a4/?
1a40QT'0q!tG0$&(d0+ ,,		,
 /1!AqD&2ad72B
QT'3q!tG3 d3#%'3( /)	) 	BAaC%(((!a%0BA&&&!,%, 	
!		!q1Q446{A!QK!O44q!tAaDDy@	!A$$'	1qttAv;	 q!Q 	
!		!s1a4yy 3q66!A$$;.Q!a?q!Q
 	
!		!tAQK(((1Q44/!Q$qttQw,>q!Q 
QT1Q4499Q??"QqS11%551Q44?q!Q
 	
!		!q!tad1Q44i'1a4Q<1q*@@q!Q
 	
!		!QqTT1W1q1a4!84QqTT99Aqs
@ = 	ttQw	q!QWOE`  % ) )CR$RA..u|||| 	)B<5((((	) )r-   c                  L   t          dt          dz  z  dt          dz  z  z   dt          z  z
  dz   t                    t          dt          dz  z  t          dz  z
  d	t          dz  z  z   d
t          d
z  z  z   dt          dz  z  z   dt          d	z  z  z   d
t          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  d	t          z  z   dz   t                    d
ft          dt                    t          dt          dz  z  dt          dz  z  z   dt          dz  z  z   dt          z  z
  dz
  t                    dft          dt          dz  z  dt          dz  z  z
  dt          z  z   dz
  t                    t          dt          dz  z  dt          dz  z  z   dt          z  z
  dz
  t                    dft          dt          dz  z  dt          d
z  z  z
  dt          dz  z  z
  dt          d	z  z  z   dt          dz  z  z   t          dz  z
  t          dz  z   dt          z  z
  t                    t          dt          dz  z  t          z   t                    dft          d	t          dz  z  dt          d	z  z  z   dt          dz  z  z
  dt          dz  z  z
  t          dz  z   dt          z  z
  dz   t                    t          dt          dz  z  dt          dz  z  z   dt          dz  z  z
  dt          z  z   dz   t                    dfg} | D ]"\  }}}t          ||t                    |k    sJ #dS )a  
    This function tests the valuation of rational
    function at oo.

    Each test case has 3 values -

    1. num - Numerator of rational function.
    2. den - Denominator of rational function.
    3. val_inf - Valuation of rational function at oo
    rv   r>   rT   r?      rW   irV   rM   rL   rR      r)         rX   rN   rU   r   irY   N)r   r'   r   )r[   r:   r;   vals       r+   test_val_at_infr     s    	R1WqAv1$q(!,,SBYA!Q$&1a4/"QT'9AadFBQq!tVKbQRTUQUgUXYZ[]^Z^X^^abcdaddgiiklmm	
 	Q

R1WqAv1a4'!A#-2A66	
 	R1WqAv!#a'++R1Wr!Q$w1$q(!,,	
 	R1Wr!Q$wAqD(1QT61AadF:QTAAqDH2a4OQRSSSAX\1	 	Qq!tVa1f_r!Q$w&1a4/!Q$61<q@!DDR1WqAv!Q$&A-2A66	1E:  . .S##sA&&#-----. .r-   c                      t          dg d          dk    sJ t          dg d          dk    sJ t          dg d          dk    sJ t          dg d          d	k    sJ d
S )zt
    This function tests the necessary conditions for
    a Riccati ODE to have a rational particular solution.
    rb   )r)   r?   rR   Fr)   r?   )r>   r)   rW   )r)   r?   rT   rU   TN)r   r0   r-   r+   test_necessary_condsr   F  s     !YYY//58888 III..%7777 III..%7777 mmm44<<<<<<r-   c            	      l   dt           dz  z  dt           dz  z  z
  dt           z  z
  dz
  dt           z  dz   z  dt           dz  z  d	t           d
z  z  z   dt           dz  z  z   dt           dz  z  z   dt           z  z
  dz
  dt           dz  z  dt           dz  z  z
  dt           z  z   dz   z  dt           dz  z  dt           d
z  z  z
  dt           dz  z  z   dt           dz  z  z
  dt           z  z
  dz
  dt           d
z  z  dt           dz  z  z   dt           dz  z  z   dt           z  z   dz
  z  dt           dz  z  dt           dz  z  z   dt           dz  z  z
  dt           d
z  z  z
  dt           dz  z  z   dt           z  z   dz
  dt           dz  z  dt           z  z
  dz
  z  dt           dz  z  dt           dz  z  z
  dt           d
z  z  z   dt           dz  z  z
  dt           z  z   dz   dt           dz  z  dt           dz  z  z
  dt           dz  z  z   dt           d
z  z  z   dt           dz  z  z
  dt           dz  z  z   dt           z  z   dz
  z  g} | D ]z}d |                                D             \  }}t          ||t                     \  }}|                    t           dt           z                                            ||z  k    sJ {dS )zi
    This function tests the substitution x -> 1/x
    in rational functions represented using Poly.
    r   r>   rT   r?   rW      ri   rM   r   rR   P      rt      K   rU   irz   rL   ru   ro   d      rv   rk   rV   c                 8    g | ]}t          |t                    S r0   )r   r'   )r1   es     r+   r3   z/test_inverse_transform_poly.<locals>.<listcomp>g  s     ;;;1DAJJ;;;r-   r)   N)r'   as_numer_denomr   subsrZ   )fnsr&   r:   r;   s       r+   test_inverse_transform_polyr   U  s    1WqAv!a"Q$(+AX1a4"QT'!Bq!tG+bd2R7#ad(SAX:MPRSTPT:TWY:YZAX1a4"QT'!Bq!tG+bd2R7"QT'Bq!tG:KbQRTUQUg:UXZ[\X\:\_a:ab1Wr!Q$wAqD 2ad7*R1W4s1u<rAC1HrRStOVXDXY1Wr!Q$wAqD 2ad7*RT1B61b52ad79JRPQSTPTW9TWYZ[]^Z^W^9^abcdfgcgag9gAg:1:: C  2 2;;(8(8(:(:;;;S)#sA66Svva1~~$$&&#c'111112 2r-   c                  n   t          dt          dz  z  dt          z  z   dz   t                    t          dt          dz  z  dt          dz  z  z   dt          z  z   dz
  t                    dft          dt          d	z  z  dt          dz  z  z
  d
t          dz  z  z
  dt          z  z
  dz   t                    t          dt          dz  z  dt          dz  z  z
  dt          z  z   dz
  t                    t          ft          dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          d	z  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          z  z   dz   t                    t          dt          dz  z  dt          dz  z  z
  dt          dz  z  z
  dt          d	z  z  z   dt          dz  z  z
  d t          dz  z  z   d!t          z  z   d"z   t                    t           ft          d!t          dz  z  d#t          dz  z  z
  d$t          dz  z  z   d$t          d	z  z  z   d%t          dz  z  z
  d&t          dz  z  z   d't          z  z   d(z   t                    t          d)t          dz  z  dt          dz  z  z   d*t          dz  z  z   d*t          d	z  z  z   d+t          dz  z  z
  d,t          dz  z  z
  d-t          z  z   d.z   t                    t          d/          dz  ft          d0t          d	z  z  d1t          dz  z  z
  d.t          dz  z  z   d2t          z  z
  d3z
  t                    t          d4t          d	z  z  dt          dz  z  z   d5t          dz  z  z
  dt          z  z   dz   t                    t          d0          d4z  fg} | D ]"\  }}}t	          ||t                    |k    sJ #d6S )7a   
    This function tests the limit at oo of a
    rational function.

    Each test case has 3 values -

    1. num - Numerator of rational function.
    2. den - Denominator of rational function.
    3. limit_at_inf - Limit of rational function at oo
    r?   ro       r>   rj   r     rR   i  ix  i  i'    i  i!rT   rL   i  rW   rs   rM   iX  H  i  iv  i  i  |  T     i  rm      i  rt   r   rk   r   r   i  i  i   i	  i
  i  r)      i  i  Z   i_  i  N)r   r'   r   r
   r   )r[   r:   r;   lims       r+   test_limit_at_infr   l  s    	SAX1_r!1%%R1Wr!Q$w1$r)1--	 	T!Q$Yad"SAX-Q6=qAAT!Q$Yad"SU*S0!44
 	T!Q$Yad"T!Q$Y.QT9C1HDs1a4xORUVWYZVZRZZ
a%	 	T!Q$Yad"R1W,tAqDy83q!t8Cd1a4iORUVWRWWZ]]_`aa		 	SAXAqD 2ad7*R1W4r!Q$w>AqDH3q5PSUUWXYYSAXAqD 3q!t8+c!Q$h6adBT!Q$YNQUVWQWWZ]]_`aa	!Q 	SAXAqD 3q!t8+c!e3b8!<<SAXAqD 419,s1u4s:A>>	#s
5E>  0 0S#Ca((C/////0 0r-   c                     t          dt          dz  z  dt          dz  z  z   dt          z  z   dz
  t          d          t          dt          dz  z  d	t          d
z  z  z   dt          dz  z  z   dt          dz  z  z   dt          dz  z  z   dt          dz  z  z   t          d          t          d          t          d          dz  t          d          t          z  dz  z   gt          d          dz  t          d          t          z  dz  z
  ggft          dt          dz  z  dt          dz  z  z   dt          z  z   dz   t          d          t          dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          z  z   dz   t          d          t          d
          dz  t          d          dz  t          d          dz  z   gt          d          dz  t          d          dz  z
  ggft          dt          z  dz   t          d          t          dt          dz  z  ddt          d          z  z
  t          dz  z  z   ddt          d          z  z
  t          dz  z  z   ddt          d          z  z
  t          z  z   dt          d          z  z   d	z   t          d           t          d          t          d          z   dz  t          d          dz  t          t          ddt          d          z  dz   d!"          d#t          d          z  d$z   z  dz             dz  z   gt          d          dz  t          t          ddt          d          z  dz   d!"          d#t          d          z  d$z   z  dz             dz  z
  ggfg} | D ]$\  }}}}t          ||t          |          |k    sJ %d%S )&ab  
    This function tests the Case 1 in the step
    to calculate coefficients of c-vectors.

    Each test case has 4 values -

    1. num - Numerator of the rational function a(x).
    2. den - Denominator of the rational function a(x).
    3. pole - Pole of a(x) for which c-vector is being
       calculated.
    4. c - The c-vector for the pole.
    rb   r>   r?   rR   rM   T	extensionrT      rL   rV   rU   rW   r   r)   i  i  i0  i0     i  i  ie  i  1   ij iz  r   r   r   zQQ<sqrt(3)>domainFrO      ,   N)r   r'   r
   r   r   r   r   )r[   r:   r;   polecs        r+   test_construct_c_case_1r     s    	R1WqAv!#a'd;;;Qq!tVbAg!Q$&AqD01QT69Bq!tGCQRVWWW	!
A$$q&47719Q;
	!A$$q&47719Q;"6!78	 	T!Q$Yad"SU*S0!tDDDSAXAqD 419,tAqDy83q5@2EqTXYYY	!Q
A$$q&4>>#%
%	&1a$x..2D)D(EF	 	QqS1Wa4(((R1WBtAwwJ1,,RQZA/EEQtTUwwYXYHYYQi	7 	7 	7	
1Q
A$$q&4Aqay1}u===r$q''zBORSSTTUVV
V	WqTT!Vd3q!DGG)a-%@@@"T!WW*r/RUVVWWXYYYZ	\E* # : :S$!#sAt4499999: :r-   c                  :   t          dt          d          t          t          dz
  dz  t          dz
  z  t          d          ddt           dt          z
  z  dz  gt          dt          z   z  dz  ggft          dt          dz  z  dt          d	z  z  z
  d
t          dz  z  z
  dz   t          d          t          dt          z  dz
  dz  t          dz   dz  z  t          d          t          d          dz  dt          d           dz  gt          d           dz  ggft          t          dz  t          dz  z
  d	t          z  z   t          d          t          t          dz
  d	z  t          dz   dz  z  t          d          dd	d
t	          d          z  t          d          dz  d	t	          d          z  d
z  z
  z  dz  dt	          d          z  d
z  gdt	          d          z  t          d          dz  d	t	          d          z  d
z  z   z  dz  dt	          d          z  d
z  ggft          dt          dz  z  t          d	z  z   dz   t          d          t          d	t          z  dz   d	z  t          dz   z  t          d          t          d           d	z  d	dt	          d          z  t	          d           dz  t          d          dz  z
  z  dz  t	          d          dz  gdt	          d          z  t	          d          dz  t          d          dz  z
  z  dz  t	          d           dz  ggft          t          dz  dz   t          d          t          dt          z  dz
  dz  t          dz  dz   z  t          d          t          d          dz  ddt	          d          z  t	          d           dz  t          d          dz  z
  z  dz  dt	          d          z  dz  t	          d          d z  gd!t	          d          z  t	          d          dz  t          d          dz  z
  z  dz  dt	          d          z  dz  t	          d           d z  ggft          t          dz  dz   t          d          t          t          t	          d          z
  dz  t          d          t	          d          dt	          d"          t          d          d
z  dt	          d"          z  z
  z  d#z  t	          d
          d
z  t	          d"          gt	          d"           t          d          d
z  dt	          d"          z  z   z  d#z  t	          d
           d
z  t	          d"           ggfg} | D ]&\  }}}}}t          ||t          ||          |k    sJ 'd$S )%a  
    This function tests the Case 2 in the step
    to calculate coefficients of c-vectors.

    Each test case has 5 values -

    1. num - Numerator of the rational function a(x).
    2. den - Denominator of the rational function a(x).
    3. pole - Pole of a(x) for which c-vector is being
       calculated.
    4. mul - The multiplicity of the pole.
    5. c - The c-vector for the pole.
    r)   Tr   r?   rQ   r>   rM   rU   rR   rL   Y   rp   rV   rt   iW  rY   r   i  7   i 8     irW   rl   B   6      i$ r   i  rw   ir      N)r   r'   r   r
   r   r   )r[   r:   r;   r   mulr   s         r+   test_construct_c_case_2r     s   " 	QT"""a!eaZQd333	1"b1f+a-1b1f:a<.)	 	Qq!tVbAg!Q$&*A>>>acAg\1q51*$a4888	!QR55&)!uRxj!	 	QTAqD[1Q3T222a!eaZQ
"A666	1
DGG)QrUU3Y4771,
-b
0!DGG)A+	>	DGGQrUU3Y4771,	-b	0"T!WW*Q,?	A	 	Qq!tVad]QT222acAg\1q5!1555	
1a
d3ii-$s))C!B%%+5
6s
:DIIcM	J	d3iic32u4	5c	9DII:c>J	L	 	QTAXqD)))acAg\1a4!8$a4888	!Q
T"XX+Ry|affVm3
4R
7DHHT9I4PR88TW<	X	T"XXtBxx{QsVVF]2	3B	6$r((
4$r((SVW	Y	 	QTBYT***a$q''kAqD111Q
r((AaDDFQtBxxZ'
(
+T!WWQYR	A
r((AaDDFQtBxxZ'	(	+d1ggXaZ$r((C	E	K+EX #( ? ?S$Q!#sAtS99Q>>>>>? ?r-   c                  2    t                      dggk    sJ dS )z`
    This function tests the Case 3 in the step
    to calculate coefficients of c-vectors.
    r)   N)r    r0   r-   r+   test_construct_c_case_3r     s%    
 QC5((((((r-   c                     t          t          dz   dt          dz  z  z
  dt          dz  z  z   dt          z  z   dz   t          d          t          dt          dz  z  dt          dz  z  z
  dt          z  z   dz
  t          d          ddt          z  d	z  t          dz  d
t          z  t          d          dz  t          dz  z
  z  dz  gdt          z  d	z  t           dz  dt          z  t          d          dz  t          dz  z   z  dz  ggft          t          dz   dt          dz  z  z   dt          dz  z  z   dt          dz  z  z   dt          dz  z  z   dt          z  z   dz   t          d          t          t          dz  dt          dz  z  z   dt          dz  z  z   t          z
  dz   t          d          ddt          z  t          t           dt          z
  z  dz  gdt          z  t           t          dt          z   z  dz  ggft          dt          dz  z  t          dz  z
  t          dz  z
  dt          dz  z  z
  t          dz  z
  dt          z  z
  dz
  t          d          t          dt          dz  z  dt          z  z   dz   t          d          ddt	          d          z  t          z  dz  dt	          d          z  t          z  dz  t	          d          t          z  dz  t	          d           t          z  t          d          dz  dt	          d          z  t          z  dz  z
  z  dz  gdt	          d          z  t          z  dz  dt	          d          z  t          z  dz  t	          d           t          z  dz  t	          d          t          z  t          d          dz  dt	          d          z  t          z  dz  z   z  dz  ggft          d
t          dz  z  dt          dz  z  z
  dt          dz  z  z
  t          dz  z
  dz
  t          d          t          dt          z  dz
  t          d          ddt          z  dz  dt          z  dz  t          dz  t           t          d           d z  t          z
  z  gd!t          z  dz  d"t          z  dz  t           dz  t          t          d           d z  t          z   z  ggft          t          dz   t          dz  z
  t          dz  z
  t          dz  z
  t          z
  t          d          t          t          dz   t          d          dd#t          z  dz  dt          z  t           t          t           d$dt          z  z
  z  dz  gdt          z  dz  dt          z  t          t           t          d$dt          z  z   z  dz  ggft          t          dz   t          dz  z
  dt          dz  z  z
  dt          dz  z  z
  t          dz  z
  t          dz  z
  dt          z  z   dz
  t          d          t          dt          z  dz
  t          d          ddt	          d          z  t          z  dz  dt	          d          z  t          z  dz  t	          d          t          z  dz  t	          d          t          z  dz  t	          d           t          z  t          d           d%z  dt	          d          z  t          z  dz  z
  z  dz  gd
t	          d          z  t          z  dz  d
t	          d          z  t          z  dz  t	          d           t          z  dz  t	          d           t          z  dz  t	          d          t          z  t          d           d%z  dt	          d          z  t          z  dz  z   z  dz  ggfg} | D ]>\  }}}}t          ||t          t          |d          }t          ||dz            |k    sJ ?d&S )'a9  
    This function tests the Case 4 in the step
    to calculate coefficients of the d-vector.

    Each test case has 4 values -

    1. num - Numerator of the rational function a(x).
    2. den - Denominator of the rational function a(x).
    3. mul - Multiplicity of oo as a pole.
    4. d - The d-vector.
    rM   r?   rR   r>   Tr   rV   rv   rl   rb      rh   r   rW   rL   rU   rX   r}   rY   i  r   irz   iIB  i 
  ir)   )      ru   ;   i   ir   rN   r   rT   N)r   r'   r   r
   r   r$   r   r!   )r[   r:   r;   r   dsers         r+   test_construct_d_case_4r     s    	adUQq!tV^a1f$qs*Q.TBBBQq!tVa1f_r!t#a'd;;;	
Q$r'1Q31affSj1Q3./1	2	QrA2a41affSj1Q3./12	4	 	adUQq!tV^a1f$qAv-!Q$61<q@!tTTTQTAadF]R1W$q(1,a4@@@	
Q$A2rAv;q=	!AaC!QQZ\#:;	 	R1Wq!t^ad"Qq!tV+ad2QqS81<a4PPPQq!tVbd]QT222	
d1gg+a-
Sa[]2-tAwwqy{T!WWHQJ%QU
DGG)A+a-I == 
"477l1nS0"T!WW*Q,r/DGG8A:a<Q	1U88D=1T!WW9Q;q=01!35	6	 	R1WqAv!Q$&A-11EEERTAXqD)))	
Q$s(AaCFAaC!aeeVD[1_!5	6	QsBqDGaRT1quufTkAo#67	9	 	adUQT\AqD 1a4'!+Q$???QUA&&&	
Q$q&!A#r1qb"qs(mAo	.1Q1a!QQqS\RS^0TU	 	adUQT\AadF"Qq!tV+ad2QT9AaC?!CQRVWWWQqS1Wa4(((	
DGG)A+a-4771QQ	!T!WWQYq[477(1*qQRtteTUg	$q''	!AO CC 
tAwwJqLNBtAwwJqLNT!WWHQJqL4PQ77(ST*UV,Q	AaDD57QtAwwYq[]*+A-/	0	M-E\ " 4 4S#q%c32sA>>!#sAv..!333334 4r-   c            
      <   t          dt          dz  z  t          dz  z   t          z   dz
  t          d          t          dt          dz  z  dt          dz  z  z   dt          z  z   dz
  t          d          t          d          dz  t          d           dz  gt          d           dz  t          d          dz  ggft          dt          dz  z  t          d	z  z   t          dz  z
  t          dz  z   dt          z  z
  dz
  t          d
          t          dt          dz  z  dt          d	z  z  z   dt          dz  z  z   dt          dz  z  z   dt          z  z   dz   t          d
          t          d          dz  dt          d          z  dz  gt          d           dz  dt          d          z  dz  ggft          t          dz  t          z
  dz   t          d
          t          dt          dz  z  dt          z  z   dz   t          d
          t          d          dz  dt          d          z  dz  gt          d           dz  dt          d          z  dz  ggfg} | D ]9\  }}}t          ||t          t          dd          }t          |          |k    sJ :dS )a  
    This function tests the Case 5 in the step
    to calculate coefficients of the d-vector.

    Each test case has 3 values -

    1. num - Numerator of the rational function a(x).
    2. den - Denominator of the rational function a(x).
    3. d - The d-vector.
    r?   r>   Tr   rV   rM   r)   r|   rR   ZZr   rL   rY   rl   rN   r   N)r   r'   r   r$   r   r"   )r[   r:   r;   r   r   s        r+   test_construct_d_case_5r   E  sm    	Qq!tVad]Q"A666Qq!tVa1f_qs"Q&T:::
q''!)d1ggXc\	"d1ggXaZa$=> 	Qq!tVad]QT!AqD(1Q3.2AdCCCQq!tVa1f_qAv%!Q$.14q8!DIII
q''!)RQZ]	#tAwwhqj!DGG)B,%?@ 	QTAX\1T***Qq!tVac\Aq...
q''!)RQZ\	"d1ggXaZ4771$=>E   , ,S!%c32q!<<!#&&!+++++, ,r-   c            	      \   t          dt          dz  z  dz
  t          d          t          dt          dz  z  dt          dz  z  z   dt          z  z   dz   t          d          t          d          dz  t          dz  z   gt          d          dz  t          dz  z
  ggft          dt          d	z  z  dt          dz  z  z
  dt          z  z
  dz
  t          d          t          t          d
z  t          dz  z
  dt          dz  z  z   dt          d	z  z  z
  dt          dz  z  z
  dt          z  z
  dz   t          d          dgdggft          dt          d	z  z  t          dz  z   dt          z  z   dz   t          d          t          d
t          dz  z  dt          dz  z  z
  dt          d
z  z  z
  dt          dz  z  z
  dt          dz  z  z
  dt          d	z  z  z
  dt          dz  z  z
  dt          z  z
  dz
  t          d          dgdggfg} | D ]"\  }}}t	          ||t                    |k    sJ #dS )a  
    This function tests the Case 6 in the step
    to calculate coefficients of the d-vector.

    Each test case has 3 values -

    1. num - Numerator of the rational function a(x).
    2. den - Denominator of the rational function a(x).
    3. d - The d-vector.
    rY   r?   rM   r   r   rR   rv   r)   r>   rW   rV   r   rN   r   rU   rT   rq   rL   rl   r   .   "   *   N)r   r'   r
   r   r#   )r[   r:   r;   r   s       r+   test_construct_d_case_6r   f  s2    	R1Wq[!D)))Qq!tVa1f_r!t#a'4888
A$$q&1Q3,!A$$q&1Q3,( 	R1WqAv!#a'4888QTAqD[1QT6!AadF*Qq!tV3ac9A=qNNN
qc
 	R1Wq!t^bd"R'4888Qq!tVbAg1a4'"QT'1Bq!tG;bAgE1a4O
Q$t	% 	% 	%
qc
	E"  4 4S!!#sA..!333334 4r-   c                  
   t          t          dz  dt          z  z
  dz   t          d          t          t          dz  t          z
  t          d          t          d          dddd	dd
dd
dft          dt          dz  z  dt          z  z
  dz   t          d          t          dt          dz  z  dt          dz  z  z
  dt          dz  z  z
  dt          z  z   dz
  t          d          t          d          dz  ddt          d          dz  t          d          dz  t          d          dz  t          d          dz  dft          dt          d          t          t          dz  dt          d          z  dz
  t          dz  z  z   dt          d          z  d z   t          dz  z  z   d!dt          d          z  z
  t          dz  z  z   ddt          d          z  z   t          z  z   dz
  t          d          t          d          dddt          d          z   d"dt          d          z  z
  t	          d#d"dt          d          z  z
  d$%          d#t          d          z   z  d"dt          d          z  z
  d#t          d          z   dz  z  t	          d#d"dt          d          z  z
  d$%          d#t          d          z   dz  z  d"dt          d          z  z
  d#t          d          z   dz  z  d&ft          t          dz  dt          dz  z  z
  dt          dz  z  z   d't          z  z   d(z
  t          d          t          t          dz  dz
  t          d          t
          dddd)ddd*d+d,ft          dt          dz  z  dt          dz  z  z   dt          z  z
  dz   t          d          t          dt          dz  z  t          dz  z
  dt          dz  z  z
  dt          z  z   dz   t          d          t          d          dz  d)dt          d-          d.z  t          d/          d0z  t          d1          d2z  t          d3          d4z  t          d5          d6z  d7ft          d8t          dz  z  dt          z  z   dz
  t          d          t          dt          dz  z  dt          dz  z  z   dt          dz  z  z   dt          dz  z  z   dt          z  z   dz   t          d          t
          d)dd)d)t          d9           d:z  d)d#t          d;          dz  d<fg} | D ](\  }}}}}}|t          ||t          |||          k    sJ )d=S )>a  
    This function tests the computation of coefficients
    of Laurent series of a rational function.

    Each test case has 5 values -

    1. num - Numerator of the rational function.
    2. den - Denominator of the rational function.
    3. x0 - Point about which Laurent series is to
       be calculated.
    4. mul - Multiplicity of x0 if x0 is a pole of
       the rational function (0 otherwise).
    5. n - Number of terms upto which the series
       is to be calculated.
    r?   r>   rV   Tr   r)   rW   rL   ir   )r)   r   rQ   rY   rb   rS   @   i  i  rR   r   i?  i  i  rT   i iKi  i  l    `B l   -R i0 i}' )r   r?   rQ   r)   rM   rS   rU   r   rb   rQ   FrO   )rR   r>   r?   r)   r   rQ   rv   r   r   r   r}   )r>   r?   r)   r   rQ   rY   i  i  i i) l   ?PT l   @qs lF41l   @4lJ!tz l    Zdjm )r   rQ   rY   rb   rS   r   G   r   r   )r   rY   rN   rQ   rb   rS   N)r   r'   r
   r   r   r   r$   )r[   r:   r;   x0r   nr   s          r+   test_rational_laurent_seriesr     s(   & 	QTAaCZ!^Q$///QTAXqD)))	!a"!33	 	R1WtAv$a4888R1Wr!Q$wQT)DF2S8!tLLL	!Q1hKK QtWWS[ann[6PV99U?	 		 	QT"""QTRQZ!^QT))QtAwwY^QT,AAS1TRSWW9_VWYZVZDZZqay=!
 !"d	4 	4 	4QAQKB477Ns2rAd1ggI~PU/V/V/VXZ
q''Y 0QtAwwYd1gg(99c"b1TRSWW9n_d ?
 ?
 ?
Q<!
?"$qay.2Q<!2C!C	E 	E 	QTAadF]Qq!tV#bd*R/dCCCQTAXqD)))
Aq!aRR00	 	Qq!tVa1f_qs"Q&T:::Qq!tVad]Qq!tV#ac)A-qDAAA	!Q1dGGDLaii/Qz]]:5Mnm+3D1E1EFV1V	X 	X	 	R1Wqs]QT222Qq!tVa1f_qAv%!Q$.14q8!tLLL
Aq11R55&)"a@@	S.E^ &+ G G!S"c1c-c32sAFFFFFFFG Gr-   c                    t          | t                    r| j        | j        z
  } t	          | t
          t                    \  }}t          t          t                    t          g|R  }t          d          fd|D             }t          d t          | |          D                       sJ t          fdt          ||          D                       sJ dS )z
    Helper function to check if actual solution
    matches expected solution if actual solution
    contains dummy symbols.
    C1c                 <    g | ]}|                               S r0   )r   )r1   rI   r   	dummy_syms     r+   r3   z#check_dummy_sol.<locals>.<listcomp>  s'    444CHHR##444r-   c              3   &   K   | ]}|d          V  dS )r   Nr0   )r1   r'   s     r+   	<genexpr>z"check_dummy_sol.<locals>.<genexpr>  s&      33qt333333r-   c              3   J   K   | ]\  }}|                     |          V  d S )N)dummy_eq)r1   s1s2r   s      r+   r   z"check_dummy_sol.<locals>.<genexpr>  s5      IIfb"r{{2y))IIIIIIr-   N)
isinstancer	   lhsrhsr   r&   r'   r%   r   allr   zip)rH   solser   r2   r   solsr   s     `   @r+   check_dummy_solr     s     "b Vbf_RA&&HAu1q)5)))D	tB44444t444D33[T2233333333IIIID%8H8HIIIIIIIIIIr-   c                  (%   t          d          } t          t          t                                        t                    t          t                    dz  z   dz
  d          t          t          t                    t          d                    t          t          t                    t          d                     gft          t                    dz  t          t                                        t                    z   dt          t                    z  t          z  z   dt          dz  z  z   t          t          t                    d| z  t          z
  | t          z  t          dz  z   z            gfdt          dz  z  t          t                                        t                    z  t          dt          t                    z  t          t                                        t                    z   dz
  z  z
  t          t                    dz
  t          t                    z  z   t          t          t                    | dt          dz  z  z   | t          z   z            gft          t          t                                        t                    t          t                    dz   dt          dz  t          dz  z
  z  z
            t          t          t                    dt          dz  t          z
  z            gft          dz  dt          z  dt          z  z   t          t                    z  z
  t          t                    dz  z   t          t                                        t                    z   t          t          t                    | t          z  t          dz  z   dt          z  z   | t          dz  z   z            t          t          t                    t                    gft          dz  t          t                                        t                    z  t          dz  z   t          dt          t                    dz  z  t          t                                        t                    z   z  z
  t          t                    z   t          t          t                    | t          dz  z  t          z   | t          dz  z   z            t          t          t                    t          dz            gft          t                    dz   t          t                                        t                    z   dt          dz  z  d	t          z  z
  d
z   t          dz
  dz  dt          z  dz
  dz  z  z  z   t          t          t                    d| z  t          z  d| z  z
  dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          z  z
  dz   d| z  t          dz  z  d| z  t          z  z
  d| z  z   dt          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          z  z
  z            t          t          t                    dt          z  dz
  dt          dz  z  dt          z  z
  dz   z            gft          t                    dz  t          t                                        t                    z   dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z   d
t          dz  z  z   d	t          z  z
  dz   dt          dz  z  z  z
  t          t          t                    dt          dz  z  dt          dz  z  z
  t          dz  z
  dt          dz  z  z   dt          z  z   dz
  dt          dz  z  dt          dz  z  z
  z            gft          t          t                                        t                    t          dz   dt          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          z  z
  dz   t          dz  dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          d
z  z  z
  d t          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          dz  z  z
  dt          dz  z  z   dt          z  z
  dz   z  t          t                    dz  z   t          t                    z             t          t          t                    dt          dz  dt          dz  z  z
  dt          dz  z  z   d	t          dz  z  z
  dt          dz  z  z   dt          z  z
  dz   z            gft          t          t                                        t                    t          t          t                    z  dt          z  z   dt          z  dz
  t          t                    dz  z  dt          z  dz   z  z   dt          dz  z  d
t          z  z
  d!z   d"t          dz  z  dt          dz  z  z
  dz   z  z   t          d          dz  z
            t          t          t                    ddt          z  z
  dt          z  dz
  z            gft          t          t                                        t                    d#t          dz  z  d$t          z  z
  dz
  dt          dz  z  dt          dz  z  z
  dt          z  z   dz   z  dt          t                    dz  z  dt          z  dz   z  z             t          t          t                    dt          z  dz   dt          z  dz
  z            gft          t                                        t                    dt          dz  z  dz   t          t                    dz  z  t          z  z   dt          dz  z  t          z
  dz   t          t                    z  t          t          dz
  z  z  z   dt          dz  z  dt          z  z
  dz   t          t          dz
  dz  z  z  z   t          t          t                    |  t          dz  z
  t          dz  z   dt          z  z
  | t          z  | z
  t          dz  z   t          dz  z
  t          dz  z   t          z
  z            t          t          t                    d%t          dz
  z            gft          t                                        t                    dt          z  t          t                    dz  dz   z  t          z  z
  t          t          t                    t           | z  t          t          dz  z  z   | t          dz  z   z            t          t          t                    t                     gft          t          t                                        t                    t          t          t                    z  t          d          dz  dt          z  z
  z  t          dz  t          d          dz  z
  t          t                    dz  z  dt          z  dz  t          d          dz  z
  z  z   t          d          dz  z
  d&t          dz  z  d't          z  z
  d(z   d"t          dz  z  dt          dz  z  z
  z  z             t          t          t                    dt          z
  t          z            t          t          t                    dt          d)z  z  d*t          d+z  z  z   d,t          dz  z  z   d-t          dz  z  z   d.t          dz  z  z   d/t          dz  z  z   d0t          dz  z  z   d1t          d
z  z  z   d2t          dz  z  z   d3t          dz  z  z   d4t          dz  z  z   d5t          dz  z  z   d6t          dz  z  z   d7t          z  z   d8z   dt          d)z  z  d9t          d+z  z  z   d:t          dz  z  z   d;t          dz  z  z   d<t          dz  z  z   d/t          dz  z  z   d=t          dz  z  z   d>t          d
z  z  z   d?t          dz  z  z   d@t          dz  z  z   dAt          dz  z  z   dBt          dz  z  z   dBt          dz  z  z   dCt          z  z   z            gft          t          t                                        t                    dDt          dz  z  dDt          dz  z  z   t           dz  t          d          dz  z
  t          t                    dz  z  z   dz             t          t          t                    dt          z            gft          t          t                                        t                    dEt          dz  z  dz  dt          z  dz  z   t          dz  t          d          dz  z
  t          t                    dz  z  z   dz   dt          z
  t          t                    z  t          z  z   dt          z  z             t          t          t                    dEt          z  dz  dz
            gfg}|D ]\  }}t          |||            dFS )Ga  
    This function tests the computation of rational
    particular solutions for a Riccati ODE.

    Each test case has 2 values -

    1. eq - Riccati ODE to be solved.
    2. sol - Expected solution to the equation.

    Some examples have been taken from the paper - "Statistical Investigation of
    First-Order Algebraic ODEs and their Rational General Solutions" by
    Georg Grasegger, N. Thieu Vo, Franz Winkler

    https://www3.risc.jku.at/publications/download/risc_5197/RISCReport15-19.pdf
    C0r?   r   rR   rY   r)   r>   r   ro   rL   rV   rW   rM   rt   rn   rj   r      9   :   rT   rU   r   rk   ru   r   r   rv        i  i  rq   r   r   0   rQ   i  r   r   r   r   r   r   r   i0H  i iF i4" i< ii2ҍi"0	iimi^   r   i  i<Z  i8X i4 iLB i i|Mi:i r   rb   N)	r   r	   r&   r'   r@   r   r
   r   r   r   r[   rH   rI   s       r+   test_solve_riccatir     s      
tB 	1Q4499Q<<!A$$'!A%q))	AaDD$q''		Bqttd1ggX../ 	
!a!A$$))A,,1Q44)AadF2	AaDD2b519r!tad{+	,	,- 	
!Q$qttyy||a1Q44!A$$))A,,!6!:;;qttax1oM	AaDD2!Q$;a(	)	)* 	1Q4499Q<<!A$$'Aq!tad{O344	AaDD!QTAX,		  	
1!ac	1Q44!A$$')AaDDIIaLL8	AaDD2a4!Q$;1$rAqDy1	2	2BqttQKK@
 	
1QqTTYYq\\AqD 1a!ai!A$$))A,,&>#??!A$$F	AaDD2ad7Q;ad+	,	,b1q!tnn= 
1q1Q4499Q<<2ad7RT>A#5Q
AaCED 9 # 		AaDD1R46AbD=2ad7*R1W4r!Q$w>AqDH
Q$rT!Q$Y2a'!B$.1a47"QT'A
1a4QT'q!tG$&'c*+ 
, 
,-/!qsQw1a4
A#BB 7 . .	 	
!a!A$$))A,,!AqD&1QT6/Bq!tG";a1f"DadF#T## !!Q$"( 	(	AaDD1QT6AadF?QT)AadF2QqS81<qAv1f@  
 
 	 	1Q4499Q<<1a4%"QT'/Bq!tG3bAg=1DqHUR2X1b5(3q!t83c!Q$h>QTICPQSTPTHT1H1a4x "%ad(+-/1W579!t<>?@ACDQ447KMNqTTR 	S 	S 
AaDD!QTAadF]R1W,r!Q$w6AqD@1Q3FJK	L	LM	 	1Q4499Q<<1Q44!A#1q!A$$'(91Q37(CCq!tVac\BAqD2ad7!2Q!678:;A$$q&A 	B 	B	AaDD1qs7QqS1W%	&	&' 	1Q4499Q<<#ad(RT/B.AqD2ad71BQqS1H11LM!ai1q!" 	# 	#	AaDD1Q37QqS1W%	&	&' 	
!		!!Q$
AaDD!G+A--1a4!a10Eq!K H 1 	q!tVac\A%1q51*5	6	AaDDB3A:1$qs*RTBYA-=1-Dq!t-K.  
 
addBAJ''	) 	
!		!qsAaDD!GaK(**	AaDDA2b51QT6>BAI.	/	/AaDD1"> 	1Q4499Q<<1Q441a!A#.!A#!Q,!a1GqSUQqTT!V^2  ttAv&),QTDF):S)@2ad7RPQSTPTWCT(UV 	W 	W	AaDD1q5!)		b11b52ae8(;c!R%i(G$qRTu*(T!R%K) A+)&(.q!t)46=adl)CELQPQT\)RT\qDU)AqD=)!#,QT>)24=adN)CENq[)QS\)] BhQU"SBY.ae;eArEkIFSTVWSWKW1a4K!!Q$,')0A68@AFHPQRTUQUVX`TYQTM"$,QJ/(1 2 2 	3	 	1Q4499Q<<AqD2ad7*qbdQqTT!VmQqTT1W-DDqHII	AaDD!A# 	1Q4499Q<<AqDRT!V+qsQqTT!V|QqTT1W.DDq5!A$$,q.!#$Q3' 	( 	(	AaDD"Q$q&1*		AdEJ  % %CC$$$$% %r-   c            	         t          d          } t          t          t                                        t                    dt          z
  t          t                    z  t          dz
  z  ddt          z  z
  t          t                    dz  z  dt          z  dz
  z  z   dt          dz  z  dt          dz  z  z
  d	t          z  z   d
z
  dt          dz  z  dt          dz  z  z
  dt          dz  z  z   dt          z  z
  dz   z  z   dz             t          t          t                    dt          z  dz   dt          z  dz
  z            gfg}|D ]\  }}t          |||            dS )z
    This function tests the computation of rational
    particular solutions for a Riccati ODE.

    Each test case has 2 values -

    1. eq - Riccati ODE to be solved.
    2. sol - Expected solution to the equation.
    r   r)   r>   r?   rU   rV   i  i/ i i- rT   rR      i*  i  r   r   rW   N)r   r	   r&   r'   r@   r   r   s       r+   test_solve_riccati_slowr   X  sT    
tB 	1Q4499Q<<!a%1q1u-RT1Q4470BAaC!G0LL1a4Z&A+%	1G;a1fs1a4x>ORUVWYZVZRZ>ZF??  ! 	" 	" 
AaDD2a4!8acAg&	'	'(	E  % %CC$$$$% %r-   N)Jsympy.core.randomr   sympy.core.functionr   sympy.core.mulr   sympy.core.numbersr   r   r   sympy.core.relationalr	   sympy.core.singletonr
   sympy.core.symbolr   r   &sympy.functions.elementary.exponentialr   r   %sympy.functions.elementary.hyperbolicr   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   sympy.polys.polytoolsr   sympy.simplify.ratsimpr   sympy.solvers.ode.subscheckr   sympy.testing.pytestr   sympy.solvers.ode.riccatir   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r,   r6   r<   rJ   r`   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r0   r-   r+   <module>r     sp   % % % % % % ( ( ( ( ( (       0 0 0 0 0 0 0 0 0 0 $ $ $ $ $ $ " " " " " " . . . . . . . . = = = = = = = = 6 6 6 6 6 6 9 9 9 9 9 9 8 8 8 8 8 8 & & & & & & * * * * * * 3 3 3 3 3 3 % % % % % %                                    HSMMGCLL
B B BE E E     ?F ?F ?FD36 36 36l`) `) `)F). ). ).X= = =2 2 2.+0 +0 +0\#: #: #:L;? ;? ;?|) ) )<4 <4 <4~, , ,B4 4 4@@G @G @GFJ J J$z% z% z%z % % % % %r-   