Created
August 27, 2014 16:04
-
-
Save fredrik-johansson/37676f396ed74ca804ef to your computer and use it in GitHub Desktop.
nemo exponential
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exp{T <: Ring}(a::T) | |
a != 0 && error("Exponential of nonzero element") | |
return one(T) | |
end | |
function exp{T<: Ring, S}(a::PowerSeries{T, S}) | |
if a == 0 | |
return PowerSeries(PowerSeries{T, S}, [one(T)], a.prec) | |
elseif a.prec == nothing | |
error("Unable to compute exponential of infinite precision power series") | |
end | |
d = Array(T, a.prec) | |
d[0+1] = exp(coeff(a, 0)) | |
len = length(a) | |
for k = 1 : a.prec-1 | |
s = zero(T) | |
for j = 1 : min(k+1, len) - 1 | |
s += j * coeff(a, j) * d[k-j+1] | |
end | |
d[k+1] = s / k | |
end | |
b = PowerSeries(PowerSeries{T, S}, d, a.prec) | |
return b | |
end | |
function exp{S}(a::PowerSeries{QQ, S}) | |
if a == 0 | |
return PowerSeries(PowerSeries{QQ, S}, [QQ(1)], nothing) | |
elseif a.prec == nothing | |
error("Unable to compute exponential of infinite precision power series") | |
end | |
b = PowerSeries(PowerSeries{QQ, S}, Array(QQ, 0), a.prec) | |
ccall((:fmpq_poly_exp_series, :libflint), Void, | |
(Ptr{PowerSeries}, Ptr{PowerSeries}, Int), | |
&b, &a, a.prec) | |
return b | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment