Feedback In ((add_xreal xr1 xr2) p) compute precisions for xr1, xr2 from p 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Project Step #2, deadline Wednesday 13 November (Mike O'Donnell)
Re: None Proper use of variables in operations (Rich Lusk)
Date: 2002, Nov 12
From: Mike O'Donnell <odonnell@cs.uchicago.edu>


(((add_xreal (rational->xreal 2) (rational->xreal 3)) 2 4) 10)
If I understand this right, you're providing the 2 as a precision argument to (rational->xreal 2), the 4 to (rational->xreal 3), and the 10 to the result returned by add_xreal. That's definitely the wrong thing to do.
(add_xreal (rational->xreal 2) (rational->xreal 3))
should be a function taking one rational argument and returning a ratintvl. You've made it into a function taking two rational arguments, producing a function taking one rational argument, and returning a ratintvl. So
((add_xreal (rational->xreal 2) (rational->xreal 3)) 10)
should return a ratintvl of width at most 10 containing 5. (2 8) (representing the interval [2,8]) is an OK result. So is (0 10). But the most sensible result to get in this case is (5 5). The easiest way to implement rational->xreal is to return perfect precision no matter what the argument to the xreal asks for. You're always allowed to provide better precision than what was requested.

The general form of (add_xreal xr1 xr2) should be something like

(lambda (prec) ... (xr1 ...) ... (xr2 ...) ...)
The arguments for xr1 and xr2 can be computed very simply from the argument prec to (add_xreal xr1 xr2).

I suspect that the trivial nature of (rational->xreal r) is confusing you. Try some irrational numbers, constructed from the rational-power code that I posted. They will exercise the power of the xreal representation more thoroughly, so they might stimulate your insight better.




Mike O'D.


Messages

1. None Thanks by Rich Lusk, 2002, Nov 12

to: "In ((add_xreal xr1 xr2) p) compute precisions for xr1, xr2 from p"