Ask Your Question

rburing's profile - activity

2019-12-06 15:51:39 -0600 commented question Solve set of equations with all unique values in sage

Can you add the set of equations? Select your code and press the '101010' button to format it correctly.

2019-12-05 13:45:39 -0600 answered a question How to use a string in a symbolic expression with SageMath?

I would re-evaluate whether using strings is really what you want to do; probably whatever problem you have can be solved in a better way. Nevertheless, it is possible:

var('x1 x2 x3 y1 y2 y3')
st = eval('y1,0,1')
2019-12-05 10:05:38 -0600 received badge  Nice Answer (source)
2019-12-05 05:38:56 -0600 answered a question How can I define a field of numbers by hitting to the field of rationals two roots of the same polynomial ?

Note number fields in SageMath are abstract extensions of $\mathbb{Q}$; they come with several embeddings into $\mathbb{C}$; see below.

Option 1 (number field from algebraic numbers):

sage: K, [A,B], emb = number_field_elements_from_algebraics([alpha,beta], minimal=True)
sage: K
Number Field in a with defining polynomial y^8 + 4*y^6 + 358*y^4 + 708*y^2 + 529
sage: A
-1/80*a^6 - 3/80*a^4 - 359/80*a^2 - 357/80
sage: B
1/920*a^7 + 1/230*a^5 + 381/920*a^3 + 607/460*a
sage: emb(A) == QQbar(alpha), emb(B) == QQbar(beta)
(True, True)

For other options, let's first find what polynomial we are talking about:

sage: f = alpha.minpoly(); f
x^4 + 11*x^2 + 11

Option 2 (splitting field):

sage: K.<c> = f.splitting_field()
sage: f_roots = f.roots(K, multiplicities=False)
sage: emb = K.embeddings(QQbar)[0]
sage: map(emb, f_roots)
[0.?e-16 + 1.054759596450271?*I,
 0.?e-16 - 1.054759596450271?*I,
 0.?e-16 - 3.144436705309246?*I,
 0.?e-16 + 3.144436705309246?*I]
sage: QQbar(alpha), QQbar(beta)
(1.054759596450272?*I, 3.144436705309246?*I)
sage: a = f_roots[0]; b = f_roots[3]
sage: emb(a) == QQbar(alpha), emb(b) == QQbar(beta)
(True, True)

Option 3 (successive extensions):

sage: K.<a> = NumberField(x^4 + 11*x^2 + 11)
sage: R.<y> = PolynomialRing(K)
sage: R(f).factor()
(y - a) * (y + a) * (y^2 + a^2 + 11)
sage: g = y^2 + a^2 + 11
sage: L.<b> = K.extension(g)
sage: f.change_ring(L).factor()
(x - b) * (x - a) * (x + a) * (x + b)
sage: emb = L.embeddings(QQbar)[4]
sage: emb(a) == QQbar(alpha), emb(b) == QQbar(beta)
(True, True)

You can also make an absolute extension from the relative one:

sage: M.<c> = L.absolute_field(); M
Number Field in c with defining polynomial x^8 + 110*x^6 + 3839*x^4 + 44770*x^2 + 43681
sage: from_M, to_M = M.structure()
sage: to_M(a)
7/2508*c^7 + 145/627*c^5 + 509/114*c^3 + 421/76*c
sage: to_M(b)
7/1254*c^7 + 290/627*c^5 + 509/57*c^3 + 459/38*c
sage: emb = M.embeddings(QQbar)[4]
sage: emb(to_M(a)) == QQbar(alpha), emb(to_M(b)) == QQbar(beta)
(True, True)
2019-11-27 02:13:32 -0600 commented question conditions among the variables

@user789 if that's all, then just substitute e.g. $e=a+b-d$ into your polynomial.

2019-11-23 05:45:07 -0600 commented question How to count rational points of a curve defined as an intersection of two zero sets?

How can the first equation have any rational solutions?

2019-11-22 04:37:07 -0600 commented answer Sagemath and TI-83 giving different answers

Probably OP wants to know why taking the cube root in SageMath yields this particular root and not the real root.

2019-11-20 07:28:10 -0600 answered a question Do newer versions change the way 'simplify' works?

When you make a vague request (e.g. 'simplify'), there is a risk that the answer will change if you ask it again.

Unfortunately I don't know what has changed or why. Maybe e.g. using git blame someone can find it out.

I am guessing that you are interested in the expression as a polynomial in $x,y,Z$.

A precise way to request the expression in that form is as follows (using polynomial rings):

sage: var('Z,x,y,a,w1,w2,w3,G')
sage: eqn = (Z*a + Z*w2 - a + w2)*(Z*a + Z*w3 - a + w3)*y == (Z*a + Z*w1 - a + w1)*G*(Z + 1)*x
sage: A = PolynomialRing(QQ, names='a,w1,w2,w3,G')
sage: B = PolynomialRing(A, names='Z,x,y')
sage: SR(B(eqn.lhs())) == SR(B(eqn.rhs()))
(a^2 + a*w2 + a*w3 + w2*w3)*Z^2*y - 2*(a^2 - w2*w3)*Z*y + (a^2 - a*w2 - a*w3 + w2*w3)*y == (G*a + G*w1)*Z^2*x + 2*G*Z*w1*x - (G*a - G*w1)*x

You could also factor each coefficient:

sage: sum(SR(C).factor()*SR(X) for C,X in B(eqn.lhs())) == sum(SR(C).factor()*SR(X) for C,X in B(eqn.rhs()))
Z^2*(a + w2)*(a + w3)*y - 2*(a^2 - w2*w3)*Z*y + (a - w2)*(a - w3)*y == G*Z^2*(a + w1)*x + 2*G*Z*w1*x - G*(a - w1)*x
2019-11-20 05:33:03 -0600 commented answer Why SageMath cannot inverte this matrix?

You're welcome. That it takes a long time doesn't mean SageMath is not able to do it. Your original code works on my machine; it took 1 hour and 12 minutes.

2019-11-19 10:31:51 -0600 commented question conditions among the variables

This can be done (with some effort) in many cases, depending on the type of condition. Are the conditions linear equations, polynomial equations, trigonometric equations? An example would be great.

2019-11-18 08:49:06 -0600 commented question simple script gives "ValueError: element is not in the prime field"

The error depends on the information you've omitted, such as the definition of r, l, and x. As a general rule, please give an unambiguous self-contained example that produces the error. Probably the problem is that l cannot be lifted to an integer.

2019-11-17 17:05:04 -0600 received badge  Nice Answer (source)
2019-11-16 10:39:38 -0600 commented answer Why SageMath cannot inverte this matrix?

It is working, but there seems to be some kind of bug in displaying the algebraic numbers. For example if you define S = Q*M[0]*P then set(S.diagonal()) == set(M[0].eigenvalues()) is True, and the workaround S.apply_map(lambda z: z.interval(CIF)) shows the matrix correctly.

2019-11-16 06:36:53 -0600 answered a question Why SageMath cannot inverte this matrix?

Since $\bar{\mathbb{Q}}$ is a little big, try instead working in a number field $K$ that's big enough but as small as possible:

M = [matrix(QQ,l) for l in L]
K,_,_ = number_field_elements_from_algebraics(sum([m.eigenvalues() for m in M], []), minimal=True)
p = identity_matrix(K,8)
q = ~p
for m in M:
    a = q*m*p
    da, pa = a.change_ring(K).jordan_form(transformation=True)
    p = p*pa
    q = ~p

Here $K$ is an abstract number field of degree $48$ with several (i.e. $48$) different embeddings into $\bar{\mathbb{Q}}$.

sage: set([sigma(p.det()) for sigma in K.embeddings(QQbar)])
{-97929.96732359303?, 97929.96732359303?}

For a given sigma in K.embeddings(QQbar), you can embed p and q by p.apply_map(sigma) and q.apply_map(sigma); those matrices are defined over QQbar and they simultaneously diagonalize all m in M.

2019-11-15 04:17:53 -0600 commented question Sage 8.1 on Mint 19.2 doesn't start

Those look like dependencies, yes. What is the issue with them? What is invalid?

2019-11-15 03:01:35 -0600 commented question Sage 8.1 on Mint 19.2 doesn't start

Please be more precise about the dependency issue (for the .deb file).

2019-11-12 09:39:41 -0600 answered a question Vector multiplication

For one, because you can't transpose lists. Secondly, you should take the (single) entry of c*aa.

aa = vector(var('delta_%d' % i) for i in (0..2))
c = n(matrix(1,3,(-0.5,0.2,.3)),2)
U = e^((c*aa)[0])

$$e^{\left(-0.50 \delta_{0} + 0.19 \delta_{1} + 0.25 \delta_{2}\right)}$$

(Note that you specified 2 bits of precision with n.)

2019-11-09 02:21:35 -0600 commented question How to create a subgroup with MAGMA inside SAGE of a group created with MAGMA inside SAGE?

Assuming that the rest of the code is correct, the issue is that you use the text "GGG" to refer to the variable GGG. Instead you should use something like I don't have Magma so I am not sure of the exact syntax; try dir(GGG) to find the right method name.

2019-11-06 13:28:32 -0600 answered a question Bug report (z[0]+z[1]+z[2])^5 == z0^5 + z1^5 + z2^5

This is not a bug.

sage: var('x,y,z')
sage: ((x+y+z)^5).expand()
x^5 + 5*x^4*y + 10*x^3*y^2 + 10*x^2*y^3 + 5*x*y^4 + y^5 + 5*x^4*z + 20*x^3*y*z + 30*x^2*y^2*z + 20*x*y^3*z + 5*y^4*z + 10*x^3*z^2 + 30*x^2*y*z^2 + 30*x*y^2*z^2 + 10*y^3*z^2 + 10*x^2*z^3 + 20*x*y*z^3 + 10*y^2*z^3 + 5*x*z^4 + 5*y*z^4 + z^5

Note the divisibility by 5 of all terms which are "missing" in your characteristic $p=5$ calculation.

This is a consequence of the Freshman's dream: $(x+y)^p \equiv x^p + y^p \pmod p$; just apply it twice.

It looks too good to be true, but it really is true in characteristic $p$ (the proof is in the linked article).

2019-11-06 13:16:48 -0600 commented question maximizing sum over feasible set of vectors

I didn't ask the question, but yes that's right. The binary ordering was just a (natural) suggestion. Of course the ordering is irrelevant, but probably some ordering is necessary for the implementation.

2019-11-06 05:38:39 -0600 commented question maximizing sum over feasible set of vectors

$|A|$ means the number of elements in $A$. To have $\underline{\alpha}$ be a vector one should choose an ordering of the (nonempty) subsets of $[5]$, e.g. by identifying them with binary strings of length 5 (not equal to $00000$).

2019-10-31 04:50:03 -0600 commented question How to solve this algebraic equation by SageMath (rather than by hand)

The relation $r^2u^4 - (a^2 + r^2 + t^2)u^2 + t^2 = 0$ holds.

2019-10-30 14:31:49 -0600 received badge  Nice Answer (source)
2019-10-30 11:04:37 -0600 answered a question Plotting polynomials defined over a number field

You have the right idea: do f.change_ring(R) with the argument R set to one of K.embeddings(RR):

K.<t> = NumberField(w^2-3)
R.<x,y> = PolynomialRing(K)
f = y - t*x

You might also like:

implicit_plot(f.change_ring(K.embeddings(RR)[0]),(x,-3,3),(y,-3,3), color='blue') + implicit_plot(f.change_ring(K.embeddings(RR)[1]),(x,-3,3),(y,-3,3), color='red')
2019-10-25 02:43:38 -0600 answered a question How can I map functions into polynomial coefficients

Here is a way:

sage: var('a,b,c,x')
sage: sinx = function('sinx',nargs=1)
sage: pol =  3*a*x^(-b)*log(x)*b^2 - 6*a*b*c*sinx(x*b) + 3*a*c^2 + 5
sage: R = PolynomialRing(SR, names='a,c')
sage: f = pol.polynomial(ring=R)
sage: dict(zip(f.monomials(), f.coefficients()))
{1: 5, a: 3*b^2*log(x)/x^b, a*c: -6*b*sinx(b*x), a*c^2: 3}

Note the generators of the ring R are not the same as the symbolic variables a and c.

To get the coefficient of c as in your example, you can do:

sage: f.monomial_coefficient(R.gen(1))

Or maybe more conveniently, something like:

sage: A,C = R.gens()
sage: f.monomial_coefficient(C)
2019-10-22 07:06:00 -0600 commented question About algorithm for testing whether a point is in a V-polyhedron

This may depend on the backend used, so can you give an example of a Polyhedron for which you want to know the answer?

2019-10-22 04:01:22 -0600 answered a question Elliptic curves - morphism

You can do this:

sage: T.<t> = FunctionField(QQ)
sage: R.<u,v> = T[]
sage: f = u^3+v^3+t
sage: h = Jacobian(f, curve=Curve(f)); h
Scheme morphism:
  From: Affine Plane Curve over Rational function field in t over Rational Field defined by u^3 + v^3 + t
  To:   Elliptic Curve defined by y^2 = x^3 + (-27/4*t^2) over Rational function field in t over Rational Field
  Defn: Defined on coordinates by sending (u, v) to
        ((-t^3)*u^4*v^4 + (-t^4)*u^4*v + (-t^4)*u*v^4 : 1/2*t^3*u^6*v^3 + (-1/2*t^3)*u^3*v^6 + (-1/2*t^4)*u^6 + 1/2*t^4*v^6 + 1/2*t^5*u^3 + (-1/2*t^5)*v^3 : t^3*u^3*v^3)
2019-10-16 07:03:11 -0600 commented answer Finite field F_16=F_4[y]/(y**2+xy+1) (where F_4=F_2[x]/(x**2+x+1))

To avoid constructing the list you could use next on the iterator.

2019-10-15 16:12:33 -0600 received badge  Nice Answer (source)
2019-10-15 03:17:54 -0600 commented question how do I find kernel of a ring homomorphism?

Please add a code sample including a definition of f.

2019-10-15 02:47:06 -0600 answered a question Verma modules and accessing constants of proportionality

Not sure if it's the best way, but you can do the following:

sage: for n in range(10):
sage:    c = (x2^n*y2^n*v).coefficients()[0]
sage:    print('c_{} = {}'.format(n, c))
c_0 = 1
c_1 = -3
c_2 = 24
c_3 = -360
c_4 = 8640
c_5 = -302400
c_6 = 14515200
c_7 = -914457600
c_8 = 73156608000
c_9 = -7242504192000
2019-10-11 09:04:06 -0600 answered a question Adapt the nauty_directg function

Entering digraphs.nauty_directg?? into a SageMath session will show you the source code of the function.

In this case it simply calls an external program directg which is part of nauty.

You can download and edit that program's source code, compile your new version, and call that one instead.

To edit the source code you should start by looking at the file directg.c. Good luck!

2019-10-05 03:49:37 -0600 commented answer uniform way to iterate over terms of uni-/multi-variate polynomials

It's not very nice to change your question when it has received a correct answer, even if you suffered from the XY problem. Anyway, I updated the answer. In the future, please ask the new question separately (and link to the previous question).

2019-10-04 02:00:03 -0600 answered a question uniform way to iterate over terms of uni-/multi-variate polynomials

Define R2 as a multivariate polynomial ring in 1 variable:

sage: R2.<z> = PolynomialRing(QQ, 1)
sage: Q = z + 5
sage: for c,t in Q: print c,t
1 z
5 1

This ring (and its elements) will have different methods than the ordinary univariate ring (elements).

Alternatively: keep your original ring, define R3 = PolynomialRing(QQ, 1, name='z') and use R3(Q).

An answer to the new question:

def to_multivariate_poly(expr, base_ring):
    vars = expr.variables()
    if len(vars) == 0:
        vars = ['x']
    R = PolynomialRing(base_ring, len(vars), names=vars)
    return R(expr)

Then you can do:

sage: x,y,z = var('x,y,z')
sage: P = to_multivariate_poly(x + 2*y + x*y + 3, QQ)
sage: for c,t in P: print c,t
1 x*y
1 x
2 y
3 1
sage: Q = to_multivariate_poly(z + 5, QQ)
sage: for c,t in Q: print c,t
1 z
5 1
2019-10-04 01:45:45 -0600 commented answer Request: Have the len function output a Sage Integer instead of a Python int

Ah, there is a subtlety with srange (explained in the documentation) that by default the output consists of numbers of the type you put in. You can override that by passing universe=ZZ to srange; I've added this to the answer.

2019-10-03 00:02:21 -0600 commented answer Request: Have the len function output a Sage Integer instead of a Python int

It is not a bug. One should be aware of the difference between int and Integer. The second part of your code uses int division, there is no magic Sage can do to change that. Just be careful to write srange when you want Integers.

2019-10-02 09:20:41 -0600 answered a question Request: Have the len function output a Sage Integer instead of a Python int

In the second part you are using Python ints instead of SageMath Integers.

Use srange (with universe=ZZ if you're not passing an Integer) instead of range, or convert to an Integer before the division, e.g. Integer(i[0])/len(a).

2019-09-22 04:02:01 -0600 answered a question Defining q-binomial coefficients $\binom{n}{k}_q$ symbolic in $n, k$

If you want to make a symbolic sum then all the terms should be symbolic. Your example does not work because qbin(n,k) is not defined for symbolic n.

What you can do is to make qbin a symbolic function with custom typesetting:

def qbin_latex(self, n, k):
    return '{' + str(n) + ' \choose ' + str(k) + '}_{' + str(q) + '}'
qbin = function('qbin', nargs=2, print_latex_func=qbin_latex)

$$\sum_{k=0}^{n} {n \choose k}_{q}$$

To check the identities that you are interested in, you will probably have to do some substitutions by hand, and/or pass an evalf_func parameter to function in the definition of qbin. Have a look at the documentation for symbolic functions.

2019-09-22 03:42:51 -0600 answered a question Change of programmation of implicit

It seems that you want the following:

y = function('y')(x)
f = function('f')(x,y)


D[1](f)(x, y(x))*diff(y(x), x) + D[0](f)(x, y(x))
2019-09-20 02:35:00 -0600 answered a question Wrong hessian

The matrix you constructed by hand doesn't look like a Hessian to me. Here is the Hessian:

sage: H = L.function(x,y,l).hessian()(x,y,l)
sage: H

$$\left(\begin{array}{rrr} A {\left(\alpha - 1\right)} \alpha x^{\alpha - 2} y^{\beta} & A \alpha \beta x^{\alpha - 1} y^{\beta - 1} & -p_{x} \\ A \alpha \beta x^{\alpha - 1} y^{\beta - 1} & A {\left(\beta - 1\right)} \beta x^{\alpha} y^{\beta - 2} & -p_{y} \\ -p_{x} & -p_{y} & 0 \end{array}\right)$$

2019-09-18 04:02:51 -0600 commented question How sage checks the irreducibility of a polynomial?

Polynomial in one variable? Over which ring?

2019-09-16 11:21:06 -0600 answered a question Check whether point is on a projective variety

Sure, you can take a point from the ambient projective space and do a membership test:

sage: PP.<x,y,z,w,u,v> = ProductProjectiveSpaces([3,1],QQ)
sage: W = PP.subscheme([y^2*z-x^3,z^2-w^2,u^3-v^3])
sage: PP.point([1,1,1,1,1,1]) in W
sage: PP.point([1,1,1,1,1,2]) in W

Internally this does a try - except block around W.point(...).