This site describes solve-engine 2.44.0, the version npm installs.
Constants
Package:
CONSTANTS_PACKAGE. Registered bycreateEngine(); for a slimmer engine, register it explicitly (see choosing packages).
Reach for a well-known constant by name instead of typing the digits. Where a constant has a unit, it arrives as a proper quantity, so it converts and multiplies like any other measurement.
Dimensioned constants
Section titled “Dimensioned constants”The speed of light and the acceleration of gravity carry their units:
speed of light // 299,792,458.00 m/sgravity // 9.81 m/s²Because they are real quantities, they take part in the arithmetic. Gravity times a mass is a force, and it reads out in newtons through the named derived units:
gravity * 70 kg as N // 686.47 Nspeed of light in km/h // 1,079,252,848.80 km/hMathematical constants
Section titled “Mathematical constants”tau is a full turn, 2π, and the golden ratio (also phi) is the proportion
that appears throughout art and nature. pi and e are already built in.
tau // 6.28golden ratio // 1.62Each is a number with a name, exactly as pi is, so it goes anywhere a number
does. An amount written straight before one multiplies it, the way 2pi is two
times pi, and an equation or a function can hold one:
2tau // 12.573 golden ratio // 4.85(1 + 1)tau // 12.57solve(x^2 = tau, x) // [-2.51, 2.51]solve(x^2 = 2tau, x) // [-3.54, 3.54]der(tau*x^2, x) // 12.5663706144xA constant with a unit goes into a function or a map the same way, and the
answer keeps its unit. A function here is a formula you name once and use
again, f(m) = m * gravity read as “the weight of a mass m”; a map works an
expression out for each item of a list.
f(m) = m * gravity // f(m) definedf(70 kg) as N // 686.47 Nmap(x * gravity, [1, 2]) // [9.81 m/s², 19.61 m/s²]The boundary is the dimensioned constants. A bare amount before gravity or
speed of light is not read as a product, since 2 gravity could as well mean
two of something measured in gravities; write the *. And an equation, a
derivative or an integral works on a formula, which is algebra on plain
numbers and has nowhere to keep a unit, so a constant with a unit there is
refused for its unit, and the line says which:
solve(x = gravity * 2, x) // A formula keeps no units, so combining "x" with an amount in m/s² would drop the m/s². Give "x" a value on a line above, or write the formula without the unit.A constant in a unit the engine cannot write yet (planck, avogadro) is a
plain number, so an equation takes it as it takes any number.
Physical constants (values)
Section titled “Physical constants (values)”These are precise scientific values. Avogadro’s number is large enough to show in full; the others are so small that the default display rounds them, so they are listed here with their proper values and units:
avogadro // 602,214,076,000,000,000,000,000| constant | value | unit |
|---|---|---|
planck | 6.62607015 × 10⁻³⁴ | J·s |
boltzmann | 1.380649 × 10⁻²³ | J/K |
elementary charge | 1.602176634 × 10⁻¹⁹ | C |
gas constant | 8.314462618 | J/(mol·K) |
avogadro | 6.02214076 × 10²³ | mol⁻¹ |
electron mass | 9.1093837015 × 10⁻³¹ | kg |
proton mass | 1.67262192369 × 10⁻²⁷ | kg |
electron mass and proton mass carry their kilograms, and boltzmann its
joules per kelvin, so they convert and combine like the other dimensioned
constants: the Boltzmann constant times a temperature is an energy.
boltzmann // 1.38e-23 J/Kboltzmann * 300 K // 4.14e-21 JThe rest are in units the engine cannot write yet: a joule-second, a coulomb (the unit of electric charge), and anything per mole (the chemist’s count of particles). Each of them is a plain number, and scaling one by a plain number works as it always has. What is refused is meeting a quantity, since a plain number takes the other side’s unit and the answer would be labelled wrongly: Planck’s constant times a frequency is an energy, not a number of hertz.
planck * 5e14 // 3.31e-19avogadro * 2 // 1,204,428,152,000,000,000,000,000planck * 5e14 Hz // A constant measured in J·s and a quantity in Hz cannot be multiplied: the engine cannot spell J·s yet, so the answer would wrongly be in Hz. Leave the unit off the other side and read the result in the unit it should have.The refusal applies to the constant itself, as written or held in a variable. A
value already worked out from one, planck * 2, is an ordinary number.