SICP Exercise 2.95 non-integer operations in gcd

Exercise 2.95.  Define P1P2, and P3 to be the polynomials




Now define Q1 to be the product of P1 and P2 and Q2 to be the product of P1 and P3, and use greatest-common-divisor (exercise 2.94) to compute the GCD of Q1 and Q2. Note that the answer is not the same as P1. This example introduces noninteger operations into the computation, causing difficulties with the GCD algorithm.61 To understand what is happening, try tracing gcd-terms while computing the GCD or try performing the division by hand.

SOLUTION

See here:

SICP Exercise 2.95

You can see from the result that the gcd algorithm is not working properly. The result is just a number which is clearly wrong.

The 'print-poly' procedure came in very handy here. I could print the various stages of polynomials in a readable format.

Comments

Popular posts from this blog

SICP Exercise 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions