Function vecmul-define function addvec and use vecmul

Assignment Help Other Subject
Reference no: EM13194600

1. Write a function vecmul that will take as inputs two simple lists of numbers. vecmul should multiply these lists element-wise as one would multiply vectors. Assume the two lists are of the same length. [For example, (vecmul '(2 3 4 5) '(1 4 5 2)) returns (2*1 3*4 4*5 5*2) or (2 12 20 10).] (5 Marks)

2. Define function addvec and use vecmul to define a product function innpuch to find sum of the products, such as, (innprod '(1 2 3) '(7 8 9)) returns 1*7 + 2*8 + 3*9 or 50. (5 Marks)

3. Define a function last1 which returns the last element of a list (at the top level) without making use of reverse or last (already built in to Common Lisp.) (5 Marks)

4. Write a reverse function srev which reverses all lists that occur in an S-expression at any level. Thus (srev '((a b (c d)) e (f g))) should yield ((g f) e ((d c) b a)). 
(5 Marks)
5. Write a function insert1 which takes its first integer argument and inserts it at the correct place in its second argument, a list of integers sorted in increasing order, so that (insert1 3 '(1 4 6 6 7)) produces (1 3 4 6 6 7). 
(5 Marks)

6. Use insert to write a function sort1 which sorts a list of integers into increasing order. [We are done if the list is nil. Otherwise insert the car of the list into the sorted cdr]. (5 Marks)

7. Define a function occurrence that takes a list and returns a list indicating the number of times each (eql) element appears, sorted from most common element to least common.
(5 Marks)
Example:(occurrences '(a b a d a c d c a)) ?

((A 4) (C 2) (D 2) (B 1))

8. Your friend is trying to write a function that returns the sum of all the non-nil elements in a list to help you to submit assignment on your behalf. He has written two versions of this function and neither of them work. Explain what is wrong with each, and give a correct version. 
(2?5 Marks)
(1 nil 4 5 nil 8 9 nil nil) => 27
(a) (defun summit (lst)
(remove nil lst)
(apply #'+ lst))

(b) (defun summit (lst)
(let ((x (car lst)))
(if (null x)
(summit (cdr lst))
(+ x (summit (cdr lst))))))

9. Suppose the function pos+ takes a list and returns a list of each element plus its position. (10 Marks)
(pos+ '(7 5 1 4))? (7 6 3 7)
Define this function using (a) recursion (b) iteration.

Reference no: EM13194600

Questions Cloud

What term best describes elena’s behavior : Elena’s boss told her that she is being let go due to company downsizing. Later that day when gets home, she is critical of her girlfriend’s choice of restaurant for dinner. What term best describes Elena’s behavior?
Financing healthcare affects health care facilities : I need to create 3 slides of information all three on how historical trends in financing healthcare affects health care facilities. I need charts, notes, and references for the three slides
Customer remove a watch from a display case : A sales clerk at Big C Store observed a customer remove a watch from a display case and put it in his pocket. In most cases, Big C:
Focus of the the individual marketing plan : Description of the product (new not coke pepsi or any product already produce by another company. it should a make-up ) which will be the focus of the the individual marketing plan.
Function vecmul-define function addvec and use vecmul : Write a function vecmul that will take as inputs two simple lists of numbers. vecmul should multiply these lists element-wise as one would multiply vectors. Assume the two lists are of the same length
Example of media convergence : Provide an example of media convergence and explain the media elements that are being combined. Explain how the combination of media elements in your example may be useful and to whom
Equivocated on food labeling : Do you think the food industry in general has equivocated on food labeling? Are all foods labeled natural "natural" in the same way? Has modern society subverted the concept of nature/natural?
Conditional formatting and sorting a table : Open the table created previously (inventory level Priority) Add conditional formatting to the priority field using the Icon sets format style and the 5 ratings icon style. Complete the following three sorts A)sort the table in ascending sequence (sm..
Determines patient benefits eligibility : What are the appropriate steps to take when insurance does not cover a planned service? Relate these steps to the eligibility factor you identified and provide two examples of patient charges with corresponding billing transactions.

Reviews

Write a Review

Other Subject Questions & Answers

  Discuss how the new technology works

Discuss how the new technology works, what method or product the new technology is designed to replace, why the new technology is preferable to the old method or product, how this new technology benefits a print media corporation, the public, or both..

  State the purpose of a fire log book

Describe the typical content of a fire safety training session for the employees State the purpose of a fire log book

  Many notable characters-songs and movies

Many notable characters, songs, and movies that were previously set to enter into the public domain have not as of yet due to repeated extensions of the copyright laws that have extended protections.

  How us constitution implements separation of powers-checks

Write 200-250 words, examine how U.S. Constitution implements separation of powers and checks and balances. Describe why constitutional framers based new government on these ideas.

  Uniform crime and national incident-based reporting system

What are the similarities between Uniform Crime Reporting and National Incident-Based Reporting System ?

  Circular cylindrical shell and internal pressure

Calculate the maximum allowable internal pressure pmax based upon an allowable shear stress in the wall of the shell of 60 MPa. What is the change in wall thickness at this pressure? (E = 205 GPa, ν = 0.25)

  Essay opposing home schooling

Write a short essay opposing home schooling. Start with a debatable thesis statement. Include a paragraph acknowledging opposing views.

  Problem related to coefficient of friction

Assume the coefficient of friction between the pavement and tires is .3 and the alignment of this section of the road is horizontal. For this particular problem we can ignore the friction value and just use a standard deceleration rate of 11.2 ft/s..

  Utilitarian theory and libertarian theory

Compare Egalitarian theory, Utilitarian theory and Libertarian theory in the distribution of resources. How does the concept different from the concept stated by the President's Commission in question 2?

  Factors contributing to prejudice and discrimination

Critically discuss the major factors contributing to prejudice and discrimination? What might we do to reduce the levels of hate that pervade our society?

  What is accreditation

Give a brief outline of Guthrie's ideas. Which ideas make the most sense to you and why?

  Substance abusing high-risk family group

A summary of the substance abusing high-risk family group, with explanation of the high-risk condition and associated behaviors or patterns.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd