Rational "//" used instead of "/"
chriselrod opened this issue · comments
Hi,
Manipulating Julia expressions seems like an awesome and convenient tool!
However, using "//" poses a problem when trying to evaluate expressions, eg:
julia> using Reduce
Reduce (Free PSL version, revision 4218), 22-Sep-2017 ...
julia> rcall(:(int( x^3 * exp(-x^2), x)))
:(-((x ^ 2 + 1)) // (2 * e ^ (x ^ 2)))
Rational division is that it is invalid for Floats, making the above expressions invalid. I can try to work around this through writing code such as:
julia> @generated function intexp(x, ::Val{N}) where N
f = rcall(:(int( x^$N * exp(-x^2), x)))
f.args[1] = :/
f
end
julia> @generated function intoutexp(::Val{N}, ::Type{T} = Float64) where {N,T}
f = rcall(:(int( x^$N * exp(-x^2), x, -Inf, Inf)))
if isa(f, Expr) && f.args[1] == ://
f.args[1] = :/
end
:(convert(T,$f))
end
To get things to work as intended (at least in the use cases I've tried).
Simply searching the repository for // didn't return any hits, and I'm not familiar with Reduce so I couldn't quickly see how to make the change myself.
Hi, thanks for your interest. It is simple to work around this with the Reduce.Rational(::Bool)
toggle:
julia> R"x/2" |> parse
:(x // 2)
julia> Reduce.Rational(false)
false
julia> R"x/2" |> parse
:(x / 2)
Let me know if that works out for you.
The package is still under development, but the docs do mention Reduce.Rational