Should Julia guarantee semi-monotonic where appropriate (or even monotonic) math? Such as trancendentals

I think the main place that would want it is interval arithmetic

Let me present a counter-solution: make nextfloat(x) > x return probably.

Jokes aside, I recommend to not equate floating point numbers to concrete numbers just because they are stored and (quite terribly) named as such. They are rather representations of intervals of possible values, where the length of the interval depends on context.

While enursing monotonicity for some simpler edge cases would still be numerically expensive, trying to translate other mathematical properties, as has already been pointed out, will necessarily fail. To add more, fhe function sin can not have a single critical point (per interval). The value 0.0 is in the range of x->1/x. The function x->sqrt(x) has fixedpoints other than 0.0.

If anything, this shows that AI will elaborate anything into a nail once you have given it a hammer.

(The hammer was LEAN certification in case that wasn´t clear).

No, this is a common fallacy. Floating-point arithmetic ≠ interval arithmetic. A floating point number is simply a rational number, no more, no less. As Kahan once wrote:

Many a textbook asserts that a floating-point number represents the set of all numbers that differ from it by no more than a fraction of the difference between it and its neighbors with the same floating-point format. This figment of the author’s imagination may influence programmers who read it but cannot otherwise affect computers that do not read minds. A number can represent only itself, and does that perfectly.

Floating-point numbers 𝔽 are “just” a subset of the rationals ℚ. Crucially, the rules of arithmetic on floating-point numbers are based on their interpretation as numbers, not as “intervals”: elementary “exactly rounded” operations like ±, ×, ÷ simply round the exact result to the closest value in 𝔽. (As Kahan says, even if you imagine an interval, that’s not what the computer is actually doing.) For example, since integers (up to 2^{53}) are in 𝔽 (for Float64), integer values and integer arithmetic are exact in floating-point (until results exceed 2^{53}, at which point the errors increase gradually, unlike the catastrophic overflow that occurs with Int). e.g. 1.0 + 1.0 is exactly the correct answer 2.0, not 2.0 ± ε.

(Interval arithmetic is completely different and cannot be represented by individual floating-point numbers, because the error bounds grow as you do consecutive operations.)

PS. Perhaps the source of the confusion is the mapping f = \operatorname{fl}(x) from \mathbb{R} \mapsto \mathbb{F}, converting a real number x \in \mathbb{R} to the closest value f \in \mathbb{F}. People’s initial experience with floating-point arithmetic focuses heavily on the initial rounding that can occur when you attempt to input a real number (particularly decimal values like 0.1 and 0.2). I see many discussions of floating point online that begin and end with this initial conversion, when in actual practice it is much more important to understand how errors can accumulate in the course of many arithmetic operations. If you only think about the initial mapping, it may seem natural to identify each floating-point number f \in \mathbb{F} with its pre-image \operatorname{fl}^{-1}[\{f\}] \subset \mathbb{R}, the set of real numbers that round to it. But this way lies madness when you start to think about arithmetic on floating-point values. For arithmetic, it is much clearer to simply identify floating-point numbers with rational numbers, i.e. \mathbb{F} \subset \mathbb{Q} \subset \mathbb{R}, at which point an elementary floating-point operation \odot can be defined in terms of its exact real-number counterpart \cdot by f_1 \odot f_2 = \operatorname{fl}(f_1 \cdot f_2) (i.e., you do the exact operation and round the result).

PPS. For more complicated operations like \tanh or worse, of course, it is not generally practical to guarantee exact rounding. (Even just summing n numbers \sum_{i=1}^n f_i with an exactly rounded result requires arbitrary intermediate precision, as implemented by packages like Xsum.jl.) Merely preserving (weak) monotonicity is tricky for functions that are complicated enough, but I agree that it is probably a reasonable and worthwhile goal to pursue for some elementary library functions like \tanh and \exp. We certainly can’t guarantee it universally at a language level, however, because it is heavily dependent on precisely how such functions are implemented.

While I somewhat appreciate the length and thus probably time spent with the answer, I strongly have to disagree. And I do not appreciate that much of what you mentioned was never claimed or implied in the first place.

There is a difference between implementation and numerical interpretation I thought I made clear.

Certainly, floating point numbers are just stored as single numbers, but this is where the similarities soon end. I strongly advise to not state something as weak as an implied subset relation like \mathbb{F} \subset \mathbb{Q} as an argument in the given context (if you meant the mathematical, rational numbers).

Yes, you can map every single floating point number to an ordinary rational number, basically with the identity depending on how one constructs both, which can technically make it a subset. And yes, multiplication is conveniently defined via rounding and ordinary multiplication (apart from that sources not necessarily agree on what this rounding actually should do or if it should even be deterministic).

But \mathbb{F} lacks any more advanced structure of \mathbb{Q} (being a group, or a field, or infinite, or dense). The embedding is not a homomorphism in any sense.

So while this is taught rather for ease of the presenter to new students in numerics, it is ultimately counterproductive didactically. With width of interval given by context I never claimed to mean the range numbers are rounded to it. Instead, the context comes from initial accuracy, and the increased or decreased accuracy through repeated applications of functions, roughly by their condition numbers.

Once you strip away the numerical interpretation, which is essentialy a single implemented number but a mathematically given context of accuracy, then instead of monotonicity, you could as well ask if solving a linear system in Julia should always be stable. You can not argue away fundamental numerical limitations, or the cost to overcome such, because some mathematical property is wishful and seemingly easy to define.

While that is one way people sometimes think of floating point numbers, it is directly contrary to how IEEE chooses to define elementary function on them. Under your definition (which is arguably more sensible) sin would return NaN for any inputs where it catastrophically loses precision (e.g. |x| > 2^23 for Float32). Instead, ieee defines elementary functions as returning the nearest rounded result to the function computed in infinite precision on the input as defined by injection into the reals.

In any case, I think how humans perceive floating-point numbers is off-topic.
As mentioned above, (semi-)monotonicity is a property related to differentiation, but I don’t think anyone expects tanh(::Float32) to be defined as a step function.