Skip to content

Commit

Permalink
Fix -(a) for Const
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenszhu committed Sep 16, 2024
1 parent 8d18d9d commit 85efc31
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,19 @@ end
+(a::SN) = a

function -(a::SN)
!issafecanon(*, a) && return term(-, a)
isadd(a) ? _Add(sub_t(a), -a.impl.coeff, mapvalues((_, v) -> -v, a.impl.dict)) :
_Add(sub_t(a), makeadd(-1, 0, a)...)
if isconst(a)
v = a.impl.val
mv = -v
return _Const(mv)
end
if !issafecanon(*, a)
return term(-, a)
end
if isadd(a)
_Add(sub_t(a), -a.impl.coeff, mapvalues((_, v) -> -v, a.impl.dict))
else
_Add(sub_t(a), makeadd(-1, 0, a)...)
end
end
function -(a::SN, b::SN)
(!issafecanon(+, a) || !issafecanon(*, b)) && return term(-, a, b)
Expand Down

0 comments on commit 85efc31

Please sign in to comment.