Are mathematical functions used in computer science? [closed]

Well, I know the difference between functions used in math and C language. But what are those specific areas where mathematical functions are used?

• What do you mean by "mathematical functions?" Are you asking specifically about "functions" as defined in real analysis? Are you asking about functions in general? Computer science is mathematics, but it borrows more from discrete math than it does from real analysis. May 3 '18 at 20:36
• Functions, like most elementary mathematical objects, are used in all sciences, and computer science is no exception. I'd say that in virtually all the areas of CS functions are used in some form.
– chi
May 3 '18 at 20:38
• P.S., Not sure that either the functional-programming tag or the generating-functions tag is appropriate, because this question does not appear to be about a programming technique. May 3 '18 at 20:40
• Closing as "too broad" as if obvious answer is "yes" (other than for C, which has no place in CS other in specialized curricula and maybe applied topics) but giving anything close to a complete list of uses would fill books.
– Raphael
May 4 '18 at 6:38
• I think it's brave and a little adorable that you call mathematical functions the "real world" functions. =)
– Raphael
May 4 '18 at 6:39

Strictly speaking, "functions" in computer science are actually the computable functions (i.e. the morphisms in the category of computable objects).

This is important, because Cantor's theorem states that there is no set $X$ such that there is a bijection between $X$ and its powerset. However, it is possible in many programming languages to define a type which has this property. For example, this type in Haskell:

newtype X = X (X -> Bool)

defines a type $X$ such that $X \cong 2^X$. This is not an isomorphism in the category of sets-with-functions, but it is an isomorphism in the category of computable sets-with-computable functions. Hence, it doesn't contradict Cantor's theorem.

In a comment, it seems like you're actually asking a numeric analysis question. Of course, we use elementary and special functions in scientific computing, engineering computing, computer graphics, etc. Anything that involves geometry, physics, simulation, statistics, etc involves the evaluation of elementary functions and special functions.

There is also a whole subfield of numeric analysis devoted to how to calculate functions of this kind. See, for example, all of the software that falls into GAMS Class C. Any introductory book on numeric analysis will have at least a chapter on this topic.

Just as a final note: For some special functions, it's sometimes not immediately obvious what convention to use, the most famous example of which is the gamma function. As an industry, we appear to have settled on the NIST Digital Library of Mathematical Functions (the companion and successor to the classic Abramowitz and Stegun) as the authoritative source.

• I don't think all functions in CS are computable, because we at times talk about uncomputable functions. Perhaps you mean that all functions used in algorithms or computer programs must be computable? May 4 '18 at 11:41
• That's a fair way of putting it. May 4 '18 at 11:43

You can write mathematical functions in computer science. The OCaml function id (x: int): int = x, for example, is a mathematical function $id : \mathbb{Z} \rightarrow \mathbb{Z}$, where $id = n \mapsto n$ (OK, if we ignore the fact that OCaml ints are machine integers and not bignums, just for a second.

However, not all programming functions are mathematical functions (i.e. many-to-one relations between two sets $S$ and $R$). Specifically, by this definition, a function is also a set; however, the "domain" of programming functions can contain the function itself. Consider, for example, the OCaml function id x = x, which has the type 'a -> 'a (or, mathematically, $\forall \alpha \ . \ \alpha$). Note that id can be applied to itself. This violate the Axiom of Regularity in Zermelo-Fraenkel set theory; however, id is a real mathematical construct that concretely exists. It's a thing that is not a mathematical function!

Instead, programming language researchers interpret functions either inside domain theory as functions in complete partial orders (cpo's) [note: in this approach they're interpreted a bit differently so that it doesn't violate the Axiom of Regularity anymore], or alternatively inside category theory as functors between categories (which I don't claim to fully understand). This approach of understanding computational constructs is called denotational semantics.