As of May 4 2007 the scripts will autodetect your timezone settings. Nothing here has to be changed, but there are a few things

Please follow this blog

Search this blog

Saturday, May 21, 2011

Equivalence classes in Mathematica

An equivalence relation like 'has the same remainder after division by 5' partitions a set in equivalence classes.

The relevant Mathematica function is GatherBy[ set, equivalence relation] -> {equivalence classes}:

In[5]:= GatherBy[{1, 2, 3, 4, 5}, Mod[#, 5] &]

Out[5]= {{1}, {2}, {3}, {4}, {5}}

In[6]:= GatherBy[{49, 33, 11, 1, 2, 3, 4, 5}, Mod[#, 5] &]

Out[6]= {{49, 4}, {33, 3}, {11, 1}, {2}, {5}}

Or when using the equivalence relation 'Is Odd?' on the same set:
In[7]:= GatherBy[{49, 33, 11, 1, 2, 3, 4, 5},OddQ]

Out[7]= {{49, 33, 11, 1, 3, 5}, {2, 4}}

No comments:

Post a Comment

Popular Posts

Welcome to The Bridge

Mathematics: is it the fabric of MEST?
This is my voyage
My continuous mission
To uncover hidden structures
To create new theorems and proofs
To boldly go where no man has gone before




(Raumpatrouille – Die phantastischen Abenteuer des Raumschiffes Orion, colloquially aka Raumpatrouille Orion was the first German science fiction television series. Its seven episodes were broadcast by ARD beginning September 17, 1966. The series has since acquired cult status in Germany. Broadcast six years before Star Trek first aired in West Germany (in 1972), it became a huge success.)