Skip to content

Commit

Permalink
close issue #477 (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Aug 16, 2022
1 parent ff52d9b commit b6316e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/mathops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@



+(x::SymbolicObject, y::SymbolicObject) = x.__add__(y)
*(x::SymbolicObject, y::SymbolicObject) = x.__mul__(y)
-(x::SymbolicObject, y::SymbolicObject) = x.__sub__(y)
-(x::SymbolicObject) = x.__neg__()
/(x::SymbolicObject, y::SymbolicObject) = x.__truediv__(y)
^(x::SymbolicObject, y::SymbolicObject) = x.__pow__(y)
^(x::SymbolicObject, y::Rational) = x^convert(Sym,y)
#^(x::SymbolicObject, y::Integer) = x^convert(Sym,y) # no Union{Integer, Rational}, as that has ambiguity
//(x::SymbolicObject, y::Int) = x / Sym(y)
//(x::SymbolicObject, y::Rational) = x / Sym(y)
//(x::SymbolicObject, y::SymbolicObject) = x / y

\(x::SymbolicObject, y::SymbolicObject) = (y'/x')' # ?
+(x::Sym, y::Sym)::Sym = x.__add__(y)
*(x::Sym, y::Sym)::Sym = x.__mul__(y)
-(x::Sym, y::Sym)::Sym = x.__sub__(y)
(-)(x::Sym)::Sym = x.__neg__()
/(x::Sym, y::Sym)::Sym = x.__truediv__(y)
^(x::Sym, y::Sym)::Sym = x.__pow__(y)
^(x::Sym, y::Rational) = x^convert(Sym,y)
#^(x::Sym, y::Integer) = x^convert(Sym,y) # no Union{Integer, Rational}, as that has ambiguity
//(x::Sym, y::Int) = x / Sym(y)
//(x::Sym, y::Rational) = x / Sym(y)
//(x::Sym, y::Sym) = x / y

\(x::Sym, y::Sym) = (y'/x')' # ?

Base.inv(x::Sym) = x.__pow__(Sym(-1))

# special case Boolean; issue 351
# promotion for Boolean here is to 0 or 1, not False, True
+(x::Bool, y::SymbolicObject) = Sym(Int(x)).__add__(y)
*(x::Bool, y::SymbolicObject) = Sym(Int(x)).__mul__(y)
-(x::Bool, y::SymbolicObject) = Sym(Int(x)).__sub__(y)
/(x::Bool, y::SymbolicObject) = Sym(Int(x)).__truediv__(y)
^(x::Bool, y::SymbolicObject) = Sym(Int(x)).__pow__(y)
+(x::SymbolicObject, y::Bool) = x.__add__(Int(y))
*(x::SymbolicObject, y::Bool) = x.__mul__(Int(y))
-(x::SymbolicObject, y::Bool) = x.__sub__(Int(y))
/(x::SymbolicObject, y::Bool) = x.__truediv__(Int(y))
^(x::SymbolicObject, y::Bool) = x.__pow__(Int(y))
+(x::Bool, y::Sym)::Sym = Sym(Int(x)).__add__(y)
*(x::Bool, y::Sym)::Sym = Sym(Int(x)).__mul__(y)
-(x::Bool, y::Sym)::Sym = Sym(Int(x)).__sub__(y)
/(x::Bool, y::Sym)::Sym = Sym(Int(x)).__truediv__(y)
^(x::Bool, y::Sym)::Sym = Sym(Int(x)).__pow__(y)
+(x::Sym, y::Bool)::Sym = x.__add__(Int(y))
*(x::Sym, y::Bool)::Sym = x.__mul__(Int(y))
-(x::Sym, y::Bool)::Sym = x.__sub__(Int(y))
/(x::Sym, y::Bool)::Sym = x.__truediv__(Int(y))
^(x::Sym, y::Bool)::Sym = x.__pow__(Int(y))
8 changes: 8 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ end
@syms x
ex = integrate(sqrt(1 + (1/x)^2), (x, 1/sympy.E, sympy.E))
@test N(ex) 3.196198513599507

## Issue #477 non typestable ops
@test Base.Broadcast.combine_eltypes(+, (zero(Sym), zero(Sym))) == Sym
@test Base.Broadcast.combine_eltypes(-, (zero(Sym), zero(Sym))) == Sym
@test Base.Broadcast.combine_eltypes(*, (zero(Sym), zero(Sym))) == Sym
@test Base.Broadcast.combine_eltypes(/, (zero(Sym), zero(Sym))) == Sym
@test Base.Broadcast.combine_eltypes(^, (zero(Sym), zero(Sym))) == Sym

end

@testset "generic programming, issue 223" begin
Expand Down

2 comments on commit b6316e4

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66359

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.7 -m "<description of version>" b6316e4d6f711222e27a3a47c020327a96e8f9b6
git push origin v1.1.7

Please sign in to comment.