From 3f5aaacbf220e1f84ab38a8be4bfaeaa0998ca89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sun, 13 Oct 2019 18:08:15 +0300 Subject: [PATCH] First draft of essential polynomial arithmetic functionality. Former-commit-id: f34d258aaffbd52c4e4d251f5b6f1ff3733e3a08 --- qpms/polynomials.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 qpms/polynomials.h diff --git a/qpms/polynomials.h b/qpms/polynomials.h new file mode 100644 index 0000000..8101578 --- /dev/null +++ b/qpms/polynomials.h @@ -0,0 +1,79 @@ +/** \file polynomials.h + * \brief Basic operations with polynomials. + * + */ +#ifndef QPMS_POLYNOMIALS_H +#include + +/// Polynomial with rational coeffs. +typedef struct qpq_t { + int order; + int offset; + int capacity; + mpq_t *coeffs; +} qpq_t; + +/// Initiasise the coefficients array in qpq_t. +void qpq_init(qpq_t *x, int maxorder); + +/// Deinitialise the coefficients array in qpq_t. +void qpq_clear(qpq_t *x); + +/// Polynomial addition. +void qpq_add(qpq_t *sum, const qpq_t *addend1, const qpq_t *addend2); + +/// Polynomial substraction. +void qpq_sub(qpq_t *difference, const qpq_t *minuend, const qpq_t *substrahend); + +/// Polynomial multiplication. +void qpq_mul(qpq_t product, const qpq_t *multiplier, const qpq_t *multiplicand); + + +/// Polynomial with double coeffs. +typedef struct qpz_t { + int order; + int offset; + int capacity; + double *coeffs; +} qpz_t; + +/// Initiasise the coefficients array in qpz_t. +void qpz_init(qpz_t *x, int maxorder); + +/// Deinitialise the coefficients array in qpz_t. +void qpz_clear(qpz_t *x); + +/// Polynomial addition. +void qpz_add(qpz_t *sum, const qpz_t *addend1, const qpz_t *addend2); + +/// Polynomial substraction. +void qpz_sub(qpz_t *difference, const qpz_t *minuend, const qpz_t *substrahend); + +/// Polynomial multiplication. +void qpz_mul(qpz_t product, const qpz_t *multiplier, const qpz_t *multiplicand); + +/// Convert rational coefficient polynomial to double coefficient polynomial +void qpz_from_qpq(qpz_t *target, const qpq_t *src); + + + +/// Table with pre-calculated Ferrers function coeffs. +typedef struct qpms_legendre_table_t { + qpms_l_t lMax; + // TODO +} qpms_legendre_table_t; + +/// Constructor for qpms_legendre_table_t. +qpms_legendre_table_t *qpms_legendre_table_init(qpms_l_t lMax); + +/// Destructor for qpms_legendre_table_t. +void qpms_legendre_table_free(qpms_legendre_table_t *); + +/// Evaluates a Ferrers function. +double qpms_legendre_table_eval(const qpms_legendre_table_t *, + qpms_l_t l, qpms_m_t m, double x); + + +// TODO pre-calculate also the products?? + +#endif //QPMS_POLYNOMIALS_H