diff --git a/README.md b/README.md index 4bb06b4..5d66e12 100644 --- a/README.md +++ b/README.md @@ -21,66 +21,33 @@ $ fermi 5000000 12000000 => 5.0M 12.0M * beta 1 200 -1.9K 123.1K +=> 1.9K 123.1K * 30 180 -122.9K 11.7M +=> 122.9K 11.7M / 48 52 -2.5K 234.6K +=> 2.5K 234.6K / 5 6 -448.8 43.0K +=> 448.8 43.0K / 6 8 -64.5 6.2K +=> 64.5 6.2K / 60 -1.1 103.7 +=> 1.1 103.7 ``` Perhaps this example is more understandable with comments and better units: ``` $ fermi -5M 12M # number of people living in Chicago -=> 5.0M 12.0M -* beta 1 200 # fraction of people that have a piano -1.9K 123.1K -30 180 # minutes it takes to tune a piano, including travel time -122.9K 11.7M -/ 48 52 # weeks a year pianotuners work for -2.5K 234.6K -/ 6 8 # hours a day -353.9 34.1K -/ 60 # minutes to an hour -5.9 568.3 -=: piano_tuners_in_Chicago -piano_tuners_in_Chicago => 5.9 568.3 +5M 12M # number of people living in Chicago +beta 1 200 # fraction of people that have a piano +30 180 # minutes it takes to tune a piano, including travel time +/ 48 52 # weeks a year that piano tuners work for +/ 5 6 # days a week in which piano tuners work +/ 6 8 # hours a day in which piano tuners work +/ 60 # minutes to an hour +=: piano_tuners ``` -Here is instead an example using beta distributions and variables: - -``` -$ fermi -1 2 -=> 1.0 2.0 -* 1_000_000_000 -=> 1000.0M 2.0B -=: x # assign to variable -x => 1000.0M 2.0B -. # clear the stack, i.e., make it be 1 - -beta 1 2 -=> beta 1.0 2.0 -beta 12 300 -=> beta 13.0 302.0 -=. y # assign to variable and clear the stack (return it to 1) -y => beta 13.0 302.0 - -x -=> 1000.0M 2.0B -* y -=> samples 31.3M 98.2M -``` - -The difference between `=: x` and `=. y` is that `=.` clears the stack after the assignment. - If you type "help", you can see a small grammar: ``` @@ -95,24 +62,31 @@ help Variable assignment: =: variable_name Variable assignment and clear stack: =. variable_name Special: - Clear stack: clear | c | . - Print this help message: help | h - Print debug info: debug | d - Exit: exit | e Comment: # this is a comment + Clear stack: clear | c | . + Print debug info: debug | d + Print help message: help | h + Start additional stack: operator ( + Return from additional stack ) + Exit: exit | e Examples: + 2 - / 2.5 - * 1 10 (interpreted as lognormal) + # this is a comment + / 2.5 # this is an operation followed by a comment + * 1 10 # "low high" is interpreted as lognormal + 1 10 * beta 1 10 - 1 10 (multiplication taken as default operation) - =: x - . + 1 10 # multiplication taken as default operation) + =: x + . # return the stack to 1. 1 100 + x - # this is a comment - * 1 12 # this is an operation followed by a comment + * 1 12 + * ( + 1 10 + + beta 1 100 + ) + =. y # save to variable and clear stack exit ``` @@ -160,11 +134,12 @@ Done: - [x] Clean up error code. Right now only needed for division - [x] Maintain *both* a more complex thing that's more featureful *and* the more simple multiplication of lognormals thing. - [x] Allow input with K/M/T +- [x] Document parenthesis syntax To (possibly) do: - [ ] Specify number of samples as a command line option -- [ ] Document parenthesis syntax +- [ ] Figure out how to make models executable, by adding a #!/bin/bash-style command at the top? - [ ] Add functions. Now easier to do with an explicit representation of the stakc - [ ] Think about how to draw a histogram from samples - [ ] Dump samples to file diff --git a/f.go b/f.go index 67e7b65..34878cb 100644 --- a/f.go +++ b/f.go @@ -3,6 +3,7 @@ package main import ( "bufio" "errors" + "flag" "fmt" "git.nunosempere.com/NunoSempere/fermi/pretty" "git.nunosempere.com/NunoSempere/fermi/sample" @@ -101,7 +102,8 @@ const HELP_MSG = " Operation | Variable assignment | Special\n" + const NORMAL90CONFIDENCE = 1.6448536269514727 const INIT_DIST Scalar = Scalar(1) -const N_SAMPLES = 1_000_000 + +var N_SAMPLES = 1_000_000 /* Printers */ func prettyPrintDist(dist Dist) { @@ -408,6 +410,10 @@ replForLoop: } func main() { + num_samples_flag := flag.Int("n", N_SAMPLES, "Specifies the number of samples to draw when using samples") + flag.Parse() + N_SAMPLES = *num_samples_flag + reader := bufio.NewReader(os.Stdin) stack := Stack{old_dist: INIT_DIST, vars: make(map[string]Dist)} runRepl(stack, reader) diff --git a/more/piano-tuners-commented.f b/more/piano-tuners-commented.f deleted file mode 100644 index 9590255..0000000 --- a/more/piano-tuners-commented.f +++ /dev/null @@ -1,9 +0,0 @@ -5M 12M # number of people living in Chicago -0.002 0.01 # fraction of people that have a piano -30 180 # minutes it takes to tune a piano, including travel time -/ 48 52 # weeks a year that piano tuners work for -/ 5 6 # days a week in which piano tuners work -/ 6 8 # hours a day in which piano tuners work -/ 60 # minutes to an hour -# ^ piano tuners in Chicago - diff --git a/more/piano-tuners-commented.fermi b/more/piano-tuners-commented.fermi new file mode 100644 index 0000000..190d47f --- /dev/null +++ b/more/piano-tuners-commented.fermi @@ -0,0 +1,9 @@ +5M 12M # number of people living in Chicago +beta 1 200 # fraction of people that have a piano +30 180 # minutes it takes to tune a piano, including travel time +/ 48 52 # weeks a year that piano tuners work for +/ 5 6 # days a week in which piano tuners work +/ 6 8 # hours a day in which piano tuners work +/ 60 # minutes to an hour +=: piano_tuners +exit