Skip to content

Commit 0cae526

Browse files
Add merging of Pow's for better canonical form
1 parent 2dccd21 commit 0cae526

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/types.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ function (::Type{<:Pow{T}})(a, b; metadata=NO_METADATA) where {T}
831831
Pow{T, typeof(a), typeof(b), typeof(metadata)}(a,b,metadata)
832832
end
833833
function Pow(a, b; metadata=NO_METADATA)
834-
Pow{promote_symtype(^, symtype(a), symtype(b))}(a, b, metadata=metadata)
834+
Pow{promote_symtype(^, symtype(a), symtype(b))}(makepow(a, b)..., metadata=metadata)
835835
end
836836
symtype(a::Pow{X}) where {X} = X
837837

@@ -847,6 +847,16 @@ Base.isequal(p::Pow, b::Pow) = isequal(p.base, b.base) && isequal(p.exp, b.exp)
847847

848848
Base.show(io::IO, p::Pow) = show_term(io, p)
849849

850+
function makepow(a, b)
851+
base = a
852+
exp = b
853+
if a isa Pow
854+
base = a.base
855+
exp = a.exp * b
856+
end
857+
return (base, exp)
858+
end
859+
850860
^(a::SN, b) = Pow(a, b)
851861

852862
^(a::SN, b::SN) = Pow(a, b)

0 commit comments

Comments
 (0)