K idZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZdd lmZd d lmZGd d eZy)zG Unit system for physical quantities; include definition of constants. ) annotations)Add) DerivativeFunction)Mul)Pow)S)_QuantityMapperQuantity) DimensionceZdZUdZiZded<ddddifdfd ZdZd Zddddifdd Z d Z fd Z fd Z e dZe dZedZedZeddZdZdZddZxZS) UnitSystemz UnitSystem represents a coherent set of units. A unit system is basically a dimension system with notions of scales. Many of the methods are defined in the same way. It is much better if all base units have a symbol. zdict[str, UnitSystem] _unit_systemsNc|tj|<||_||_||_||_t t|t|z|_t ||_||_ t|-yN) rrnamedescr _base_units_dimension_systemtupleset_units_derived_unitssuper__init__)self base_unitsunitsrrdimension_system derived_units __class__s d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/units/unitsystem.pyrzUnitSystem.__init__sj)-   &  %!1C Oc%j89  ,+ c|jdk7r |jSddjd|jDzS)z Return the name of the system. If it does not exist, then it makes a list of symbols (or names) of the base dimensions. rzUnitSystem((%s)), c32K|]}t|ywr)str).0ds r& z%UnitSystem.__str__..7s22A22s)rjoinrr s r&__str__zUnitSystem.__str__,sD 99?99 % 22 $ 0 022)22 2r'c2dt|jzS)Nz)reprrr0s r&__repr__zUnitSystem.__repr__:s!D)9)9$:::r'c |jt|z}|jt|z}t|||||i|j|S)aExtend the current system into a new one. Take the base and normal units of the current system to merge them to the base and normal units given in argument. If not provided, name and description are overridden by empty strings. )rrrrr)r baser"r descriptionr#r$s r&extendzUnitSystem.extend=sR%+- eEl*$t[:JLttObObLtfsLtuur'c|jSr)rr0s r&get_dimension_systemzUnitSystem.get_dimension_systemJs%%%r'ch|jj}||vr||St| |Sr)r:_quantity_dimension_maprget_quantity_dimension)r unitqdmr%s r&r=z!UnitSystem.get_quantity_dimensionMs8'')AA 3;t9 w-d33r'ch|jj}||vr||St| |Sr)r:_quantity_scale_factorsrget_quantity_scale_factor)r r>qsfmr%s r&rBz$UnitSystem.get_quantity_scale_factorSs8((*BB 4<: w066r'c t|tr|S|tjvr@tdj dj t tjtj|S)NzDUnit system is not supported. Currentlysupported unit systems are {}r)) isinstancerr ValueErrorformatr/sorted) unit_systems r&get_unit_systemzUnitSystem.get_unit_systemYsf k: .  j66 6006IIfZ%=%=>?1 '' 44r'c(tjdS)NSI)rrrr'r&get_default_unit_systemz"UnitSystem.get_default_unit_systemhs''--r'c,t|jS)zr Give the dimension of the system. That is return the number of units forming the basis. )lenrr0s r&dimzUnitSystem.dimls4##$$r'c6|jjS)zI Check if the underlying dimension system is consistent. )r: is_consistentr0s r&rRzUnitSystem.is_consistentus ((*888r'c|jSr)rr0s r&r$zUnitSystem.derived_units}s"""r'c\ddlm}t|tr/t|jDcgc]}|j |c}St|t r(|j |j|jzSt|tr|j |jdSt|trH|j |j}|jD]\}}||j ||zz}|St|trY|jDcgc]}|j |}}td|Drtj S|j"|St||r|j%|j&Stj Scc}wcc}w)Nrr c3&K|] }|dk( yw)r Nr)r,is r&r.z2UnitSystem.get_dimensional_expr..s(a16()sympy.physics.unitsr rErargsget_dimensional_exprrr6exprrexprvariable_countrallr Onefuncr=r) r r\r rVrP independentcountargrYs r&rZzUnitSystem.get_dimensional_exprsb0 dC tyyI!2215IJ J c ",,TYY7488C C c ",,TYYq\: : j )++DII6C&*&9&9 E" Ut00=uDD EJ h '>BiiHsD--c2HDH(4((uu 499d# # h '..t499 9uu #JIs F$"F)cddlm}t||r|j|jfSt|t r@d}t d}|jD] }|j|\}}||z}||z}"||fSt|trj|j|j\}}|j|j\} } |jj| rd} || z|| | zzfSt|tr|j|jd\}}|jddD]W} |j| \} } |jj|| st!dj#| | ||| z }Y||fSt|t$r]|j|jd\}}|j&D])\}}|j|\}}|||zz}|||zz}+||fSt|t(r|jDcgc]}|j|}}|Dcgc]4}|jj|dr t dn|d6}}|j*d|Dg|St|t rt,j.|fS|t dfScc}wcc}w)zU Return tuple with scale factor expression and dimension expression. rr r Nz,Dimension of "{}" is {}, but it should be {}c3&K|] }|d yw)rNr)r,fs r&r.z;UnitSystem._collect_factor_and_dimension..s2!2rW)rXr rE scale_factor dimensionrrrY_collect_factor_and_dimensionrr6r[r:is_dimensionlessrequivalent_dimsrFrGrr]rr`r r_)r r\r factorrhrc arg_factorarg_dimrP exp_factorexp_dimaddend addend_factor addend_dimrarbifactoridimfdsr-dimss r&riz(UnitSystem._collect_factor_and_dimensions 1 dH %$$dnn4 4 c "F!! Iyy %&*&H&H&M# G*$W$  %9$ $ c "<* z002BB3 S$..4f"J/566-' (3;  j )<z3UnitSystem.get_units_non_prefixed..s $5$Ta>T>T:Tr')rfilterrr0s r&get_units_non_prefixedz!UnitSystem.get_units_non_prefixeds6TVZVaVabccr')r$dict[Dimension, Quantity])returnr)rz set[Quantity])__name__ __module__ __qualname____doc__r__annotations__rr1r4r8r:r=rB staticmethodrJrMpropertyrPrRr$rZrir __classcell__)r%s@r&rrs,.M(-)+"BQUAC  2;"$""tA v&4 7  5 5..%%99##,/&bdr'rN)r __future__rsympy.core.addrsympy.core.functionrrsympy.core.mulrsympy.core.powerrsympy.core.singletonr sympy.physics.units.dimensionsr sympy.physics.units.quantitiesr dimensionsrrrr'r&rs7#6 ":3!{d{dr'