o
    §ƒðjÓ  ã                   @   s\   d dl mZ d dlmZ d dlmZ d dlZdd„ Zdd„ Zd	d
„ Z	ddd„Z
ddd„ZdS )é    )ÚFloat)ÚDummy)ÚlambdifyNc                 C   s2   | du rdS t | tƒrdS t | ¡ ot | ¡ S )z)Check if a floating point number is validNF)Ú
isinstanceÚcomplexÚmathÚisinfÚisnan)Úx© r   ú™/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/plotting/textplot.pyÚis_valid   s
   
r   c                 C   sœ   g }|| }|| d }t |ƒD ];}t| | ƒrF| | | | }	t|	ƒs*| d¡ qt|	| |d  |d  | ƒ ¡ }
t|
ƒ}
| |
¡ q| d¡ q|S )zƒRescale the given array `y` to fit into the integer values
    between `0` and `H-1` for the values between ``mi`` and ``ma``.
    é   Né   )Úranger   Úappendr   ÚroundÚint)ÚyÚWÚHÚmiÚmaÚy_newÚnormÚoffsetr
   Ú
normalizedÚrescaledr   r   r   Úrescale   s   $r   c                    s   ‡ ‡‡fdd„t ˆ ƒD ƒS )Nc                    s$   g | ]}ˆˆˆ | ˆ d    ‘qS )r   r   )Ú.0r
   ©ÚnumÚstartÚstopr   r   Ú
<listcomp>)   s   $ zlinspace.<locals>.<listcomp>)r   )r"   r#   r!   r   r    r   Úlinspace(   s   r%   é7   é   c                 c   sx  � | j }t|ƒdkrtd |¡ƒ‚|r| ¡ ntƒ }t|g| ƒ}t|tƒr-|j	dkr-|j
}t|tƒr:|j	dkr:|j
}t|ƒ}t|ƒ}t|||ƒ}g }|D ]}	z	| ||	ƒ¡ W qL tttfyh   | d¡ Y qLw ttt|ƒƒ}
|
r�t|
ƒ}t|
ƒ}||kr�|r‹tdd| gƒ\}}n	d\}}nd\}}|| }t t |¡¡d }|d9 }t||ƒ}t||ƒ}t|||||ƒ}t|||ƒ}d}t|d ddƒD ]«}d	g| }t|ƒD ]W}|| |k�r*|dksê||d  |d krÿ||d ksú||d  |d krÿd
||< qÓ|dk�s||d  |d k�r&||d k�s!||d  |d k�r&d||< qÓd||< qÓ|dk�r<t|ƒD ]}d||< �q4|d|d |d fv �rVd||   |¡d|… }nd	| }d |¡}||d k�rl| d	d¡}|d | V  qÈd	|d  }|d|d   |d ¡7 }|d dk�rž|d||d    |d ¡7 }n|d||d    |d d ¡7 }|d|d  7 }|V  dS )z#Generator for the lines of the plotr   z4The expression must have a single variable. (Got {})r   Nr   )éÿÿÿÿr   r(   é   ú ú/ú\Ú.Ú_z%gÚ ú-z |) Úfree_symbolsÚlenÚ
ValueErrorÚformatÚpopr   r   r   r   ÚimagÚrealÚfloatr%   r   Ú	TypeErrorÚZeroDivisionErrorÚlistÚfilterr   ÚmaxÚminÚsortedr   ÚfloorÚlog10r   r   r   ÚrjustÚjoinÚreplaceÚljust)ÚexprÚaÚbr   r   Úfreer
   Úfr   ÚvalÚy_validr   r   Úy_rangeÚ	precisionÚy_binsÚmarginÚhÚsÚiÚprefixÚbottomr   r   r   Útextplot_str,   sŒ   €þ



ÿ€


<
D
€

 "
rV   c                 C   s"   t | ||||ƒD ]}t|ƒ qdS )aÃ  
    Print a crude ASCII art plot of the SymPy expression 'expr' (which
    should contain a single symbol, e.g. x or something else) over the
    interval [a, b].

    Examples
    ========

    >>> from sympy import Symbol, sin
    >>> from sympy.plotting import textplot
    >>> t = Symbol('t')
    >>> textplot(sin(t)*t, 0, 15)
     14 |                                                  ...
        |                                                     .
        |                                                 .
        |                                                      .
        |                                                .
        |                            ...
        |                           /   .               .
        |                          /
        |                         /      .
        |                        .        .            .
    1.5 |----.......--------------------------------------------
        |....       \           .          .
        |            \         /                      .
        |             ..      /             .
        |               \    /                       .
        |                ....
        |                                    .
        |                                     .     .
        |
        |                                      .   .
    -11 |_______________________________________________________
         0                          7.5                        15
    N)rV   Úprint)rF   rG   rH   r   r   Úliner   r   r   Útextplotƒ   s   $
ÿrY   )r&   r'   )Úsympy.core.numbersr   Úsympy.core.symbolr   Úsympy.utilities.lambdifyr   r   r   r   r%   rV   rY   r   r   r   r   Ú<module>   s    	
W