Somewhat OT: defining algebras in D

Amorphorious Amorphorious at gmail.com
Thu Feb 8 21:37:59 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

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.

For example, it seems that you are using a group presentation to 
define the a algebra... but a few examples are not enough to 
provide a complete context in what it can be used for besides the 
example. This requires understanding the details in detail, which 
can be too time consuming for some. For example, can it be used 
to define an algebra on sets? If not, could it be modified to do 
so easily? To answer that one probably has to know how the code 
works in detail... which means spending time, which then goes to 
if it is worth it over a new implementation, etc.





More information about the Digitalmars-d mailing list