In this assignment, we are going to implement a custom list called CauchyList. A CauchyList is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this assignment, we are going to implement a custom list called CauchyList. A CauchyList is a standard Python list with some arithmetic operations associated to it. A description of the CauchyList class is in the following section. Your program is going to be one Python file, called assignment3.py, that contains the CauchyList class. CauchyList class Instance variables • p: an integer that is used as the modulus. This means that all operations are done mod p. • content: a list of integers. Methods • _init_: accepts an integer p. Initializes the instance variable p to p and the instance variable content to an empty list. • generate_random: accepts an integer n. Populates content with n random integers in the range [0, p - • length: returns the length of this CauchyList. 1). • get: accepts an integer i. If i is smaller than the length of the list then returns the i-th element. Otherwise, returns 0. • -_add__: returns the sum of this CauchyList and the input CauchyList. The sum of two CauchyLists is defined component-wise. That means if a, b are two CauchyList then we define c = a + b by setting c.content[i] = a.content[i] + b.content[i] where the addition is done mod p. This is a special method that is called to evaluate expressions of the form a + b. We have seen other special methods such as str_ and _lt__ in the lectures. For example, lt__ is called to evaluate expressions of the form a < b. This method should be able to handle CauchyLists of different lengths. When adding two lists of length m and n, where m > n, the resulting list should be of length m and the higher elements of shorter list is assumed to be zero. Hint: you can use the get method for this. If the two CauchyLists have different values of p, this method should raise a ValueError exception. -_sub__: similar to add_ except that it is called to evaluate expressions of the form a b. -_mul : returns the product of this CauchyList and the input CauchyList. Suppose that a, b are two CauchyLists. Then the productc = a * b is defined as follows: cli] = a[0] * b[i] + a[1] * bli - 1] + a[2] * b[i - 2] + ... + ali] * b(0] where we denoted a.content[k] by a[k] for simplicity. Remember, cli] must be reduced mod p at the end. Product of two CauchyLists of lengths m and n is a CauchyList of length m + n - 1. So the index i in c[i] can be larger than the lengths of a and b. You can use the get method to avoid IndexError. If the two CauchyLists have different values of p, this method should raise a ValueError exception. If the second argument is an integer, not a list, Then this method performs a scalar product which is much simpler. That is, if b is an integer then cli] = a[i] * b. This allows us to be able to, for example, evaluate an expression of the form a * 65. • --str_: returns a string representation of the CauchyList in the following format: p: p length: length content: content In this assignment, we are going to implement a custom list called CauchyList. A CauchyList is a standard Python list with some arithmetic operations associated to it. A description of the CauchyList class is in the following section. Your program is going to be one Python file, called assignment3.py, that contains the CauchyList class. CauchyList class Instance variables • p: an integer that is used as the modulus. This means that all operations are done mod p. • content: a list of integers. Methods • _init_: accepts an integer p. Initializes the instance variable p to p and the instance variable content to an empty list. • generate_random: accepts an integer n. Populates content with n random integers in the range [0, p - • length: returns the length of this CauchyList. 1). • get: accepts an integer i. If i is smaller than the length of the list then returns the i-th element. Otherwise, returns 0. • -_add__: returns the sum of this CauchyList and the input CauchyList. The sum of two CauchyLists is defined component-wise. That means if a, b are two CauchyList then we define c = a + b by setting c.content[i] = a.content[i] + b.content[i] where the addition is done mod p. This is a special method that is called to evaluate expressions of the form a + b. We have seen other special methods such as str_ and _lt__ in the lectures. For example, lt__ is called to evaluate expressions of the form a < b. This method should be able to handle CauchyLists of different lengths. When adding two lists of length m and n, where m > n, the resulting list should be of length m and the higher elements of shorter list is assumed to be zero. Hint: you can use the get method for this. If the two CauchyLists have different values of p, this method should raise a ValueError exception. -_sub__: similar to add_ except that it is called to evaluate expressions of the form a b. -_mul : returns the product of this CauchyList and the input CauchyList. Suppose that a, b are two CauchyLists. Then the productc = a * b is defined as follows: cli] = a[0] * b[i] + a[1] * bli - 1] + a[2] * b[i - 2] + ... + ali] * b(0] where we denoted a.content[k] by a[k] for simplicity. Remember, cli] must be reduced mod p at the end. Product of two CauchyLists of lengths m and n is a CauchyList of length m + n - 1. So the index i in c[i] can be larger than the lengths of a and b. You can use the get method to avoid IndexError. If the two CauchyLists have different values of p, this method should raise a ValueError exception. If the second argument is an integer, not a list, Then this method performs a scalar product which is much simpler. That is, if b is an integer then cli] = a[i] * b. This allows us to be able to, for example, evaluate an expression of the form a * 65. • --str_: returns a string representation of the CauchyList in the following format: p: p length: length content: content
Expert Answer:
Answer rating: 100% (QA)
import random class CauchyList def initselfp selfp p selfcontent def generateRando... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
In this question, you are going to implement a human vs. human version of Notakto. Notakto is a tic-tac-toe variant. It is played across three 3 x 3 boards: Board A, board B and board C. When you...
-
In this question, you are going to implement an artificial intelligence (AI) vs. human version of Notakto. The AI will be the Player 1, i.e., the AI will always start. Here the AI means that the move...
-
Consider a quasi-one-dimensional steady advection-diffusion flow with the boundary conditions as illustrated in Figure 1: u(x) x=0 p=0 in = puA = 1 x 10-4 -4 kg/s Figure 1 In Figure 1, the velocity u...
-
Maicom Construction Materials Inc. , hereinafter referred to as "MCM", is a construction materials company established in Moncton, New Brunswick. Its facilities (warehouse, store and offices) are...
-
Find Dx30y in each case, (a) y = x19 + x12 + x5 + 10 (b) y = x20 + x19 + x18 (c) y = 7x21 + 3x20 (d) y = sin x + cos x (e) y = sin 2x (f) y = 1/x
-
In problem, follow Steps 1 through 8 to analyze the graph of each function. R(x) = x 2 + 3x 10/x 2 + 8x + 15
-
An asset has the estimated salvage values for various lives, shown in the table below. For each possible life from 1 to 6 by 1, determine the capital recovery cost for MARR of 8 percent/year. EOY NCF...
-
Putnam Corporation had these transactions during 2014. (a) Purchased a machine for $30,000, giving a long-term note in exchange. (b) Issued $50,000 par value common stock for cash. (c) Issued...
-
Display Oracle database employee last_name and salary for employee_ids between 100and 102. Include a third column that divides each salary by 1.55 and rounds the result two decimal places.
-
Give two characteristics of each type of legal standard: statute, case, and regulation. (An example of a characteristic would be the source of the legal standard.)
-
On a typical weekday, the Whole Foods in Ann Arbor is visited by 10000 customers. It is estimated that on average there are 500 customers in the store. Assuming that the store is open 15 hours per...
-
Would the item qualify just by using tariff shift. Yes or No and Explain. (- Read the Rule of Origin and analyze options to qualify) Material 1 Hs.9006.01 USA(CUSMA certificate available) $ 56...
-
Discuss the implications of using the "continue" statement in error handling and exception propagation mechanisms within loop constructs, including considerations related to fault tolerance, error...
-
Discuss why we need to do adjusting entries for sales returns and allowances.
-
CASE: Westminster Company: A System Design Assessment products are marketed through a network of diverse retailers and wholesalers. Trade class as a percent of sales is 37% grocery, 20% drug, 35%...
-
In the context of parallel and concurrent programming paradigms, analyze the role of the "continue" statement in loop parallelization and task scheduling strategies, particularly in scenarios where...
-
Can you elucidate the role of data cleansing and data deduplication techniques in the transformation phase of the ETL process, and how these activities contribute to ensuring data accuracy and...
-
"Standard-cost procedures are particularly applicable to process-costing situations." Do you agree? Why?
-
Calculate the cathode potential (versus S.C.E.) needed to reduce cobalt(II) to 1.0 M in each of the following solutions. In each case, Co(s) is the product of the reaction. (a) 0.10 M HClO 4 (b) 0.10...
-
(a) Prepare a family of graphs for the titration of 50.0 mL of 0.0200 M HA (pKa 4.00) with 0.100 M B (pKb = 3.00, 6.00, and 9.00). (b) Write the acid-base reaction that occurs when acetic acid and...
-
The acid HA has pKa = 4.00. Use Equations 9-17 and 9-18 to find the fraction in the form HA and the fraction in the form A- at pH = 5.00. Does your answer agree with what you expect for the quotient...
-
See Table 2.5 showing financial statement data and stock price data for Mydeco Corp. a. Compute Mydecos PE ratio each year from 2019 to 2023. In which year was it the highest? b. What was Mydecos...
-
See Table 2.5 showing financial statement data and stock price data for Mydeco Corp. a. Compute Mydecos ROE each year from 2019 to 2023. b. Compute Mydecos ROA each year from 2019 to 2023. c. Which...
-
In early 2018, United Airlines (UAL) had a market capitalization of \($25.14\) billion, debt of \($12.73\) billion, and cash of \($5.59\) billion. United also had annual revenues of \($38.72\)...
Study smarter with the SolutionInn App