ATell-SoundTheory / CliffordAlgebras.jl

A fast and lightweight Julia package for Clifford and geometric algebras.
https://atell-soundtheory.github.io/CliffordAlgebras.jl/
MIT License
36 stars 4 forks source link

Bug with norm #11

Closed davibarreira closed 1 year ago

davibarreira commented 1 year ago

The norm function is giving an error because norm_sqr is returning a negative value. Here is the case:

cl    = CliffordAlgebra(:CGA2D)
mv  = -4.0×e1e₊-4.0×e2e₊-4.0×e1e₋+4.0×e₋e2-2.0×e₊e₋
norm_sqr(mv) # returns -2
ATell-SoundTheory commented 1 year ago

That's not really a bug. I am using the most commonly used definition of a norm in Clifford algebras, and for this definition there is no real norm for all vectors if the underlying quadratic form of the algebra has negative eigenvalues. You could modify the definition by adding an abs() in norm_sqr(), which would still give you a proper norm, but you'd make the norm less useful in a number of situations.

If you really want an imaginary result, then you can use the commit I've just made which enables a special case treatment for algebras with negative eigenvalues. In this case norm() will return a complex number instead of a real one. But it will always do that, even if the actual result is real.

I hope this solves your problem.

davibarreira commented 1 year ago

Perfect! Thanks a lot for all the answers!