Ask Your Question

Jesustc's profile - activity

2020-03-26 12:58:44 -0500 received badge  Popular Question (source)
2017-08-06 07:07:40 -0500 received badge  Popular Question (source)
2017-03-18 10:33:13 -0500 received badge  Famous Question (source)
2017-02-13 10:05:15 -0500 received badge  Notable Question (source)
2014-07-12 12:25:48 -0500 received badge  Notable Question (source)
2014-06-28 20:15:44 -0500 marked best answer Symbolic matrices and "integrity" of their inverse

I have to solve the following problem:

Does a matrix $G\in GL(n,\mathbb{Z})$ exists such that $$ G\times A\times G^{-1}=B $$ being $A,B$ given matrices in $\mathbb{Q}$?

Doing everything by hand, I finally find myself with a bunch of symbolic matrices. Now I have to check if they can lay inside $GL(n,\mathbb{Z})$, i.e. if there are integer values for the variables in the matrix such that the matrix is integer, invertible and with integer inverse.

E.g.: $$\left(\begin{array}{cc}x & 0 \\ 0 & y\end{array}\right)$$ does the trick only for $x=y=1$.

Is there a quick method within Sage to solve that last problem?


2014-06-28 20:15:24 -0500 marked best answer WeylCharacterRing and coroots / Dynkin labels

This might be a stupid question coming from a poor physicist, but there we go:

I would like to work with representations of Lie algebras, having the weights expressed in terms of the times they contain each of the fundamental weights, what we call 'Dynkin labels'. It seems to correspond to the style='coroot' when declaring a WeylCharacterRing: if I want the representation whose highest weight is 3 times the 1st fundamental weight, I ask for

sage: WCR = WeylCharacterRing("A2",style='coroots')
sage: WCR(3,0,0,...,0)

That said, I get:

sage: A2 = WeylCharacterRing("A2",style='coroots')
sage: rep = A2(1,0)
sage: print rep.weight_multiplicities()
{(2/3, -1/3, -1/3): 1, (-1/3, 2/3, -1/3): 1, (-1/3, -1/3, 2/3): 1}

but I would like to get

sage: A2 = WeylCharacterRing("A2",style='coroots')
sage: rep = A2(1,0)
sage: print rep.weight_multiplicities()
{( 1, 0): 1, ( -1, 1): 1, ( 0, -1): 1}

which is the right answer in Dynkin labels.

It would be easy to go from one place to the other if I could get the fundamental weights in the same ambient space as the weights: in this case (2/3, -1/3, -1/3) and (1/3, 1/3, -2/3). But I find no way to get them in general.

From the 1st example:

sage: A2.fundamental_weights()
Finite family {1: (1, 0, 0), 2: (1, 1, 0)}

which is not the answer I would expect, and seems inconsistent to me, since the highest weight of the representation, (2/3, -1/3, -1/3), is precisely the 1st fundamental weight.

Cheers, JesúsTorrado

2014-06-28 20:15:24 -0500 marked best answer Not able to relabel a Cartan type in the notebook

In the shell:

sage: A3 = CartanType("A3")
sage: A3.relabel({1:2,2:3,3:1})
['A', 3] relabelled by {1: 2, 2: 3, 3: 1}

But in the notebook:


A3 = CartanType("A3")


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 10, in <module>
    exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("QTMgPSBDYXJ0YW5UeXBlKCJBMyIpCkEzLnJlbGFiZWwoezE6MiwyOjMsMzoxfSk="),globals())+"\\n"); execfile(os.path.abspath(""))
  File "", line 1, in <module>

  File "/tmp/tmpWUCLyz/", line 4, in <module>
exec compile(u'A3.relabel({_sage_const_1 :_sage_const_2 ,_sage_const_2 :_sage_const_3 ,_sage_const_3 :_sage_const_1 })
  File "", line 1, in <module>

  File "/usr/lib/sage/local/lib/python2.7/site-packages/sage/combinat/root_system/", line 795, in relabel
import type_relabel
  File "/usr/lib/sage/local/lib/python2.7/site-packages/sage/combinat/root_system/", line 278, in <module>
class CartanType_affine(sage.combinat.root_system.cartan_type.CartanType_affine):
AttributeError: 'module' object has no attribute 'cartan_type'

Strange, isn't it?

2014-06-28 20:14:51 -0500 marked best answer Collapsing cells - comments in directives

Dear all,

I know that with the directive '%hide' at the beginning of a cell it can be collapsed. It is useful, but it would be much more if I could see something else from the collapsed cell, in addition to the '%hide'. So, is there any trick?

Putting a comment in the first line and the '%hide' in the second does not work, neither putting a comment in the same line that '%hide'.


2014-05-16 05:05:39 -0500 received badge  Popular Question (source)
2013-10-21 14:37:14 -0500 received badge  Nice Answer (source)
2013-08-07 02:21:43 -0500 received badge  Enthusiast
2013-08-03 05:31:21 -0500 answered a question speed up execution time of script (Cython or other...)

Take a look at the last section of this. As it is quoted there, «Premature optimization is the root of all evil». So use the profiler (or put prints in the appropriate places) to find out what parts of your calculation are taking the most, and the we will be able to give you more specific answers. Good luck!

2013-08-03 05:26:37 -0500 marked best answer Symbolic matrices and "integrity" of their inverse

A direct approach (not using symbolic solving) could be:

sage: A = matrix(QQ,[[3,1],[2,4]]) ; A
[3 1]
[2 4]
sage: B = matrix(QQ,[[2,4],[0,5]]) ; B
[2 4]
[0 5]
sage: A.is_similar(B)                       
sage: T = A.is_similar(B,transformation=True)[1] ; T
[ 1.000000000000000?             0.?e-18]
[0.2500000000000000? 0.2500000000000000?]
sage: T.change_ring(QQ)
[  1   0]
[1/4 1/4]
sage: G = T.change_ring(QQ)/det(T) ; G
[4 0]
[1 1]
sage: G * A * G^(-1) == B

See A.is_similar? for details.

2013-08-03 05:26:35 -0500 commented answer Symbolic matrices and "integrity" of their inverse

That's a good one, thanks!

2013-08-03 05:11:27 -0500 answered a question multiple cores - adventage - How enable it?

It is possible: just check the nice answer by @niles to a similar question: There you have a clear example.

2013-07-19 03:10:45 -0500 answered a question high resolution image - matplotlib

Go for a vector format, like svg or pdf, and then open in, say, Gimp. At the moment of opening, you can specify the resolution easily.

2013-06-23 20:38:30 -0500 received badge  Good Question (source)
2013-05-31 04:56:50 -0500 answered a question run Python file from command line in Sage

It is enough to add to

from sage.all import *
from sage.matrix.matrix2 import Matrix

Alternatively, the 2nd line (yours) is enough if you rename your file to sageruntest.sage (then it will be preparsed by Sage).

2013-05-28 23:34:47 -0500 received badge  Organizer (source)
2013-05-28 06:57:20 -0500 commented answer Embedding R graphics device in Sage notebook

Well, in the X11 case it doesn't embed either, but does exactly as you say. I guess @jaia will be happy with that :) But yeah, it would be great to have it embedded, and the same for the interactive interface of matplotlib. Unfortunately, my knowledge of the notebook is close to zero. I hope someone gets to do it at some point!

2013-05-28 05:24:13 -0500 commented answer Embedding R graphics device in Sage notebook

@kcrisman I added your comment. Thanks!

2013-05-28 02:30:21 -0500 commented answer Embedding R graphics device in Sage notebook

@jaia: Answer edited. There you have it ;)

2013-05-28 02:29:41 -0500 edited answer Embedding R graphics device in Sage notebook

Static plots -- png device

The answer seems to be the png device: see the accepted answer of this question.

Interactive graphics -- X11 device


sage: r.X11()    # pc-only
sage: r.quartz() # mac-only
sage: r.hist("rnorm(100)") # place your plot here
sage: r.locator(1) # example of interactivity: locate mouse "data" coordinates
2013-05-22 00:40:42 -0500 received badge  Good Answer (source)
2013-05-07 22:20:09 -0500 commented answer Sage for physicists

@kcrisman. Thanks for the edit! :)

2013-05-07 05:24:56 -0500 answered a question Sage for physicists

Here's another physicist using Sage, in particular doing a PhD, and I can only encourage you to use Sage any time you can :) It cannot do everything that Mathematica does, but it goes the other way around too. For an undergrad, you won't notice the difference if you are patient in learning Sage.

As an approach for using Sage as a physicist, I would recommend simply going through the tutorial, and asking here or in sage-support any particular concern you may have, starting right now!

2013-04-28 22:13:24 -0500 answered a question Hidden features of Sage

Though is general for python, it is always worth reading: Code like a Pythonista

2013-04-25 06:13:44 -0500 commented answer matplotlib x11 window

Sorry, maybe I didn't understand it completely: do you want to do it from the command line or from the notebook? In the notebook, the savefig('') should work, while in the command line, in the worst case, you can always save the plot to a file and see it in any image viewer, with plt.savefig('some_path_and_file_name'). As for the wiki page, as I told you, I haven't tried it myself. Why don't you try to post the errors you get in the sage-support mailing list? (

2013-04-24 14:09:15 -0500 answered a question matplotlib x11 window

For the cases in which you don't need interactivity, you can just change your

by a


If you really want interactivity, you may find this wiki page useful (I haven't tried it myself, I must say).

2013-04-23 00:28:11 -0500 received badge  Nice Answer (source)
2013-04-22 02:00:48 -0500 answered a question code for tail and head of an edge in a bipartite graph

You may want to take a look to this, and in particular this. Good luck!


Let $G$ be a bipartite graph that you have generated using one of the ways commented in the 2nd link above. Now you want to take an edge and get its head an tail. In order to do that, you can just identify the sets of tails and heads with the "bipartition" method of the graph, and check which of the vertices of an edge is in which set. It could be something like

tail_set, head_set = G.bipartition()
print "Set of tails: ",tail_set
print "Set of heads: ",head_set
for edge in G.edges():
    v1, v2 = edge[:2]
    tail = (v1 if v1 in tail_set else v2)
    head = (v1 if tail == v2 else v2)
    print "Edge: ",edge
    print "  Tail: ",tail,", Head: ",head
2013-04-21 23:00:11 -0500 received badge  Critic (source)
2013-04-21 23:00:08 -0500 commented question Mathcad 14 Help required

Wrong forum, lad. Try . Good luck!

2013-04-21 01:17:46 -0500 commented answer Numerical and graphical summaries of data

Sorry, but I cannot help pointing this out: the 2nd block of code, "d[0]=[x[0] for x in data]; d[1]=[...]" can be written simply as "d0,d1,d2,d3 = zip(\*data)", or "zip(*data)[:4]" if "data" has more than 3 fields. I love python :)

2013-04-19 05:16:41 -0500 commented answer Embedding R graphics device in Sage notebook

Kudos to Mike Hansen!

2013-04-19 02:41:43 -0500 received badge  Nice Answer (source)