Documentation
¶
Overview ¶
Package math re-exports big.Int utilities for backwards compatibility. New code should import github.com/luxfi/math/big directly.
Index ¶
- Variables
- func AbsDiff[T constraints.Unsigned](a, b T) T
- func Add[T constraints.Unsigned](a, b T) (T, error)
- func IsSortedBytes[T ~[]byte](s []T) bool
- func MaxUint[T constraints.Unsigned]() T
- func Mul[T constraints.Unsigned](a, b T) (T, error)
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func SafeSub(x, y uint64) (uint64, bool)
- func Sub[T constraints.Unsigned](a, b T) (T, error)
- func Zero[T any]() T
- type Averager
- type AveragerHeap
- type Decimal256
- type HexOrDecimal64
- type HexOrDecimal256
Constants ¶
This section is empty.
Variables ¶
var ( NewHexOrDecimal256 = luxbig.NewHexOrDecimal256 NewDecimal256 = luxbig.NewDecimal256 ParseBig256 = luxbig.ParseBig256 MustParseBig256 = luxbig.MustParseBig256 ParseUint64 = luxbig.ParseUint64 MustParseUint64 = luxbig.MustParseUint64 BigPow = luxbig.BigPow BigMax = luxbig.BigMax BigMin = luxbig.BigMin PaddedBigBytes = luxbig.PaddedBigBytes ReadBits = luxbig.ReadBits U256 = luxbig.U256 U256Bytes = luxbig.U256Bytes )
Function aliases for backwards compatibility.
var ( ErrOverflow = errors.New("overflow") ErrUnderflow = errors.New("underflow") // Deprecated: Add64 is deprecated. Use Add[uint64] instead. Add64 = Add[uint64] // Deprecated: Mul64 is deprecated. Use Mul[uint64] instead. Mul64 = Mul[uint64] )
MaxBig256 is the maximum value for a 256-bit unsigned integer.
Functions ¶
func AbsDiff ¶
func AbsDiff[T constraints.Unsigned](a, b T) T
AbsDiff returns the absolute difference between a and b.
func Add ¶
func Add[T constraints.Unsigned](a, b T) (T, error)
Add returns: 1) a + b 2) If there is overflow, an error
func IsSortedBytes ¶
IsSortedBytes returns true if s is sorted in ascending order.
func MaxUint ¶
func MaxUint[T constraints.Unsigned]() T
MaxUint returns the maximum value of an unsigned integer of type T.
func Mul ¶
func Mul[T constraints.Unsigned](a, b T) (T, error)
Mul returns: 1) a * b 2) If there is overflow, an error
func Sub ¶
func Sub[T constraints.Unsigned](a, b T) (T, error)
Sub returns: 1) a - b 2) If there is underflow, an error
Types ¶
type Averager ¶
type Averager interface {
// Observe the value at the given time
Observe(value float64, currentTime time.Time)
// Read returns the average of the provided values.
Read() float64
}
Averager tracks a continuous time exponential moving average of the provided values.
func NewAverager ¶
func NewSyncAverager ¶
func NewUninitializedAverager ¶
NewUninitializedAverager creates a new averager with the given halflife. If [Read] is called before [Observe], the zero value will be returned. When [Observe] is called the first time, the averager will be initialized with [value] at that time.
type AveragerHeap ¶
type AveragerHeap[K comparable] interface { // Add the average to the heap. If key is already in the heap, the // average will be replaced and the old average will be returned. If there // was not an old average, false will be returned. Add(key K, averager Averager) (Averager, bool) // Remove attempts to remove the average that was added with the provided // key, if none is contained in the heap, [false] will be returned. Remove(key K) (Averager, bool) // Pop attempts to remove the node with either the largest or smallest // average, depending on if this is a max heap or a min heap, respectively. Pop() (K, Averager, bool) // Peek attempts to return the node with either the largest or smallest // average, depending on if this is a max heap or a min heap, respectively. Peek() (K, Averager, bool) // Len returns the number of nodes that are currently in the heap. Len() int }
AveragerHeap maintains a heap of the averagers keyed by a comparable type. K is the key type (e.g., ids.NodeID).
func NewMaxAveragerHeap ¶
func NewMaxAveragerHeap[K comparable]() AveragerHeap[K]
NewMaxAveragerHeap returns a new empty max heap. The returned heap is not thread safe.
type HexOrDecimal64 ¶
type HexOrDecimal64 = luxbig.HexOrDecimal64
Type aliases for backwards compatibility.
type HexOrDecimal256 ¶
type HexOrDecimal256 = luxbig.HexOrDecimal256
Type aliases for backwards compatibility.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package backend defines how `luxfi/math` selects between CPU and GPU implementations of the same primitive.
|
Package backend defines how `luxfi/math` selects between CPU and GPU implementations of the same primitive. |
|
big
module
|
|
|
Package codec is the bounded-decode contract for every wire format in luxfi/math (and downstream luxfi/lattice, luxfi/pulsar, luxfi/fhe).
|
Package codec is the bounded-decode contract for every wire format in luxfi/math (and downstream luxfi/lattice, luxfi/pulsar, luxfi/fhe). |
|
cmd/emit_codec_kat
command
|
|
|
Package modarith provides modular-arithmetic primitives shared across every Lux cryptographic protocol.
|
Package modarith provides modular-arithmetic primitives shared across every Lux cryptographic protocol. |
|
cmd/emit_modarith_kat
command
|
|
|
Package ntt is the canonical Number-Theoretic-Transform interface for luxfi/math.
|
Package ntt is the canonical Number-Theoretic-Transform interface for luxfi/math. |
|
cmd/emit_ntt_kat
command
|
|
|
subring
Package subring owns the Lattigo-derived Montgomery NTT body — SubRing layout, root-table generator, scalar primitives (MRed/MRedLazy/MForm/BRed/CRed/...), the loop-unrolled-by-16 NTT kernel, and the SIMD AVX2 dispatch hooks.
|
Package subring owns the Lattigo-derived Montgomery NTT body — SubRing layout, root-table generator, scalar primitives (MRed/MRedLazy/MForm/BRed/CRed/...), the loop-unrolled-by-16 NTT kernel, and the SIMD AVX2 dispatch hooks. |
|
Package params is the single Lux registry of cryptographic parameter identifiers.
|
Package params is the single Lux registry of cryptographic parameter identifiers. |
|
Package poly provides polynomial-arithmetic primitives over R_q = Z_q[X] / (X^N + 1) used by every Lux lattice protocol.
|
Package poly provides polynomial-arithmetic primitives over R_q = Z_q[X] / (X^N + 1) used by every Lux lattice protocol. |
|
Package rns provides the Residue Number System primitives that FHE schemes use to operate over a chain of small primes instead of one large modulus.
|
Package rns provides the Residue Number System primitives that FHE schemes use to operate over a chain of small primes instead of one large modulus. |
|
safe
module
|
|
|
Package sample provides primitive samplers — uniform mod q, ternary, centered binomial, discrete Gaussian — used as building blocks by every Lux lattice protocol.
|
Package sample provides primitive samplers — uniform mod q, ternary, centered binomial, discrete Gaussian — used as building blocks by every Lux lattice protocol. |
|
cmd/emit_sample_kat
command
|
|