lisp代写:CMPT306 assignment 1

 To become familiar with the basic features of Lisp syntax and semantics..

 To become acquainted with the techniques of pure functional programming..

 To learn to think recursively..

NOTE:: Properly acknowledge (aadd a note and//oor hyperlink and//oor comment)) any help or resource you used..

1)) Write a set of LISP functions to implement the following operations on polynomials::

 Poly -aadd – to add two polynomials

 Poly–ssub – to subtract two polynomials

 Poly–mmul – to multiply two polynomials

 Poly–dder – to compute the derivative of a polynomial

 Poly–vval – to compute the value of a polynomial for a given argument

 Poly–pprim – to compute the primitive((aantiderivative)) of a polynomial

A polynomial will be represented as an association list.. There will be one sublist for each term of the polynomial.. Each sublist will have the exponent of the term as the first component and the coefficient as the second component..

Ex:: 3X 5 +33X 3 +77 is represented as (((55 3)) (33 3)) (00 7)))) .

2))

Write the LISP

function::

(ddeep -ssubst x y L))

that returns a list L1 formed by replacing,, within the recursive–llist L,, each occurrence of the atom x (aat any level)) with the atom y . (YYou may assume that L is a recursive list,, and that x and y are each atoms..))

(ddeep -ssubst 4 t ‘((ttruth is 4)))) → (TTRUTH IS T)) (ddeep -ssubst 4 nil ‘((44 is not (44)))))) → (NNIL IS not (NNIL)))) (ddeep -ssubst 4 nil ‘((55 is not (222)))))) → (55 is not (222))))

3)) Write the LISP function

(ccount– sub– list – occ L1 L2))

That returns the number of occurrences of the list L1 as a sublist of L2.. L1 is a sublist of L2 if all the elements of L2 can be found in sequence in L1..

For example:: (11 2)) is a sublistof (33 1 2))

(11 3)) is not a sublist of (11 2 3))

(11 3)) is not a sublist of (33 2 1))

(11 1)) is a sublist of (22 3 2 3 1 1 3 2))

(ccount– sub– list – occ ‘((11 2)) ‘((11 2 3))))→→11

(ccount– sub– list – occ ‘((11 2)) ‘((33 2 3))))→→00

(ccount– sub– list – oc c ‘((11 2)) ‘((11 2 1 2 3))))→→22

(ccount– sub– list – occ ‘((11 1)) ‘((11 1 1 1))))→→33

4)) The following procedure illustrates a possible way of generating password for different servers::

1..SStart with an easy to remember sentence.. Get a letter code by taking the first letter of each word in the sentence.. If the sentence contains numbers,, then the entire number is selected in the code..

o For example::

 The sentence “HHow I wish how I wish you were here”” generates the code HIWHIWYWH

 The sentence “

There were 12 of us this morning I am the only one this evening””,, generates

the code TW12OUTMIATOOTE..

2..AAdd the first letter of the server name in front of the code and the last letter of the server name after the code to generate an intermediate password

o For example::

 If the server name is “MMy new cool business”” and the code is HIWHIWYWH,, the intermediate password is M HIWHIWYWH S

 If the server name is “MMacEwan”” and the code is

TW12OUTMIATOOTE the intermedia

te

password is

M

TW12OUTMIATOOTE

N

3..

Consider a replacement list which specifies pairs of symbols,, where each occurrence of the first symbolis to

be replaced by the second symbol.. Get the final password by replacing the symbols of the intermediate

password

according to the replacement list..

o

For example::

If the intermediate password is

M

HIWHIWYWH

S

and the replacement list is ( (SS 5)) (II 1))))

the final password is:: M

H

1

WH

1

WYWH

5

 If the intermediate password is

TW12OUTMIATOOTE and the replacement list is (((TT 7)) (MM

Q))((OO 0)))) the final password is::

7

W12

0

U

7

Q

IA

7007

E

Write the LISP function::

(ggen – passsn– list st – list subst– list))

That returns a password formed as explained above for the server name list sn – list , sentence list st – list and replacement list subst – list . The sn – list and the st– list are lists which contains the letters of each word as lists..

For example :

The site–nname “MMy new cool business”” is represented as

‘((((mm y)) (nn e w)) (cc o o l)) (bb u s i n e s s)))) .

The sentence “HHow I wish how I wish you were here”” is represented as

‘((((hh o w)) (ii)) (ww i s h)) (hh o w)) (ii)) (ww i s h)) (yy o u)) (ww e r e)) (hh e r e)))).. The replacement list is a list of pairs – where the first element specifies the symbol to be replaced and the second one specifies the symbol to replace it by..

(ggen – pass

‘((((mm y)) (nn e w)) (cc o o l))((bb u s i n e s s))))

‘((((hh o w)) (ii)) (ww i s h)) (hh o w)) (ii)) (ww i s h)) (yy o u)) (ww e r e)) (hh e r e))))

( (OO 0)) (II 1))))

) → ‘((

M

H 1 W H 1 W Y W H S))

( gen – pass

‘(((( m a c e w a n))))

‘((((

There

)((

were

)((

12

)((

of

)((

us

)((

th

i

s

)((

morn

i

ng

)((ii))((

am

)((

the

)((

only

)((

one

)((

th

i

s

)((

even

i

ng

)

)

,

( (

W 3

) (

T7

)))

) → ‘((

M

7 3 1 2 O U 7 M I A 7 O O 7

E

N

)

Implementation is subject to the constraint that it should illustrate pure functional programming;; that is,, it should not use set,, setf,, setq , or any other binding primitive.. You may use set , etc..,, for the purposes of testing your functions,, but not in any of the functions that form part of your solution to the problem.. You may,, of course,, define any other subsidiary functions that you might find useful.. The list of LISP built–iin functions and forms that you can use is attached to this assignment….

Correctness – The programs should conform to the specifications for which it was written.. It should include correct handling of special cases,, error conditions,, etc..,, except that you may assume that input will be provided in the specified format.. Your file must load without error in the clisp evaluator installed on ugrad..ccs..mmacewan..cca.. There is a 50%% penalty if errors are detected at loading time..

Design and Efficiency – The program should be constructed from small,, coherent,, independent and loosely coupled functions.. Each function should access only its own parameters.. The control constructs and data structures used should be those appropriate to the problem at hand.. The program should not perform unnecessary steps,, use extraneous variables,, nor implement the algorithm in a contorted or inefficient way.. Your functions must be documented – through comments and properly indented..

Marking scheme::

Item

Mark

1

35

2

10

3

10

4

25

Design and efficiency

20

TOTAL

10 0