# SICP Solutions

### Section - 2.4 Multiple Representations for Abstract Data

#### Exercise 2.73

(a)

Like the complex number example, expression is considered to be of multiple types depending on the operator.

Thus operator serves as tag for differentiating different implementations of expression.

Each expression has an operator and operands.

Each expression can be differentiated wrt a variable.

The implementation of derivative procedure of an expression is based on the type of expression.

Each derivative procedure is assumed to be stored in table corresponding to the operator.

The generic derivative of an expression is implemented by looking up procedure from the table, using operator and invoking it using operands. Or in other words data directed dispatch.

Notice that number and variable can be considered as expression but both have no operators. Thus we cant differentiate between the two using operator. Thus we need a separate way to deal with them, which in this case we are using predicates number? and variable? and same-variable? to deal with them instead of fitting them with the generic way of lookup in table and invoke.

(b)

(c)

I am combining parts(b) and (c).

Here is the complete code including all helper functions:

Test/Output:

(d)

We only need to change the order of arguments while invoking put.