# Machine error in computer arithmetic

I'm wondering if if is possible to have a function $f$ such that there exists $x,y$ such that we have $f_t(x) > f_t(y)$ where $f_t$ denotes the true value of $f$ and $f_a(x)<f_a(y)$ where $f_a$ denotes the value of f as stored in a computer? (I am referring to floating point numbers and numerical analysis)

I am looking at programs that solve equations and so am concerned about if my programs will work in extreme cases. Things like if I have a function that is extremely close to $0$ in an absolute sense over the interval and I want to find the root. (In this case I think I can make an argument that if $f_t(x) \geq 0$, then we must have that $f_a(x) \geq 0$.) But if I'm looking for a maximum of a function that is almost constant, say $g$, then I don't think I know that $g_t(x) > g_t(y)$ implies that $g_a(x) > g_a(y)$. Is this correct?

Any other resources on this matter would be greatly appreciated.

• What do you mean by "the value of f as stored in the computer"? A mathematical function is a mathematical construct that has a value. You can write program code. The code might either implement the mathematical function correctly or might do so incorrectly. If the code is incorrect, of course its result might be totally anything, and of course we can have such a situation. I don't really know how to interpret your question in a way that makes it not entirely trivial. Can you edit your question to clarify? Perhaps it would help to add some context/motivation, too. – D.W. Dec 12 '17 at 2:41
• Or are you perhaps asking about floating point numbers, numerical instability, overflow/underflow/roundoff error, etc.? If so, there's an entire field, called numerical analysis (see also this). I suggest doing some background reading about that subject, then seeing if you can formulate a more specific question. – D.W. Dec 12 '17 at 2:42
• Your second comment is correct - I am referring to floating point numbers. In terms of specificity of my question, it is 2 yes/no parts, I'm not sure how I can make it more specific? I am trying to get at a general point floating point calculations and so don't want to make the question overly-specific. – KingJ Dec 12 '17 at 2:58
• I think you're confusing/conflating "mathematical function" with "code" (e.g., procedure, function, program). Try rewriting your question to use those terms, and specify what relationship you want $f_t$ to have to $f_a$. I think you'll discover that your question is ill-specified. Right now you don't place any restrictions on $f_t$/$f_a$ so they might be unrelated. I also think you'll find that the field of numerical analysis is all about how analyzing code that is intended to approximately compute a mathematical function to determine how much error it might have. – D.W. Dec 12 '17 at 3:03
• I think $f_t$ is well-specified as it is just a general function. In terms of using $f_a$, I just want it to be any (although I am assuming valid/correct - I am not making any assumptions as to it being the best implementation) implementation of the function into a program. And so I am asking if it is possible for the Boolean value of $f(x)>f(y)$ to be different depending on if we look at the true values or the computational values. – KingJ Dec 12 '17 at 3:36

## 1 Answer

Yes! Various languages and APIs often specify the precision you are guaranteed. If the underlying hardware doesn't offer that precision, they must emulate it with extra work. For instance, some machine instructions that compute transcendental function (sin, cos, exp, log, ...) only offer a limited accuracy. Library implementations that guarantee a certain accuracy must execute extra instructions to accomplish that by correcting the error and improving the approximation.

As a concrete example, consider the native_sin function in OpenCL. The error is "implementation defined." On the other hand, the regular sin function promises a certain accuracy and implementation of OpenCL must make that happen regardless of the extra work.