sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.37k stars 462 forks source link

various Dirichlet character fixes/improvements #2192

Closed craigcitro closed 16 years ago

craigcitro commented 16 years ago

This patch does a number of different things:

I think that's it for this patch.

CC: @ncalexan

Component: number theory

Issue created by migration from https://trac.sagemath.org/ticket/2192

craigcitro commented 16 years ago

Attachment: trac-2192-dirichlet.patch.gz

Attachment: trac-2192-pt2.patch.gz

craigcitro commented 16 years ago
comment:1

Whoops ... I just realized I did an mpz_init() without an mpz_clear(), so I went and fixed that.

93749b3a-c0a4-47a7-b178-004ba08b0b97 commented 16 years ago
comment:2

In general I like this patch, but I have the following question:

Why is the integral_values parameter necessary? Since the output is always an algebraic integer, why not always return a result in the Maximal Order and have the coercion mechanism do the dirty work?

craigcitro commented 16 years ago
comment:3

ncalexan -- that's a good point, and I asked William exactly the same thing when I first noticed this. The issue is this: the main place that values of Dirichlet characters get used in Sage right now is in modular symbols calculations, which happen over a field (because it's all linear algebra). As a result, if we switched it to always return an element of the maximal order, the modular symbols code would pay the price of doing coercions every time it did, well, anything with Dirichlet characters, which is no good.

williamstein commented 16 years ago
comment:4

REFEREE REPORT:

Very good patch. A few minor points:

  1. There is at least one more "pyrex"'s that should be Cython appearing in the patch(ed) files.

  2. The doctests of {_lift_cyclotomic_element(self, new_parent)} in number_field_element_quadratic.pyx are NOT testing quadratic elements. Change the doctests to test the right thing.

  3. This appears twice in the code now:

        # Right now, I'm a little confused why quadratic extension
        # fields have a zeta_order function. I would rather they not
        # have this function, since I don't want to do this isinstance
        # check here.

Maybe we could delete it? Or?

  1. A comment says:
            if new_parent.degree() == 2: 
                ## we can only get here if self.parent() and 
                ## new_parent are exactly the two fields 
                ## CyclotomicField(3) and CyclotomicField(6) 

Why?

  1. Regarding the integral_value point, the current implementation (in this patch) is wrong. The right solution should be to make it so this works:
sage: G = DirichletGroup(60, CyclotomicField(4).ring_of_integers())
<boom right now>

Right now this fails because is_field isn't defined for rings of integers (see trac #2208). However that should get fixed. The idea with the DirichletGroup command is that DirichletGroup(N,R) gives Dirichlet characters with values in R. One shouldn't use an option to __call__ to determine the values of the character. Code like this

            if not integral_value:
                return result
            else:
                return self.base_ring().ring_of_integers()(result)

in the patch will actually break if one makes DirichletGroup(N,R) and R doesn't have a ring_of_integer() function, and the user asks for integral_value.

SUMMARY: Improve the comments a little, get rid of the integral_value option, and make a new trac ticket for fixing DirichletGroup(N,R) so it works when R is the ring of integers. Also possibly make DirichletGroup(N, integral=True) return the group with values in the ring of integers of the best cyclotomic field.

William

craigcitro commented 16 years ago

single patch with all changes

craigcitro commented 16 years ago
comment:6

Attachment: trac-2192-full.patch.gz

I've fixed several things, addressed all the referee's comments, and attached a new patch. Here's a quick description of what went into the new patch:

Just for the sake of completeness, let me address all the comments in William's referee report:

  1. Changed all the pyrexs to cythons.
  2. Actually, this doctests are perfectly fine. Notice that (somewhat counter-intuitively for me, as well as you) it's a method on the element, not on the field. So if x is in a quadratic extension, x._lift_cyclotomic_element(...) calls specifically that code.
  3. Yep, took those out. I always feel rude removing other people's comments -- after all, if I leave comments in the code, I think it's for a reason. But these are now gone.
  4. This is similar to (2) -- the issue is that in that case, you know both self.parent() and new_parent are cyclotomic fields of degree 2 over Q, and that an embedding is possible. Actually, I guess you could also have cf3 and cf3, or cf6 and cf6. The code still works in this case, but I've corrected the comment and I'll add the patch after I finish typing this.
  5. Done. I agree, this is cleaner. I didn't read until the end that you thought it should be on a separate ticket, so I'm including it here (since it's already pretty mixed in with this character code). I also added the integral flag.

I think that covers it.

craigcitro commented 16 years ago

Attachment: trac-2192-touch-up.patch.gz

apply after trac-2192-full.patch

85eec1a4-3d04-4b4d-b711-d4db03337c41 commented 16 years ago
comment:8

Merged both patches as directed in Sage 2.10.4.alpha0