Skip to content

Commit

Permalink
Be more conservative about optimizing exponentiation
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Sep 11, 2024
1 parent beb19d0 commit 195f6a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added
- `Base.literal_pow` definitions for `KVector{1}` that produce `KVector` results.

### Changed
- Natural exponential are only optimized for `KVector` types whose `BitIndices` uniformly square
to the same value.

### Fixed
- `OddCliffordNumber` constructors now fail to operate on scalars unless there is exactly one odd
element in the algebra.
- Broken bullets in `AbstractCliffordNumber` docstring.
- `StackOverflowError` in `KVector{0}` exponentiation.
- Incorrect natural exponentials in algebras with non-uniform sign signatures.

## [0.1.6] - 2024-06-27

Expand Down
10 changes: 5 additions & 5 deletions src/math/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ See also: [`exppi`](@ref), [`exptau`](@ref).
function exp(x::AbstractCliffordNumber)
T = exponential_type(x)
Tx = convert(T, x)
sq = mul(Tx, Tx)
if isscalar(sq)
mag = abs(x)
scalar(sq) < 0 && return T(cos(mag)) + Tx * (sin(mag) / mag)
scalar(sq) > 0 && return T(cosh(mag)) + Tx * (sinh(mag) / mag)
# Check that all basis blades of the type square to the same sign, too
if allequal(sign_of_square(b) for b in BitIndices(x)) && isscalar(x^2)
mag = abs(x) # should be faster to calculate directly from input type (it may be shorter)
scalar(x^2) < 0 && return T(cos(mag)) + Tx * (sin(mag) / mag)
scalar(x^2) > 0 && return T(cosh(mag)) + Tx * (sinh(mag) / mag)
return one(T) + Tx
end
return exp_taylor(x)
Expand Down

0 comments on commit 195f6a9

Please sign in to comment.