Combinatorics -- what has changed?

The following code used to work (some 1 year ago…)

collect(Iterators.flatten((prod(u) for u in with_replacement_combinations(x,i)) for i in 0:3))

Now, the code works if I change the i range to 1:3, but then I miss value 1 in the resulting vector:

[I used the code to generate multivariate basis functions for regression…]

  • What has changed?
  • What can I do to fix the change?
julia> x = [1,2,3,4,5];

julia> collect(Iterators.flatten((prod(u) for u in with_replacement_combinations(x,i)) for i in 0:3))
56-element Vector{Int64}:

It works for me :slight_smile: can you post more details about the error you’re seeing?

Sorry… my info was incomplete…

using Symbolics, Combinatorics

@variables x[1:2]

collect(Iterators.flatten((prod(u) for u in with_replacement_combinations(x,i)) for i in 0:3))

Ah… seems like it is due to a change in Symbolics

If I instead do:


using Symbolics, Combinatorics

@variables x[1:2]

x = collect(x)

collect(Iterators.flatten((prod(u) for u in with_replacement_combinations(x,i)) for i in 0:3))

Apparently, now @variables x[1:2] creates a symbolic array variable, but I need an array of symbolic variables — which is achieved by x = collect(x). [A trick I learned from @baggepinnen in a totally different setting.]

ti potrebbe essere utile questo?

julia> using DynamicPolynomials

julia> 

julia> x,y,z = @polyvar x y z
(x, y, z)

julia> monomials([x,y], 2)
3-element MonomialVector{true}:
 x²
 xy
 y²

julia> monomials([x,y], 0:3)
10-element MonomialVector{true}:
 x³
 x²y
 xy²
 y³
 x²
 xy
 y²
 x
 y
 1

julia>          monomials([x,y,z], 1:2)
9-element MonomialVector{true}:
 x²
 xy
 xz
 y²
 yz
 z²
 x
 y
 z
1 Like

My Italian is not good, but Google helps… I’ll check it.