7

In the book Computability, Complexity, and Languages (2nd edition), Martin Davis writes in chapter 1 (Preliminaries), section 2 (Functions):

A partial function on a set $S$ is simply a function whose domain is a subset of $S$. An example of a partial function on $\mathbb{N}$ is given by $g(n) = \sqrt n$, where the domain of $g$ is the set of perfect squares.

So far so simple. But he goes ahead and writes a couple lines later at the end of the section:

We will sometimes refer to the idea of closure. If $S$ is a set and $f$ is a partial function on $S$, then $S$ is closed under $f$ if the range of $f$ is a subset of $S$. For example, $\mathbb{N}$ is closed under $f(n) = n^2$, but is not closed under $h(n) = \sqrt n$ (where $h$ is a total function on $\mathbb{N}$).

So in the first quote $\sqrt n$ on $\mathbb{N}$ is an example for a partial function, whereas in the second quote the same function is an example for a total function.

Both examples seem to contradict each other. Or am I missing something in regard to closures here?

  • 1
    This is pedagogically a bad example of a partial function, because the domain is restricted only by arbitrary definition. A better example of a partial function is f(x) = 1/x, which is undefined when x = 0. – Wildcard Sep 09 '16 at 03:06
  • 1
    @Wildcard: How is this arbitrary? $\mathbb{N}$ is not an odd choice for the range of $g(n)$.. – MSalters Sep 09 '16 at 08:01
  • @MSalters, nethertheless it's a choice as in arbitrary. – Good Night Nerd Pride Sep 09 '16 at 08:06
  • 1
    @GoodNightNerdPride: If you use that logic, $1/x$ is not a better example, because there are ranges (e.g. projectively extended real line) in which that too is defined. – MSalters Sep 09 '16 at 08:13
  • @Wildcard It's not arbitrary at all. $g$ defined as a function from $\mathbb{N}$ to $\mathbb{N}$, which is a completely natural object. The function is undefined in certain places because, e.g., there is no natural number $y$ such that $y^2=2$. That's just the same as your example: it's very natural to have a function from $\mathbb{R}$ to $\mathbb{R}$, and the function you've chosen is undefined in some places because, e.g., there's no real number $y$ such that $y\cdot0=1$. – David Richerby Sep 09 '16 at 08:59

2 Answers2

12

There's no contradiction, here. The first case defines the partial function $g\colon \mathbb{N}\to\mathbb{N}$ given by $$g(n) = \begin{cases} x &\text{if $x\in\mathbb{N}$ and }x^2=n\\ \text{undefined} &\text{if no such $x$ exists.} \end{cases}$$ As the text says, "the domain of $g$ is the set of perfect squares."

The second case defines the total function $h\colon\mathbb{N}\to\mathbb{R}$ given by $$h(n) = x \quad \text{if }x\in\mathbb{R}_{\geq 0} \text{ and } x^2=n\,.$$ The domain of $h$ is the set of all the natural numbers.

You say that these are the same function, but they are not. $g(2)$ is undefined but $h(2)$ is defined (and equal to $\sqrt{2}$). $h$ associates a square root with every natural number but $g$ only associates square roots with natural numbers that are perfect squares.

$\mathbb{N}$ is closed under $g$ because, whenever $g$ is defined, $g(n)\in\mathbb{N}$. $\mathbb{N}$ is not closed under $h$ because, for example, $2\in\mathbb{N}$ but $h(2)\notin\mathbb{N}$.

David Richerby
  • 81,689
  • 26
  • 141
  • 235
  • +1, though I think the book is in error when it uses "$f$ is a partial function on $S$" to mean "$f$ is a partial function from $S$ to some set". – ruakh Sep 09 '16 at 20:23
  • @ruakh What's wrong with that? – David Richerby Sep 09 '16 at 20:32
  • In my experience, unless you explicitly add a modifier like "real-valued" (so that the codomain is clear), a function on a set is a function from that set to itself (analogously to how a relation on a set is a relation from that set to itself). But maybe that's not an error, and is just a different terminological tradition? – ruakh Sep 09 '16 at 22:34
6

In the second example, $h(n)$ is defined for all natural numbers $n$; when $n$ is not a square, $h(n)$ is some irrational quantity, and in particular not a natural number.

In other words, the set of natural numbers is not closed under taking square roots: for example, $\sqrt{2}$ is not a natural number.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • Sorry, I think I wasn't clear enough. Please see the 2nd to last paragraph I added to my question. – Good Night Nerd Pride Sep 08 '16 at 21:10
  • 4
    @GoodNightNerdPride I think Yuval is exactly right. In the first example, the square root function is a partial function from $\mathbb{N}$ to $\mathbb{N}$; in the second example, it's a total function from $\mathbb{N}$ to $\mathbb{R}$. – David Richerby Sep 08 '16 at 21:23