Alternate Distance Succession

Let’s consider the recursive definition of a mathematical succession parameterized by the real number constants \(a\), \(b\), and \(k\):

\(x_{1} = a\)

\(x_{2} = b\)

\(x_{i+1} = (-1)^{i+1} \frac{1+\sqrt{ {x_i}² + {x_{i-1}}² } }{2} \pi\)

Implement the following two Python functions (following the order is recommended) in the module adist_succ (file adist_succ.py).

The first function is:

adist_term(xim1, xi, i)

such that

given xim1, xi float values, where xim1, xi, are the values for two consecutive terms of our succession, and i is an int index of xi

returns a float with the term i+1 of the succession above

For exemple:


>>> xim1, xi, i = -1, 1, 2
>>> x = adist_term(xim1, xi, i)
>>> round(x, 4)
-3.7922

>>> xim1, xi, i = xi, x, i+1
>>> x = adist_term(xim1, xi, i)
>>> round(x, 4)
7.7313

>>> xim1, xi, i = xi, x, i+1
>>> x = adist_term(xim1, xi, i)
>>> round(x, 4)
-15.0973

Note

Python standard modules such as math may be imported and used.

Doctests are available at the adist_term.test file.


The second function is:

adist_t4t5(a, b)

such that

given a, b, float values being the 1st and 2nd terms of the succession respectively

returns a float with the addition of the 4th and the 5th terms of the succession above. The float is rounded to 4 decimals.

For exemple:

>>> a, b = -1, 1
>>> adist_t4t5(a, b)
-7.366

>>> a, b = 0, 10
>>> adist_t4t5(0, 10)               
-27.0554

Note

This function implementation must call the previous function as many times as needed.

Doctests for validation are available at the adist_t4t5.test file.