Polynomial
class (1/3)Starting from hints/ex2.py
, you are tasked with implementing a Python class called Polynomial
that represents polynomials. The class should have the following features:
Constructor: The class should have a custom constructor that takes variable coefficients as arguments. The coefficients should be provided in increasing order of degree (
String representation: Implement the __repr__
method to provide a string representation of the polynomial. The string should display the polynomial in a human-readable form. For example, for the polynomial with coefficients [1, 2, 3]
, the string representation should be "1 + 2x + 3x^2"
.
Addition and multiplication: Implement the __add__
and __mul__
methods to allow addition and multiplication of polynomials. The methods should return a new polynomial.
Polynomial
class (2/3)Class method to create from string: Implement a @classmethod
called from_string
that creates a Polynomial object from a string representation. Assume that the input string will be a polynomial in the form of "a + bx + ... + cx^(n-1) + dx^n"
.
The base class Polynomial
should be extended by two subclasses:
StandardPolynomialEvaluator
: Implements the standard polynomial evaluation method:HornerPolynomialEvaluator
: Implements Horner's rule for polynomial evaluation:Polynomial
class (3/3)Implement a measure_time
decorator, which measures the time taken by a function to execute.
Instantiate objects of both StandardPolynomialEvaluator
and HornerPolynomialEvaluator
with the same set of coefficients.
Apply the measure_time
decorator to a function that takes a PolynomialEvaluator
object and evaluates it at a given list of points.
Evaluate the polynomial at the same 1000 points using both methods and compare the results. Raise an assertion error if the results do not match.
Use the decorated function to evaluate the polynomial using both the standard method and Horner's rule, and observe the logged results and execution times.
Refactor the existing data processing code provided in hints/ex3.py
into a modular package with multiple modules, functions, classes.
dataprocessor
with the following modules:
__init__.py
: Entry point for the package, import necessary functions, classes, and data. Implement __all__
.operations.py
: Contains functions for data processing and analysis.data_analysis.py
: Introduce a class DataAnalyzer
that encapsulates data processing and analysis functionalities.main.py
script to demonstrate the usage of the package.