o
    8Va .                     @   s
  d dl m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 g d
ZG dd deZG dd deZG dd de
ZG dd deZdd Zdd Zdd Zdd Zdd Zdd Zejdd  Z ej!e e_d S )!    )
Derivative)UndefinedFunctionAppliedUndef)Symbol)init_printing)LatexPrinter)PrettyPrinter)center_accent)
StrPrinter)
PRECEDENCE)vprint	vsstrreprvsprintvpprintvlatexinit_vprintingc                   @   s    e Zd ZdZdd Zdd ZdS )VectorStrPrinterz'String Printer for vector expressions. c                    s   ddl m} |j tt fdd|jD tt|jd t	@ r:t
|jd j}t|jD ]	\}}||j7 }q.|S t |S )Nr   dynamicsymbolsc                    s   g | ]}| kqS  r   .0itr   ?/usr/lib/python3/dist-packages/sympy/physics/vector/printing.py
<listcomp>       z6VectorStrPrinter._print_Derivative.<locals>.<listcomp>)sympy.physics.vector.functionsr   _tboolsum	variables
isinstancetypeargsr   strfunc	enumerate_strr
   doprint)selfer   Zolr   vr   r   r   _print_Derivative   s   z"VectorStrPrinter._print_Derivativec                 C   sR   ddl m} |j}tt|trt |d| dS |j	j
d| |jd  S )Nr   r   z(%s) z, )r   r   r   r#   r$   r   r
   r*   replacer'   __name__Z	stringifyr%   )r+   r,   r   r   r   r   r   _print_Function   s
   z VectorStrPrinter._print_FunctionN)r1   
__module____qualname____doc__r.   r2   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )VectorStrReprPrinterz+String repr printer for vector expressions.c                 C   s   t |S N)repr)r+   sr   r   r   
_print_str(   s   zVectorStrReprPrinter._print_strN)r1   r3   r4   r5   r:   r   r   r   r   r6   &   s    r6   c                       s.   e Zd ZdZd fdd	Z fddZ  ZS )VectorLatexPrinterz&Latex Printer for vector expressions. Nc                    s   ddl m} |jj}|j}t| d| r%tt|ts%t	| d| ||S tt|trS|j
|fkrSt|}|d urM| |td }| |}d||f S t |S t ||S )Nr   r   Z_print_ZPowz%s^{%s})r   r   r'   r1   r   hasattrr#   r$   r   getattrr%   r   Zparenthesizer   Zparenthesize_supersuperZ_printr2   )r+   exprZexpr   r'   r   base	__class__r   r   r2   /   s   
z"VectorLatexPrinter._print_Functionc                    s&  ddl m} | }t|tsd| | S |j |j}|t	}|j
}t fdd|D  }t fdd|D  }|s@|rFt |S t|}| |}	|	dd}
|
d }	|dkrbd	|	 }	n!|d
krkd|	 }	n|dkrtd|	 }	n|dkr}d|	 }	nt |S t|
dkr|	d|
d  7 }	|	S )Nr   r   z\left(%s\right)c                    s   g | ]
}|j  hkrd qS )T)Zfree_symbolsr   r   r   r   r   Q   s    z8VectorLatexPrinter._print_Derivative.<locals>.<listcomp>c                    s   g | ]} |kqS r   r   r   r   r   r   r   R   r   _   z\dot{%s}   z	\ddot{%s}   z
\dddot{%s}   z\ddddot{%s})r   r   Zdoitr#   r   r*   r   r?   Zatomsr   r"   allr>   r.   lenr2   split)r+   Zder_exprr   r?   ZredsymsZtest1Ztest2dotsr@   Z
base_splitrA   r   r   r.   E   s8   






z$VectorLatexPrinter._print_Derivativer7   )r1   r3   r4   r5   r2   r.   __classcell__r   r   rA   r   r;   ,   s    r;   c                       s,   e Zd ZdZ fddZ fddZ  ZS )VectorPrettyPrinterz)Pretty Printer for vectorialexpressions. c                    s>  ddl m} |j}d}tt|j}t|dkr3|d |kr'|  |d7 }nt 	|S t|dkst
t|jtrB|jj|fksHt 	|S | |j}t|jdkr[t 	|S |dkret 	|S dddd	d
d}|j}| jsd}	td|D ]}
|	d7 }	qz|d d  |	d 7  < |S t|d d || g|d< |S )Nr   r   rD      r/   u   ̇u   ̈u   ⃛u   ⃜)r   rD   rE   rF   rG   'picturez(t))r   r   r   listreversedr"   rI   popr>   r.   r#   r$   r?   r   r%   r2   rR   __dict__Z_use_unicoderanger	   )r+   Zderivr   r   Zdot_irK   pformrL   dZapostrophesr   rA   r   r   r.   m   sD   

z%VectorPrettyPrinter._print_Derivativec                    sV   ddl m} |j}|j}|j}|j}| t|}t|t	r#||fks)t
 |S |S )Nr   r   )r   r   r   r'   r%   r1   Z_print_Symbolr   r#   r   r>   r2   )r+   r,   r   r   r'   r%   Z	func_namerX   rA   r   r   r2      s   z#VectorPrettyPrinter._print_Function)r1   r3   r4   r5   r.   r2   rM   r   r   rA   r   rN   j   s    /rN   c                 K   s6   t | fi |}ddl}|dkr||_t| dS dS )aJ  Function for printing of expressions generated in the
    sympy.physics vector package.

    Extends SymPy's StrPrinter, takes the same setting accepted by SymPy's
    :func:`~.sstr`, and is equivalent to ``print(sstr(foo))``.

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to print.
    settings : args
        Same as the settings accepted by SymPy's sstr().

    Examples
    ========

    >>> from sympy.physics.vector import vprint, dynamicsymbols
    >>> u1 = dynamicsymbols('u1')
    >>> print(u1)
    u1(t)
    >>> vprint(u1)
    u1

    r   NNone)r   builtinsrC   print)r?   settingsZoutstrr[   r   r   r   r      s   r   c                 K      t |}|| S )a  Function for displaying expression representation's with vector
    printing enabled.

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to print.
    settings : args
        Same as the settings accepted by SymPy's sstrrepr().

    )r6   r*   )r?   r]   pr   r   r   r      s   
r   c                 K   r^   )a  Function for displaying expressions generated in the
    sympy.physics vector package.

    Returns the output of vprint() as a string.

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to print
    settings : args
        Same as the settings accepted by SymPy's sstr().

    Examples
    ========

    >>> from sympy.physics.vector import vsprint, dynamicsymbols
    >>> u1, u2 = dynamicsymbols('u1 u2')
    >>> u2d = dynamicsymbols('u2', level=1)
    >>> print("%s = %s" % (u1, u2 + u2d))
    u1(t) = u2(t) + Derivative(u2(t), t)
    >>> print("%s = %s" % (vsprint(u1), vsprint(u2 + u2d)))
    u1 = u2 + u2'

    )r   r*   )r?   r]   Zstring_printerr   r   r   r      s   
r   c                 K   sF   t |}|jd }ddlm} ||}z
|| W || S || w )a  Function for pretty printing of expressions generated in the
    sympy.physics vector package.

    Mainly used for expressions not inside a vector; the output of running
    scripts and generating equations of motion. Takes the same options as
    SymPy's :func:`~.pretty_print`; see that function for more information.

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to pretty print
    settings : args
        Same as those accepted by SymPy's pretty_print.


    use_unicoder   )pretty_use_unicode)rN   Z	_settings&sympy.printing.pretty.pretty_symbologyra   r*   )r?   r]   ppr`   ra   Zuflagr   r   r   r      s   

r   c                 K   r^   )a  Function for printing latex representation of sympy.physics.vector
    objects.

    For latex representation of Vectors, Dyadics, and dynamicsymbols. Takes the
    same options as SymPy's :func:`~.latex`; see that function for more information;

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to represent in LaTeX form
    settings : args
        Same as latex()

    Examples
    ========

    >>> from sympy.physics.vector import vlatex, ReferenceFrame, dynamicsymbols
    >>> N = ReferenceFrame('N')
    >>> q1, q2 = dynamicsymbols('q1 q2')
    >>> q1d, q2d = dynamicsymbols('q1 q2', 1)
    >>> q1dd, q2dd = dynamicsymbols('q1 q2', 2)
    >>> vlatex(N.x + N.y)
    '\\mathbf{\\hat{n}_x} + \\mathbf{\\hat{n}_y}'
    >>> vlatex(q1 + q2)
    'q_{1} + q_{2}'
    >>> vlatex(q1d)
    '\\dot{q}_{1}'
    >>> vlatex(q1 * q2d)
    'q_{1} \\dot{q}_{2}'
    >>> vlatex(q1dd * q1 / q1d)
    '\\frac{q_{1} \\ddot{q}_{1}}{\\dot{q}_{1}}'

    )r;   r*   )r?   r]   latex_printerr   r   r   r   !  s   #
r   c                  K   s*   t | d< t| d< t| d< tdi |  dS )a  Initializes time derivative printing for all SymPy objects, i.e. any
    functions of time will be displayed in a more compact notation. The main
    benefit of this is for printing of time derivatives; instead of
    displaying as ``Derivative(f(t),t)``, it will display ``f'``. This is
    only actually needed for when derivatives are present and are not in a
    physics.vector.Vector or physics.vector.Dyadic object. This function is a
    light wrapper to :func:`~.init_printing`. Any keyword
    arguments for it are valid here.

    {0}

    Examples
    ========

    >>> from sympy import Function, symbols
    >>> t, x = symbols('t, x')
    >>> omega = Function('omega')
    >>> omega(x).diff()
    Derivative(omega(x), x)
    >>> omega(t).diff()
    Derivative(omega(t), t)

    Now use the string printer:

    >>> from sympy.physics.vector import init_vprinting
    >>> init_vprinting(pretty_print=False)
    >>> omega(x).diff()
    Derivative(omega(x), x)
    >>> omega(t).diff()
    omega'

    Zstr_printerZpretty_printerrd   Nr   )r   r   r   r   )kwargsr   r   r   r   I  s   !r   zExamples
    ========N)"Zsympyr   Zsympy.core.functionr   r   Zsympy.core.symbolr   Zsympy.interactive.printingr   Zsympy.printing.latexr   Zsympy.printing.pretty.prettyr   rb   r	   Zsympy.printing.strr
   Zsympy.printing.precedencer   __all__r   r6   r;   rN   r   r   r   r   r   r   r5   rJ   paramsformatr   r   r   r   <module>   s,    >B#"(&