07-Jan-2022 22:42:23 legendre_product_polynomial_test(): MATLAB/Octave version 9.8.0.1380330 (R2020a) Update 2 Test legendre_product_polynomial() I4VEC_PRINT_TEST I4VEC_PRINT prints an I4VEC The I4VEC: 1: 91 2: 92 3: 93 4: 94 R8VEC_PRINT_TEST R8VEC_PRINT prints an R8VEC. The R8VEC: 1: 123.456 2: 5e-06 3: -1e+06 4: 3.14159 COMP_ENUM_TEST(): COMP_ENUM counts compositions; 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 1 3 6 10 15 21 28 36 45 55 1 4 10 20 35 56 84 120 165 220 1 5 15 35 70 126 210 330 495 715 1 6 21 56 126 252 462 792 1287 2002 1 7 28 84 210 462 924 1716 3003 5005 1 8 36 120 330 792 1716 3432 6435 11440 1 9 45 165 495 1287 3003 6435 12870 24310 1 10 55 220 715 2002 5005 11440 24310 48620 1 11 66 286 1001 3003 8008 19448 43758 92378 COMP_NEXT_GRLEX_TEST A COMP is a composition of an integer N into K parts. Each part is nonnegative. The order matters. COMP_NEXT_GRLEX determines the next COMP in graded lexicographic (grlex) order. Rank: NC COMP ----: -- ------------ 1: 0 = 0 + 0 + 0 ----: -- ------------ 2: 1 = 0 + 0 + 1 3: 1 = 0 + 1 + 0 4: 1 = 1 + 0 + 0 ----: -- ------------ 5: 2 = 0 + 0 + 2 6: 2 = 0 + 1 + 1 7: 2 = 0 + 2 + 0 8: 2 = 1 + 0 + 1 9: 2 = 1 + 1 + 0 10: 2 = 2 + 0 + 0 ----: -- ------------ 11: 3 = 0 + 0 + 3 12: 3 = 0 + 1 + 2 13: 3 = 0 + 2 + 1 14: 3 = 0 + 3 + 0 15: 3 = 1 + 0 + 2 16: 3 = 1 + 1 + 1 17: 3 = 1 + 2 + 0 18: 3 = 2 + 0 + 1 19: 3 = 2 + 1 + 0 20: 3 = 3 + 0 + 0 ----: -- ------------ 21: 4 = 0 + 0 + 4 22: 4 = 0 + 1 + 3 23: 4 = 0 + 2 + 2 24: 4 = 0 + 3 + 1 25: 4 = 0 + 4 + 0 26: 4 = 1 + 0 + 3 27: 4 = 1 + 1 + 2 28: 4 = 1 + 2 + 1 29: 4 = 1 + 3 + 0 30: 4 = 2 + 0 + 2 31: 4 = 2 + 1 + 1 32: 4 = 2 + 2 + 0 33: 4 = 3 + 0 + 1 34: 4 = 3 + 1 + 0 35: 4 = 4 + 0 + 0 ----: -- ------------ 36: 5 = 0 + 0 + 5 37: 5 = 0 + 1 + 4 38: 5 = 0 + 2 + 3 39: 5 = 0 + 3 + 2 40: 5 = 0 + 4 + 1 41: 5 = 0 + 5 + 0 42: 5 = 1 + 0 + 4 43: 5 = 1 + 1 + 3 44: 5 = 1 + 2 + 2 45: 5 = 1 + 3 + 1 46: 5 = 1 + 4 + 0 47: 5 = 2 + 0 + 3 48: 5 = 2 + 1 + 2 49: 5 = 2 + 2 + 1 50: 5 = 2 + 3 + 0 51: 5 = 3 + 0 + 2 52: 5 = 3 + 1 + 1 53: 5 = 3 + 2 + 0 54: 5 = 4 + 0 + 1 55: 5 = 4 + 1 + 0 56: 5 = 5 + 0 + 0 ----: -- ------------ 57: 6 = 0 + 0 + 6 58: 6 = 0 + 1 + 5 59: 6 = 0 + 2 + 4 60: 6 = 0 + 3 + 3 61: 6 = 0 + 4 + 2 62: 6 = 0 + 5 + 1 63: 6 = 0 + 6 + 0 64: 6 = 1 + 0 + 5 65: 6 = 1 + 1 + 4 66: 6 = 1 + 2 + 3 67: 6 = 1 + 3 + 2 68: 6 = 1 + 4 + 1 69: 6 = 1 + 5 + 0 70: 6 = 2 + 0 + 4 71: 6 = 2 + 1 + 3 COMP_RANDOM_GRLEX_TEST A COMP is a composition of an integer N into K parts. Each part is nonnegative. The order matters. COMP_RANDOM_GRLEX selects a random COMP in graded lexicographic (grlex) order between indices RANK1 and RANK2. 53: 5 = 3 + 2 + 0 57: 6 = 0 + 0 + 6 25: 4 = 0 + 4 + 0 57: 6 = 0 + 0 + 6 45: 5 = 1 + 3 + 1 COMP_RANK_GRLEX_TEST A COMP is a composition of an integer N into K parts. Each part is nonnegative. The order matters. COMP_RANK_GRLEX determines the rank of a COMP from its parts. Actual Inferred Test Rank Rank 1 23 23 2 31 31 3 42 42 4 59 59 5 59 59 COMP_UNRANK_GRLEX_TEST A COMP is a composition of an integer N into K parts. Each part is nonnegative. The order matters. COMP_UNRANK_GRLEX determines the parts of a COMP from its rank. Rank: -> NC COMP ----: -- ------------ 1: 0 = 0 + 0 + 0 ----: -- ------------ 2: 1 = 0 + 0 + 1 3: 1 = 0 + 1 + 0 4: 1 = 1 + 0 + 0 ----: -- ------------ 5: 2 = 0 + 0 + 2 6: 2 = 0 + 1 + 1 7: 2 = 0 + 2 + 0 8: 2 = 1 + 0 + 1 9: 2 = 1 + 1 + 0 10: 2 = 2 + 0 + 0 ----: -- ------------ 11: 3 = 0 + 0 + 3 12: 3 = 0 + 1 + 2 13: 3 = 0 + 2 + 1 14: 3 = 0 + 3 + 0 15: 3 = 1 + 0 + 2 16: 3 = 1 + 1 + 1 17: 3 = 1 + 2 + 0 18: 3 = 2 + 0 + 1 19: 3 = 2 + 1 + 0 20: 3 = 3 + 0 + 0 ----: -- ------------ 21: 4 = 0 + 0 + 4 22: 4 = 0 + 1 + 3 23: 4 = 0 + 2 + 2 24: 4 = 0 + 3 + 1 25: 4 = 0 + 4 + 0 26: 4 = 1 + 0 + 3 27: 4 = 1 + 1 + 2 28: 4 = 1 + 2 + 1 29: 4 = 1 + 3 + 0 30: 4 = 2 + 0 + 2 31: 4 = 2 + 1 + 1 32: 4 = 2 + 2 + 0 33: 4 = 3 + 0 + 1 34: 4 = 3 + 1 + 0 35: 4 = 4 + 0 + 0 ----: -- ------------ 36: 5 = 0 + 0 + 5 37: 5 = 0 + 1 + 4 38: 5 = 0 + 2 + 3 39: 5 = 0 + 3 + 2 40: 5 = 0 + 4 + 1 41: 5 = 0 + 5 + 0 42: 5 = 1 + 0 + 4 43: 5 = 1 + 1 + 3 44: 5 = 1 + 2 + 2 45: 5 = 1 + 3 + 1 46: 5 = 1 + 4 + 0 47: 5 = 2 + 0 + 3 48: 5 = 2 + 1 + 2 49: 5 = 2 + 2 + 1 50: 5 = 2 + 3 + 0 51: 5 = 3 + 0 + 2 52: 5 = 3 + 1 + 1 53: 5 = 3 + 2 + 0 54: 5 = 4 + 0 + 1 55: 5 = 4 + 1 + 0 56: 5 = 5 + 0 + 0 ----: -- ------------ 57: 6 = 0 + 0 + 6 58: 6 = 0 + 1 + 5 59: 6 = 0 + 2 + 4 60: 6 = 0 + 3 + 3 61: 6 = 0 + 4 + 2 62: 6 = 0 + 5 + 1 63: 6 = 0 + 6 + 0 64: 6 = 1 + 0 + 5 65: 6 = 1 + 1 + 4 66: 6 = 1 + 2 + 3 67: 6 = 1 + 3 + 2 68: 6 = 1 + 4 + 1 69: 6 = 1 + 5 + 0 70: 6 = 2 + 0 + 4 71: 6 = 2 + 1 + 3 mono_next_grlex_test MONO_NEXT_GRLEX computes the next monomial in M variables, in graded lexicographic order. Let M = 4 0 3 3 1 0 3 4 0 0 4 0 3 0 4 1 2 0 4 2 1 0 4 3 0 2 1 2 0 2 2 0 1 2 2 1 0 2 3 0 0 3 0 0 2 3 0 1 1 3 3 0 1 3 3 1 0 3 4 0 0 4 0 0 3 4 0 1 2 4 0 2 1 2 0 3 1 2 0 4 0 2 1 0 3 2 1 1 2 2 1 2 1 2 1 3 0 3 1 0 1 3 1 1 0 3 2 0 0 4 0 0 1 4 0 1 0 4 1 0 0 0 0 2 3 0 0 3 2 0 0 4 1 0 0 5 0 0 1 0 4 0 1 1 3 1 2 2 2 1 2 3 1 1 2 4 0 1 3 0 3 1 3 1 2 1 3 2 1 0 3 3 3 0 3 4 2 0 3 5 1 0 3 6 0 0 4 0 5 0 4 1 4 2 0 3 2 2 0 4 1 2 0 5 0 2 1 0 4 2 1 1 3 2 1 2 2 1 1 1 3 1 1 2 2 1 1 3 1 1 1 4 0 1 2 0 3 1 2 1 2 MONO_PRINT_TEST MONO_PRINT can print out a monomial. Monomial [5]:x^(5). Monomial [5]:x^(-5). Monomial [2,1,0,3]:x^(2,1,0,3). Monomial [17,-3,199]:x^(17,-3,199). mono_rank_grlex_test MONO_RANK_GRLEX returns the rank of a monomial under the grlex ordering, in the sequence of all monomials in M dimensions of degree N or less. Print a monomial sequence with ranks assigned. Let M = 3 N = 4 1: 0 0 0 2: 0 0 1 3: 0 1 0 4: 1 0 0 5: 0 0 2 6: 0 1 1 7: 0 2 0 8: 1 0 1 9: 1 1 0 10: 2 0 0 11: 0 0 3 12: 0 1 2 13: 0 2 1 14: 0 3 0 15: 1 0 2 16: 1 1 1 17: 1 2 0 18: 2 0 1 19: 2 1 0 20: 3 0 0 21: 0 0 4 22: 0 1 3 23: 0 2 2 24: 0 3 1 25: 0 4 0 26: 1 0 3 27: 1 1 2 28: 1 2 1 29: 1 3 0 30: 2 0 2 31: 2 1 1 32: 2 2 0 33: 3 0 1 34: 3 1 0 35: 4 0 0 Now, given a monomial, retrieve its rank in the sequence: (Should get 1, 2, 4, 8, 16, 32, 64 and 128.) 1: 0 0 0 4: 1 0 0 2: 0 0 1 7: 0 2 0 15: 1 0 2 24: 0 3 1 77: 3 2 1 158: 5 2 1 mono_unrank_grlex_test MONO_UNRANK_GRLEX is given a rank, and returns the corresponding monomial in the sequence of all monomials in M dimensions in grlex order. For reference, print a monomial sequence with ranks. Let M = 3 N = 4 1: 0 0 0 2: 0 0 1 3: 0 1 0 4: 1 0 0 5: 0 0 2 6: 0 1 1 7: 0 2 0 8: 1 0 1 9: 1 1 0 10: 2 0 0 11: 0 0 3 12: 0 1 2 13: 0 2 1 14: 0 3 0 15: 1 0 2 16: 1 1 1 17: 1 2 0 18: 2 0 1 19: 2 1 0 20: 3 0 0 21: 0 0 4 22: 0 1 3 23: 0 2 2 24: 0 3 1 25: 0 4 0 26: 1 0 3 27: 1 1 2 28: 1 2 1 29: 1 3 0 30: 2 0 2 31: 2 1 1 32: 2 2 0 33: 3 0 1 34: 3 1 0 35: 4 0 0 Now choose random ranks between 1 and 35: 9: 1 1 0 13: 0 2 1 29: 1 3 0 1: 0 0 0 2: 0 0 1 mono_upto_enum_test MONO_UPTO_ENUM can enumerate the number of monomials in M variables, of total degree 0 up to N. N: 0 1 2 3 4 5 6 7 8 M +------------------------------------------------------ 1 | 1 2 3 4 5 6 7 8 9 2 | 1 3 6 10 15 21 28 36 45 3 | 1 4 10 20 35 56 84 120 165 4 | 1 5 15 35 70 126 210 330 495 5 | 1 6 21 56 126 252 462 792 1287 6 | 1 7 28 84 210 462 924 1716 3003 7 | 1 8 36 120 330 792 1716 3432 6435 8 | 1 9 45 165 495 1287 3003 6435 12870 mono_upto_next_grlex_test MONO_UPTO_NEXT_GRLEX can list the monomials in M variables, of total degree up to N, one at a time, in graded lexicographic order. We start the process with (0,0,...0,0). The process ends with (N,0,...,0,0) Let M = 3 N = 4 1: 0 0 0 2: 0 0 1 3: 0 1 0 4: 1 0 0 5: 0 0 2 6: 0 1 1 7: 0 2 0 8: 1 0 1 9: 1 1 0 10: 2 0 0 11: 0 0 3 12: 0 1 2 13: 0 2 1 14: 0 3 0 15: 1 0 2 16: 1 1 1 17: 1 2 0 18: 2 0 1 19: 2 1 0 20: 3 0 0 21: 0 0 4 22: 0 1 3 23: 0 2 2 24: 0 3 1 25: 0 4 0 26: 1 0 3 27: 1 1 2 28: 1 2 1 29: 1 3 0 30: 2 0 2 31: 2 1 1 32: 2 2 0 33: 3 0 1 34: 3 1 0 35: 4 0 0 Let M = 4 N = 3 1: 0 0 0 0 2: 0 0 0 1 3: 0 0 1 0 4: 0 1 0 0 5: 1 0 0 0 6: 0 0 0 2 7: 0 0 1 1 8: 0 0 2 0 9: 0 1 0 1 10: 0 1 1 0 11: 0 2 0 0 12: 1 0 0 1 13: 1 0 1 0 14: 1 1 0 0 15: 2 0 0 0 16: 0 0 0 3 17: 0 0 1 2 18: 0 0 2 1 19: 0 0 3 0 20: 0 1 0 2 21: 0 1 1 1 22: 0 1 2 0 23: 0 2 0 1 24: 0 2 1 0 25: 0 3 0 0 26: 1 0 0 2 27: 1 0 1 1 28: 1 0 2 0 29: 1 1 0 1 30: 1 1 1 0 31: 1 2 0 0 32: 2 0 0 1 33: 2 0 1 0 34: 2 1 0 0 35: 3 0 0 0 mono_upto_random_test MONO_UPTO_RANDOM selects at random a monomial in M dimensions of total degree no greater than N. Let M = 3 N = 4 6: 0 1 1 23: 0 2 2 26: 1 0 3 23: 0 2 2 16: 1 1 1 mono_value_test MONO_VALUE evaluates a monomial. Let M = 3 N = 6 M(X) = x^(1,4,0). M(1,2,3) = 16 M(-2,4,1) = -512 M(X) = x^(0,4,0). M(1,2,3) = 16 M(-2,4,1) = 256 M(X) = x^(0,6,0). M(1,2,3) = 64 M(-2,4,1) = 4096 M(X) = x^(1,1,1). M(1,2,3) = 6 M(-2,4,1) = -8 M(X) = x^(0,1,5). M(1,2,3) = 486 M(-2,4,1) = 4 POLYNOMIAL_PRINT_TEST POLYNOMIAL_PRINT prints a polynomial. Uncompressed P(X) = + 7 * x^(0,0,0) - 5 * x^(0,0,1) + 5 * x^(0,0,1) + 9 * x^(1,0,0) + 11 * x^(0,0,2) + 3 * x^(0,0,2) + 6 * x^(0,0,2) + 0 * x^(0,1,2) - 13 * x^(3,0,1) + 1e-20 * x^(4,0,0). Compressed P(X) = + 7 * x^(0,0,0) + 0 * x^(0,0,1) + 9 * x^(1,0,0) + 20 * x^(0,0,2) - 13 * x^(3,0,1). POLYNOMIAL_PRINT_TEST(): POLYNOMIAL_PRINT prints a polynomial. P1(X) = + 7 * x^(0,0,0) - 5 * x^(0,0,1) + 9 * x^(1,0,0) + 11 * x^(0,0,2) + 0 * x^(0,1,2) - 13 * x^(3,0,1). POLYNOMIAL_SORT_TEST() POLYNOMIAL_SORT sorts a polynomial by exponent index. Unsorted polynomial: + 0 * x^(0,1,2) + 9 * x^(1,0,0) - 5 * x^(0,0,1) - 13 * x^(3,0,1) + 7 * x^(0,0,0) + 11 * x^(0,0,2). Sorted polynomial: + 7 * x^(0,0,0) - 5 * x^(0,0,1) + 9 * x^(1,0,0) + 11 * x^(0,0,2) + 0 * x^(0,1,2) - 13 * x^(3,0,1). POLYNOMIAL_VALUE_TEST POLYNOMIAL_VALUE evaluates a polynomial. P(X) = + 7 * x^(0,0,0) - 5 * x^(0,0,1) + 9 * x^(1,0,0) + 11 * x^(0,0,2) + 0 * x^(0,1,2) - 13 * x^(3,0,1). P(1,2,3) = 61 P(-2,4,1) = 99 LP_COEFFICIENTS_TEST LP_COEFFICIENTS: coefficients of Legendre polynomial P(n,x). P(0,x) = + 1 * x^(0). P(1,x) = + 1 * x^(1). P(2,x) = - 0.5 * x^(0) + 1.5 * x^(2). P(3,x) = - 1.5 * x^(1) + 2.5 * x^(3). P(4,x) = + 0.375 * x^(0) - 3.75 * x^(2) + 4.375 * x^(4). P(5,x) = + 1.875 * x^(1) - 8.75 * x^(3) + 7.875 * x^(5). P(6,x) = - 0.3125 * x^(0) + 6.5625 * x^(2) - 19.6875 * x^(4) + 14.4375 * x^(6). P(7,x) = - 2.1875 * x^(1) + 19.6875 * x^(3) - 43.3125 * x^(5) + 26.8125 * x^(7). P(8,x) = + 0.273438 * x^(0) - 9.84375 * x^(2) + 54.1406 * x^(4) - 93.8438 * x^(6) + 50.2734 * x^(8). P(9,x) = + 2.46094 * x^(1) - 36.0938 * x^(3) + 140.766 * x^(5) - 201.094 * x^(7) + 94.9609 * x^(9). P(10,x) = - 0.246094 * x^(0) + 13.5352 * x^(2) - 117.305 * x^(4) + 351.914 * x^(6) - 427.324 * x^(8) + 180.426 * x^(10). LP_VALUE_TEST(): LP_VALUE evaluates a Legendre polynomial. Tabulated Computed O X L(O,X) L(O,X) Error 0 0.250000 1 1 0 1 0.250000 0.25 0.25 0 2 0.250000 -0.40625 -0.40625 0 3 0.250000 -0.335938 -0.335938 0 4 0.250000 0.157715 0.157715 0 5 0.250000 0.339722 0.339722 0 6 0.250000 0.0242767 0.0242767 0 7 0.250000 -0.279919 -0.279919 0 8 0.250000 -0.152454 -0.152454 -2.77556e-17 9 0.250000 0.176824 0.176824 0 10 0.250000 0.2212 0.2212 2.77556e-17 3 0.000000 0 -0 0 3 0.100000 -0.1475 -0.1475 0 3 0.200000 -0.28 -0.28 0 3 0.300000 -0.3825 -0.3825 0 3 0.400000 -0.44 -0.44 -5.55112e-17 3 0.500000 -0.4375 -0.4375 0 3 0.600000 -0.36 -0.36 5.55112e-17 3 0.700000 -0.1925 -0.1925 1.11022e-16 3 0.800000 0.08 0.08 -2.22045e-16 3 0.900000 0.4725 0.4725 -1.11022e-16 3 1.000000 1 1 0 LP_VALUES_TEST(): LP_VALUES stores values of the Legendre polynomial P(o,x). Tabulated O X L(O,X) 0 0.250000 1 1 0.250000 0.25 2 0.250000 -0.40625 3 0.250000 -0.335938 4 0.250000 0.157715 5 0.250000 0.339722 6 0.250000 0.0242767 7 0.250000 -0.279919 8 0.250000 -0.152454 9 0.250000 0.176824 10 0.250000 0.2212 3 0.000000 0 3 0.100000 -0.1475 3 0.200000 -0.28 3 0.300000 -0.3825 3 0.400000 -0.44 3 0.500000 -0.4375 3 0.600000 -0.36 3 0.700000 -0.1925 3 0.800000 0.08 3 0.900000 0.4725 3 1.000000 1 LPP_TO_POLYNOMIAL_TEST: LPP_TO_POLYNOMIAL is given a Legendre product polynomial and determines its polynomial representation. Using spatial dimension M = 2: LPP #1 = L(0,X)*L(0,Y) = + 1 * x^(0,0). LPP #2 = L(0,X)*L(1,Y) = + 1 * x^(0,1). LPP #3 = L(1,X)*L(0,Y) = + 1 * x^(1,0). LPP #4 = L(0,X)*L(2,Y) = - 0.5 * x^(0,0) + 1.5 * x^(0,2). LPP #5 = L(1,X)*L(1,Y) = + 1 * x^(1,1). LPP #6 = L(2,X)*L(0,Y) = - 0.5 * x^(0,0) + 1.5 * x^(2,0). LPP #7 = L(0,X)*L(3,Y) = - 1.5 * x^(0,1) + 2.5 * x^(0,3). LPP #8 = L(1,X)*L(2,Y) = - 0.5 * x^(1,0) + 1.5 * x^(1,2). LPP #9 = L(2,X)*L(1,Y) = - 0.5 * x^(0,1) + 1.5 * x^(2,1). LPP #10 = L(3,X)*L(0,Y) = - 1.5 * x^(1,0) + 2.5 * x^(3,0). LPP #11 = L(0,X)*L(4,Y) = + 0.375 * x^(0,0) - 3.75 * x^(0,2) + 4.375 * x^(0,4). LPP_VALUE_TEST: LPP_VALUE evaluates a Legendre product polynomial. Evaluate at X = ( -0.632978, -0.263031, 0.251237 ) Rank I1 I2 I3: L(I1,X1)*L(I2,X2)*L(I3,X3) P(X1,X2,X3) 1 0 0 0 1 1 2 0 0 1 0.251237 0.251237 3 0 1 0 -0.263031 -0.263031 4 1 0 0 -0.632978 -0.632978 5 0 0 2 -0.40532 -0.40532 6 0 1 1 -0.0660831 -0.0660831 7 0 2 0 -0.396222 -0.396222 8 1 0 1 -0.159027 -0.159027 9 1 1 0 0.166493 0.166493 10 2 0 0 0.100991 0.100991 11 0 0 3 -0.33721 -0.33721 12 0 1 2 0.106612 0.106612 13 0 2 1 -0.0995457 -0.0995457 14 0 3 0 0.349052 0.349052 15 1 0 2 0.256558 0.256558 16 1 1 1 0.0418291 0.0418291 17 1 2 0 0.2508 0.2508 18 2 0 1 0.0253727 0.0253727 19 2 1 0 -0.0265638 -0.0265638 20 3 0 0 0.315443 0.315443 legendre_product_polynomial_test(): Normal end of execution. 07-Jan-2022 22:42:23