Skip to content

Commit 5ee1bae

Browse files
YingboMashashi
andcommitted
Fix pow with mpoly
Co-authored-by: "Shashi Gowda" <[email protected]>
1 parent 9c36a25 commit 5ee1bae

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/types.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ function Mul(T, a,b; metadata=NO_METADATA)
762762
if _isone(last(pair)) # first value
763763
return first(pair)
764764
else
765-
return Pow(first(pair), last(pair))
765+
return unstable_pow(first(pair), last(pair))
766766
end
767767
else
768768
Mul{T, typeof(a), typeof(b), typeof(metadata)}(a,b, Ref{Any}(nothing), Ref{UInt}(0), metadata)
@@ -775,9 +775,11 @@ istree(a::Mul) = true
775775

776776
operation(a::Mul) = *
777777

778+
unstable_pow(a, b) = a isa Integer && b isa Integer ? (a//1) ^ b : a ^ b
779+
778780
function arguments(a::Mul)
779781
a.sorted_args_cache[] !== nothing && return a.sorted_args_cache[]
780-
args = sort!([k^v for (k,v) in a.dict], lt=<ₑ)
782+
args = sort!([unstable_pow(k, v) for (k,v) in a.dict], lt=<ₑ)
781783
a.sorted_args_cache[] = isone(a.coeff) ? args : vcat(a.coeff, args)
782784
end
783785

@@ -903,7 +905,7 @@ end
903905
^(a::Number, b::SN) = Pow(a, b)
904906

905907
function ^(a::Mul, b::Number)
906-
coeff = a.coeff isa Integer && b isa Integer ? (a.coeff//1) ^ b : a.coeff ^ b
908+
coeff = unstable_pow(a.coeff, b)
907909
Mul(promote_symtype(^, symtype(a), symtype(b)),
908910
coeff, mapvalues((k, v) -> b*v, a.dict))
909911
end

0 commit comments

Comments
 (0)