SICP Exercise 1.19 PQ transformation

Viewed 19

T(p,q) transforms the pair (a,b) according to a <-- bq + aq + ap and b <-- bp + aq.

Can someone explain how this transformation works?

1 Answers

Just as you wrote,

             T(p,q) 
 (a,      ----------->     ( bq + aq + ap ,
  b)                          bp + aq     )

In pseudocode,

T(p,q)(a,b) = ( b*q + a*q + a*p , b*p + a*q )

The transformation T(p,q), given a pair (a,b), calculates two new values,

  a2 = b*q + a*q + a*p   , and
  b2 = b*p + a*q 

and then constructs a pair, (a2,b2), and returns it as the result.

Related