Tensions in Practice: A real-number answer in tension with a wider input domain¶
A square-root operation in an algebra tool
A real-root operation accepts nonnegative real inputs and returns the nonnegative square root. It has no real answer for −4. Another operation accepts every real input by returning a selected complex root: 2 i for −4, where i is defined by i² = −1. Extending the input domain also changes the answer type and the arithmetic its caller must understand.
Keep answers real
Expose a restricted domain with ordinary nonnegative real roots.
Handle every real input
Use a declared complex branch for negative radicands.
Why these aims pull against each other
The broader operation does not find a previously overlooked real root. It changes the codomain, so a caller that requires a real quantity cannot simply consume the new answer.
Choose an arrangement to see what changes and what remains difficult.
i is the imaginary unit, with i² = −1. Outside domain is an explicit contract rejection, not zero, an empty collection or an unknown result after a timeout.
What this choice protects
What it costs
When it fits
Compare the arrangements
Offer real roots
Declare domain x≥0 and return the nonnegative real root. Negative inputs are rejected as outside the contract.
| Input | Answer | |
|---|---|---|
| Negative | −4 | Outside domain |
| Zero | 0 | 0 |
| Positive | 4 | 2 |
- What it protects
- Every admitted answer is real and nonnegative.
- What it costs
- The caller must route negative inputs elsewhere or report that this operation does not apply.
- When it fits
- Fits calculations where only real-valued roots are meaningful.
Illustration note: This map is total on its declared nonnegative domain; viewed as a rule on all reals it is partial. The rejection is explicit, not a fabricated numerical answer.
Select a complex branch
For nonnegative x return √x; for negative x return i√(−x). The same real input now always has one selected complex output.
| Input | Answer | |
|---|---|---|
| Negative | −4 | 2 i |
| Zero | 0 | 0 |
| Positive | 4 | 2 |
- What it protects
- Every real input is covered by an explicit single-valued rule.
- What it costs
- Callers must support complex values and cannot treat them as ordinary real lengths or counts.
- When it fits
- Fits an algebraic workflow in which complex roots are valid objects.
Illustration note: This is a declared branch, not the relation containing both roots. At 4 the answer is 2, not the pair ±2; at −4 it is 2 i, not both imaginary roots.
What this illustration does—and does not—establish
The source supplies the structural tension. This bounded example makes a particular relation inspectable; the aims, conditions and residual costs are part of the comparison.
- The finite examples are exact algebra, not numerical implementation tests.
- Selecting one complex root is a convention that makes the operation single-valued.
- A total tagged result such as answer-or-error is another API design; it does not manufacture a real square root of a negative number.
Source entries
Function (Mapping)
The canonical tension motivates this comparison. The setting and arrangements are declared editorial illustrations, not observed findings.
Totality vs Partiality
A total function handles every input in its declared domain; a partial function is undefined on some inputs. Totality gives guarantees at the cost of handling edge cases (division by zero, empty-input degenerate cases, out-of-range queries). Partiality is honest about limits at the cost of forcing the caller to handle undefined cases.
The source operation
A function is a rule that assigns to each element of one set (the domain) exactly one element of another set (the codomain)