The ultimate calculator for Android and iOS

Calculators are among the most popular applications for smartphones, and therefore it is not surprising that the Google Play Store has more than 1000 calculators for the Android platform. Having used HP’s scientific calculators for more than 20 years, I picked RealCalc when I got my Android phone and set it to RPN mode. It works fine, I have no complaints about it. But I no longer use it because I found something much more powerful.

It’s called “J“, which isn’t exactly a very descriptive name. And that’s probably a good idea because describing it it not so easy. J is much more than a calculator, but it does the calculator job very well. It’s actually a full programming language, but one that differs substantially from everything else that goes by that label. The best description for J I can come up with is “executable mathematical notation”. You type an expression, and you get the result. That’s in fact not very different from working interactively with Python or Matlab, except that the expressions are very different. You can write traditional programs in J, using loops, conditionals, etc., but you can a lot of work done without ever using these features.

The basic data structure in J is the array, which can have any number of dimensions. Array elements can be numbers, characters, or other arrays. Numbers (zero-dimensional arrays) and text strings (one-dimensional arrays of characters) are just special cases. In J jargon, which takes its inspiration from linguistics, data items are called “nouns”. Standard mathematical operators (such as + or -) are called “verbs” and can have one or two arguments (one left, one right). An expression is called a “sentence”. There are no precedence rules, the right argument of any verb being everything to its right. Given the large number of verbs in J, this initially unfamiliar rule makes a lot of sense. A simple example (also showing the use of arrays) is

   2 * 3 + 10 20 30
26 46 66

Up to here, J expressions are not very different from Python or Matlab expressions. What J doesn’t have is functions with the familiar f(x, y, z) syntax, accepting any number of arguments. There are only verbs, with one or two arguments. But what makes J really different from the well-known languages for scientific computing are the “parts of speech” that have no simple equivalent elsewhere: adverbs and conjunctions.

An adverb takes a verb argument and produces a derived verb from it. For example, the adverb ~ takes a two-argument verb (a dyad in J jargon) and turns it into a one-argument verb (a monad) that’s equivalent to using the dyad with two equal arguments. With + standing for plain addition, +~ thus doubles its argument:

   +~ 1 5 10 20
2 10 20 40

meaning it is the same as

   1 5 10 20 + 1 5 10 20
2 10 20 40

A conjunction combines a verb with a noun or another verb to produce a derived verb. An example is ^:, the power conjunction, which applies a verb several times:

   +~(^:2) 1 5 10 20
4 20 40 80
   +~(^:3) 1 5 10 20
8 40 80 160

The parentheses are required to separate the argument of the power conjunction (2 or 3) from the array that is the argument to the resulting derived verb. To see the real power of the power conjunction, consider that it accepts negative arguments as well:

   +~(^:_1) 1 5 10 20
0.5 2.5 5 10

You have seen right: J can figure out that the inverse of adding a number to itself is dividing that number by two!

Pretty much any programming language permits you to assign values to names for re-use in later expressions. J is no exception:

   data =. 1 5 10 20
   double =. +~
   double data
2 10 20 40
   inv =. ^:_1
   halve =. double inv
   halve data
0.5 2.5 5 10

As you can see, names can be given not just to nouns (i.e. data), but also to verbs, adverbs, and conjunctions. Most J programs are just pieces of expressions that are assigned to names. Which means that the short summary of J that I have given here could well be all you ever need to know about the language – apart from the fact that you will have to acquire a working knowledge of many more verbs, adverbs, and conjunctions.

Before you rush off to the Play Store looking for J, let me add that J is not yet there, although it’s supposed to arrive soon. For now, you have to download the APK and install it yourself, using your preferred Android file manager. I should also point out that J is not just for Android. It’s been around for more than 20 years, and you can get J for all the common computing platforms from Jsoftware. There’s also an iOS version for the iPhone and iPad. J’s extreme terseness is a perfect fit for smartphones, where screen space is a scarce resource and where every character you don’t have to type saves you a lot of time.

Explore posts in the same categories: Computational science, Programming

7 Comments on “The ultimate calculator for Android and iOS”

  1. zerowords Says:


    Another possible variation which might be clearer for
    +~(^:2) 1 5 10 20
    4 20 40 80
    (+~^:2) 1 5 10 20
    4 20 40 80
    and similarly
    (+~^:_1) 1 5 10 20
    0.5 2.5 5 10

  2. John Baker Says:

    A very nice summary. J makes an excellent smart phone calculator. I made this point when the iOS version of J was released. More examples of J in action on smart phones can be seen at:

  3. Richard Hill Says:

    “You can write traditional programs in J, using loops, conditionals, etc., but you can a lot of work done without ever using these features.”
    there seems to be a word like “get” missing after “but you can”.

    Perhaps the fact the it is free (AFAIK) should be emphasised.

  4. Ben Fairbank Says:

    If J sounds vaguely familiar to older readers, it is perhaps because it is a direct lineal descendant of APL (which I used extensively in the early ’70s), created by the same Kenneth Iverson, and sharing many concepts with APL of blessed memory, but without the requirements for special symbols and keyboards..

  5. m1n1f1g Says:

    Sorry for being so late!

    The classic J example is the arithmetic mean: “+/%#”, which has the mnemonic “plus, slash; percent, hash”. It’s used to demonstrate forks – a way of composing tacit functions. It applies monads +/ (sum over) and # (length) to the argument, and the dyad % (divide) to the results. Here’s the example, from the bottom up:
    +/1 2 3
    #1 2 3
    (+/%#)1 2 3

    Another useful function is “+/&.:*:”, which does Pythagoras (root of the sum of squares) on a list. u&.:v y (for monads u and v) is defined as v^:_1 u v y, which means that it does the right function, then the left, then undoes the right. Here, v is *: (square) and u is +/ (sum over):
    *:3 4
    9 16
    +/*:3 4
    *:^:_1 +/*:3 4
    (+/&.:*:)3 4

    A final point is that J is ideal for Twitter and other character-limited systems. My function for Conway’s life is 38 characters long ( life =. ((]3&=)+.(*.4&=))+/@:((<:3 3#:i.9)&|.) ), leaving relatively ample description space. Unfortunately, the hashtag “#J” is not so good – it's clogged with people forgetting to remove spaces after someone's initial. I use “#jsoftware”.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: