CS 3304
Programming Assignment 1
Given: July 11, 1997 Due: July 25, 1997
This assignment is worth 100 points. The assignment is due on Friday, July 25, at 5:00 PM. NO LATE PROGRAMS WILL BE ACCEPTED.
You are to implement in Scheme a data type for matrices and some operations as Scheme procedures. A matrix is a 2-dimensional arrangement of elements. For example,
is a matrix of integers whose dimensions are 2 by 4. In Scheme, you are to represent a matrix as a list of rows, where each row is also a list. So M would be represented
( ( 3 4 57 -2 ) ( 2 8 -9 0 ) )as a Scheme matrix. The elements of a Scheme matrix may be any Scheme values, not just numbers. The dimensions of a matrix must both be positive integers.
To support the matrix data type, you are to implement these Scheme procedures.
There are two predicates to implement.
matrix? takes one argument
and returns #t if that argument is a matrix
and returns () otherwise.
matrix-of-numbers? takes one argument
and returns #t if that argument is a matrix, all of whose entries
are numbers,
and returns () otherwise.
There are 4 functions to implement.
(dimensions mat)should return the dimensions of
mat as a 2-element list,
if mat is a matrix;
it returns () otherwise.
(transpose mat)should return the matrix transpose of
mat
if mat is a matrix;
it returns () otherwise.
Hence,
(transpose '((1 2 3) (cat dog horse) (-3 -2 -1) (0 0 0)) )returns
((1 cat -3 0) (2 dog -2 0) (3 horse -1 0))
(matrix-add mat1 mat2)should return the sum of
mat1 and mat2
if they are matrices
of the same dimensions
whose elements are numbers;
it returns () otherwise.
Hence,
(matrix-add '((1 2) (3 4) (5 6)) '((7 8) (9 10) (11 12)) )returns
((8 10) (12 14) (16 18))
(matrix-times mat1 mat2)should return the product of
mat1 and mat2
if they are matrices
of compatible dimensions
whose elements are numbers;
it returns () otherwise.
Hence,
(matrix-times '((1 2) (3 4)) '((-1 0 1) (2 3 4)) )returns
((3 6 9) (5 12 19))
You may want to define additional procedures to help you implement the required procedures. Scheme procedures that you will probably want to use include
Your procedures must be implemented in a functional programming style.
Hence,
you should use recursion rather than iteration;
the do construction is not allowed.
You should also avoid assignment operations;
hence set! setcar! and setcdr! are not allowed.
You will find that Scheme vectors will not be useful
to you without the assignment operation vector-set!.
Hence vectors are not allowed.
Your implementation is to be organized in a file named matrix.lisp.
The header at the beginning of the file should identify the assignment
and should give your name.
Every Scheme procedure should be preceded by comments explaining
its purpose, calling sequence, and implementation.
You should develop a set of test cases for your procedures
that test both positive and negative cases for each procedure.
Put these in a file named matrix.test.
Capture all the results of your tests running under the Scheme interpreter
in a file matrix.trace.
Email the three files matrix.lisp, matrix.test,
and matrix.trace to
ohiuddin@csgrad.cs.vt.eduwith a carbon copy to
cs3304sm@ei.cs.vt.eduIdeally, the files will be attached to a single email message. Alternately, they may be mailed in three separate email messages. In the subject line, include the phrase
CS 3304 First Programming Assignment
Programs will be evaluated on programming style (20% for documentation and prettyprinting) and on successful execution (80%). Execution will be tested using a suite of test cases that the GTA will develop. Some of these test cases will be more elaborate than the examples given in this assignment. A portion of this test suite will be posted on the course web pages on July 23 to help you with final testing of your procedures.
END OF ASSIGNMENT\HSPACE*
This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
The command line arguments were:
latex2html -split 0 -t CS 3304 Programming Assignment 1 program1.
The translation was initiated by cs3304sm class account on Tue Jul 15 11:31:31 EDT 1997