Monomial Indexing

Get/set individual monomial coefficients

Individual monomial coefficients in a TPS can be get/set with two methods of indexing: by order, and by sparse monomial.

By Order

t[[<var_1 order>, ..., <var_N order>,<param_1 order>, ..., <param_M order>]]
t[(<var_1 order>, ..., <var_N order>,<param_1 order>, ..., <param_M order>)]

A particular monomial can be indexed by specifying the orders of each variable and parameter. For example, for a TPS t with variables $x_1$, $x_2$ and parameters $k_1$, $k_2$, the $x_1^3x_2^1k_1^2$ monomial coefficient is accessed with t[[3,1,2,0]] or equivalently t[[3,1,2]], as leaving out trailing zeros for unincluded variables/parameters is allowed. A tuple is also allowed instead of a vector for the list of orders.

Examples


julia> d = Descriptor(2, 6, 3, 6); # 2 variables, 3 parameters all to 6th order
julia> x = vars(d);
julia> k = params(d);
julia> f = 5 + sin(x[1])*sin(x[2])*cos(k[1])TPS64: Coefficient Order Exponent 5.0000000000000000e+00 0 0 0 | 0 0 0 1.0000000000000000e+00 2 1 1 | 0 0 0 -1.6666666666666666e-01 4 3 1 | 0 0 0 -1.6666666666666666e-01 4 1 3 | 0 0 0 -5.0000000000000000e-01 4 1 1 | 2 0 0 8.3333333333333332e-03 6 5 1 | 0 0 0 2.7777777777777776e-02 6 3 3 | 0 0 0 8.3333333333333332e-03 6 1 5 | 0 0 0 8.3333333333333329e-02 6 3 1 | 2 0 0 8.3333333333333329e-02 6 1 3 | 2 0 0 4.1666666666666664e-02 6 1 1 | 4 0 0
julia> f[[3,1,2]] # Leave out trailing zeros for unincluded variables/parameters0.08333333333333333
julia> f[[0]] # Scalar part5.0
julia> f[(1,1,1,1,1)] = 123; # Set monomial coefficient
julia> print(f)TPS64: Coefficient Order Exponent 5.0000000000000000e+00 0 0 0 | 0 0 0 1.0000000000000000e+00 2 1 1 | 0 0 0 -1.6666666666666666e-01 4 3 1 | 0 0 0 -1.6666666666666666e-01 4 1 3 | 0 0 0 -5.0000000000000000e-01 4 1 1 | 2 0 0 1.2300000000000000e+02 5 1 1 | 1 1 1 8.3333333333333332e-03 6 5 1 | 0 0 0 2.7777777777777776e-02 6 3 3 | 0 0 0 8.3333333333333332e-03 6 1 5 | 0 0 0 8.3333333333333329e-02 6 3 1 | 2 0 0 8.3333333333333329e-02 6 1 3 | 2 0 0 4.1666666666666664e-02 6 1 1 | 4 0 0

By Sparse Monomial

t[[<ix_var> => <order>, ...], params=[<ix_param> => <order>, ...]]
t[(<ix_var> => <order>, ...), params=(<ix_param> => <order>, ...)]

In GTPSAs with many variables and parameters, indexing-by-order is inconvenient because each order needs to be included up to the last included variable/parameter with nonzero order. In this case, a particular monomial can be indexed instead by specifying each variable/parameter number and its corresponding order in pairs. For example, for a TPS with variables $x_1, ..., x_{15}$ and parameters $k_1, ..., k_{10}$, the $x_{1}^3x_{15}^1k_{10}^2$ monomial coefficient is accessed with t[[1=>3, 15=>1], params=[10=>2]]. The scalar part of the TPS cannot be get/set with this method. A tuple is also allowed instead of a vector for the list of pairs.

Examples


julia> d = Descriptor(15, 6, 10, 6); # 15 variables, 10 parameters all to 6th order
julia> GTPSA.show_sparse = true; # Use sparse output
julia> x = vars(d);
julia> k = params(d);
julia> f = 5 + sin(x[1])*sin(x[15])*cos(k[10])TPS64: Coefficient Order Monomial 5.0000000000000000e+00 0 1 1.0000000000000000e+00 2 (x₁)¹ (x₁₅)¹ -1.6666666666666666e-01 4 (x₁)³ (x₁₅)¹ -1.6666666666666666e-01 4 (x₁)¹ (x₁₅)³ -5.0000000000000000e-01 4 (x₁)¹ (x₁₅)¹ (k₁₀)² 8.3333333333333332e-03 6 (x₁)⁵ (x₁₅)¹ 2.7777777777777776e-02 6 (x₁)³ (x₁₅)³ 8.3333333333333332e-03 6 (x₁)¹ (x₁₅)⁵ 8.3333333333333329e-02 6 (x₁)³ (x₁₅)¹ (k₁₀)² 8.3333333333333329e-02 6 (x₁)¹ (x₁₅)³ (k₁₀)² 4.1666666666666664e-02 6 (x₁)¹ (x₁₅)¹ (k₁₀)⁴
julia> f[[1=>3, 15=>1], params=[10=>2]]0.08333333333333333
julia> f[(1=>1, 15=>2), params=(10=>3,)] = 123; # Set monomial coefficient
julia> print(f)TPS64: Coefficient Order Monomial 5.0000000000000000e+00 0 1 1.0000000000000000e+00 2 (x₁)¹ (x₁₅)¹ -1.6666666666666666e-01 4 (x₁)³ (x₁₅)¹ -1.6666666666666666e-01 4 (x₁)¹ (x₁₅)³ -5.0000000000000000e-01 4 (x₁)¹ (x₁₅)¹ (k₁₀)² 8.3333333333333332e-03 6 (x₁)⁵ (x₁₅)¹ 2.7777777777777776e-02 6 (x₁)³ (x₁₅)³ 8.3333333333333332e-03 6 (x₁)¹ (x₁₅)⁵ 8.3333333333333329e-02 6 (x₁)³ (x₁₅)¹ (k₁₀)² 8.3333333333333329e-02 6 (x₁)¹ (x₁₅)³ (k₁₀)² 1.2300000000000000e+02 6 (x₁)¹ (x₁₅)² (k₁₀)³ 4.1666666666666664e-02 6 (x₁)¹ (x₁₅)¹ (k₁₀)⁴

By Monomial Index

t[idx]
t[param=param_idx]

This indexing method is not recommended/requires care when indexing monomials above first order. Indexes the TPS with all monomials sorted by order. For example, for a TPS with one variable $x_1$ and one parameter $k_1$ the $x_1$ monomial is indexed with t[1] and the $x_1^2$ monomial is indexed with either t[3]. The $k_1$ monomial can be indexed with either t[2] or equivalently using the param helper kwarg t[param=1], which simply adds the number of variables in the GTPSA to the provided index. Note that above first-order, the param kwarg is basically useless. The zeroth order part, or the scalar part of the TPS, can be set with t[0]. This method requires zero allocations for indexing, unlike the other two.

Examples

julia> # Example of indexing by monomial index -----------false
julia> d = Descriptor(2, 10, 1, 10);
julia> t = TPS(use=d); # Create zero TPS based on d
julia> t[0] = 0;
julia> t[1] = 1;
julia> t[2] = 2;
julia> t[3] = 3; # or t[param=1] = 3
julia> t[4] = 4;
julia> t[5] = 5;
julia> t[6] = 6;
julia> t[7] = 7;
julia> t[8] = 8;
julia> t[9] = 9;
julia> t[10] = 10;
julia> print(t)TPS64: Coefficient Order Exponent 1.0000000000000000e+00 1 1 0 | 0 2.0000000000000000e+00 1 0 1 | 0 3.0000000000000000e+00 1 0 0 | 1 4.0000000000000000e+00 2 2 0 | 0 5.0000000000000000e+00 2 1 1 | 0 6.0000000000000000e+00 2 0 2 | 0 7.0000000000000000e+00 2 1 0 | 1 8.0000000000000000e+00 2 0 1 | 1 9.0000000000000000e+00 2 0 0 | 2 1.0000000000000000e+01 3 3 0 | 0