diff --git a/src/types.jl b/src/types.jl index c099badf..6ed9b975 100644 --- a/src/types.jl +++ b/src/types.jl @@ -463,9 +463,9 @@ ratio(x::Integer,y::Integer) = iszero(rem(x,y)) ? div(x,y) : x//y ratio(x::Rat,y::Rat) = x//y function maybe_intcoeff(x) if ismul(x) - coeff = coeff(x) - if coeff isa Rational && isone(denominator(coeff)) - _Mul(symtype(x), coeff.num, dict(x); metadata = x.metadata) + coefficient = coeff(x) + if coefficient isa Rational && isone(denominator(coefficient)) + _Mul(symtype(x), coefficient.num, dict(x); metadata = x.metadata) else x end @@ -566,16 +566,16 @@ $(SIGNATURES) Any Muls inside an Add should always have a coeff of 1 and the key (in Add) should instead be used to store the actual coefficient """ -function makeadd(sign, coeff, xs...) +function makeadd(sign, coefficient, xs...) d = Dict{BasicSymbolic, Any}() for x in xs if isadd(x) - coeff += coeff(x) + coefficient += coeff(x) _merge!(+, d, dict(x), filter = _iszero) continue end if x isa Number - coeff += x + coefficient += x continue end if ismul(x) @@ -591,17 +591,17 @@ function makeadd(sign, coeff, xs...) d[k] = v end end - coeff, d + coefficient, d end -function makemul(coeff, xs...; d = Dict{BasicSymbolic, Any}()) +function makemul(coefficient, xs...; d = Dict{BasicSymbolic, Any}()) for x in xs if ispow(x) && x.impl.exp isa Number d[x.impl.base] = x.impl.exp + get(d, x.impl.base, 0) elseif x isa Number - coeff *= x + coefficient *= x elseif ismul(x) - coeff *= coeff(x) + coefficient *= coeff(x) _merge!(+, d, dict(x), filter = _iszero) else v = 1 + get(d, x, 0) @@ -612,7 +612,7 @@ function makemul(coeff, xs...; d = Dict{BasicSymbolic, Any}()) end end end - coeff, d + coefficient, d end unstable_pow(a, b) = a isa Integer && b isa Integer ? (a // 1)^b : a^b @@ -1229,13 +1229,13 @@ function +(a::SN, b::SN) return _Add( add_t(a, b), coeff(a) + coeff(b), _merge(+, dict(a), dict(b), filter = _iszero)) elseif isadd(a) - coeff, dict = makeadd(1, 0, b) - return _Add(add_t(a, b), coeff(a) + coeff, _merge(+, dict(a), dict, filter = _iszero)) + coefficient, dictionary = makeadd(1, 0, b) + return _Add(add_t(a, b), coeff(a) + coefficient, _merge(+, dict(a), dictionary, filter = _iszero)) elseif isadd(b) return b + a end - coeff, dict = makeadd(1, 0, a, b) - _Add(add_t(a, b), coeff, dict) + coefficient, dictionary = makeadd(1, 0, a, b) + _Add(add_t(a, b), coefficient, dictionary) end function +(a::Number, b::SN) if isconst(b) @@ -1354,9 +1354,9 @@ function ^(a::SN, b) elseif b isa Number && b < 0 _Div(1, a^(-b)) elseif ismul(a) && b isa Number - coeff = unstable_pow(coeff(a), b) + coefficient = unstable_pow(coeff(a), b) _Mul(promote_symtype(^, symtype(a), symtype(b)), - coeff, mapvalues((k, v) -> b * v, dict(a))) + coefficient, mapvalues((k, v) -> b * v, dict(a))) else _Pow(a, b) end