def projective_point(p): """ Return equivalent point with denominators removed INPUT: - ``P``, ``Q`` -- list/tuple of projective coordinates. OUTPUT: List of projective coordinates. EXAMPLES:: sage: from sage.schemes.elliptic_curves.constructor import projective_point sage: projective_point([4/5, 6/5, 8/5]) [2, 3, 4] sage: F = GF(11) sage: projective_point([F(4), F(8), F(2)]) [4, 8, 2] """ from sage.rings.integer import GCD_list from sage.arith.functions import LCM_list try: p_gcd = GCD_list([x.numerator() for x in p]) p_lcm = LCM_list(x.denominator() for x in p) except AttributeError: return p scale = p_lcm / p_gcd return [scale * x for x in p]
def _find_cusps(self): r""" Calculate the reduced representatives of the equivalence classes of cusps for this group. Adapted from code by Ron Evans. EXAMPLE:: sage: Gamma(8).cusps() # indirect doctest [0, 1/4, 1/3, 3/8, 1/2, 2/3, 3/4, 1, 4/3, 3/2, 5/3, 2, 7/3, 5/2, 8/3, 3, 7/2, 11/3, 4, 14/3, 5, 6, 7, Infinity] """ n = self.level() C = [QQ(x) for x in xrange(n)] n0 = n // 2 n1 = (n + 1) // 2 for r in xrange(1, n1): if r > 1 and gcd(r, n) == 1: C.append(ZZ(r) / ZZ(n)) if n0 == n / 2 and gcd(r, n0) == 1: C.append(ZZ(r) / ZZ(n0)) for s in xrange(2, n1): for r in xrange(1, 1 + n): if GCD_list([s, r, n]) == 1: # GCD_list is ~40x faster than gcd, since gcd wastes loads # of time initialising a Sequence type. u, v = _lift_pair(r, s, n) C.append(ZZ(u) / ZZ(v)) return [Cusp(x) for x in sorted(C)] + [Cusp(1, 0)]
def base_rays(self, fiber, points): r""" Return the primitive lattice vectors that generate the direction given by the base projection of points. INPUT: - ``fiber`` -- a sub-lattice polytope defining the :meth:`base_projection`. - ``points`` -- the points to project to the base. OUTPUT: A tuple of primitive `\ZZ`-vectors. EXAMPLES:: sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: poly = LatticePolytope_PPL((-9,-6,-1,-1),(0,0,0,1),(0,0,1,0),(0,1,0,0),(1,0,0,0)) sage: fiber = next(poly.fibration_generator(2)) sage: poly.base_rays(fiber, poly.integral_points_not_interior_to_facets()) ((-1, -1), (0, 1), (1, 0)) sage: p = LatticePolytope_PPL((1,0),(1,2),(-1,0)) sage: f = LatticePolytope_PPL((1,0),(-1,0)) sage: p.base_rays(f, p.integral_points()) ((1),) """ quo = self.base_projection(fiber) vertices = set() for p in points: v = quo(p).vector() if v.is_zero(): continue d = GCD_list(v.list()) if d > 1: v = v.__copy__() for i in range(v.degree()): v[i] /= d v.set_immutable() vertices.add(v) return tuple(sorted(vertices))
from sage.rings.integer import GCD_list f = open('B-large.in', 'r') fout = open('B-large.out', 'w') C = int(f.readline().strip()) for c in range(C): line = f.readline().strip().split() N = int(line[0]) ti = [int(line[i + 1]) for i in range(N)] ti.sort() diffs = [ti[i + 1] - ti[i] for i in range(N - 1)] #print diffs #w = GCD_list(diffs) #print w #print (-ti[0]) % w fout.write('Case #%d: ' % (c+1)) fout.write(str((-ti[0]) % GCD_list(diffs))) fout.write('\n')