o
    8Va                     @   sP   d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 G dd deZdS )	z
Physical quantities.
    )
AtomicExprSymbolsympify)_QuantityMapper)Prefix)SymPyDeprecationWarningc                   @   s   e Zd ZdZdZdZdZdZdZ			d*ddZ	d+dd	Z
d+d
dZdd Zdd Zedd Zedd Zedd Zedd Zdd Zdd Zdd Zdd Zed+d d!Zed+d"d#Zd$d% Zd+d&d'Zed(d) ZdS ),QuantityzX
    Physical quantity: can be a unit of measure, a constant or a generic quantity.
    TFNc	                 K   s   t |ts	t|}t |tst |ts|||}}}|d ur)tddddd  |d ur7tddddd  |d u r>|}n	t |trGt|}t| ||}
||
_||
_||
_	||
_
||
_||
_|d uri|
| |d urr|
| |
S )Nz1.3i7  zQuantity argumentsz&unit_system.set_quantity_dimension_mapZdeprecated_since_versionZissueZfeatureZ
useinsteadZSI_quantity_scale_factors)
isinstancer   strr   warnr   __new___name_abbrev_latex_reprZ_unicode_reprZ_ascii_reprZ_mathml_reprset_dimensionset_scale_factor)clsnameabbrev	dimensionscale_factorZ
latex_reprZpretty_unicode_reprZpretty_ascii_reprZmathml_presentation_reprZassumptionsobj r   @/usr/lib/python3/dist-packages/sympy/physics/units/quantities.pyr      sL   




zQuantity.__new__SIc                 C   @   t dddd| d  ddlm} ||}|| | d S )N1.5eE  !Moving method to UnitSystem classzIunit_system.set_quantity_dimension or {}.set_global_relative_scale_factorr	   r   
UnitSystem)r   formatr   sympy.physics.unitsr!   get_unit_systemZset_quantity_dimension)selfr   unit_systemr!   r   r   r   r   J      
zQuantity.set_dimensionc                 C   r   )Nr   r   r   zLunit_system.set_quantity_scale_factor or {}.set_global_relative_scale_factorr	   r   r    )r   r"   r   r#   r!   r$   Zset_quantity_scale_factor)r%   r   r&   r!   r   r   r   r   U   r'   zQuantity.set_scale_factorc                 C   s   |t j| < d S N)r   Z_quantity_dimension_global)r%   r   r   r   r   set_global_dimension`   s   zQuantity.set_global_dimensionc                 C   sL   ddl m} t|}|dd dd }t|}||f|j| < ||j| < dS )zN
        Setting a scale factor that is valid across all unit system.
        r   r    c                 S   s
   t | tS r(   )r
   r   xr   r   r   <lambda>k   s   
 z;Quantity.set_global_relative_scale_factor.<locals>.<lambda>c                 S      | j S r(   )r   r*   r   r   r   r,   l   s    N)r#   r!   r   replaceZ_quantity_scale_factors_globalZ,_quantity_dimensional_equivalence_map_global)r%   r   Zreference_quantityr!   r   r   r    set_global_relative_scale_factorc   s   z)Quantity.set_global_relative_scale_factorc                 C   r-   r(   )r   r%   r   r   r   r   r   s   zQuantity.namec                 C      ddl m} | }|| S )Nr   r    )r#   r!   get_default_unit_systemZget_quantity_dimensionr%   r!   r&   r   r   r   r   v   s   
zQuantity.dimensionc                 C   r-   )z
        Symbol representing the unit name.

        Prepend the abbreviation with the prefix symbol if it is defines.
        )r   r0   r   r   r   r   |   s   zQuantity.abbrevc                 C   r1   )zW
        Overall magnitude of the quantity as compared to the canonical units.
        r   r    )r#   r!   r2   Zget_quantity_scale_factorr3   r   r   r   r      s   
zQuantity.scale_factorc                 C      dS NTr   r0   r   r   r   _eval_is_positive      zQuantity._eval_is_positivec                 C   r4   r5   r   r0   r   r   r   _eval_is_constant   r7   zQuantity._eval_is_constantc                 C   s   | S r(   r   r0   r   r   r   	_eval_Abs   r7   zQuantity._eval_Absc                 C   s   t |tr| |kr| S d S d S r(   )r
   r   )r%   oldnewr   r   r   
_eval_subs   s   zQuantity._eval_subsc                 C   4   t ddddd  ddlm} ||}|| S )Nr   r   z{get_dimensional_expr() is now associated with UnitSystem objects. The dimensional relations depend on the unit system used.z unit_system.get_dimensional_exprr	   r   r    )r   r   r#   r!   r$   get_dimensional_exprexprr&   r!   r   r   r   r>      s   

zQuantity.get_dimensional_exprc                 C   r=   )zCReturn tuple with scale factor expression and dimension expression.r   r   z3This method has been moved to the UnitSystem class.z)unit_system._collect_factor_and_dimensionr	   r   r    )r   r   r#   r!   r$   _collect_factor_and_dimensionr?   r   r   r   rA      s   

z&Quantity._collect_factor_and_dimensionc                 C   s6   | j r| j S dt| jdkr| jd S | jd S )Nz\text{{{}}}      r   )r   r"   lenargs)r%   Zprinterr   r   r   _latex   s   zQuantity._latexc                 C   s   ddl m} || ||S )a  
        Convert the quantity to another quantity of same dimensions.

        Examples
        ========

        >>> from sympy.physics.units import speed_of_light, meter, second
        >>> speed_of_light
        speed_of_light
        >>> speed_of_light.convert_to(meter/second)
        299792458*meter/second

        >>> from sympy.physics.units import liter
        >>> liter.convert_to(meter**3)
        meter**3/1000
        rC   )
convert_to)utilrG   )r%   otherr&   rG   r   r   r   rG      s   zQuantity.convert_toc                 C   s   t  S )z"Return free symbols from quantity.)setr0   r   r   r   free_symbols   s   zQuantity.free_symbols)NNNNNNN)r   )__name__
__module____qualname____doc__Zis_commutativeZis_realZ	is_numberZ
is_nonzeroZ	_diff_wrtr   r   r   r)   r/   propertyr   r   r   r   r6   r8   r9   r<   staticmethodr>   rA   rF   rG   rK   r   r   r   r   r      sF    

4





r   N)rO   Zsympyr   r   r   Zsympy.physics.units.dimensionsr   Zsympy.physics.units.prefixesr   Zsympy.utilities.exceptionsr   r   r   r   r   r   <module>   s    