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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
// file: kratpoly.h
// update: 10/04/02
#ifndef _KRATPOLY_H
#define _KRATPOLY_H
#include <cassert>
#include <cstdlib>
#include <iostream>
#include "bigrational.h"
#include "bigrational_vector.h"
#include "bigrational_matrix.h"
#include "kfloatpoly.h"
using namespace std;
class K_POINT1D;
class K_POINT2D;
class K_CURVE;
class K_RATPOLY
{
// A class for representing polynomials with bigrational coefficients
//friend class PseudorootList;
friend class ROOT1;
friend class K_POINT1D;
friend class K_POINT2D;
friend class K_CURVE;
friend class K_SURF;
friend class K_PATCH;
friend class K_SOLID;
unsigned long num_vars; // number of variables
long* deg; // max. degrees in variables
unsigned long num_coeffs; // number of coefficients
bigrational* coeffs;
K_RATPOLY* Sturm_seq; // pointer to the Sturm sequence
unsigned long ref_count; // reference counter
// stream
ostream& output(ostream&) const;
// primitive
// long* index_to_powers(const unsigned long i) const
// returns p = (p[0], p1[1], ..., p[num_vars - 1]) s.t.
// coeffs[i] is the coefficient of the monomial X^p of *this.
long* index_to_powers(const unsigned long) const;
// unsigned long index_to_deg(const unsigned long i) const
// returns t s.t.
// coeffs[i] is the coefficient of the monomial of *this of degree t.
unsigned long index_to_deg(const unsigned long) const;
// unsigned long powers_to_index(const long* const p) const
// returns i s.t.
// coeffs[i] is the coefficient of the monomial X^p of *this.
unsigned long powers_to_index(const long* const) const;
// K_RATPOLY add_var(const unsigned long i) const
// returns a polynomial of num_vars + 1 variables of degree
// deg[0], deg[1], ..., deg[i - 1], 0, deg[i], ..., deg[num_vars - 1].
// e.g. add_variable(1) applied to P(X, Y) returns P(X, Z, Y).
K_RATPOLY add_var(const unsigned long) const;
// K_RATPOLY remove_var(const unsigned long i) const
// PROVIDED deg[i] == 0,
// returns a polynomial of num_vars - 1 variables of degree
// deg[0], deg[1], ..., deg[i - 1], deg[i + 1], ..., deg[num_vars - 1].
// e.g. remove_variable(2) applied to P(X, Y, Z) returns P(X, Y)
// provided deg_Z P(X, Y, Z) == 0.
K_RATPOLY remove_var(const unsigned long) const;
// arithmetic
K_RATPOLY add(const K_RATPOLY&) const;
K_RATPOLY sub(const K_RATPOLY&) const;
K_RATPOLY mul(const K_RATPOLY&) const;
K_RATPOLY mul(const bigrational&) const;
K_RATPOLY neg() const;
K_RATPOLY exact_div(const K_RATPOLY&) const;
// comparison
// int cmp(const K_RATPOLY& P) const
// returns 0 if *this and P are the same. i.e.,
// deg and coeffs of *this and P are the same, and
// returns non-0 otherwise.
int cmp(const K_RATPOLY&) const;
// evaluation
// K_RATPOLY subst_val_first_var_proto(const bigrational& b,
// const int reduced) const
// returns a polynomial of num_vars - 1 variables obtained by
// computing *this(b, X_1, ..., X_{num_vars - 1}), and
// renaming X_1, ..., X_{num_vars - 1} to X_0, X_1, ..., X_{num_vars - 2}.
// reduce_deg() is applied if reduced == 1.
K_RATPOLY subst_val_first_var_proto(const bigrational&, const int) const;
// int fp_sgn_at(const bigrational& b) const
// PROVIDED *this is a univariate polynomial,
// returns 1 if *this(b) is certainly positive,
// - 1 if *this(b) is certainly negative, and
// 0 otherwise.
int fp_sgn_at(const bigrational&) const;
// K_RATPOLY subst_val_proto(const unsigned long i, const bigrational& b,
// const int reduced) const
// returns a polynomial of num_vars - 1 variables obtained by
// computing
// *this(X_0, X_1, ..., X_{i - 1}, b, X_{i + 1}, ..., X_{num_vars - 1})
// and, renaming X_{i + 1}, ..., X_{num_vars - 1} to
// X_i, ..., X_{num_vars - 2}.
// reduce_deg() is applied if reduced == 1.
K_RATPOLY subst_val_proto(const unsigned long, const bigrational&,
const int) const;
// univariate algebra
// K_RATPOLY div(const K_RATPLOY& P, K_RATPOLY& R) const
// PROVIDED *this and P are univariate polynomials,
// computes univariate polynomials Q and R s.t.
// *this = P * Q + R with deg R < deg P
// returns Q.
K_RATPOLY div(const K_RATPOLY&, K_RATPOLY&) const;
// // K_RATPOLY* set_Sturm_seq()
// // PROVIDED *this is a univariate polynomial,
// // generates Sturm sequence of *this.
//
// K_RATPOLY* set_Sturm_seq();
// K_RATPOLY gcd1(const K_RATPOLY& P) const
// PROVIDED *this and P are univariate polynomials,
// returns their gcd computed by using Euclidean algorithm.
K_RATPOLY gcd1(const K_RATPOLY&) const;
// bigrational Sylvester1(const K_RATPOLY& P) const
// PROVIDED *this and P are univariate polynomials,
// returns Sylvester resultant for *this and P.
bigrational Sylvester1(const K_RATPOLY&) const;
K_RATPOLY monic() const;
K_RATPOLY monic_gcd1(const K_RATPOLY&) const;
// bivariate algebra
// K_RATPOLY Sylvester2(const K_RATPOLY& P, const unsigned long i) const
// PROVIDED *this and P are bivariate polynomials,
// returns Sylvester resultant for *this and P w.r.t. X_i.
K_RATPOLY Sylvester2(const K_RATPOLY&, const unsigned long) const;
K_RATPOLY gcd2_pp(const K_RATPOLY&) const;
K_RATPOLY gcd2(const K_RATPOLY&) const;
// K_RATPOLY GoodSylvester(const K_RATPOLY& P, const unsigned long i) const
// PROVIDED *this and P are bivariate polynomials,
// returns Sylvetser resultant for *this and P w.r.t. X_i.
K_RATPOLY GoodSylvester(const K_RATPOLY&, const unsigned long) const;
public:
// constructors, assignment and destructor
// K_RATPOLY()
// constructs a zero polynomial.
K_RATPOLY();
// K_RATPOLY(const unsigned long nv, const long* d)
// constructs a polynomial
// of nv variables of degree d[0], d[1], ..., d[nv - 1]
// with anonymous coefficients.
K_RATPOLY(const unsigned long, const long* const);
// K_RATPOLY(const unsigned long nv, const long* const d,
// const unsigned long nc, const bigrational* const c)
// constructs a polynomial
// of nv variables of degree d[0], d[1], ..., d[nv - 1]
// with coefficients c[0], c[1], ..., c[nc - 1].
K_RATPOLY(const unsigned long, const long* const,
const unsigned long, const bigrational* const);
// K_RATPOLY(const unsigned long nv,
// const unsigned long i, const bigrational b)
// constructs a polynomial X_i - b of nv variables.
K_RATPOLY(const unsigned long n, const unsigned long i,
const bigrational& b);
K_RATPOLY(const K_RATPOLY&);
K_RATPOLY& operator =(const K_RATPOLY&);
~K_RATPOLY();
// stream
friend ostream& operator <<(ostream&, const K_RATPOLY&);
// primitive
// unsigned long get_num_vars() const
// returns the number of variables of *this.
unsigned long get_num_vars() const;
// unsigned long get_total_deg() const
// returns the total degree of *this.
unsigned long get_total_deg() const;
// bigrational& get_coeff(const long* const p) const
// returns the coefficient of the monomial X^p of *this.
bigrational& get_coeff(const long* const) const;
// int reduce_deg()
// reduces deg[0], deg[1], ..., deg[num_vars - 1]
// to max. degrees in X_0, X_1, ..., X_{num_vars - 1}, resp.
// returns 1 if some deg[i] is reduced, and
// 0 otherwise.
int reduce_deg();
int reduce_num_coeffs();
// Make all the coefficients to integers.
int reduce_coeffs();
// Make all the coefficients to integers.
// arithmetic
friend K_RATPOLY operator +(const K_RATPOLY&, const K_RATPOLY&);
friend K_RATPOLY operator -(const K_RATPOLY&, const K_RATPOLY&);
friend K_RATPOLY operator *(const K_RATPOLY&, const K_RATPOLY&);
friend K_RATPOLY operator *(const K_RATPOLY&, const bigrational&);
friend K_RATPOLY operator *(const bigrational&, const K_RATPOLY&);
friend K_RATPOLY operator -(const K_RATPOLY&);
// K_RATPOLY exact_div(const K_RATPOLY& P1, const K_RATPOLY& P2)
// returns P1 / P2 PROVIDED P1 is divisible by P2.
friend K_RATPOLY exact_div(const K_RATPOLY&, const K_RATPOLY&);
// K_RATPOLY derivative(const unsigned long i) const
// returns the partial derivative of *this w.r.t. X_i.
K_RATPOLY derivative(const unsigned long) const;
// comparison
friend int operator ==(const K_RATPOLY&, const K_RATPOLY&);
// int is_zero() const
// returns 1 if *this is a zero polynomial, and
// 0 otherwise.
int is_zero() const;
// int eq_upto_const(const K_RATPOLY& P) const
// returns 1 if *this == P * b for some bigrational b, and
// 0 otherwise.
int eq_upto_const(const K_RATPOLY&) const;
// evaluation
// K_RATPOLY subst_val_first_var(const bigrational& b) const
// returns a polynomial of num_vars - 1 variables obtained by
// computing *this(b, X_1, ..., X_{num_vars - 1}), and
// renaming X_1, ..., X_{num_vars - 1} to X_0, X_1, ..., X_{num_vars - 2}.
K_RATPOLY subst_val_first_var(const bigrational&) const;
// bigrational evaluate(const bigrational& b) const
// returns *this(b) PROVIDED *this is a univariate polynomial.
bigrational evaluate(const bigrational&) const;
// bigrational evaluate(const bigrational* const B) const
// returns *this(B[0], B[1], ..., B[num_vars - 1]).
bigrational evaluate(const bigrational* const) const;
// bigrational evaluate(const bigrational_vector& B) const
// returns *this(B[0], B[1], ..., B[num_vars - 1]).
bigrational evaluate(const bigrational_vector&) const;
// int sgn_at(const bigrational& b) const
// PROVIDED *this is a univariate polynomial,
// returns the sign of *this(b).
int sgn_at(const bigrational&) const;
// int sgn_at(const bigrational* const B) const
// PROVIDED *this is a univariate polynomial,
// returns the sign of *this(B[0], B[1], ..., B[num_vars - 1]).
int sgn_at(const bigrational* const) const;
// int sgn_at(const bigrational_vector& B) const
// PROVIDED *this is a univariate polynomial,
// returns the sign of *this(B[0], B[1], ..., B[num_vars - 1]).
int sgn_at(const bigrational_vector&) const;
// K_RATPOLY subst_val(const unsigned long i, const bigrational& b) const
// returns a polynomial of num_vars - 1 variables obtained by
// computing
// *this(X_0, X_1, ..., X_{i - 1}, b, X_{i + 1}, ..., X_{num_vars - 1})
// and, renaming
// X_{i + 1}, ..., X_{num_vars - 1} to X_i, ..., X_{num_vars - 2}.
K_RATPOLY subst_val(const unsigned long, const bigrational&) const;
// K_RATPOLY subst_expr(const unsigned long i, const K_RATPOLY& P) const
// returns a polynomial of num_vars - 1 variables obtained by
// computing
// *this(X_0, X_1, ..., X_{i - 1},
// P (X_0, X_1, ..., X_{i - 1}, X_{i + 1}, X_{num_vars - 1}),
// X_{i + 1}, ..., X_{num_vars - 1})
// and, renaming
// X_{i + 1}, ..., X_{num_vars - 1} to X_i, ..., X_{num_vars - 2}.
K_RATPOLY subst_expr(const unsigned long, const K_RATPOLY&) const;
// K_RATPOLY subst_expr(const unsigned long i,
// const K_RATPOLY& N, const K_RATPOLY& D) const
// returns a polynomial of num_vars - 1 variables obtained by
// computing
// *this(X_0, X_1, ..., X_{i - 1},
// N/D (X_0, X_1, ..., X_{i - 1}, X_{i + 1}, X_{num_vars - 1}),
// X_{i + 1}, ..., X_{num_vars - 1})
// and, renaming
// X_{i + 1}, ..., X_{num_vars - 1} to X_i, ..., X_{num_vars - 2}.
K_RATPOLY subst_expr(const unsigned long,
const K_RATPOLY&, const K_RATPOLY&) const;
// K_RATPOLY subst_param_expr(const K_RATPOLY& X,
// const K_RATPOLY& Y,
// const K_RATPOLY& Z,
// const K_RATPOLY& W) const
// PROVIDED *this is a 3-variate polynomial and
// X, Y, Z, W are bivariate polynomials,
// returns *this(X/W, Y/W, Z/W).
K_RATPOLY subst_param_expr(const K_RATPOLY& X,
const K_RATPOLY& Y,
const K_RATPOLY& Z,
const K_RATPOLY& W) const;
// other
// int eval_range(const bigrational* const low_in,
// const bigrational* const high_in,
// bigrational& low_out,
// bigrational& high_out)
// computes the range [low_out, high_out]
// which *this is evaluated at some value in [low_in, high_in]
// using affine arithmetic.
int eval_range(const bigrational* const low_in,
const bigrational* const high_in,
bigrational& low_out,
bigrational& high_out);
// int eval_range(const bigrational_vector& low_in,
// const bigrational_vector& high_in,
// bigrational& low_out,
// bigrational& high_out)
// computes the range [low_out, high_out]
// which *this is evaluated at some value in [low_in, high_in]
// using affine arithmetic.
int eval_range(const bigrational_vector& low_in,
const bigrational_vector& high_in,
bigrational& low_out,
bigrational& high_out);
// K_FLOATPOLY as_FLOATPOLY() const
// returns a polynomial whose coefficients are
// floating point approximations of those of *this.
K_FLOATPOLY as_FLOATPOLY() const;
K_RATPOLY conv_to_Bernstein(const long, const long) const;
// univariate algebra
// K_RATPOLY div(const K_RATPOLY& P1, const K_RATPLOY& P2,
// K_RATPOLY& R) const
// PROVIDED P1 and P2 are univariate polynomials,
// computes univariate polynomials Q and R s.t.
// P1 = P2 * Q + R with deg R < deg P2
// returns Q.
friend K_RATPOLY div(const K_RATPOLY&, const K_RATPOLY&, K_RATPOLY&);
friend K_RATPOLY operator /(const K_RATPOLY&, const K_RATPOLY&);
friend K_RATPOLY rem(const K_RATPOLY&, const K_RATPOLY&);
// K_RATPOLY* set_Sturm_seq()
// PROVIDED *this is a univariate polynomial,
// generates Sturm sequence of *this.
K_RATPOLY* set_Sturm_seq();
// long num_Sturm_seq_perm(const bigrational& b) const
// PROVIDED *this is a univariate polynomial,
// returns
// the number of sign permanencies in the Sturm sequence of *this at b.
long num_Sturm_seq_perm(const bigrational&) const;
// bigrational get_Mignotte_bd() const
// PROVIDED *this is a univariate polynomial,
// returns an upper bound on the size of the largest root of *this.
bigrational get_Mignotte_bd() const;
// univariate and bivariate algebra
// K_RATPOLY gcd(const K_RATPOLY& P1, const K_RATPOLY& P2)
// PROVIDED P1 and P2 are uni or bivariate polynomials,
// returns their gcd.
friend K_RATPOLY gcd(const K_RATPOLY&, const K_RATPOLY&);
// bigrational Sylvester1(const K_RATPOLY& P1, const K_RATPOLY& P2) const
// PROVIDED P1 and P2 are univariate polynomials,
// returns Sylvester resultant for P1 and P2.
friend bigrational Sylvester1(const K_RATPOLY&, const K_RATPOLY&);
// bivariate algebra
// K_RATPOLY GoodSylvester(const K_RATPOLY& P1, const K_RATPOLY& P2,
// const unsigned long i) const
// PROVIDED P1 and P2 are bivariate polynomials,
// returns Sylvetser resultant for P1 and P2 w.r.t. X_i.
friend K_RATPOLY GoodSylvester(const K_RATPOLY&, const K_RATPOLY&,
const unsigned long i);
// get_pts(): get algebraic points
friend unsigned long get_pts(const bigrational&, const bigrational&,
const K_RATPOLY&,
K_POINT1D**&,
const bigrational&, const int);
friend unsigned long get_pts(const bigrational&, const bigrational&,
const bigrational&, const bigrational&,
const K_RATPOLY&, const K_RATPOLY&,
K_POINT2D**&,
const bigrational&, const int);
friend unsigned long get_pts_interior(const bigrational&, const bigrational&,
const bigrational&, const bigrational&,
const K_RATPOLY&, const K_RATPOLY&,
K_POINT2D**&,
const bigrational&);
friend int refine_interior(K_POINT1D* const, K_POINT1D* const,
const K_RATPOLY&, const K_RATPOLY&,
K_POINT2D*&,
const bigrational&);
friend unsigned long get_pts_proto(const bigrational&, const bigrational&,
const K_RATPOLY&,
const bigrational&,
const K_RATPOLY&, const K_RATPOLY&,
K_POINT2D**&,
const bigrational&, const int);
friend unsigned long get_pts_proto(const bigrational&,
const bigrational&, const bigrational&,
const K_RATPOLY&,
const K_RATPOLY&, const K_RATPOLY&,
K_POINT2D**&,
const bigrational&, const int);
// gen_curve_topo()
friend unsigned long gen_curve_topo(const K_RATPOLY&,
const bigrational&, const bigrational&,
const bigrational&, const bigrational&,
K_CURVE**&);
friend unsigned long gen_curve_topo_proto(const K_RATPOLY&,
const bigrational&,
const bigrational&,
const bigrational&,
const bigrational&,
K_POINT2D** const,
const unsigned long,
K_POINT2D** const,
const unsigned long,
K_POINT2D** const,
const unsigned long,
K_POINT2D** const,
const unsigned long,
K_POINT2D** const,
const unsigned long,
K_POINT2D** const,
const unsigned long,
K_CURVE**&);
friend int implicitize(const K_RATPOLY&,
const K_RATPOLY&,
const K_RATPOLY&,
const K_RATPOLY&,
const long,
K_RATPOLY*&);
// gen_box(), gen_cyl(), gen_ell(), gen_tor()
friend int get_param_tor(const bigrational_vector&,
const bigrational_vector&,
const bigrational_vector&,
const bigrational_vector&,
const bigrational&, const bigrational&,
K_RATPOLY*&, K_RATPOLY*&, K_RATPOLY*&, K_RATPOLY*&);
K_RATPOLY transform_Impl(const bigrational_matrix&) const;
// friend K_RATPOLY read_poly(istream&);
};
K_RATPOLY read_poly(istream&);
#endif
|