Images, snippets, snapshots, math

View Gabriele Lami's profile on LinkedIn

mercoledì 24 settembre 2008

Algebraic group


Today I started to write a class in Scala to represent a group (in the mathematical sense).
To test closure, i.e.:







the code I wrote is:

def closure( ): Boolean =
elements.forall(
el => elements.forall(
el2 => elements.exists(
el2.*(el, this).name == _.name ) ) )





'elements' is the list of all group elements and and each element has a different 'name'.
The following piece of code is the product of two elements.

  el2.*(el, this)

the * operator is defined as follows:

def *( b : groupElement ,group: genericGroup ) : groupElement

the code is not optimized, but it is amazing how, in this language,
we can write a test like this in a way so simple!
this is only a snippet of the entire code...
I hope to post the complete code soon

1 commento:

Anonimo ha detto...

nice but not so clear