# What is the difference between operator and function?

We have operator and operands, function and formal arguments. Is the difference purely lexical (we use alphanumerics for funciton identifiers but identify operators with special characters, e.g. "+" and ">=") or it is syntactical, like I guessed here

f(a,b) -- prefix notation used for functions
a.f(b) -- infix notation for method invocation (used in OOP)
a f b  -- infix notation without dot and parenthesis used in operator invocations


so that when we write a + b we have an operator but "+"(a, b) (both ways are acceptable in VHDL) makes it a function? Do tools treat them differently? Can you differentiate them? Can you say that this is not a function, it is an operator or vice-verse? When I read the definitions in wikipedia, I do not see that syntax is a distinguishing feature of a concept. So, is it right that operators and functions are synonyms, two different words for the same thing, same meaning, same notion? I have such guess but have never seen it stated explicitly. Please agree with my guess or say what is the difference.

• What is your context? I don't think there is a general answer. For example, integer + is an operator in Java and a method in Scala (which has no operators as such). And in mathematics, I don't think there is a difference.
– Raphael
Oct 14 '12 at 16:14
• I think that in mathematics situation is similar to programming: two words for the same thing. Operators might have a flavour of "higher-order functions" there. You see, I tried to ask a specific question in VHDL group but it does not help. I do not think that specialists in some language have a better idea of why they call some thing a function and another operator than answering it in general. So, I ask from computer scientists in general.
– Val
Oct 14 '12 at 18:44
• But I also welcome if you come up with specific contexts, which are concrete on the topic
– Val
Oct 14 '12 at 18:58
• In mathematics, $\mathbb R \to \mathbb R$ is a function, $(\mathbb R \to \mathbb R) \to \mathbb R$ is a functional, and $(\mathbb R \to \mathbb R) \to (\mathbb R \to \mathbb R)$ is an operator. Nov 26 '16 at 12:03

Historically, my guess is that the difference is rooted in how things were (and still are) translated into machine code.

An operator such as addition of integers or exclusive-or of booleans would be translated into one (or few) assembler commands which would be directly executed by the processor (resp. its ALU). It would also be part of the syntax.

A function (or procedure, method), on the other hand, is a subprogram the (main) program would explicitly jump to during execution. That is, a new stack frame is allocated, register values are saved, parameters are passed and only then is the function executed. See here for details. Furthermore, functions are defined by the programmer.

Younger programming languages have introduced more abstraction, partially or totally removing the distinction. In C#, for instance, you can overload operators for your own types. In Scala, there are no operators but only syntactic sugar for binary methods. Once these languages are compiled, though, you can see which language elements are translated to flat instructions and which to subroutine calls. Keep in mind that optimising and/or just-in-time compilers may liberally move between worlds.

• As I suspected, the answer has no context. The history determines the whole realm of machine languages.
– Val
Oct 14 '12 at 22:19
• @Val To complete Raphael's answer, in many modern languages, something is called a function if it has an alphabetical name that's written before the argument and an operator if it's made of punctuation and may be infix or otherwise syntactically special. The distinction is not deep and is language-dependent. Oct 14 '12 at 23:51
• Another viewpoint is that operators are primitive constructs of a language, given meaning as part of that language's formal semantics, whereas a function is defined in the language itself. Nov 24 '16 at 17:46
• And lambda calculus isn't part of computer science, now? In mathematics, $f$ is the function and $f(x)$ is the value to which it maps $x$. And, in any case, what does this have to do with the distinction between functions and operators. Nov 26 '16 at 13:14
• No, I'm not "silently applying $f(x)$ to a value": I'm explicitly applying $f$ to the value $x$. $f(x)$ is a value, so I can't apply it to some other value. Wittgenstein wrote quite a bit, so I'm gonna need a specific reference. Nov 27 '16 at 22:32