pint-compute

pint-compute

热门

使用 Pint 进行感知单位的计算 - 单位转换、量纲分析与单位四则运算

3940Star
303Fork
更新于 2026/1/26
SKILL.md
只读
名称
pint-compute
描述

使用 Pint 进行感知单位的计算 - 单位转换、量纲分析与单位四则运算

使用 Pint 进行单位计算

用于感知单位计算的认知增强工具。使用 Pint 在不同单位之间进行转换、执行带单位的算术运算、检查量纲兼容性以及简化复合单位。

适用场景

  • 单位之间的转换(米转英尺、千克转磅)
  • 感知单位的算术运算(速度 × 时间 = 距离)
  • 量纲分析(力是否等于质量 × 加速度?)
  • 将复合单位简化为基本单位或命名单位
  • 解析和分析带有单位的物理量

快速参考

我想要... 命令 示例
转换单位 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"

常见单位领域

领域 示例
长度 meter, foot, inch, mile, km, yard
时间 second, minute, hour, day, year
质量 kg, gram, pound, ounce, ton
速度 m/s, km/h, mph, knot
能量 joule, calorie, eV, kWh, BTU
力 newton, pound_force, dyne
温度 kelvin, celsius, fahrenheit
压强 pascal, bar, atmosphere, psi
功率 watt, horsepower

输出格式

所有命令均返回包含相关字段的 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 - 符号计算