Alternatives to parentheses for grouping

I've just begun reading Whitehead and Russell's "Principia Mathematica" available here and was surprised to find on page 9 a nice readable alternative to parentheses for grouping.

Each operator is preceded and/or succeeded by some dots written as colons and periods. The more dots an operator has, the lower precedence it has. To take one of their examples (page 10),
p -> q .->. q -> r :->. p -> r
((p -> q) -> (q -> r)) -> (p -> r)

I find the dot version more readable and easier to type than the parentheses version. I'm curious if anyone here knows of other alternatives to parentheses for grouping. Prefix and postfix we've all heard of here, but do you have less well known ones? Hideous or beautiful I'd love to see them! Have any been tried in programming languages?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Moving Code Around

Seems like moving code around could be frustrating: with parentheses you can copy a well-formed expression (that means what you want it to mean) into some other expression and all is well. With the dot notation you describe you might need to change a lot of dots, in a sort of non-local fashion.

What's nice about the dots notation is that is sort of a stand in for 'weight'; like in the example given :->. looks the 'heaviest', so it splits up the two sides of the expression 'first'.

Thanks for the pointer, it's kind of neat.

Ordinary parentheses combined with this

Since the dot notation doesn't use parentheses at all, you can add ordinary parentheses to it, and then put a pasted expression in parentheses until you get its precedence dots sorted out. I don't think programmers would mind such a system, since we already have similar work to do in languages with operator precedence.

That said, discouraging copy/paste coding might be a good idea anyway, because code that was correct in one context might be wrong in another. The problem is that the dot system probably wouldn't give an error on a pasted code fragment, it would just do the wrong thing, which is bad.

Quine, as well

I first encountered the notation in Quine's Mathematical Logic in the late 60's (and forgot about it when I encountered FORTRAN). I remember the same mixed-feeling reaction over its contrast with "normal" algebraic notation.

I see it as an example of the QWERTY phenomenon. There may be nice alternatives to the conventional way we do things (QWERTY vs. Dvorak, dots vs. parentheses, OO vs. PO, FP vs. OO, English vs. metric, et cetera ad nauseum) but the imagined and real costs of change often seem to swamp the discussion of technical tradeoffs, at least until there's some compelling use case that triggers a phase change.

I'm more fascinated by our tendency (including my own) to think of this in terms of character manipulation, rather than expression manipulation. A notation-aware editor could automatically locate the expression (one of the nested set of expressions) enclosing the current cursor location, and extract only well-formed expressions for a variety of operations (cut, paste, drag, immediate evaluation, etc.)

(I'm not sure whether its our tools that limit our thinking habits or the other way around... ;-)

Dots and the dot

The use of dot for logical conjunction derives from this style. In PM, an operator consisting only of dots was conjunction; how many dots it had determined its precedence, as with other operators.

Pure lets you define pairs of outfix operators, which are semantically a single unary operator but syntactically function like parentheses:

outfix [| |];
[| x |] = whatever x;

I always found that to be

I always found that to be the most annoying thing about PM...

Horizontal Layout

Merd uses horizontal layout to define precedence (e.g. 1+2 * 3 = 9).

which drives me pretty batty

i mean, i kinda think real math already has precedence defined.

Spacing is precedence too

Math does have well-defined precedence rules, but I think spacing is an even more basic expression of precedence. Plus, I think the code ends up being a bit easier to read.

Maybe you'd prefer Fortress' more conservative approach of ensuring the spacing agrees with the operator precedence rules?

nice link

which makes me think it is a hard problem in usability.

p.s. "Here's one more example of interest. When entered as 2 ^ 3 ^ 4 without parentheses, the TI85 calculator shows 4096 and the TI89 shows 2.41785163923 E24. (Those are the answers to (2 ^ 3) ^ 4 and 2 ^ (3 ^ 4), respectively.)" from

If A=B...

...then you'd like to be able to substitute A for B as a subexpression without having to edit A according to the new context first.

Might be nice

But most infix languages with operator precedence don't have that property, anyway. Take A=1+2, B=3 in the expression B*2.

Your example might need fixing as it doesn't mention A

If you want to substitute A for B you can simply put parentheses around A before substituting. This new notation requires the operators in A to be edited first.


I was assuming parentheses would still work.

I once encountered

I once encountered, while browsing in a university library, a book from about a couple of generations later that used that dot notation; I'll guess it was a theoretical physics book from the 1960s or 70s, but I wouldn't swear to it. I recognized the notation from a description by my father, who had remembered it as an eccentricity of a professor he'd encountered in graduate school. As it was a subject I had some interest in (I clearly recall that, anyway), I consequently spent some time trying to study it; but the spectacularly non-standard notation made the formulae effectively incomprehensible, and in the end I had to just walk away from it despite my interest. I work routinely with ideas that are somewhat off the beaten path, and I've always kept that book in mind as an object lesson in the hazards of sinking fundamentally unconventional ideas with gratuitously unconventional presentation.

What about a conventional presentation to complement ...

...unconventional notation?

I think the most interesting thing I ever read about symbolic manipulation was a book that argued that the way we teach children to add numbers would not be the technique we would use to train adults. I have that book somewhere in my closet... I found it astounding because I could not imagine a similar way to add numbers.

Maybe that professors notation was simply the C++ of notations for that math discipline...

Dot notation isn't standard probably because... contrast to parentheses, which are used for grouping, that is, to help the reader see a subexpression as a cohesive unit, the dots are essentially fragmentive: they are used to split the expression into pieces, and the reader then has to turn that information inside out to identify the subexpressions. This becomes clearer when the expression is deeply nested — as I recall, that physics(?) book had expressions at least five dots deep. It's also clearer when dealing with something like theoretical physics, where big hairy mathematical expressions are usually typeset in the sort of way that TeX is so good at, taking full advantage of the two-dimensional space on the page. In that sort of typeset expression, the whole thing is a nested hierarchy of rectangular regions on the page, with many of those regions visually bounded by parentheses that span the entire height of the rectangle on its left and right sides. The dot notation is a mostly one-dimensional notation, even if the dots are always stacked vertically (which we can't do when we're representing a program text using ascii characters, of course). But even if one is limited to a string of ascii characters, parentheses still seem to me to have an advantage because they work by cohesion rather than fragmentation.

On the general problem of unconventional notation, my original remark was about combining it with other unconventional elements; the point was that if you're trying to get people to listen to one unconventional thing, it behooves you to have, and explain, a very good reason why that one thing is worth bucking convention for, and whatever you do don't ask your audience to confront more unconventionality than necessary, because whatever benefit of doubt they may be willing to give you will not stretch beyond that one very good reason (if you're even skillful enough to get that reason across to them). If the one unconventional thing is the notation, you still need the very good reason — and in the case of dot notation I don't think you have it, because of the cohesion/fragmentation contrast.


IIRC the dots are Peano's invention. A modernization of this might be font size, where operators of a larger font size are of higher precedence. (Or, I suppose, any other propery -- you might have all your characters blink, and the higher-precedence operators blink faster. Or each could emit a tone with a unique pitch, and the higher-precedence operators could be louder. Or you could use parentheses.)

Graphical notation

Frege used a two-dimensional notation for predicate formulae, where implications were marked by forks. Take a look at Stan Burris' summary.

Peirce devised a graphical notation, called existential graphs, which are something like Venn diagrams with modifications to allow them to represent existential quantification.

I find Frege's notation fairly intuitive, but on the whole, I'm not impressed by the case that direct transformations of formulae into a graphical form does anything to improve readability. The case for graphical representations is that, with a little effort, one can add supplementary information with less distraction from the overall structure, achieving higher information density without sacrificng intelligibility.