Ask Your Question

MLainz's profile - activity

2023-09-30 21:07:54 +0200 received badge  Popular Question (source)
2022-12-31 15:52:28 +0200 received badge  Notable Question (source)
2022-12-31 15:52:28 +0200 received badge  Popular Question (source)
2022-01-23 10:55:16 +0200 received badge  Notable Question (source)
2021-04-22 15:15:32 +0200 received badge  Taxonomist
2020-04-18 13:21:07 +0200 received badge  Good Question (source)
2020-04-17 22:31:51 +0200 received badge  Nice Question (source)
2020-04-17 19:07:14 +0200 asked a question Rational parametrization of plane curves. Is this a bug?

I am trying to compute the rational parametrization of a plane curve. According to sage is irreducible and has genus 0, hence it should be possible.

B.<u,v> = AffineSpace(QQ,2)
p=Curve([2*u^2 + 2*u*v + 2*v^2 - 1],B)
p.rational_parameterization()

However, i get the following error

Singular crashed -- automatically restarting.

---------------------------------------------------------------------------
SingularError                             Traceback (most recent call last)
<ipython-input-10-db30bbca0c11> in <module>()
      1 B = AffineSpace(QQ,Integer(2), names=('u', 'v',)); (u, v,) = B.    _first_ngens(2)
      2 p=Curve([Integer(2)*u**Integer(2) + Integer(2)*u*v + Integer(2)    *v**Integer(2) - Integer(1)],B)
----> 3 p.rational_parameterization()

/home/mlainz/.local/SageMath/local/lib/python3.7/site-packages/sage/schemes/    curves/affine_curve.py in rational_parameterization(self)
   1451                     ((-7*t^2 + 7)/((-a)*t^2 + (-a)), 14*t/((-a)*t^2 +     (-a)))
   1452         """
-> 1453         para = self.projective_closure(i=0).rational_parameterization().    defining_polynomials()
   1454         # these polynomials are homogeneous in two indeterminants, so     dehomogenize wrt one of the variables
   1455         R = para[0].parent()

/home/mlainz/.local/SageMath/local/lib/python3.7/site-packages/sage/schemes/    curves/projective_curve.py in rational_parameterization(self)
   1569         singular.lib("paraplanecurves.lib")
   1570         R = singular.paraPlaneCurve(self.defining_polynomial())
-> 1571         singular.setring(R)
   1572         param = singular('PARA').sage().gens()
   1573         R = R.sage()

/home/mlainz/.local/SageMath/local/lib/python3.7/site-packages/sage/interfaces/    singular.py in set_ring(self, R)
   1097         if not isinstance(R, SingularElement):
   1098             raise TypeError("R must be a singular ring")
-> 1099         self.eval("setring %s; short=0"%R.name(), allow_semicolon=True)
   1100 
   1101     setring = set_ring

/home/mlainz/.local/SageMath/local/lib/python3.7/site-packages/sage/interfaces/    singular.py in eval(self, x, allow_semicolon, strip, **kwds)
    657         # Singular actually does use that string
    658         if s.find("error occurred") != -1 or s.find("Segment fault") !=     -1:
--> 659             raise SingularError('Singular error:\n%s'%s)
    660 
    661         if get_verbose() > 0:

SingularError: Singular error:
   ? sage19 is no name of a ring/qring
   ? error occurred in or before STDIN line 11: `setring sage19; short=0;`

Is this a SAGE or a Singular bug or am I missing something?

2019-11-28 16:37:01 +0200 asked a question Check if a curve is a geodesic

Suppose you have a curve gamma on a riemannian manifold (M,g). Can you check if gamma is a geodesic?

I tried

nabla =g.connection()
nabla(gamma.nabla.tangent_vector_fields())

But it seems to be impossible to compute covariant derivatives of vectors field along curves. Is there any way to do this?

2019-10-30 14:40:14 +0200 commented answer Compute the inverse of a 2-form

For the record, one would have to write omega_inv = M.tensor_field(2, 0, om.inverse())

2019-10-30 14:36:36 +0200 commented answer Compute the inverse of a 2-form

omega is not a form, but a general 2-tensor. Apart from that, the idea works (at least when we only have one chart).

2019-10-23 12:39:17 +0200 asked a question Compute the inverse of a 2-form

I have a nondegenerate (0,2)-tensor omega on a manifold which is not a metric and I would like to compute its 'inverse', which is a (2,0)-tensor.

I tried omega[:].inverse() but I get the following error 'ChartFunctionRing_with_category' object has no attribute 'fraction_field'. This worked for me in older versions of Sagemath (I think it was 7.4).

2019-07-11 12:10:33 +0200 received badge  Popular Question (source)
2019-07-02 10:47:01 +0200 received badge  Famous Question (source)
2018-02-19 19:45:29 +0200 asked a question Create multivariate function of a list of variables

I have created a list of variables, myvars

I'd like to create a function of those variables, but

myvars = var('x y z')
 f = function('f')(myvars)

doesn't work.

Of course in my actual code I'm creating myvars programatically, so doing

 f = unction('f')(myvars[0], myvars[1], myvars[2])

is not convenient

2016-02-19 19:03:45 +0200 received badge  Notable Question (source)
2016-02-19 19:03:45 +0200 received badge  Famous Question (source)
2016-02-17 00:09:46 +0200 received badge  Popular Question (source)
2016-02-14 23:50:12 +0200 commented answer Compute perfect matchings in a graph

Thank you. Now I use the Jupyter notebook. It's much easier noticing that mistakes with syntax colouring.

2016-02-13 00:42:52 +0200 asked a question Compute perfect matchings in a graph

I am trying to calculate all the perfect matchings of a graph G (i. e., the subgraphs of G such that every two points are connected)

def matchings(G):
    """Returns a list of the perfect matchings of G.
    It uses a recursive algorithm. Get a vertex x in G.
    Since all the perfect matchings contain exactly one edge for every vertex,
    we have that matchings(G) = {<x,y> U matchings(G\{x,y}) for y adjacent to x}.
    """
    Ms=[]   #List of mathchings
    x = G.random_vertex()
    for e in G.edges_incident(x):
        H=G.copy()
        H.delete_vertices([e[0],e[1]]
        for M in matchings(H):
            Ms.append(M.add_edge(e))
    return Ms

But this gives me

line 14 for M in matchings(H):
SyntaxError: invalid syntax

I don't understand the error (the loop seems fine to me). What's wrong?

2016-02-04 02:30:48 +0200 asked a question Get vector from abelian group

I want to represent the Cayley graph of an abelian group (let's say $A=Z_5^2$) is a way that the element $g=a^i b^j$ is in the position $[i,j]$. I need a method .pos()such that:

A= groups.presentation.FGAbelian([n,n]);
g=A[2]

 ---> g = a*b*a^-1

g.pos()

 ---> [0,1]

How could I do that?

2016-02-04 02:22:33 +0200 asked a question Get abelian group element powers.

I have the abelian group (let's say, $Z_5^2$). I want to represent its Cayley graph as a grid, in which the element $a^i b^j$ occupies the $[i,j]$ position in the plane. For that, I need would need a method .pos(). which did the following.

A = groups.presentation.FGAbelian([n,n]);
e=A[2]

-->e=aba^-1

e.pos()

--> [0,1]

How can I create something like that?

2015-10-29 03:55:13 +0200 received badge  Supporter (source)
2015-10-20 00:57:46 +0200 asked a question Grad, Div and Curl in spherical coordinates with SageManifold

As eric_g recommended in this post http://ask.sagemath.org/question/2959..., I tried SageManifolds (I had to give up index notation, since the current implementation is still very basic).

I tried to derive the formulas for Grad, Div and Curl in spherical coordinates. However, it only worked for Curl. This is my notebook: https://cloud.sagemath.com/projects/4...

I don't know what am I doing wrong. Also, I cannot simplify simple expressions such as the one for the divergence.

2015-10-20 00:09:26 +0200 received badge  Notable Question (source)
2015-09-27 02:47:25 +0200 received badge  Popular Question (source)
2015-09-26 16:26:50 +0200 received badge  Student (source)
2015-09-26 00:51:23 +0200 asked a question Index notation

I am taking a course in general relativity, and I was planing to use sage for doing calculations.

I have

from sage.tensor.modules.tensor_with_indices import TensorWithIndices
M = FiniteRankFreeModule(QQ, 4, name='M')
e = M.basis('e')
a = M.tensor((2,0), name='a')
a[:] = [[2,0,1,-1], [1,0,3,2], [-1,1,0,0], [-2,1,1,-2]]
g = M.tensor((0,2), name='g')
g[:] = [[1,0,0,0], [0,1,0,0], [0,0,1,0],[0,0,0,1]]
v=M.tensor((1,0), name='v')
v[:]=[-1,2,0,-2]

I wanted to calculate $a^{^i,^j}$ Is there some way to tell Sage what is the metric, and do the index lowering automatically? I did it manually, but it's cumbersome for more complicated calculations.

 A=a['^ik']*g['_jk'];A[:]

Also, I don't know how to compute $vî v_i$, since

v['^i']*g['_ij']*v['i']

does not work.

Apart from that, I would like to know if there is a way to do this kind of computations with tensor fields and index notation, including derivatives, etc.

2015-08-27 00:28:51 +0200 marked best answer Using interact

I want to visualize these functions in the complex plane:

$$f_n(z)=\exp(z) - \sum_{k=0}^{n} \frac{z^k}{k!}$$

I tried this code, but it gives me an error.

z,k = var('z,k')
@interact
    def _(n=(1..8)):
    complex_plot(exp(z)- sum(z^k/factorial(k), k, 0, n), (-5, 5), (-5, 5))

I am new to Sage (I previously used Mathematica). I wrote the code based on this example: http://wiki.sagemath.org/interact/ . How can I fix that?

EDIT: I would also like to know why doesn't this work either

def myPlot(n):
   complex_plot(exp(z)- sum(z^k/factorial(k), k, 0, n), (-5, 5), (-5, 5))

Then I type myPlot(2) in the notebook, but I get nothing. However, if I type:

complex_plot(exp(z)- sum(z^k/factorial(k), k, 0, 2), (-5, 5), (-5, 5))

I get the correct plot.

EDIT 2:

I tried

myPlot = lambda n: complex_plot(exp(z)- sum(z^k/factorial(k), k, 0, n), (-5, 5), (-5, 5))

And now I can evaluate it. However, I still can't use @Interact.

This doesn't make sense to me.