Idea Sketch of a design for cached precision functions 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Project step #5, deadline Monday 2 December (Mike O'Donnell)
Re: Question Questions and Thoughts (Mark Kittisopikul)
Date: 2002, Nov 29
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

I have not gone through a whole solution to this problem, so my design proposals are speculative. As you fill in the details, you might find that they need to be modified. But I'm pretty confident that they provide a good starting direction.

  • For the form of a cached function, Mark's idea of looking at the make_one_with_count procedure in my stream with counter for a model is good. The new-withdraw procedure on page 221 of the text, and the make-withdraw procedure on page 222 are also good models to look at. The difference between them appears to be essentially that my make_one_with_count uses define to introduce the local memory, new-withdraw uses let, and make-withdraw uses its parameter balance. I don't see any noticeable advantage to one method over the other. There are some cases where you want to introduce the the local storage but you don't need a parameter for any other reason, and in those cases you probably should use define or let. It's a good idea to experiment a bit with the basic technique to make sure that we've understood the storage operations correctly. For example, see what happens when the local variable name is coincidentally the same as a global variable name, to make sure that you really reliably made it local. But I'm pretty sure that both define and let provide new local storage in all cases.

  • You probably do not need the operation parameter that I used in make_one_with_count (the op parameter to the procedure created by make_one_with_count) and that the text used in make-account on page 223. I'm pretty sure that every invocation of an xreal procedure can do the same thing to its cache, so there is no need to distinguish different cache operations.

  • It's not clear yet whether you should define a general-purpose procedure make_cache_function to generate the basic structure of a function with a cache, and use make_cache_function in each procedure that returns an xreal (rational->xreal, add_xreal, mult_xreal, etc.). The alternative is to write the basic structure of a function with a cache into each one of the procedures that returns an xreal. This design choice should depend on how much code is the same across all definitions of xreal-returning procedures, and how easy it is to separate it from the rest of the definition.

  • I suggest that you don't worry about which sorts of xreals do and do not benefit from a cache, but just cache an interval for every xreal. I think that the uniformity will be more valuable that any difference. In effect, the constant functions produced by rational->xreal are a sort of cache that never changes. It's probably better to make them look a lot like the caches that do change.

  • I also suggest that you cache some interval at the moment that you create an xreal, rather than waiting for the first invocation of that xreal with a precision argument. This initial interval will look a lot like the initial balance in make-withdraw and new-withdraw. I think that it will usually be easy to come up with some sort of interval containing your real number. Choose one that's really easy to get, even if it's much larger than it could be. The creation of an interval when you create an xreal will probably save you from an annoying and wasteful test to see whether there is a cached interval.

  • I think that by following and refining these design ideas, you can come up with a fairly simple structure for each xreal. Every invocation of the xreal with a particular precision first checks whether the cached interval has enough precision, returns it if it does, otherwise calls an inner function that looks just like a regular old precfunc function and both caches and returns the result. You can probably abstract the basic structure of this code into a single apply_cached_function procedure that you can invoke within every xreal.




Mike O'D.


Messages

1. Feedback Response by Mark Kittisopikul, 2002, Nov 29
1. Feedback Initial interval happens only once, extra test happens for every invocation of xreal by Mike O'Donnell, 2002, Nov 29
1. Feedback performance hit? by Katie Edmonds, 2002, Dec 02
... 1 Message(s)
2. Feedback performance by Katie Edmonds, 2002, Dec 02
2. Feedback I'm considering code to create the cache and code to use it separately by Mike O'Donnell, 2002, Nov 29
1. Idea Combining them... by Benedict Singer, 2002, Nov 29
3. Feedback Cacheing (make_ratintvl r r) in (rational->xreal) makes sense to me by Mike O'Donnell, 2002, Nov 29
2. Question define vs let by Mark Kittisopikul, 2002, Nov 29
1. Feedback Internal define and let appear to be the same by Mike O'Donnell, 2002, Nov 29
3. Question Accessing the cache by Mark Kittisopikul, 2002, Nov 29
1. Agree A debugging command to return cache contents is a great idea by Mike O'Donnell, 2002, Nov 29
2. More Debugging thought... by Benedict Singer, 2002, Nov 29

to: "Sketch of a design for cached precision functions"