Multiindices
Multi-index sets (exponent vectors) with graded lexicographic (Grlex) ordering. Provides sorted containers, efficient generation, queries, factorizations, and combinatorial counting.
MORFE.Multiindices.FactorisationEntry — Type
FactorisationEntryOne result from a factorisation function: an ordered list of multiindex-set indices (one per factor slot) together with the number of distinct ordered arrangements of that combination.
factor_indices— indices into the multiindex set, one per factor slot.multiplier— number of distinct orderings (permutations) of this combination. Always 1 forfactorisations_asymmetric, which enumerates each ordering as a separate entry.
All three factorisation functions return Vector{FactorisationEntry}, so call sites do not need to know which variant produced the data.
MORFE.Multiindices.MultiindexSet — Type
MultiindexSet{N}A fixed collection of exponent vectors (multiindices) stored as a vector of SVector{N, Int}. The set is guaranteed to be sorted according to the graded lexicographic (Grlex) order.
Fields
exponents::Vector{SVector{N, Int}}: each element is an exponent vector.
MORFE.Multiindices._last_index_below_degree — Method
_last_index_below_degree(set::MultiindexSet, max_total_deg::Int,
allowed_indices::AbstractVector{Int}) -> IntSame as the 2‑argument version, but the search is restricted to the indices listed in allowed_indices (which must be sorted in increasing order). The returned value is still an actual column index (or 0 if none qualifies).
MORFE.Multiindices._last_index_below_degree — Method
_last_index_below_degree(set::MultiindexSet, max_total_deg::Int) -> IntReturn the last column index i in the Grlex‑sorted set such that the total degree of set[i] is strictly less than max_total_deg. If no such index exists, return 0.
MORFE.Multiindices._multinomial — Method
_multinomial(e::Int, k::Vector{Int}) -> IntMultinomial coefficient: e! / (k₁! k₂! … kₚ!) where sum(k) = e. Uses iterative multiplication of binomial coefficients to avoid overflow.
MORFE.Multiindices._sv_eq_tuple — Method
_sv_eq_tuple(v::SVector{N,Int}, t::NTuple{N,Int})Helper functions that compares: SVector ==(indexwise) NTuple
MORFE.Multiindices.all_multiindices_in_box — Method
all_multiindices_in_box(bound::Vector{Int}) -> MultiindexSetGenerate all multi-indices v of length length(bound) such that 0 ≤ v[i] ≤ bound[i] for all i. The vectors are generated and then sorted according to graded lexicographic order.
MORFE.Multiindices.all_multiindices_up_to — Method
all_multiindices_up_to(nvars::Int, max_degree::Int) -> MultiindexSetGenerate all exponent vectors with nvars variables whose total degree ≤ max_degree, sorted according to graded lexicographic order. Returns a MultiindexSet.
MORFE.Multiindices.bounded_index_tuples — Method
bounded_index_tuples(M, exp::SVector{N,Int})Enumerate all index tuples of length M whose component counts are bounded by exp.
This function generates all tuples (i₁, ..., i_M) with entries in 1:N such that:
- Each index
kappears at mostexp[k]times - The total length of the tuple is exactly
M
Each tuple is represented in its canonical sorted form (non-decreasing order), so that it uniquely corresponds to a count vector (multiindex).
For each valid tuple, the function also returns:
- The associated multiindex
alpha, wherealpha[k]is the number of timeskappears - The number of distinct permutations of the tuple
Returns a vector of tuples: (indextuple, multiindex, permutationcount)
where:
index_tuple::NTuple{M,Int}is the sorted tuplemultiindex::SVector{N,Int}contains the countspermutation_count::Intis the number of distinct permutations
MORFE.Multiindices.build_exponent_index_map — Method
build_exponent_index_map(set::MultiindexSet) -> Dict{NTuple{N,Int}, Int} where NBuild a dictionary mapping each exponent (as a tuple) to its column index in the set. Useful for O(1) lookups without repeated binary searches.
The keys are NTuple{N,Int} where N is the number of variables.
MORFE.Multiindices.divides — Method
divides(a::AbstractVector{Int}, b::AbstractVector{Int}) -> BoolCheck whether a divides b componentwise, i.e., a[i] ≤ b[i] for all i.
MORFE.Multiindices.factorisations_asymmetric — Method
factorisations_asymmetric(set, exp, num_factors, candidate_indices) -> Vector{FactorisationEntry}Return every ordered num_factors-tuple of indices from candidate_indices whose exponent vectors sum to exp. Each ordering is a separate entry with multiplier = 1.
MORFE.Multiindices.factorisations_fully_symmetric — Method
factorisations_fully_symmetric(set, exp, num_factors, candidate_indices) -> Vector{FactorisationEntry}Return all unordered (non-decreasing index) num_factors-tuples from candidate_indices whose exponent vectors sum to exp. multiplier is the multinomial coefficient num_factors! / (m₁! m₂! … mₖ!) counting the distinct ordered arrangements of each combination.
Duplicate entries in candidate_indices are removed internally.
MORFE.Multiindices.factorisations_groupwise_symmetric — Method
factorisations_groupwise_symmetric(set, exp, group_sizes, candidate_indices) -> Vector{FactorisationEntry}Return factorisations of exp into M = length(group_sizes) groups, where group i has group_sizes[i] factor slots and is internally symmetric.
factor_indices in each entry is the concatenation of per-group indices in group order (each group sorted non-decreasingly). multiplier is the product of the per-group permutation counts — the total number of ordered arrangements.
MORFE.Multiindices.find_in_set — Method
find_in_set(set::MultiindexSet, exp::AbstractVector{Int}) -> Union{Int, Nothing}Return the column index of exp in set.exponents using binary search, exploiting the fact that the set is sorted according to Grlex. Returns nothing if exp is not present.
MORFE.Multiindices.find_in_set — Method
find_in_set(set::MultiindexSet, exp::NTuple{N,Int}) where N -> Union{Int, Nothing}Tuple version – avoids allocating a vector for the exponent.
MORFE.Multiindices.grlex_precede — Method
grlex_precede(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer}) -> BoolGraded lexicographic order: compare total degree first, then lexicographic descending. Returns true if a comes before b in this order.
MORFE.Multiindices.grlex_precede — Method
grlex_precede(t::NTuple{N,Int}, v::AbstractVector{Int}) -> BoolCompare a tuple (representing an exponent) with a vector in graded lexicographic order. Useful for binary search without allocating a vector.
MORFE.Multiindices.indices_in_box_with_bounded_degree — Method
indices_in_box_with_bounded_degree(set::MultiindexSet, box_upper::AbstractVector{Int},
degree_lower_bound::Int, total_deg_upper::Int,
allowed_indices::AbstractVector{Int}) -> Vector{Int}Same as the 4‑argument version, but the search is restricted to the indices listed in allowed_indices (which must be sorted). Only those indices that also satisfy the componentwise bound are returned.
MORFE.Multiindices.indices_in_box_with_bounded_degree — Method
indices_in_box_with_bounded_degree(set::MultiindexSet, box_upper::AbstractVector{Int},
degree_lower_bound::Int, total_deg_upper::Int) -> Vector{Int}Return the column indices of all multiindices v in set such that
v ≤ box_uppercomponentwise,degree_lower_bound ≤ sum(v[i]) < total_deg_upper.
Uses the degree bounds to limit the search to relevant columns.
MORFE.Multiindices.is_constant — Method
is_constant(exp::AbstractVector{Int}) -> BoolReturn true if the exponent vector is all zeros.
MORFE.Multiindices.monomial_rank — Method
monomial_rank(exp::AbstractVector{Int}, nvars::Int, max_degree::Int) -> IntReturn the 1‑based rank of the exponent vector exp in the complete set of all multiindices of length nvars with total degree ≤ max_degree, sorted according to graded lexicographic order (Grlex).
The vector exp must satisfy length(exp) == nvars and sum(exp) ≤ max_degree. Uses combinatorial counting formulas for efficiency (O(nvars) time).
If the computed rank exceeds typemax(Int), an error is thrown.
MORFE.Multiindices.multiindex — Method
multiindex(components::Int...) -> Vector{Int}Convenience constructor for an exponent vector.
MORFE.Multiindices.multiindices_with_total_degree — Method
multiindices_with_total_degree(nvars::Int, deg::Int) -> MultiindexSetGenerate all exponent vectors of length nvars with total degree exactly deg, sorted in lexicographic order (the tie‑breaker for Grlex). Returns a MultiindexSet.
MORFE.Multiindices.num_multiindices_up_to — Method
num_multiindices_up_to(nvars::Int, max_degree::Int) -> IntegerReturn the number of exponent vectors of length nvars with total degree ≤ max_degree. For nvars = 0 the set contains one element if max_degree ≥ 0, otherwise zero.
MORFE.Multiindices.zero_multiindex — Method
zero_multiindex(n::Int) -> Vector{Int}Return the zero exponent vector of length n (all components zero).