fermi/README.md

106 lines
2.7 KiB
Markdown
Raw Normal View History

# A minimalist calculator for fermi estimation
2024-05-10 21:38:20 +00:00
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.
2024-05-10 21:38:20 +00:00
## Usage
2024-05-10 21:38:20 +00:00
Here is an example
2024-05-10 21:38:20 +00:00
```
$ 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
2024-05-11 11:22:07 +00:00
/ 60
2024-05-10 21:38:20 +00:00
=> 6.1 81.6
```
2024-05-10 21:38:20 +00:00
Perhaps this example is more understandable with comments and better units:
2024-05-10 21:38:20 +00:00
```
$ 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
2024-05-11 11:22:07 +00:00
/ 60 # minutes to an hour
2024-05-10 21:38:20 +00:00
=> 6.1 81.6
# ^ piano tuners in Chicago
```
2024-05-13 22:26:31 +00:00
You can see a recording in action here:
[![asciicast](https://asciinema.org/a/fygBtg0XDc1iVajArdQn9b9CA.svg)](https://asciinema.org/a/fygBtg0XDc1iVajArdQn9b9CA)
2024-05-10 21:38:20 +00:00
## Installation
2024-05-10 21:38:20 +00:00
```
make build
sudo make install
f # rather than the previous go run f.go
```
2024-05-10 19:09:35 +00:00
2024-05-10 21:38:20 +00:00
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
2024-05-10 19:09:35 +00:00
2024-05-10 21:47:34 +00:00
```bash
2024-05-10 21:38:20 +00:00
f
2024-05-10 21:47:34 +00:00
sed -u "s|#.*||" | sed -u 's|M|000000|g' | f
2024-05-10 21:38:20 +00:00
cat more/piano-tuners.f | f
cat more/piano-tuners-commented.f | sed -u "s|#.*||" | sed -u 's|M|000000|g' | f
2024-05-10 21:47:34 +00:00
2024-05-10 21:38:20 +00:00
tee -a input.log | go run f.go | tee -a output.log
tee -a io.log | go run f.go | tee -a io.log
2024-05-10 21:47:34 +00:00
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
}
2024-05-10 21:38:20 +00:00
```
2024-05-10 19:09:35 +00:00
2024-05-10 21:47:34 +00:00
## Tips & tricks
Conceptually clearer to have all the multiplications first and then all the divisions
2024-05-10 21:38:20 +00:00
## Roadmap
2024-05-10 19:09:35 +00:00
2024-05-10 21:38:20 +00:00
- [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
2024-05-12 17:10:25 +00:00
- [x] Scalar multiplication and division
2024-05-10 21:38:20 +00:00
- [ ] Program into a small device, like a calculator?
- [ ] Think of some way of calling bc
2024-05-10 21:47:34 +00:00
- [ ] Think how to integrate with squiggle.c to draw samples
- [ ] Think about how to draw a histogram from samples