MathExt

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AVG

func AVG(elems []float64) (float64, bool)

AVG calculates the average of a slice of float64 elements.

Parameters:

  • elems: The elements to calculate the average of.

Returns:

  • float64: The average of the elements.
  • bool: False if the slice is empty. True otherwise.

func Add

func Add(n1, n2 []int, base int) []int

Add adds two numbers of the same base. Both numbers are Least Significant Digit (LSD) first.

Parameters:

  • n1: The first number to add.
  • n2: The second number to add.
  • base: The base of the numbers.

Returns:

  • []int: The sum of the two numbers. Nil if the base is less than or equal to 0.

func ApproximateConvergence

func ApproximateConvergence(values []*big.Float, n int) (*big.Float, error)

ApproximateConvergence approximates the convergence of a series. It calculates the average of the last n values.

Parameters:

  • n: The number of values to calculate the average.

Returns:

  • *big.Float: The average of the last n values.
  • error: An error if the calculation fails.

Errors:

  • *luc.ErrInvalidParameter: If n is less than or equal to 0 or if there are not enough values to calculate the average.

func BigFloatDivision

func BigFloatDivision(numerator, denominator int) (*big.Float, error)

BigFloatDivision is a function that performs division on two integers and returns the result as a big.Float.

Parameters:

  • numerator: The numerator of the division.
  • denominator: The denominator of the division.

Returns:

  • *big.Float: The result of the division as a big.Float.
  • error: An error of type *ErrInvalidParameter if the numerator is negative or the denominator is less than or equal to 0.

func CalculateConvergence

func CalculateConvergence(series Serieser, upperLimit int, delta int) (values []*big.Float, err error)

CalculateConvergence calculates the convergence of a series. It calculates the quotient of the ith term and the (i+delta)th term.

Parameters:

  • series: The series to calculate the convergence.
  • upperLimit: The upper limit of the series to calculate the convergence.
  • delta: The difference between the terms to calculate the convergence.

Returns:

  • *ConvergenceResult: The convergence result.
  • error: An error if the calculation fails.

func GreatestCommonDivisor

func GreatestCommonDivisor(a, b int) int

GreatestCommonDivisor is a function that calculates the greatest common divisor (GCD) of two integers using the Euclidean algorithm.

Parameters:

  • a, b: The two integers to find the GCD of.

Returns:

  • int: The GCD of the two input numbers.

func IntToBigInt

func IntToBigInt(n int) *big.Int

IntToBigInt converts an integer to a big.Int.

Parameters:

  • n: The integer to convert.

Returns:

  • *big.Int: The big.Int representation of the integer.

func PrimeFactorization

func PrimeFactorization(inputNumber int) map[int]int

PrimeFactorization is a function that performs prime factorization on an input number.

Parameters:

  • inputNumber: The number to factorize.

Returns:

  • map[int]int: A map where the keys are the prime factors and the values are their respective powers. Nil if the input number is 0.

Behaviors:

  • The input number is converted to a positive number.
  • The prime factors are sorted in ascending order.
  • -1 and 1 are represented as [1: 1].
  • The resulting map does not contain any prime factor with a value of 1.

func SQM

func SQM(elems []float64) (float64, bool)

SQM calculates the Standard Quadratic Mean of a slice of float64 elements.

Parameters:

  • elems: The elements to calculate the SQM of.

Returns:

  • float64: The SQM of the elements.
  • bool: False if the slice is empty. True otherwise.

func Subtract

func Subtract(n1, n2 []int, base int) ([]int, error)

Subtract subtracts two numbers of the same base. Both numbers are Least Significant Digit (LSD) first.

Parameters:

  • n1: The number to subtract from.
  • n2: The number to subtract.
  • base: The base of the numbers.

Returns:

  • []int: The result of the subtraction.
  • error: An error if the subtraction failed.

Errors:

  • *ErrSubtractionUnderflow: The subtraction resulted in a negative number.
  • *errors.ErrInvalidParameter: The base is less than or equal to 0.

Types

type ErrSubtractionUnderflow

type ErrSubtractionUnderflow struct{}

ErrSubtractionUnderflow is an error that is returned when a subtraction operation results in a negative number.

func NewErrSubtractionUnderflow

func NewErrSubtractionUnderflow() *ErrSubtractionUnderflow

NewErrSubtractionUnderflow creates a new ErrSubtractionUnderflow error.

Returns:

  • *ErrSubtractionUnderflow: The new ErrSubtractionUnderflow error.

func (*ErrSubtractionUnderflow) Error

func (e *ErrSubtractionUnderflow) Error() string

Error is a method of ErrSubtractionUnderflow that returns the message: "subtraction underflow".

Returns:

  • string: The error message.

type LinearRegression

type LinearRegression struct {
	// A is the coefficient of the linear regression.
	A *big.Float

	// B is the exponent of the linear regression.
	B *big.Float
}

LinearRegression is a struct that holds the equation of a linear regression.

func NewLinearRegression

func NewLinearRegression() *LinearRegression

NewLinearRegression creates a new LinearRegression.

Returns:

  • LinearRegression: The new LinearRegression.

func (*LinearRegression) FindEquation

func (l *LinearRegression) FindEquation(values []*big.Float) bool

FindEquation is a method of ConvergenceResult that finds the equation of the series that best fits the convergence values.

The equation is of the form y = a * x^b.

Returns:

  • bool: False if there are less than 2 values to calculate the equation. True otherwise.

func (*LinearRegression) String

func (lr *LinearRegression) String() string

String implements the fmt.Stringer interface.

Format: y = a * x^b

type Serieser

type Serieser interface {
	// Term returns the nth term of the series.
	//
	// Parameters:
	//   - n: The term number.
	//
	// Returns:
	//   - *big.Int: The nth term of the series.
	//   - error: An error if the term cannot be calculated.
	Term(n int) (*big.Int, error)
}

Serieser is an interface for series.

Jump to

Keyboard shortcuts

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