SICP Exercise 2.95 non-integer operations in gcd
Exercise 2.95. Define P1, P2, 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.
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
Post a Comment