Skip to content

Commit

Permalink
Merge pull request #156 from JuliaSymbolics/myb/int
Browse files Browse the repository at this point in the history
Use _isinteger check in power rules
  • Loading branch information
shashi authored Jan 8, 2021
2 parents e00284a + 19dcae1 commit 2461789
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymbolicUtils"
uuid = "d1185830-fcd6-423d-90d6-eec64667417b"
authors = ["Shashi Gowda"]
version = "0.6.2"
version = "0.6.3"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand Down
4 changes: 2 additions & 2 deletions src/simplify_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ let


POW_RULES = [
@rule(^(*(~~x), ~y::isliteral(Integer)) => *(map(a->pow(a, ~y), ~~x)...))
@rule((((~x)^(~p::isliteral(Integer)))^(~q::isliteral(Integer))) => (~x)^((~p)*(~q)))
@rule(^(*(~~x), ~y::_isinteger) => *(map(a->pow(a, ~y), ~~x)...))
@rule((((~x)^(~p::_isinteger))^(~q::_isinteger)) => (~x)^((~p)*(~q)))
@rule(^(~x, ~z::_iszero) => 1)
@rule(^(~x, ~z::_isone) => ~x)
@rule(inv(~x) => ~x ^ -1)
Expand Down
8 changes: 4 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ is_operation(f) = @nospecialize(x) -> istree(x) && (operation(x) == f)
isliteral(::Type{T}) where {T} = x -> x isa T
is_literal_number(x) = isliteral(Number)(x)

_iszero(t) = false
_iszero(x::Number) = iszero(x)
_isone(t) = false
_isone(x::Number) = isone(x)
# checking the type directly is faster than dynamic dispatch in type unstable code
_iszero(x) = x isa Number && iszero(x)
_isone(x) = x isa Number && isone(x)
_isinteger(x) = (x isa Number && isinteger(x)) || (x isa Symbolic && symtype(x) <: Integer)

issortedₑ(args) = issorted(args, lt=<ₑ)
needs_sorting(f) = x -> is_operation(f)(x) && !issortedₑ(arguments(x))
Expand Down
1 change: 1 addition & 0 deletions test/rulesets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ end
@eqtest simplify(a + b + 0*c + d) == simplify(a + b + d)
@eqtest simplify(a * b * c^0 * d) == simplify(a * b * d)
@eqtest simplify(a * b * 1*c * d) == simplify(a * b * c * d)
@eqtest simplify(x^2.0/(x*y)^2.0) == y ^ (-2.0)

@test simplify(Term(one, [a])) == 1
@test simplify(Term(one, [b+1])) == 1
Expand Down

0 comments on commit 2461789

Please sign in to comment.