Skip to content

Commit

Permalink
add type_parameter.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrodium committed Nov 25, 2023
1 parent a41be79 commit b189952
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ makedocs(;
"APIs" => "api.md",
"Examples" => [
"examples/basics.md",
"examples/type_parameter.md",
"examples/rotations.md",
"examples/dual_quaternions.md"
],
Expand Down
61 changes: 0 additions & 61 deletions docs/src/examples/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,67 +65,6 @@ Quaternion(Int) # Similar to `Complex(Int)`.
quat(Int) # Similar to `complex(Int)`.
```

## The type parameter `T` in `Quaternion{T}`

The type parameter `T <: Real` in `Quaternion{T}` represents the type of real and imaginary parts of a quaternion.

### Lipschitz quaternions
By using this type parameter, some special quaternions such as [**Lipschitz quaternions**](https://en.wikipedia.org/wiki/Hurwitz_quaternion) ``L`` can be represented.

```math
L = \left\{a+bi+cj+dk \in \mathbb{H} \mid a,b,c,d \in \mathbb{Z}\right\}
```

```@setup LipschitzHurwitz
using Quaternions
```

```@repl LipschitzHurwitz
q1 = Quaternion{Int}(1,2,3,4)
q2 = Quaternion{Int}(5,6,7,8)
islipschitz(q::Quaternion) = isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)
islipschitz(q1)
islipschitz(q2)
islipschitz(q1 + q2)
islipschitz(q1 * q2)
islipschitz(q1 / q2) # Division is not defined on L.
q1 * q2 == q2 * q1 # non-commutative
```

### Hurwitz quaternions
If all coefficients of a quaternion are integers or half-integers, the quaternion is called a [**Hurwitz quaternion**](https://en.wikipedia.org/wiki/Hurwitz_quaternion).
The set of Hurwitz quaternions is defined by

```math
H = \left\{a+bi+cj+dk \in \mathbb{H} \mid a,b,c,d \in \mathbb{Z} \ \text{or} \ a,b,c,d \in \mathbb{Z} + \tfrac{1}{2}\right\}.
```

Hurwitz quaternions can be implemented with [HalfIntegers.jl](https://github.com/sostock/HalfIntegers.jl) package.

```@repl LipschitzHurwitz
using HalfIntegers
q1 = Quaternion{HalfInt}(1, 2, 3, 4)
q2 = Quaternion{HalfInt}(5.5, 6.5, 7.5, 8.5)
q3 = Quaternion{HalfInt}(1, 2, 3, 4.5) # not Hurwitz quaternion
ishurwitz(q::Quaternion) = (isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)) | (ishalfinteger(q.s) & ishalfinteger(q.v1) & ishalfinteger(q.v2) & ishalfinteger(q.v3))
ishurwitz(q1)
ishurwitz(q2)
ishurwitz(q3)
ishurwitz(q1 + q2)
ishurwitz(q1 * q2)
ishurwitz(q1 / q2) # Division is not defined on H.
q1 * q2 == q2 * q1 # non-commucative
abs2(q1) # Squared norm is always an integer.
abs2(q2) # Squared norm is always an integer.
abs2(q3) # Squared norm is not an integer because `q3` is not Hurwitz quaternion.
```

### Biquaternions
If all coefficients of a quaternion are complex numbers, the quaternion is called a [**Biquaternion**](https://en.wikipedia.org/wiki/Biquaternion).
However, the type parameter `T` is restricted to `<:Real`, so biquaternions are not supported in this package.
Note that `Base.Complex` has the same type parameter restriction, and [bicomplex numbers](https://en.wikipedia.org/wiki/Bicomplex_number) are not supported in Base.
See [issue#79](https://github.com/JuliaGeometry/Quaternions.jl/issues/79) for more discussion.

## Compatibility with `Complex`
There is no natural embedding ``\mathbb{C}\to\mathbb{H}``.
Thus, `quat(w,x,0,0)` is not equal to `complex(w,x)`, i.e.
Expand Down
60 changes: 60 additions & 0 deletions docs/src/examples/type_parameter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The type parameter `T` in `Quaternion{T}`

The type parameter `T <: Real` in `Quaternion{T}` represents the type of real and imaginary parts of a quaternion.

## Lipschitz quaternions
By using this type parameter, some special quaternions such as [**Lipschitz quaternions**](https://en.wikipedia.org/wiki/Hurwitz_quaternion) ``L`` can be represented.

```math
L = \left\{a+bi+cj+dk \in \mathbb{H} \mid a,b,c,d \in \mathbb{Z}\right\}
```

```@setup LipschitzHurwitz
using Quaternions
```

```@repl LipschitzHurwitz
q1 = Quaternion{Int}(1,2,3,4)
q2 = Quaternion{Int}(5,6,7,8)
islipschitz(q::Quaternion) = isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)
islipschitz(q1)
islipschitz(q2)
islipschitz(q1 + q2)
islipschitz(q1 * q2)
islipschitz(q1 / q2) # Division is not defined on L.
q1 * q2 == q2 * q1 # non-commutative
```

## Hurwitz quaternions
If all coefficients of a quaternion are integers or half-integers, the quaternion is called a [**Hurwitz quaternion**](https://en.wikipedia.org/wiki/Hurwitz_quaternion).
The set of Hurwitz quaternions is defined by

```math
H = \left\{a+bi+cj+dk \in \mathbb{H} \mid a,b,c,d \in \mathbb{Z} \ \text{or} \ a,b,c,d \in \mathbb{Z} + \tfrac{1}{2}\right\}.
```

Hurwitz quaternions can be implemented with [HalfIntegers.jl](https://github.com/sostock/HalfIntegers.jl) package.

```@repl LipschitzHurwitz
using HalfIntegers
q1 = Quaternion{HalfInt}(1, 2, 3, 4)
q2 = Quaternion{HalfInt}(5.5, 6.5, 7.5, 8.5)
q3 = Quaternion{HalfInt}(1, 2, 3, 4.5) # not Hurwitz quaternion
ishurwitz(q::Quaternion) = (isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)) | (ishalfinteger(q.s) & ishalfinteger(q.v1) & ishalfinteger(q.v2) & ishalfinteger(q.v3))
ishurwitz(q1)
ishurwitz(q2)
ishurwitz(q3)
ishurwitz(q1 + q2)
ishurwitz(q1 * q2)
ishurwitz(q1 / q2) # Division is not defined on H.
q1 * q2 == q2 * q1 # non-commucative
abs2(q1) # Squared norm is always an integer.
abs2(q2) # Squared norm is always an integer.
abs2(q3) # Squared norm is not an integer because `q3` is not Hurwitz quaternion.
```

## Biquaternions
If all coefficients of a quaternion are complex numbers, the quaternion is called a [**Biquaternion**](https://en.wikipedia.org/wiki/Biquaternion).
However, the type parameter `T` is restricted to `<:Real`, so biquaternions are not supported in this package.
Note that `Base.Complex` has the same type parameter restriction, and [bicomplex numbers](https://en.wikipedia.org/wiki/Bicomplex_number) are not supported in Base.
See [issue#79](https://github.com/JuliaGeometry/Quaternions.jl/issues/79) for more discussion.

0 comments on commit b189952

Please sign in to comment.