Ask Your Question

Clemens Heuberger's profile - activity

2021-09-02 10:34:17 +0100 received badge  Notable Question (source)
2021-01-04 15:57:08 +0100 received badge  Famous Question (source)
2020-05-26 11:30:56 +0100 received badge  Popular Question (source)
2018-03-17 01:03:27 +0100 received badge  Notable Question (source)
2017-12-10 23:05:33 +0100 received badge  Nice Question (source)
2017-12-10 23:04:08 +0100 received badge  Popular Question (source)
2017-02-13 21:49:17 +0100 received badge  Teacher (source)
2017-02-13 13:38:32 +0100 answered a question Code error in sagemath

SageMath code is written in Python (with a few extensions by the preparser). Your code does not resemble Python. Indentation matters, no end is required, forloops are written as for b in s:, functions are defined as def bruteforce():, write print instead of puts.

2017-02-10 12:54:37 +0100 asked a question Conversion fraction field(QQ[X]) to fraction field(ZZ[X])

How to I convert an element of the fraction field of QQ[X] to the fraction field of ZZ[X]?

sage: R.<x> = ZZ[]
sage: F = R.fraction_field()
sage: e = (1/2)/(x+1)
sage: e.parent()
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: F(e)
Traceback (most recent call last):
TypeError: no conversion of this rational to integer

In my use case, e is the result of a lengthy computation where at some point beyond my control the result was coerced into QQ[X]. In my particular case, I prefer the fraction field of ZZ[X] because the output is nicer.

2017-01-04 14:40:30 +0100 commented answer Lifting a matrix from $\mathbb{Q}[Y]/(Y-1)$

Thank you, the work-around works for me. Is the underlying problem a known bug or shall I create a ticket?

2017-01-04 06:34:11 +0100 asked a question Linear Combination for Resultant


R.<a, b, X> = ZZ[]
f = 1 - a*X^2
g = 1 - b*X^3

I need to compute polynomials u and v such that u f + v g = r where r = f.resultant(g, X).

Pari has a function polresultantext for that purpose, so one solution for my problem is

(u, v, r) = (R(p) for p in f._pari_().polresultantext(g._pari_(), 'X'))

Nevertheless, I have a few questions:

  • Is there a method in Sage which directly does this?
  • Is the detour via Pari the recommended solution? Or is there an alternative, e.g., in singular?
  • If there is currently no method in Sage for doing this directly, what name would you recommend? resultant_ext ?
2016-12-15 11:23:52 +0100 asked a question What is _SAGE_VAR_(0)?

Using SageMath 7.4, I do the following:

sage: var('u R omega')
sage: hs = (1+u^R).series(u==omega, 2); hs
(omega^R + 1) + (R*omega^R/omega)*(-omega + u) + Order((omega - u)^2)
sage: hs.subs({omega^R: -1}).simplify()
R*(omega - u)/omega + Order((omega - u)^2) + _SAGE_VAR_(0)

I am wondering what _SAGE_VAR_(0) shall be and how to get rid of it.

2016-11-13 06:47:52 +0100 asked a question Lifting a matrix from $\mathbb{Q}[Y]/(Y-1)$

I have a matrix in $\mathbb{Q}[Y]/(Y-1)$ and want to lift it to $\mathbb{Q}[Y]$, however, I get an error:

sage: D.<Y> = QQ[]
sage: B = matrix(D, [[Y, 0]])
sage: Dbar = D.quotient(Y-1)
sage: Bbar = B.change_ring(Dbar)
sage: Bbar.lift()
Traceback (most recent call last):
TypeError: unable to convert 1 to a rational

Lifting single elements instead of a matrix works:

sage: Dbar(Y^2).lift()

Lifting a matrix from the integers modulo a prime works also:

sage: B = matrix(ZZ, [[7, 0]])
sage: Dbar = ZZ.quotient(5)
sage: Bbar = B.change_ring(Dbar)
sage: Bbar.lift()
[2 0]

So how do I lift the matrix? Building a new matrix by hand und lifting componentwise seems to be an option; however, I think that it is somewhat ugly.

2016-10-03 13:59:24 +0100 commented answer How to extend ring homomorphism to polynomial ring (or its fraction field)

I now have performance problems with my above solution:

R.<x> = AA[]
v = QQbar.polynomial_root(AA.common_polynomial(x^5 - 2), CIF(RIF(RR(0.35496731310463009), RR(0.35496731310463014)), RIF(RR(1.0924770557774537), RR(1.0924770557774539))))
rho = 1/60*v^4 + 1/30*v^3 + 1/60*v^2 + 1/30*v + 1/15
mp = rho.minpoly()
%time NumberField(mp, 'rho', embedding=rho)
CPU times: user 1min 5s, sys: 64 ms, total: 1min 5s
Wall time: 1min 5s
Number Field in rho with defining polynomial x^5 - 1/3*x^4 + 1/30*x^3 - 1/600*x^2 + 1/24000*x - 1/2400000

Any ideas?

2016-09-27 08:24:43 +0100 commented answer How to extend ring homomorphism to polynomial ring (or its fraction field)

It worked once, but then my code came accross another example and UniqueRepresentation gave me problems. So I ended up avoiding as_number_field_element alltogether and replacing it by

alpha_qqbar = QQbar(sqrt(2))
nf = NumberField(alpha_qqbar.minpoly(), 'alpha', embedding=alpha_qqbar)
hom = nf.coerce_embedding()
x1 = polygen(nf, 'x')
x2 = polygen(QQbar, 'x')
1/x1 - 1/x2
2016-09-27 05:28:44 +0100 received badge  Supporter (source)
2016-09-27 05:28:28 +0100 received badge  Scholar (source)
2016-09-27 05:28:23 +0100 commented answer How to extend ring homomorphism to polynomial ring (or its fraction field)

Thank you, the shortcut was exactly what I need.

2016-09-26 19:02:31 +0100 received badge  Student (source)
2016-09-26 16:11:42 +0100 asked a question How to extend ring homomorphism to polynomial ring (or its fraction field)

I have a homomorphism from a number field nf to the field of algebraic numbers QQbar:

nf, alpha, hom = QQbar(sqrt(2)).as_number_field_element()

I now work in the polynomial ring R over nf:

R.<x> = nf[]

f = x - alpha; f

How do I get a homomorphism from R to the polynomial ring over QQbar extending hom? For the moment, I can use


Same question about the fraction field of R, e.g.,

g = f/(x+1)

Is there a more elegant way than calling


So basically, I'd like to extend my homomorphism hom to the polynomial ring and its field of fractions.