More I added tristream solutions 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Project step #4, deadline Monday 25 November (Mike O'Donnell)
Re: News Let's share implementations in the testing step (Mike O'Donnell)
Date: 2002, Nov 20
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

I just posted some definitions for tristream procedures on the solutions page.

I inspected and tested these definitions very rudimentarily. In particular, I'm not completely sure that I reduced the factors in a multiplication far enough before applying mult_xreal_lt_one.

The last error that I found was somewhat interesting. Look at the mult_power_3_xreal procedure that I define locally in mult_xreal:


(define (mult_power_3_xreal xr n)

    (define (mult_power_3_trit_fby_expansion trit xr_suffix n)

      (cond ((> n 0) (mult_power_3_trit_fby_expansion
		      (+ (* 3 trit) (stream-car xr_suffix))
		      (stream-cdr xr_suffix)
		      (- n 1)))

	    ((< n 0) (mult_power_3_trit_fby_expansion
		      (quotient trit 3)
		      (cons-stream (remainder trit 3) xr_suffix)
		      (+ n 1)))
	    
	    (else    (cons-stream trit xr_suffix))))

    (mult_power_3_trit_fby_expansion
     (stream-car xr)
     (stream-cdr xr)
     n))
Because of the redundancy of the base-3 notation with trits from -2 to 2, there are several variations that are all mathematically correct. I initially used the variation with integer-floor and modulo, instead of quotient and remainder. These pairs differ only in their treatments of negative numbers (see the MIT Scheme Reference Manual). They are both mathematically correct for the purpose. But, with an integer part of -1, the (integer-floor, modulo) pair never reduces the integer part to 0, no matter how large a negative power of 3 is given. The (quotient, remainder) pair always reduces the integer part to 0 for a sufficiently large negative power of 3. So, my first version led to an infinite computation when used in reduce_by_power_3_xreal, while the second version at least misses that particular error. This is the first example that I've encountered where the (quotient, remainder) pair has useful mathematical properties for the solution of a problem. In the past, I have always seen it used for mere compatibility with quirky qualities of C, Pascal, and other old programming languages.




Mike O'D.


Messages

1. Question problem in tristream by Katie Edmonds, 2002, Nov 21
(_ Feedback Compressing a prefix is the right approach by Mike O'Donnell, 2002, Nov 21

to: "I added tristream solutions"