RoughlyRational.jl
Installation
For the first time only, run the following code in your Jupyter Notebook:
using Pkg
Pkg.add(path="https://github.com/ohno/RoughlyRational.jl")
or use add
upon Pkg REPL:
]
add https://github.com/ohno/RoughlyRational.jl
Usage
To use this package, run the following code in your Jupyter Notebook or code:
using RoughlyRational
maybeinteger(x)
and RoughlyRational(x)
are available.
Examples
maybeinteger(x)
can determine whether x
is an integer or not, more roughly than isinteger(x)
:
julia> x = sin(2π)
-2.4492935982947064e-16
julia> isinteger(x)
false
julia> maybeinteger(x)
true
roughlyRational
can convert x
to a rational number more roughly than Rational(x)
:
julia> Rational(0.499999)
9007181240342483//18014398509481984
julia> roughlyRational(0.499999)
1//2
Several packages allow to display Legendre polynomials:
# using Pkg
# Pkg.add("SpecialPolynomials")
# Pkg.add("Polynomials")
# Pkg.add(path="https://github.com/ohno/RoughlyRational.jl")
# Pkg.add("SimplePolynomials")
# Pkg.add("LaTeXStrings")
# Pkg.add("Latexify")
using SpecialPolynomials
using Polynomials
using RoughlyRational
using SimplePolynomials
using LaTeXStrings
using Latexify
for n in 0:15
p = basis(Legendre, n)
q = convert(Polynomial, p)
r = roughlyRational.(q.coeffs)
s = SimplePolynomial(r...)
latexstring("P_{$n}(x) = ", latexify("$s", env=:raw, cdot=false)) |> display
end
Rational(Float32(x))
replaces roughlyRational(x)
but has an error:
# using SpecialPolynomials
# using Polynomials
# using Latexify
# using LaTeXStrings
for n in 4:4
for k in 0:1
# derivative of the Laguerre polynomials
p = basis(Laguerre{0}, n)
p = convert(Polynomial, p)
p = derivative(p,k)
p = Rational.(Float32.(p.coeffs))
p = SimplePolynomial(p...)
latexstring("L_n^k(x) = ", latexify("p", env=:raw, cdot=false)) |> display
# Conversion from generalized Laguerre polynomials
p = basis(Laguerre{k}, n-k)
p = convert(Polynomial, p) * (-1)^k
p = Rational.(Float32.(p.coeffs))
p = SimplePolynomial(p...)
latexstring("L_n^k(x) = ", latexify("p", env=:raw, cdot=false)) |> display
end
end
roughlyRational(x)
solves this problem.
# using SpecialPolynomials
# using Polynomials
# using Latexify
# using LaTeXStrings
for n in 4:4
for k in 0:1
# derivative of the Laguerre polynomials
p = basis(Laguerre{0}, n)
p = convert(Polynomial, p)
p = derivative(p,k)
p = roughlyRational.(p.coeffs)
p = SimplePolynomial(p...)
latexstring("L_n^k(x) = ", latexify("p", env=:raw, cdot=false)) |> display
# Conversion from generalized Laguerre polynomials
p = basis(Laguerre{k}, n-k)
p = convert(Polynomial, p) * (-1)^k
p = roughlyRational.(p.coeffs)
p = SimplePolynomial(p...)
latexstring("L_n^k(x) = ", latexify("p", env=:raw, cdot=false)) |> display
end
end