Date: Thu, 15 Jan 2026 15:34:16 +0100
> On 15 Jan 2026, at 14:56, Thiago Macieira <thiago_at_[hidden]> wrote:
>
> On Thursday, 15 January 2026 00:53:07 Pacific Standard Time Hans Åberg wrote:
>>> All _BitInt of a power of 2 have exactly that size, with no padding bits.
>>> Therefore, _BitInt(256) or _BitInt(65536) *can* be as efficient as your
>>> code.
>>>
>>> _BitInt(4096) has exactly 4096 bits. Are you claiming that to get the best
>>> performance, it should be padded up to 65536 bits, the next power of 2
>>> raised to a power of 2 (k = 4)?
>>
>> The number 2^(2^k) is the modulus; the number of bits is 2^k.
>
> Ah, ok. Sorry.
>
> So this means _BitInt(4096) can be optimal. Therefore, we're not seeing any
> point in your proposal.
The original post is for a modular integer type int_mod<m> ≔ ℤ/mℤ, with a suggestion of limiting the modulus m to numbers that fit into a fixed-sized word, say up to 4096 bits for use in cryptology, as that can be easily implemented. One can have, with more effort, an unlimited modulus based on multiprecision words.
Implementation-wise, the ℤ/mℤ for different moduli m are compile-time different and can have special implementations. One can, say, factor out the power of 2 in m, and implement the set product, etc.
The bit integers are the special case when the modulus m is a power of 2; if m = 2^k, k is the number of bits.
>
> On Thursday, 15 January 2026 00:53:07 Pacific Standard Time Hans Åberg wrote:
>>> All _BitInt of a power of 2 have exactly that size, with no padding bits.
>>> Therefore, _BitInt(256) or _BitInt(65536) *can* be as efficient as your
>>> code.
>>>
>>> _BitInt(4096) has exactly 4096 bits. Are you claiming that to get the best
>>> performance, it should be padded up to 65536 bits, the next power of 2
>>> raised to a power of 2 (k = 4)?
>>
>> The number 2^(2^k) is the modulus; the number of bits is 2^k.
>
> Ah, ok. Sorry.
>
> So this means _BitInt(4096) can be optimal. Therefore, we're not seeing any
> point in your proposal.
The original post is for a modular integer type int_mod<m> ≔ ℤ/mℤ, with a suggestion of limiting the modulus m to numbers that fit into a fixed-sized word, say up to 4096 bits for use in cryptology, as that can be easily implemented. One can have, with more effort, an unlimited modulus based on multiprecision words.
Implementation-wise, the ℤ/mℤ for different moduli m are compile-time different and can have special implementations. One can, say, factor out the power of 2 in m, and implement the set product, etc.
The bit integers are the special case when the modulus m is a power of 2; if m = 2^k, k is the number of bits.
Received on 2026-01-15 14:34:36
