Posts tagged with 'calculators'

The negatives of negatives

  • Posted on May 9, 2009 at 4:40 pm

Many many moons ago, when I was still at school, one of the things that bugged me was the +/- button on my calculator. It just seemed redundant given that there was already a - button. Clearly I needed to get out more, but I digress. It wasn’t until I properly learned about groups, unary and binary operations, inverses and the like that the distinction became clearer, although the extra button still seemed unnecessary.

So, it’s a little ironic that I’ve spent this afternoon adding an extra ‘negative’ unary operation into the Symbolic library, even though there’s already a binary ’subtraction’ operator in there already. I bet I grow to regret this as things get more complicated, but it makes things easier for now.

The main benefit of this change is that previously when you wanted to use a negative number or expression you’d have to write something like “0-5″ or “0-cos(x)”.  Now you just need to do “-5″ or “-cos(x)”. Much more civil. I did think about adding in the zero implicitly, so that “-a” got silently converted internally to “0-a“, but this just seemed ugly and was going to make things complex when it was converted back into a text string.

So, the good news is that now functions with negatives that look like they ought to work, but would previously have resulted in a confusing empty function, now actually work as they should. Hooray for unary negation!

Top