ArticleslgStudy

computer science

Common operator notation

Common operator notation is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Common operator notation rather than just read about it. In short: In programming languages, scientific calculators and similar common operator notation or operator grammar is a way to define and analyse mathematical and other formal expressions. In this model a linear sequence of tokens are divided into two classes: operators and operands.

Key takeaways

  • Common operator notation belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Common operator notation to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Common operator notation from memory before moving on to harder problems.

Reference excerpt

In programming languages, scientific calculators and similar common operator notation or operator grammar is a way to define and analyse mathematical and other formal expressions. In this model a linear sequence of tokens are divided into two classes: operators and operands. Operands are objects upon which the operators operate. These include literal numbers and other constants as well as identifiers (names) which may represent anything from simple scalar variables to complex aggregated structures and objects, depending on the complexity and capability of the language at hand as well as usage context. One special type of operand is the parenthesis group. An expression enclosed in parentheses is typically recursively evaluated to be treated as a single operand on the next evaluation level. Each operator is given a position, precedence, and an associativity. The operator precedence is a number (from high to low or vice versa) that defines which operator takes an operand that is surrounded by two operators of different precedence (or priority). Multiplication normally has higher precedence than addition, for example, so 3+4×5 = 3+(4×5) ≠ (3+4)×5. In terms of operator position, an operator may be prefix, postfix, or infix. A prefix operator immediately precedes its operand, as in −x. A postfix operator immediately succeeds its operand, as in x! for instance. An infix operator is positioned in between a left and a right operand, as in x+y. Some languages, most notably the C-syntax family, stretches this conventional terminology and speaks also of ternary infix operators (a?b:c). Theoretically it would even be possible (but not necessarily practical) to define parenthesization as a unary bifix operation.

Operator associativity

Operator associativity determines what happens when an operand is surrounded by operators of the same precedence, as in 1-2-3: An operator can be left-associative, right-associative, or non-associative. Left-associative operators are applied to operands in left-to-right order while right-associative operators are the other way round. The basic arithmetic operators are normally all left-associative, which means that 1-2-3 = (1-2)-3 ≠ 1-(2-3), for instance. This does not hold true for higher operators. For example, exponentiation is normally right-associative in mathematics, but is implemented as left-associative in some computer applications like Excel. In programming languages where assignment is implemented as an operator, that operator is often right-associative. If so, a statement like a := b := c would be equivalent to a := (b := c), which means that the value of c is copied to b which is then copied to a. An operator which is non-associative cannot compete for operands with operators of equal precedence. In Prolog for example, the infix operator :- is non-associative, so constructs such as a :- b :- c are syntax errors. Unary prefix operators such as − (negation) or sin (trigonometric function) are typically associative prefix operators. When more than one associative prefix or postfix operator of equal precedence precedes or succeeds an operand, the operators closest to the operand goes first. So −sin x = −(sin x), and sin -x = sin(-x). Mathematically oriented languages (such as on scientific calculators) sometimes allow implicit multiplication with higher priority than prefix operators (such as sin), so that sin 2x+1 = (sin(2x))+1, for instance. However, prefix (and postfix) operators do not necessarily have higher precedence than all infix operators. Some (hypothetical) programming language may well have an operator called sin with a precedence lower than × but higher than + for instance. In such a language, sin 2·x+1 = sin(2·x)+1 would be true, instead of (sin 2)·x+1, as would normally be the case. The rules for expression evaluation are usually three-fold:

Treat any sub-expression in parentheses as a single recursively-evaluated operand (there may be different kinds of parentheses though, with different semantics). Bind operands to operators of higher precedence before those of lower precedence. For equal precedence, bind operands to operators according to the associativity of the operators. Some more examples:

1-2+3/4*5+6+7 = (((1-2)+((3/4)*5))+6)+7 4 + -x + 3 = (4 + (-x)) + 3

Generalizations of Common Operator Notation The use of operator precedence classes and associativities is just one way. However, it is not the most general way: this model cannot give an operator more precedence when competing with '−' than it can when competing with '+', while still giving '+' and '−' equivalent precedences and associativities. A generalized version of this model (in which each operator can be given independent left and right precedences) can be found at [1].

See also Order of operations Relational operator Operator (computer programming) Operators in C and C++

References

Worked examples

Example 1 — a first encounter with Common operator notation

Start with the simplest possible case. Write down what Common operator notation claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Common operator notation before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Common operator notation ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Common operator notation

In research
Common operator notation appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Common operator notation in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Common operator notation is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer arithmetic, Operators (programming), so understanding it makes those chapters shorter.
In everyday life
Look for Common operator notation outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Common operator notation” →

How to study Common operator notation in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Common operator notation means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Common operator notation out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Common operator notation in simple terms?

In programming languages, scientific calculators and similar common operator notation or operator grammar is a way to define and analyse mathematical and other formal expressions. In this model a linear sequence of tokens are divided into two classes: operators and operands.

Why does Common operator notation matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Common operator notation?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Common operator notation.

Tags

  • Computer arithmetic
  • Operators (programming)

Keep exploring