135 lines
3.7 KiB
Markdown
135 lines
3.7 KiB
Markdown
# A minimalist calculator for fermi estimation
|
|
|
|
This project contains a minimalist command-line calculator for Fermi estimation. For now, it just multiplies lognormals.
|
|
|
|
## Motivation
|
|
|
|
Sometimes, [Squiggle](https://github.com/quantified-uncertainty/squiggle), [simple squiggle](https://git.nunosempere.com/quantified.uncertainty/simple-squiggle) or [squiggle.c](https://git.nunosempere.com/personal/squiggle.c) are still too complicated and un-unix-like.
|
|
|
|
## Usage
|
|
|
|
Here is an example
|
|
|
|
```
|
|
$ go run f.go
|
|
5000000 12000000
|
|
=> 5000000.0 12000000.0
|
|
0.002 0.01
|
|
=> 13859.5 86583.4
|
|
30 180
|
|
=> 706832.8 9167656.0
|
|
/ 48 52
|
|
=> 14139.1 183614.7
|
|
/ 5 6
|
|
=> 2573.1 33632.0
|
|
/ 6 8
|
|
=> 368.4 4893.5
|
|
/ 60
|
|
=> 6.1 81.6
|
|
```
|
|
|
|
Perhaps this example is more understandable with comments and better units:
|
|
|
|
```
|
|
$ sed -u "s|#.*||" | sed -u 's|M|000000|g' | go run f.go
|
|
5M 12M # number of people living in Chicago
|
|
=> 5000000.0 12000000.0
|
|
0.002 0.01 # fraction of people that have a piano
|
|
=> 13859.5 86583.4
|
|
30 180 # minutes it takes to tune a piano, including travel time
|
|
=> 706832.8 9167656.0
|
|
/ 48 52 # weeks a year that piano tuners work for
|
|
=> 14139.1 183614.7
|
|
/ 5 6 # days a week in which piano tuners work
|
|
=> 2573.1 33632.0
|
|
/ 6 8 # hours a day in which piano tuners work
|
|
=> 368.4 4893.5
|
|
/ 60 # minutes to an hour
|
|
=> 6.1 81.6
|
|
# ^ piano tuners in Chicago
|
|
```
|
|
|
|
You can see a recording in action here:
|
|
|
|
[![asciicast](https://asciinema.org/a/fygBtg0XDc1iVajArdQn9b9CA.svg)](https://asciinema.org/a/fygBtg0XDc1iVajArdQn9b9CA)
|
|
|
|
## Installation
|
|
|
|
```
|
|
make build
|
|
sudo make install
|
|
f # rather than the previous go run f.go
|
|
```
|
|
|
|
Why use make instead of the built-in go commands? Because the point of make is to be able to share command-line recipes.
|
|
|
|
## Usage together with standard Linux utilities
|
|
|
|
```bash
|
|
f
|
|
sed -u "s|#.*||" | sed -u 's|M|000000|g' | f
|
|
|
|
cat more/piano-tuners.f | f
|
|
cat more/piano-tuners-commented.f | sed -u "s|#.*||" | sed -u 's|M|000000|g' | f
|
|
|
|
tee -a input.log | go run f.go | tee -a output.log
|
|
tee -a io.log | go run f.go | tee -a io.log
|
|
|
|
function f(){
|
|
sed -u "s|#.*||" |
|
|
sed -u "s|//.*||" |
|
|
sed -u 's|K|000|g' |
|
|
sed -u 's|M|000000|g' |
|
|
sed -u 's|B|000000000|g' |
|
|
/usr/bin/f
|
|
}
|
|
```
|
|
|
|
Note that these sed commands are just hacks, and won't parse e.g., `3.5K` correctly—it will just substitute for 3.5000
|
|
|
|
## Tips & tricks
|
|
|
|
Conceptually clearer to have all the multiplications first and then all the divisions
|
|
|
|
## Roadmap
|
|
|
|
- [x] Write README
|
|
- [x] Add division?
|
|
- [x] Read from file?
|
|
- [x] Save to file?
|
|
- [x] Allow comments?
|
|
- [x] Use a sed filter?
|
|
- [x] Add show more info version
|
|
- [x] Scalar multiplication and division
|
|
- [ ] Program into a small device, like a calculator?
|
|
- [-] Think of some way of calling bc
|
|
- [x] Think how to integrate with squiggle.c to draw samples
|
|
- [x] Copy the time to botec go code
|
|
- [ ] Define samplers
|
|
- [ ] Call those samplers when operating on distributions that can't be operted on algebraically
|
|
- [ ] Think about how to draw a histogram from samples
|
|
- [x] Display output more nicely, with K/M/B/T
|
|
- [ ] Consider the following: make this into a stack-based DSL, with:
|
|
- Variables that can be saved to and then displayed
|
|
- Other types of distributions, particularly beta distributions? => But then this requires moving to bags of samples. It could still be ~instantaneous though.
|
|
- Figure out syntax for
|
|
- Maps
|
|
- Joint types
|
|
- Enums
|
|
|
|
Some possible syntax for a more expressive stack-based DSL
|
|
|
|
```
|
|
1B to 20B
|
|
* 1 to 100
|
|
/ beta 1 2 # or b 1 2
|
|
=: x # content of the stack at this point saved into x
|
|
|
|
1 to 10
|
|
10 to 100
|
|
=: y # content of the stack at this point saved into y
|
|
|
|
x # put x on the stack
|
|
- y # substract y from the content of the stack. Requires interpreting x and y as list of samples
|
|
```
|