algebra

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convergent

func Convergent[T common.Integers](n T, fn convergentSeries) (*big.Int, *big.Int)

Convergent returns the nth convergence of whichever series you pass in a function for

func DigitSum

func DigitSum[T common.Integers](n T) T

DigitSum returns the sum of the digits in the number

func DigitsToInt

func DigitsToInt(digits []int8) int

DigitsToInt converts a slice of digits to an int

func Divisors

func Divisors[T common.Integers](n T) []T

Divisors returns a sorted list of all positive divisors of n

func E

func E[T common.Integers](n T) int64

E returns the nth number (1-based) in the convergent series of e

func Factors

func Factors(n int) []int

Factors returns a sorted list of the unique prime factors of n

func FactorsCounted

func FactorsCounted(n int) map[int]int

FactorsCounted returns counts of how many times each factor divides into n

func GCD

func GCD[T common.Integers](a, b T) T

GCD returns the greatest common divisor of a and b

func GCDBigInt added in v0.0.11

func GCDBigInt(a, b *big.Int) *big.Int

GCDBigInt returns the greatest common divisor of a and b

func Hamming added in v0.11.0

func Hamming(n int) bool

Hamming returns true if n is a Hamming number (a 5-smooth number)

func Hammings added in v0.11.0

func Hammings(n int) []int

Hammings returns a sorted list of all Hamming numbers <= n

func Harshad

func Harshad[T common.Integers](n T) bool

Harshad returns true if n is divisible by the sum of its digits

func IntToDigits

func IntToDigits[T common.Integers](n T) []int8

IntToDigits converts an integer into a slice of its component digits

func IsCube

func IsCube[T common.Integers](n T) bool

IsCube returns true if n is a cube number

func IsInt

func IsInt[T common.Floats](n T) bool

IsInt returns true if n is an integer

func IsSquare

func IsSquare[T common.Integers](n T) bool

IsSquare returns true if n is a square number

func KSmooth added in v0.11.0

func KSmooth(n, k int) bool

KSmooth returns true if n is a k-smooth number

func KSmooths added in v0.15.0

func KSmooths(n, k int) []int

KSmooths returns a sorted list of all k-smooth numbers <= n

func LCM

func LCM[T common.Integers](a, b T) T

LCM returns the least common multiple of a and b

func LCMBigInt added in v0.0.11

func LCMBigInt(a, b *big.Int) *big.Int

LCMBigInt returns the least common multiple of a and b

func MaxBigInt added in v0.0.11

func MaxBigInt(a, b *big.Int) *big.Int

MaxBigInt returns the largest of a or b

func MinBigInt added in v0.0.11

func MinBigInt(a, b *big.Int) *big.Int

MinBigInt returns the smallest of a or b

func MulFraction

func MulFraction[T common.Integers](n1, d1, n2, d2 T) (T, T)

MulFraction returns the product of the two fractions, still in fraction form

func MulFractionBigInt added in v0.0.11

func MulFractionBigInt(n1, d1, n2, d2 *big.Int) (*big.Int, *big.Int)

MulFractionBigInt returns the product of the two fractions, still in fraction form

func NextSquare

func NextSquare[T common.Numbers](n T) (uint, uint)

NextSquare returns the next highest square and its square root

func PascalTriangle

func PascalTriangle(max int) [][]int

PascalTriangle returns a triangle of the max depth specified

func PowerMod added in v0.15.0

func PowerMod(base, exp, mod int) int

PowerMod returns (base^exp)%mod

func PythagoreanTriples added in v0.15.0

func PythagoreanTriples(upper int) [][3]int

PythagoreanTriples returns Pythagorean Triple primitives [a,b,c] where c <= upper

func ReduceFraction

func ReduceFraction[T common.Integers](n, d T) (T, T)

ReduceFraction returns the lowest that n and d reduce to

func ReduceFractionBigInt added in v0.0.11

func ReduceFractionBigInt(n, d *big.Int) (*big.Int, *big.Int)

ReduceFractionBigInt returns the lowest that n and d reduce to

func Sqrt2

func Sqrt2[T common.Integers](n T) int64

Sqrt2 returns the nth number (1-based) in the convergent series of root 2

func SquareFree

func SquareFree(n int) bool

SquareFree returns true if no square of a prime divides n

func SumFraction

func SumFraction[T common.Integers](n1, d1, n2, d2 T) (T, T)

SumFraction returns the sum of the two fractions, still in fraction form

func SumFractionBigInt added in v0.0.11

func SumFractionBigInt(n1, d1, n2, d2 *big.Int) (*big.Int, *big.Int)

SumFractionBigInt returns the sum of the two fractions, still in fraction form

func Totient

func Totient(n int) int

Totient returns how many numbers k are relatively prime to n

func Totients added in v0.11.0

func Totients(upper int) []int

Totients returns a slice where a[x] =ɸ(x) for 0 <= x <= upper

Types

This section is empty.

Jump to

Keyboard shortcuts

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