6
$\begingroup$

I never learned a lot of mathematics (generally only arithmetic) and never learned computer science in a formal frame.

I emphasize that I don't mean to ask about a "function" in programming ("procedure"/"method"), rather only about the difference between the formal definition of function in mathematics to the formal definition of function in (theoretical) computer science, if at all there is any such difference (unless computer science don't share the exact definition common in mathematics).

Is there difference between a function in mathematics to a function in computer science?

$\endgroup$
3
  • 1
    $\begingroup$ I would argue that the word 'function' within computer science itself varies subtly in definition from place to place. Sometimes it matches the mathematical kind, sometimes it is meant to be a computable function, at other times it refers to a piece of computer code, etc. E.g. Python's random.random() is unequivocally called a function in its documentation and when people refer to it, but violates most of the mathematical properties of a function. $\endgroup$
    – orlp
    Oct 9, 2020 at 8:55
  • $\begingroup$ Maybe this will introduce more noise in your understanding, but I have to say it. In modern use there are not one, but two non equivalent definitions of function in mathematics. They are very similar, but often you see books that state one definition and later prove theorems that are only true for the other definition. Both concepts are used in computer science too. $\endgroup$
    – plop
    Oct 9, 2020 at 16:50

4 Answers 4

4
$\begingroup$

A function in mathematics is just a special case for a binary relation, where for every x there is exactly one y such that xRy is in the binary relation.

Computer science uses that term with the same meaning, as it uses lots of mathematical terms. It also uses the term "function" (or "subroutine", "procedure", "method") with a totally different meaning of one component of a program in the area of computer programming.

Just like the word "function" would be used with a completely different meaning in patent law (functional vs. decorative components) architecture (a functional design), medicine or psychology (like a "functional alcoholic").

$\endgroup$
3
$\begingroup$

As others have noted, the answer is "yes", but it's often a qualified "yes". Sometimes we talk about sets and functions, but sometimes we talk about computable sets and computable functions.

There is a temptation to think of programming language types as sets of values (e.g. $\hbox{Bool}$ is the set of values $\left\{ \hbox{False}, \hbox{True} \right\}$), and programming language functions as functions between those sets, but this isn't correct.

Consider a function with this type:

$$f : X \rightarrow 2^X$$

In set theory, this function cannot be bijective, because Cantor's theorem states that there is no bijection between a set and its power set.

But with computable sets and computable functions, there's no such problem. In a programming language like Haskell, for example, I can write:

newtype X = X (X -> Bool)

And in doing so, I have constructed a type $X$ such that $X$ and $2^X$ are isomorphic.

$\endgroup$
1
$\begingroup$

I would be a lot more confident if you were asking about a specific usage, rather than in generaly--would you like to give an example?

That said no, they are the same. Further, theoretical computer science is arguably a field of mathematics, and certainly inherits a lot of culture and terminology from it. You can expect most terms to be the same.

However, do keep in mind:

  1. As you mention, sometimes when computer scientists say "function", they mean a function call or subprocedure. This should generally be clear in context.

  2. (Rare) If you are reading about computability, for example early in a class when the halting problem is introduced, "function" may be used as a (sloppy) abbreviation for "partial function". A "partial function" is like an ordinary (or "total") function, except that it is allowed to be undefined for some inputs. This corresponds to a deterministic computational process like a Turing machine--it either outputs something, or it may run forever.

$\endgroup$
-2
$\begingroup$

Function in computer science in simple words represents by braces( ) like in c++ we use predefine functions like main() etc but sometimes in ( java) we call this function as method also we have many predefined functions in java like substring(),indexOf() and many more but also you will remeber one think these languages also provides controls to declares your own function

Thanks bro for more reply me i have better command in java ,python and javascript to let me know in which language you want to know the concept of function i will try my best

$\endgroup$
1
  • $\begingroup$ This reads like function in program code. Programming isn't even on topic - concepts of programming languages, especially in general and in comparison, are. There is use of function beyond that, witness other answers. $\endgroup$
    – greybeard
    Oct 11, 2020 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.