Total functions
Introduction / Definition
A total function gives a defined result for every input in its stated domain. Totality makes software behavior more predictable. A function may be partial if some inputs have no valid result. Domains or explicit error results can be used to handle problematic inputs.
Syntax / Structure / Formula
f : A → B means every a∈A has exactly one result f(a)∈B.
Detailed Explanation
Division is not total over all integer pairs because division by zero is undefined. Restricting the domain or returning an explicit error makes behavior well defined.
Example
Example: safeDivide(a,b) returns a result or an error when b=0.
Output / Result
Every allowed input has a defined outcome.
Important Points / Notes
- Define the domain clearly.
- Handle invalid inputs explicitly.
Mini Practice Question
Why is ordinary integer division partial if zero is allowed as divisor?