Пример #1
0
def niceideals(F, ideals):  #HNF + sage ideal + label
    """Convert a list of ideas from strongs to actual NumberField ideals

    F is a Sage NumberField

    ideals is a list of strings representing ideals I in the field, of
    the form [N,a,alpha] where N is the norm of I, a the least
    positive integer in I, and alpha a field element such that I is
    generated by a and alpha.

    The output is a list

    """
    nideals = []
    ilabel = 1
    norm = ZZ(0)
    for i in range(len(ideals)):
        N, n, idl, _ = str2ideal(F, ideals[i])
        assert idl.norm() == N and idl.smallest_integer() == n
        if N != norm:
            ilabel = ZZ(1)
            norm = N
        label = N.str() + '.' + ilabel.str()
        hnf = idl.pari_hnf().python()
        nideals.append([hnf, idl, label])
        ilabel += 1
    return nideals
Пример #2
0
def niceideals(F, ideals): #HNF + sage ideal + label
    """Convert a list of ideas from strongs to actual NumberField ideals

    F is a Sage NumberField

    ideals is a list of strings representing ideals I in the field, of
    the form [N,a,alpha] where N is the norm of I, a the least
    positive integer in I, and alpha a field element such that I is
    generated by a and alpha.

    The output is a list

    """
    nideals = []
    ilabel = 1
    norm = ZZ(0)
    for i in range(len(ideals)):
        N,n,idl,_ = str2ideal(F,ideals[i])
        assert idl.norm() == N and idl.smallest_integer() == n
        if N != norm:
            ilabel = ZZ(1)
            norm = N
        label = N.str() + '.' + ilabel.str()
        hnf = idl.pari_hnf().python()
        nideals.append([hnf, idl, label])
        ilabel += 1
    return nideals
Пример #3
0
 def _iter_ideals(self, primes=False, number=None):
     """
     Iterator through all ideals of self.  Delivers dicts with keys
     'label' and 'ideal'.
     """
     count = 0
     ilabel = 1
     norm = ZZ(0)
     ideals = self.ideals
     if primes:
         ideals = self.primes
     for idlstr in ideals:
         N, n, idl, _ = str2ideal(self.K(), idlstr)
         assert idl.norm() == N and idl.smallest_integer() == n
         if N != norm:
             ilabel = ZZ(1)
             norm = N
         label = N.str() + '.' + ilabel.str()
         yield {'label': label, 'ideal': idl}
         ilabel += 1
         count += 1
         if count == number:
             raise StopIteration
Пример #4
0
 def _iter_ideals(self, primes=False, number=None):
     """
     Iterator through all ideals of self.  Delivers dicts with keys
     'label' and 'ideal'.
     """
     count = 0
     ilabel = 1
     norm = ZZ(0)
     ideals = self.ideals
     if primes:
         ideals = self.primes
     for idlstr in ideals:
         N,n,idl,_ = str2ideal(self.K(),idlstr)
         assert idl.norm() == N and idl.smallest_integer() == n
         if N != norm:
             ilabel = ZZ(1)
             norm = N
         label = N.str() + '.' + ilabel.str()
         yield {'label':label, 'ideal':idl}
         ilabel += 1
         count += 1
         if count==number:
             raise StopIteration
Пример #5
0
def read_lfunction_file_old(filename):
    """
    reads an .lfunction file
    adds to it the order_of_vanishing
    and Lhash


    expects:
    <target accuracy> + 1
    ZZ(root_number * 2^<target accuracy>) ???
    ZZ(L(1/2) * 2^<target accuracy>)
    order_of_vanishing
    n = number of zeros computed
    z1
    z2
    z3
    ...
    zn
    plot_delta
    number of plot_values
    plot_value1
    plot_value2
    ...
    """

    output = {};
    with open(filename, "r") as lfunction_file:
        for i, l in enumerate(lfunction_file):
            if i == 0:
                accuracy = int(l) - 1;
                output['accuracy'] = accuracy;
                two_power = 2 ** output['accuracy'];
                R = ComplexIntervalField(accuracy)
            elif i == 1:
                root_number  = R(*map(ZZ, l.split(" ")))/two_power;
                if (root_number - 1).contains_zero():
                    root_number = R(1);
                    sign_arg = 0;
                elif (root_number + 1).contains_zero():
                    root_number = R(-1);
                    sign_arg = 0.5
                else:
                    assert (root_number.abs() - 1).contains_zero(), "%s, %s" % (filename, root_number.abs() )
                    sign_arg = float(root_number.arg()/(2*pi))
                    root_number = root_number #.str(style="question").replace('?', '')
                output['root_number'] = root_number;
                output['sign_arg'] = sign_arg
            elif i == 2:
                output['leading_term'] = (R(ZZ(l))/two_power).str(style="question").replace('?', '');
            elif i == 3:
                output['order_of_vanishing'] = int(l);
                if output['order_of_vanishing'] > 0:
                    output['leading_term'] = '\N'
            elif i == 4:
                number_of_zeros = int(l);
                output['positive_zeros'] = [];
            elif i < 5 +  number_of_zeros:
                double_zero, int_zero = l.split(" ");
                double_zero = float(double_zero);
                int_zero = ZZ(int_zero);
                zero = RealNumber(int_zero.str()+".")/two_power;
                zero_after_string = (RealNumber(zero.str(truncate=False)) * two_power).round()
                assert double_zero == zero, "%s, %s != %s" % (filename, double_zero, zero)
                assert zero_after_string  == int_zero, "zero_after_field = %s\nint_zero = %s" % (zero_after_string, int_zero,)
                if int_zero == 0:
                    assert 5 +  output['order_of_vanishing'] > i, "%s, %s < %s" % (filename, 5 +  output['order_of_vanishing'], i);
                else:
                    assert 5 +  output['order_of_vanishing'] <= i,  "%s, %s >= %s" % (filename, 5 +  output['order_of_vanishing'], i);

                    # they will be converted to strings later on
                    # during populate_rational_rows
                    output['positive_zeros'] += [zero];
                    #Lhash = (first_zero * 2^100).round()
                    if 'Lhash' not in output:
                        output['Lhash'] = str( QQ(int_zero*2**(100 - accuracy)).round() )
                        if accuracy < 100:
                            output['Lhash'] = "_" +  output['Lhash'];
            elif i == 5 +  number_of_zeros:
                output['plot_delta'] = float(l);
            elif i == 6 +  number_of_zeros:
                len_plot_values = int(l);
                output['plot_values'] = [];
            elif i >  6 + number_of_zeros:
                output['plot_values'] += [float(l)];

    assert len(output['plot_values']) == len_plot_values, "%s, %s != %s" % (filename, len(output['plot_values']), len_plot_values)
    assert len(output['positive_zeros']) ==  number_of_zeros - output['order_of_vanishing'], "%s, %s != %s" % (filename, len(output['positive_zeros']),  output['number_of_zeros'] - output['order_of_vanishing']) ;


    assert 'Lhash' in output, "%s" % filename
    for i in range(0,3):
        output['z' + str(i + 1)] = str(output['positive_zeros'][i])

    return output
Пример #6
0
def read_lfunction_file(filename):
    """
    reads an .lfunction file
    adds to it the order_of_vanishing
    and Lhash


    expects:
    root_number as acb2, see from_acb2
    order_of_vanishing
    L(1/2)^r / r! as arb2
    n = number of zeros computed
    z1 as arb2
    z2 as arb2
    z3 as arb2
    ...
    zn as arb2
    plot_delta
    number of plot_values
    plot_value1
    plot_value2
    ...
    """
    output = {}
    with open(filename, "r") as lfunction_file:
        for i, l in enumerate(lfunction_file):
            if i == 0:
                # Root number
                vals = map(int, l.split())
                if len(vals) == 1:
                    return read_lfunction_file_old(filename)
                assert len(vals) == 6
                root_number = from_acb2(*vals)
                assert root_number.abs().contains_exact(1), "%s, %s" % (filename, root_number.abs() )
                try:
                    root_number = ZZ(root_number)
                    if root_number == 1:
                        sign_arg = 0
                    elif root_number == -1:
                        sign_arg = 0.5
                    else:
                        assert root_number in [1, -1], "%s %s" % (root_number, from_acb2(*vals))
                except Exception:
                    sign_arg = float(root_number.arg()/(2*pi))
                root_number = CIF(root_number) # for conversion to text purposes
                output['root_number'] = root_number;
                output['sign_arg'] = sign_arg;
            elif i == 1:
                # Order of vanishing
                output['order_of_vanishing'] = int(l);
            elif i == 2:
                # Leading term
                # L^(r)(1/2) / r!
                vals = map(int, l.split())
                assert len(vals) == 3
                output['leading_term'] = RRR(from_arb2(*vals)).str(style="question").replace('?', '')
            elif i == 3:
                # Number of zeros
                number_of_zeros = int(l);
                output['positive_zeros'] = [];
            elif i < 4 +  number_of_zeros:
                vals = map(int, l.split())
                assert len(vals) == 3
                if vals == [0,0,0]:
                    int_zero = 0
                    double_zero = 0
                    assert 4 +  output['order_of_vanishing'] > i, "%s, %s < %s" % (filename, 5 +  output['order_of_vanishing'], i);
                else:
                    assert 4 +  output['order_of_vanishing'] <= i,  "%s, %s >= %s" % (filename, 5 +  output['order_of_vanishing'], i);
                    assert vals[1] - vals[0] <= 2, "%s %s %s" % (filename, vals, i)
                    arb_zero = from_arb2(*vals).real()
                    double_zero = float(arb_zero)
                    if 'accuracy' not in output:
                        # if vals[3] = -101
                        # then accuracy = 100
                        output['accuracy'] = -vals[2] - 1
                        two_power = 2**output['accuracy']
                    else:
                        assert -(output['accuracy'] + 1) == vals[2]
                    try:
                        int_zero = ZZ(arb_zero*two_power)
                    except ValueError:
                        print "%s %s %s" % (filename, vals, i)
                        raise
                    zero = RealNumber(int_zero.str()+".")/two_power;
                    zero_after_string = (RealNumber(zero.str(truncate=False)) * two_power).round()
                    assert double_zero == zero, "%s, %s != %s" % (filename, double_zero, zero)
                    assert zero_after_string  == int_zero, "zero_after_field = %s\nint_zero = %s" % (zero_after_string, int_zero,)
                    # will be converted to strings later on
                    # as zero.str(truncate=False)
                    # during populate_rational_rows
                    output['positive_zeros'] += [zero];
                    #Lhash = (first_zero * 2^100).round()
                    if 'Lhash' not in output:
                        output['Lhash'] = str( QQ(int_zero*2**(100 - output['accuracy'])).round() )
                        if output['accuracy'] < 100:
                            output['Lhash'] = "_" +  output['Lhash'];
            elif i == 4 +  number_of_zeros:
                output['plot_delta'] = float(l);
            elif i == 5 +  number_of_zeros:
                len_plot_values = int(l);
                output['plot_values'] = [];
            elif i >  5 + number_of_zeros:
                output['plot_values'] += [float(l)];
    assert len(output['plot_values']) == len_plot_values, "%s, %s != %s" % (filename, len(output['plot_values']), len_plot_values)
    assert len(output['positive_zeros']) ==  number_of_zeros - output['order_of_vanishing'], "%s, %s != %s" % (filename, len(output['positive_zeros']),  output['number_of_zeros'] - output['order_of_vanishing']) ;

    assert 'Lhash' in output, "%s" % filename
    for i in range(0,3):
        # were we don't want to truncate
        output['z' + str(i + 1)] = str(output['positive_zeros'][i])

    return output