math

package
v0.0.0-...-a4a72b7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package math is a package that contains mathematical algorithms and its different implementations.

filename : krishnamurthy.go description: A program which contains the function that returns true if a given number is Krishnamurthy number or not. details: A number is a Krishnamurthy number if the sum of all the factorials of the digits is equal to the number. Ex: 1! = 1, 145 = 1! + 4! + 5! author(s): [GooMonk](https://github.com/GooMonk) see krishnamurthy_test.go

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptySlice = errors.New("empty slice provided")

ErrEmptySlice is the error returned by functions in math package when an empty slice is provided to it as argument when the function expects a non-empty slice.

View Source
var ErrNonZeroArgsOnly error = errors.New("arguments cannot be zero")
View Source
var ErrPosArgsOnly error = errors.New("arguments must be positive")

Functions

func Abs

func Abs(n int) int

Abs returns absolute value

func AliquotSum

func AliquotSum(n int) (int, error)

This function returns s(n) for given number

func Combinations

func Combinations(n int, k int) (int, error)

C is Binomial Coefficient function This function returns C(n, k) for given n and k

func Cos

func Cos(x float64) float64

Cos returns the cosine of the radian argument x. [See more](https://en.wikipedia.org/wiki/Sine_and_cosine) [Based on the idea of Bhaskara approximation of cos(x)](https://math.stackexchange.com/questions/3886552/bhaskara-approximation-of-cosx)

func DefaultPolynomial

func DefaultPolynomial(n *big.Int) func(*big.Int) *big.Int

DefaultPolynomial is the commonly used polynomial g(x) = (x^2 + 1) mod n

func FindKthMax

func FindKthMax(nums []int, k int) (int, error)

FindKthMax returns the kth large element given an integer slice with nil `error` if found and returns -1 with `error` `search.ErrNotFound` if not found. NOTE: The `nums` slice gets mutated in the process.

func FindKthMin

func FindKthMin(nums []int, k int) (int, error)

FindKthMin returns kth small element given an integer slice with nil `error` if found and returns -1 with `error` `search.ErrNotFound` if not found. NOTE: The `nums` slice gets mutated in the process.

func IsAutomorphic

func IsAutomorphic[T constraints.Integer](n T) bool

func IsKrishnamurthyNumber

func IsKrishnamurthyNumber[T constraints.Integer](n T) bool

IsKrishnamurthyNumber returns if the provided number n is a Krishnamurthy number or not.

func IsPerfectNumber

func IsPerfectNumber(inNumber uint) bool

Checks if inNumber is a perfect number

func IsPowOfTwoUseLog

func IsPowOfTwoUseLog(number float64) bool

IsPowOfTwoUseLog This function checks if a number is a power of two using the logarithm. The limiting degree can be from 0 to 63. See alternatives in the binary package.

func Lerp

func Lerp(v0, v1, t float64) float64

Lerp or Linear interpolation This function will return new value in 't' percentage between 'v0' and 'v1'

func LiouvilleLambda

func LiouvilleLambda(n int) (int, error)

Lambda is the liouville function This function returns λ(n) for given number

func Mean

func Mean[T constraints.Number](values []T) float64

func Median

func Median[T constraints.Number](values []T) float64

func Mode

func Mode[T constraints.Number](numbers []T) (T, error)

func Mu

func Mu(n int) int

Mu is the Mobius function This function returns μ(n) for given number

func Phi

func Phi(n int64) int64

Phi is the Euler totient function. This function computes the number of numbers less then n that are coprime with n.

func PollardsRhoFactorization

func PollardsRhoFactorization(n *big.Int, f func(n *big.Int) func(x *big.Int) *big.Int) (*big.Int, error)

PollardsRhoFactorization is an implementation of Pollard's rho factorization algorithm using the default parameters x = y = 2

func PronicNumber

func PronicNumber(n int) bool

PronicNumber returns true if argument passed to the function is pronic and false otherwise.

func Sin

func Sin(x float64) float64

Sin returns the sine of the radian argument x. [See more](https://en.wikipedia.org/wiki/Sine_and_cosine)

func SumOfProperDivisors

func SumOfProperDivisors(inNumber uint) uint

Returns the sum of proper divisors of inNumber.

Types

This section is empty.

Directories

Path Synopsis
Package binary describes algorithms that use binary operations for different calculations.
Package binary describes algorithms that use binary operations for different calculations.
Package factorial describes algorithms Factorials calculations.
Package factorial describes algorithms Factorials calculations.
Package geometry contains geometric algorithms
Package geometry contains geometric algorithms
filename: strassenmatrixmultiply.go description: Implements matrix multiplication using the Strassen algorithm.
filename: strassenmatrixmultiply.go description: Implements matrix multiplication using the Strassen algorithm.

Jump to

Keyboard shortcuts

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