@@ -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
776776operation (a:: Mul ) = *
777777
778+ unstable_pow (a, b) = a isa Integer && b isa Integer ? (a// 1 ) ^ b : a ^ b
779+
778780function 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)
782784end
783785
903905^ (a:: Number , b:: SN ) = Pow (a, b)
904906
905907function ^ (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))
909911end
0 commit comments