News for hackers. Stuff that matters.
Re:Galois field instructions on 2021 CPUs by sbf501 on Sunday November 06, 2022 @01:03PM (#33495340)
Why is 256 == 0 computer friendly and 251 == 0 reduction math friendly? Other than modulus bias, that initial assertion isn't clear to me. I mean, you can say "well, 251 isn't 2^N" which is abundantly obvious, but why does that matter? Is it because you can't create a bit polynomial for a non-power-of-two reduction?
Re:Galois field instructions on 2021 CPUs by jacoblambda on Sunday November 06, 2022 @01:18PM (#33495477)
`251 == 0` is maths friendly because 251 is a prime number. Like the article outlines, this means that for any given number x in the field, there exists some other y where `x * y == 1`. This isn't necessarily the case for non-primes.

When that breaks down, you can no longer invert numbers in a reversible way. aka `1/(1/x) == x` no longer holds true. This means you can no longer easily manipulate values or equations using the common set of properties established for most mathematics, hence "not maths friendly".

Re:Galois field instructions on 2021 CPUs by creata on Sunday November 06, 2022 @04:27PM (#33497405)
> Like the article outlines, this means that for any given number x in the field, there exists some other y where `x * y == 1`. This isn't necessarily the case for non-primes.

Your use of the word "field" here hurts my head. The integers mod k form a field (under the usual addition and multiplication) precisely when k is prime. The elements of a field always have inverses.

Re:Galois field instructions on 2021 CPUs by sbf501 on Sunday November 06, 2022 @04:31PM (#33497449)
So P=256 cannot define a field because it isn't prime?
Re:Galois field instructions on 2021 CPUs by creata on Sunday November 06, 2022 @04:32PM (#33497458)
There is a field with 256 elements, because 256 is the power of a prime. But that field is not the integers mod 256: it has different rules for addition and multiplication.
Re:Galois field instructions on 2021 CPUs by sbf501 on Sunday November 06, 2022 @04:36PM (#33497514)
Ah, thanks! Fields are a lot less intimidating than I thought they would be! Well, I mean: the basic idea (after reading these replies + wikipedia).
Re:Galois field instructions on 2021 CPUs by vmilner on Sunday November 06, 2022 @05:23PM (#33498097)
There is a finite field (or Galois field GF(p)) of size p for any prime p. This can be exhibited by integers mod p.

There are also finite (Galois) fields GF(p^n) of size p^n (positive integer powers of p)

These can be exhibited by polynomials with coefficients in the GF(p) field with up to n terms.

Eg for p = 2 and n = 3

0

1

x

1 + x

1 + x + x^2

1 + x^2

x + x^2

x^2

Re:Galois field instructions on 2021 CPUs by chriswarbo on Sunday November 06, 2022 @01:20PM (#33495501)
It's mentioned later, but the "math friendly" versions satisfy the axioms of a group and a field, which only works if the modulus is a prime.

In particular, all non-zero values have a unique inverse:

> As 251 is prime, this reduction rule is math-friendly. By that, I mean that for any x other than zero, there is some y such that x * y == 1. For example, taking x of 16, we have 16 * 204 == 1. This property is not true for the 256 == 0 reduction rule; with that rule, there is no y such that 16 * y == 1. Where it exists, this y can be called inv(x) or 1/x.

Re:Galois field instructions on 2021 CPUs by hither_shores on Sunday November 06, 2022 @06:54PM (#33499059)
> It's mentioned later, but the "math friendly" versions satisfy the axioms of a group and a field, which only works if the modulus is a prime.

The integers mod n >= 1 are always a group (under addition), only the field structure requires prime n.

Re:Galois field instructions on 2021 CPUs by voldacar on Sunday November 06, 2022 @07:38PM (#33499493)
It doesn't have to be a prime, it can also be a prime power
Re:Galois field instructions on 2021 CPUs by kccqzy on Sunday November 06, 2022 @01:23PM (#33495530)
The article is trying to get to the concept of a group inverse without using too much jargon. If you don't mind jargon, as usual you'll want to go to Wikipedia to learn more.

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

Re:Galois field instructions on 2021 CPUs by wging on Sunday November 06, 2022 @01:38PM (#33495682)
I'd suggest https://en.wikipedia.org/wiki/Finite_field - they'd probably get to the page you linked in trying to understand finite fields, but finite fields (AKA Galois fields) are exactly what the post is about.
Re:Galois field instructions on 2021 CPUs by AlotOfReading on Sunday November 06, 2022 @01:29PM (#33495597)
All modern computers are implemented with binary digital logic. If you build the hardware the obvious, computing mod 256 is just masking the lower 8 bits or nothing at all if it's an 8 bit register. Computing mod arbitrary N is equivalent to doing integer division, which is an inherently complex operation that's typically anywhere from 10-100x slower. It also scales much worse for very large operands.
Re:Galois field instructions on 2021 CPUs by vbezhenar on Sunday November 06, 2022 @06:15PM (#33498621)
There were computers with triary digital logic. Can we make a computers which would store 251 values per bit (using variable voltage, for example, or something like that)?
Re:Galois field instructions on 2021 CPUs by AlotOfReading on Sunday November 06, 2022 @06:51PM (#33499025)
There's no inherent reason you couldn't, but it'd almost certainly be faster, cheaper, and vastly more reliable to do it with binary logic.

In actual practice what we typically do is select primes that are "near" a power of two, called the Mersenne primes (which have the form 2^N - 1) and Pseudo-Mersenne primes (2^N - a). These have special properties that let us work with them more efficiently. Modern algorithms for these kinds of special cases are branchless, divisionless, and constant time, even if they're not quite as fast as operations in the binary fields.