You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
1.1 KiB
22 lines
1.1 KiB
|
|
Exercise 2.58: Suppose we want to modify the
|
|
differentiation program so that it works with ordinary mathematical notation,
|
|
in which + and * are infix rather than prefix operators. Since
|
|
the differentiation program is defined in terms of abstract data, we can modify
|
|
it to work with different representations of expressions solely by changing the
|
|
predicates, selectors, and constructors that define the representation of the
|
|
algebraic expressions on which the differentiator is to operate.
|
|
|
|
|
|
Show how to do this in order to differentiate algebraic expressions presented
|
|
in infix form, such as (x + (3 * (x + (y + 2)))). To simplify the task,
|
|
assume that + and * always take two arguments and that
|
|
expressions are fully parenthesized.
|
|
|
|
The problem becomes substantially harder if we allow standard algebraic
|
|
notation, such as (x + 3 * (x + y + 2)), which drops unnecessary
|
|
parentheses and assumes that multiplication is done before addition. Can you
|
|
design appropriate predicates, selectors, and constructors for this notation
|
|
such that our derivative program still works?
|
|
|
|
|
|
|