Defactoring: Difference between revisions
Cmloegcmluin (talk | contribs) |
Cmloegcmluin (talk | contribs) |
||
Line 260: | Line 260: | ||
smithDefactor[m_] := Take[Inverse[rightReducingMatrix[m]], MatrixRank[m]]</nowiki> | smithDefactor[m_] := Take[Inverse[rightReducingMatrix[m]], MatrixRank[m]]</nowiki> | ||
So the first thing that happens to <span><math>m</math></span> when you pass it in to <code>smithDefactor[]</code> is that it calls <code>rightReducingMatrix[]</code> on it. This will find the Smith decomposition (using a function built in to Wolfram Language), which gives you three outputs: the Smith normal form, flanked by its left and right reducing matrices. | So the first thing that happens to <span><math>m</math></span> when you pass it in to <code>smithDefactor[]</code> is that it calls <code>rightReducingMatrix[]</code> on it. This will find the Smith decomposition (using a function built in to Wolfram Language), which gives you three outputs: the Smith normal form, flanked by its left and right reducing matrices. Gene asks only for the right reducing matrix, so we grab that with <code>Last[]</code>. So that's what the function on the first line, <code>rightReducingMatrix[]</code>, does. | ||
Then Gene asks us to invert this result and take its first <span><math>r</math></span> rows, where <span><math>r</math></span> is the rank of the temperament. <code>Invert[]</code> takes care of the inversion, of course. <code>MatrixRank[m]</code> gives the count of linearly independent rows to the mapping, AKA the rank, or count of generators in this temperament. In this case that's 2. And so <code>Take[list, 2]</code> simply returns the first 2 entries of the list. | Then Gene asks us to invert this result and take its first <span><math>r</math></span> rows, where <span><math>r</math></span> is the rank of the temperament. <code>Invert[]</code> takes care of the inversion, of course. <code>MatrixRank[m]</code> gives the count of linearly independent rows to the mapping, AKA the rank, or count of generators in this temperament. In this case that's 2. And so <code>Take[list, 2]</code> simply returns the first 2 entries of the list. | ||
Almost done! Except Gene not only defactors, he also calls for HNF, as we would, to achieve canonical form. | Almost done! Except Gene not only defactors, he also calls for HNF, as we would, to achieve canonical (unique ID) form. | ||
<nowiki>normalize[m_] := Last[HermiteDecomposition[m]]</nowiki> | <nowiki>normalize[m_] := Last[HermiteDecomposition[m]]</nowiki> |