Ask Your Question

rmp251's profile - activity

2024-02-18 11:55:32 +0100 received badge  Famous Question (source)
2023-11-21 13:21:14 +0100 received badge  Famous Question (source)
2022-10-31 22:26:34 +0100 received badge  Notable Question (source)
2022-10-31 22:26:34 +0100 received badge  Popular Question (source)
2020-06-21 08:17:42 +0100 received badge  Notable Question (source)
2020-06-21 08:17:42 +0100 received badge  Popular Question (source)
2018-04-14 13:09:09 +0100 received badge  Popular Question (source)
2017-05-20 09:23:19 +0100 received badge  Notable Question (source)
2015-12-05 14:18:24 +0100 received badge  Famous Question (source)
2014-12-15 09:13:02 +0100 received badge  Famous Question (source)
2014-08-27 23:28:33 +0100 received badge  Notable Question (source)
2014-06-29 03:15:26 +0100 marked best answer Navigating sage source code

I'm thoroughly confused by the source code. I've downloaded and unpacked all the source code in spkg/standard and spkg/base, but what I get looks totally different from what I see when browsing the code online (http://hg.sagemath.org/sage-main/file...). Can someone please help me make sense of the source code? I just want to be able to navigate through the code that gets executed when some sage commands are invoked.

Thank you.

2014-06-29 03:15:26 +0100 marked best answer python/sage scripts

First of all, my apologies for being a noob and a windows user. I'm using sage in virtualbox. I'm at this part of the tutorial: sagenb.org/doc/live/tutorial/programming.html#standalone-python-sage-scripts

I'm having 2 problems:

(1) I can't execute "./factor 2006". It says "no such file or directory", but the file is definitely there, and "sage -python factor 2006" works.

(2) factoring polynomials doesn't seem to work for me in sage. If I call factor on a string I get a TypeError: "unable to factor n".

Edit: Part of the problem may have been that the script was in a shared folder in VirtualBox. Here is some exact input/output, working completely locally (this changes the error in (2)).

>./factor 2006

/usr/bin/env: sage -python: No such file or directory

>sage -python factor "32*x^5-1"

NameError: name 'x' is not defined

Any assistance is much appreciated!

2014-01-10 12:09:29 +0100 marked best answer Getting plot data

For example:

C = cube()
C.json_repr(C.default_render_params())
2014-01-10 12:09:11 +0100 commented answer Getting plot data

Thank you!

2014-01-09 11:17:13 +0100 commented answer Getting plot data

Thanks. What about 2d plots? e.g. C = circle((0,0),5) ?

2014-01-08 23:01:13 +0100 asked a question Getting plot data

Is there a way to extract the set of values used in a plot using sage/python code?

For example, if I have 3D surface plot, what is the best way to get the set of vertices, or the z-values, for the mesh? (and similarly for 2d plots) I've looked through some of the plotting source code but haven't found a straightforward way to access the underlying plot data.

Any tips would be appreciated!

2014-01-08 22:26:52 +0100 received badge  Popular Question (source)
2013-12-31 11:22:01 +0100 received badge  Nice Question (source)
2013-11-22 13:07:40 +0100 received badge  Popular Question (source)
2013-10-21 05:17:08 +0100 received badge  Notable Question (source)
2013-03-31 10:02:01 +0100 received badge  Popular Question (source)
2012-12-19 19:12:00 +0100 marked best answer Does a subtraction symbolic expression actually exist?

We only use add, mul and pow operations in the expression tree. Subtraction is represented as addition with an appropriate coefficient and division is multiplication with an appropriate exponent. This makes it easier to handle expressions since you don't need to worry about handling these cases separately.

For example:

sage: var('x,y')
(x, y)
sage: ex = x+y-1
sage: ex.operator()
<built-in function add>
sage: ex.operands()
[x, y, -1]

You can read more about the internal representation of expressions in the relevant part of the GiNaC tutorial.

The patch attached to ticket #13738 wraps some internal GiNaC functions to view the expression tree.

2012-12-18 22:28:15 +0100 asked a question Does a subtraction symbolic expression actually exist?

Can someone please give me an example of a symbolic expression in sage of the subtraction variety? (by subtraction variety I mean using the subtraction operator)

Precisely: how can I create an object o of type sage.symbolic.expression.Expression such that o.operator() is operator.sub? It seems that subtraction expressions are always converted to additions.

For example:

sage: x = var('x')
sage: (x-1).operator()
<built-in function add>
2012-11-13 18:53:13 +0100 marked best answer Traversing sage's symbolic expression trees in python

Did you read TFM? There is a Converterclass to build your own expressions trees: http://www.sagemath.org/doc/reference...

If you want to do it by hand you can use

sage: eq = x*sin(x)
sage: eq.op
Operands of x*sin(x)
sage: list(eq.op)
[x, sin(x)]

but I'd recommend you use the Converter

2012-11-13 18:53:09 +0100 commented answer Traversing sage's symbolic expression trees in python

Thank you. op and operator are what I was looking for. I did read TFM but it's pretty... complete. It takes a while to find the needle in the haystack.

2012-11-12 18:16:40 +0100 asked a question Traversing sage's symbolic expression trees in python

I'm writing some python code around sage and I need to build an expression tree of the following basic form:

  • each node represents an operation
  • each child tree represents an expression tree to which the operation applies

Can anyone point me in the right direction as to how to traverse an instance of sage.symbolic.expression.Expression, so as to extract this kind of semantic information?

2012-11-10 20:36:01 +0100 commented answer Python's C API and SAGE

Thanks, this seems to work. Even compiling it outside the sage shell and running it in the sage shell works. Not quite what I was looking for though (I'd prefer if sage didn't need to be the master).

2012-11-10 03:43:45 +0100 received badge  Student (source)
2012-11-09 23:47:05 +0100 asked a question Python's C API and SAGE

I have written some python code which imports and uses the sage library. I would like to invoke some of this code from C++ code using the C API for python. The problem is that the C API uses the system-wide python installation, rather than sage's python, and therefore the "from sage.all import *" statement generates ImportError. Can anyone tell me how to
(i) install the sage libraries into the system's python installation, OR
(ii) tell the C API to use sage's python rather than the regular version, OR
(iii) resolve this some other way?

2012-10-15 17:19:42 +0100 marked best answer python/sage scripts

Edit: try replacing the first line with #!/usr/bin/env sage. That might bypass all of the problems described below.

One more attempt at an answer: perhaps the shell in VirtualBox doesn't accept the syntax #!/usr/bin/env sage -python — some shells balk at having more than one term after "/usr/bin/env". So changing this first line to #!/usr/bin/env python and executing it with sage -sh -c './factor 2012' should work, as should first running sage -sh and then ./factor 2012. In either case, sage -sh tells /usr/bin/env python to use Sage's version of Python, which knows how to import the Sage library (from the line from sage.all import *).

That's my guess. See Wikipedia's article on 'Shebang (Unix)' – I don't know how to add the link here, since the link has a right parenthesis in it, which conflicts with the markup here for links – and in particular the part which says

Another portability problem is the interpretation of the command arguments. Some systems, including Linux, do not split up the arguments;[11] for example, when running the script with the first line like,

`#!/usr/bin/env python -c`

That is, python -c will be passed as one argument to /usr/bin/env, rather than two arguments. Cygwin also behaves this way.

While the original script (with #!/usr/bin/env sage -python) works on my OS X box, it doesn't work on a linux machine that I have access to. This part of the tutorial needs to be fixed, I think.

2012-10-15 17:19:42 +0100 commented answer python/sage scripts

I see - thanks.

2012-10-15 17:19:42 +0100 received badge  Commentator
2012-10-15 15:27:39 +0100 marked best answer Navigating sage source code

If you've downloaded the source code for Sage but haven't built Sage yet (by typing 'make'), then as kcrisman says, the source code for the Sage library is packaged in SAGE_ROOT/spkg/standard/sage-5.2.spkg. So you could do this (starting from SAGE_ROOT):

$ cd spkg/standard
$ tar xfj sage-5.2.spkg
$ cd sage-5.2/sage

Then you can browse through the source code as found on line.