202212152212
Partial Functions
Note
A Partial Function is a function that has values on some arguments but not on all arguments The reason why a function would not return all values are :
- Error Termination: Evaluation of a function cannot proceed because of a conflict between the operator and an operand.
- Nontermination: Evaluation of a function proceeds indefinitely.
An example of the first case would be the expression
x:= 3 / 0
, because devision by0
is undefined. An example of the second scenario can be a functionf(x: int) := if x = 0 then 0 else x + f(x-2)
, this function does not terminate when3
is given as an argument.
A partial function is not a function as defined by the mathematical sense. A mathematical function is a set of ordered pair satisfying the following conditions:
- If and , then .
- For every , there exists a such that . But a partial function only follows the first condition.