In this Homework, we continue our definition of vector spaces in ML:
if
by using pattern matching. This means that scale, add
and dot need new definitions. (The function magn
doesn't need to be changed since it is defined without if
anyway.) When you do this, you will need a few explicit type
qualifications to ensure that the functions operate on vectors, rather
than integer lists.
project,
projectAll and inSpan (see below).
vector2.sml.
Mathematically we write a vector using a boldface lowercase letter:
Then we can define our existing operations:
Our new operations are defined as follows:
val FUDGE = 0.000001;
- val w1:vector = [1.0]; val w1 = [1.0] : vector - val w2:vector = [0.0,1.0,1.0]; val w2 = [0.0,1.0,1.0] : vector - val w3:vector = [0.0,0.0,0.0,2.0]; val w3 = [0.0,0.0,0.0,2.0] : vector - val S = [w1,w2,w3]; val S = [[1.0],[0.0,1.0,1.0],[0.0,0.0,0.0,2.0]] : vector list - projectAll(S,[1.0,2.0,3.0,4.0]); val it = [1.0,2.5,2.5,4.0] : real list - inSpan(S,[1.0,2.0,3.0,4.0]); val it = false : bool - projectAll(S,[1.0,2.0,2.0,3.0]); val it = [1.0,2.0,2.0,3.0] : real list - inSpan(S,[1.0,2.0,2.0,3.0]); val it = true : bool
Do Exercises 3 and 4 of Chapter 8 (page 131).
Leave vector2.sml in your AFS folder. Turn in the book exercises
on paper at the beginning of lecture.