Somewhat OT: defining algebras in D
Mark
smarksc at gmail.com
Fri Feb 9 17:42:42 UTC 2018
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:
>
>
> alias quaternion = Algebra!(
> float,
> "1,i,j,k",
> op("1", any) = any,
> op("i,j,k", self) = "-1",
> op("i", "j") = "k".antiCommutative,
> op("j", "k") = "i".antiCommutative,
> op("k", "i") = "j".antiCommutative,
> );
>
> source:
>
> https://gist.github.com/Biotronic/833680b37d4afe774c8562fd21554c6b
>
> --
> Simen
Nice. An interesting potential extension is to support
composition (for instance, defining the complex numbers using the
template and then defining the quaternions as an two-dimensional
algebra over the complex).
More information about the Digitalmars-d
mailing list