名称: pint-compute 描述: 使用Pint进行单位感知计算 - 转换单位、维度分析、单位算术 允许工具: [Bash, Read]
使用Pint进行单位计算
单位感知计算的认知辅助。使用Pint进行单位转换、执行单位算术、检查维度兼容性和简化复合单位。
何时使用
- 单位间转换(米到英尺,千克到磅)
- 单位感知算术(速度 x 时间 = 距离)
- 维度分析(力 = 质量 x 加速度?)
- 将复合单位简化为基础或命名单位
- 解析和分析带单位的数量
快速参考
| 我想… | 命令 | 示例 |
|---|---|---|
| 转换单位 | convert |
convert "5 meters" --to feet |
| 单位数学 | calc |
calc "10 m/s * 5 s" |
| 检查维度 | check |
check newton --against "kg * m / s^2" |
| 解析数量 | parse |
parse "100 km/h" |
| 简化单位 | simplify |
simplify "1 kg*m/s^2" |
命令
parse
解析数量字符串为大小、单位和维度。
uv run python -m runtime.harness scripts/pint_compute.py \
parse "100 km/h"
uv run python -m runtime.harness scripts/pint_compute.py \
parse "9.8 m/s^2"
convert
将数量转换为不同单位。
uv run python -m runtime.harness scripts/pint_compute.py \
convert "5 meters" --to feet
uv run python -m runtime.harness scripts/pint_compute.py \
convert "100 km/h" --to mph
uv run python -m runtime.harness scripts/pint_compute.py \
convert "1 atmosphere" --to pascal
calc
执行单位感知算术。运算符必须用空格分隔。
uv run python -m runtime.harness scripts/pint_compute.py \
calc "5 m * 3 s"
uv run python -m runtime.harness scripts/pint_compute.py \
calc "10 m / 2 s"
uv run python -m runtime.harness scripts/pint_compute.py \
calc "5 meters + 300 cm"
check
检查两个单位是否有兼容的维度。
uv run python -m runtime.harness scripts/pint_compute.py \
check newton --against "kg * m / s^2"
uv run python -m runtime.harness scripts/pint_compute.py \
check joule --against "kg * m^2 / s^2"
simplify
将复合单位简化为基础或紧凑形式。
uv run python -m runtime.harness scripts/pint_compute.py \
simplify "1 kg*m/s^2"
uv run python -m runtime.harness scripts/pint_compute.py \
simplify "1000 m"
常见单位领域
| 领域 | 示例 |
|---|---|
| 长度 | 米、英尺、英寸、英里、公里、码 |
| 时间 | 秒、分钟、小时、天、年 |
| 质量 | 千克、克、磅、盎司、吨 |
| 速度 | 米/秒、公里/小时、英里/小时、节 |
| 能量 | 焦耳、卡路里、电子伏特、千瓦时、BTU |
| 力 | 牛顿、磅力、达因 |
| 温度 | 开尔文、摄氏度、华氏度 |
| 压力 | 帕斯卡、巴、大气压、psi |
| 功率 | 瓦特、马力 |
输出格式
所有命令返回带相关字段的JSON:
{
"result": "16.4042 foot",
"magnitude": 16.4042,
"units": "foot",
"dimensionality": "[length]",
"latex": "16.4042\\,\\mathrm{ft}"
}
错误处理
维度错误被捕获并报告:
# 这将错误 - 不兼容的维度
uv run python -m runtime.harness scripts/pint_compute.py \
convert "5 meters" --to kg
# 错误: 无法将'[length]'转换为'[mass]'
相关技能
- /math-mode - 完整数学编排(SymPy + Z3)
- /sympy-compute - 符号计算