Show HN: Unsure Calculator – back-of-a-napkin probabilistic calculator
49 comments
·April 15, 2025NunoSempere
NunoSempere
Fermi in particular has the following syntax
```
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
```
multiplication is implied as the default operation, fits are lognormal.
NunoSempere
Here is a thread with some fun fermi estimates made with that tool: e.g., number of calories NK gets from Russia: https://x.com/NunoSempere/status/1857135650404966456
900K 1.5M # tonnes of rice per year NK gets from Russia
* 1K # kg in a tone
* 1.2K 1.4K # calories per kg of rice
/ 1.9K 2.5K # daily caloric intake
/ 25M 28M # population of NK
/ 365 # years of food this buys
/ 1% # as a percentage
OisinMoran
This is neat! If you enjoy the write up, you might be interested in the paper “Dissolving the Fermi Paradox” which goes even more on-depth into actually multiplying the probability density functions instead of the common point estimates. It has the somewhat surprising result that we may just be alone.
roughly
I like this!
In the grand HN tradition of being triggered by a word in the post and going off on a not-quite-but-basically-totally-tangential rant:
There’s (at least) three areas here that are footguns with these kinds of calculations:
1) 95% is usually a lot wider than people think - people take 95% as “I’m pretty sure it’s this,” whereas it’s really closer to “it’d be really surprising if it were not this” - by and large people keep their mental error bars too close.
2) probability is rarely truly uncorrelated - call this the “Mortgage Derivatives” maxim. In the family example, rent is very likely to be correlated with food costs - so, if rent is high, food costs are also likely to be high. This skews the distribution - modeling with an unweighted uniform distribution will lead to you being surprised at how improbable the actual outcome was.
3) In general normal distributions are rarer than people think - they tend to require some kind of constraining factor on the values to enforce. We see them a bunch in nature because there tends to be negative feedback loops all over the place, but once you leave the relatively tidy garden of Mother Earth for the chaos of human affairs, normal distributions get pretty abnormal.
I like this as a tool, and I like the implementation, I’ve just seen a lot of people pick up statistics for the first time and lose a finger.
youainti
> I’ve just seen a lot of people pick up statistics for the first time and lose a finger.
I love this. I've never though of statistics like a power tool or firearm, but the analogy fits really well.
vortico
Cool! Some random requests to consider: Could the range x~y be uniform instead of 2 std dev normal (95.4%ile)? Sometimes the range of quantities is known. 95%ile is probably fine as a default though. Also, could a symbolic JS package be used instead of Monte-Carlo? This would improve speed and precision, especially for many variables (high dimensions). Could the result be shown in a line plot instead of ASCII bar chart?
ttoinou
Would be nice to retransform the output into an interval / gaussian distribution
Note: If you're curious why there is a negative number (-5) in the histogram, that's just an inevitable downside of the simplicity of the Unsure Calculator. Without further knowledge, the calculator cannot know that a negative number is impossible
Drake Equation or equation multiplying probabilities can also be seen in log space, where the uncertainty is on the scale of each probability, and the final probability is the product of exponential of the log probabilities. And we wouldnt have this negative issuehatthew
The default example `100 / 4~6` gives the output `17~25`
omoikane
If I am reading this right, a range is expressed as a distance between the minimum and maximum values, and in the Monte Carlo part a number is generated from a uniform distribution within that range[1].
But if I just ask the calculator "1~2" (i.e. just a range without any operators), the histogram shows what looks like a normal distribution centered around 1.5[2].
Shouldn't the histogram be flat if the distribution is uniform?
[1] https://github.com/filiph/unsure/blob/123712482b7053974cbef9...
hatthew
Under the "Limitations" section:
> Range is always a normal distribution, with the lower number being two standard deviations below the mean, and the upper number two standard deviations above. Nothing fancier is possible, in terms of input probability distributions.
gregschlom
The ASCII art (well technically ANSI art) histogram is neat. Cool hack to get something done quickly. I'd have spent 5x the time trying various chart libraries and giving up.
Retr0id
On a similar note, I like the crude hand-drawn illustrations a lot. Fits the "napkin" theme.
krick
It sounds like a gimmick at first, but looks surprisingly useful. I'd surely install it if it was available as an app to use alongside my usual calculator, and while I cannot quite recall a situation when I needed it, it seems very plausible that I'll start finding use cases once I have it bound to some hotkey on my keyboard.
marcodiego
I put "1 / (-1~1)" and expected something around - to + infinty. It instead gave me -35~35.
I really don't known how good it is.
thih9
Feature request: allow specifying the probability distribution. E.g.: ‘~’: normal, ‘_’: uniform, etc.
alex-moon
> The UI is ugly, to say the least.
I actually quite like it. Really clean, easy to see all the important elements. Lovely clear legible monospace serif font.
djoldman
I perused the codebase but I'm unfamiliar with dart:
https://github.com/filiph/unsure/blob/master/lib/src/calcula...
I assume this is a montecarlo approach? (Not to start a flamewar, at least for us data scientists :) ).
kccqzy
Yes it is.
porridgeraisin
Can you explain how? I'm an (aspiring)
kccqzy
I didn't peruse the source code. I just read the linked article in its entirety and it says
> The computation is quite slow. In order to stay as flexible as possible, I'm using the Monte Carlo method. Which means the calculator is running about 250K AST-based computations for every calculation you put forth.
So therefore I conclude Monte Carlo is being used.
hawthorns
It's dead simple. Here is the simplified version that returns the quantiles for '100 / 2 ~ 4'.
import numpy as np
def monte_carlo(formula, iterations=100000):
res = [formula() for _ in range(iterations)]
return np.percentile(res, [0, 2.5, \*range(10, 100, 10),
97.5, 100])
def uncertain_division():
return 100 / np.random.uniform(2, 4)
monte_carlo(uncertain_division, iterations=100000)
constantcrying
Line 19 to 21 should be the Monte-Carlo sampling algorithm. The implementation is maybe a bit unintuitive but apparently he creates a function from the expression in the calculator, calling that function gives a random value from that function.
I have written similar tools
- for command line, fermi: https://git.nunosempere.com/NunoSempere/fermi
- for android, a distribution calculator: https://f-droid.org/en/packages/com.nunosempere.distribution...
People might also be interested in https://www.squiggle-language.com/, which is a more complex version (or possibly <https://git.nunosempere.com/personal/squiggle.c>, which is a faster but much more verbose version in C)