Idea Square root of 2 for testing 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Project Step #2, deadline Wednesday 13 November (Mike O'Donnell)
Date: 2002, Nov 11
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

After class it sunk in how hard it will be to test with the natural implementation of rational numbers as constant xreal functions. You can cook up deliberately worse representations of rationals as xreals to make testing more interesting. But it will be more fun to have some genuine irrationals around. Here is the square root of 2 as an xreal in the precfunc implementation. It's pretty easy to generalize this into an arbitrary rational power of a positive rational.




Mike O'D.

((define (abs_tolerance_ratintvl->rational ri)

  (- (max_ratintvl->rational ri) (min_ratintvl->rational ri)))

define (sqrt_2 prec)

  (define (refine_sqrt_2 ri prec)

    (cond ((<= (abs_tolerance_ratintvl->rational ri) prec)
	   ri)

	  (else
	   (let ((midpoint (mid_ratintvl->rational ri)))

		(if (< (* midpoint midpoint) 2)

		    (refine_sqrt_2 (make_ratintvl midpoint
						  (max_ratintvl->rational ri))
				   prec)

		    (refine_sqrt_2 (make_ratintvl (min_ratintvl->rational ri)
						  midpoint)
				   prec))))))

  (refine_sqrt_2 (make_ratintvl 1 2) prec))


Messages

1. More Rational powers for test cases by Mike O'Donnell, 2002, Nov 11
2. Feedback spanning 0 by Katie Edmonds, 2002, Nov 13

to: "Square root of 2 for testing"