6

I am confused about something. I wanted to generate an example (in Clojure) demonstrating how a fixed point combinator could be used to evaluate the fixed point of a sequence that mathematically converges after an infinite number of applications but would, in fact, converge after a finite number of steps due to finite precision of floating points. I am apparently missing something here.

(defn Y [r]
  ((fn [f] (f f))
   (fn [f]
     (r (fn [x] ((f f) x))))))

(defn simple-convergent [func]
  (fn [x]
    (if (zero? x)
      0.0
      (* 0.5 (func x)))))

I can then get

user=> ((Y simple-convergent) 0.)
0.0
user=> ((Y simple-convergent) 0.2)
java.lang.StackOverflowError (NO_SOURCE_FILE:0)

I don't understand this stack overflow. More generally, related to my earlier post, I am wondering if someone can present a "correct" version of a fixed point combinator which can be used to approximate fixed points of sequences in this fashion.

1
  • 4
    Should the last line perhaps be (func (* 0.5 x))? It looks like it's recurring with the same x forever. Commented Jul 13, 2010 at 23:30

1 Answer 1

3

Thanks to Brian Carper for his (correct) answer as a comment. The corrected code

(defn simple-convergent [func]
  (fn [x]
    (if (zero? x)
      0.0
      (func (* 0.5 x)))))

behaves as I expected. My next project is to try to build a fixed point combinator which find unstable fixed points. I don't believe the Y combinator implemented above can do this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.