o
    8Va                     @   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mathZisinfZisnan)x r	   9/usr/lib/python3/dist-packages/sympy/plotting/textplot.pyis_valid   s
   
r   c                 C   s   t  }|| }|| d }t|D ];}t| | rG| | | | }	t|	s+|d qt|	| |d  |d  |  }
t|
}
||
 q|d q|S )zRescale the given array `y` to fit into the integer values
    between `0` and `H-1` for the values between ``mi`` and ``ma``.
       N   )listranger   appendr   roundint)yWHmimaZy_newZnormoffsetr   Z
normalizedZ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   sF   | j }t|dkrtd||r| nt }t|g| }t|}t|}t|||}t	 }|D ]}	z	|
||	 W q3 tttfyO   |
d Y q3w t	tt|}
|
rwt|
}t|
}||krv|rrtdd| g\}}n	d\}}nd\}}|| }tt|dd }|d9 }t||}t||}t|||||}t|||}d	}t|d ddD ]}d
g| }t|D ]V}|| |kr|dks||d  |d kr||d ks||d  |d krd||< q|dks||d  |d kr||d ks||d  |d krd||< qd||< q|dkr#t|D ]}d||< q|d|d |d fv r=d||  |d| }nd
| }d|}||d krS|d
d}|d | V  qd
|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 {})Nr   r   )r   
   r#       /\._z%g -z |)Zfree_symbolslen
ValueErrorformatpopr   r   floatr    r   r   	TypeErrorZeroDivisionErrorfilterr   maxminsortedr   Zfloorlogr   r   r   rjustjoinreplaceljust)exprabr   r   freer   fr   valZy_validr   r   Zy_rangeZ	precisionZy_binsZmarginhsiprefixZbottomr	   r	   r
   textplot_str.   s   


<
B


 "
rG   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)rG   print)r=   r>   r?   r   r   liner	   r	   r
   textplot   s   $
rJ   )r!   r"   )Zsympy.core.numbersr   Zsympy.core.symbolr   Zsympy.utilities.lambdifyr   r   r   r   r    rG   rJ   r	   r	   r	   r
   <module>   s    	
Q