# Re: Somewhat OT: defining algebras in D

On Friday, 9 February 2018 at 02:40:06 UTC, Nick Sabalausky (Abscissa) wrote:
```On 02/08/2018 04:37 PM, Amorphorious wrote:
```
On Thursday, 8 February 2018 at 15:23:05 UTC, Simen Kjærås wrote:
So I was bored in a meeting and decided to implement a generic template for defining complex numbers, dual numbers, quaternions and many other possible algebras by simply defining a set of rules and the components on which they act:
```
source:

https://gist.github.com/Biotronic/833680b37d4afe774c8562fd21554c6b

```
```
```
Cool. Took me a while to start to understand it and still not 100% grokked (partly because I've never quite been able to fully grasp quaternion math (at least, beyond Unity3D's ultra-easy abstraction for it) and never heard of dual numbers before), but staring at the complex number example helped see how this works. It's a very cool idea!
```
```
```
```
quats are just complex numbers with extra variables like i. Each one is the square root of -1, but they are obviously incompatible.
```
i^2 = j^2 = k^2 = -1

https://en.wikipedia.org/wiki/Quaternion

See the multiplication table.

```
It's just an "extension" of complex numbers. They are homomorphic to 4x4 matrices but sometimes easier to work with.
```
Nothing really special about them... sorta like pepsi vs coke.

```
It would be nice if you learned how to document your code. It's not always easy for someone on the outside to be able to pick it up and it ultimately means your hard work will be less used as it could be. I know that sometimes comments can be redundant but it can also provide a better understanding.
```
```
```
```
Well, that's the difference between a formal library package release vs sharing a working proof of concept jotted down to pass time ;)
```
```
Yes, but he can go back an add some friendly text at some point... He knows most about it so it is much easier and shouldn't take more than a few mins.
```

```