In Coursera course Functional Programming Principles in Scala
, the Lecturer talks about the Fixed Point
and wrote some simple implementation of it.
def isCloseEnough(x: Double, y: Double) =
math.abs((x - y) / x) / x < tolerance
def fixedPoint(f: Double => Double)(guess: Double) = {
def iterate(guess: Double): Double = {
val next = f(guess)
if (isCloseEnough(guess, next)) next
else iterate(next)
}
iterate(guess)
}
Such implementation will allow the following function f(x) = 1 + x
to have a Fixed Point.
However this should not never happen. As in this function graph:
And this is what stated by Wikipedai:
Not all functions have fixed points: for example, if f is a function defined on the real numbers as f(x) = x + 1, then it has no fixed points, since x is never equal to x + 1 for any real number.
The point here is in the isCloseEnough
that I couldn't why it is written that way.
I am here to understand the isCloseEnough
and why it was implemented that way
That is All.