Order of Operations: Trigonometric Functions

(An archive question of the week)

Last time we looked at some details that are rarely mentioned in stating the conventions for interpreting algebraic expressions. I couldn’t fit a discussion of the most complicated case: trigonometric functions, which when written without parentheses, as they traditionally have been, can raise several issues. (Much of the same is true of logarithms.)

Trig functions without parentheses

Here is the question, from 2010:

Ordering Products, Powers, and Parameters of Trigonometric Functions

I am tying to clarify the order of operations as it applies to trigonometric functions. I want to know what the correct order of operations is for an expression like sin2x. When do we know that the multiplication is implied? When my textbook says sin2x, I know that it means sin(2x). But often the parentheses are missing. Is it then correct to assume that the multiplication is always implied to be in parentheses? If that's true, wouldn't that imply that sinxcosy would have to be read as sin(xcosy)? (I've seen that written in my textbook too, but I know I am supposed to interpret that as (sinx)(cosy).) I know that grouping symbols should always be included to avoid ambiguity; but when there are none, what is the correct way to interpret these expressions?

If trig functions were written using the normal notation for functions, e.g. \(\sin(2x)\), there would be no problem. But trig functions arose before modern function notation (or even the function concept), and the old notation was “grandfathered in”, so that although many authors today recommend always using parentheses, the old form is still common. As Jim has pointed out, if, as in \(\sin 2x\), multiplication takes precedence over the function (as if it were in parentheses), then \(\sin x \cos y\) would seem to imply that the multiplication came before the application of the sine function, making it \(\sin(x \cos y)\). And I have never seen an “official” explanation of this.

No rules, just people

I answered:

I've pondered this a number of times, and my own conclusion is that there are no actual rules.

What we are looking at here is a language that has developed not by deliberate design, but organically -- with agreement among its users -- just as any natural language evolves. Linguists can study a language to figure out its rules, but they are essentially reverse-engineering something that exists without explicit rules. You can see some of that development in the order of operations here:

  History of the Order of Operations

All a linguist can do to understand a language is to study how it is used by its speakers. Languages (apart from a few “constructed languages”) are not invented with a prepared rulebook, but grow organically as people speak them, constantly changing. Much of the English grammar we learn, which supposedly consists of a definite set of rules, was actually imposed on English by scholars who believed any valid language had to fit the categories known from Latin – with the result that it often doesn’t fit with the way we really speak. The same is true of PEMDAS: It is a set of rules imposed on our “language”, intended to represent how math is done, but a little more rigid than reality. And trigonometry is a dialect of its own!

The page referred to was my attempt to combine data and speculation to discuss how we got the “rules” we have, and will be the subject of another upcoming post.

The language of trigonometry is especially hard to explain logically. I just looked through Cajori's _History of Mathematical Notations_, and the variety of early forms is remarkable. In particular, he shows how much inconsistency there was in writing 

Some would write it as 

  sin x^2
Others would render it as

  (sin x)^2
And still others would denote it as

  sin^2 x

The Cajori reference is to volume 2, page 178. The actual forms mentioned, of course, don’t use “^”, but are \(\sin x^2\), \((\sin x)^2\), and \(\sin^2 x\).

That last way is the usual one today, despite long-acknowledged difficulties. Specifically, it could be taken to mean sin(sin(x)) -- a repeated application of the sine function. But Cajori points out

  "As functions of the last type [sin(sin x)] do
not ordinarily present themselves, the danger
of misinterpretation is very much less than in
case of log^2 x, where log x * log x and
log(log x) are of frequent occurrence in analysis." What he's saying is that this abbreviated notation is used because it is sufficient to distinguish commonly used forms from one another: experience tells us that someone wouldn't mean sin(sin(x)).

This is not, of course, the main issue we are discussing, but illustrates the fact that the notation of trigonometry is idiosyncratic, and is acceptable largely because “we know it when we see it” without needing rules.

The rule of common sense

I think that basic rule of common sense lies behind the laxness in the use of other forms, such as the second and third examples you mention:

  sin 2x          means      sin(2x)

  sin x cos y     means      sin(x)cos(y)

These mean what they do simply because we know enough NOT to expect that

  sin 2x        would mean   sin(2)*x
  sin x cos y   would mean   sin(x*cos(y))

There is perhaps also a bit of typographical consideration: the spacing generally suggests that 2x belongs as a unit, as do sinx and cosy in the second example.

In modern textbooks (especially in calculus) there may be complicated expressions made up just to challenge one’s skills, without reference to whether they would ever really be used; in such a context, common sense might turn out to be useless! The other part of common sense then applies: When there is any possibility of misinterpretation, use parentheses. And the contrapositive of that is, if an expression doesn’t have parentheses, assume the author intended it to be read in the most natural way (whatever that is).

So it may be possible to examine all usages linguistically and come up with some rules -- for example, "multiplication precedes trig functions except where another trig function would be a factor." But what we really do in reading these expressions is to use common sense based on mathematical experience.

Does that help at all?

In other words, I didn’t think it’s worthwhile to try to come up with a complete set of rules.

Jim answered:

This helps a lot. I appreciate knowing that this is not as cut and dried as I thought it must be.

Thanks for the very clear explanation -- I really appreciate it!

The skeleton in our closet

Whenever I give an answer that comes largely out of my own head, I like to look for additional evidence. In this case, I found it in a 2008 (then unarchived) answer by Doctor Tom, which I now quoted. Here is the question:

Dear Doctor Math,
Are there rules (relating to order of operations maybe) that set guidelines for using parentheses with trig functions?

For example, we are told to write the derivative of ...
  sin(4x^2 - 2) 

... as

  8x cos(4x^2)
This leaves no ambiguity as to whether ...
  cos(4x^2 - 2)   is multiplied by    8x
... or just 
  4x^2 - 2        is multiplied by    8x

Positioning the 8x term in front helps avoid confusion about where one expression ends and another one begins.
But mathematically, and conventionally, what would this mean?
  cos(4x^2 - 2)(8x)
Personally, I would take it to mean
  [cos(4x^2 - 2)] (8x)
If I wanted to convey "take the cosine of the whole quantity," I would write 
I understand it's best to use parentheses and brackets to erase any doubt, but would it be wrong to write cos(a) (b) when you mean (b)cos(a)?

When no parentheses are used -- for example, with sin 2x -- I know we usually take this to mean sin(2x). So that's something else to think about!


This is much like the question I answered, but with a bigger example. If we ever wrote \(\cos(a)(b)\), would we take it as a function of a product, as we would with \(\cos ab\)? If not, why not?

There is actually a quick answer to this particular one: When parentheses are used with a function, they always enclose the entire argument. The fact that parentheses are optional for trig functions is irrelevant; once you use parentheses at all, you lose the right to think of them as containing only one factor of the argument.

Doctor Tom answered the bigger question instead:

Hi Bev,
Good question! You've caught us mathematicians with our pants down.
I think it's mostly out of laziness that we even write things like this
  "sin x"
Almost every other function other than the trigonometric (and possibly logarithmic) ones requires that there be parentheses around the parameter(s).

Once you admit the legality of a form like "sin 2x," you've opened a can of worms. Even something like this ...
  f(x) = sin x + cos x

... could then mean this, right? f(x) = sin(x + cos(x))

I think everyone more or less agrees that addition is definitely done after the function, so that \(\sin\alpha + \beta \ne \sin(\alpha + \beta)\). (On the other hand, if \(\alpha\) and \(\beta\) are known to be angles, we might consider it clear that the first form must mean the second, as we never add angles to ratios.) But such a rule is not generally stated explicitly, and without such rules, anything is possible.

This is going to sound awful, but I have seen this sloppy usage so often that I just "know" what's intended. We mathematicians simply do a lot of "assumed grouping." For example, no professional mathematician would ever write a product this way:

She'd always write it like this:
In the same way, I'd never write ...
  sin x 2
... or even
  (sin x)2
I'd move the 2 in front, to make it this ...
  2 sin x 
... or this:
  2 sin(x)
Likewise, interpreting this ...
  sin 2x
... as "the sine of 2, multiplied by x" would be very unusual, since first off, we'd almost surely put the "x" in front of the "sin 2"; and second, unless there's a "degree" symbol after the "2," it would be incredibly unlikely that you'd be taking the sine of 2 radians.

So rather than grammatical rules, we use a different convention in practice: Write expressions in a consistent order (e.g. numerical coefficient followed by variable), even when logically it would make no difference. If we see \(x2\), rather than just follow the rule that says this is multiplication, we instead think, I’d better ask the author if she meant \(x^2\), because this just isn’t the way we write. This is a way to remove ambiguity and add redundancy, so we can recognize errors. A similar convention is to always write a radical last, to make sure the vinculum isn’t misread as extending too far: \(2i\sqrt{3}\) rather than \(2\sqrt{3}i\), which looks too much like \(2\sqrt{3i}\). These are not considered part of the order of operations, or absolute rules; they are just common practice as a matter of politeness – a different sort of “convention”.

In this case, the convention might be, always write a trig function last, rather than following it with any multipliers; that way, everything following “sin” (until a “+”) is part of the argument.

Most computer languages require parentheses for the trig functions (well, any functions), because they have to be precise.

If you do put parentheses after sin, cos, et cetera, then there's no doubt that the contents of those parentheses represent exactly the parameter to the function.

So for your example of "cos(4x^2 - 2)(8x)", every mathematician in the world would interpret this as the cosine of 4x^2 - 2, with that result then multiplied by 8x.

I'm sorry there's not a clean, clear answer, but that's the way it is: an ugly skeleton in the mathematician's closet.

I concluded:

So, Dr. Tom more or less agrees with me, but says it in ways that complement my explanations.

Having started a consideration of why we follow the conventions we do, next time I’ll look at some of many questions we’ve had on the reasons for the order of operations.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.