Example:
import itertools
D = 10 # Dimensions
N = 3 # Maximum Total Degree
# Generate all combinations of indices from 0 to N for 10 dimensions
all_combinations = itertools.product(range(N + 1), repeat=D)
# Filter: ONLY keep combinations where the SUM of indices is <= N
total_degree_indices = [idx for idx in all_combinations if sum(idx) <= N]
print(f"Total coefficients kept: {len(total_degree_indices)}")
# For N=3, D=10, this prints 286 (instead of 4^10 = 1,048,576!)
Example: