Lecture 44: Third Review¶
The question on the third review focus on the number system and basic data structures. This review corresponds to the first review, to prepare for the first midterm exam.
Our First Steps¶
Explain the difference between RDF and RR. Illustrate with an example.
Give a list of ten rational approximations for \(\sqrt{3}\), accurate with 2, 3, up to 11 decimal places.
Consider \({\mathbb Z}_{31}\).
What is the multiplicative inverse of 7?
Show that \(15 x^5 + 4 x^4 + 23 x^3 + 26 x^2 + 6 x + 1\) is irreducible over \({\mathbb Z}_{31}\).
Expand
exp(I*2*Pi/k)
ascos(2*Pi/k) + I*sin(2*Pi/k)
.Consider \(q = \cos(x^3 - 1) + 3 \sin(y) - z^7\). Draw the expression tree of \(q\).
Save a random matrix to file, destroy its reference, and load then the saved matrix back into SageMath.
Generate optimized code to evaluate \(p = 79 x^{298} + 56 x^{205} + 49 x^{164} + 63 x^{121} + 57 x^{119} - 59 x^{42}\).
How many operations are needed to evaluate \(p\)?
Compare with the cost of a direct evaluation of \(p\).
Consider the right hand side of
\[\int_1^2 \frac{1}{x} dx \approx \frac{1}{2n} \left( 1 + \frac{1}{2} \right) + \frac{1}{n} \sum_{k=1}^n \left( \frac{1}{1 + k/n} \right).\]
Write a Python function
P
to define the evaluation of the right hand side of the above sum, for any value for \(n\) which is the input parameter to the functionP
.Compare the value of
P(10000)
with the exact value of the integral.Time the execution of the function for \(n = 10,000\).
Use vectorization to define a more efficient function
F
which computes the same sum asP
, and which also takes \(n\) as an input parameter.Compare the value of
F(10000)
with the exact value of the integral.Time the execution of the function for \(n = 10,000\).
Compare the result of the timings.
Polynomials and Rational Expressions¶
Draw the internal representation of \(x y (x-y)\).
Consider \(p = x^3 - x - 2\) and give all commands for an exact, numeric, and symbolic factorization. In particular, answer the following questions.
How can you write \(p\) as an exact product of linear factors, with exact complex numbers?
Compute a numerical factorization of \(p\) over the complex numbers.
Define a symbolic (i.e.: formal) factorization of \(p\), declaring sufficiently many roots.
Compute a symbolic-numeric factorization, extending the field of rational numbers with complex intervals.
Give all commands to transform \((x-y) (x+y)\) into \((x+y) x - (x+y) y\).
Consider \({\displaystyle r = \frac{79 x^5 + 56 x^4 + 49 x^3 + 63 x^2 + 57 x - 59}{45 x^5 - 8 x^4 - 93 x^2 + 43 x - 62}}\).
Convert \(r\) into a form which is more efficient to evaluate.
Compare the number of arithmetical operations needed to evaluate \(r\) in this more efficient form with the number of arithmetical operations to evaluate \(r\) in its given form.
Compare this number of operations with the Horner forms of numerator and denominator for \(r\).
Explain why normal forms are so important to symbolic computation.
What can we do if a normal form is too expensive to compute? Illustrate with a good example.