o
    GZh?                     @   sd   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
 G dd deZG d	d
 d
eZdS )z
Physical quantities.
    )
AtomicExpr)Symbol)sympify)_QuantityMapper)Prefixc                   @   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 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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   st   t |ts	t|}|d u r|}n	t |trt|}|| _t| ||}	||	_||	_||	_||	_	||	_
||	_||	_|	S N)
isinstancer   str_is_prefixedr   __new___name_abbrev_latex_reprZ_unicode_reprZ_ascii_reprZ_mathml_repr)
clsnameabbrevZ
latex_reprZpretty_unicode_reprZpretty_ascii_reprZmathml_presentation_repris_prefixedZassumptionsobj r   M/var/www/auris/lib/python3.10/site-packages/sympy/physics/units/quantities.pyr      s    

zQuantity.__new__c                 C   s   |t j| < d S r   )r   Z_quantity_dimension_global)self	dimensionr   r   r   set_global_dimension3   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   
UnitSystemTc                 S   s
   t | tS r   )r	   r   xr   r   r   <lambda>@   s   
 z;Quantity.set_global_relative_scale_factor.<locals>.<lambda>c                 S      | j S r   )scale_factorr   r   r   r   r   A   s    N)	sympy.physics.unitsr   r   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_factor6   s   
z)Quantity.set_global_relative_scale_factorc                 C   r   r   )r   r   r   r   r   r   G   s   zQuantity.namec                 C      ddl m} | }|| S )Nr   r   )r!   r   get_default_unit_systemZget_quantity_dimensionr   r   unit_systemr   r   r   r   K   s   
zQuantity.dimensionc                 C   r   )z
        Symbol representing the unit name.

        Prepend the abbreviation with the prefix symbol if it is defines.
        )r   r$   r   r   r   r   Q   s   zQuantity.abbrevc                 C   r%   )zW
        Overall magnitude of the quantity as compared to the canonical units.
        r   r   )r!   r   r&   Zget_quantity_scale_factorr'   r   r   r   r    Z   s   
zQuantity.scale_factorc                 C      dS NTr   r$   r   r   r   _eval_is_positivec      zQuantity._eval_is_positivec                 C   r)   r*   r   r$   r   r   r   _eval_is_constantf   r,   zQuantity._eval_is_constantc                 C   s   | S r   r   r$   r   r   r   	_eval_Absi   r,   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_subsl   s   zQuantity._eval_subsc                 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)r   printerr   r   r   _latexp   s   zQuantity._latexSIc                 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
        r3   )
convert_to)utilr:   )r   otherr(   r:   r   r   r   r:   w   s   zQuantity.convert_toc                 C   s   t  S )z"Return free symbols from quantity.)setr$   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   r$   r   r   r   r      r?   zQuantity.is_prefixed)NNNNNF)r9   )__name__
__module____qualname____doc__Zis_commutativeZis_realZ	is_numberZ
is_nonzerois_physical_constantZ	_diff_wrtr   r   r#   propertyr   r   r   r    r+   r-   r.   r1   r8   r:   r>   r   r   r   r   r   r      sB    






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)r@   rA   rB   rC   rD   r   r   r   r   rF      s    rF   N)rC   Zsympy.core.exprr   Zsympy.core.symbolr   Zsympy.core.sympifyr   Zsympy.physics.units.dimensionsr   Zsympy.physics.units.prefixesr   r   rF   r   r   r   r   <module>   s     
