Distinction between partial and total computable functions, undefined values, domains of definition, and the role of nontermination.
A computable process may fail to produce an output for some inputs, not because the input is malformed, but because the process never halts. This distinction leads to two kinds of functions: total functions, which are defined on every input, and partial functions, which may be undefined on some inputs.
In computability theory, partial functions are essential because algorithms are allowed to run forever. A computation that never halts produces no output, and this behavior must be represented mathematically.
Total Functions
A total function from to assigns an output to every possible input.
Definition 10.28 (Total Function)
An ary total function is a function:
such that for every input:
there exists a value:
Thus a total function is defined everywhere on its domain.
Example 10.29
The addition function:
is total, because every pair of natural numbers has a sum.
The multiplication function:
is total, because every pair of natural numbers has a product.
The successor function:
is total, because every natural number has a successor.
Partial Functions
A partial function may be undefined for some inputs. We write:
to indicate that is a partial function.
The arrow means that not every input is required to have an output.
Definition 10.30 (Partial Function)
An ary partial function from to is a rule that assigns a value:
to some inputs:
and assigns no value to the remaining inputs.
The set of inputs on which is defined is called the domain of definition of and is denoted:
Thus:
If an input is not in , then is undefined on that input.
Example 10.31
Define:
This partial function is defined exactly on even natural numbers.
Its domain is:
For example:
but:
is undefined.
Undefined Values and Nontermination
In computability theory, an undefined value usually represents nontermination.
If an algorithm computes a partial function , then:
means that the algorithm halts on input and outputs .
By contrast:
means that the algorithm does not halt on input .
This interpretation is important. A partial function does not return a special error value. It returns no value at all.
Notation for Definedness
We write:
to mean that is defined.
We write:
to mean that is undefined.
For an ary function:
means that the computation halts with an output, while:
means that the computation does not halt.
Definition 10.32 (Equality of Partial Functions)
Let:
be partial functions. We say that and are equal if they have the same domain of definition and agree on every input in that domain.
Equivalently:
if and only if for every input :
if , then and ,
and if , then and .
This definition is stricter than merely saying that the functions agree where both are defined, because equality also requires the same undefined inputs.
Example 10.33
Let:
and:
for every .
Then and agree at , but they are not equal as partial functions because:
while:
Computable Partial Functions
A partial function is computable if there is an algorithm that produces the correct output whenever the function is defined and runs forever whenever the function is undefined.
Definition 10.34 (Partial Computable Function)
A partial function:
is partial computable if there exists an algorithm such that, for every input :
if , then the algorithm halts on input and outputs ,
and if is undefined, then the algorithm does not halt on input .
In recursive function theory, these are the partial recursive functions.
Total Computable Functions
A total computable function is a computable function that halts on every input.
Definition 10.35 (Total Computable Function)
A function:
is total computable if there exists an algorithm that, for every input:
halts and outputs:
In recursive function theory, these are also called total recursive functions or general recursive functions.
Lemma 10.36
Every total computable function is a partial computable function.
Proof
Let:
be total computable. By definition, there is an algorithm that halts on every input and outputs .
Since a total function is defined on all inputs, it may also be regarded as a partial function whose domain of definition is all of .
The same algorithm witnesses that is partial computable, because for every input on which is defined, which is every input, the algorithm halts and returns the correct value. There are no undefined inputs to check.
Thus every total computable function is partial computable.
Lemma 10.37
Not every partial computable function is total.
Proof
Consider the partial function:
This function is partial computable. An algorithm computing it proceeds as follows: on input , check whether . If , halt and output . If , enter an infinite loop.
The algorithm correctly halts and outputs when , and it does not halt when .
However, is not total, because is undefined.
Therefore some partial computable functions are not total.
Domains of Partial Computable Functions
The domain of a partial computable function is the set of inputs on which the corresponding computation halts.
If:
is partial computable, then:
is the set:
Such sets are called recursively enumerable or computably enumerable. They are exactly the sets whose members can be recognized by a computation that halts on members and may run forever on nonmembers.
Definition 10.38 (Semidecision)
A set:
is semidecidable if there is an algorithm such that:
if , then the algorithm halts on input ,
and if , then the algorithm does not halt on input .
A semidecision procedure confirms membership but may never confirm nonmembership.
Example 10.39
Let be the set:
This set is decidable, hence semidecidable, because there is an algorithm that checks whether is divisible by and halts in all cases.
A more interesting semidecidable set arises from a search problem. Suppose:
where is decidable.
Then is semidecidable. On input , search through:
and check whether holds. If a witness is found, halt. If no witness exists, the search continues forever.
Definition 10.40 (Decision)
A set:
is decidable if there is an algorithm that halts on every input and correctly determines whether:
Equivalently, the characteristic function:
is total computable.
Lemma 10.41
Every decidable set is semidecidable.
Proof
Let be decidable. Then there is an algorithm that halts on every input and determines whether .
To semidecide , run this decision algorithm. If it says that , halt. If it says that , enter an infinite loop.
This new algorithm halts exactly on the members of , so is semidecidable.
Lemma 10.42
A set is decidable if and only if both and its complement:
are semidecidable.
Proof
First suppose that is decidable. Then is semidecidable by Lemma 10.41. Its complement is also decidable, because the decision procedure for can be used and the answer can be reversed. Therefore the complement is semidecidable.
Conversely, suppose that both and are semidecidable. Let be a semidecision procedure for , and let be a semidecision procedure for .
On input , run and in parallel. This can be done by alternating one computation step of with one computation step of .
Since every natural number either belongs to or belongs to its complement, one of these two procedures must eventually halt. If halts first, accept that . If halts first, reject and conclude that .
Thus there is a halting decision procedure for , so is decidable.
Partiality from Minimization
The minimization operator naturally produces partial functions because the required witness may fail to exist.
Suppose:
is a total computable function, and define:
Then is defined exactly when there exists some such that:
If such a exists, the computation searches:
until it finds the least witness. If no such exists, the search continues forever.
Example 10.43
Let:
Then:
returns the least square root of when is a perfect square, and is undefined when is not a perfect square.
For example:
but:
Total Extensions
A partial function may sometimes be extended to a total function by assigning arbitrary values to the inputs where it is undefined, but such an extension may lose the computational meaning of the original function.
Definition 10.44 (Total Extension)
Let:
be a partial function. A total function:
is a total extension of if:
for every:
The values of outside are not constrained.
Example 10.45
Let:
One total extension is:
This total function agrees with wherever is defined.
Lemma 10.46
A partial computable function need not have a computable total extension.
Proof
Let be a semidecidable set that is not decidable, such as the halting set introduced later in the chapter. Since is semidecidable, there is a partial computable function such that:
if:
and:
if:
Suppose had a computable total extension . Since extends , we would have:
for every .
This alone does not necessarily decide , because may also equal outside . To obtain a sharper example, define a partial computable function:
with domain all of would already be a total decision function, which cannot exist when is undecidable.
Therefore the general claim must be stated carefully: some partial computable functions have computable total extensions, while others cannot be extended computably in a way that preserves additional intended information about undefinedness. Undefinedness itself is not a value that a total computable extension can record directly.
Computation Traces
A useful way to understand partiality is to view a computation as a sequence of finite stages.
At each stage, the computation has produced only finite information. If the computation eventually reaches a halting state, it produces an output. If it never reaches such a state, no output is produced.
Thus:
means that there exists a finite computation trace ending in an output.
And:
means that no finite halting trace exists.
This finite trace viewpoint is central in later proofs about the halting problem and recursively enumerable sets.
Totality as a Global Property
For a partial computable function:
the statement that is total means:
This is a global property of the computation. It requires knowing that every possible input eventually halts.
In many cases, verifying totality is difficult or impossible by algorithmic means. This fact is one of the main sources of undecidability phenomena in computability theory.