forked from johannesgerer/jburkardt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonomial.html
463 lines (414 loc) · 13.8 KB
/
monomial.html
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
<html>
<head>
<title>
MONOMIAL - Multivariate Monomials
</title>
</head>
<body bgcolor="#eeeeee" link="#cc0000" alink="#ff3300" vlink="#000055">
<h1 align = "center">
MONOMIAL <br> Multivariate Monomials
</h1>
<hr>
<p>
<b>MONOMIAL</b>
is a C++ library which
enumerates, lists, ranks, unranks and randomizes multivariate monomials
in a space of D dimensions, with total degree less than N,
equal to N, or lying within a given range.
</p>
<p>
A (univariate) monomial in 1 variable x is simply any (nonnegative integer) power of x:
<pre>
1, x, x^2, x^3, ...
</pre>
The exponent of x is termed the degree of the monomial.
</p>
<p>
Since any polynomial p(x) can be written as
<pre>
p(x) = c(0) * x^0 + c(1) * x^1 + c(2) * x^2 + ... + c(n) * x^n
</pre>
we may regard the monomials as a natural basis for the space of
polynomials, in which case the coefficients may be regarded as
the coordinates of the polynomial.
</p>
<p>
A (multivariate) monomial in D variables x(1), x(2), ..., x(d) is a product of the
form
<pre>
x(1)^e(1) * x(2)^e(2) * ... * x(d)^e(d)
</pre>
where e(1) through e(d) are nonnegative integers. The sum of the
exponents is termed the degree of the monomial.
</p>
<p>
Any polynomial in D variables can be written as a linear
combination of monomials in D variables. The "total degree" of the
polynomial is the maximum of the degrees of the monomials that it
comprises. For instance, a polynomial in D = 2 variables of total
degree 3 might have the form:
<pre>
p(x,y) = c(0,0) x^0 y^0
+ c(1,0) x^1 y^0 + c(0,1) x^0 y^1
+ c(2,0) x^2 y^0 + c(1,1) x^1 y^1 + c(0,2) x^0 y^2
+ c(3,0) x^3 y^0 + c(2,1) x^2 y^1 + c(1,2) x^1 y^2 + c(0,3) x^0 y^3
</pre>
The monomials in D variables can be regarded as
a natural basis for the polynomials in D variables.
</p>
<p>
For multidimensional polynomials, a number of orderings are possible.
Two common orderings are "grlex" (graded lexicographic) and
"grevlex" (graded reverse lexicographic). Once an ordering is imposed,
each monomial in D variables has a rank, and it is possible to ask (and answer!) the
following questions:
<p>
<li>
How many monomials are there in D dimensions, of degree N, or
up to and including degree N, or between degrees N1 and N2?
</li>
<li>
Can you list in rank order the monomials in D dimensions, of degree N, or
up to and including degree N, or between degrees N1 and N2?
</li>
<li>
Given a monomial in D dimensions, can you determine the rank
it holds in the list of all such monomials?
</li>
<li>
Given a rank, can you determine the monomial in D dimensions
that occupies that position in the list of all such monomials?
</li>
<li>
Can you select at random a monomial in D dimensions from the set
of all such monomials of degree up to N?
</li>
</p>
</p>
<p>
As mentioned, two common orderings for monomials are "grlex" (graded lexicographic) and
"grevlex" (graded reverse lexicographic).
The word "graded" in both names indicates that, for both orderings,
one monomial is "less" than another if its total degree is less.
Thus, for both orderings, xyz^2 is less than y^5 because a monomial of
degree 4 is less than a monomial of degree 5.
</p>
<p>
But what happens when we compare two monomials of the same degree?
For the lexicographic ordering, one monomial is less than another if its
vector of exponents is lexicographically less. Given two vectors
v1=(x1,y1,z1) and v2=(x2,y2,z2), v1 is less than v2 if
<ul>
<li>
x1 is less than x2;
</li>
<li>
or x1 = x2, but y1 is less than y2;
</li>
<li>
or x1 = x2, and y1 = y2, but z1 is less than z2;
</li>
</ul>
(For a graded ordering, the third case can't occur, since we have
assumed the two monomials have the same degree, and hence the
exponents have the same sum.)
</p>
<p>
Thus, for the grlex ordering, we first order by degree, and then
for two monomials of the same degree, we use the lexicographic ordering.
Here is how the grlex ordering would arrange monomials in D=3 dimensions.
<pre>
# monomial expon
-- --------- -----
1 1 0 0 0
2 z 0 0 1
3 y 0 1 0
4 x 1 0 0
5 z^2 0 0 2
6 y z 0 1 1
7 y^2 0 2 0
8 x z 1 0 1
9 x y 1 1 0
10 x^2 2 0 0
11 z^3 0 0 3
12 y z^2 0 1 2
13 y^2z 0 2 1
14 y^3 0 3 0
15 x z^2 1 0 2
16 x y z 1 1 1
17 x y^2 1 2 0
18 x^2 z 2 0 1
19 x^2y 2 1 0
20 x^3 3 0 0
21 z^4 0 0 4
22 y z^3 0 1 3
23 y^2z^2 0 2 2
24 y^3z 0 3 1
25 y^4 0 4 0
26 x z^3 1 0 3
27 x y z^2 1 1 2
28 x y^2z 1 2 1
29 x y^3 1 3 0
30 x^2 z^2 2 0 2
31 x^2y z 2 1 1
32 x^2y^2 2 2 0
33 x^3 z 3 0 1
34 x^3y 3 1 0
35 x^4 4 0 0
36 z^5 0 0 5
... ......... .....
</pre>
</p>
<p>
For the reverse lexicographic ordering, given two vectors,
v1=(x1,y1,z1) and v2=(x2,y2,z2), v1 is less than v2 if:
<ul>
<li>
z1 is greater than z2;
</li>
<li>
or z1 = z2 but y1 is greater than y2;
</li>
<li>
or z1 = z2, and y1 = y2, but x1 is greater than x2.
</li>
</ul>
(For a graded ordering, the third case can't occur, since we have
assumed the two monomials have the same degree, and hence the
exponents have the same sum.)
</p>
<p>
Thus, for the grevlex ordering, we first order by degree, and then
for two monomials of the same degree, we use the reverse lexicographic ordering.
Here is how the grevlex ordering would arrange monomials in D=3 dimensions.
<pre>
# monomial expon
-- --------- -----
1 1 0 0 0
2 z 0 0 1
3 y 0 1 0
4 x 1 0 0
5 z^2 0 0 2
6 y z 0 1 1
7 x z 1 0 1
8 y^2 0 2 0
9 x y 1 1 0
10 x^2 2 0 0
11 z^3 0 0 3
12 y z^2 0 1 2
13 x z^2 1 0 2
14 y^2z 0 2 1
15 x y z 1 1 1
16 x^2 z 2 0 1
17 y^3 0 3 0
18 x y^2 1 2 0
19 x^2y 2 1 0
20 x^3 3 0 0
21 z^4 0 0 4
22 y z^3 0 1 3
23 x z^3 1 0 3
24 y^2z^2 0 2 2
25 x y z^2 1 1 2
26 x^2 z^2 2 0 2
27 y^3z^1 0 3 1
28 x y^2z 1 2 1
29 x^2y z 2 1 1
30 x^3 z 3 0 1
31 y^4 0 4 0
32 x y^3 1 3 0
33 x^2y^2 2 2 0
34 x^3y 3 1 0
35 x^4 4 0 0
36 z^5 0 0 5
... ......... .....
</pre>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>MONOMIAL</b> is available in
<a href = "../../c_src/monomial/monomial.html">a C version</a> and
<a href = "../../cpp_src/monomial/monomial.html">a C++ version</a> and
<a href = "../../f77_src/monomial/monomial.html">a FORTRAN77 version</a> and
<a href = "../../f_src/monomial/monomial.html">a FORTRAN90 version</a> and
<a href = "../../m_src/monomial/monomial.html">a MATLAB version</a> and
<a href = "../../py_src/monomial/monomial.html">a Python version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../cpp_src/combo/combo.html">
COMBO</a>,
a C++ library which
includes routines for ranking, unranking, enumerating and
randomly selecting balanced sequences, cycles, graphs, Gray codes,
subsets, partitions, permutations, restricted growth functions,
Pruefer codes and trees.
</p>
<p>
<a href = "../../cpp_src/hermite_product_polynomial/hermite_product_polynomial.html">
HERMITE_PRODUCT_POLYNOMIAL</a>,
a C++ library which
defines Hermite product polynomials, creating a multivariate
polynomial as the product of univariate Hermite polynomials.
</p>
<p>
<a href = "../../cpp_src/legendre_product_polynomial/legendre_product_polynomial.html">
LEGENDRE_PRODUCT_POLYNOMIAL</a>,
a C++ library which
defines Legendre product polynomials, creating a multivariate
polynomial as the product of univariate Legendre polynomials.
</p>
<p>
<a href = "../../cpp_src/polynomial/polynomial.html">
POLYNOMIAL</a>,
a C++ library which
adds, multiplies, differentiates, evaluates and prints multivariate
polynomials in a space of M dimensions.
</p>
<p>
<a href = "../../cpp_src/set_theory/set_theory.html">
SET_THEORY</a>,
a C++ library which
demonstrates MATLAB commands that implement various
set theoretic operations.
</p>
<p>
<a href = "../../cpp_src/subset/subset.html">
SUBSET</a>,
a C++ library which
enumerates, generates, ranks and unranks combinatorial objects
including combinations, compositions, Gray codes, index sets, partitions,
permutations, subsets, and Young tables.
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "monomial.cpp">monomial.cpp</a>, the source code.
</li>
<li>
<a href = "monomial.hpp">monomial.hpp</a>, the include file.
</li>
<li>
<a href = "monomial.sh">monomial.sh</a>,
BASH commands to compile the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<ul>
<li>
<a href = "monomial_prb.cpp">monomial_prb.cpp</a>,
a sample calling program.
</li>
<li>
<a href = "monomial_prb.sh">monomial_prb.sh</a>,
BASH commands to compile and run the sample program.
</li>
<li>
<a href = "monomial_prb_output.txt">monomial_prb_output.txt</a>,
the output file.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>I4_CHOOSE</b> computes the binomial coefficient C(N,K).
</li>
<li>
<b>I4_MAX</b> returns the maximum of two I4's.
</li>
<li>
<b>I4_MIN</b> returns the minimum of two I4's.
</li>
<li>
<b>I4_UNIFORM_AB</b> returns a scaled pseudorandom I4 between A and B.
</li>
<li>
<b>I4VEC_PRINT</b> prints an I4VEC.
</li>
<li>
<b>I4VEC_SUM</b> sums the entries of an I4VEC.
</li>
<li>
<b>MONO_BETWEEN_ENUM</b> enumerates monomials in D dimensions of degrees in a range.
</li>
<li>
<b>MONO_BETWEEN_NEXT_GREVLEX:</b> grevlex next monomial with total degree between N1 and N2.
</li>
<li>
<b>MONO_BETWEEN_NEXT_GRLEX:</b> grlex next monomial, degree between N1 and N2.
</li>
<li>
<b>MONO_BETWEEN_RANDOM:</b> random monomial with total degree between N1 and N2.
</li>
<li>
<b>MONO_RANK_GREVLEX</b> returns the grevlex rank of a monomial in D dimensions.
</li>
<li>
<b>MONO_TOTAL_ENUM</b> enumerates monomials in D dimensions of degree equal to N.
</li>
<li>
<b>MONO_TOTAL_NEXT_GREVLEX:</b> grevlex next monomial with total degree equal to N.
</li>
<li>
<b>MONO_TOTAL_NEXT_GRLEX:</b> grlex next monomial with total degree equal to N.
</li>
<li>
<b>MONO_TOTAL_RANDOM:</b> random monomial with total degree equal to N.
</li>
<li>
<b>MONO_UNRANK_GREVLEX</b> returns the monomial in D dimensions of given grevlex rank.
</li>
<li>
<b>MONO_UPTO_ENUM</b> enumerates monomials in D dimensions of degree up to N.
</li>
<li>
<b>MONO_UPTO_NEXT_GREVLEX:</b> grevlex next monomial with total degree up to N.
</li>
<li>
<b>MONO_UPTO_NEXT_GRLEX:</b> grlex next monomial with total degree up to N.
</li>
<li>
<b>MONO_UPTO_RANDOM:</b> random monomial with total degree less than or equal to N.
</li>
<li>
<b>RANK_DEGREE_GREVLEX</b> finds the degree of a monomial of given grevlex rank.
</li>
<li>
<b>TIMESTAMP</b> prints the current YMDHMS date as a time stamp.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../cpp_src.html">
the C++ source codes</a>.
</p>
<hr>
<i>
Last revised on 20 November 2013.
</i>
<!-- John Burkardt -->
</body>
<!-- Initial HTML skeleton created by HTMLINDEX. -->
</html>