Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions src/sage/matrix/matrix_integer_dense_hnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,10 @@ def ones(H, pivots):
# that contain exactly one "1" entry and all other entries 0.
onecol = []
onerow = []
i = 0
for c in pivots:
for i, c in enumerate(pivots):
if H[i, c] == 1:
onecol.append(c)
onerow.append(i)
i += 1
onecol_set = set(onecol)
non_onerow = [j for j in range(len(pivots)) if j not in onerow]
non_onecol = [j for j in range(H.ncols()) if j not in onecol_set][:len(non_onerow)]
Expand Down
4 changes: 1 addition & 3 deletions src/sage/matroids/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,9 @@ def Matroid(groundset=None, data=None, **kwds):
V = G.vertices(sort=True)
n = G.num_verts()
A = matrix(ZZ, n, m, 0)
mm = 0
for i, j, k in G.edge_iterator():
for mm, (i, j, k) in enumerate(G.edge_iterator()):
A[V.index(i), mm] = -1
A[V.index(j), mm] += 1 # So loops get 0
mm += 1
M = RegularMatroid(matrix=A, groundset=groundset)
want_regular = False # Save some time, since result is already regular
else:
Expand Down
12 changes: 2 additions & 10 deletions src/sage/matroids/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,8 @@ def make_regular_matroid_from_matroid(matroid):
# First create a reduced 0-1 matrix
B = list(M.basis())
NB = list(M.groundset().difference(B))
dB = {}
i = 0
for e in B:
dB[e] = i
i += 1
dNB = {}
i = 0
for e in NB:
dNB[e] = i
i += 1
dB = {e: i for i, e in enumerate(B)}
dNB = {e: i for i, e in enumerate(NB)}
A = Matrix(ZZ, len(B), len(NB), 0)
G = BipartiteGraph(A.transpose()) # Sage's BipartiteGraph uses the column set as first color class. This is an edgeless graph.
for e in NB:
Expand Down
63 changes: 27 additions & 36 deletions src/sage/misc/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,45 +2164,36 @@ def repr_lincomb(symbols, coeffs):
sage: latex(x)
\text{\texttt{x}} + 2\text{\texttt{y}}
"""
s = ""
first = True
i = 0

from sage.rings.cc import CC
terms = []
for c, sym in zip(coeffs, symbols):
if c == 0:
continue
if c == 1:
coeff = ""
elif c == -1:
coeff = "-"
else:
coeff = coeff_repr(c)

for c in coeffs:
bv = symbols[i]
b = latex(bv)
if c != 0:
if c == 1:
if first:
s += b
else:
s += " + %s" % b
b = latex(sym)
# this is a hack: I want to say that if the symbol happens to
# be a number, then we should put a multiplication sign in
try:
if sym in CC and coeff not in ("", "-"):
term = f"{coeff}\\cdot {b}"
else:
coeff = coeff_repr(c)
if coeff == "-1":
coeff = "-"
if first:
coeff = str(coeff)
else:
coeff = " + %s" % coeff
# this is a hack: i want to say that if the symbol
# happens to be a number, then we should put a
# multiplication sign in
try:
if bv in CC:
s += r"%s\cdot %s" % (coeff, b)
else:
s += "%s%s" % (coeff, b)
except Exception:
s += "%s%s" % (coeff, b)
first = False
i += 1
if first:
s = "0"
s = s.replace("+ -", "- ")
return s
term = f"{coeff}{b}"
except Exception:
term = f"{coeff}{b}"

terms.append(term)

if not terms:
return "0"

s = " + ".join(terms)
return s.replace("+ -", "- ")
Copy link
Contributor

Choose a reason for hiding this comment

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

the following lines should be removed, and there is whitespace. Sorry, that's an artefact of how github suggestions do not work :-(

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.. now fixed



common_varnames = ['alpha',
Expand Down
4 changes: 1 addition & 3 deletions src/sage/monoids/automatic_semigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,11 @@ def _iter_concurrent(self):
sage: M._constructed
True
"""
i = 0
# self._elements is never empty; so we are sure
for x in self._elements:
for i, x in enumerate(self._elements, 1):
yield x
# some other iterator/ method of the semigroup may have
# been called before we move on to the next line
i += 1
if i == len(self._elements) and not self._constructed:
try:
next(self._iter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ def class_polynomial(self):
# the Fq-vector space generated by the phi_T^i(T^(-s+1))
# for i varying in NN.
v = vector(Fq, s)
v[s-1] = 1
v[s - 1] = 1
vs = [v]
for i in range(s-1):
v = v*M
for i in range(s - 1):
v = v * M
vs.append(v)
V = matrix(vs)
V.echelonize()
Expand All @@ -638,12 +638,11 @@ def class_polynomial(self):
# as an Fq-linear map (encoded in the matrix N)
dim = V.rank()
pivots = V.pivots()
j = ip = 0
for i in range(dim, s):
j = 0
for ip, i in enumerate(range(dim, s)):
while ip < dim and j == pivots[ip]:
j += 1
ip += 1
V[i,j] = 1
V[i, j] = 1
N = (V * M * ~V).submatrix(dim, dim)

# The class module is now H where the action of T
Expand Down
23 changes: 11 additions & 12 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -11924,18 +11924,17 @@ def _multiplicative_order_table(self):
try:
return self.__multiplicative_order_table
except AttributeError:
t = {}
x = self(1)
n = self.zeta_order()
m = 0
zeta = self.zeta(n)
# todo: this desperately needs to be optimized!!!
for i in range(n):
t[x.polynomial()] = n // gcd(m, n) # multiplicative_order of (zeta_n)**m
x *= zeta
m += 1
self.__multiplicative_order_table = t
return t
pass
t = {}
x = self.one()
n = self.zeta_order()
zeta = self.zeta(n)
# todo: this desperately needs to be optimized!!!
for m in range(n):
t[x.polynomial()] = n // gcd(m, n) # multiplicative_order of (zeta_n)**m
x *= zeta
self.__multiplicative_order_table = t
return t

def zeta(self, n=None, all=False):
"""
Expand Down
9 changes: 3 additions & 6 deletions src/sage/rings/polynomial/polynomial_quotient_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,13 +1351,10 @@ def _S_decomposition(self, S):
fields = []
isos = []
iso_classes = []
i = 0
for f, _ in F:
D = K.extension(f, 'x'+str(i))
for i, (f, _) in enumerate(F):
D = K.extension(f, f'x{i}')
fields.append(D)
D_abs = D.absolute_field('y'+str(i))
i += 1

D_abs = D.absolute_field(f'y{i}')
seen_before = False
j = 0
for D_iso, _ in iso_classes:
Expand Down
4 changes: 1 addition & 3 deletions src/sage/schemes/elliptic_curves/ell_egros.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,15 @@ def egros_get_j(S=[], proof=None, verbose=False):
SS = [-1] + S

jlist = []
wcount = 0
nw = 6**len(S) * 2

if verbose:
print("Finding possible j invariants for S = ", S)
print("Using ", nw, " twists of base curve")
sys.stdout.flush()

for ei in xmrange([6] * len(S) + [2]):
for wcount, ei in enumerate(xmrange([6] * len(S) + [2]), 1):
w = QQ.prod(p**e for p, e in zip(reversed(SS), ei))
wcount += 1
if verbose:
print("Curve #", wcount, "/", nw, ":")
print("w = ", w, "=", w.factor())
Expand Down
6 changes: 2 additions & 4 deletions src/sage/schemes/elliptic_curves/ell_rational_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -6925,13 +6925,12 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound):
mw_base_p_log = []
beta = []
mp = []
tmp = 0
for p in S:
for tmp, p in enumerate(S):
Np = E.Np(p)
cp = E.tamagawa_exponent(p)
mp_temp = Z(len_tors).lcm(cp*Np)
mp.append(mp_temp) # only necessary because of verbose below
p_prec = 30+E.discriminant().valuation(p)
p_prec = 30 + E.discriminant().valuation(p)
p_prec_ok = False
while not p_prec_ok:
if verbose:
Expand All @@ -6957,7 +6956,6 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound):
except ValueError:
# e.g. mw_base_p_log[tmp]==[0]: can occur e.g. [?]'172c6, S=[2]
beta.append([0] for j in range(r))
tmp += 1

if verbose:
print('mw_base', mw_base)
Expand Down
12 changes: 3 additions & 9 deletions src/sage/schemes/elliptic_curves/gal_reps_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,21 +571,15 @@ def primes_iter():
for P in K.primes_above(p):
if E.has_good_reduction(P):
yield P
numP = 0
for P in primes_iter():

for numP, P in enumerate(primes_iter()):
if not L or numP == patience: # stop if no primes are left, or patience is exhausted
break

numP += 1

# Discard any l for which the Frobenius polynomial at P is
# irreducible modulo l

disc = E.reduction(P).frobenius_polynomial().discriminant()

L = [l for l in L if legendre_symbol(disc,l) != -1]

#print("After using {} primes P, {} primes l remain".format(numP,len(L)))
L = [l for l in L if legendre_symbol(disc, l) != -1]

if include_2:
L = [2] + L
Expand Down
39 changes: 18 additions & 21 deletions src/sage/tensor/modules/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def __getitem__(self, args):
return self._output_formatter(self._ring.zero())
else:
return self._output_formatter(self._ring.zero(),
format_type)
format_type)

def _get_list(self, ind_slice, no_format=True, format_type=None):
r"""
Expand Down Expand Up @@ -2345,23 +2345,21 @@ def compprod(a, b):
# definition of the parallel function
@parallel(p_iter='multiprocessing', ncpus=nproc)
def make_Contraction(this, other, local_list, rev_s, rev_o,
shift_o,contractions, comp_for_contr):
shift_o, contractions, comp_for_contr):
local_res = []
for ind in local_list:
ind_s = [None for i in range(this._nid)] # initialization
ind_o = [None for i in range(other._nid)] # initialization
ind_o = [None for i in range(other._nid)] # initialization
for i, pos in enumerate(rev_s):
ind_s[pos] = ind[i]
for i, pos in enumerate(rev_o):
ind_o[pos] = ind[shift_o+i]
ind_o[pos] = ind[shift_o + i]
sm = 0
for ind_c in comp_for_contr.index_generator():
ic = 0
for pos_s, pos_o in contractions:
for ic, (pos_s, pos_o) in enumerate(contractions):
k = ind_c[ic]
ind_s[pos_s] = k
ind_o[pos_o] = k
ic += 1
sm += this[[ind_s]] * other[[ind_o]]
local_res.append([ind, sm])
return local_res
Expand All @@ -2373,19 +2371,17 @@ def make_Contraction(this, other, local_list, rev_s, rev_o,
# sequential computation
for ind in res.non_redundant_index_generator():
ind_s = [None for i in range(self._nid)] # initialization
ind_o = [None for i in range(other._nid)] # initialization
ind_o = [None for i in range(other._nid)] # initialization
for i, pos in enumerate(rev_s):
ind_s[pos] = ind[i]
for i, pos in enumerate(rev_o):
ind_o[pos] = ind[shift_o+i]
ind_o[pos] = ind[shift_o + i]
sm = 0
for ind_c in comp_for_contr.index_generator():
ic = 0
for pos_s, pos_o in contractions:
for ic, (pos_s, pos_o) in enumerate(contractions):
k = ind_c[ic]
ind_s[pos_s] = k
ind_o[pos_o] = k
ic += 1
sm += self[[ind_s]] * other[[ind_o]]
res[[ind]] = sm

Expand Down Expand Up @@ -2775,7 +2771,7 @@ def _matrix_(self):
return matrix(tab)


#******************************************************************************
# *****************************************************************************

class CompWithSym(Components):
r"""
Expand Down Expand Up @@ -4018,15 +4014,16 @@ def non_redundant_index_generator(self):
# to reset it
ind[isym[k]] = si
if not step_finished and i == 0 and len(antisym) == 0:
return # we went through all indices and didn't
# find one which we can increase, thus we
# have generated all indices
for i in range(len(antisym)-1,-1,-1):
# we went through all indices and didn't find one
# which we can increase, thus we have generated
# all indices
return
for i in range(len(antisym)-1, -1, -1):
# the antisymmetrized indices work similar to the
# symmetrized ones
isym = antisym[i]
if not step_finished:
for k in range(len(isym)-1,-1,-1):
for k in range(len(isym)-1, -1, -1):
if ind[isym[k]] + len(isym)-1-k != imax:
ind[isym[k]] += 1
for l in range(k+1, len(isym)):
Expand Down Expand Up @@ -4609,7 +4606,7 @@ def antisymmetrize(self, *pos):
return result


#******************************************************************************
# *****************************************************************************

class CompFullySym(CompWithSym):
r"""
Expand Down Expand Up @@ -5054,7 +5051,7 @@ def paral_sum(a, b, local_list_ind):
return CompWithSym.__add__(self, other)


#******************************************************************************
# *****************************************************************************

class CompFullyAntiSym(CompWithSym):
r"""
Expand Down Expand Up @@ -5491,7 +5488,7 @@ def interior_product(self, other):
res[[ind]] = factorial_s*sm
return res

#******************************************************************************
# *****************************************************************************


class KroneckerDelta(CompFullySym):
Expand Down
Loading