In functional programming you have Referential Transparency, which means that you can replace a function with its value without altering the program. This is true in Math too, but this is not always true in Imperative languages.

A math function is defined by: a relationship that maps elements from one set (A) to another (B), mapping each element of the first set with only one of the other set. In C (as in other programming languages) this is also true, you have your input set, and your output set (which is almost always only ONE).

The main difference, is, then, that if you call f(x) in math, you will ALWAYS get the same answer, but if you call f'(x) in C, the answer may not be the same - the same arguments don't always return the same output. A function in non-functional languages may not depend solely on the arguments you give them, but on other things in the program (enclosing scope, globals, builtins, state if you're using object orientation).

Another difference between math and C functions, is that in Math you can't make a function that goes from a non-empty set to an empty set (in C this would be: You aren't requiered to always return something with your function). Also, not all function are computable (I don't know if there's something similiar to this in math..). You don't have functions for infinite sets (you have finite memory, so the set of the possible input parameters must be finite), but in math, you can define a function for infinite sets (like f: N -> N) and for uncountable sets (like f: R -> R) (In C you have floating point numbers, but they only represent a reduced set of real numbers, which is finite).

Summarizing:

In C you don't always have Referential Transparency. Your functions may not always give the same output for the same input parameters. You can have Math functions that defined for an infinite set of inputs, but in C functions your input is finite. In C functions you can have functions that returns nothing, but in Math you can't have that (if you have a function that has a non empty input set, you must map each element with one of another set).

Answer from Marco on Stack Overflow
🌐
Programmer's Wiki
code.fandom.com › wiki › Mathematical_functions
Mathematical functions | Programmer's Wiki | Fandom
While functions in programming languages are subroutines that return values given certain parameters, functions in mathematics are defined as relations between elements in a definition set Df, and elements in a value set Dv, such that f: x --> ...
Top answer
1 of 6
31

In functional programming you have Referential Transparency, which means that you can replace a function with its value without altering the program. This is true in Math too, but this is not always true in Imperative languages.

A math function is defined by: a relationship that maps elements from one set (A) to another (B), mapping each element of the first set with only one of the other set. In C (as in other programming languages) this is also true, you have your input set, and your output set (which is almost always only ONE).

The main difference, is, then, that if you call f(x) in math, you will ALWAYS get the same answer, but if you call f'(x) in C, the answer may not be the same - the same arguments don't always return the same output. A function in non-functional languages may not depend solely on the arguments you give them, but on other things in the program (enclosing scope, globals, builtins, state if you're using object orientation).

Another difference between math and C functions, is that in Math you can't make a function that goes from a non-empty set to an empty set (in C this would be: You aren't requiered to always return something with your function). Also, not all function are computable (I don't know if there's something similiar to this in math..). You don't have functions for infinite sets (you have finite memory, so the set of the possible input parameters must be finite), but in math, you can define a function for infinite sets (like f: N -> N) and for uncountable sets (like f: R -> R) (In C you have floating point numbers, but they only represent a reduced set of real numbers, which is finite).

Summarizing:

In C you don't always have Referential Transparency. Your functions may not always give the same output for the same input parameters. You can have Math functions that defined for an infinite set of inputs, but in C functions your input is finite. In C functions you can have functions that returns nothing, but in Math you can't have that (if you have a function that has a non empty input set, you must map each element with one of another set).

2 of 6
6

It depends on the domain (I don't mean the domain of the function, I mean the domain of study) and also possibly the language.

In math, a function has an input that maps to only one output for a given input value (vertical line test, remember). In programming, this might not be strictly the same, depending on where you draw the line between "input" and "function logic."

For instance, let's imagine we have a function rand() that reads atmospheric conditions to arrive at a truly random number. Let's also imagine that a calling function takes one integer parameter as a mutiplier of sorts. Is the following a function?:

Copyint giveRandAtmosWithMul(int mult)
{
    return mult * rand();
}

In the mathematic sense, it probably is not a function if you consider mult as the only input to the problem, but clearly rand() is offering input as well (even though rand() always has the same entry point in machine code).

As you can see, the differences aren't really objectively definable without some standard protocol that everybody agrees to.

Discussions

I'm new so sorry if this appears silly but are functions in programming inspired by functions in maths and are operators nothing but functions.
Yes, they are certainly inspired by maths! In the early days of programming, computers were primarily used for solving math-problems - or rather, doing the calculations. In maths you can have a function that receives some parameter, and then returns a value that is in some way calculated from the parameter - and that function can use other functions in it's calculations, where each function-call gets calculated/translated into a value depending on the input-parameter. Functions in programming can do the same! They can also do much more, and be used to simply group lines of code into a unit, but there is a concept of a "pure function" that is exactly like a maths-function, and always gives the same output from the same input - other functions might have "side effects" and modify something outside of themselves, something that is impossible in maths. An operator - like * - can also be thought of as a special kind of invoking a function. Where you would usually call a function by F(x,y), operators work between the parameters, like x * y, but the end-result is the same. In some languages, notably C++, you can override operators, and write different functions for them ... I don't think that it helps to learn maths functions when learning programming - but if you like maths, and find it intuitive to think in that way, then it is fairly easy to transfer that thinking to programming. More on reddit.com
🌐 r/learnprogramming
20
60
January 25, 2023
Why are functions in programming not considered "mathematical" functions?
For the sake of interest I was out looking for a discussion of functions in computer science as generalized functions. I started my search by something such as "computer functions as mathematical... More on researchgate.net
🌐 researchgate.net
21
6
July 25, 2018
Is recursion in programming the same thing as recursion in math?
To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
36
69
December 26, 2021
How much math is prevalent in programming? What types of math are used frequently aside from basic arithmetic?
Mathematics is very important in some fields of programming, such as cryptography, algorithm design, AI development, finance and algorithmic trading, ... Matheatics is typically used far less in other fields, such as front end web development, user interface design, system admin, chatbot development, ... More on reddit.com
🌐 r/learnpython
122
134
September 27, 2024
People also ask

What is the return type of most math functions?
Most math functions in C return a double value.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › math-functions
Math Functions in C Programming (Full List With Examples)
🌐
Medium
erik-engheim.medium.com › functions-in-mathematics-and-programming-9741cbeb8d4b
Functions in Mathematics and Programming | by Erik Engheim | Medium
September 11, 2020 - We can express this function in different programming languages. In python we would write: ... The problem is that we have to specify type, which our math example did not bother with. This does not mean mathematical notation does not allow you to express argument types, quite the contrary.
🌐
Reddit
reddit.com › r/learnprogramming › i'm new so sorry if this appears silly but are functions in programming inspired by functions in maths and are operators nothing but functions.
r/learnprogramming on Reddit: I'm new so sorry if this appears silly but are functions in programming inspired by functions in maths and are operators nothing but functions.
January 25, 2023 -

I think functions in maths and programming sound too similar and can't operators be modelled by functions themselves? I think operators can be defined via functions. I think learning functions in maths would be more helpful for learning programming. Am I right in these conclusions or is it wrong.

Top answer
1 of 5
64
Yes, they are certainly inspired by maths! In the early days of programming, computers were primarily used for solving math-problems - or rather, doing the calculations. In maths you can have a function that receives some parameter, and then returns a value that is in some way calculated from the parameter - and that function can use other functions in it's calculations, where each function-call gets calculated/translated into a value depending on the input-parameter. Functions in programming can do the same! They can also do much more, and be used to simply group lines of code into a unit, but there is a concept of a "pure function" that is exactly like a maths-function, and always gives the same output from the same input - other functions might have "side effects" and modify something outside of themselves, something that is impossible in maths. An operator - like * - can also be thought of as a special kind of invoking a function. Where you would usually call a function by F(x,y), operators work between the parameters, like x * y, but the end-result is the same. In some languages, notably C++, you can override operators, and write different functions for them ... I don't think that it helps to learn maths functions when learning programming - but if you like maths, and find it intuitive to think in that way, then it is fairly easy to transfer that thinking to programming.
2 of 5
8
There is an important connection between the two. Indeed, the word "function" in programming is borrowed from maths, and so is the f(x) notation. Originally, computers were designed to assist scientists and engineers with number-crunching. It makes sense that these people would have wanted features that allowed them to represent mathematical functions. However, there are important differences between the two concepts, and unfortunately, different languages often use the word to mean subtly different things. Many imperative languages use the word "function" for what would more appropriately be called a "procedure" (my preferred word) — a block of code to be injected with parameters and run as many times as you like. You can certainly represent the process of calculating a mathematical function with a procedure, but this isn't quite the same thing as the mathematical function itself. The mathematical function represents the abstract association between a given input and the resultant output. The procedure, on the other hand, represents the concrete computation performed. Further, the output of a procedure can depend on the state of the program, or even on external factors (like user input, or the value given by a sensor attached to the computer, or a random number generator). This means you could provide the exact same parameters, and get different return values, depending on when or how many times or in what order you call your procedures. This is never the case for mathematical functions. This behaviour is sometimes described as impurity, and procedures which never change their outputs for a given input are called pure, or just functions (though again, some languages use the word "function" or "impure function" for every kind of procedure). Pure functions are much closer to mathematical functions, but even then they are not the same thing (they describe the computation, not the abstract association). There is a style of programming called "functional programming", which uses only pure functions to describe computation instead of step-by-step instructions. Functional programmers try to make all their code look as much like mathematical functions as possible. Even then, however, the "functions" they write are not true, mathematical functions (for example, there can be functions which never return).

In functional programming you have Referential Transparency, which means that you can replace a function with its value without altering the program. This is true in Math too, but this is not always true in Imperative languages.

A math function is defined by: a relationship that maps elements from one set (A) to another (B), mapping each element of the first set with only one of the other set. In C (as in other programming languages) this is also true, you have your input set, and your output set (which is almost always only ONE).

The main difference, is, then, that if you call f(x) in math, you will ALWAYS get the same answer, but if you call f'(x) in C, the answer may not be the same - the same arguments don't always return the same output. A function in non-functional languages may not depend solely on the arguments you give them, but on other things in the program (enclosing scope, globals, builtins, state if you're using object orientation).

Another difference between math and C functions, is that in Math you can't make a function that goes from a non-empty set to an empty set (in C this would be: You aren't requiered to always return something with your function). Also, not all function are computable (I don't know if there's something similiar to this in math..). You don't have functions for infinite sets (you have finite memory, so the set of the possible input parameters must be finite), but in math, you can define a function for infinite sets (like f: N -> N) and for uncountable sets (like f: R -> R) (In C you have floating point numbers, but they only represent a reduced set of real numbers, which is finite).

Summarizing:

In C you don't always have Referential Transparency. Your functions may not always give the same output for the same input parameters. You can have Math functions that defined for an infinite set of inputs, but in C functions your input is finite. In C functions you can have functions that returns nothing, but in Math you can't have that (if you have a function that has a non empty input set, you must map each element with one of another set).

Answer from Marco on Stack Overflow
Top answer
1 of 14
4
Short answer. The use of the term "function" as a designator in commonly-used programming languages is actually a mistaken use of the mathematical notion having the same name. It seems that, in the early days of computer software and programming language development, the choice of nomenclature was in some sense a corruption of the mathematical usage. It wasn't malicious, but an over-reaching that was perhaps not well-understood at the time. In programming languages, "function" is used to designate a specific computational procedure. For appropriately-written procedures, there is establishment of a specific algorithm for some similarly-named mathematical function. It is not the function, it is an algorithmic procedure. When accurate, the correspondence between represented operands and the represented result satisfies the relationship established for the mathematical functions domain and range members. There are many procedures for the same function, in this sense (and there can be many mathematical characterizations of the same function). The clouding of nomenclature becomes an issue when one needs to deal with the fact that mathematical use of functions need not have any direct connection with computation.
2 of 14
0
Dear Petrus, The answer depends upon the aim of your research. One area of publications which may be of interest is the treatment of computer functions using level index arithmetic. There is a large body of literature on this subject, e.g. entering level index arithmetic functions computer (without quotes) in Google Scholar yields over 400,000 results.
Find elsewhere
🌐
Wikipedia
en.wikipedia.org › wiki › C_mathematical_functions
C mathematical functions - Wikipedia
February 14, 2026 - C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. Different C standards provide different, albeit backwards-compatible, sets of functions.
🌐
W3Schools
w3schools.com › c › c_math.php
C Math Functions
There is also a list of math functions available, that allows you to perform mathematical tasks on numbers. To use them, you must include the math.h header file in your program:
🌐
WsCube Tech
wscubetech.com › resources › c-programming › math-functions
Math Functions in C Programming (Full List With Examples)
1 week ago - Learn in this tutorial about math functions in C programming with simple examples. Learn how to use each function with clear syntax and practical applications.
🌐
Medium
medium.com › codex › the-mathematical-connection-of-functions-in-programming-cba7b6a707a7
The mathematical connection of functions in programming | by Eliana Lopez | CodeX | Medium
June 22, 2022 - This is how a function is traditionally defined in mathematics: A function from X to Y assigns each element of X to each element of Y. However the notation of a function can also be written as: I have written the second notation because it can be easier to visualize how a function also works within a program, which would then better illustrate the parallels of how functions work in both mathematics and in programming.
🌐
Medium
iorilan.medium.com › functions-in-math-and-programming-382aa80dedae
Functions in math and programming | by LORY | Medium
September 3, 2023 - Which was a very interesting discussion. Yes and no. First, let's talk about programming. after a decade of programming with 5+ languages, I found that programming itself is always a kind of building some system, and function is one part of the work — get things done.
🌐
San Bei Ji
essays.sanbeiji.com › 2023 › 04 › 09 › functions
Functions in math vs programming – San Bei Ji
April 18, 2023 - To illustrate, here’s a basic example of a mathematical function: ... This formula takes in a value for x and returns the cube value of x. If you feed this function a value of 2, it’ll give you back a value of 8. Give it a 5 and it’ll return 125. Here’s a function I wrote in the Kotlin programming language called cube() that performs a similar (for lack of a better word) function:
🌐
Quora
quora.com › What-is-the-difference-between-mathematical-function-and-function-in-a-program
What is the difference between mathematical function and function in a program? - Quora
Answer (1 of 3): In general : * A mathematical function only uses it’s inputs and outputs its values in one way - i..e. it’s output (equivalent to it’s return value) * A computing function can use data other than it’s input (global variables, instance variables - in OOP, databases) ...
🌐
NRICH
nrich.maths.org › 6873
An Introduction to Computer Programming and Mathematics
Exercise: Write a function that takes two integers a and b, and returns the value of $a^b$. We have covered the basic functionality of C++. C++ also comes with a whole range of predefined functions - for example, the common mathematical functions such as sin, cos, and square root, and functions for generating random numbers.
🌐
Dremendo
dremendo.com › cpp-programming-tutorial › cpp-mathematical-functions
Mathematical Functions in C++ Programming | Dremendo
We can quickly solve a mathematical equation in C++ with the help of Mathematical Functions. These are predefined inbuilt programs that accept values and return the result. We have to import the math header file in our program to use these mathematical functions.
🌐
Aritmética Mental Europa
abakus-center.com › blog › real-life-applications
Real-Life Applications of Functions Across Various Fields
Mathematically, a function takes ... In programming, functions perform similar roles, encapsulating reusable logic or code that can be invoked with varying inputs....
🌐
Wikipedia
en.wikipedia.org › wiki › Functional_programming
Functional programming - Wikipedia
2 weeks ago - This allows programs to be written in a declarative and composable style, where small functions are combined in a modular manner. Functional programming is sometimes treated as synonymous with purely functional programming, a subset of functional programming that treats all functions as deterministic mathematical functions, or pure functions.
🌐
Brinckerhoff
brinckerhoff.org › blog › 2020 › 12 › 11 › on-the-relationship-between-mathematical-functions-and-program-functions
On the relationship between mathematical functions and program functions
December 11, 2020 - Yikes.). In programming, functions are often thought of as being elements of abstraction that are designed to allow repetition. And so they are. But it turns out that they also, in most modern programming languages, can be thought of as mathematical functions.
🌐
Wikipedia
en.wikipedia.org › wiki › Function_(mathematics)
Function (mathematics) - Wikipedia
2 weeks ago - That is, it is a program unit that produces an output for each input. Functional programming is the programming paradigm consisting of building programs by using only subroutines that behave like mathematical functions, meaning that they have no side effects and depend only on their arguments: they are referentially transparent.
🌐
DataCamp
datacamp.com › tutorial › what-is-a-function-in-math
What Is a Function In Math? An Intuitive Explanation | DataCamp
2 weeks ago - To see how these ideas fit into real machine learning workflows, you can continue with the Understanding Machine Learning course. A mathematical function is a rule that maps each input to exactly one output.