Documentation ¶
Overview ¶
Package quat implements arithmetic for Hamilton, Cockle, and Macfarlane quaternions.
Index ¶
- type Cockle
- func (z *Cockle) Add(x, y *Cockle) *Cockle
- func (z *Cockle) Commutator(x, y *Cockle) *Cockle
- func (z *Cockle) Conj(y *Cockle) *Cockle
- func (z *Cockle) Copy(y *Cockle) *Cockle
- func (z *Cockle) Curv() (r, ξ, θ1, θ2 float64, sign int)
- func (z *Cockle) Dil(y *Cockle, a float64) *Cockle
- func (z *Cockle) Equals(y *Cockle) bool
- func (z *Cockle) Inv(x *Cockle) *Cockle
- func (z *Cockle) IsIndempotent() bool
- func (z *Cockle) IsInf() bool
- func (z *Cockle) IsNaN() bool
- func (z *Cockle) IsNilpotent(n int) bool
- func (z *Cockle) IsZeroDiv() bool
- func (z *Cockle) Mul(x, y *Cockle) *Cockle
- func (z *Cockle) Neg(y *Cockle) *Cockle
- func (z *Cockle) Quad() float64
- func (z *Cockle) Quo(x, y *Cockle) *Cockle
- func (z *Cockle) Scal(y *Cockle, a complex128) *Cockle
- func (z *Cockle) String() string
- func (z *Cockle) Sub(x, y *Cockle) *Cockle
- type Hamilton
- func (z *Hamilton) Add(x, y *Hamilton) *Hamilton
- func (z *Hamilton) Cartesian() (a, b, c, d float64)
- func (z *Hamilton) Commutator(x, y *Hamilton) *Hamilton
- func (z *Hamilton) Conj(y *Hamilton) *Hamilton
- func (z *Hamilton) Copy(y *Hamilton) *Hamilton
- func (z *Hamilton) Curv() (r, θ1, θ2, θ3 float64)
- func (z *Hamilton) Dil(y *Hamilton, a float64) *Hamilton
- func (z *Hamilton) Equals(y *Hamilton) bool
- func (z *Hamilton) Im() complex128
- func (z *Hamilton) Inv(y *Hamilton) *Hamilton
- func (z *Hamilton) IsInf() bool
- func (z *Hamilton) IsNaN() bool
- func (z *Hamilton) Mul(x, y *Hamilton) *Hamilton
- func (z *Hamilton) Neg(y *Hamilton) *Hamilton
- func (z *Hamilton) Quad() float64
- func (z *Hamilton) Quo(x, y *Hamilton) *Hamilton
- func (z *Hamilton) Re() complex128
- func (z *Hamilton) Scal(y *Hamilton, a complex128) *Hamilton
- func (z *Hamilton) SetIm(b complex128)
- func (z *Hamilton) SetRe(a complex128)
- func (z *Hamilton) String() string
- func (z *Hamilton) Sub(x, y *Hamilton) *Hamilton
- type Macfarlane
- func (z *Macfarlane) Add(x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) AlternatorL(x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) AlternatorR(x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Associator(w, x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Commutator(x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Conj(y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Copy(x *Macfarlane) *Macfarlane
- func (z *Macfarlane) Curv() (r, ξ, θ1, θ2 float64, sign int)
- func (z *Macfarlane) Equals(y *Macfarlane) bool
- func (z *Macfarlane) Inv(x *Macfarlane) *Macfarlane
- func (z *Macfarlane) IsIndempotent() bool
- func (z *Macfarlane) IsInf() bool
- func (z *Macfarlane) IsNaN() bool
- func (z *Macfarlane) IsZeroDiv() bool
- func (z *Macfarlane) Mul(x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Neg(y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Quad() float64
- func (z *Macfarlane) Quo(x, y *Macfarlane) *Macfarlane
- func (z *Macfarlane) Scal(y *Macfarlane, a float64) *Macfarlane
- func (z *Macfarlane) String() string
- func (z *Macfarlane) Sub(x, y *Macfarlane) *Macfarlane
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cockle ¶
type Cockle [2]complex128
A Cockle represents a Cockle quaternion (also known as a split-quaternion) as an ordered array of two complex128 values.
func CockleInf ¶
CockleInf returns a pointer to a Cockle quaternionic infinity value.
Example ¶
fmt.Println(CockleInf(-1, 0, 0, 0)) fmt.Println(CockleInf(0, -1, 0, 0)) fmt.Println(CockleInf(0, 0, -1, 0)) fmt.Println(CockleInf(0, 0, 0, -1))
Output: (-Inf+Infi+Inft+Infu) (+Inf-Infi+Inft+Infu) (+Inf+Infi-Inft+Infu) (+Inf+Infi+Inft-Infu)
func CockleNaN ¶
func CockleNaN() *Cockle
CockleNaN returns a pointer to a Cockle quaternionic NaN value.
Example ¶
fmt.Println(CockleNaN())
Output: (NaN+NaNi+NaNt+NaNu)
func NewCockle ¶
NewCockle returns a pointer to a Cockle value made from four given float64 values.
Example ¶
fmt.Println(NewCockle(1, 0, 0, 0)) fmt.Println(NewCockle(0, 1, 0, 0)) fmt.Println(NewCockle(0, 0, 1, 0)) fmt.Println(NewCockle(0, 0, 0, 1)) fmt.Println(NewCockle(1, 2, 3, 4))
Output: (1+0i+0t+0u) (0+1i+0t+0u) (0+0i+1t+0u) (0+0i+0t+1u) (1+2i+3t+4u)
func RectCockle ¶
RectCockle returns a Cockle value made from given curvilinear coordinates and quadrance sign.
func (*Cockle) Commutator ¶
Commutator sets z equal to the commutator of x and y, and returns z.
func (*Cockle) Curv ¶
Curv returns the curvilinear coordinates of a Cockle value, along with the sign of the quadrance.
func (*Cockle) Dil ¶
Dil sets z equal to the dilation of y by a, and returns z.
This is a special case of Mul:
Dil(y, a) = Mul(y, Cockle{complex(a, 0), 0})
func (*Cockle) Inv ¶
Inv sets z equal to the inverse of x, and returns z. If x is a zero divisor, then Inv panics.
func (*Cockle) IsIndempotent ¶
IsIndempotent returns true if z is an indempotent (i.e. if z = z*z).
func (*Cockle) IsNilpotent ¶
IsNilpotent returns true if z raised to the nth power vanishes.
func (*Cockle) IsZeroDiv ¶
IsZeroDiv returns true if z is a zero divisor (i.e. it has zero quadrance).
func (*Cockle) Mul ¶
Mul sets z equal to the product of x and y, and returns z.
The multiplication rule for the basis elements i := Cockle{0, 1, 0, 0}, t := Cockle{0, 0, 1, 0}, and u := Cockle{0, 0, 0, 1} is:
Mul(i, i) = Cockle{-1, 0, 0, 0} Mul(t, t) = Mul(u, u) = Cockle{1, 0, 0, 0} Mul(i, t) = -Mul(t, i) = +u Mul(t, u) = -Mul(u, t) = -i Mul(u, i) = -Mul(i, u) = +t
func (*Cockle) Quad ¶
Quad returns the quadrance of z, which can be either positive, negative or zero.
func (*Cockle) Quo ¶
Quo sets z equal to the quotient of x and y, and returns z. If y is a zero divisor, then Quo panics.
func (*Cockle) Scal ¶
func (z *Cockle) Scal(y *Cockle, a complex128) *Cockle
Scal sets z equal to y scaled by a (with a being a complex128), and returns z.
This is a special case of Mul:
Scal(y, a) = Mul(y, Cockle{a, 0})
type Hamilton ¶
type Hamilton [2]complex128
A Hamilton represents a Hamilton quaternion (i.e. a traditional quaternion) as an ordered array of two complex128 values.
func HamiltonInf ¶
HamiltonInf returns a pointer to a Hamilton quaternionic infinity value.
Example ¶
fmt.Println(HamiltonInf(-1, 0, 0, 0)) fmt.Println(HamiltonInf(0, -1, 0, 0)) fmt.Println(HamiltonInf(0, 0, -1, 0)) fmt.Println(HamiltonInf(0, 0, 0, -1))
Output: (-Inf+Infi+Infj+Infk) (+Inf-Infi+Infj+Infk) (+Inf+Infi-Infj+Infk) (+Inf+Infi+Infj-Infk)
func HamiltonNaN ¶
func HamiltonNaN() *Hamilton
HamiltonNaN returns a pointer to a Hamilton quaternionic NaN value.
Example ¶
fmt.Println(HamiltonNaN())
Output: (NaN+NaNi+NaNj+NaNk)
func NewHamilton ¶
NewHamilton returns a pointer to a Hamilton value made from four given float64 values.
Example ¶
fmt.Println(NewHamilton(1, 0, 0, 0)) fmt.Println(NewHamilton(0, 1, 0, 0)) fmt.Println(NewHamilton(0, 0, 1, 0)) fmt.Println(NewHamilton(0, 0, 0, 1)) fmt.Println(NewHamilton(1, 2, 3, 4))
Output: (1+0i+0j+0k) (0+1i+0j+0k) (0+0i+1j+0k) (0+0i+0j+1k) (1+2i+3j+4k)
func RectHamilton ¶
RectHamilton returns a Hamilton value made from given curvilinear coordinates.
Example ¶
{ }
Output:
func (*Hamilton) Commutator ¶
Commutator sets z equal to the commutator of x and y, and returns z.
func (*Hamilton) Dil ¶
Dil sets z equal to the dilation of y by a, and returns z.
This is a special case of Mul:
Dil(y, a) = Mul(y, Hamilton{complex(a, 0), 0})
func (*Hamilton) Im ¶
func (z *Hamilton) Im() complex128
Im returns the Cayley-Dickson imaginary part of z, a complex128 value.
func (*Hamilton) Inv ¶
Inv sets z equal to the inverse of y, and returns z. If y is zero, then Inv panics.
func (*Hamilton) IsNaN ¶
IsNaN returns true if any component of z is NaN and neither is an infinity.
func (*Hamilton) Mul ¶
Mul sets z equal to the product of x and y, and returns z.
The multiplication rule for the basis elements i := Hamilton{0, 1, 0, 0}, j := Hamilton{0, 0, 1, 0}, and k := Hamilton{0, 0, 0, 1} is:
Mul(i, i) = Mul(j, j) = Mul(k, k) = Hamilton{-1, 0, 0, 0} Mul(i, j) = -Mul(j, i) = +k Mul(j, k) = -Mul(k, j) = +i Mul(k, i) = -Mul(i, k) = +j
func (*Hamilton) Quo ¶
Quo sets z equal to the quotient of x and y, and returns z. If y is zero, then Quo panics.
func (*Hamilton) Re ¶
func (z *Hamilton) Re() complex128
Re returns the Cayley-Dickson real part of z, a complex128 value.
func (*Hamilton) Scal ¶
func (z *Hamilton) Scal(y *Hamilton, a complex128) *Hamilton
Scal sets z equal to y scaled by a (with a being a complex128), and returns z.
This is a special case of Mul:
Scal(y, a) = Mul(y, Hamilton{a, 0})
func (*Hamilton) SetIm ¶
func (z *Hamilton) SetIm(b complex128)
SetIm sets the Cayley-Dickson imaginary part of z equal to a given complex128 value.
func (*Hamilton) SetRe ¶
func (z *Hamilton) SetRe(a complex128)
SetRe sets the Cayley-Dickson real part of z equal to a given complex128 value.
type Macfarlane ¶
type Macfarlane [4]float64
A Macfarlane represents a Macfarlane quaternion (also known as a hyperbolic quaternion) as an ordered list of four float64 values.
func MacfarlaneInf ¶
func MacfarlaneInf(a, b, c, d int) *Macfarlane
MacfarlaneInf returns a pointer to a Macfarlane quaternionic infinity value.
Example ¶
fmt.Println(MacfarlaneInf(-1, 0, 0, 0)) fmt.Println(MacfarlaneInf(0, -1, 0, 0)) fmt.Println(MacfarlaneInf(0, 0, -1, 0)) fmt.Println(MacfarlaneInf(0, 0, 0, -1))
Output: (-Inf+Infs+Inft+Infu) (+Inf-Infs+Inft+Infu) (+Inf+Infs-Inft+Infu) (+Inf+Infs+Inft-Infu)
func MacfarlaneNaN ¶
func MacfarlaneNaN() *Macfarlane
MacfarlaneNaN returns a pointer to a Macfarlane quaternionic NaN value.
Example ¶
fmt.Println(MacfarlaneNaN())
Output: (NaN+NaNs+NaNt+NaNu)
func NewMacfarlane ¶
func NewMacfarlane(a, b, c, d float64) *Macfarlane
NewMacfarlane returns a pointer to an Macfarlane value made from four given float64 values.
Example ¶
fmt.Println(NewMacfarlane(1, 0, 0, 0)) fmt.Println(NewMacfarlane(0, 1, 0, 0)) fmt.Println(NewMacfarlane(0, 0, 1, 0)) fmt.Println(NewMacfarlane(0, 0, 0, 1)) fmt.Println(NewMacfarlane(1, 2, 3, 4))
Output: (1+0s+0t+0u) (0+1s+0t+0u) (0+0s+1t+0u) (0+0s+0t+1u) (1+2s+3t+4u)
func RectMacfarlane ¶
func RectMacfarlane(r, ξ, θ1, θ2 float64, sign int) *Macfarlane
RectMacfarlane returns a Macfarlane value made from given curvilinear coordinates and quadrance sign.
func (*Macfarlane) Add ¶
func (z *Macfarlane) Add(x, y *Macfarlane) *Macfarlane
Add sets z equal to the sum of x and y, and returns z.
func (*Macfarlane) AlternatorL ¶
func (z *Macfarlane) AlternatorL(x, y *Macfarlane) *Macfarlane
AlternatorL sets z equal to the left alternator of x and y, and returns z.
func (*Macfarlane) AlternatorR ¶
func (z *Macfarlane) AlternatorR(x, y *Macfarlane) *Macfarlane
AlternatorR sets z equal to the right alternator of x and y, and returns z.
func (*Macfarlane) Associator ¶
func (z *Macfarlane) Associator(w, x, y *Macfarlane) *Macfarlane
Associator sets z equal to the associator of w, x, and y, and returns z.
func (*Macfarlane) Commutator ¶
func (z *Macfarlane) Commutator(x, y *Macfarlane) *Macfarlane
Commutator sets z equal to the commutator of x and y, and returns z.
func (*Macfarlane) Conj ¶
func (z *Macfarlane) Conj(y *Macfarlane) *Macfarlane
Conj sets z equal to the conjugate of y, and returns z.
func (*Macfarlane) Copy ¶
func (z *Macfarlane) Copy(x *Macfarlane) *Macfarlane
Copy copies x onto z, and returns z.
func (*Macfarlane) Curv ¶
func (z *Macfarlane) Curv() (r, ξ, θ1, θ2 float64, sign int)
Curv returns the curvilinear coordinates of a Macfarlane value, along with the sign of the quadrance.
func (*Macfarlane) Equals ¶
func (z *Macfarlane) Equals(y *Macfarlane) bool
Equals returns true if y and z are equal.
func (*Macfarlane) Inv ¶
func (z *Macfarlane) Inv(x *Macfarlane) *Macfarlane
Inv sets z equal to the inverse of x, and returns z. If x is a zero divisor, then Inv panics.
func (*Macfarlane) IsIndempotent ¶
func (z *Macfarlane) IsIndempotent() bool
IsIndempotent returns true if z is an indempotent (i.e. if z = z*z).
func (*Macfarlane) IsInf ¶
func (z *Macfarlane) IsInf() bool
IsInf returns true if any of the components of z are infinite.
func (*Macfarlane) IsNaN ¶
func (z *Macfarlane) IsNaN() bool
IsNaN returns true if any component of z is NaN and neither is an infinity.
func (*Macfarlane) IsZeroDiv ¶
func (z *Macfarlane) IsZeroDiv() bool
IsZeroDiv returns true if z is a zero divisor (i.e. it has zero quadrance).
func (*Macfarlane) Mul ¶
func (z *Macfarlane) Mul(x, y *Macfarlane) *Macfarlane
Mul sets z equal to the product of x and y, and returns z.
The multiplication rule for the basis elements s := Macfarlane{0, 1, 0, 0}, t := Macfarlane{0, 0, 1, 0}, and u := Macfarlane{0, 0, 0, 1} is:
Mul(s, s) = Mul(t, t) = Mul(u, u) = Macfarlane{1, 0, 0, 0} Mul(s, t) = -Mul(t, s) = +u Mul(t, u) = -Mul(u, t) = +s Mul(u, s) = -Mul(s, u) = +t
func (*Macfarlane) Neg ¶
func (z *Macfarlane) Neg(y *Macfarlane) *Macfarlane
Neg sets z equal to the negative of y, and returns z.
func (*Macfarlane) Quad ¶
func (z *Macfarlane) Quad() float64
Quad returns the quadrance of z, which can be either positive, negative or zero.
func (*Macfarlane) Quo ¶
func (z *Macfarlane) Quo(x, y *Macfarlane) *Macfarlane
Quo sets z equal to the quotient of x and y, and returns z. If y is a zero divisor, then Quo panics.
func (*Macfarlane) Scal ¶
func (z *Macfarlane) Scal(y *Macfarlane, a float64) *Macfarlane
Scal sets z equal to y scaled by a, and returns z.
func (*Macfarlane) String ¶
func (z *Macfarlane) String() string
String returns the string representation of a Macfarlane value. If z corresponds to the Macfarlane quaternion a + bs + ct + du, then the string is "(a+bs+ct+du)", similar to complex128 values.
func (*Macfarlane) Sub ¶
func (z *Macfarlane) Sub(x, y *Macfarlane) *Macfarlane
Sub sets z equal to the difference of x and y, and returns z.