| 1 |
#include "quadratic-poly.h" |
| 2 |
|
| 3 |
/** |
| 4 |
* @brief Allocate a new Quadratic polynomial of the specified level. |
| 5 |
* |
| 6 |
* Quadratic polynomials are defined by recurrence as \f$P_0(z) = 0\f$, |
| 7 |
* \f$P_{k+1} = P_{k}(z)^2 + z\f$. The polynomial \f$P_k(z)\f$ is called the |
| 8 |
* \f$k\f$-th level Quadratic polynomial. |
| 9 |
* |
| 10 |
* @param ctx The current mps_context. |
| 11 |
* @param level The desired level for the Quadratic polynomial. |
| 12 |
* @return A pointer to a newly-allocated mps_quadratic_poly. |
| 13 |
*/ |
| 14 |
mps_quadratic_poly * |
| 15 |
mps_quadratic_poly_new (mps_context * ctx, int level) |
| 16 |
{ |
| 17 |
mps_quadratic_poly *mp = mps_new (mps_quadratic_poly); |
| 18 |
mps_polynomial *p = MPS_POLYNOMIAL (mp); |
| 19 |
mps_polynomial_init (ctx, p); |
| 20 |
|
| 21 |
mp->level = level; |
| 22 |
p->degree = pow(2, level) - 1; |
| 23 |
|
| 24 |
p->type_name = "mps_quadratic_poly"; |
| 25 |
p->structure = MPS_STRUCTURE_REAL_INTEGER; |
| 26 |
p->density = MPS_DENSITY_DENSE; |
| 27 |
|
| 28 |
/* Load methods */ |
| 29 |
p->fnewton = mps_quadratic_poly_fnewton; |
| 30 |
p->dnewton = mps_quadratic_poly_dnewton; |
| 31 |
p->mnewton = mps_quadratic_poly_mnewton; |
| 32 |
p->feval = mps_quadratic_poly_feval; |
| 33 |
p->deval = mps_quadratic_poly_deval; |
| 34 |
p->meval = mps_quadratic_poly_meval; |
| 35 |
p->dstart = mps_quadratic_poly_dstart; |
| 36 |
p->fstart = mps_quadratic_poly_fstart; |
| 37 |
p->free = mps_quadratic_poly_free; |
| 38 |
|
| 39 |
return mp; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @brief Free a Quadratic polynomial. |
| 44 |
* |
| 45 |
* @param ctx The current mps_context. |
| 46 |
* @param p The polynomial that has to be freed. |
| 47 |
*/ |
| 48 |
void |
| 49 |
mps_quadratic_poly_free (mps_context * ctx, |
| 50 |
mps_polynomial * p) |
| 51 |
{ |
| 52 |
/* Quadratic polynomials haven't any data, so there's essentially |
| 53 |
* nothing to do here. */ |
| 54 |
free (p); |
| 55 |
} |