o
    hk                     @   s  d Z ddl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mZmZmZ ddlmZ ddlmZ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$ edZ%edZ&edZ'edZ(ed\Z)Z*Z+ede&e'Z,ede,e(Z-edZ.edZ/edZ0edZ1ej23de.ge&gfe/ge&gfe0ge&gfe1ge&gfe&ge&gfe'ge&gfe&e' ge&gfe&e' ge&gfe&d ge&gfe&e' ge&gfee&ge&gfee&ge&gfe e&ge&gfe.e/e&e'e&e' e&e' ge&e'gfe&e' ee&e'  ee' e&e' ee'  ge&e'gfe%e e'e(  e&e e'e(   e%e& e e'e(  e&e e'e(   ge%e&e'e(gfe)d e* e*d e+ e+d e) ge)e*e+gfe-e
e-e& e, de&  ge&gfgdd Z4dd Z5d d! Z6d"d# Z7d$d% Z8d&d' Z9d(d) Z:d*d+ Z;d,d- Z<dS ).z5Tests for the ``sympy.simplify._cse_diff.py`` module.    N)Symbolsymbols)Integer)Function)
Derivative)exp)ImmutableDenseMatrix)dynamicsymbols)_forward_jacobian_remove_cse_from_derivative_forward_jacobian_cse!_forward_jacobian_norm_in_cse_out)simplify)Matrixeye)raises)cossintan)trigsimp)csewxyzzq1 q2 q3kf      z	expr, wrtc                 C   sL   t | gj} t |gj}t| |}t j|j }t|| | |ks$J d S N)r   Tr
   zerosshaper   jacobian)exprwrtr$   r"    r'   X/var/www/html/ai/venv/lib/python3.10/site-packages/sympy/simplify/tests/test_cse_diff.pytest_forward_jacobian+   s
   
r)   c                  C   s  t d\} }}td}td}t||| ||t||| |||  || | d|   g}t|\}}t||\}}	t d}
t d}|
|| |f|||
|fgtd|  |
 | t||| |||  ggf}||d kszJ d|d  d	| |	|d
 ksJ d|d
  d	|	 d S )Nx y zr   r   r   x0x1r   z	Expected z
, but got r   )r   r   r   r   r   r   )r   r   r   r   r   r%   replreducedp_repl	p_reducedr+   r,   expected_outputr'   r'   r(   test_process_cseL   s   >,$(r2   c                  C   s   t d\} }}t| | ||  | | |  | d |d  |d  | | | |  ||  g}t| ||g}t|\}}t|||\}}}	t|d t|d sSJ dt||\}
}}t|d t|d sjJ dt||}t|t|szJ dd S )Nr*   r   r   z9Jacobian should be a Matrix of the same type as the input)r   r   r   r   
isinstancetyper   r
   )r   r   r   r%   r&   replacementsreduced_exprreplacements_corejacobian_coreprecomputed_fs_corereplacements_normjacobian_normprecomputed_fs_normr$   r'   r'   r(   test_io_matrix_type`   s    

r=   c                  C   s  t d\} }}t| | ||  | | |  | d |d  |d  | | | |  ||  g}t| ||g}t|\}}t|||\}}}	t|t|sOJ dt|t|sZJ dt|	tscJ dt|t|ksoJ dt|dksyJ dt|	t|ksJ d	t||\}
}}t|
t|sJ dt|t|sJ dt|tsJ dt|
t|ksJ dt|dksJ dt|t|ksJ d	d S )
Nr*   r   zReplacements should be a listzJacobian should be a listz)Precomputed free symbols should be a listz%Length of replacements does not matchr   z Jacobian should have one elementz1Length of precomputed free symbols does not match)	r   r   r   r   r3   r4   listlenr   )r   r   r   r%   r&   r5   r6   r7   r8   r9   r:   r;   r<   r'   r'   r(   "test_forward_jacobian_input_outputy   s,   r@   c                  C   s   t ddtd t dtd  tt  g} ttg}t| |t dt t td gtdt t ggks3J t ddttd td  g} t| |t ddgdt td  td d td  ggks`J d S )Nr   r         r   )r   r   r   r
   )Lsymsr'   r'   r(   test_jacobian_hessian   s
   (6BrE   c                  C   s   t d\} }t| t| | t| g}t| |g}t||}|||jks)J ||j|ks3J ||j|jks>J |jt|jd  | }|	t
}|tddgd| d ggks_J d S )Nrho,phir   r   r   )r   r   r   r   r
   r$   r!   r   r#   	applyfuncr   )rhophiXYJgr'   r'   r(   test_jacobian_metrics   s   

$rN   c                  C   s   t d\} }t| t| | t| | d g}t| |g}tt||  t| gt|| t| gd|  dgg}t|||ksBJ d S )NrF   r   r   )r   r   r   r   r
   )rH   rI   rJ   rK   rL   r'   r'   r(   test_jacobian2   s   "
rO   c                  C   s   t ttt t ttt t ttt t g} t tttg}tddD ]D}tddD ]<}| d |d d f }|d |d d f }t||}|j|ksNJ |j|ksUJ t|D ]}|d d |f |ksgJ qYq,q%d S )Nr   rB   )	r   r   r   r   r   ranger
   rowscols)rJ   rK   ijX_sliceY_slicerL   r   r'   r'   r(   test_issue_4564   s   2
rW   c                      s   t ttt t ttt t gttt t ttt t gg tt fdd  dd d f  t ttgttggtt fdd tt fdd d S )Nc                      s   t  ttttgS r    r
   r   r   r   r   r'   rJ   r'   r(   <lambda>   s    z(test_nonvectorJacobian.<locals>.<lambda>r   c                      s
   t  S r    )r
   r'   rJ   rK   r'   r(   rZ      s   
 c                      s   t  tttgttggS r    rX   r'   rY   r'   r(   rZ      s    )r   r   r   r   r   r   	TypeErrorr'   r'   r[   r(   test_nonvectorJacobian   s    r]   )=__doc__pytestsympy.core.symbolr   r   sympy.core.numbersr   sympy.core.functionr   
sympy.corer   &sympy.functions.elementary.exponentialr   sympy.matrices.immutabler   sympy.physics.mechanicsr	   sympy.simplify._cse_diffr
   r   r   r   sympy.simplify.simplifyr   sympy.matricesr   r   sympy.testing.pytestr   (sympy.functions.elementary.trigonometricr   r   r   sympy.simplify.trigsimpr   sympyr   r   r   r   r   q1q2q3r   r   zeroonetwoneg_onemarkparametrizer)   r2   r=   r@   rE   rN   rO   rW   r]   r'   r'   r'   r(   <module>   st    





4N* 
	