Skip to content
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

Features/metrics #2

Merged
merged 30 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d20a20c
Added new `Metrics` module for metric signatures
brainandforce Mar 28, 2024
679e38d
Tried removing `QuadraticForm` type constraint from `AbstractClifford…
brainandforce Mar 28, 2024
4369902
Created `AbstractSignature` type hierarchy, renamed `OrthonormalMetri…
brainandforce Mar 28, 2024
3dd4c21
Added `Metrics.dimension()`
brainandforce Mar 28, 2024
c9ec76b
Added custom `show` method
brainandforce Mar 28, 2024
8887e5b
Created `AbstractSignature` subtypes specific to common families of a…
brainandforce Apr 19, 2024
abd90ff
Updated docstring for `Exterior` metric type
brainandforce May 1, 2024
7a81158
Fixed incorrect function signatures and missing imports
brainandforce May 1, 2024
67b2222
Added functions to return the number of basis blades and range of grades
brainandforce May 1, 2024
83554aa
Added missing subtype relations for `CGA`, `LGA`, and `Exterior`
brainandforce May 1, 2024
d1dbaf4
Removed all erroneous `dimensions` instead of `dimension`
brainandforce May 1, 2024
b9256bd
Added tests for metric signature objects
brainandforce May 1, 2024
cf30dbc
Added `signature` function for extracting metric signatures
brainandforce May 1, 2024
a7ee5d5
Renamed `basis_blades` to `blade_count`; updated tests
brainandforce May 1, 2024
be688e3
Added new methods for generating a `BitIndex` with new signature types
brainandforce May 1, 2024
059537e
Added better print methods for some `AbstractSignature` subtypes
brainandforce May 1, 2024
3e576c1
Fixed pluralization of `dimensions` again
brainandforce May 1, 2024
c14c751
Renamed `elements()` to `blade_count()`; exported `is_degenerate()` a…
brainandforce May 1, 2024
aedf935
Fixed methods for `scalar_index()` and `pseudoscalar_index()`
brainandforce May 1, 2024
3686d33
Fixed `QuadraticForms` tests
brainandforce May 1, 2024
69162ba
Corrected `BitIndices` constructor behavior
brainandforce May 1, 2024
1def8c2
Use `Val` to wrap signatures, added print method for new signature types
brainandforce May 1, 2024
72e5ee8
Reworked `similar_type()` to always use `Val` with signature
brainandforce May 1, 2024
08b5e24
Removed references to `QuadraticForm` in some docstrings and signatures
brainandforce May 1, 2024
02706a8
Extended multiplication sign(bit) functions
brainandforce May 1, 2024
fe6ed1b
Replaced all instances of `APS` with `VGA(3)`
brainandforce May 1, 2024
ec20185
Ripped out old `QuadraticForm` internals
brainandforce May 2, 2024
f7f9156
Updated metric signature documentation
brainandforce May 2, 2024
d3581a3
Moved show methods to a better place
brainandforce May 2, 2024
1effa49
Added missing docstrings for `is_degenerate` and `is_positive_definite`
brainandforce May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ makedocs(;
"API" => Any[
"CliffordNumbers" => "api/clifford.md",
"Indexing" => "api/indexing.md",
"Math" => "api/indexing.md",
"Quadratic forms" => "api/quadratic.md",
"Math" => "api/math.md",
"Metric signatures" => "api/metric.md",
"Internals" => "api/internal.md",
]
],
Expand Down
42 changes: 42 additions & 0 deletions docs/src/api/metric.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Metric signatures

## Signature types

```@docs
CliffordNumbers.Metrics.AbstractSignature
CliffordNumbers.Metrics.Signature
CliffordNumbers.Metrics.VGA
CliffordNumbers.Metrics.PGA
CliffordNumbers.Metrics.CGA
CliffordNumbers.Metrics.LGA
CliffordNumbers.Metrics.LGAEast
CliffordNumbers.Metrics.LGAWest
CliffordNumbers.Metrics.Exterior
```

## Aliases for common signatures

```@docs
CliffordNumbers.Metrics.VGA2D
CliffordNumbers.Metrics.VGA3D
CliffordNumbers.Metrics.PGA2D
CliffordNumbers.Metrics.PGA3D
CliffordNumbers.Metrics.CGA2D
CliffordNumbers.Metrics.CGA3D
CliffordNumbers.Metrics.STAEast
CliffordNumbers.Metrics.STAWest
CliffordNumbers.Metrics.STA
CliffordNumbers.Metrics.STAPEast
CliffordNumbers.Metrics.STAPWest
CliffordNumbers.Metrics.STAP
```

## Associated methods

```@docs
CliffordNumbers.dimension
CliffordNumbers.basis_blades
CliffordNumbers.grades
CliffordNumbers.is_degenerate
CliffordNumbers.is_positive_definite
```
26 changes: 0 additions & 26 deletions docs/src/api/quadratic.md

This file was deleted.

14 changes: 9 additions & 5 deletions src/CliffordNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ const BaseNumber = Union{Real,Complex}

# Contains tools for working with Hamming weights of integers
include("hamming.jl")
# Tools for defining quadratic forms/metric signatures (convention may not be great)
include("quadratic.jl")
export QuadraticForm, APS, STA, VGA, PGA, CGA
export dimension, elements, grades
# New module for metric signatures
include("metrics.jl")
using .Metrics
import .Metrics: dimension, blade_count, grades, is_degenerate, is_positive_definite
export Metrics
export Signature, VGA, PGA, CGA, LGA, LGAEast, LGAWest, Exterior
export dimension, blade_count, grades, is_degenerate, is_positive_definite
export VGA2D, VGA3D, PGA2D, PGA3D, CGA2D, CGA3D, STA, STAEast, STAWest, STAP, STAPEast, STAPWest
# Abstract supertype for all Clifford numbers
include("abstract.jl")
export AbstractCliffordNumber
export numeric_type
export signature, numeric_type
# Working with the grades represented by an AbstractCliffordNumber subtype
include("grades.jl")
export RepresentedGrades
Expand Down
26 changes: 16 additions & 10 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ with each basis blade represented by `C`.
`getfield(x, :data)::Tuple`, so any type declared with a `NTuple` field named `data` should have
this defined automatically.
"""
abstract type AbstractCliffordNumber{Q<:QuadraticForm,T<:BaseNumber} <: Number
abstract type AbstractCliffordNumber{Q,T<:BaseNumber} <: Number
end

#---Default varargs constructors for types---------------------------------------------------------#

(::Type{T})(x::Vararg{BaseNumber}) where {Q,T<:AbstractCliffordNumber{Q}} = T(x)

#---Get type parameters----------------------------------------------------------------------------#
"""
signature(T::Type{<:AbstractCliffordNumber{Q}}) = Q
signature(x::AbstractCliffordNumber{Q}) = Q

QuadraticForm(::Type{<:AbstractCliffordNumber{Q}}) where Q = Q
QuadraticForm(::AbstractCliffordNumber{Q}) where Q = Q
Returns the metric signature object associated with an `AbstractCliffordNumber` `x` or its type `T`.
"""
signature(::Type{<:AbstractCliffordNumber{Q}}) where Q = Q
signature(::AbstractCliffordNumber{Q}) where Q = Q

"""
numeric_type(::Type{<:AbstractCliffordNumber{Q,T}}) = T
Expand Down Expand Up @@ -91,20 +96,21 @@ oneunit(::Union{T,Type{T}}) where T<:AbstractCliffordNumber = convert(T, one(T))
CliffordNumbers.similar_type(
C::Type{<:AbstractCliffordNumber},
[N::Type{<:BaseNumber} = numeric_type(C)],
[Q::Type{<:QuadraticForm} = QuadraticForm(C)]
[Q::Val = Val(signature(C))]
) -> Type{<:AbstractCliffordNumber{Q,N}}

Constructs a type similar to `T` but with numeric type `N` and quadratic form `Q`.
Constructs a type similar to `T` but with numeric type `N` and quadratic form `Q`. The quadratic
form must be wrapped in a `Val` to preserve type stability.

This function must be defined with all its arguments for each concrete type subtyping
`AbstractCliffordNumber`.
"""
function similar_type(x::AbstractCliffordNumber, T::Type{<:BaseNumber}, Q::Type{<:QuadraticForm})
function similar_type(x::AbstractCliffordNumber, T::Type{<:BaseNumber}, Q::Val)
return similar_type(typeof(x), T, Q)
end

similar_type(x, T::Type{<:BaseNumber}) = similar_type(x, T, QuadraticForm(x))
similar_type(x, Q::Type{<:QuadraticForm}) = similar_type(x, numeric_type(x), Q)
similar_type(x, T::Type{<:BaseNumber}) = similar_type(x, T, Val(signature(x)))
similar_type(x, Q::Val) = similar_type(x, numeric_type(x), Q)

similar(C::Type{<:AbstractCliffordNumber}, args...) = zero(similar_type(C, args...))
similar(x::AbstractCliffordNumber, args...) = zero(similar_type(x, args...))
Expand Down Expand Up @@ -144,7 +150,7 @@ end

Base.complex(x::AbstractCliffordNumber{<:Any,<:Complex}) = x

function Base.complex(x::T, y::T) where T<:AbstractCliffordNumber{<:QuadraticForm,<:Real}
function Base.complex(x::T, y::T) where T<:AbstractCliffordNumber{<:Any,<:Real}
C = similar_type(x, complex(numeric_type(x)))
return C(complex.(Tuple(x), Tuple(y)))
end
Expand All @@ -153,7 +159,7 @@ Base.complex(x::AbstractCliffordNumber, y::AbstractCliffordNumber) = complex(pro

#---Error checking---------------------------------------------------------------------------------#
"""
CliffordNumbers.check_element_count(sz, Q::Type{<:QuadraticForm}, [L], data)
CliffordNumbers.check_element_count(sz, [L], data)

Ensures that the number of elements in `data` is the same as the result of `f(Q)`, where `f` is a
function that generates the expected number of elements for the type. This function is used in the
Expand Down
Loading
Loading