JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

Incorrect degrees of multivariate polynomials using Symbolics.degree #778

Open xiang-yu opened 1 year ago

xiang-yu commented 1 year ago

I try to get the degree of a multivariate polynomials (*y=x1x2) using Symbolics.degree, but I got unexpected values. I must misunderstood the function Symbolics.degree. At any rate, could you please point me to the Symbolics function that can return a degree of 2**?

julia> using Symbolic julia> x = @variables x1, x2 julia> y=x[1]*x[2] julia> Symbolics.degree(y,x) 0

julia> Symbolics.degree.(y,x) 2-element Vector{Int64}: 1 1

I am expecting 2 though.

bowenszhu commented 1 year ago

The second argument of Symbolics.degree should be a single symbolic variable or just nothing.

(@v1.8) pkg> st -m Symbolics
Status `~/.julia/environments/v1.8/Manifest.toml`
  [0c5d862f] Symbolics v4.13.0

julia> using Symbolics

help?> Symbolics.degree
  degree(p, sym=nothing)

  Extract the degree of p with respect to sym.

julia> x = @variables x1, x2
2-element Vector{Num}:
 x1
 x2

julia> y = x1 * x2
x1*x2

julia> Symbolics.degree(y)
2

julia> Symbolics.degree(y, x1)
1

julia> Symbolics.degree(y, x2)
1

julia> Symbolics.degree.(y, x) # element-wise
2-element Vector{Int64}:
 1
 1

Symbolics.degree can only compute the degree with respect to either one single symbolic variable or all symbolic variables.

xiang-yu commented 1 year ago

Thanks a lot! Symbolics.degree(y) works like a charm.