# Jesustc's profile - activity

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?

Thanks!

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.

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:

In:

A3 = CartanType("A3")
A3.relabel({1:2,2:3,3:1})


Out:

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

File "/tmp/tmpWUCLyz/___code___.py", 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/cartan_type.py", line 795, in relabel
import type_relabel
File "/usr/lib/sage/local/lib/python2.7/site-packages/sage/combinat/root_system/type_relabel.py", 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'.

Thanks!

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)
True
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
True


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: http://ask.sagemath.org/question/702/whenhow-to-use-parallel. 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-05-31 04:56:50 -0500 answered a question run Python file from command line in Sage

It is enough to add to sageruntest.py:

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 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

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

Example:

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-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? (http://groups.google.com.au/group/sage-support)

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

plt.show()


by a

plt.savefig('')


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

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!

UPDATE

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
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