o
    §ƒðj?  ã                   @   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_reprÚ_unicode_reprÚ_ascii_reprÚ_mathml_repr)
ÚclsÚnameÚabbrevÚ
latex_reprÚpretty_unicode_reprÚpretty_ascii_reprÚmathml_presentation_reprÚis_prefixedÚassumptionsÚobj© r   ú /tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/physics/units/quantities.pyr      s    

zQuantity.__new__c                 C   s   |t j| < d S r   )r   Ú_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   ÚreplaceÚ_quantity_scale_factors_globalÚ,_quantity_dimensional_equivalence_map_global)r    r)   Ú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_systemÚ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   r0   r   r   r   r   Q   s   zQuantity.abbrevc                 C   r1   )zW
        Overall magnitude of the quantity as compared to the canonical units.
        r   r#   )r*   r$   r2   Úget_quantity_scale_factorr4   r   r   r   r)   Z   s   
zQuantity.scale_factorc                 C   ó   dS ©NTr   r0   r   r   r   Ú_eval_is_positivec   ó   zQuantity._eval_is_positivec                 C   r7   r8   r   r0   r   r   r   Ú_eval_is_constantf   r:   zQuantity._eval_is_constantc                 C   s   | S r   r   r0   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
        rA   )Ú
convert_to)ÚutilrH   )r    Úotherr5   rH   r   r   r   rH   w   s   zQuantity.convert_toc                 C   s   t ƒ S )z"Return free symbols from quantity.)Úsetr0   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   r0   r   r   r   r   �   rM   zQuantity.is_prefixed)NNNNNF)rG   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_commutativeÚis_realÚ	is_numberÚ
is_nonzeroÚis_physical_constantÚ	_diff_wrtr   r"   r/   Úpropertyr   r!   r   r)   r9   r;   r<   r?   rF   rH   rL   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)rN   rO   rP   rQ   rV   r   r   r   r   rY   •   s    rY   N)rQ   Úsympy.core.exprr   Úsympy.core.symbolr   Úsympy.core.sympifyr   Úsympy.physics.units.dimensionsr   Úsympy.physics.units.prefixesr   r   rY   r   r   r   r   Ú<module>   s     
