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

  Fast food culture and food concept

Compare American's fast food culture and Italian's slow food concept. what is different between?

  Therapeutic alliance-skills-barriers and solutions

Can you please provide a brief description of three important skills needed to establish a successful therapeutic alliance? Then, explain possible barriers that may impede implementing these skills.

  Criminal case

Suppose that after the criminal case is settled Tyler Clementi's family attempts to sue Dharun Ravi on behalf of Tyler in civil court for the tort of invasion of privacy. Please provide the basic elements of the tort of invasion of privacy in New Jer..

  Approach of therapeutic treatment

Since there is no one theory/therapy that applies to all people, eclecticism is the ideal manner in which to provide therapeutic treatment.

  Displays the subtotal of the sale

Design a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of the sales tax and the total. The sales tax is 6 percent. I also need help with developing a flowchart we are using raptor.

  Explain characteristics of character as a person

Explain the character also you can in one page. Write characteristics: what do details tell you about character as a person? As representative of their occupation or position in society?

  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..

  Protection of unreasonable searches and seizures

Please describe the â??emergency administrative searchâ? exception to the general rule that a warrant must be issued for a lawful search. a) What is â??reasonable suspicionâ? in the context of the 4th Amendment?

  Methodology morgan used to investigate foreign cultures

The methodology Morgan used to investigate foreign cultures included

  About race and ethnicity

How do these paradigms relate to the general concerns of nineteenth-century West European sociologists and their thinking about race and ethnicity?

  Defining ethnic and race issues

With increasing numbers of inter-racial marriages, there will be many more people claiming bi-racial and multi-racial identities in the decades to come.

  Research way company is organized-business philosophy

Research way company is organized, its business philosophy, and its niche in marketplace. Write down report which would be helpful to other students who might be interested in seeking employment there.

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