Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Beating Floating Point at Its Own Game: Posit Arithmetic [pdf] (johngustafson.net)
89 points by xenophonf 16 hours ago | past | favorite | 28 comments
 help



Having witnessed the acceleration and adoption of IEEE754 close up (Weitek in the 80s), it is easy to underestimate the level of hardware tuning tricks baked into and developed around that standard.

I have made a spreadsheet app in Rust with exact and fast arithmetic, centered on Apache Arrow and Polars, so Integer (i64) and Float (f64) are joined by Decimal[n] (.parquet Decimal38) and Fraction(num/dec).

After considering some alternatives for Fraction, including BigRat and maybe interval arithmetic the current pick is symbolic handling of num/dec stored as .parquet Strings. Why? Well the other three types are fast, so it seems OK to have a slow but sure “back stop”.

It works well for Googol ranges of arithmetic and knows that 1/7+4/7 is 5/7. This seems good for teaching purposes and scratching the exactness itch.

Anyway, I’m open to adding Posit provided there’s a Rust crate (fast-posit.rs?) and a way to shoe horn them into parquet. Please raise an issue over at https://omasheet.org repo if this is of interest.


Funny thing about spreadsheets is that, if you want to be Excel-compatible, IEEE 754 isn't sufficient. Excel worries a lot about making floating point numbers feel like real numbers to non computer scientists, to the extent that it sacrifices precision to achieve the property that the digits you type might by truncated, but they'll never be rounded to a non-zero digit. And many Excel features work on numbers as displayed, rather than the underlying bytes. Numeric identity isn't bit-equivalence, in Excel (e.g., 0.3 == 0.1 + 0.2). And order isn't even transitive, for some applications (like filters).

It's very easy to make a spreadsheet that adds binary64 numbers faster than Excel.


Yes. Some programming languages (raku) allow for 0.1+0.2==0.3 (in that case Rats [or FatRats] are the default for decimal literals). Since Omasheet is built on Polars, I use their Decimal38 type for decimals, but conscious that that does not make 0.1+0.2=0.3, there is also a Fraction type with quotient literals and exact math for rational numbers.

Unlike Excel, Omasheet is kind of aimed at folk who know and care about numeric types. It has 6 base numeric types Integer(1), Fraction(1/1), Decimal(1.0), Float(1e0), Scientific(1e0(00)) and Complex(1+0i) to cover ℤ, ℚ, ℝ and ℂ conceptually [with basic uncertainty to handle CODATA 2022]. And, like Raku, operations between unlike operands go to the more infectious type - so sin(x) is always irrational (Float or Complex).

So this, necessarily, is a forced compromise between helping a wide number of math/ science/ data/ education centric users with a sensible set of strict types and having an eye to the Excel level of usability since in the main most users of a spreadsheet are just going to be chucking numbers in and expect it to work.

I started with Rust BigRat for Fraction, but I couldn't work out a way to line it up with the .parquet file format. Since the goal was to cover all kinds of arithmetic examples including "how many atoms in the universe" and "what is a Googol (100*100)" as well as proper fractions and ℚ without rounding. This works fine atm with symbolic num/den representation (stored as Parquet Struct of Strings. You need to cast into one of the other types to get the Polars engine speed of course, so this is mainly for extreme edge cases and purity.


IEEE 754 isn't sufficient. Excel worries a lot about making floating point numbers feel like real numbers to non computer scientists

William Kahan, father of IEEE 754, wrote about that: https://people.eecs.berkeley.edu/~wkahan/Mind1ess.pdf

> And many Excel features work on numbers as displayed, rather than the underlying bytes.

I think that’s a configuration flag


Very interesting, I am doing a review of the types right now so I will read that (and the fat document).

I'm the maintainer of fast-posit. It is not "feature complete" in the sense that it doesn't implement all those elementary functions prescribed by the standard, with 100% correct rounding (far beyond my powers :)). It does impl the four basic operations, sqrt, conversions between it and all fundamental Rust numeric types, comparisons, all quire operations (add, sub, dot product): everything correctly rounded, and tested exhaustively or with proptest. It also supports "bounded-posits" (one more parameter you tweak to make sure your type covers your expected domain accurately).

You're welcome to give it a try! https://github.com/andrepd/posit-rust/

I'm not sure how relevant it is to you, since you require exact arithmetic! In fact I'm not sure how you even use floats at all.


thanks! I'll take a look ... one of the scary/fun things about LLM era development is we could just make a posit spreadsheet ... the question is "why" ;-)

The paper’s central hw claim that a posit processing unit requires less circuitry and achieves higher POPS/W than an IEEE 754 FPU was empirically refuted by ASIC and FPGA implementations earlier this month.

Source: (https://www.researchgate.net/publication/417276683_Hardware_...)

TLDR; The leading 0 + dynamic length and the 512-bit accumulators for quires require hardware specifics like extra register per MAC and barrel shifters which take up about 30% of the total unit area.

Probably not impossible to get around but in no way a drop-in or currently better supported by HW.

---

Also non-uniform relative error is a nightmare for any numerical formal verifier that are used by most frontier labs today to avoid numerical divergence during training.


Is there any good walkthrough on how to multiply and add with posits without converting to an intermediate representation. I see the appeal of it as an encoding of numbers in bits, but the times I have looked at the process of working with them, they seemed either impenetrable or converted to a higher precision float did the operation and converted back.

If you mean a software implementation, I would daresay my impl is actually pretty readable :) https://github.com/andrepd/posit-rust/blob/main/src/posit/op.... It's also the fastest I'm aware of (at least back when I was working on it).

You do pretty much always have to convert to an intermediate representation of "mantissa + exponent". That is how IEEE754 impls work also. It is a bit more complex than IEEE to do so, because of the variable-length field, but surprisingly not too much so (count-leading-0 plus a couple of shifts and xors do the trick!) Less than 2ns on my machine :)


It's effectively a "slide rule" numerical system so (to avoid intermediate representations) multiplication become addition and addition becomes softmax, right?

I'm not sure what you mean by "slide rule" or "softmax" in this context :p but both binary IEEE and posits are essentially encodings of numbers of the form `(fraction / DENOMINATOR) * 2*exponent`, where `fraction` and `exponent` are integers and `DENOMINATOR` is fixed. The same general principles for implementing arithmetic operations apply for both.

Oh boy, this is a fun one. :)

Slide-rules are handy because they convert multiplication into addition. Or technically that's what logarithms do, and slide-rules are a physical implementation of logarithms.

Recall the classic identity:

log(x * y) = log(x) + log(y)

Slide-rules have multiple rulers, and some are marked in log scale, which lets you multiply totally mechanically! By aligning the markings, you effectively add two lengths, which (when read back on the log tick marks) becomes multiplication.

If you perform the same algebra transform as above, you see that addition becomes (oddly, but more intuitive the more you think about it) the Softmax function.

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

This is my first time seeing Posits, but (having had similar ideas loosely inspired by the Doom bit-hacks) I just assumed this was one of the main sales pitches for Posits!


I think you're overstating the claims and results of both papers. I would not regard anything in the first paper regarding how as a central claim (especially considering they did not really investigate hw implementations) and the second paper does review the challenges of hw implementations and importantly the progress toward as dressing them. I don't think it refutes the claim of the first paper that hw implementations could potentially be less complex, it simply shows that implementation is more significantly more difficult in reality (the quite being a significant part of the difficulties). I don't think it makes a statement that posits are fundamentally more complex (again considering it's a review it can't really make such claim).

This was an observational study not a constructional necessity ablation study, its design cannot support the conclusion you drew from it. Furthermore the conclusion for the latest gens is that it IS competitive when fixed.

You get a very different numerical system with bounded regime sizes. The system you get with fixed sizes isn't all that different from IEEE sans NaNs, denormals, etc.

This is quite an old paper. Much progress has been made since! Check out this paper from this year, showing an extension of the posit format (a new parameter besides bit count and exponent-field size, namely regime-field max size) that improves the mathematical properties of posits _and_ enables better hw designs https://arxiv.org/abs/2603.01615

> Also non-uniform relative error is a nightmare for any numerical formal verifier that are used by most frontier labs today to avoid numerical divergence during training.

I'm not sure what you mean by this. Yes IEEE has 40+ years of study behind it so its numerical properties are very well understood, that much is obvious. But I don't see what you are claiming exactly.


> I'm not sure what you mean by this

The floating-point number format has not been chosen due to some historical accident, but because it is the only number format that combines fast computation with almost constant relative error over the domain of the represented numbers.

In almost all scientific/technical computing applications, constant relative error is what is desired, and it also enables a relatively simple analysis of the error propagation.

The non-constant relative error of the posits makes the analysis of the error propagation very difficult. Many applications need accurate estimations of the worst-case errors that can affect the results.

For any number representation system where the relative error is not constant, decreasing the error in some part of the domain increases the error in other parts of the domain, because the number of values is the same, being determined by the number of bits.

For some weird reason, posits want smaller errors around the origin, and this is paid by greater errors far from the origin.

Perhaps there are applications where this is useful, but in decades of experience with various applications of scientific/engineering computing I never wanted this error behavior, but I always wanted the constant relative error provided by FP numbers, even very far from the origin, with few exceptions where constant absolute error was desired, which is provided by fixed-point numbers, not by posits.

So for me, posits are a solution in search for a problem, because I do not see which professional would want such a thing. Tailors might work with feet and inches, so posits might be adequate for them, but fixed-point numbers are even better for them, being easier to use and having a lower absolute error. On the other hand, an electronics engineer works with picoseconds, femtofarads, nanoamperes, megavolts, terahertz, the elementary electric charge, Planck's constant, Boltzmann's constant, Avogadro's constant and so on, for which posits are useless.

Perhaps posits might be better than floating-point for ML/AI applications, but I say this only because I do not know which properties of the numbers really matter in that application, unlike for scientific/engineering computations, where I know with certainty that posits are not suitable, by leading to greater computational errors, while having a chance to be faster only for small number formats, not for 64-bit or bigger numbers.


I'm not a numerical analyst, but what I've seen from Gustafson is that he's been at this game for over a decade. His original proposal was 'unums', which were essentially interval arithmetic, and heavily pitched on the basis of not needing numerical analysis to be able to do the sort of scientific computing that motivated floating-point. His book introducing the concept is literally titled "The End of Error" (although it's missing the word 'Analysis'). Then there was a "debate" between Gustafson and Kahan over unums versus floating-point [1], which, to my eyes, both sides lost [2].

Evidently, Gustafson felt he had to change tack because he seems to have dropped unums after that debate and changed entirely to posits. And in the change to posits, he seems to have dropped most of the actual benefits of unums he was touting, although he hasn't quite dropped some of the cultish language he uses around the concept. The main trick of posits is to achieve greater precision for numbers around ±1 and greater exponent range, but by brushing the trade-offs used to achieve that under the rug. Except there's not really any demand for greater exponent range, so the trade-offs really overwhelm the marginal benefit of higher precision for a very specific range of numbers.

The new paper linked in the comment you replied to appears to acknowledge this, even in the AI tiny floating-point space, by basically fixing a maximum exponent range so that you have usable precision at higher exponents.

[1] I'd say IEEE floating-point, but the principles that Gustafson is attacking are found in virtually all formats pre-IEEE 754, with the exception of NaNs.

[2] The transcript is here, for the reader to decide for themselves: http://www.johngustafson.net/pdfs/DebateTranscription.pdf


There is also Takum arithmetic https://arxiv.org/abs/2404.18603

Worth noting that while these may be smaller than equivalent floats for many values (and indeed, for some applications a 32-bit posit could replace a 64-bit double), they lose precision far more rapidly at larger values, they lack NaN and Infinity entirely, and saturation can silently create enormously incorrect results. Also, attempts at creating hardware implementations have found them far more difficult and bulky than for floats, partly because of all the variable-length shenanigans.

Still, it's quite nice to see yet another option for representing magnitudes in programming. Given the right domain, these could show many benefits indeed.


They have an infinity. It's unsigned and you should probably treat it like a NaN.

But yeah the tradeoff between precision and range is harsh.


Their diagrams represent maxpos as an infinity, but it is simply the limit of their saturating arithmetic, and is just another finite value. If it ever gets into your calculation, you can end up with an incorrect result without realizing maxpos ever happened, and it could be infinitely incorrect.

At least with IEEE 754 Infinity, it corrupts your entire calculation into Infinity or NaN and then that's obvious in the result. Rounding errors, even compounding ones are also not nearly such a big issue.


Maxpos is 0111111, negative maxpos is 1000001. Bit pattern 1000000 used to be infinity but is now "not a real" (I had forgotten the change when I made the previous comment). Combining infinity with NaN means it's even less sneaky than in IEEE, because dividing by it won't give you zero.

Edit: I guess if you saturate and later divide you might escape maxpos without ever hitting infinity/NaR but that risk doesn't seem significantly worse than standard floating point, just different.


Ah wait, you are correct, I misinterpreted the paper. maxpos and infinity are indeed distinct, my bad.

> they lack NaN and Infinity entirely

These are frequently ditched in AI accelerators anyway, so that's arguably a feature (at least for AI).


dunno why, but subconsciouslly this all weirdly reminds of what they do in RoPE and TurboQuant

That's probably down to the two-axis rotational representation, though my understanding of posits is that a lot of the love comes from reflection operations positionally.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: