factor

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package factor defines basic factors: rationals and symbols.

Index

Constants

This section is empty.

Variables

View Source
var ErrDone = errors.New("factor parsing done")
View Source
var ErrSyntax = errors.New("syntax problem")

Functions

func Order added in v0.5.2

func Order(a []Value) int

Order returns the power complexity of the Value slice, a.

func Prod

func Prod(vs ...Value) string

Prod returns a string representing a product of values. This function does not attempt to simplify the array first.

func ValidSymbol added in v0.7.0

func ValidSymbol(token string) bool

ValidSymbol confirms that a symbol can be considered externally meaningful. Various packages may use other forms for book keeping purposes (factoring etc), but for "external" purposes this is the only valid form.

Types

type ByAlpha

type ByAlpha []Value

func (ByAlpha) Len

func (a ByAlpha) Len() int

func (ByAlpha) Less

func (a ByAlpha) Less(i, j int) bool

func (ByAlpha) Swap

func (a ByAlpha) Swap(i, j int)

type Value

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

Value captures a single factor. It is either a number or a symbol.

func D

func D(num, den int64) Value

D converts two integers to a rational number value.

func Den

func Den(vs []Value) []Value

Den picks all of the negative power symbols from a list of values and inverts them.

func GCF

func GCF(a, b []Value) []Value

GCF returns the greatest common factor of a set of symbolic terms.

func I

func I(n *big.Int) Value

I copies an integer value into a number value.

func Inv

func Inv(a []Value) []Value

Inv generates the inverse of a set of symbolic factors. It ignores Values with no symbol.

func LCP

func LCP(a, b []Value) []Value

LCP returns the least common product of a set of symbolic terms.

func Parse

func Parse(s string) ([]Value, int, error)

Parse parses a simple list of string arguments into an product of factors. Supported combinations are:

-33*y*x  -> -33*x*y
+33*x^4*y^-3*z/x/3 -> 11*x^3*y^-3*z

func R

func R(n *big.Rat) Value

R copies a rational value into a number value.

func Replace

func Replace(a, b, c []Value, max int) (int, []Value)

Replace replaces copies of b found in a with c. The number of times b appeared in a is returned as well as the replaced array of factors.

func S

func S(sym string) Value

S converts a string into a symbol value.

func Segment

func Segment(vs ...Value) (*big.Rat, []Value, string)

Segment simplifies a set of factors and returns the numerical coefficient, the non-numeric array of factors and a string representation of this array of non-numeric factors.

func Simplify

func Simplify(vs ...Value) []Value

Simplify condenses an unsorted array (product) of values into a simplified (ordered) form.

func Sp

func Sp(sym string, pow int) Value

Sp converts a string, power to a symbol value.

func (Value) IsNum

func (v Value) IsNum() bool

IsNum indicates that v is a rational number.

func (Value) Num

func (v Value) Num() *big.Rat

Num simply returns the num value of the term.

func (Value) String

func (v Value) String() string

String displays a single factor.

func (Value) Symbol

func (v Value) Symbol() string

Symbol returns the symbol associated with this value or "" if no symbol is present in v.

Jump to

Keyboard shortcuts

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