# Substitution of products of symbolic variables

I am trying to simplify a symbolic expression by replacing products of symbolic variables, eg. `x*y`, with a single new variable, e.g. `z`, but I cannot succeed in doing it. Any suggestion?

MWE:

``````using Symbolics
using SymbolicUtils

@variables x[1:2] z

f = 3.0 + 2.0*(x*x);
g = substitute(f, Dict(x*x => z));

println(g);
``````

Actual output: `3.0 + 2.0x*x`
Expected output: `3.0 + 2.0z`

Thanks!

``````using SymbolicUtils

@syms a b z

r = @acrule *(a, b) => z

f = 3.0 + 2.0b*a
simplify(f, RuleSet([r]))
``````

Thank you.
Is this extensible to arrays of symbolic variables someway?

Ideally, I have a complex expression (a polynomial in the `x[i]`, where `x` is an array of symbolic variables and the coefficients can be either floats or other symbolic variables) and a list of “monomials” that I want to replace, e.g. `c*x*x => c*y`, `d*x^2 => d*y`, etc…

The goal is:

• set to zero all monomials of order greater than 2, e.g. `x^3` or `x*x*x`
• replace all second-order expressions with a simpler one, e.g. `c*x^2 => c*y` or `d*x*x => d*y`

Write down all the rules and interpolate when you refer to an array element.
Example:
`r = [@acrule(*(\$(x), \$(x), \$(x)) => 0)]`
If you work with polynomials the `polynomial_coeffs` function may be useful.
Example:
`d, rem = polynomial_coeffs(f, [x...])`