quantity_simplify_units
Simplify quantities with units by converting to standard forms using SymPy. Ideal for physics and engineering expressions involving SI units, mixed units, and constants like speed of light.
Instructions
Simplifies a quantity with units using sympy's built-in simplify method for Quantity objects.
Args:
expr_key: The key of the expression (previously introduced) to simplify.
unit_system: Optional unit system (from UnitSystem enum). Not used with direct simplify method.
The following units are available by default:
SI base units: meter, second, kilogram, ampere, kelvin, mole, candela
Length: kilometer, millimeter
Mass: gram
Energy: joule
Force: newton
Pressure: pascal
Power: watt
Electric: coulomb, volt, ohm, farad, henry
Constants: speed_of_light, gravitational_constant, planck
Example:
# Simplify force expressed in base units
expr_key = introduce_expression("kilogram*meter/second**2")
result = quantity_simplify_units(expr_key)
# Returns newton (as N = kg·m/s²)
# Simplify a complex expression with mixed units
expr_key = introduce_expression("joule/(kilogram*meter**2/second**2)")
result = quantity_simplify_units(expr_key)
# Returns a dimensionless quantity (1)
# Simplify electrical power expression
expr_key = introduce_expression("volt*ampere")
result = quantity_simplify_units(expr_key)
# Returns watt
Example with Speed of Light:
# Introduce the speed of light
c_key = introduce_expression("speed_of_light")
# Convert to kilometers per hour
km_per_hour_key = convert_to_units(c_key, ["kilometer", "1/hour"])
# Simplify to get the numerical value
simplified_key = quantity_simplify_units(km_per_hour_key)
# Print the result
print_latex_expression(simplified_key)
# Shows the numeric value of speed of light in km/h
Returns:
A key for the simplified expression, or an error message.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
expr_key | Yes | ||
unit_system | No |
Input Schema (JSON Schema)
{
"$defs": {
"UnitSystem": {
"enum": [
"MKS",
"MKSA",
"natural",
"SI",
"cgs"
],
"title": "UnitSystem",
"type": "string"
}
},
"properties": {
"expr_key": {
"title": "Expr Key",
"type": "string"
},
"unit_system": {
"anyOf": [
{
"$ref": "#/$defs/UnitSystem"
},
{
"type": "null"
}
],
"default": null
}
},
"required": [
"expr_key"
],
"title": "quantity_simplify_unitsArguments",
"type": "object"
}