Slicing and par
Indexing a specific polynomial within the TPS
Slicing a TPS
A polynomial within the TPS with certain variable orders can be extracted by slicing the TPS. When indexing by order, a colon (:
) can be used in place for a variable order to include all orders of that variable. If the last specified index is a colon, then the rest of the variable indices are assumed to be colons (else, they are assumed to be zero, following the convention of monomial coefficient indexing).
julia> d = Descriptor(5, 10, 2, 10);
julia> x = vars(d);
julia> k = params(d);
julia> f = 2*x[1]^2*x[3] + 3*x[1]^2*x[2]*x[3]*x[4]^2*x[5]*k[1] + 6*x[3] + 5
TPS64: Coefficient Order Exponent 5.0000000000000000e+00 0 0 0 0 0 0 | 0 0 6.0000000000000000e+00 1 0 0 1 0 0 | 0 0 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0 3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
julia> g = f[[2,:,1]]
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0
julia> h = f[[2,:,1,:]]
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0 3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
A TPS can also be sliced with indexing by sparse monomial. In this case, if a colon is included anywhere in the sparse monomial variable index, then all orders of all variables and parameters not explicity specified will be included (colon position does not matter in sparse monomial indexing):
julia> g = f[[1=>2, :, 3=>1, 4=>0, 5=>0], params=[1=>0, 2=>0]]
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0
julia> h = f[(1=>2, 3=>1, :)] # Colon position is irrelevant in slicing with sparse monomial indexing
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0 3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
When indexing by monomial index, a colon simply needs to be included after the variable index, or just a colon if a parameter is specified:
julia> fx3 = f[3,:]
TPS64: Coefficient Order Exponent 6.0000000000000000e+00 1 0 0 1 0 0 | 0 0 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0 3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
julia> fk1 = f[:,param=1]
TPS64: Coefficient Order Exponent 3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
par
par
is very similar to slicing a TPS, with two differences:
- The specified variables and parameters are removed from the resulting slice
- When indexing by order, a colon is always presumed for unincluded variables/parameters
Syntax
f = par(tps, orders)
f = par(tps [, vars_sparse_mono] [, params=params_sparse_mono])
f = par(tps, idx)
f = par(tps, param=param_idx)
Description
Indexing by Order
f = par(tps, orders)
extracts the polynomial from the TPS with the monomial indexed-by-order in orders
, and removes the variables/parameters included in the indexing from the polynomial
Indexing by Sparse Monomial
f = par(tps, vars_sparse_mono)
extracts the polynomial from the TPS with the monomial indexed-by-sparse monomial in vars_sparse_mono
, and removes the variables included in the indexing from the polynomial
f = par(tps, params=params_sparse_mono)
extracts the polynomial from the TPS with the monomial indexed-by-sparse monomial in params_sparse_mono
, and removes the parameters included in the indexing from the polynomial
f = par(tps, vars_sparse_mono, params=params_sparse_mono)
extracts the polynomial from the TPS with the monomial indexed-by-sparse monomial in vars_sparse_mono
and params_sparse_mono
, and removes the variables and/or parameters included in the indexing from the polynomial
Indexing by Monomial Index
f = par(tps, idx)
extracts the polynomial from the TPS with a first-order dependence on the specified monomial, and removes the variable from the polynomial
f = par(tps, param=param_idx)
extracts the polynomial from the TPS with a first-order dependence on the specified monomial with index param_idx+nv
where nv
is the number of variables in the GTPSA, and removes the parameter from the polynomial
Examples
julia> d = Descriptor(5, 10, 2, 10);
julia> x = vars(d);
julia> k = params(d);
julia> f = 2*x[1]^2*x[3] + 3*x[1]^2*x[2]*x[3]*x[4]^2*x[5]*k[1] + 6*x[3] + 5
TPS64: Coefficient Order Exponent 5.0000000000000000e+00 0 0 0 0 0 0 | 0 0 6.0000000000000000e+00 1 0 0 1 0 0 | 0 0 2.0000000000000000e+00 3 2 0 1 0 0 | 0 0 3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
julia> par(f, 3)
TPS64: Coefficient Order Exponent 6.0000000000000000e+00 0 0 0 0 0 0 | 0 0 2.0000000000000000e+00 2 2 0 0 0 0 | 0 0 3.0000000000000000e+00 7 2 1 0 2 1 | 1 0
julia> par(f, param=1)
TPS64: Coefficient Order Exponent 3.0000000000000000e+00 7 2 1 1 2 1 | 0 0
julia> par(f, [2,:,1])
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 0 0 0 0 0 0 | 0 0 3.0000000000000000e+00 5 0 1 0 2 1 | 1 0
julia> par(f, [2,0,1])
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 0 0 0 0 0 0 | 0 0
julia> par(f, [1=>2, 3=>1])
TPS64: Coefficient Order Exponent 2.0000000000000000e+00 0 0 0 0 0 0 | 0 0 3.0000000000000000e+00 5 0 1 0 2 1 | 1 0
julia> par(f, params=[1=>1])
TPS64: Coefficient Order Exponent 3.0000000000000000e+00 7 2 1 1 2 1 | 0 0
Documentation
GTPSA.par
— Functionpar(t::TPS, v::Union{TPSColonIndexType, Vector{Pair{<:Integer,<:Integer}}, Vector{<:Integer}, Integer, Colon, Nothing}=nothing; param::Union{Integer,Nothing}=nothing, params::Union{SMIndexType, Nothing}=nothing)
Extracts a polynomial from the TPS containing the specified monomial, and removes the monomial.
Input
v
– An integer (for variable index), an array/tuple of orders for each variable (for indexing-by-order), or an array/tuple of pairs (sparse monomial)param
– (Keyword argument, optional) An integer for the parameter indexparams
– (Keyword argument, optional) An array of pairs for sparse-monomial indexing
Examples: Variable/Parameter Index:
julia> d = Descriptor(5, 10, 2, 10); x = vars(d); k = params(d);
julia> f = 2*x[1]^2*x[3] + 3*x[1]^2*x[2]*x[3]*x[4]^2*x[5]*k[1] + 6*x[3] + 5
TPS:
Coefficient Order Exponent
5.0000000000000000e+00 0 0 0 0 0 0 | 0 0
6.0000000000000000e+00 1 0 0 1 0 0 | 0 0
2.0000000000000000e+00 3 2 0 1 0 0 | 0 0
3.0000000000000000e+00 8 2 1 1 2 1 | 1 0
julia> par(f, 3)
TPS:
Coefficient Order Exponent
6.0000000000000000e+00 0 0 0 0 0 0 | 0 0
2.0000000000000000e+00 2 2 0 0 0 0 | 0 0
3.0000000000000000e+00 7 2 1 0 2 1 | 1 0
julia> par(f, param=1)
TPS:
Coefficient Order Exponent
3.0000000000000000e+00 7 2 1 1 2 1 | 0 0
Examples: Monomial Index-by-Order
julia> par(f, [2,:,1])
TPS:
Coefficient Order Exponent
2.0000000000000000e+00 0 0 0 0 0 0 | 0 0
3.0000000000000000e+00 5 0 1 0 2 1 | 1 0
julia> par(f, [2,0,1])
TPS:
Coefficient Order Exponent
2.0000000000000000e+00 0 0 0 0 0 0 | 0 0
Examples: Monomial Index-by-Sparse Monomial
julia> par(f, [1=>2, 3=>1])
TPS:
Coefficient Order Exponent
2.0000000000000000e+00 0 0 0 0 0 0 | 0 0
3.0000000000000000e+00 5 0 1 0 2 1 | 1 0
julia> par(f, params=[1=>1])
TPS:
Coefficient Order Exponent
3.0000000000000000e+00 7 2 1 1 2 1 | 0 0