def setup_fields_and_triangles(self): from sage.all import RealIntervalField, ComplexIntervalField, sin, cos, exp self.RIF = RealIntervalField(120) self.CIF = ComplexIntervalField(120) alpha = self.RIF(0.4) self.finiteTriangle1 = FiniteTriangle([ FinitePoint(z=exp(self.CIF(0, 2.1 * i + 0.1)) * cos(alpha), t=sin(alpha)) for i in range(3) ]) self.idealTriangle1 = IdealTriangle([ ProjectivePoint(z=exp(self.CIF(0, 2.1 * i + 0.1))) for i in range(3) ]) self.idealTriangle2 = IdealTriangle( [ProjectivePoint(self.CIF(z)) for z in [-1, 0, 1]]) self.idealTriangle3 = IdealTriangle([ ProjectivePoint(self.CIF(1)), ProjectivePoint(self.CIF(-1)), ProjectivePoint(self.CIF(0), True) ])
def __init__(self, tiling_engine, bits_prec=53): self.RIF = RealIntervalField(bits_prec) self.CIF = ComplexIntervalField(bits_prec) self.baseTetInCenter = FinitePoint( self.CIF(tiling_engine.baseTetInCenter.z), self.RIF(tiling_engine.baseTetInCenter.t)) self.generator_matrices = { g: m.change_ring(self.CIF) for g, m in tiling_engine.mcomplex.GeneratorMatrices.items() } self.max_values = {} for tile in tiling_engine.all_tiles(): if tile.word: matrix = prod(self.generator_matrices[g] for g in tile.word) tileCenter = FinitePoint(self.CIF(tile.center.z), self.RIF(tile.center.t)) err = tileCenter.dist( self.baseTetInCenter.translate_PSL(matrix)).upper() l = len(tile.word) self.max_values[l] = max(err, self.max_values.get(l, err))
def __init__(self, tiling_engine, bits_prec=2 * 53): self.RIF = RealIntervalField(bits_prec) self.CIF = ComplexIntervalField(bits_prec) self.baseTetInCenter = vector( self.RIF, complex_and_height_to_R13_time_vector( tiling_engine.baseTetInCenter.z, tiling_engine.baseTetInCenter.t)) self.generator_matrices = { g: matrix(self.RIF, PSL2C_to_O13(m)) for g, m in tiling_engine.mcomplex.GeneratorMatrices.items() } self.max_values = {} for tile in tiling_engine.all_tiles(): if tile.word: m = prod(self.generator_matrices[g] for g in tile.word) tileCenter = vector( self.RIF, complex_and_height_to_R13_time_vector( tile.center.z, tile.center.t)) #print("=====") #print(tileCenter) #print(m * self.baseTetInCenter) #print(inner_prod(m * self.baseTetInCenter, tileCenter).endpoints()) err = my_dist(m * self.baseTetInCenter, tileCenter).upper() l = len(tile.word) self.max_values[l] = max(err, self.max_values.get(l, err))
def evaluate_at_roots(numberField, exact_values, precision=53): """ numberField is a sage number field. exact_values a dictionary where values are elements in that number field. precision is desired precision in bits. For each embedding of the number field, evaluates the values in the dictionary and produces a new dictionary with the same keys. The new dictionaries are returned in a list. """ CIF = ComplexIntervalField(precision) return [{k: v.lift().substitute(root) for k, v in exact_values.items()} for root, multiplicity in numberField.polynomial().roots(CIF)]
def matrices(self): from sage.all import RealIntervalField, ComplexIntervalField, matrix RIF = RealIntervalField(120) CIF = ComplexIntervalField(120) return [ matrix([[CIF(RIF(1.3), RIF(-0.4)), CIF(RIF(5.6), RIF(2.3))], [CIF(RIF(-0.3), RIF(0.1)), CIF(1)]]), matrix([[CIF(RIF(0.3), RIF(-1.4)), CIF(RIF(3.6), RIF(6.3))], [CIF(RIF(-0.3), RIF(1.1)), CIF(1)]]), matrix([[CIF(2.3, 1.2), CIF(0)], [CIF(0), CIF(1)]]), matrix([[CIF(2.3, 1.2), CIF(5)], [CIF(0), CIF(1)]]), matrix([[CIF(2.3, 1.2), CIF(0)], [CIF(5.6), CIF(1)]]), matrix([[CIF(1), CIF(10.0)], [CIF(0), CIF(1)]]), matrix([[CIF(1), CIF(0)], [CIF(10.0), CIF(1)]]), matrix([[CIF(0), CIF(-1)], [CIF(1), CIF(2)]]), matrix([[CIF(2), CIF(-1)], [CIF(1), CIF(0)]]) ]
def test_plane_point(self): from sage.all import RealIntervalField, ComplexIntervalField CIF = ComplexIntervalField(120) RIF = RealIntervalField(120) pts = [ ProjectivePoint(CIF(1.01)), ProjectivePoint(CIF(3)), ProjectivePoint(CIF(2, 1)) ] pt = FinitePoint(CIF(2, 5), RIF(3)) plane = PlaneReflection.from_three_projective_points(*pts) p = PlanePointDistanceEngine(plane, PointReflection.from_finite_point(pt)) e = p.endpoint() if not abs(p.dist() - pt.dist(e)) < 1e-20: raise Exception("Distance incorrect %r %r" % (p.dist(), pt.dist(e)))
def test_plane_plane(self): from sage.all import RealIntervalField, ComplexIntervalField CIF = ComplexIntervalField(120) RIF = RealIntervalField(120) pts = [[ ProjectivePoint(CIF(1)), ProjectivePoint(CIF(3)), ProjectivePoint(CIF(2, 1)) ], [ ProjectivePoint(CIF(-1)), ProjectivePoint(CIF(-3)), ProjectivePoint(CIF(-2, 1)) ]] planes = [ PlaneReflection.from_three_projective_points(*pt) for pt in pts ] p = PlanePlaneDistanceEngine(*planes) e = p.endpoints() if not abs(p.dist() - e[0].dist(e[1])) < 1e-20: raise Exception("Distance incorrect %r %r" % (p.dist(), e[0].dist(e[1]))) e_baseline = [ FinitePoint(CIF(1.5), RIF(0.75).sqrt()), FinitePoint(CIF(-1.5), RIF(0.75).sqrt()) ] for e0, e_baseline0 in zip(e, e_baseline): if not e0.dist(e_baseline0) < 1e-15: raise Exception("%s %s" % (e0, e_baseline0))
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
from sage.all import ComplexIntervalField, RealNumber, ZZ, CDF, prime_pi, prime_divisors, ComplexBallField, RealIntervalField, QQ, prime_powers, PowerSeriesRing, PolynomialRing, prod, spline, srange, gcd, primes_first_n, exp, pi, I, next_prime, Infinity, RR import os, sys, json from dirichlet_conrey import DirichletGroup_conrey, DirichletCharacter_conrey # 265 = 80 digits default_prec = 300 CCC = ComplexBallField(default_prec) RRR = RealIntervalField(default_prec) CIF = ComplexIntervalField(default_prec) def toRRR(elt, drop = True): if "." in elt and len(elt) > 70: # drop the last digit and convert it to an unkown if 'E' in elt: begin, end = elt.split("E") elif 'e' in elt: begin, end = elt.split("E") else: begin = elt end = "0" if drop: begin = begin[:-1] # drop the last digit return RRR(begin + "0e" + end, begin + "9e" + end) else: return RRR(elt) def toCCC(r, i, drop = True): return CCC(toRRR(r, drop)) + CCC.gens()[0]*CCC(toRRR(i, drop)) def print_RRR(elt): if elt.contains_integer(): try: