math

package
v1.2.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ZERO  = NewInt(0)
	ONE   = NewInt(1)
	TWO   = NewInt(2)
	THREE = NewInt(3)
	FOUR  = NewInt(4)
	FIVE  = NewInt(5)
	SIX   = NewInt(6)
	SEVEN = NewInt(7)
	EIGHT = NewInt(8)
)

Number constants

Functions

This section is empty.

Types

type Curve added in v1.2.32

type Curve interface {
	N() *Int
	G() Point
	Inf() Point

	Add(p1, p2 Point) Point
	Mult(k *Int, p Point) Point
}

type Field

type Field []complex128

Field instances are input/output objects for transformation methods.

type Int

type Int struct {
	// contains filtered or unexported fields
}

Int is an integer of arbitrary size

func NewInt

func NewInt(v int64) *Int

NewInt returns a new Int from an intrinsic int64

func NewIntFromBig

func NewIntFromBig(i *big.Int) *Int

NewIntFromBig creates a new Int from a *big.Int.

func NewIntFromBytes

func NewIntFromBytes(buf []byte) *Int

NewIntFromBytes converts a binary array into an unsigned integer.

func NewIntFromHex

func NewIntFromHex(s string) *Int

NewIntFromHex converts a hexadecimal string into an unsigned integer.

func NewIntFromString

func NewIntFromString(s string) *Int

NewIntFromString converts a string representation of an integer

func NewIntRnd

func NewIntRnd(j *Int) *Int

NewIntRnd creates a new random value between [0,j[

func NewIntRndBits

func NewIntRndBits(n int) *Int

NewIntRndBits creates a new random value with a max. bitlength.

func NewIntRndPrime

func NewIntRndPrime(j *Int) *Int

NewIntRndPrime generates a new random prime number between [0,j[

func NewIntRndPrimeBits

func NewIntRndPrimeBits(n int) *Int

NewIntRndPrimeBits generates a new random prime number with a maximum bitlength

func NewIntRndRange

func NewIntRndRange(lower, upper *Int) *Int

NewIntRndRange returns a random integer value within given range.

func SqrtModP

func SqrtModP(n, p *Int) (*Int, error)

SqrtModP computes the square root of a quadratic residue mod p It uses the Shanks-Tonelli algorithm to compute the square root see (http://en.wikipedia.org/wiki/Shanks%E2%80%93Tonelli_algorithm)

func (*Int) Abs

func (i *Int) Abs() *Int

Abs returns the unsigned value of an Int.

func (*Int) Add

func (i *Int) Add(j *Int) *Int

Add two Ints

func (*Int) Bit

func (i *Int) Bit(n int) uint

Bit returns the bit value of an Int at a given position.

func (*Int) BitLen

func (i *Int) BitLen() int

BitLen returns the number of bits in an Int.

func (*Int) Bytes

func (i *Int) Bytes() []byte

Bytes returns a byte array representation of the integer.

func (*Int) Cmp

func (i *Int) Cmp(j *Int) int

Cmp returns the comparison between two Ints.

func (*Int) Div

func (i *Int) Div(j *Int) *Int

Div divides two Int (no fraction)

func (*Int) DivMod

func (i *Int) DivMod(j *Int) (*Int, *Int)

DivMod returns the quotient and modulus of two Ints.

func (*Int) Equals

func (i *Int) Equals(j *Int) bool

Equals check if two Ints are equal.

func (*Int) ExtendedEuclid

func (i *Int) ExtendedEuclid(j *Int) [2]*Int

ExtendedEuclid computes the factors (x,y) for (a,b) where the following equation is satisfied: x*a + b*y = gcd(a,b)

func (*Int) FixedBytes

func (i *Int) FixedBytes(n int) []byte

FixedBytes returns a byte array representation of the integer of a given size.

func (*Int) GCD

func (i *Int) GCD(j *Int) *Int

GCD return the greatest common divisor of two Ints.

func (*Int) Int64

func (i *Int) Int64() int64

Int64 returns the int64 value of an Int.

func (*Int) LCM

func (i *Int) LCM(j *Int) *Int

LCM returns the least common multiplicative of two Ints.

func (*Int) Legendre

func (i *Int) Legendre(p *Int) int

Legendre computes (i\p)

func (*Int) Lsh

func (i *Int) Lsh(n uint) *Int

Lsh returns the left shifted value of an Int.

func (*Int) Mod

func (i *Int) Mod(j *Int) *Int

Mod returns the modulus of two Ints

func (*Int) ModInverse

func (i *Int) ModInverse(j *Int) *Int

ModInverse returns the multiplicative inverse of i in the ring ℤ/jℤ.

func (*Int) ModPow

func (i *Int) ModPow(n, m *Int) *Int

ModPow returns the modular exponentiation of an Int as (i^n mod m).

func (*Int) ModSign

func (i *Int) ModSign(j *Int) *Int

ModSign returns a signed modulus of two Ints.

func (*Int) Mul

func (i *Int) Mul(j *Int) *Int

Mul multiplies two Ints

func (*Int) Neg

func (i *Int) Neg() *Int

Neg flips the sign of an Int.

func (*Int) NextProbablePrime added in v1.2.32

func (i *Int) NextProbablePrime(n int) (j *Int)

NextProbablePrime returns the smallest prime larger than i,

func (*Int) NthRoot

func (i *Int) NthRoot(n int, upper bool) *Int

NthRoot computes the n.th root of an Int. If upper is set, the result is raised to the next highest value.

func (*Int) Pow

func (i *Int) Pow(n int) *Int

Pow raises an Int to power n.

func (*Int) ProbablyPrime

func (i *Int) ProbablyPrime(n int) bool

ProbablyPrime checks if an Int is prime. The chances this is wrong are less than 2^(-n).

func (*Int) Rsh

func (i *Int) Rsh(n uint) *Int

Rsh returns the right shifted value of an Int.

func (*Int) SetBit

func (i *Int) SetBit(n int, v uint) *Int

SetBit sets the bit value of an Int at a given position.

func (*Int) Sign

func (i *Int) Sign() int

Sign returns the sign of an Int.

func (*Int) String

func (i *Int) String() string

String converts an Int to a string representation.

func (*Int) Sub

func (i *Int) Sub(j *Int) *Int

Sub subtracts two Ints

type Kcheck added in v1.2.32

type Kcheck func(f []*Int, pos int64) int64

Kcheck is a callback to check if a sequence element is recurring. It is the task of the calback to compute the element from the list of factors and the initial values.

type Knacci added in v1.2.32

type Knacci struct {
	// contains filtered or unexported fields
}

Knacci generates a k-step Fibonacci sequence in a cyclic group C_n with elements S_i. Each S_i is a list of factors S_{i,j} (0 <= j < k). The k-nacci result v_i is computed from the initial values a_j as: v_i = Sum_{j=1}^{k}(S_{i,j}*a_j)

func NewKnacci added in v1.2.32

func NewKnacci(k int, N *Int) (kn *Knacci)

NewKnacci instantiates a new k-nacci on the group modulo N

func ReadKnacci added in v1.2.32

func ReadKnacci(rdr io.Reader) (kn *Knacci, err error)

ReadKnacci creates a Knacci from data in a file

func (*Knacci) Factors added in v1.2.32

func (kn *Knacci) Factors(n int64) []*Int

Factors returns the factor list at given position. If the position is zero, the current factor list is returned.

func (*Knacci) Next added in v1.2.32

func (kn *Knacci) Next() (step int64, f []*Int)

Next returns the next position and factor list

func (*Knacci) Recurrence added in v1.2.32

func (kn *Knacci) Recurrence(depth int64, check Kcheck) (f []*Int, p1, p2 int64)

Recurrence searches for a recurrence in the Fibonacci sequence. If successful, it returns the positions of the matching element (p1,p2) and the factor list at p2.

func (*Knacci) Reset added in v1.2.32

func (kn *Knacci) Reset()

Reset instance to initial conditions.

func (*Knacci) Solve added in v1.2.32

func (kn *Knacci) Solve(f1, f2, init []*Int) *Int

Solve the equation for the first initial value

func (*Knacci) Steps added in v1.2.32

func (kn *Knacci) Steps() *Int

Steps returns the real number of steps

func (*Knacci) Write added in v1.2.32

func (kn *Knacci) Write(wrt io.Writer) (err error)

Write Knacci instance to writer

type KnacciECC added in v1.2.32

type KnacciECC struct {
	*Knacci
	// contains filtered or unexported fields
}

KnacciECC is a k-nacci sequence of points on an elliptic

func NewKnacciECC added in v1.2.32

func NewKnacciECC(c Curve, d Point, r []*Int) *KnacciECC

KnacciECC creates a k-nacci sequence over an elliptic

func (*KnacciECC) Recurrence added in v1.2.32

func (kn *KnacciECC) Recurrence(depth int64, descr string) (f []*Int, p1, p2 int64)

Recurrence detects a recurring point. The memory only spans a limit timeframe (1e6 steps), so recurrences could possibly be missed.

func (*KnacciECC) Solve added in v1.2.32

func (kn *KnacciECC) Solve(f1, f2 []*Int) *Int

Solve the equation for the scalar of the first initial point.

func (*KnacciECC) Value added in v1.2.32

func (kn *KnacciECC) Value(f []*Int) (n Point)

compute point on E(p)

type KnacciInt added in v1.2.32

type KnacciInt struct {
	*Knacci
	// contains filtered or unexported fields
}

KnacciInt is a k-nacci integer sequence over a cyclic group C_n.

func NewKnacciInt added in v1.2.32

func NewKnacciInt(N *Int, init ...*Int) *KnacciInt

NewKnacciInt instantiates a new integer-based k-nacci.

func (*KnacciInt) Recurrence added in v1.2.32

func (kn *KnacciInt) Recurrence(depth int64, descr string) (f []*Int, p1, p2 int64)

Recurrence detects a recurring value. The memory only spans a limit timeframe (1e6 steps), so recurrences could possibly be missed.

func (*KnacciInt) Solve added in v1.2.32

func (kn *KnacciInt) Solve(f1, f2 []*Int) *Int

Solve the equation for the first initial value

func (*KnacciInt) Value added in v1.2.32

func (kn *KnacciInt) Value(f []*Int) (n *Int)

compute the current value of the sequence.

type Point added in v1.2.32

type Point interface {
	Equals(Point) bool
}

type Transformer

type Transformer struct {
	// contains filtered or unexported fields
}

Transformer type declaration (worker object for FF transformations).

func NewTransformer

func NewTransformer(n int) (*Transformer, error)

NewTransformer creates a new transformer worker instance.

func (*Transformer) Freq2Time

func (t *Transformer) Freq2Time(in Field) (Field, error)

Freq2Time transforms a frequency series into the time domain.

func (*Transformer) GetSize

func (t *Transformer) GetSize() int

GetSize returns the field size for a transformation worker instance.

func (*Transformer) Time2Freq

func (t *Transformer) Time2Freq(in Field) (Field, error)

Time2Freq transforms a time series into the frequency domain.

Directories

Path Synopsis
qs
sac

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL