Skip to content

Commit

Permalink
Merge pull request #306 from JuliaSymbolics/myb/div
Browse files Browse the repository at this point in the history
Preserve rational if possible
  • Loading branch information
YingboMa authored Jul 9, 2021
2 parents 0112c2c + 1b56117 commit c91806f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ struct FnType{X<:Tuple,Y} end

function (f::Symbolic)(args...)
error("Sym $f is not callable. " *
"Use @syms $f(var1, var2,...) to create it as a callable. " *
"See ?@fun for more options")
"Use @syms $f(var1, var2,...) to create it as a callable.")
end

"""
Expand Down Expand Up @@ -494,7 +493,7 @@ end
function show_mul(io, args)
length(args) == 1 && return print_arg(io, *, args[1])

paren_scalar = args[1] isa Complex || args[1] isa Rational || (args[1] isa Number && !isfinite(args[1]))
paren_scalar = (args[1] isa Complex && !_iszero(imag(args[1]))) || args[1] isa Rational || (args[1] isa Number && !isfinite(args[1]))
minus = args[1] isa Number && args[1] == -1
unit = args[1] isa Number && args[1] == 1
nostar = !paren_scalar && args[1] isa Number && !(args[2] isa Number)
Expand Down Expand Up @@ -831,7 +830,7 @@ end

\(a::Number, b::SN) = b / a

/(a::SN, b::Number) = inv(b) * a
/(a::SN, b::Number) = (b isa Integer ? 1//b : inv(b)) * a

//(a::Union{SN, Number}, b::SN) = a / b

Expand Down
1 change: 1 addition & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ end
@test isequal(w == 0, Term{Bool}(==, [w, 0]))

@eqtest x // 5 == (1 // 5) * x
@eqtest (1//2 * x) / 5 == (1 // 10) * x
@eqtest x // Int16(5) == Rational{Int16}(1, 5) * x
@eqtest 5 // x == 5 / x
@eqtest x // a == x / a
Expand Down
3 changes: 3 additions & 0 deletions test/fuzz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ seed!(6174)
@testset "Fuzz test" begin
@time @testset "expand fuzz" begin
for i=1:500
i % 100 == 0 && @info "expand fuzz" iter=i
fuzz_test(5, num_spec, SymbolicUtils.expand; min_depth=3)
end
end
@time @testset "num fuzz" begin
for i=1:1500
i % 100 == 0 && @info "num fuzz" iter=i
fuzz_test(5, num_spec)
end
end
@time @testset "bool fuzz" begin
for i=1:500
seed!(i)
i % 100 == 0 && @info "bool fuzz" iter=i
fuzz_test(5, bool_spec)
end
end
Expand Down

0 comments on commit c91806f

Please sign in to comment.