Ask Your Question

Iguananaut's profile - activity

2020-01-15 07:13:59 -0600 received badge  Necromancer (source)
2020-01-13 06:05:17 -0600 commented answer Working with units

astropy also has a very powerful units and quantities package which took much of its original inspiration from Pint. Actually, lately they've been converging more and more again on shared functionality (thanks in part to recent updates to Numpy making propagation of units easier)--I wonder if one day it will be possible for them to converge, rather than maintaining separate projects. Though astropy.units does have some more advanced functionality specific to the astronomy community (though also useful for most any science).

2020-01-13 06:00:59 -0600 edited question Generating and evaluating a polynomial

I woud like to create a polynomial P(x) = 1 + x + x^2 + ...... + x^50 and evaluate it for different values of x.

What would be a good way to do this without entering it by hand.

Thank you!

I am very new to Sage. I would like to create a polynomial and evaluate it for a certain x say x=1.00001

The polynomial is: P(x) = 1 + x + x^2 + ..... + x^50

Thank you for the help!

2020-01-09 07:58:21 -0600 commented answer Problem importing Sage library in Python script on Windows

If you can be more specific about what exactly you tried to do and where you got stuck I might be able to give a more precise answer.

2020-01-09 07:57:57 -0600 commented answer Problem importing Sage library in Python script on Windows

SageMath is really two things: There's what's referred to sometimes as "sagelib": the actual sage Python package, and then there's "Sage the Distribution" consisting of sagelib and all its dependencies. Though there's been some work done toward making Sage installable with pip like any Python package (there's no strong reason Sage needs its own Python interpreter) it's still non-trivial because you need most of the dependencies already in place. An (outdated) list of those dependencies is here. Some of those are optional, but many non-trivial ones are very integral. conda makes it seem easy because it can pull in all those dependencies, but outside that context it's not trivial.

2020-01-09 05:10:57 -0600 answered a question Problem importing Sage library in Python script on Windows

I'm not sure what you mean exactly by "using Sage in a Python script". You didn't really provide any details.

Sage has always traditionally included its own Python interpreter, and so using Sage meant you'd have to run the Python interpreter that comes with Sage (if you're at all familiar with conda as you say, this is a little like having its own conda environment). The folks who've packaged Sage for conda make that a little more transparent, since you can now install sage directly in a conda environment. But either way it's effectively similar.

What do I need to do with the installation to get my python script to find Sage?

You will need to run it with the Python interpreter that comes with Sage. If you have additional dependencies, as I wrote, this is a complete Python environment so you can pip install them using Sage's Python.

As an aside, is there a reason why there is no conda package for Sage on Windows, only Linux and MacOS?

Because Sage on Windows depends on Cygwin, and there is no official Cygwin target for conda. There could be, and it's something I would like there to be, but it would be a large effort for which there is currently no support.

But it seems completely incompatible for integration with other languages/tools.

Not necessarily but it is a little tricky. Search this site for other questions like this one where I explain how to use Sage in PyCharm--again it's not all that different from using a virtualenv; still just a little trickier. If you have any good ideas for how to make this easier I'm all for it.

When I looked at the log for that, it seems like there was a connection issue and the source could not be downloaded.

I noticed also there were some problems with some connection problems with some of the mirrors yesterday. Try just running make again and the build should resume where it left off. If you followed the instructions here it should work.

Sage is a complex beast: Its large set of non-standard and/or tightly-pinned dependencies makes it non-trivial to install and use compared to a normal Python package. People have been working hard for years to make that easier (see, again, your success with conda) but this is not easy. You're welcome to lend a hand if you have any insights.

2020-01-09 04:56:17 -0600 commented answer Should I avoid using unicode in names of variables?

IPython on Python 3, yes.

2020-01-08 12:14:35 -0600 received badge  Nice Answer (source)
2020-01-08 11:29:10 -0600 commented answer Should I avoid using unicode in names of variables?

@dsejas I agree, it might be good to have a module defining unicode aliases for different globals. It can be made to load on Python 3 only (which is now the default anyways).

2020-01-08 11:27:28 -0600 commented answer Should I avoid using unicode in names of variables?

I meant to add; I opened a ticket for this. I suggest following up there with suggestions: https://trac.sagemath.org/ticket/28966

2020-01-08 09:18:59 -0600 commented question Rotate a parametric plot

As in just, rotating all the pixels of the image, including axes? I'm still not sure why you would want to do that. And also the question is: rotate by an arbitrary amount, or just by 90 degrees? Since rotating images by arbitrary angles means you need some way to deal with clipping. Perhaps you could just add some example images of what results you're trying to obtain...

2020-01-08 09:16:36 -0600 commented answer ask.sagemath.org Y2k20 bug

I'm impressed that you bothered to track it down :)

2020-01-08 09:13:59 -0600 commented answer Should I avoid using unicode in names of variables?

Of course--this is an IPython feature.

2020-01-07 10:54:30 -0600 commented answer Should I avoid using unicode in names of variables?

You would have to look into what unicode completion plugins exist for emacs (I'm sure there are several).

2020-01-07 10:52:08 -0600 commented question Rotate a parametric plot

I don't know Maple so I don't know exactly how to interpret that example. But what do you mean by "rotate a plot"? That could have several different interpretations. In the example you gave in Sage you didn't rotate the plot so much as you rotated a vector field and that plotted the rotated vector field. Do you want to rotate the axes? The entire image?

2020-01-07 10:40:31 -0600 received badge  Good Question (source)
2020-01-07 10:39:03 -0600 received badge  Nice Question (source)
2020-01-07 09:25:53 -0600 commented question TypeError: 'sage.rings.integer.Integer' object is not iterable

What do you mean by "When I try to compile it" Do you mean when you run it? I can't reproduce the problem because your code sample has several presumably custom-written functions. What does the full traceback show? This "WARNING: Code contains non-ascii characters" is also mysterious. The code you showed us does not obviously contain any non-ascii characters. In short, without at least knowing what gen_par, up, down, keygeneration, randompolyBinary enc, dec, are there's no way to tell you what the problem is. But apparently you are trying to iterate over an integer somewhere.

2020-01-07 09:21:41 -0600 commented question Sage error from module `typing` and python 3.8

I'm not exactly clear how you're installing Sage. Sage doesn't support Python 3.8 yet.

2020-01-07 09:19:44 -0600 edited question Sage @fork Parallel Decorator Breaking Interface to Singular

Exception raised by child process with pid=1704:

Traceback (most recent call last):
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/parallel/use_fork.py", line 177, in __call__
self._subprocess(f, dir, *v0)
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/parallel/use_fork.py", line 302, in _subprocess
value = f(*args, **kwds)
File "<ipython-input-9-532b53e3019b>", line 167, in master
reduktion = reduction(polynomial)
File "<ipython-input-9-532b53e3019b>", line 94, in reduction
singular.set_ring(currentRing)
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 1098, in set_ring
self.eval("setring %s; short=0"%R.name(), allow_semicolon=True)
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 658, in eval
raise SingularError('Singular error:\n%s'%s)
SingularError: Singular error:
? sage1317 is no name of a ring/qring
? error occurred in or before STDIN line 11: `setring sage1317; short=0;`

I've been implementing parallelism on a program built in Sage MATH using its interface to Singular. I am attempting to use Sage's @fork parallel decorator, which seems to cause issues with Singular (this error does not occur if the decorator is not present). I'm very new to parallelism and am unsure what the issue here could be. Thanks for any and all help! :D

2020-01-07 09:16:27 -0600 asked a question ask.sagemath.org Y2k20 bug

It seems ask.sagemath.org (or rather Askbot) has fallen prey to the Y2k20 bug, just in its date format. Just look at how the dates of some posts or comments are formatted: Previously they would be displayed like "Dec 31 '19" and now they display "Jan 7 '0" with the year formatted as "'0" instead of "'20".

I don't know if it's worth doing anything about; I just found it amusing.

2020-01-07 08:41:29 -0600 answered a question Should I avoid using unicode in names of variables?

In Python 3 you can do some nice things like:

sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1

and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.

Ticket: https://trac.sagemath.org/ticket/28966

2020-01-07 08:35:44 -0600 commented answer Should I avoid using unicode in names of variables?

Ah, I figured it out, you can type o\acute<tab>. Similarly u\ddot<tab> gives you ü, etc. So you can either do the full unicode character name, or you can use its latex name if it has one (e.g. \ss gives ß), but for latex commands that modify a character, you type the character firstthen the command, then tab. This is documented at https://ipython.readthedocs.io/en/sta...

2020-01-07 08:33:33 -0600 commented answer Should I avoid using unicode in names of variables?

I'm all for it--in fact I've been hoping that Sage will start to come with more unicode variables built-in (e.g. for pi). Also; neat trick available in Python 3 only that most people don't know: You can tab-complete unicode characters e.g. by typing \pi<tab>. Unfortunately it doesn't work well with some simple accented characters. For example to complete ó you have to type (afaict) \LATIN SMALL LETTER O WITH ACUTE<tab>. That should be fixed somehow...

2020-01-07 08:18:28 -0600 commented question Rotate a parametric plot

What do you mean by "without drawing it again"? If you just want to perform the rotation then just perform the rotation: R(theta)*vector([cos(2*t), sin(3*t)]). This is the actual application of the rotation matrix to a vector; you just need to supply values for t. parametric_plot only plots your vectors for some range of t., but of course you can perform these calculations without plotting them. What are you trying to accomplish exactly?

2020-01-07 08:14:27 -0600 edited question Rotate a parametric plot

Hi,

I am trying to rotate a plot given by


t=var("t")
P=parametric_plot((cos(2*t),  sin(3*t) ), (t,-10*pi,10*pi),rgbcolor=(1,0,0), thickness=2,scale='linear')
. I can rotate P by using the rotation matrix
PR=parametric_plot( (R(theta)*vector([cos(2*t), sin(3*t)])), (t,-10*pi,10*pi),rgbcolor=(1,0,0), thickness=2,scale='linear')

But is there a way to rotate it without drawing it again?

2020-01-07 08:11:40 -0600 commented question Writing the Bubble Sort on the GAP

Perhaps. We may never know...

2019-12-31 04:35:45 -0600 commented question why sagemath says 1.0 is integer?

I should note, when you write "in sympy" none of what you demonstrate actually has anything to do with SymPy and is just plain Python behavior w.r.t. the types of objects, which is an entirely language-level statement and has basically no mathematical meaning. In Python type(1) is int, and type(1.0) is float. This is asking about the language-level type that implements the value (just as type('') is str). The mathematical fact (depending on the domain you're working in...) that 1.0 is the same as 1 is irrelevant here.

2019-12-31 04:29:34 -0600 commented answer Confusion about integrating a string.

IMO the string should be parsed into a generic symbolic expression and converted into some backend-agnostic representation, but I'm still not 100% sure how symbolic expressions really work in Sage and if something like that is exactly possible...

2019-12-31 04:27:10 -0600 commented answer Confusion about integrating a string.

OTOH I think str (and most other common built-in types in Python) do deserve special consideration given their commonality, and the fact that they have a literal syntax built into the language. And I don't think it's entirely unreasonable that one might pass as symbolic expression as a string to functions like integrate() and derivative() that explicitly operate on symbolic expressions. So I think @Nasser is well-motivated to suggest that str should be given special consideration here, and that it does appear a bit sloppy that it works in many cases but not all--it's not completely random as it might be with some more arbitrary inputs, since e.g. fricas will accept some strings, but not all. I think this deserves more careful consideration.

2019-12-31 04:23:17 -0600 commented answer Confusion about integrating a string.

I generally agree with this: If you engage in undefined behavior (passing a string as the argument to integrate() then undefined (and hence unpredictable) behavior is what you get. And because Python does not perform type checking, you could pass literally any object to integrate() and maybe it will happen to work in some corner cases; most of the time it will crash. It is not standard practice in Python to manually strictly type-check all function inputs, especially given that it's possible one could, e.g., define a str subclass that duck-types as whatever type(s) the function is expecting. Not saying there's always necessarily a good reason to do that, but sometimes there is! Python trades strictness for this kind of flexibility and "consenting adult" approach to coding.

2019-12-31 04:11:12 -0600 commented question Writing the Bubble Sort on the GAP

What have you tried? Bubble sort is fairly easy to write by hand in pseudocode. GAP is a Turing complete programming language, which means that any computable algorithm you can write out by hand can then be converted to GAP code, so long as you've learned at least the basics of GAP's syntax and basic data structures such as lists. There is a nice tutorial on basic programming in GAP.

2019-12-31 04:09:49 -0600 commented answer Running sage (8.9) from command line (Windows)

It should be enough unless there's something specific about your .sage file that it needs to be run out of a specific directory.

2019-12-24 01:56:24 -0600 received badge  Necromancer (source)
2019-12-23 10:01:51 -0600 answered a question import error on debian

I recently answered this on the debian-science-sagemath mailing list: https://alioth-lists.debian.net/piper...

It seems you are using Debian testing, which currently has a version mismatch between Sage and GAP which needs to be fixed.

2019-12-23 09:58:49 -0600 edited question What does it mean that the relative discriminant is generated by a unit?

Does it mean that there is no relative integral basis?

sage: alpha=sqrt(-17/2 + sqrt(17^2-4(17))/2)
sage: f=alpha.minpoly()
sage: K.<a>=NumberField(x^4+17*x^2+17)
sage: R<y>=PolynomialRing(K)
sage: R(f).factor()
(y-a)(y+a)(y^2+a^2+17)

sage: g=y^2+a^2+17
sage: L.<b>=K.extension(g)
sage: L.relative_discriminant()
Fractional ideal (1)
2019-12-23 09:56:46 -0600 commented answer unicode coding

In what way does it "not work" for you? I just tested in this on Sage 8.9 with Python 2.7 on Windows and it works as expected. On Python 3 it's not necessary because all files are treated as UTF-8 encoded by default unless specified otherwise.

2019-12-23 09:55:18 -0600 commented answer can you programmatically define a [mathematical] function?

I feel like there ought to be an easy to to create a polynomial from a list of coefficients (and possibly a specified order). Built-in, I mean. But if it exists I can't find it....

2019-12-23 09:46:43 -0600 commented question Condition of type: STORAGE-EXHAUSTED

Depends. What are you trying to calculate? Maybe you simply don't have enough system memory to perform that computation, either in the way it's being computed, or in general.

2019-12-23 09:42:55 -0600 commented answer unicode coding
2019-12-23 09:42:00 -0600 commented answer unicode coding

Since you cited PEP-263, read carefully the regular expression it gives for what the coding line should match:

^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)

specifically, the string coding should be immediately followed by a : or =, no whitespace. The encoding name UTF-8 is fine since encoding names are not case-sensitive.

The most common way to write this is:

# -*- coding: utf-8 -*-

Note: Since this is just a standard Python feature it is not specific to Sage, so you could also likely find answers to your problem on StackOverflow or any other source for Python help.