-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathqf_poly.h
134 lines (106 loc) · 4.87 KB
/
qf_poly.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************************
qf_poly.h
----------------
begin : Mon Jan 02 2006
copyright : (C) 2006 by Vincent Habchi, F5RCS
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _QF_POLY_H
#define _QF_POLY_H
/* Headers for R[X] arithmetic */
#include <limits>
#include "qf_common.h"
#undef _QF_POLY_DEBUG
// Setup precision for roots search
# undef extended
# if defined (extended)
# define lcplx Lcplx
# define Longdouble long double
# else
# define lcplx Cplx
# define Longdouble double
# endif
// A polynom is just a valarray of coefficients
// The 'k' and 'dg' variables are always updated and valid
// k == 0 means we are dealing with the null polynom (P = 0)
// dg == 0 means a constant polynom (P = k, k real)
// The pointers may be obsoleted, in which case the array they point to
// is freed and they are set to NULL which means representation invalid
class qf_poly {
private :
unsigned dg; // Current degree
qf_double_t k; // Constant k
qf_coeff *cf; // Array of coefficients
// Functions used by solve
public :
qf_poly (const qf_double_t&, const qf_double_t&,
const qf_double_t&);
qf_poly (qf_coeff*, const qf_double_t&,
const unsigned);
qf_poly (const qf_poly&);
~qf_poly (void);
// access operators
qf_poly& operator = (const qf_poly&); // P = Q
// arithmetic operators
qf_poly operator - (void); // Unary -
qf_poly& operator += (const qf_poly&);
qf_poly& operator += (const qf_double_t&);
qf_poly& operator -= (const qf_poly&);
qf_poly& operator -= (const qf_double_t&);
friend qf_poly operator * (qf_poly&, qf_poly&);
friend qf_poly operator * (const qf_poly&, const qf_double_t&);
qf_poly& operator *= (const qf_poly&); // P(X) = P(X)*Q(X)
qf_poly& operator *= (const qf_double_t&);
qf_poly operator << (const unsigned); // Basic div by X^n
qf_poly operator >> (const unsigned); // Multiply by X^n
bool operator == (const qf_poly&); // Test
bool operator != (const qf_poly&); // Test
bool is_null (void) {return (k == 0);}
unsigned deg (void) {return dg;} // Degree of poly
unsigned val (void); // Valuation
void fdeg (void); // Find the new order
unsigned fdeg (const qf_coeff*); // Other form
qf_poly odd (void); // Odd part
qf_poly even (void); // Even part
void slfodd (void); // Odd part
void slfeven (void); // Even part
qf_poly mnx (void); // P(X) -> P(-X)
qf_poly hsq (void); // P(X)*P(-X)
qf_poly sqr (void); // Q(X) = P(X^2)
qf_double_t eval (const qf_double_t&); // P(X = a)
qf_double_t evalX2 (const qf_double_t&); // P(X^2 = a)
qf_poly rvs (void);
qf_double_t pk (void) {return k;} // Return k factor
qf_double_t lnt (void); // Lowest non-zero term
bool div (const Cplx&); // Simple division
void hurw (void); // "Hurwitzes" polynom
void scale (const qf_double_t&); // Scales polynom
void nrm (unsigned); // Scales to p[0]=1
void zerod (void); // P[dg(P)] = 0
void zerov (void); // P[val(P)] = 0
void cabs (void); // Q(X) = |a(i)| x^i
bool rroot (qf_double_t&); // Returns 1st real root
qf_poly intgrt (void); // Integrates
qf_poly rond (qf_poly&); // P(Q(X)) = Q o P(X)
void coeff (qf_roots&); // Compute cf from roots
void roots (qf_roots&); // Find all roots
void p_and_dp (lcplx&, lcplx&, lcplx&); // P(z) & P'(z)
bool newton (lcplx&); // Roots enhancement
void disp (const string); // Prints P(X)
void disp_cf (void);
void disp_rt (void);
};
qf_poly operator + (qf_poly&, qf_poly&);
qf_poly operator + (qf_poly&, qf_double_t&);
qf_poly operator - (qf_poly&, qf_poly&);
qf_double_t setroottol (qf_double_t&);
qf_double_t setrootprec (qf_double_t&);
#endif // _QF_POLY_H