A script for PCalc

The iPad/iPhone app PCalc (9.99 in the AppStore - there's also a free light version for you to give it a try first) has a programming function that lets you create your own formulas and shortcuts to an easy answer. To make the programming function work the way you want however often needs a bit of tinkering around. Luckily it has quite a few pre-programmed functions, enabling you to check out how to apply rules. You cannot change built-in rules, so no need to be afraid you might screw things up.

What about the 'tinkering' part? Let me give you an example. Maybe you are more familiar with the program and can improve on this scenario. In that case I love to hear from you.

It started with observing Saturn and Mars in the night sky. My star chart told me that at that time Mars has a magnitude of -1.6 and Saturn shone at +0.2. That's a difference of magnitude 1.8, of course. Now I wanted to convert this to difference in brightness. That is quite easy. Difference in magnitude is defined as magnitude 1 being 100 times brighter than magnitude 6. This simply means:

$a\cdot a\cdot a\cdot a\cdot a=100$


hence $\sqrt[5]{100}=2,51188643150958$

and a lot more decimals, but this will suffice.

Thus, every magnitude more decreases the brightness with a factor $2,51188643150958$. This makes calculating easy. If you compare two bodies with magnitude $m_1$ and magnitude $m_2$ you can calculate their difference in brightness $\Delta{m}$ as


Now let's return to PCalc. The script should be straightforward.
  • enter $m_1$ and $m_2$
  • subtract these two
  • take the absolute value of this number (as magnitudes can be both positive and negative)
  • calculate 2,51188643150958 to the power of this number
This, however, does not go well. A simple function call to take the absolute value is not available. And there's no simple formula to set a chosen number with this absolute value as a power. It means we have to use some workarounds.

First of all the absolute value. If the difference between the two magnitude $x$ turns out negative, how to get the absolute value? That's simple, yet a bit stupid for the program to lack. So we circumvent (you can check out the formula under the "special" section):


In PCalc programming language that means: first x to the power 2, then the result to the power 0.5 (because, of course, $\sqrt{x}=x^{\frac{1}{2}}$, duh).

Now we have the absolute value. This is the power we need for the exponentiation with base 2,51188643150958 and exponent x: $2,51188643150958^x$ So where is this function? It's not available, so we have to find another workaround. First, write 2,51188643150958 to a memory place with the set command. You can do this as one of the first steps: the value is written to the memory slot and will stay there. Now you can use this memory slot to perform the exponentiation.

But doing that doesn't make the answer show up on the main screen, just in the memory register where you allocated it. So as a last step you have to transfer the new memory slot value to the main screen, and, as you're a clean operator, clear the memory slot after that.

Let's see if it works, in PCalc language.
  • Base: decimal
  • Mode: RPN
  • Set M0 to 2,51188643150958
  • subtract Y from X
  • X to Power of 2
  • X to Power of 0.5
  • M0 to Power of X
  • Set X to M0
  • Clear M0
Does it work? Yes it does, see the screenshot above. Simply enter the two magnitudes in any particular order you wish (after all, you do have two possibilities at your disposal...) and see the answer appear in the pull-down menu with the appropriate function active. You can check it with 1 and 6; the result should be 100 or very close to it.

Good luck. (5.24807460249773. Mars, times, brighter than Saturn. Answer. You're welcome.)