Submitted by Moonside in programming
Moonside OP wrote
Reply to comment by twovests in So what project are you working on? by Moonside
Arbitrary precision integer arithmetic is just a mouthful for what is in Python long
and in Java BigInteger. Just integers that go arbitrarily big in absolute value. I literally had to google for the official name!
It might be that I don't understand enough about the music theory behind it, but why don't you trust ints? Is that distrust just for this application, or more general?
It was a bit of hyperbole, it's mostly that I've gotten a bit bored with the tricks we have to do in software to make things palatable for computers, instead of doing the most straightforwardly correct thing at first and then making it hairy in the name of efficiency. It's like we have a computer brain or binary fog or what you call it!
The big problem was representing notes so that they have correct letter names, the correct amount of accidentals and octave; this is enough to name them correctly and also play the pitch. I wrote convoluted and buggy versions of this, so I was motivated to do it Right. The original version was just storing these directly, but calculating intervals between them was convoluted, but I noticed that each note is some distance (interval) away from middle C. Notes can be represented as rewrapped intervals.
I represented intervals as pairs of integers (I can distinguish between augmented fourths and diminished fifths that way). I defined addition and inverse on them so it turns out that they are isomorphic to the additive group of integer points on a XY-plane, or Z². And as notes are just intervals from middle C in disguise, naming all of them correctly is easy since the bookkeeping is done by underlying presentation. It's about ten lines of code and half of that are signatures.
So it was just an easy thing to do, because the innermost representation really is infinite in two directions. That said, it doesn't matter much, because the largest integer is 9223372036854775807 and basically for my purposes about 1000 is enough, without doing a bunch of renormalizations.
Viewing a single comment thread. View all comments