Skip to content

Commit 58f28f3

Browse files
fix: fix negative coefficient Mul raised to fractional power
1 parent 0cd9f06 commit 58f28f3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/types.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,9 +1533,14 @@ function ^(a::SN, b)
15331533
elseif b isa Real && b < 0
15341534
Div(1, a ^ (-b))
15351535
elseif ismul(a) && b isa Number
1536-
coeff = unstable_pow(a.coeff, b)
1537-
Mul(promote_symtype(^, symtype(a), symtype(b)),
1538-
coeff, mapvalues((k, v) -> b*v, a.dict))
1536+
if a.coeff isa Real && a.coeff < 0 && !isinteger(b)
1537+
coeff = unstable_pow(-a.coeff, b)
1538+
coeff * Pow(Mul(promote_symtype(^, symtype(a), symtype(b)), -1, copy(a.dict)), b)
1539+
else
1540+
coeff = unstable_pow(a.coeff, b)
1541+
Mul(promote_symtype(^, symtype(a), symtype(b)),
1542+
coeff, mapvalues((k, v) -> b*v, a.dict))
1543+
end
15391544
else
15401545
Pow(a, b)
15411546
end

test/basics.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,8 @@ end
442442
res = substitute(ex, Dict(y => 0))
443443
@test SymbolicUtils.isequal_with_metadata(res, x)
444444
end
445+
446+
@testset "Negative coefficient to fractional power" begin
447+
@syms a
448+
@test isequal((-5a)^0.5, sqrt(5) * Pow{Number}(-a, 0.5))
449+
end

0 commit comments

Comments
 (0)