Skip to content

Commit e6b0aa8

Browse files
committed
Fix isequal(::Add, ::Symbolic)
1 parent 20f777b commit e6b0aa8

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/types.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ symtype(::Symbolic{T}) where {T} = T
5858

5959
Base.isequal(s::Symbolic, x) = false
6060
Base.isequal(x, s::Symbolic) = false
61-
Base.isequal(x::Symbolic, y::Symbolic) = false
61+
62+
function Base.isequal(t1::Symbolic, t2::Symbolic)
63+
t1 === t2 && return true
64+
(istree(t1) && istree(t2)) || return false
65+
a1 = arguments(t1)
66+
a2 = arguments(t2)
67+
68+
isequal(operation(t1), operation(t2)) &&
69+
length(a1) == length(a2) &&
70+
all(isequal(l,r) for (l, r) in zip(a1,a2))
71+
end
6272
### End of interface
6373

6474
"""
@@ -155,7 +165,7 @@ function (f::Sym)(args...)
155165
end
156166

157167
"""
158-
`promote_symtype(f::Sym{FnType{X,Y}}, arg_symtypes...)`
168+
promote_symtype(f::Sym{FnType{X,Y}}, arg_symtypes...)
159169
160170
The output symtype of applying variable `f` to arugments of symtype `arg_symtypes...`.
161171
if the arguments are of the wrong type then this function will error.
@@ -287,15 +297,6 @@ function Base.hash(t::Term{T}, salt::UInt) where {T}
287297
hashvec(arguments(t), hash(operation(t), hash(T, salt)))
288298
end
289299

290-
function Base.isequal(t1::Term, t2::Term)
291-
t1 === t2 && return true
292-
a1 = arguments(t1)
293-
a2 = arguments(t2)
294-
295-
isequal(operation(t1), operation(t2)) && length(a1) == length(a2) &&
296-
all(isequal(l,r) for (l, r) in zip(a1,a2))
297-
end
298-
299300
function term(f, args...; type = nothing)
300301
if type === nothing
301302
T = rec_promote_symtype(f, symtype.(args)...)
@@ -618,7 +619,7 @@ struct Pow{X, B, E} <: Symbolic{X}
618619
exp::E
619620
end
620621

621-
function Pow(a,b)
622+
function Pow(a, b)
622623
_iszero(b) && return 1
623624
_isone(b) && return a
624625
Pow{promote_symtype(^, symtype(a), symtype(b)), typeof(a), typeof(b)}(a,b)

0 commit comments

Comments
 (0)