Spring 2001, CSE 428: Additional notes about Assignment 5
Exercise 2
- Please represent the operators on simple expressions as the string containing
the conventional mathematical symbol. More precisely:
+ (plus) is represented by "+"
- (minus) is represented by "-"
* (product) is represented by "*"
/ (division) is represented by "/"
^ (exponentiation) is represented by "^"
- The last equation for differentiation, namely
D(u^n) = n*u^(n-1)*Du
is actually valid also for n=0 (originally the case 0 was excluded). So you
should not test that n is different from 0 when you define this case. However,
it is valid only when n is a number (not a function of x). This means that when
you define this case, you have to write a line like
| deriv (Opr("^",u,Num n), x) = ...
This will give you a "match nonexhaustive" warning, but that's ok. On the
contrary, allowing the third argument of Opr to be a generic expression, in this
definition, will be considered an error.
- Please try to follow closely the definition of the table
Dz = 0 if z is a number or a variable different from x
Dx = 1
D(u+v) = Du + Dv
D(u-v) = Du - Dv
D(u*v) = v*Du + u*Dv
D(u/v) = (v*Du - u*Dv) / (v^2)
D(u^n) = n*u^(n-1)*Du where n is a number
Namely, do not change the order in which the argument of an operator are
written, like for instance Dv*u instead of u*Dv. Although these expressions are
theoretically equivalent, they produce a different symbolic output, and it would
make the correction difficult for the TA.
- Please do not load any package in your code. You don't need any extra
operators for solving any of the exercises of this assignment. Loading a package
may redefine operators and mess up things when the TA tests other exercises. If
you really think you need to use some other operations, like those available in
the "Real" package, then you can use the name extension, like for instance
Real.rem (remainder on reals). However, once more, you can write the solutions
just by using those operators that are loaded authomatically when you start sml.
In fact, the only operator on reals you need to use is the minus, and that is
simply represented by the symbol -, which is overloaded (e.g. 5-1 is on int and
5.0-1.0 is on reals).
Exercise 3
You can assume that in (numbered n), the integer n ranges from 2 to 10. In other
words, the ordering is the following (in increasing order):
1 ace
2 numbered 2
3 numbered 3
4 numbered 4
5 numbered 5
6 numbered 6
7 numbered 7
8 numbered 8
9 numbered 9
10 numbered 10
11 jack
12 queen
13 king
you can assume that the function smaller is never applied to "non-cards", like
for instance (numbered 11)