calc: Rewrites Answer 5

 
 3.7.56 Rewrites Tutorial Exercise 5
 -----------------------------------
 
 If ‘x’ is the sum ‘a + b’, then ‘nterms(X)’ must be ‘nterms(A)’ plus
 ‘nterms(B)’.  If ‘x’ is not a sum, then ‘nterms(X)’ = 1.
 
      [ nterms(a + b) := nterms(a) + nterms(b),
        nterms(x)     := 1 ]
 
 Here we have taken advantage of the fact that earlier rules always match
 before later rules; ‘nterms(x)’ will only be tried if we already know
 that ‘x’ is not a sum.