Qalculate / libqalculate

Qalculate! library and CLI
https://qalculate.github.io/
GNU General Public License v2.0
1.8k stars 145 forks source link

How to use quaternion / versor algebra #700

Open Selorax opened 2 weeks ago

Selorax commented 2 weeks ago

I wanted to multiply two quaternions, however qalc seem to produce this kind of output:

> (1+2i+3j+4k)

  error: Trailing characters "j" (not a valid variable/function/unit) in number "3j" were ignored.
  1 + (2 × i) + 3 + (4 × 1000) = 4004 + 2i

So either I am using wrong syntax or quaternions are not implemented. If they are not implemented, then they probably should be in some way. Search in issues and manual index by keywords versor and quaternion produced no results.

hanna-kn commented 2 weeks ago

There is no support for quaternions in libqalculate.

Selorax commented 2 weeks ago

@hanna-kn, is it planned to be added?

hanna-kn commented 2 weeks ago

@hanna-kn, is it planned to be added?

I've not considered it before.

It seems as if it should be relatively easy to add support for quaternions in specific functions, with 4-dimensional vectors as arguments. E.g. 1+2i+3j+4k would be represented as (1, 2, 3, 4) (or [1 2 3 4]) and multiplied using a function perhaps named qmultiply.

Adding quaternion as a separate data class, or as an extension to complex numbers, with support for regular operators and functions, would likely be considerably more complicated and require extensive changes to existing code.

Selorax commented 1 week ago

It is up to you, then, how and whether to implement it at all. Of course if quaternions are implemented at all, there should be functions for all arithmetic operations and other things commonly done with them, not just multiplication. Also quaternion multiplication is not commutative, so perhaps notation like (1+2i+3j+4k)*(2+3i+4j+5k) will create additional problems because it's not the same as (2+3i+4j+5k)*(1+2i+3j+4k), unlike complex and real numbers.