o
    *ήcL#                     @   sx   d 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mZmZ G dd	 d	eZG d
d deZdS )z
Physical quantities.
    )
AtomicExpr)Symbol)sympify)_QuantityMapper)Prefix)sympy_deprecation_warningSymPyDeprecationWarningignore_warningsc                   @   s   e Zd 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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 ur1tdddd |d u r8|}n	t |trAt|}|	| _t| ||}||_||_||_	||_
||_||_|	|_|d ur}tt || W d    n1 sxw   Y  |d urtt || W d    |S 1 sw   Y  |S )Nz
                The 'dimension' argument to to Quantity() is deprecated.
                Instead use the unit_system.set_quantity_dimension() method.
                z1.3z*deprecated-quantity-dimension-scale-factordeprecated_since_versionactive_deprecations_targetz
                The 'scale_factor' argument to to Quantity() is deprecated.
                Instead use the unit_system.set_quantity_scale_factors()
                method.
                )
isinstancer   strr   _is_prefixedr   __new___name_abbrev_latex_repr_unicode_repr_ascii_repr_mathml_reprr	   r   set_dimensionset_scale_factor)clsnameabbrev	dimensionscale_factor
latex_reprpretty_unicode_reprpretty_ascii_reprmathml_presentation_repris_prefixedassumptionsobj r&   E/tmp/pip-target-vg8gfxp4/lib/python/sympy/physics/units/quantities.pyr      sT   

	




zQuantity.__new__SIc                 C   <   t d|  dddd ddlm} ||}|| | d S )Nz
            Quantity.set_dimension() is deprecated. Use either
            unit_system.set_quantity_dimension() or
            z-.set_global_dimension() instead.
            1.5deprecated-quantity-methodsr   r   
UnitSystem)r   sympy.physics.unitsr-   get_unit_systemset_quantity_dimension)selfr   unit_systemr-   r&   r&   r'   r   \      	
zQuantity.set_dimensionc                 C   r)   )Nz
            Quantity.set_scale_factor() is deprecated. Use either
            unit_system.set_quantity_scale_factors() or
            z9.set_global_relative_scale_factor() instead.
            r*   r+   r   r   r,   )r   r.   r-   r/   set_quantity_scale_factor)r1   r   r2   r-   r&   r&   r'   r   j   r3   zQuantity.set_scale_factorc                 C   s   |t j| < d S N)r   _quantity_dimension_global)r1   r   r&   r&   r'   set_global_dimensionx   s   zQuantity.set_global_dimensionc                 C   s\   ddl m} t|}t|trd| _|dd dd }t|}||f|j| < ||j| < dS )zN
        Setting a scale factor that is valid across all unit system.
        r   r,   Tc                 S   s
   t | tS r5   )r   r   xr&   r&   r'   <lambda>   s   
 z;Quantity.set_global_relative_scale_factor.<locals>.<lambda>c                 S      | j S r5   )r   r8   r&   r&   r'   r:      s    N)	r.   r-   r   r   r   r   replace_quantity_scale_factors_global,_quantity_dimensional_equivalence_map_global)r1   r   reference_quantityr-   r&   r&   r'    set_global_relative_scale_factor{   s   
z)Quantity.set_global_relative_scale_factorc                 C   r;   r5   )r   r1   r&   r&   r'   r      s   zQuantity.namec                 C      ddl m} | }|| S )Nr   r,   )r.   r-   get_default_unit_systemget_quantity_dimensionr1   r-   r2   r&   r&   r'   r      s   
zQuantity.dimensionc                 C   r;   )z
        Symbol representing the unit name.

        Prepend the abbreviation with the prefix symbol if it is defines.
        )r   rA   r&   r&   r'   r      s   zQuantity.abbrevc                 C   rB   )zW
        Overall magnitude of the quantity as compared to the canonical units.
        r   r,   )r.   r-   rC   get_quantity_scale_factorrE   r&   r&   r'   r      s   
zQuantity.scale_factorc                 C      dS NTr&   rA   r&   r&   r'   _eval_is_positive      zQuantity._eval_is_positivec                 C   rG   rH   r&   rA   r&   r&   r'   _eval_is_constant   rJ   zQuantity._eval_is_constantc                 C   s   | S r5   r&   rA   r&   r&   r'   	_eval_Abs   rJ   zQuantity._eval_Absc                 C   s   t |tr| |kr| S d S d S r5   )r   r
   )r1   oldnewr&   r&   r'   
_eval_subs   s   zQuantity._eval_subsc                 C   .   t dddd ddlm} ||}|| S )Na  
            Quantity.get_dimensional_expr() is deprecated. It is now
            associated with UnitSystem objects. The dimensional relations
            depend on the unit system used. Use
            unit_system.get_dimensional_expr() instead.
            r*   r+   r   r   r,   )r   r.   r-   r/   get_dimensional_exprexprr2   r-   r&   r&   r'   rQ      s   


zQuantity.get_dimensional_exprc                 C   rP   )zCReturn tuple with scale factor expression and dimension expression.z
            Quantity._collect_factor_and_dimension() is deprecated. This
            method has been moved to the UnitSystem class. Use
            unit_system._collect_factor_and_dimension(expr) instead.
            r*   r+   r   r   r,   )r   r.   r-   r/   _collect_factor_and_dimensionrR   r&   r&   r'   rT      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   formatlenargs)r1   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
        rV   )
convert_to)utilr\   )r1   otherr2   r\   r&   r&   r'   r\      s   zQuantity.convert_toc                 C   s   t  S )z"Return free symbols from quantity.)setrA   r&   r&   r'   free_symbols      zQuantity.free_symbolsc                 C   r;   )zWWhether or not the quantity is prefixed. Eg. `kilogram` is prefixed, but `gram` is not.)r   rA   r&   r&   r'   r#      ra   zQuantity.is_prefixed)NNNNNNNF)r(   )__name__
__module____qualname____doc__is_commutativeis_real	is_number
is_nonzerois_physical_constant	_diff_wrtr   r   r   r7   r@   propertyr   r   r   r   rI   rK   rL   rO   staticmethodrQ   rT   r[   r\   r`   r#   r&   r&   r&   r'   r
      sN    

A






r
   c                   @   s   e Zd ZdZdZdS )PhysicalConstantzLRepresents a physical constant, eg. `speed_of_light` or `avogadro_constant`.TN)rb   rc   rd   re   rj   r&   r&   r&   r'   rn      s    rn   N)re   sympy.core.exprr   sympy.core.symbolr   sympy.core.sympifyr   sympy.physics.units.dimensionsr   sympy.physics.units.prefixesr   sympy.utilities.exceptionsr   r   r	   r
   rn   r&   r&   r&   r'   <module>   s     l