U
    9%e                     @   s   d Z ddlmZ ddlmZ ddlZe Zej	Z	ejZej
Z
ejZejZejZejZe ZejZdddZdddZdddZdddZdddZdddZdS )aS  
When you need to use random numbers in SymPy library code, import from here
so there is only one generator working for SymPy. Imports from here should
behave the same as if they were being imported from Python's random module.
But only the routines currently used in SymPy are included here. To use others
import ``rng`` and access the method directly. For example, to capture the
current state of the generator use ``rng.getstate()``.

There is intentionally no Random to import from here. If you want
to control the state of the generator, import ``seed`` and call it
with or without an argument to set the state.

Examples
========

>>> from sympy.core.random import random, seed
>>> assert random() < 1
>>> seed(1); a = random()
>>> b = random()
>>> seed(1); c = random()
>>> assert a == c
>>> assert a != b  # remote possibility this will fail

    )is_sequence)as_intN   c                 C   s    t j| |d tj| |d d S )Naversion)rngseed_assumptions_rngr    r   P/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/core/random.pyr	   ,   s    r	         Fc           
      C   s^   ddl m} ddlm} t| |t|| }}	|s>|||	  S ||d|d|||	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.
    r   )I)	nsimplifyT)rational	tolerance)sympy.core.numbersr   Zsympy.simplify.simplifyr   uniform)
r   bcdr   r   r   r   ABr   r   r   random_complex_number1   s    
r   ư>c                    s   ddl m} ddlm ddlm}	 fdd| |fD \} }|dkrT| j|jB }nt||rd|g}tt	| fdd	|D }
| 
|
 }|
|
 }|	|||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.core.random import verify_numerically as tn
    >>> tn(sin(x)**2 + cos(x)**2, 1, x)
    True
    r   )Symbolsympifycompc                 3   s   | ]} |V  qd S )Nr   ).0ir   r   r   	<genexpr>Y   s     z%verify_numerically.<locals>.<genexpr>Nc                    s   g | ]}t  qS r   )r   )r"   _)r   r   r   r   r   r   
<listcomp>^   s     z&verify_numerically.<locals>.<listcomp>)Zsympy.core.symbolr   Zsympy.core.sympifyr   r   r!   Zfree_symbols
isinstancelistzipsubsn)fgztolr   r   r   r   r   r!   ZrepsZz1Zz2r   )r   r   r   r   r   r   verify_numericallyD   s    
"r0   c                 C   s\   ddl m} ddlm} 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.core.random import test_derivative_numerically as td
    >>> td(sin(x), x)
    True
    r   r    )
Derivative)	r   r!   Zsympy.core.functionr1   r   diffr*   Zdoit_numericallyr+   )r,   r.   r/   r   r   r   r   r!   r1   Zz0f1f2r   r   r   test_derivative_numericallyd   s    r5   c                    s^   | dkrt S t| tr$t|  t S t| rRt| } |   d| f fdd	  S tddS )a8  Return a randrange generator.

    ``seed`` can be

    * None - return randomly seeded generator
    * int - return a generator seeded with the int
    * 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.core.random 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 krd|  } }t | t | } }||  }|dk r<tdz| }W n tk
rd   tdY nX | |  krz|k rn n|S  | ||S d S )Nr   r   z_randrange got empty rangez!_randrange sequence was too shortr   
ValueErrorpop
IndexErrorr   r   seqwxgiver   r   r?      s    
z_randrange.<locals>.givez!_randrange got an unexpected seed)		randranger'   intr   r	   r   r(   reverser7   r	   r   r>   r   
_randrange~   s    

rD   c                    s\   | dkrt S t| tr$t|  t S t| rPt| } |   | f fdd	  S tddS )a:  Return a randint generator.

    ``seed`` can be

    * None - return randomly seeded generator
    * int - return a generator seeded with the int
    * 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.core.random 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                    s   t | t | } }||  }|dk r*tdz| }W n tk
rR   tdY nX | |  krh|krpn n|S  | ||S d S )Nr   z_randint got empty rangez_randint sequence was too shortr6   r:   r>   r   r   r?      s    z_randint.<locals>.givez_randint got an unexpected seed)	randintr'   rA   r   r	   r   r(   rB   r7   rC   r   r>   r   _randint   s    

rF   )Nr   )r   r   r   r   FN)Nr   r   r   r   r   )r   r   r   r   r   )N)N)__doc__Zsympy.utilities.iterablesr   Zsympy.utilities.miscr   random_randomRandomr   choicerE   r@   sampleshuffler   r
   Z_assumptions_shuffler	   r   r0   r5   rD   rF   r   r   r   r   <module>   s&   


 

5