xyli
October 31, 2022, 5:08am
1
Does anyone know if there are other Julia functions that can substitute “x*y” by “a”? I had a discussion with Symbolics developers about it, but it seems to be a deadlock now. Please kindly see the discussion here,
opened 09:29PM - 29 Oct 22 UTC
I have a vector "g" with high order polynomial elements x^alpha. I want to repla… ce the high order polynomials x^alpha with first order variables "phi".
Here is my Julia code using Symbolics.jl,
phi = Symbolics.variables(:phi, 1:3)
g = Symbolics.variables(:g, 1:3)
g[1] = a * x^2 + b * y^2 + d * x*y + 1
g[2] = b * x^2 + a * y^2 + d * x*y + 1
g[3] = 0
m = Symbolics.variables(:m, 1:3)
m[1] = x^2
m[2] = y^2
m[3] = xy
expr = Symbolics.variables(:x, 1:3)
for i = 1:3
expr[i] = substitute(g[i], Dict(m[i]=>phi[i]))
end
This returns,
julia> expr
3-element Vector{Num}:
g₁
g₂
g₃
This is not right because it should be
a*phi1 + b*phi2 + d *phi3 +1
b*phi1 + a*phi2 + d *phi3+1
0