frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Uncertain<T>

https://nshipster.com/uncertainty/
236•samtheprogram•7h ago

Comments

mackross•6h ago
Always enjoy mattt’s work. Looks like a great library.
boscillator•6h ago
Does this handle covariance between different variables? For example, the location of the object your measuring your distance to presumably also has some error in it's position, which may be correlated with your position (if, for example, if it comes from another GPS operating at a similar time).

Certainly a univarient model in the type system could be useful, but it would be extra powerful (and more correct) if it could handle covariance.

layer8•5h ago
To properly model quantum mechanics, you’d have to associate a complex-valued wave function with any set of entangled variables you might have.
evanb•4h ago
If you need to track covariance you might want to play with gvar https://gvar.readthedocs.io/en/latest/ in python.
jakubmazanec•6h ago
[flagged]
cobbal•6h ago
I don't think inference is part of this at all, frequentist or otherwise.

It's not part of the type system, it's just the giry monad as a library.

frizlab•6h ago
> And why does it need to be part of the type system?

As presented in the article, it is indeed just a library.

geocar•5h ago
> What if I want Bayesian?

Bayes is mentioned on page 46.

> And why does it need to be part of the type system? It could be just a library.

It is a library that defines a type.

It is not a new type system, or an extension to any particularly complicated type system.

> Am I missing something?

Did you read it?

https://www.microsoft.com/en-us/research/wp-content/uploads/...

https://github.com/klipto/Uncertainty/

jakubmazanec•5h ago
> Bayes is mentioned on page 46.

Bayes isn't mentioned in the linked article. But thanks for the links.

muxl•5h ago
It was chosen to be implemented as a generic type in this design because the way that uncertainty "pollutes" underlying values maps well onto monads which were expressed through generics in this case.
AlotOfReading•5h ago
A small note, but GPS is only well-approximated by a circular uncertainty in specific conditions, usually open sky and long-time fixes. The full uncertainty model is much more complicated, hence the profusion of ways to measure error. This becomes important in many of the same situations that would lead you to stop treating the fix as a point location in the first place. To give a concrete example, autonomous vehicles will encounter situations where localization uncertainty is dominated by non-circular multipath effects.

If you go down this road far enough you eventually end up reinventing particle filters and similar.

mikepurvis•4h ago
Vehicle GPS is usually augmented by a lot of additional sensors and assumptions, notably the speedometer, compass, and knowledge the you'll be on one of the roads marked on its map. Not to mention a fast fix because you can assume you haven't changed position since you last powered on.
monocasa•3h ago
As well as a fast fix because you know what mobile cell or wifi network you're on.
layer8•5h ago
Arguably Uncertain should be the default, and you should have to annotate a type as certain T when you are really certain. ;)
esafak•5h ago
A complement to Optional.
nine_k•4h ago
Only for physical measurements. For things like money, you should be pretty certain, often down to exact fractional cents.

It appears that a similar approach is implemented in some modern Fortran libraries.

XorNot•3h ago
Money has the problem that no matter how clever you are someone will punch all the values into Excel and then complain they don't match.

Or specify they're paying X per day, but want hourly itemized billing...but it should definitely come out to X per day (this was one employer which meant I invoiced them with like 8 digits of precision due to how it divided, and they refused to accept a line item for mathematical uncertainty aggregates).

rictic•3h ago
A person might have mistyped a price, a barcode may have been misread, the unit prices might be correct but the quantity could be mistaken. Modeling uncertainty well isn't just about measurement error from sensors.

I wonder what it'd look like to propagate this kind of uncertainty around. You might want to check the user's input against a representative distribution to see if it's unusual and, depending on the cost of an error vs the friction of asking, double-check the input.

random3•3h ago
have you ever tried working computationally with money? Forget money, have you worked with floating points? There really isn't anything certain.
nine_k•3h ago
Yes, I worked in a billing department. No, floats are emphatically not suitable for representing money, except the very rounded values in presentations.

Floats try to keep the relative error at bay, so their absolute precision varies greatly. You need to sum them starting with the smallest magnitude, and do many other subtle tricks, to limit rounding errors.

munchler•5h ago
Is this essentially a programmatic version of fuzzy logic?

https://en.wikipedia.org/wiki/Fuzzy_logic

esafak•5h ago
https://en.wikipedia.org/wiki/Probabilistic_programming more like. It is already a thing; see, for example, https://pyro.ai/
krukah•5h ago
Monads are really undefeated. This particular application feels to me akin to wavefunction evolution? Density matrices as probability monads over Hilbert space, with unitary evolution as bind, measurement/collapse as pure/return. I guess everything just seems to rhyme under a category theory lens.
valcron1000•4h ago
Relevant (2006): https://web.engr.oregonstate.edu/~erwig/pfp/
8note•4h ago
for mechanical engineering drawings to communicate with machinists and the like, we use tolerances

eg. 10cm +8mm/-3mm

for what the acceptable range is, both bigger and smaller.

id expect something like "are we there yet" referencing GPS should understand the direction of the error and what directions of uncertainty are better or worse

mabster•2h ago
Something that's bugged me about this notation though is that sometimes it means "cannot exceed the bounds" and sometimes it means "only exceeds the bounds 10% of the time"
taneq•1h ago
I don’t think I’ve ever seen mechanical drawings have “90% confidence” dimensions like this. If a part’s too big then it won’t fit, and it’s probably useless.
kevin_thibedeau•1h ago
If a test procedure is verifying all dimensional accuracy, it can be assumed to be bounding tolerance. If it's a mass production line with less than 100% testing of parts, you'd have to expect that some outliers get by and the tolerance is something like 3-sigma on a Gaussian.
cb321•4h ago
If you are in an even more "approximate" mindset (as opposed to propagating by simulation to get real world re-sampled skewed distributions, as often happens in experimental physics labs, or at least their undergraduate courses), there is an error propagation (https://en.wikipedia.org/wiki/Propagation_of_uncertainty) simplification for "small" errors thing you can do. Then translating "root" errors to "downstream errors" is just simple chain rule calculus stuff. (There is a Nim library for that at https://github.com/SciNim/Measuremancer that I use at least every week or two - whenever I'm timing anything.)

It usually takes some "finesse" to get your data / measurements into territory where the errors are even small in the first place. So, I think it is probably better to do things like this Uncertain<T> for the kinds of long/fat/heavy tailed and oddly shaped distributions that occur in real world data { IF the expense doesn't get in your way some other way, that is, as per Senior Engineer in the article }.

black_knight•4h ago
This seems closely related to this classic Functional Pearl: https://web.engr.oregonstate.edu/~erwig/papers/PFP_JFP06.pdf

It’s so cool!

I always start my introductory course on Haskell with a demo of the Monty Hall problem with the probability monad and using rationals to get the exact probability of winning using the two strategies as a fraction.

droideqa•4h ago
Could this be implemented in Rust or Clojure?

Does Anglican kind of do this?

j2kun•4h ago
This concept has been done many times in the past, under the name "interval arithmetic." Boost has it [1] as does flint [2]

What is really curious is why, after being reinvented so many times, it is not more mainstream. I would love to talk to people who have tried using it in production and then decided it was a bad idea (if they exist).

[1]: https://www.boost.org/doc/libs/1_89_0/libs/numeric/interval/... [2]: https://arblib.org/

Tarean•3h ago
Interval arithmetic is only a constant factor slower but may simplify at every step. For every operation over numbers there is a unique most precise equivalent op over intervals, because there's a Galois connection. But just because there is a most precise way to represent a set of numbers as an interval doesn't mean the representation is precise.

A computation graph which gets sampled like here is much slower but can be accurate. You don't need an abstract domain which loses precision at every step.

bee_rider•3h ago
It would have been sort of interesting if we’d gone down the road of often using interval arithmetic. Constant factor slower, but also the operations are independent. So if it was the conventional way of handling non-integer numbers, I guess we’d have hardware acceleration by now to do it in parallel “for free.”
pklausler•3h ago
Interval arithmetic makes good intuitive sense when the endpoints of the intervals can be represented exactly. Figuring out how to do that, however, is not obvious.
kccqzy•3h ago
The article says,

> Under the hood, Uncertain<T> models GPS uncertainty using a Rayleigh distribution.

And the Rayleigh distribution is clearly not just an interval with a uniformly random distribution in between. Normal interval arithmetic isn't useful because that uniform random distribution isn't at all a good model for the real world.

Take for example that Boost library you linked. Ask it to compute (-2,2)*(-2,2). It will give (-4,4). A more sensible result might be something like (-2.35, 2.35). The -4 lower bound is only attainable when you have -2 and 2 as the multiplicands which are at the extremes of the interval; probabilistically if we assume these are independent random variables then two of them achieving this extreme value simultaneously should have an even lower probability.

anal_reactor•2h ago
Because reasoning about uncertain values / random variables / intervals / fuzzy logic / whatever is difficult and the model where things are certain is much easier to process while it models the reality well enough.
PaulDavisThe1st•1h ago
Several years ago when I discovered some of the historical work on interval arithmetic, I was astounded to find that there was a notable contingent in the 60s that was urging hardware developers to make interval arithmetic be the basic design of new CPUs, and saying quite forcefully that if we simply went with "normal" integers and floating point, we'd be unable to correctly model the world.
woah•55m ago
Using simple types (booleans etc) is very simple and easy to reason about, and any shortcomings are obvious. Trying to model physical uncertainty is difficult and requires different models for different domains. Once you have committed to needing to do that, it would be much better to use a purpose built model instead of a library which put some bell curves behind a pretty API.
orlp•3m ago
Not sure why this is being upvoted as the article is not describing interval arithmetic. It supports all kinds of uncertainty distributions.
nicois•3h ago
Is there a risk that this will underemphasise some values when the source of error is not independent? For example, the ROI on financial instruments may be inversely correlated to the risk of losing your job. If you associate errors with each, then combine them in a way which loses this relationship, there will be problems.
tricky_theclown•3h ago
S
lloydatkinson•3h ago
IS there the complete C# available for this? I looked over the original paper and it's just snippets.
kittoes•1h ago
https://github.com/klipto/uncertainty
Pxtl•37m ago
10 years since commit and no attached documents besides a tiny readme. Pass.
contravariant•2h ago
I feel like if you're worried about picking the right abstraction then this is almost certainly the wrong one.
lxe•2h ago
I really like that this leans on computing probabilities instead of forcing everything into closed-form math or classical probability exercises. I’ve always found it way more intuitive to simulate, sample, and work directly with distributions. With a computer, it feels much more natural to uh... compute: you just run the process, look at the results, and reason from there.
keeganpoppen•1h ago
oh man i had forgotten about this blog from when i orbited the swift ecosystem a bit... it's clearly as great as always! fun post!
dcsommer•1h ago
Seems more proper to call it a `ProbabilityDistribution` type. It's a more general and intuitive way to handle the concept.
ngruhn•1h ago
Yeah but the shorter name wins

Ask HN: The government of my country blocked VPN access. What should I use?

700•rickybule•8h ago•401 comments

Python: The Documentary

https://lwn.net/Articles/1035537/
28•chmaynard•1h ago•2 comments

Fuck up my site – Turn any website into beautiful chaos

https://www.fuckupmysite.com/?url=https%3A%2F%2Fnews.ycombinator.com&torchCursor=true&comicSans=t...
130•coloneltcb•3h ago•40 comments

Some thoughts on LLMs and software development

https://martinfowler.com/articles/202508-ai-thoughts.html
174•floverfelt•6h ago•159 comments

My startup banking story (2023)

https://mitchellh.com/writing/my-startup-banking-story
155•dvrp•5h ago•66 comments

Uncertain<T>

https://nshipster.com/uncertainty/
237•samtheprogram•7h ago•50 comments

Death by PowerPoint: the slide that killed seven people

https://mcdreeamiemusings.com/blog/2019/4/13/gsux1h6bnt8lqjd7w2t2mtvfg81uhx
44•scapecast•3h ago•10 comments

Expert LSP the official language server implementation for Elixir

https://github.com/elixir-lang/expert
46•pimienta•3h ago•8 comments

RSS Is Awesome

https://evanverma.com/rss-is-awesome
58•edverma2•1h ago•12 comments

Building your own CLI coding agent with Pydantic-AI

https://martinfowler.com/articles/build-own-coding-agent.html
102•vinhnx•6h ago•21 comments

TuneD is a system tuning service for Linux

https://tuned-project.org/
27•tanelpoder•3d ago•8 comments

Are OpenAI and Anthropic losing money on inference?

https://martinalderson.com/posts/are-openai-and-anthropic-really-losing-money-on-inference/
431•martinald•14h ago•414 comments

AI adoption linked to 13% decline in jobs for young U.S. workers: study

https://www.cnbc.com/2025/08/28/generative-ai-reshapes-us-job-market-stanford-study-shows-entry-l...
169•pseudolus•10h ago•260 comments

Launch HN: Dedalus Labs (YC S25) – Vercel for Agents

43•windsor•8h ago•11 comments

Rupert's Property

https://johncarlosbaez.wordpress.com/2025/08/28/a-polyhedron-without-ruperts-property/
19•robinhouston•2h ago•1 comments

A forgotten medieval fruit with a vulgar name (2021)

https://www.bbc.com/future/article/20210325-the-strange-medieval-fruit-the-world-forgot
65•ohjeez•1d ago•27 comments

Dependent types I › Universes, or types of types

https://www.jonmsterling.com/01ET/index.xml
7•matt_d•1d ago•0 comments

Bad Craziness

https://www.math.columbia.edu/~woit/wordpress/?p=15191
13•jjgreen•1h ago•2 comments

You no longer need JavaScript: an overview of what makes modern CSS so awesome

https://lyra.horse/blog/2025/08/you-dont-need-js/
82•todsacerdoti•4h ago•30 comments

Thrashing

https://exple.tive.org/blarg/2025/08/26/thrashing/
12•pch00•1d ago•1 comments

Speed-coding for the 6502 – a simple example

https://www.colino.net/wordpress/en/archives/2025/08/28/speed-coding-for-the-6502-a-simple-example/
18•mmphosis•3h ago•7 comments

Will AI Replace Human Thinking? The Case for Writing and Coding Manually

https://www.ssp.sh/brain/will-ai-replace-humans/
110•articsputnik•10h ago•90 comments

VLT observations of interstellar comet 3I/ATLAS II

https://arxiv.org/abs/2508.18382
44•bikenaga•6h ago•32 comments

Optimising for maintainability – Gleam in production at Strand

https://gleam.run/case-studies/strand/
87•Bogdanp•9h ago•21 comments

Show HN: SwiftAI – open-source library to easily build LLM features on iOS/macOS

https://github.com/mi12labs/SwiftAI
52•mi12-root•11h ago•11 comments

Web Bot Auth

https://developers.cloudflare.com/bots/reference/bot-verification/web-bot-auth/
38•ananddtyagi•6h ago•37 comments

In Search of AI Psychosis

https://www.astralcodexten.com/p/in-search-of-ai-psychosis
85•venkii•2d ago•48 comments

RFC 8594: The Sunset HTTP Header Field (2019)

https://datatracker.ietf.org/doc/html/rfc8594
24•aiven•5h ago•9 comments

I researched every attempt to stop fascism in history. The success rate is 0%

https://cmarmitage.substack.com/p/i-researched-every-attempt-to-stop
11•rbanffy•38m ago•8 comments

That boolean should probably be something else

https://ntietz.com/blog/that-boolean-should-probably-be-something-else/
84•vidyesh•12h ago•94 comments