Skip to content

substitutions for powers with new symbolic variables using Symbolics.jl  #773

@xiang-yu

Description

@xiang-yu

I have a vector "g" with high order polynomial elements x^alpha. I want to replace 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 * xy + 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

aphi1 + bphi2 + d phi3 +1
b
phi1 + a*phi2 + d *phi3+1
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions