Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
- ``name`` -- string
OUTPUT:
- UnitExpression
EXAMPLES::
sage: sage.symbolic.units.str_to_unit('acre')
acre
sage: type(sage.symbolic.units.str_to_unit('acre'))
"""
return UnitExpression(SR, SR.var(name))
Returns variable if 'unit' is not a unit::
sage: sage.symbolic.units.base_units(var('x'))
x
"""
from sage.misc.all import sage_eval
if not unit_to_type.has_key(str(unit)):
return unit
elif unit_to_type[str(unit)] == 'si_prefixes' or unit_to_type[str(unit)] == 'unit_multipliers':
return sage_eval(unitdict[unit_to_type[str(unit)]][str(unit)])
else:
v = SR.var(unit_to_type[str(unit)])
if unit_derivations.has_key(str(v)):
base = unit_derivations_expr(v)
for i in base.variables():
base = base.subs({i:SR.var(value_to_unit[str(i)]['1'])})
return base*sage_eval(unitdict[str(v)][str(unit)])
else:
base = SR.var(value_to_unit[str(v)]['1'])*sage_eval(unitdict[str(v)][str(unit)])
return base
kilogram*meter/second^2
sage: sage.symbolic.units.base_units(units.volume.liter)
1/1000*meter^3
Returns variable if 'unit' is not a unit::
sage: sage.symbolic.units.base_units(var('x'))
x
"""
from sage.misc.all import sage_eval
if not unit_to_type.has_key(str(unit)):
return unit
elif unit_to_type[str(unit)] == 'si_prefixes' or unit_to_type[str(unit)] == 'unit_multipliers':
return sage_eval(unitdict[unit_to_type[str(unit)]][str(unit)])
else:
v = SR.var(unit_to_type[str(unit)])
if unit_derivations.has_key(str(v)):
base = unit_derivations_expr(v)
for i in base.variables():
base = base.subs({i:SR.var(value_to_unit[str(i)]['1'])})
return base*sage_eval(unitdict[str(v)][str(unit)])
else:
base = SR.var(value_to_unit[str(v)]['1'])*sage_eval(unitdict[str(v)][str(unit)])
return base