Skip to content

Commit

Permalink
close #351; issue with Bool type and arithmetic (#352)
Browse files Browse the repository at this point in the history
* close #351; issue with  Bool type and arithmetic
  • Loading branch information
jverzani authored May 30, 2020
1 parent 6f51a94 commit 0a0ac35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "1.0.22"
version = "1.0.23"


[deps]
Expand Down
13 changes: 13 additions & 0 deletions src/mathops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@
\(x::SymbolicObject, y::SymbolicObject) = (y'/x')' # ?

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::SymbolicObject, y::Bool) = x.__add__(Int(y))
*(x::Bool, y::SymbolicObject) = Sym(Int(x)).__mul__(y)
*(x::SymbolicObject, y::Bool) = x.__mul__(Int(y))
-(x::Bool, y::SymbolicObject) = Sym(Int(x)).__sub__(y)
-(x::SymbolicObject, y::Bool) = x.__sub__(Int(y))
/(x::Bool, y::SymbolicObject) = Sym(Int(x)).__div__(y)
/(x::SymbolicObject, y::Bool) = x.__div__(Int(y))
^(x::Bool, y::SymbolicObject) = Sym(Int(x)).__pow__(y)
^(x::SymbolicObject, y::Bool) = x.__pow__(Int(y))
9 changes: 7 additions & 2 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ end
@test eltype(A*A) == Sym
@test eltype(A*ones(2,2)) == Sym
@test eltype(A*Diagonal([1,1])) == Sym
@test_broken eltype(A * I(2)) == Sym
VERSION >= v"1.2.0" && @test eltype(A * I(2)) == Sym

## Issue 328 with E -> e
@vars x
Expand Down Expand Up @@ -654,6 +654,11 @@ end
@test lambdify(PI^4*xreal)(256) == 256 * pi^4



## Issue 351 booleans and arithmetic operations
@test 1 + true == 2 == true + 1
@test 1 - true == 0 == true - 1
@test 1 * true == 1 == true * 1
@test 1/true == 1 == true/1
@test true^1 == 1 == 1^true

end

2 comments on commit 0a0ac35

@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/15617

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.0.23 -m "<description of version>" 0a0ac35e410fd216e76a3305eeb190d10c099bb0
git push origin v1.0.23

Please sign in to comment.