o
    8Va                     @   s   d Z ddlmZmZmZmZ ddl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 dddZdddZdddZdddZdddZdS )z  Helpers for randomized testing     )uniformRandom	randrangerandint)is_sequenceas_int)Tuple)compI)Symbol)	nsimplify         FNc                 C   sF   t | |t ||}}|s|t|  S t|d|dtt|d|d  S )a  
    Return a random complex number.

    To reduce chance of hitting branch cuts or anything, we guarantee
    b <= Im z <= d, a <= Re z <= c

    When rational is True, a rational approximation to a random number
    is obtained within specified tolerance, if any.
    T)rational	tolerance)r   r
   r   )abcdr   r   AB r   8/usr/lib/python3/dist-packages/sympy/testing/randtest.pyrandom_complex_number   s   
r   ư>c                    sx   t | ||\} }}t|tr|gn| j|jB }tt| fdd|D }| | }	|| }
t|	|
|S )a  
    Test numerically that f and g agree when evaluated in the argument z.

    If z is None, all symbols will be tested. This routine does not test
    whether there are Floats present with precision higher than 15 digits
    so if there are, your results may not be what you expect due to round-
    off errors.

    Examples
    ========

    >>> from sympy import sin, cos
    >>> from sympy.abc import x
    >>> from sympy.testing.randtest import verify_numerically as tn
    >>> tn(sin(x)**2 + cos(x)**2, 1, x)
    True
    c                    s   g | ]	}t  qS r   )r   ).0_r   r   r   r   r   r   
<listcomp>1   s    z&verify_numerically.<locals>.<listcomp>)	r   
isinstancer   Zfree_symbolslistzipsubsnr	   )fgztolr   r   r   r   ZrepsZz1Zz2r   r   r   verify_numerically   s   "r*   c                 C   sP   ddl m} t||||}| |||}	|| ||}
t|	 |
 |S )a  
    Test numerically that the symbolically computed derivative of f
    with respect to z is correct.

    This routine does not test whether there are Floats present with
    precision higher than 15 digits so if there are, your results may
    not be what you expect due to round-off errors.

    Examples
    ========

    >>> from sympy import sin
    >>> from sympy.abc import x
    >>> from sympy.testing.randtest import test_derivative_numerically as td
    >>> td(sin(x), x)
    True
    r   )
Derivative)Zsympy.core.functionr+   r   Zdiffr$   Zdoit_numericallyr	   r%   )r&   r(   r)   r   r   r   r   r+   Zz0f1f2r   r   r   test_derivative_numerically7   s
   r.   c                    sV   | du rt S t| trt| j S t| r't| } |   d| f fdd	  S td)aG  Return a randrange generator. ``seed`` can be
        o None - return randomly seeded generator
        o int - return a generator seeded with the int
        o list - the values to be returned will be taken from the list
          in the order given; the provided list is not modified.

    Examples
    ========

    >>> from sympy.testing.randtest import _randrange
    >>> rr = _randrange()
    >>> rr(1000) # doctest: +SKIP
    999
    >>> rr = _randrange(3)
    >>> rr(1000) # doctest: +SKIP
    238
    >>> rr = _randrange([0, 5, 1, 3, 4])
    >>> rr(3), rr(3)
    (0, 1)
    Nc                    s   |d u r	d| } }t | t |} }||  }|dk rtdz| }W n ty/   tdw | |  kr;|k r<|S   | ||S )Nr   r   z_randrange got empty rangez!_randrange sequence was too shortr   
ValueErrorpop
IndexErrorr   r   seqwxgiver   r   r8   m   s   
z_randrange.<locals>.givez!_randrange got an unexpected seed)r   r!   intr   r   r"   reverser0   Zseedr   r7   r   
_randrangeP   s   

r<   c                    sT   | du rt S t| trt| j S t| r&t| } |   | f fdd	  S td)aI  Return a randint generator. ``seed`` can be
        o None - return randomly seeded generator
        o int - return a generator seeded with the int
        o list - the values to be returned will be taken from the list
          in the order given; the provided list is not modified.

    Examples
    ========

    >>> from sympy.testing.randtest import _randint
    >>> ri = _randint()
    >>> ri(1, 1000) # doctest: +SKIP
    999
    >>> ri = _randint(3)
    >>> ri(1, 1000) # doctest: +SKIP
    238
    >>> ri = _randint([0, 5, 1, 2, 4])
    >>> ri(1, 3), ri(1, 3)
    (1, 2)
    Nc                    sr   t | t |} }||  }|dk rtdz| }W n ty&   tdw | |  kr2|kr3|S   | ||S )Nr   z_randint got empty rangez_randint sequence was too shortr/   r3   r7   r   r   r8      s   z_randint.<locals>.givez_randint got an unexpected seed)r   r!   r9   r   r   r"   r:   r0   r;   r   r7   r   _randint   s   

r=   )r   r   r   r   FN)Nr   r   r   r   r   )r   r   r   r   r   )N)__doc__Zrandomr   r   r   r   Zsympy.core.compatibilityr   r   Zsympy.core.containersr   Zsympy.core.numbersr	   r
   Zsympy.core.symbolr   Zsympy.simplify.simplifyr   r   r*   r.   r<   r=   r   r   r   r   <module>   s    



1