What's the difference between operators and functions?

In summary, there is a fundamental difference between operators and functions. Operators can be considered a type of function, but they are defined on functions rather than numbers. Often, we use infix notation for operators for convenience and familiarity. However, this can cause confusion as operators are not always written in this way.
  • #1
SW VandeCarr
2,199
81
Is there a fundamental difference between operators and functions?

For example we could have F(x,y)=x+y or we could write SUM(x,y) where SUM is a defined operation in some program. Could operators be considered a particular type of function?
 
Mathematics news on Phys.org
  • #2
Yes. Any binary operation on [itex]S[/itex] is simpy a function from [itex]S \times S \to S[/itex]. We use infix notation (that is, we write the function in between the operands as in x + y instead of +(x, y) ) out of convenience and familiarity.
 
  • #3
Moo Of Doom said:
Yes. Any binary operation on [itex]S[/itex] is simpy a function from [itex]S \times S \to S[/itex]. We use infix notation (that is, we write the function in between the operands as in x + y instead of +(x, y) ) out of convenience and familiarity.

Thanks Moo Of Doom. I was pretty sure of this, but math texts usually use these in terms in distinct ways.
 
Last edited:
  • #4
Moo of Doom talked about "operations". Your question was about "operators". Generally, an "operator" is a function defined on functions as opposed to functions on numbers.
 
  • #5
HallsofIvy said:
Moo of Doom talked about "operations". Your question was about "operators". Generally, an "operator" is a function defined on functions as opposed to functions on numbers.

Then SUM(x,y) would not be read as an operator on (x,y), but rather as an operation on (x,y)?
 
  • #6
Yes, that is true. The original post was ambiguous.
 

1. What are operators in programming?

Operators are symbols or keywords used in programming languages to perform operations on data. They are used to manipulate data and perform calculations. Examples of operators include addition (+), subtraction (-), multiplication (*), division (/), and comparison (==).

2. What are functions in programming?

Functions are reusable blocks of code that perform a specific task. They take in input, process it, and return an output. Functions help make code more organized, efficient, and easier to maintain. They can also be called multiple times within a program.

3. How do operators and functions work together?

Operators can be used within functions to manipulate data and perform calculations. Functions can also take in operator symbols as parameters to perform specific operations on given data. For example, a function may use the addition operator to sum two input values and return the result.

4. What is the difference between unary and binary operators?

Unary operators operate on a single operand, while binary operators operate on two operands. Examples of unary operators include the increment (++) and decrement (--) operators, which add or subtract 1 from a variable. Binary operators include addition (+), subtraction (-), multiplication (*), and division (/).

5. How do I use built-in functions in my code?

Most programming languages have a set of built-in functions that can be used without having to write them from scratch. These functions are typically documented in the language's documentation and can be called by their name with appropriate parameters. For example, the built-in function "print()" can be used to display output to the console in many programming languages.

Similar threads

Replies
3
Views
264
Replies
17
Views
2K
  • General Math
Replies
2
Views
723
Replies
18
Views
1K
  • General Math
Replies
13
Views
2K
Replies
2
Views
247
  • General Math
Replies
2
Views
740
  • General Math
Replies
11
Views
398
Replies
9
Views
1K
Back
Top