Ask Your Question

alejandroerickson's profile - activity

2020-03-03 00:46:33 -0500 received badge  Notable Question (source)
2019-10-27 10:29:22 -0500 received badge  Famous Question (source)
2019-03-21 17:00:09 -0500 received badge  Popular Question (source)
2018-04-22 23:12:20 -0500 received badge  Good Question (source)
2017-12-01 07:59:30 -0500 received badge  Taxonomist
2017-04-10 02:13:38 -0500 received badge  Notable Question (source)
2017-04-10 02:13:38 -0500 received badge  Popular Question (source)
2016-09-15 07:10:17 -0500 received badge  Notable Question (source)
2016-07-20 04:05:38 -0500 received badge  Necromancer (source)
2015-11-05 10:50:21 -0500 received badge  Popular Question (source)
2015-10-28 09:40:32 -0500 received badge  Notable Question (source)
2015-10-27 04:02:48 -0500 received badge  Nice Question (source)
2015-03-20 05:29:14 -0500 commented answer /sage: line 334: path/sage-ipython: Permission denied

Thank you! What a silly pitfall :(. I did it by reinstalling without sudo, but this would be faster.

2015-03-19 17:37:42 -0500 commented question /sage: line 334: path/sage-ipython: Permission denied

Reading related posts... does it matter that I did this:

sudo cp -r /Volumes/sage-6.5-x86_64-Darwin/sage ~/
2015-03-19 17:32:14 -0500 asked a question /sage: line 334: path/sage-ipython: Permission denied

I get an error like this one when I try to start sage.

/sage: line 334: path/sage-ipython: Permission denied

It does start (with related errors), however, when I run

$ sudo sage

I might need help providing the right details, but here goes:

    usrname$ sage
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.5, Release Date: 2015-02-17                         │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
/Users/usrname/sage/src/bin/sage: line 334: /Users/usrname/sage/src/bin/sage-ipython: Permission denied
/Users/usrname/sage/src/bin/sage: line 334: exec: /Users/usrname/sage/src/bin/sage-ipython: cannot execute: Undefined error: 0

I get a different error using sudo.

usrname:~ usrname$ sudo sage
sys:1: RuntimeWarning: not adding directory '' to sys.path since it's not owned by a trusted user.
Untrusted users could put files in this directory which might then be imported by your Python code. As a general precaution from similar exploits, you should not execute Python code from this directory
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.5, Release Date: 2015-02-17                         │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: quit()
Exiting Sage (CPU time 0m0.19s, Wall time 3m1.92s).

I also tried it with sage in

/Applications/sage

Same problems.

and I also tried installing the Sage.app (in Applications), but this failed as well (Error 500, presumably for the same reasons as the above errors)

The permissions in my home folder install are

usrname (ME) read and write, staff Read only, everyone Read only

My /Applications folder additionally has (this motivated me to try it in the home folder)

system read and write

I have checked that I'm using the right sage install by using for my sage command

sudo ln -s ~/sage/sage /usr/local/bin/sage

and checking that I was not overriding this with something else in my path. Also,

usrname:sage usrname$ which sage
/usr/local/bin/sage
2014-12-21 14:50:54 -0500 answered a question running sage as an argument to ssh command causes interpreter shell to hang

Looks like I forgot the -t flag to the second ssh. It works with

$ssh -t user@host1 '
screen -mS sage ssh -t host2 sh -c '\''cd /path/to/working/directory;sage'\'''
2014-12-21 14:12:06 -0500 received badge  Editor (source)
2014-12-21 14:11:10 -0500 asked a question running sage as an argument to ssh command causes interpreter shell to hang

I have sage on a remote server, and I can ssh to that server and then run sage to get the interpreter. But when I run sage from the ssh command, sage hangs before I get the sage: command prompt. Like this:

$ ssh user@host sage
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.1.1, Release Date: 2014-02-04                       │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘

I do not have admin rights on the server.

Ultimately, what I want to do is run the command

$ssh -t user@host1 '
screen -mS sage ssh host2 sh -c '\''cd /path/to/working/directory;sage'\'''

If you must know, it's because only host2 has sage and only host1 has screen. I have an unreliable connection to both, but they have a reliable connection between them.

The question: How can I get this to work?

2014-06-29 07:30:44 -0500 received badge  Popular Question (source)
2014-06-29 07:30:44 -0500 received badge  Notable Question (source)
2014-06-28 21:22:43 -0500 received badge  Famous Question (source)
2014-06-28 21:22:43 -0500 received badge  Notable Question (source)
2014-06-28 20:15:06 -0500 marked best answer How to do mul(function, i=1..n); like in Maple?

I want to a product of polynomials which I define in Maple as

f := n->mul((1+x^k),k=1..n);

The obvious choice, mimicking Sage's 'sum' command does not work. I can't do

def f(n):
    return mul((1+x^k),k,1,n)

Instead I had to use

def S(n,k):
    return mul(1+x^(k+1) for k in range(n))

Maybe my problem is another, so I'll post my whole problem and traceback:

 def S(n,k):
    s = mul(1+x^(i+1) for i in range(n))
    return s.expand().coeff(x^k)
def H(n,k):
    return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
H(121,4)

Traceback (most recent call last):        return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
  File "", line 1, in <module>

  File "/tmp/tmpKvQFbK/___code___.py", line 10, in <module>
    exec compile(u'H(_sage_const_121 ,_sage_const_4 )
  File "", line 1, in <module>

  File "/tmp/tmpKvQFbK/___code___.py", line 9, in H
    return sum(sum( S(_sage_const_2 *i+_sage_const_1 ,b)*S(n-_sage_const_2 *i-_sage_const_3 ,k-(_sage_const_2 *i+_sage_const_2 )-b),b,_sage_const_0 ,k-(_sage_const_2 *i+_sage_const_2 )),i,_sage_const_0 ,floor((n-_sage_const_5 )/_sage_const_4 ))
  File "/tmp/tmpKvQFbK/___code___.py", line 4, in S
    s = mul(_sage_const_1 +x**(i+_sage_const_1 ) for i in range(n))
TypeError: range() integer end argument expected, got sage.symbolic.expression.Expression.

All advice is welcome.

2014-06-28 20:14:25 -0500 marked best answer How do I install python modules, or use a different version of python? (with sage)

I have several versions of python, as well as the one included with sage. I want to use the svgwrite module in /Library/Frameworks/Python.framework/Versions/2.7/bin/python , but sage does not have it.

I want to run the following (combined with some output from sage)

import svgwrite

dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.text('Test', insert=(0, 0.2), fill='red'))
dwg.save()

It runs fine with the calls

python drawT.sage
python2.7 drawT.sage

But when I try to call it directly or with a system call in sage I have problems.

sage: import sys
sage: os.system("python /path/drawT.sage")
Traceback (most recent call last):
  File "/path/drawT.sage", line 1, in <module>
    import svgwrite
ImportError: No module named svgwrite
256
sage: os.system("which python")
/Applications/sage/local/bin/python
0

Okay fine, sage's installation does not have the module. But now I try to force it to use the installation that does have it:

sage: os.system("which python2.7")
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
0
sage: os.system("python2.7 /path/drawT.sage")
Traceback (most recent call last):
  File "/path/drawT.sage", line 1, in <module>
    import svgwrite
ImportError: No module named svgwrite
256

How can I install svgwrite, or invoke a given python installation from sage?

2014-06-18 11:00:27 -0500 received badge  Popular Question (source)
2014-06-11 02:37:03 -0500 commented answer Simple counting on restricted n-ary k-tuples

they are a restricted class of integer vectors, since every vector would have the same number of coordinates, $k$, and the maximum in each coordinate is also fixed at $n$. edit: the biggest difference, however, is that I think IV computes all of the vectors with the given parameters, whilst I want algebraic answers for general parameters.

2014-06-11 00:57:19 -0500 asked a question Simple counting on restricted n-ary k-tuples

I have some simple counting problems, for example, how many n-ary k-tuples, i.e. $(v_0,v_1,\ldots, v_k)$ with $0\le v_i < n$, are there which have $v_0=1$, and $m$ non-zero coordinates.

What sort of functionality is there is Sage or other computer algebra systems for answering such questions for general $n,k$ and $m$?

2014-04-24 02:55:29 -0500 marked best answer built in cython integration [beginner]

Yes.

You can find much of this out by trying

sage: g.traveling_salesman_problem??

to read the code. Note that in this case the function itself is in a .py (uncompiled, though in byte code I think) file. But the line

from sage.numerical.mip import MixedIntegerLinearProgram

indicates it uses MILP, and this is indeed a compiled file (as you can see by doing

sage: sage.numerical.mip.MixedIntegerLinearProgram?

where it indicates an .so file type.

However, in truth this calls an outside program (which you can set, e.g. CPLEX) to do the LP, so the compiled piece is less relevant than the fact that it uses a dedicated library to do the LP.

2014-04-24 01:54:25 -0500 asked a question built in cython integration [beginner]

When I run a built-in sage function that is defined as cython code, does it automatically run compiled code, or do I have to activate cython or something?

For example:

When I run the code

g = graphs.CompleteGraph(10)
g.traveling_salesman_problem()

in a notebook, without anything else, the second command contains instances of 'MixedIntegerLinearProgram', which appears to be a cdef from a pyx file. I've learnt today that this means it is written in cython, and I would like to confirm that if MixedIntegerLinearProgram gets called in g.traveling_salesman_problem(), that it does indeed run compiled code, and that I don't have to do anything special to activate it.

2014-04-01 04:18:32 -0500 commented answer graph vertex labels placement or alignment

As of now it doesn't work on my installation, but I'll select it when it works for me. Thanks!

2014-03-31 05:34:51 -0500 commented answer graph vertex labels placement or alignment

The example is pretty. I think I might use the tikz graphs every time!

2014-03-31 02:40:01 -0500 asked a question graph vertex labels placement or alignment

I made a sage Graph() for visualizing a bibliography and found that there was no good way to align or change the placement of the vertex labels.

I wanted some labels to align left and others to align right, but they were all centred on their vertex. I ended up doubling the length of the label string with spaces and adding a period with some code like the following

    lDict = {}
for v in G.vertices():
    if <test for the type of vertex>:
        lDict[v] = v + len(v)*' ' + '.'
    else:
        lDict[v] = ''.join(['.',len(v)*' ',v])
G.relabel(lDict)

I managed to get this (click for full sized image):

Graph

Is there a way to manipulate the placement of the labels?

2014-03-31 02:29:48 -0500 answered a question Graph theory: Make vertex labels in plots bigger

One way is to use figsize to indirectly change the relative size of the labels.

P = graphs.PetersenGraph()
P.show(figsize=[1,1],vertex_size=0,layout='spring')

The output of this is:

Mangled Petersen graph with large labels.

2014-03-31 02:16:32 -0500 answered a question Plotting Grid Graph

You might want to adjust the spacing or label size with the figsize option:

G.show(figsize=[10,10],pos=dict([(v,v) for v in G.vertices()]))

or store the positions as a property of the graph with

G.set_pos(dict([(v,v) for v in G.vertices()])) 
G.plot()
2013-10-09 00:18:13 -0500 received badge  Nice Question (source)
2013-10-02 22:05:47 -0500 received badge  Popular Question (source)
2013-05-07 12:43:19 -0500 marked best answer How do I install python modules, or use a different version of python? (with sage)
  1. Download svgwrite and unpack the gzipped tar file or the zip file.

  2. From within the svgwrite directory, run sage --python setup.py install.

  3. Then run sage: now import svgwrite should work.

That should install svgwrite in Sage's copy of Python. Using a different copy of Python with Sage is difficult, but installing Python packages in Sage's Python should be pretty straightforward.