Nemocas / Nemo.jl

Julia bindings for the FLINT number theory C library
http://nemocas.github.io/Nemo.jl/
Other
189 stars 58 forks source link

Can we make ComplexField(QQ) ? #1110

Open zhaoli-IHEP opened 3 years ago

zhaoli-IHEP commented 3 years ago

Is it possible to have the rational complex field instead of the float number complex field? Meanwhile maybe fit into LaurentSeriesField(ComplexField(QQ), 5, "ep")?

thofma commented 3 years ago

It is already there, but maybe not under the name that you would have in mind.

julia> Qx, x = QQ["x"]
(Univariate Polynomial Ring in x over Rational Field, x)

julia> CC, i = NumberField(x^2 + 1, "i")
(Number field over Rational Field with defining polynomial x^2 + 1, i)

julia> i^2
-1

(https://en.wikipedia.org/wiki/Gaussian_rational)

Do you have a suggestion for an alias? Would you suggest ComplexField(QQ)?

zhaoli-IHEP commented 3 years ago

It is already there, but maybe not under the name that you would have in mind.

julia> Qx, x = QQ["x"]
(Univariate Polynomial Ring in x over Rational Field, x)

julia> CC, i = NumberField(x^2 + 1, "i")
(Number field over Rational Field with defining polynomial x^2 + 1, i)

julia> i^2
-1

(https://en.wikipedia.org/wiki/Gaussian_rational)

Do you have a suggestion for an alias? Would you suggest ComplexField(QQ)?

So great! Thank you. I think ComplexField(QQ) would be nice.

thofma commented 3 years ago

Let's hear what the others think. @wbhart @tthsqe12

wbhart commented 3 years ago

I don't have any objections. It would be nice if it also worked for Nemo.

thofma commented 3 years ago

This is a about Nemo.

tthsqe12 commented 3 years ago

I have a reservation about ComplexField(QQ): it suggests that we can do ComplexField(F) for a multitude of fields F, ie extent F by a nonreal something. What is ComplexField(GF(5)) or ComplexField(GF(7))? If you share my reservations, name them GaussianRationals() and GaussianIntegers(). Otherwise, call it whatever you want. Just make sure all instances hash equal!

On a related note, Complex{fmpq} doesn't work :(

thofma commented 3 years ago

After sleeping one night over this, I also don't like it too much anymore. It does not really play nice with im and should it return both the field and the imaginary unit? It is also awkward because one needs to use i = gen(K) to get the imaginary unit.

tthsqe12 commented 3 years ago

So, I have come across the need for exactly this kind of thing. There are parents ZZi and QQi with elem types fmpzi and fmpqi. The behaviour is the following (I am not willing to compromise on the denominator(x) != 25 thing).

julia> i = ZZi(im)
im

julia> typeof(ans)
fmpzi

julia> x = (3+4i)//(5+10i)
(11 - 2*im)/25

julia> typeof(ans)
fmpqi

julia> (numerator(x), denominator(x))
(2 + im, 4 + 3*im)

julia> map(factor, ans)
(1 * (2 + im), im * (2 - im)^2)

It is supposed to play nice with the other complex types:

julia> CC = AcbField(50); gamma(CC(1/2,1/3))
[1.1789716859081 +/- 3.88e-14] + [-0.7570793934981 +/- 4.63e-14]*im

julia> simplest_rational_inside(ans)
(38171685330064 - 24512035975001*im)/32377100982424

(This may or may not be the simplest rational inside, it is just for demo purposes)