Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some comments in conjugate_quad(a::AbsSimpleNumFieldElem) #1653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/NumField/NfAbs/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -920,13 +920,22 @@ function conjugate_quad(a::AbsSimpleNumFieldElem)
q = ZZRingElem()
GC.@preserve b begin
a_ptr = reinterpret(Ptr{Int}, pointer_from_objref(a))
b_ptr = reinterpret(Ptr{Int}, pointer_from_objref(b))
p_ptr = reinterpret(Ptr{Int}, k.pol_coeffs)
s = sizeof(Ptr{ZZRingElem})

ccall((:fmpz_mul, libflint), Cvoid, (Ref{ZZRingElem}, Ptr{Int}, Ptr{Int}), q, p_ptr+s, a_ptr +s)
ccall((:fmpz_sub, libflint), Cvoid, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), reinterpret(Ptr{Int}, pointer_from_objref(b)), a_ptr, q)
ccall((:fmpz_neg, libflint), Cvoid, (Ptr{ZZRingElem}, Ptr{ZZRingElem}), reinterpret(Ptr{Int}, pointer_from_objref(b))+1*s, a_ptr + s)
ccall((:fmpz_set, libflint), Cvoid, (Ptr{ZZRingElem}, Ptr{ZZRingElem}), reinterpret(Ptr{Int}, pointer_from_objref(b))+3*s, a_ptr+3*s)
# The C type `nf_elem_t` (corresponding to `AbsSimpleNumFieldElem`) starts with
# an `fmpq_poly_t` (our `QQPolyRingElem`).
Comment on lines +927 to +928
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that this is true, since the quadratic case is handled differently: https://github.com/flintlib/flint/blob/main/src/nf_elem.h#L49.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it may be wrong. I'll update it once I find the time.

(Just to explain how this PR came about: I converted ccalls in Hecke to use the new Nemo helpers like set!, but the code in here really confused the hell out of me, so I tried to untangle it... at some point I decided it's not worth it right now to try to convert it, but thought that perhaps my comments would still be helpful.)


# compute r*y, where `r` is the second coefficient in k.pol_coeffs (hence `p_ptr+s`)
# and `y` is the second coefficient in `a`
ccall((:fmpz_mul, libflint), Cvoid, (Ref{ZZRingElem}, Ptr{Int}, Ptr{Int}), q, p_ptr+s, a_ptr+s)
# compute x - r*y, store it as first coefficient for `b`
ccall((:fmpz_sub, libflint), Cvoid, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), b_ptr, a_ptr, q)
# compute -y, store it as second coefficient for `b`
ccall((:fmpz_neg, libflint), Cvoid, (Ptr{ZZRingElem}, Ptr{ZZRingElem}), b_ptr+s, a_ptr+s)
# copy the denominator from `a` to `b`
ccall((:fmpz_set, libflint), Cvoid, (Ptr{ZZRingElem}, Ptr{ZZRingElem}), b_ptr+3*s, a_ptr+3*s)
end
#TODO:
# - write in c?
Expand Down
Loading