Documentation ¶
Overview ¶
Package algebra implements various generic algebra types.
Index ¶
- func Abs(x int) int
- func GCD(a, b int) int
- type BuiltinField
- type BuiltinRing
- type Cmplx
- type Complex
- func (Complex[T, R]) Add(z, w [2]T) [2]T
- func (Complex[T, R]) Conjugate(z [2]T) [2]T
- func (Complex[T, R]) Dot(z, w [2]T) T
- func (Complex[T, R]) Format(z [2]T) string
- func (Complex[T, R]) Identity() [2]T
- func (c Complex[T, R]) Inv(z [2]T) [2]T
- func (Complex[T, R]) Mul(z, w [2]T) [2]T
- func (Complex[T, R]) Neg(z [2]T) [2]T
- func (Complex[T, R]) ScalarMul(k T, z [2]T) [2]T
- func (Complex[T, R]) Zero() [2]T
- type DivisionRing
- type Field
- type Fieldable
- type GaussianInteger
- type Integer
- type Matrix
- func (Matrix[T, R]) Add(m, n grid.Dense[T]) grid.Dense[T]
- func (Matrix[T, R]) IdentityMatrix(n int) grid.Dense[T]
- func (M Matrix[T, R]) Mul(m, n grid.Dense[T]) grid.Dense[T]
- func (Matrix[T, R]) Neg(m grid.Dense[T]) grid.Dense[T]
- func (Matrix[T, R]) ScalarMul(k T, m grid.Dense[T]) grid.Dense[T]
- func (Matrix[T, R]) ZeroMatrix(h, w int) grid.Dense[T]
- type QR2
- type Quaternion
- func (Quaternion[T, R]) Add(x, y [4]T) [4]T
- func (Quaternion[T, R]) Conjugate(x [4]T) [4]T
- func (Quaternion[T, R]) Dot(x, y [4]T) T
- func (Quaternion[T, R]) Format(x [4]T) string
- func (Quaternion[T, R]) Identity() [4]T
- func (q Quaternion[T, R]) Inv(x [4]T) [4]T
- func (Quaternion[T, R]) Mul(x, y [4]T) [4]T
- func (Quaternion[T, R]) Neg(x [4]T) [4]T
- func (Quaternion[T, R]) ScalarMul(k T, x [4]T) [4]T
- func (Quaternion[T, R]) Zero() [4]T
- type Real
- type Ring
- type Ringable
- type Vector
- type VectorSpace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BuiltinField ¶
type BuiltinField[T Fieldable] struct{}
BuiltinField implements a field over T using built-in arithmetic.
func (BuiltinField[T]) Inv ¶
func (BuiltinField[T]) Inv(x T) T
Inv returns 1/x. This panics if x is zero.
type BuiltinRing ¶
type BuiltinRing[T Ringable] struct{}
BuiltinField implements a ring over T using built-in arithmetic.
type Cmplx ¶
type Cmplx = BuiltinField[complex128]
Cmplx implements ℂ using complex128 (not with the Complex type).
type Complex ¶
Complex implements complex numbers generically as a 2-dimensional algebra over any ring.
func (Complex[T, R]) Conjugate ¶
func (Complex[T, R]) Conjugate(z [2]T) [2]T
Conjugate returns the conjugate of z.
func (Complex[T, R]) Dot ¶
func (Complex[T, R]) Dot(z, w [2]T) T
Dot returns Re(z)*Re(w) + Im(z)*Im(w).
func (Complex[T, R]) Inv ¶
func (c Complex[T, R]) Inv(z [2]T) [2]T
Inv returns 1/z, or panics if R is not a division ring or is zero.
type DivisionRing ¶
DivisionRing is a Ring that also has multiplicative inverses (which can be expected to panic on zero). This is the same interface required for Field, but has a separate name to remind us that multiplication is not commutative. TODO: continue bothering with this distinction?
type Field ¶
type Field[T any] DivisionRing[T]
Field is a commutative division ring. The interface is the same.
type Fieldable ¶
type Fieldable interface { ~float32 | ~float64 | ~complex64 | ~complex128 }
Fieldable matches types with built-in arithmetic that can support a field.
type GaussianInteger ¶
GaussianInteger implements the integral domain ℤ[𝕚] using int.
type Matrix ¶
Matrix implements matrix algebra on grid.Dense[T] given a ring R.
func (Matrix[T, R]) IdentityMatrix ¶
IdentityMatrix returns an identity matrix of size n.
func (Matrix[T, R]) Mul ¶
Mul multiplies two matrices of compatible size (the width of m must equal the height of n)
type QR2 ¶
type QR2 struct{}
QR2 implements numbers in the algebraic number field ℚ(√2) (the rationals adjoined with √2). ℚ(√2) = {(a + b√2)/c : a,b,c ∈ ℤ}.
type Quaternion ¶
Quaternion implements quaternions generically as an algebra over some other ring. Traditional quaternions (ℍ) use ℝ.
func (Quaternion[T, R]) Conjugate ¶
func (Quaternion[T, R]) Conjugate(x [4]T) [4]T
Conjugate returns the quaternion conjugate. This is equal to the inverse for rotation quaternions (those with norm 1).
func (Quaternion[T, R]) Dot ¶
func (Quaternion[T, R]) Dot(x, y [4]T) T
Dot returns the dot product of q with r (treating them as 4D vectors).
func (Quaternion[T, R]) Format ¶
func (Quaternion[T, R]) Format(x [4]T) string
Format formats x into a string.
func (Quaternion[T, R]) Identity ¶
func (Quaternion[T, R]) Identity() [4]T
Identity returns 1 + 0𝕚 + 0𝕛 + 0𝕜
func (Quaternion[T, R]) Inv ¶
func (q Quaternion[T, R]) Inv(x [4]T) [4]T
Inv returns x⁻¹, or panics if R is not a division ring or x.x has no inverse.
func (Quaternion[T, R]) Mul ¶
func (Quaternion[T, R]) Mul(x, y [4]T) [4]T
Mul returns the quaternion product qr.
func (Quaternion[T, R]) ScalarMul ¶
func (Quaternion[T, R]) ScalarMul(k T, x [4]T) [4]T
ScalarMul returns k*x.
type Ring ¶
type Ring[T any] interface { Add(T, T) T Neg(T) T Zero() T Mul(T, T) T Identity() T }
Ring describes an algebraic structure with addition, negation, and multiplication. Rings also have a zero element and an identity element.
type Vector ¶
Vector implements a vector space for vectors of type []T and operations from any ring R.
func (Vector[T, R]) Dot ¶
func (Vector[T, R]) Dot(v, w []T) T
Dot returns the dot product (also known as inner product) v.w.
type VectorSpace ¶
type VectorSpace[V, K any] interface { Add(V, V) V Neg(V) V ScalarMul(K, V) V Dot(V, V) K }
VectorSpace describes a vector space (supports addition, scalar multiplication, and dot product).