# Lecture 17: the First Midterm Exam¶

The first midterm exam covers the first two parts of the course.

## Questions on the Spring 2017 First Midterm Exam¶

The list of questions on the Spring 2017 first midterm exam are below. The exam is open book, open notes and open computer. All answers to the questions must be handwritten, submitted on paper.

Let \(N\) be the number \(\exp(\pi)\).

Write a rational approximation \(A\) for \(N\), accurate with 3 decimal places.

Give the Sage command(s) to verify that \(A\) approximates \(N\) indeed with 3 decimal places.

Compute a list of consecutively more accurate approximations for \(N\).

The list should start with the number \(A\) and have length 10.

Do not write the list, write only the Sage command(s) to compute this list.

Let \(p = x^3 + x + 1\) be a polynomial over the finite field (also called a Galois field) of five numbers.

Write the Sage commands to define \(p\) and to show that \(p\) does not factor over this finite field.

Use \(p\) to extend the finite field of five numbers.

Write the factorization of \(p\) over this field extension.

Give all relevant Sage commands you used to obtain this factorization.

What is a symbolic ring? Give a good example of a use of a symbolic ring.

Consider a polynomial with integer coefficients in three variables, \(x\), \(y\), and \(z\).

Define one normal form of such a polynomial.

Illustrate your definition with an example of a random polynomial.

What is the application of a normal form?

Let \(q = (x^2 + x - 1)/(x^2 - 2)\). Draw the expression tree of \(q\).

Do not write any Sage commands.

We have covered a couple of different ways to substitute. Describe two different ways and illustrate each way with an example. Explain on the examples why one way to substitute is appropriate for the example instead of the other way to substitute.

Let \(p = (x^2 - 3 y) (x + 2 y)\) and \(q = x^3 + 2 x^2 y - 3 x y - 6 y^2\).

Give the Sage commands to

transform \(p\) into \(q\); and

transform \(q\) into \(p\).

## Questions on the Fall 2018 First Midterm Exam¶

The list of questions on the Fall 2018 first midterm exam are below. The exam is open book, open notes and open computer. All answers to the questions must be handwritten, submitted on paper.

Let \(N\) be the natural logarithm of 10.

Give a floating-point approximation \(A\) of \(N\), accurate with 5 decimal places.

Compute a rational approximation \(R\) for \(N\), accurate with 5 decimal places. Write the value for \(R\). Write the Sage command(s) and its output to verify that \(R\) approximates \(N\) indeed with an accuracy of 5 decimal places.

Give the Sage command to compute a list of the first 10 rational approximations of \(N\). Do not write the entire list, write only its last element.

Let

`x`

and`y`

be variables, declared via`x, y = var('x,y')`

.Explain the difference between

`y = 2; x = y`

and`y = 2; x = 'y'`

.Explain the relations between

`x`

and`y`

in both cases.Let \(p\) be the polynomial \(p = x^8 + 2 x^7 + 5 x^6 - 3 x^5 - 4 x^4 - x^3 + x^2 + x - 2\).

What is the smallest number of arithmetical operations needed to evaluate \(p\)?

What is the fastest way to evaluate \(p\) in hardware arithmetic?

Give all Sage commands to convert \(p\) into an expression best suited for fast evaluation. Do not write the output of the Sage commands.

Give timing results to compare the straightforward evaluation of \(p\) with the evaluation of the form for fast evaluation.

For this question, write all relevant Sage commands and their output.

Define the polynomial \(p = 9 x^3 - 72 x^2 - 78 x + 3\) over the field of rational coefficients.

Is \(p\) irreducible? If not, what are the factors of \(p\)?

Extend the field of rational numbers with sufficiently many formal roots so \(p\) factors as a product of linear polynomials over the field extension.

Type

`x, y = var('x, y'); q = (x-y+1)/(x^2+3*y)`

and draw the expression tree of`q`

.Give some relevant Sage commands you used to obtain your drawing.

For polynomials in several variables explain the difference between the pure lexicographic and the degree lexicographic order.

Illustrate the difference with good examples.

What are the commands to transform \({\displaystyle \frac{(x-y)^2}{(x+y)^2} + 1 \mbox{ into } \frac{(x-y)^2 + (x+y)^2}{(x+y)^2}}\)?

## Questions on the Spring 2019 First Midterm Exam¶

The list of questions on the Spring 2019 first midterm exam are below. The exam is open book, open notes and open computer. All answers to the questions must be handwritten, submitted on paper.

Consider \(c = \sqrt{\pi/3}\).

Give a rational approximation to \(c\), accurate with 5 decimal places.

What is the actual error of your rational approximation?

Give a list of rational approximations of \(c\). The first number of the list is the same rational number as the one above, accurate to 5 decimal places. The last rational number has an accuracy of 10 decimal places.

For

`x = var('x')`

, why does Sage not automatically simplify`sqrt(x^2)`

to`x`

?Illustrate your explanation with a good example.

Consider the efficient evaluation of \(p=x^6 + 2 x^5 + 3 x^4 + 4 x^3 + 5 x^2 + 6 x + 7\).

Construct the Horner form for \(p\).

How many arithmetical operations does it take to evaluate \(p\)?

What is the most efficient way to evaluate \(p\) with hardware arithmetic?

Compare this most efficient way to the straightforward way to evaluate \(p\).

Give all relevant commands for this problem. Consider the polynomial \(p = x^4 + x^2 + 1\) over the field \({\mathbb Z}_2 = \{ 0, 1 \}\), the field of bits, 0 and 1.

Is \(p\) irreducible? If not, then what are its factors?

Extend the field \({\mathbb Z}_2\) with sufficiently many formal roots so \(p\) factors as a product of linear factors. Write the factorization of \(p\).

Type

`x,y = var('x,y')`

followed by`q = (x^2 - y + 1)/(y^2 - x + 1)`

.Draw the internal representation of

`q`

.Give some relevant commands used to make your drawing.

Explain the meaning of

`QQ['x,y,z']`

,`QQ['x']['y,z']`

, and`QQ['z']['y']['x']`

.Explain the differences between

`QQ['x,y,z']`

,`QQ['x']['y,z']`

, and`QQ['z']['y']['x']`

.Illustrate the differences with good examples.

Write the commands to transform \({\displaystyle x + \frac{(x - y)^5}{(x + y)^5}}\) into \({\displaystyle \frac{(x + y)^5 \cdot x + (x - y)^5}{(x + y)^5}}\).

## Questions on the Summer 2022 First Midterm Exam¶

The exam in the summer 2022 took 100 minutes and was administered online, in two different versions. Questions had to be uploaded into one single Jupyter notebook into gradescope.

The list of the nine questions on the first version is below.

Let \(N = \cos(\pi/5)\).

Compute a rational approximation for \(N\), accurate to 2 decimal places.

Verify that the accuracy of your rational approximation is indeed 2 decimal places.

Compute the sequence of the first ten consecutive rational approximations for \(N\), accurate with 2, 3, up to 11 decimal places.

Explain the difference between \(1.0 + 10^{-32}\) and \(1 + 10^{-32}\).

What would you need to do for SageMath to return the

*same*,*correct*, and*real*value of those two sums?Declare

`r`

and`theta`

as variables in the`RR`

domain.Define

`n`

as the expression`r*exp(I*theta)`

. What are the real and imaginary parts of`n`

?Compute the Horner form of \(p = x^7 - 7 x^5 - 2 x^4 - x^3 - 4 x^2 - 2 x + 1.\)

Explain the use of the Horner form.

What is its advantage of the Horner form over representing \(p\) as above?

Explain the difference between

`eval(x)`

and`eval(preparse(x))`

.Give a good example of

`x`

to illustrate the difference.Consider the function

def python_sum(n): """ Returns the floating-point value of the sum of (3*k/n)**2, for k from 1 to n-1, multiplied by 3/n. """ return float((3/n)*sum([(3*k/n)**2 for k in range(1, n)]))

Time the execution of

`python_sum(10**4)`

.Explain why the execution is slow.

Apply vectorization to write a faster version. Verify the correctness.

Time the execution of your vectorized function for

`n = 10**4`

and compare with your timing of the original`python_sum(10**4)`

.

Consider the polynomial \(p = x^3 - x^2 - 3\).

Compute the exact, symbolic, and numeric factorization for \(p\).

Consider the expression:

\[\frac{a - 2b}{3a + b + 2c},\]for \(a\), \(b\), \(c\) defined as

`a, b, c = var('a, b, c')`

.Draw the internal representation of this expression.

Transform \((y+1)^6 - x^4\) into \(((y+1)^3 + x^2)((y+1)^3 - x^2)\).

The list of the nine questions on the second version is below.

Let \(N = \log(\pi/2)\).

Compute a nearby rational approximation for \(N\), with the denominator bounded by 100.

What is the accuracy of your nearby rational approximation?

Compute the sequence of the first ten nearby rational approximations for \(N\), where the size of the denominator of the \(k\)-th approximation is bounded by \(10^k\), \(k=1,2, \ldots 10\).

Explain the difference between 0 and 0.000.

Give a good example of a calculation which results in 0.000, to illustrate the difference with a result of a computation equal to 0.

Make

`eqn`

so`print(eqn)`

shows`cos(pi) == -1`

.Without retyping

`eqn`

, change`eqn`

so`print(eqn)`

shows`-1 == -1`

.Consider the statements

a, b, c = var('a, b, c') a = b; b = 2; c = b

Describe the relations between the three variables.

Execute the commands to verify the relations.

What does the

`preparse()`

function do?Illustrate your explanation with a good example where

`preparse()`

is needed.Consider the function

def python_sum(n): """ Returns the floating-point value of the sum of exp(-k/n) for k from 1 to n-1, multiplied by 1/n. """ return float((1/n)*sum([exp(-k/n) for k in range(1, n)]))

Time the execution of

`python_sum(10**4)`

.Explain why the execution is slow.

Apply vectorization to write a faster version. Verify the correctness.

Time the execution of your vectorized function for

`n = 10**4`

and compare with your timing of the original`python_sum(10**4)`

.

Consider the polynomial \(p = x^3 + x^2 + 3\).

Compute the exact, symbolic, and numeric factorization for \(p\).

Draw the binary expression tree defined by the fast callable

\[\frac{a + 2b}{3a - b + 2c}.\]Transform \(((y+1)^3 + x^2)((y+1)^3 - x^2)\) into \((y+1)^6 - x^4\).