@@ -297,8 +297,10 @@ hashvec(xs, z) = foldr(hash, xs, init=z)
297297
298298function Base. hash (t:: Term{T} , salt:: UInt ) where {T}
299299 h = t. hash[]
300- ! iszero (h) && return h
301- t. hash[] = hashvec (arguments (t), hash (operation (t), hash (T, salt)))
300+ (iszero (salt) && ! iszero (h)) && return h
301+ h′ = hashvec (arguments (t), hash (operation (t), hash (T, salt)))
302+ iszero (salt) && (t. hash[] = h′)
303+ return h′
302304end
303305
304306_promote_symtype (f:: Sym , args) = promote_symtype (f, map (symtype, args)... )
@@ -454,12 +456,6 @@ function arguments(a::Add)
454456 a. sorted_args_cache[] = iszero (a. coeff) ? args : vcat (a. coeff, args)
455457end
456458
457- function Base. hash (a:: Add , u:: UInt64 )
458- h = a. hash[]
459- ! iszero (h) && return h
460- a. hash[] = hash (0xaddaddaddaddadda , hash (a. coeff, hash (a. dict, u)))
461- end
462-
463459Base. isequal (a:: Add , b:: Add ) = isequal (a. coeff, b. coeff) && isequal (a. dict, b. dict)
464460
465461Base. show (io:: IO , a:: Add ) = show_term (io, a)
@@ -582,15 +578,8 @@ function arguments(a::Mul)
582578 a. sorted_args_cache[] = isone (a. coeff) ? args : vcat (a. coeff, args)
583579end
584580
585- function Base. hash (m:: Mul , u:: UInt64 )
586- h = m. hash[]
587- ! iszero (h) && return h
588- m. hash[] = hash (0xaaaaaaaaaaaaaaa , hash (m. coeff, hash (m. dict, u)))
589- end
590-
591581Base. isequal (a:: Mul , b:: Mul ) = isequal (a. coeff, b. coeff) && isequal (a. dict, b. dict)
592582
593-
594583Base. show (io:: IO , a:: Mul ) = show_term (io, a)
595584
596585function makemul (coeff, xs... ; d= sdict ())
@@ -729,3 +718,12 @@ function similarterm(p::Union{Mul, Add, Pow}, f, args)
729718 f (args... )
730719 end
731720end
721+
722+ function Base. hash (t:: Union{Add,Mul} , u:: UInt64 )
723+ h = t. hash[]
724+ (iszero (u) && ! iszero (h)) && return h
725+ hashoffset = t isa Add ? 0xaddaddaddaddadda : 0xaddaddaddaddadda
726+ h′= hash (hashoffset, hash (t. coeff, hash (t. dict, u)))
727+ iszero (u) && (t. hash[] = h′)
728+ return h′
729+ end
0 commit comments