# Francis Clarke's profile - activity

2015-12-02 10:11:52 +0200 commented answer Latex name of generators of number fields extending other number field

This is now trac ticket 19657

2015-12-01 17:26:31 +0200 answered a question Latex name of generators of number fields extending other number field

The problem is caused in the first place by a mistake in NumberFieldFactory. In line 610 of sage/rings/number_field/number_field.py(Sage 6.9), the latex_namedoesn't get passed on to the extension method of the base field.

Unfortunately, you cannot get round this by using extension directly; in this case:

sage: G.<alpha> = NumberField(x^2 - 2, latex_name='alpharedefined')
sage: print latex(alpha), G.latex_variable_name()
alpharedefined alpharedefined
sage: P.<t> = G[]
sage: H.<beta> = G.extension(t^4 - alpha, latex_name='betaredefined')
sage: print latex(beta), print H1.latex_variable_name()
\beta betaredefined


The inconsistencies here indicate that there are other things that need correcting in this part of the code.

2015-05-21 09:31:44 +0200 answered a question get the coefficients from the Polynomial
sage: f.coefficients(sparse=False)
[1, 1, 0, 1]


or

sage: f.list()
[1, 1, 0, 1]

2015-05-20 11:20:52 +0200 commented question Elements in the lattice $A_n$

Perhaps Compositions(k, length=n+1) would be closer to what you want.

2015-05-16 11:28:22 +0200 answered a question TypeError for hom between multivariate Laurent polynomial rings?

It seems that the root of the problem is :

sage: R.<a> = LaurentPolynomialRing(ZZ)
sage: S.<b,c> = LaurentPolynomialRing(ZZ)
sage: a.is_unit()
True
sage: b.is_unit()
Traceback (most recent call last):
...
NotImplementedError:

2015-05-15 11:54:46 +0200 commented question TypeError for hom between multivariate Laurent polynomial rings?

I note that R.hom([b], check=False) works ok.

2015-05-10 07:45:28 +0200 commented answer How to build a matrix thought of as an array of smaller matrices?

This is mostly fairly basic python syntax:

(1) d is not an empty list; it is a dictionary.

(2) m is a list of four lists of four 2 by 2 zero matrices. It is not a matrix, but (after it is modified) it is used to create a (block) matrix. The command could have been written as m = [[matrix(2, 2, 0) for j in range(4)] for i in range(4)]

(3) d = {} creates an empty dictionary; d = [] creates an empty list.

2015-05-09 14:14:59 +0200 answered a question How to build a matrix thought of as an array of smaller matrices?

The block_matrix construction will do what you want. An example follows.

I first set up a dictionary containing data of the kind you discussed (I'm assuming that the final entry in your data set should be $(1,3,D)$ if you want a $4k$ by $4k$ matrix )

sage: d = {}
sage: d[0, 2] = matrix([[5, 11], [1, 2]])
sage: d[0, 3] = matrix([[2, 3], [1, 1]])
sage: d[1, 2] = matrix([[-1, 3], [0, -1]])
sage: d[1, 3] = matrix([[4, 9], [-1, -2]])


Then I defined a 4 by 4 array of zero matrices and put the data matrices in the appropriate positions

sage: m = [[matrix(2, 2, 0)]*4 for _ in range(4)]
sage: for i in range(4):
....:     for j in range(4):
....:         if (i, j) in d:
....:             m[i][j] = d[i, j]
....:         elif (j, i) in d:
....:             m[i][j] = d[j, i].inverse()


Now

sage: block_matrix(m)
[ 0  0| 0  0| 5 11| 2  3]
[ 0  0| 0  0| 1  2| 1  1]
[-----+-----+-----+-----]
[ 0  0| 0  0|-1  3| 4  9]
[ 0  0| 0  0| 0 -1|-1 -2]
[-----+-----+-----+-----]
[-2 11|-1 -3| 0  0| 0  0]
[ 1 -5| 0 -1| 0  0| 0  0]
[-----+-----+-----+-----]
[-1  3|-2 -9| 0  0| 0  0]
[ 1 -2| 1  4| 0  0| 0  0]


All the usual matrix methods are available, e.g.,

sage: block_matrix(m).rank()
6

2015-05-02 18:47:09 +0200 answered a question Factor base of class group computation

The following does involve calling PARI's bnfinit. But for a number field K, K.class_group() calls bnfinit, the output of which is cached. The factor base used can be recovered as follows:

sage: K.<a> = NumberField(x^3 - 11)
sage: map(K.ideal, K.pari_bnf()[4])
[Fractional ideal (2, a + 1),
Fractional ideal (5, a - 1),
Fractional ideal (-a + 2),
Fractional ideal (2, a^2 + a + 1),
Fractional ideal (a)]

2015-02-01 18:57:36 +0200 answered a question Units in number fields.

The problem is that your ais not an algebraic integer (though its norm is 1).
Following on from your code :

sage: a.is_integral()
False
sage: a.minpoly()
x^2 - 3/2*x + 1

2014-12-17 14:55:42 +0200 commented answer Computations in a Quotient Ring

But e^5 equals -38*a*b*c*d*e in S, so the expression can be written as a polynomial in the mi times a*b*c*d*e

2014-12-03 09:35:33 +0200 commented question Bug in roots()?

Seems to be a bug in the Singular interface. For f._singular_() returns x^4

2014-11-19 11:26:43 +0200 answered a question Possible coefficients for a given discriminant

You can do:

sage: BinaryQF_reduced_representatives(-47)
[x^2 + x*y + 12*y^2,
2*x^2 - x*y + 6*y^2,
2*x^2 + x*y + 6*y^2,
3*x^2 - x*y + 4*y^2,
3*x^2 + x*y + 4*y^2]


and to get the coefficients:

sage: [qf.polynomial().coefficients() for qf in BinaryQF_reduced_representatives(-47)]
[[1, 1, 12], [2, -1, 6], [2, 1, 6], [3, -1, 4], [3, 1, 4]]

2014-11-02 10:47:51 +0200 commented answer How to compute this exponential generating function?

Probably worth noting that print oeis('Narayana')[0].programs()[0] gives a very simple formula for the coefficients.

2014-10-27 11:11:09 +0200 answered a question what matrix.plot meanings?

The lighter shades correspond to the larger entries of the matrix. In your example the black square are in positions (0, 1) and (2, 1), where the entries are -1, and the white square is in position (0, 0), where the entry is 3, which is the largest entry in the matrix. Typing

sage: M = matrix([[3,-1,1],[2,0,1],[1,-1,2]])
sage: M.plot?


2014-10-25 18:21:28 +0200 commented answer Homomorphisms for relative number fields

The problem should be solved by trac #10843.

2014-09-18 17:49:41 +0200 commented answer Homomorphisms for relative number fields

Now I see. Your F_pol was a symbolic expression, but mine was a polynomial. Unfortunately the root methods for each are not compatible.

2014-09-18 13:52:59 +0200 answered a question Homomorphisms for relative number fields

First you need to write

sage: lam_im = F_pol.roots(L)[1][0]
sage: e_im = K_pol.roots(L)[1][0]


Then the following works

sage: HomKL = K.Hom(L)
sage: HomKL(e_im, F.hom([lam_im]))
Relative number field morphism:
From: Number Field in e with defining polynomial x^2 + 4 over its base field
To:   Algebraic Field
Defn: e |--> 0.?e-53 + 2.000000000000000?*I
lam |--> 1.618033988749895? + 0.?e-53*I


Typing

sage: HomKL.__call__?


explains the syntax. There should be an easier way to do this.

## On the second question

This is a bug, the check parameter does not get passed on as it should be. I will raise a ticket to deal with this, but in the meantime you can get the result you want as follows.

sage: K_abs = K.absolute_field('a')
sage: from_abs = K_abs.structure()[0]
sage: a = from_abs(K_abs.gen())
sage: R = L['x']
sage: f = R(map(F.hom([lam_im], check=False), a))
sage: abs_hom = K_abs.hom([f(e_im)], check=False)
sage: from sage.rings.number_field.morphism import RelativeNumberFieldHomomorphism_from_abs
sage: RelativeNumberFieldHomomorphism_from_abs(K.Hom(L), abs_hom)
Relative number field morphism:
From: Number Field in e with defining polynomial x^2 - 4*lam^2 - 4*lam + 4 over its base field
To:   Complex Field with 53 bits of precision
Defn: e |--> 4.02438434522465
lam |--> 1.80193773580484


This is taken, with some slight modifications, from the code for _from_im in sage/rings/number_field/morphism.py, the key difference being the addition of check=False where abs_hom is defined.

2014-08-16 17:43:59 +0200 commented question Plane curve genus: new minimal polynomial

No, I did look briefly at the Singular documentation, but couldn't find anything helpful. Yes, I also found that the minimal polynomial varies. I tried calling genus(I) 32 times, and got 17 distinct polynomials. However, there were only 5 distinct leading coefficients.

2014-08-15 09:57:38 +0200 commented question Plane curve genus: new minimal polynomial

The calculation seems to be performed by Singular. Unwrapping the code, what C.genus() does is: sage: I = C.defining_ideal() sage: genus = sage.libs.singular.ff.normal__lib.genus sage: genus(I) // new minimal polynomial: 2097152a6+2359296a5-239616a4-518400a3+37800a2+13203a+54 11

2014-06-20 03:46:53 +0200 answered a question polynomial list, array

But maybe you meant:

sage: R.<x> = ZZ[]
sage: f = R.random_element(); f
-10*x^5 + 2*x^4 + 6*x^3 + x^2 + x + 4
sage: f.list()
[4, 1, 1, 6, 2, -10]


or

sage: list(f)
[4, 1, 1, 6, 2, -10]

2014-04-12 06:15:27 +0200 commented question QQ.extension() with embedding: incorrect modulus

This is definitely a defect in Sage. If z is an element in a number field K, then z.abs(i) returns the absolute value of the the i-th embedding of K into CC , and if i is omitted, the zero-th embedding is used. Thus any specified embedding used to construct K is ignored. I have raises a ticket on this issue; see http://trac.sagemath.org/ticket/16147.

2013-12-11 04:46:46 +0200 answered a question interger-ring() and maximal_order() is the same in numberfield

I think you must mean ring_of_integers rather than "interger-ring". And indeed K.ring_of_integers() and K.maximal_order() are the same for a number field K. You can see this explicitly as follows:

sage: K.ring_of_integers??
Type:       builtin_function_or_method
String Form:<built-in method ring_of_integers of NumberField_absolute_with_category object at     0x7f85bc4dae00>
Definition: K.ring_of_integers(self, *args, **kwds)
Source:
def ring_of_integers(self, *args, **kwds):
r"""
Synomym for self.maximal_order(...).

EXAMPLES::

sage: K.<a> = NumberField(x^2 + 1)
sage: K.ring_of_integers()
Maximal Order in Number Field in a with defining polynomial x^2 + 1
"""
return self.maximal_order()

2013-11-30 06:23:09 +0200 answered a question Yet another linear combination

This is just standard linear algebra: form a 21 by 20 matrix whose rows consist of the linearly dependent vectors and the 20 linearly independent vectors, and find the one-dimensional left kernel (nullspace); alternatively transpose and find the right kernel. The coefficients of the single element in a basis of the kernel provide a linear combination of all 21 vectors which is zero. Hence the dependent vector can be written as a linear combination of the 20 independent vectors.

A small scale version in Sage:

sage: V = VectorSpace(QQ, 6)
sage: vectors = [V.random_element() for _ in range(6)]
sage: V.subspace(vectors).rank()
6


Confirming that the vectors are linearly independent, otherwise repeat. Then form a random linear combination, and create the matrix:

sage: w = sum(randint(-4, 4)*v for v in vectors)
sage: A = matrix([w] + vectors)


Now take the first (and only) generator of the kernel, and verify the result:

sage: c = A.kernel().basis()[0]
sage: w == -sum(c[i+1]*vectors[i] for i in range(6))
True

2013-05-27 13:39:45 +0200 commented answer referencing polynomial variables

It is worth mentioning that R = PolynomialRing(ZZ, n, 'x') and P = sum(c\*R.gen(i) for i, c in enumerate(mylist)) are perhaps a little less cryptic, and that R.inject_variables() allows one to write things like Q = 3\*x1\*x2^3 - x3^4

2013-02-25 06:09:05 +0200 answered a question berlekamp massey

Yes, there is a problem with the Sage implementation. But other implementations such as the one at bma.bozhu.me may give varying results. The point is that for your sequence $s_0,s_1,\dots,s_{35}$ there does not exist a unique sequence $c_1,c_2,\dots,c_k$ in $GF(2)$ such that $$s_i+\sum_{j=1}^{k}c_js_{i-j}=0,\qquad\text{for i=k,\dots,35.}$$

The result that Sage produces comes from the fact that $$s_i+s_{i-2}+s_{i-3}+s_{i-4}+s_{i-5}=0,\qquad\text{for i=16,\dots,33.}$$ But this fails (generally) if $i=5,\dots,15$ or $i=34, 35$.

The degree 19 result indeed says that $$s_i+\sum_{j\in\lbrace1, 2, 5, 6, 9, 10, 11, 13, 16, 17, 19\rbrace}s_{i-j}=0,\qquad\text{for i=19,\dots,35.}$$ However, this is not unique (it cannot be because the input sequence only has length 36), for example we could add in $s_{i-2}+s_{i-4}+s_{i-5}+s_{i-6}+s_{i-7}$, which, as we have seen, is zero for $i=18,\dots,35$. Thus the degree 19 polynomial has no right to be called the minimal polynomial. Of course, Massey's 1969 paper "Shift-register synthesis and BCH decoding" is clear on this point; the algorithm he describes produces "one of the [linear feedback shift registers] of [minimum length] which generates $s_0,s_1,\dots,s_N$" [§ III].

2013-02-16 07:29:17 +0200 answered a question How does one find solutions to a polynomial over a finite field?

Alternatively

sage: R.<x,y> = GF(5)[]
sage: C = Curve(y^2 - x^3 - 1)
sage: C.point_set().points()
[(0, 1), (0, 4), (2, 2), (2, 3), (4, 0)]

2013-02-06 06:22:52 +0200 answered a question polynomial evaluation

For polynomial substitution there are several possibilities:

sage: R.<x,y,z> = QQ[]
sage: f = x^2*y + y^2*z + z^2*x
sage: f(1, 2, 3)
23
sage: f(x=1, y=2, z=3)
23
sage: f.subs(x=1, y=2, z=3)
23
sage: f(x=1)
y^2*z + z^2 + y


To handle symmetric polynomials it may be best to work in a polynomial ring. For example:

sage: E = SymmetricFunctionAlgebra(QQ, basis='elementary')
sage: g = E([2,1])
sage: h = g.expand(3); h
x0^2*x1 + x0*x1^2 + x0^2*x2 + 3*x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2
sage: R = h.parent()
sage: x0, x1, x2 = R.gens()


We can then check symmetry

sage: h == h(x0=x1, x1=x0) and h == h(x0=x1, x1=x2, x2=x0)
True


and do other sorts of substitution

sage: S.<q> = R[]
sage: h(1, q, q^2)
q^5 + 2*q^4 + 3*q^3 + 2*q^2 + q

sage: Z9.<c> = Zq(9)
sage: z = Z9.random_element(); z
2*c + (c + 2)*3 + (2*c + 2)*3^2 + (2*c + 2)*3^3 + 2*3^4 + (2*c + 1)*3^5 + (2*c + 1)*3^6 + (c + 2)*3^7 + c*3^8 + (2*c + 2)*3^10 + (c + 2)*3^11 + (2*c + 2)*3^13 + 2*3^14 + (2*c + 2)*3^15 + (c + 1)*3^16 + 2*c*3^17 + (2*c + 1)*3^18 + c*3^19 + O(3^20)
sage: z.list()
[[0, 2], [2, 1], [2, 2], [2, 2], [2], [1, 2], [1, 2], [2, 1], [0, 1], [], [2, 2], [2, 1], [], [2, 2], [2], [2, 2], [1, 1], [0, 2], [1, 2], [0, 1]]


But note that here the coefficient of $3^9$, which is zero, yields [] as its list of coefficients. Similarly, for the coefficient of $3^4$, which is $2$, we get [2].

2012-12-30 18:05:47 +0200 commented answer Problem with infinite sum

The remark that $|B_{2k}|\to\infty$ was intended only to justify divergence for $n=1$. The final sentence implies divergence for $n>1$.

2012-12-30 12:10:19 +0200 commented answer Problem with infinite sum

The series certainly doesn't converge for n=1, since abs(bernoulli(2*k)) tends to infinity as k tends to infinity. In fact I don't believe that the series converges for any integral value of n, for I think $sum_{k=1}^{\infty}B_{2k}x^{2k}$ has zero radius of convergence. This should follow from knowing that $sum_{k=1}^{\infty}B_{2k}x^{2k}/(2k)!$ has radius of convergence $2\pi$; the value is $x/(e^x-1)-1-x/2$.

2012-12-07 04:56:08 +0200 answered a question Explicit finite field extensions

There can't be a coercion from GF(q) to GF(q^k) if q is not prime since there will be several embeddings, none of which has any reason to be preferred. But it is simple to list the embeddings:

sage: F.<a> = GF(5^2); K.<b> = GF(5^6)
sage: Hom(F, K).list()
[
Ring morphism:
From: Finite Field in a of size 5^2
To:   Finite Field in b of size 5^6
Defn: a |--> 4*b^5 + 2*b^4 + 4*b^2 + b,
Ring morphism:
From: Finite Field in a of size 5^2
To:   Finite Field in b of size 5^6
Defn: a |--> b^5 + 3*b^4 + b^2 + 4*b + 1
]


It is possible to construct a field of order 5^6 which GF(25) coerces into:

sage: PF.<t> = F[]
sage: f, g = prime_factors(PF(b.minpoly())); f, g
(t^3 + (2*a + 2)*t + 4*a, t^3 + (3*a + 4)*t + a + 4)
sage: L.<c> = F.extension(f)
sage: L.is_field()
True
sage: L.order().factor()
5^6
sage: a + c in L
True


But at present there are limits to what can be done with this field:

sage: K.list()[:7]
[0, b, b^2, b^3, b^4, b^5, 4*b^4 + b^3 + 4*b^2 + 3]
sage: L.list()[:7]
Traceback (most recent call last)
...
NotImplementedError: object does not support iteration