1 /* 2 * This file is part of MPSolve 3.2.1 3 * 4 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa. 5 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher 6 * 7 * Authors: 8 * Leonardo Robol <leonardo.robol@unipi.it> 9 */ 10 11 #ifndef MPS_MONOMIAL_POLY_H_ 12 #define MPS_MONOMIAL_POLY_H_ 13 14 /** 15 * @file 16 * @brief Implementation of the allocation and edit functions for the 17 * handling of monomial polynomials. 18 */ 19 20 21 #include <mps/polynomial.h> 22 #include <mps/mps.h> 23 #include <gmp.h> 24 #include <pthread.h> 25 26 #define MPS_MONOMIAL_POLY(t) (MPS_POLYNOMIAL_CAST (mps_monomial_poly, t)) 27 #define MPS_IS_MONOMIAL_POLY(t) (mps_polynomial_check_type (t, "mps_monomial_poly")) 28 29 MPS_BEGIN_DECLS 30 31 #ifdef _MPS_PRIVATE 32 33 struct mps_monomial_poly_double_buffer { 34 char active; 35 mpc_t *mfpc1; 36 mpc_t *mfpc2; 37 }; 38 39 40 /** 41 * @brief Data regarding a polynomial represented in the monomial 42 * base. 43 */ 44 struct mps_monomial_poly { 45 /** 46 * @brief Implementation of the methods. 47 */ 48 struct mps_polynomial methods; 49 50 struct mps_monomial_poly_double_buffer db; 51 52 /** 53 * @brief This array contains the structure of the sparse 54 * polynomial. 55 * 56 * <code>spar[i]</code> is <code>true</code> if and only if 57 * the i-th coefficients of the polynomial is a non-zero 58 * coefficients 59 */ 60 mps_boolean *spar; 61 62 /** 63 * @brief Standard real coefficients. 64 */ 65 double *fpr; 66 67 /** 68 * @brief Standard complex coefficients. 69 */ 70 cplx_t *fpc; 71 72 /** 73 * @brief Array containing standard complex coefficients 74 */ 75 cplx_t *fppc; 76 77 /** 78 * @brief Dpe real coefficients. 79 */ 80 rdpe_t *dpr; 81 82 /** 83 * @brief Dpe complex coefficients. 84 */ 85 cdpe_t *dpc; 86 87 /** 88 * @brief Multiprecision real coefficients. 89 */ 90 mpf_t *mfpr; 91 92 /** 93 * @brief Multiprecision complex coefficients. 94 */ 95 mpc_t *mfpc; 96 97 /** 98 * @brief Array of mutexes that need to be locked when reading at the 99 * i-th compoenent of the poly. 100 */ 101 pthread_mutex_t * mfpc_mutex; 102 103 /** 104 * @brief Multiprecision complex coefficients of \f$p'(x)\f$. 105 */ 106 mpc_t *mfppc; 107 108 /** 109 * @brief Array containing moduli of the coefficients as double numbers. 110 */ 111 double *fap; 112 113 /** 114 * @brief Array containing moduli of the coefficients as dpe numbers. 115 */ 116 rdpe_t *dap; 117 118 /** 119 * @brief Real part of rational input coefficients. 120 */ 121 mpq_t *initial_mqp_r; 122 123 /** 124 * @brief Imaginary part of rational input coefficients. 125 */ 126 mpq_t *initial_mqp_i; 127 128 /** 129 * @brief This mutex must be locked while regenerating the coefficients 130 * of the polynomial. 131 */ 132 pthread_mutex_t regenerating; 133 134 /** 135 * @brief Precision of the polynomial coefficients. 136 */ 137 long int prec; 138 }; 139 #endif /* #ifdef _MPS_PRIVATE */ 140 141 /* These routines are thought for polynomial handling, i.e. allocating and 142 * setting coefficients of the polynomials, and setting the precision of the 143 * floating point coefficients that are in there */ 144 145 mps_monomial_poly * mps_monomial_poly_new (mps_context * s, long int degree); 146 147 void mps_monomial_poly_free (mps_context * s, mps_polynomial * mp); 148 149 long int mps_monomial_poly_get_precision (mps_context * s, mps_monomial_poly * mp); 150 151 long int mps_monomial_poly_raise_precision (mps_context * s, mps_polynomial * mp, long int prec); 152 153 void mps_monomial_poly_set_coefficient_q (mps_context * s, mps_monomial_poly * mp, long int i, 154 mpq_t real_part, mpq_t imag_part); 155 void mps_monomial_poly_set_coefficient_d (mps_context * s, mps_monomial_poly * mp, long int i, 156 double real_part, double imag_part); 157 void mps_monomial_poly_set_coefficient_f (mps_context * s, mps_monomial_poly * p, long int i, 158 mpc_t coeff); 159 void mps_monomial_poly_set_coefficient_int (mps_context * s, mps_monomial_poly * mp, long int i, 160 long long real_part, long long imag_part); 161 162 void mps_monomial_poly_set_coefficient_s (mps_context * s, mps_monomial_poly * p, 163 int i, const char * real_coeff, 164 const char * imag_coeff); 165 166 void mps_monomial_poly_get_coefficient_d (mps_context * s, mps_monomial_poly * p, 167 int i, cplx_t output); 168 169 void mps_monomial_poly_get_coefficient_q (mps_context * s, mps_monomial_poly * p, 170 int i, mpq_t real_output, mpq_t imag_output); 171 172 mps_monomial_poly * mps_monomial_poly_derive (mps_context * s, mps_monomial_poly * p, int k, long int wp); 173 174 mps_boolean mps_monomial_poly_feval (mps_context * ctx, mps_polynomial *p, cplx_t x, cplx_t value, double * error); 175 176 mps_boolean mps_monomial_poly_deval (mps_context * ctx, mps_polynomial *p, cdpe_t x, cdpe_t value, rdpe_t error); 177 178 mps_boolean mps_monomial_poly_meval (mps_context * ctx, mps_polynomial *p, mpc_t x, mpc_t value, rdpe_t error); 179 180 void mps_monomial_poly_fstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations); 181 182 void mps_monomial_poly_dstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations); 183 184 void mps_monomial_poly_mstart (mps_context * ctx, mps_polynomial * p, mps_approximation ** approximations); 185 186 void mps_monomial_poly_fnewton (mps_context * ctx, mps_polynomial * p, 187 mps_approximation * root, cplx_t corr); 188 189 void mps_monomial_poly_dnewton (mps_context * ctx, mps_polynomial * p, 190 mps_approximation * root, cdpe_t corr); 191 192 void mps_monomial_poly_mnewton (mps_context * ctx, mps_polynomial * p, 193 mps_approximation * root, mpc_t corr, long int wp); 194 195 void mps_monomial_poly_get_leading_coefficient (mps_context * ctx, mps_polynomial * p, 196 mpc_t leading_coefficient); 197 198 void mps_monomial_poly_deflate (mps_context * ctx, mps_polynomial * p); 199 200 mps_monomial_poly * mps_monomial_poly_read_from_stream (mps_context * s, mps_input_buffer * buffer, 201 mps_structure structure, mps_density density, 202 long int precision); 203 204 MPS_END_DECLS 205 206 #endif 207