a super fast scientific calculator with dimensional analysis support written in Rust 🦀🐛
heavily inspired from insect
Command mode:
$ larvae '1kg^-2kg kg*e/e*ln(e)*pi/pi*sqrt(1)!%2*1.123kilometer^2/s+100s^-1m*m+10km^2/s-0m^2/s-> m^3/m/s'
11123100 m²/s
Interactive mode:
$ larvae
>>> 1kg^-2kg kg*e/e*log(10)*pi/pi*sqrt(1)!%2*1.123kilometer^2/s+100s^-1m*m+10km^2/s-0m^2/s-> m^3/m/s
11123100 m²/s
>>>
- I thought it'd be fun
- Maybe I'd learn something cool like Earley parsing
- Maybe with a little more work, it'll even be as useful as insect someday
- It's super fast. It's like 2 orders of magnitude faster than insect in its current state (albeit it's still lacking some features):
$ hyperfine \
'insect "e/e*pi/pi*sqrt(1)%2*1.123kilometer^2/s+100s^-1 m*m+10km^2/s-0m^2/s->m^3/m/s"' \
'larvae "e/e*pi/pi*sqrt(1)%2*1.123kilometer^2/s+100s^-1 m*m+10km^2/s-0m^2/s->m^3/m/s"'
Benchmark 1: insect "e / e * log ( 10 ) * pi / pi * sqrt ( 1 ) ! % 2 * 1.123 kilometer ^ 2 / s + 100 s ^ -1 m * m + 10 km ^ 2 / s - 0 m ^ 2 / s -> m ^ 3 / m / s"
Time (mean ± σ): 307.8 ms ± 4.4 ms [User: 384.5 ms, System: 29.0 ms]
Range (min … max): 301.2 ms … 314.0 ms 10 runs
Benchmark 2: larvae "e / e * log ( 10 ) * pi / pi * sqrt ( 1 ) ! % 2 * 1.123 kilometer ^ 2 / s + 100 s ^ -1 m * m + 10 km ^ 2 / s - 0 m ^ 2 / s -> m ^ 3 / m / s"
Time (mean ± σ): 1.9 ms ± 0.7 ms [User: 1.7 ms, System: 1.3 ms]
Range (min … max): 0.6 ms … 4.3 ms 489 runs
Warning: Command took less than 5 ms to complete. Results might be inaccurate.
Summary
'larvae "e / e * log ( 10 ) * pi / pi * sqrt ( 1 ) ! % 2 * 1.123 kilometer ^ 2 / s + 100 s ^ -1 m * m + 10 km ^ 2 / s - 0 m ^ 2 / s -> m ^ 3 / m / s"' ran
160.53 ± 57.94 times faster than 'insect "e / e * log ( 10 ) * pi / pi * sqrt ( 1 ) ! % 2 * 1.123 kilometer ^ 2 / s + 100 s ^ -1 m * m + 10 km ^ 2 / s - 0 m ^ 2 / s -> m ^ 3 / m / s"'
-
Basic arithmetic (dimensionless numbers)
- +, -,
- *, /
- ^
- Other mathematical functions
- %
- !
- sqrt
- pi
- exp
- log
-
Dimensional analysis
- Dimensional analysis arithmetic
- Basic units
- Length
- Mass
- Time
- Compound units
- Force
-
Cli
- Basic functionality (currently only works when tokens are separated by white space)
- Equation parsing w/ recognition of dimensioned quantities
- "Smart" Tokenisation of equation strings containing functions, units, values, etc.
- Colors
- Fancy characters (i.e. s⁻³·m⁻², Ω)
-
Future goals
- Support algebraic solving of variables w/ units