# Combinatorics -- what has changed?

**URL:** <https://discourse.julialang.org/t/combinatorics-what-has-changed/95355>\
**Category:** General Usage\
**Created:** [February 28, 2023, 9:12pm UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355 "2023-02-28T21:12:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [February 28, 2023, 9:12pm UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355/1 "2023-02-28T21:12:37Z")

</div>

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

```julia
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:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/f/cf487a83cb5fe76bac6790d8bd175d0a62856333.png)

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

- What has changed?
- What can I do to fix the change?

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [February 28, 2023, 9:15pm UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355/2 "2023-02-28T21:15:50Z")

</div>

```julia
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 🙂 can you post more details about the error you’re seeing?

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [February 28, 2023, 9:30pm UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355/3 "2023-02-28T21:30:37Z")

</div>

Sorry… my info was incomplete…

```julia
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))

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [February 28, 2023, 9:37pm UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355/4 "2023-02-28T21:37:00Z")

</div>

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

If I instead do:

```julia

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.]

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [February 28, 2023, 10:09pm UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355/5 "2023-02-28T22:09:25Z")

</div>

ti potrebbe essere utile questo?

```julia
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

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [March 1, 2023, 8:58am UTC](https://discourse.julialang.org/t/combinatorics-what-has-changed/95355/6 "2023-03-01T08:58:50Z")

</div>

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