-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs/src/examples/basics.md
page
#134
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
53c9bd3
update docs
hyrodium 4e46ee2
update docs
hyrodium aa85398
add dependency on HalfIntegers in docs
hyrodium 5469667
update basics
hyrodium 77e7468
update docs
hyrodium ad53ba5
Fix docs/src/examples/basics.md
hyrodium 723fd56
Fix typo in docs/src/examples/basics.md
hyrodium 10236e7
Fix docs/src/examples/basics.md
hyrodium f4c9daa
Fix docs/src/examples/basics.md
hyrodium 0445b86
Fix docs/src/examples/basics.md
hyrodium 01d34db
Fix docs/src/examples/basics.md
hyrodium 28a37fc
add docs for `sign`
hyrodium 03ccc0f
add type_parameter.md
hyrodium d47b036
remove `warnonly=true`
hyrodium dfde745
update first examples
hyrodium 14f67be
Fix `ishurwitz` by replacing `ishalfinteger` with `ishalfodd`
hyrodium 1873339
add `ishalfodd` in the documentation because HalfIntegers.jl#59 takes…
hyrodium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Basics | ||
|
||
## Basic operations for quaternions | ||
Quaternions can be defined with the [`Quaternion`](@ref) constructor or [`quat`](@ref) function. | ||
Note that the order of the arguments is ``w+xi+yj+zk``, not ``xi+yj+zk+w``. | ||
|
||
```@repl intro | ||
using Quaternions | ||
q1 = Quaternion(1,2,3,4) | ||
q2 = quat(5,6,7,8) | ||
q3 = quat(9) | ||
``` | ||
|
||
The multiplication is not commutative. | ||
```@repl intro | ||
q1 * q2 | ||
q2 * q1 | ||
``` | ||
|
||
The multiplicative inverse can be calculated with [`Base.inv`](@ref). | ||
```@repl intro | ||
inv(q1) | ||
inv(q1) * q1 | ||
``` | ||
|
||
The division is also not commutative. | ||
|
||
```@repl intro | ||
q1 / q2 # Same as `q1*inv(q2)` mathematically. | ||
q2 \ q1 # Same as `inv(q2)*q1` mathematically. | ||
``` | ||
|
||
A conjugate of a quaternion can be calculated with [`Base.conj`](@ref). | ||
But `Base.imag(::Quaternion)` is not defined because it should return three real values which is not consistent with `imag(::Complex)` and `imag(::Real)`. | ||
Instead, the [`imag_part`](@ref) function can be used to obtain the imaginary part of a quaternion. | ||
See [issue#61](https://github.com/JuliaGeometry/Quaternions.jl/issues/61) for more discussion. | ||
|
||
```@repl intro | ||
conj(q1) | ||
imag(q1) # Not supported. | ||
imag_part(q1) # Use this instead. | ||
``` | ||
|
||
Unit quaternions can be obtained with [`sign`](@ref). | ||
|
||
```@repl intro | ||
sign(q1) | ||
sign(q2) | ||
sign(q3) | ||
sign(quat(0)) # Zero-quaternion will not be normalized. | ||
``` | ||
|
||
## `Quaternion` vs `quat` | ||
The general rule is that [`quat`](@ref) is to [`Quaternion`](@ref) as [`complex`](https://docs.julialang.org/en/v1/base/numbers/#Base.complex-Tuple{Complex}) is to [`Complex`](https://docs.julialang.org/en/v1/base/numbers/#Base.Complex). | ||
`Complex` and `Quaternion` are both constructors so should return an object of the corresponding type, whereas `quat` and `complex` both can operate on types and arrays. | ||
|
||
```@setup Quaternion-quat | ||
using Quaternions | ||
``` | ||
|
||
```@repl Quaternion-quat | ||
Quaternion(1,2,3,4) | ||
quat(1,2,3,4) | ||
Quaternion(Int) # Similar to `Complex(Int)`. | ||
quat(Int) # Similar to `complex(Int)`. | ||
``` | ||
|
||
## Compatibility with `Complex` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this does feel like it belongs here. |
||
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. | ||
|
||
```math | ||
\mathbb{C} \ni w+ix \ne w+ix+0j+0k \in \mathbb{H}. | ||
``` | ||
|
||
```@setup complex | ||
using Quaternions | ||
``` | ||
|
||
```@repl complex | ||
1 + complex(1,2) # `Complex` is compatible with `Real` | ||
1 + quat(1,2,3,4) # `Quaternion` is compatible with `Real` | ||
1 + complex(1,2) + quat(1,2,3,4) # no compatibility | ||
complex(1,2) == quat(1,2,0,0) # no compatibility | ||
complex(1) == quat(1) # no compatibility | ||
complex(1) == 1 == quat(1) # Both `quat(1)` and `complex(1)` are equal to `1`. | ||
``` | ||
|
||
See [issue#62](https://github.com/JuliaGeometry/Quaternions.jl/issues/62) for more discussion. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# 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 | ||
ishalfodd(x::Number) = isodd(twice(x)) # Should be defined in HalfIntegers.jl (HalfIntegers.jl#59) | ||
ishurwitz(q::Quaternion) = (isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)) | (ishalfodd(q.s) & ishalfodd(q.v1) & ishalfodd(q.v2) & ishalfodd(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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like
sign
should be somewhere discussed here as the right approach for constructing a unit quaternion.