Ask Your Question

Kate Stange's profile - activity

2021-11-11 17:03:24 +0200 received badge  Notable Question (source)
2020-07-27 19:24:50 +0200 received badge  Notable Question (source)
2019-01-30 04:29:52 +0200 received badge  Famous Question (source)
2017-08-04 04:46:25 +0200 received badge  Famous Question (source)
2017-07-18 16:33:49 +0200 received badge  Notable Question (source)
2017-07-08 21:27:10 +0200 received badge  Popular Question (source)
2016-12-29 04:54:18 +0200 received badge  Popular Question (source)
2015-07-08 00:59:55 +0200 asked a question subgroup of number field unit group

I would like to be able to create subgroups of a unit group generated by given elements. I haven't, thus far, been able to find a way to make this work. The following doesn't work:

N.<a> = NumberField(x^3+2)
G = N.unit_group()
g = G.random_element()
G.subgroup([g])

Can anyone help me find a workaround?

(Note: it appears to be a bug, see trac.sagemath.org/ticket/18863, but I'm just looking for a workaround for now.)

2015-05-28 17:44:37 +0200 asked a question How to flatten polynomial rings?

It is possible in Sage to create a polynomial ring over a polynomial ring. But Sage stores this as a two-tiered structure that is sometimes inconvenient. I would like to flatten it.

For example,

sage: P = PolynomialRing(QQ, 'c', 6)
sage: S = PolynomialRing(P, 't', 6)

creates a polynomial ring in t0, t1, t2, ...., t5 over a polynomial ring in c0, c1, ..., c5. But then

sage:  clist = list( P.gens()[i] for i in range(6)) # get names for variables
sage:  tlist = list( S.gens()[i] for i in range(6))
sage:  poly = clist[0]*tlist[0] # produces polynomial c0*t0 in S
sage:  poly.polynomial(clist[0]) # asks for poly as a polynomial in c0

fails with "var must be one of the generators of the parent polynomial ring."

I would like to `flatten' S so it is simply a single polynomial ring over QQ in 12 variables.

You may ask, why don't I just construct a single ring in the first place? In this instance, because I want to create a polynomial ring in c0, ...., cn and t0, ...., tn where n is a variable, and I don't know how to do this (I'd prefer to avoid just making c0, ..., c2n and trying to keep track of which are actually t's). I can imagine other situations where one would like to be able to flatten also.

2014-06-29 03:12:44 +0200 marked best answer publish 3d plots to web?

I'd like to post the output of a 3d plot to the web. For example, after plotting a surface, a Jmol output is produced, which my browser renders in the notebook. I'd like this Jmol plot to be output as a file that could be uploaded to a server and embedded in a webpage (where it can still be manipulated with the mouse, etc.). Is there a way to do this?

2014-06-13 09:29:44 +0200 received badge  Popular Question (source)
2014-01-19 11:30:53 +0200 received badge  Great Question (source)
2013-09-19 00:43:27 +0200 received badge  Notable Question (source)
2013-04-27 18:09:20 +0200 received badge  Popular Question (source)
2013-04-18 08:19:11 +0200 received badge  Notable Question (source)
2012-09-11 05:28:11 +0200 received badge  Taxonomist
2012-07-25 05:12:52 +0200 received badge  Good Question (source)
2012-07-18 18:16:18 +0200 marked best answer Plotting a latex matrix using text()

matplotlib uses its own typsetting system called mathtext by default. I think the problem you are getting is due to mathtext not supporting arrays in math mode?

In any case, you can work around this by telling matplotlib to use your system LaTeX instead of mathtext like this:

from matplotlib import rc
rc('text', usetex=True)
my_matrix = r'$\left( \begin{array}{ll} 2 & 3 \\ 4 & 5 \end{array} \right)$'
text(my_matrix, (1,1))

You can look at another example here, it shows you how to change fonts to match the font in your document.

2012-07-18 18:16:00 +0200 commented answer Plotting a latex matrix using text()

Thanks! This solved my problem.

2012-07-15 02:18:55 +0200 received badge  Nice Question (source)
2012-07-14 09:04:17 +0200 asked a question Plotting a latex matrix using text()

I would like to plot a latex'd matrix at a location in a 2d plot. I tried this:

text('$\\left( \\begin{array}{ll} 2 & 3 \\\\ 4 & 5 \\end{array} \\right)$', (1,0) )

and various variations to do with the backslashes being escaped or not. But every time I get an error:

matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\left( \begin{array}{ll} 2 & 3 \\ 4 & 5 \end{array} \right)$ (at char 0), (line:1, col:1)

It appears that matplotlib doesn't want to parse an array or a pmatrix etc. Is there a workaround?

2012-04-30 18:57:27 +0200 received badge  Good Question (source)
2012-01-11 12:18:55 +0200 received badge  Popular Question (source)
2011-06-02 06:21:45 +0200 received badge  Nice Question (source)
2011-06-02 06:21:45 +0200 received badge  Good Question (source)
2011-05-23 01:17:00 +0200 commented question coerce pari type or string to rational function workaround?
2011-05-23 01:04:29 +0200 commented question coerce pari type or string to rational function workaround?

Thanks for the answers below. I've got my computation working (yay!), but I'm also going to find out if the bug(s) are known and report them if needed. I suspect this must be a known issue, so I'll add a comment when I've looked into it on the tracking system. Any comments or advice on that is welcome.

2011-05-23 01:01:25 +0200 marked best answer coerce pari type or string to rational function workaround?

Here's how I'd get around the problem if I needed it to work Right Now(tm):

sage: var("x y")
(x, y)
sage: t = gp.simplify((x+y)/y)
sage: 
sage: R.<x,y> = PolynomialRing(QQ)
sage: S = R.fraction_field()
sage: 
sage: t2 = S(sage_eval(repr(t),locals=locals()))
sage: t2
(x + y)/y
sage: parent(t2)
Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field
sage: parent(t2) is S
True
2011-05-23 01:01:15 +0200 commented answer coerce pari type or string to rational function workaround?

Thanks! Right Now(tm) is exactly what I needed, and this did the trick.

2011-05-23 01:00:25 +0200 commented answer coerce pari type or string to rational function workaround?

Thanks! This works, but for some reason it is extremely slow, at least on my machine.

2011-05-22 22:20:22 +0200 received badge  Supporter (source)
2011-05-22 21:23:07 +0200 received badge  Nice Question (source)
2011-05-22 16:27:01 +0200 edited question coerce pari type or string to rational function workaround?

I am getting some rational functions from pari/gp and want to work with them in Sage. I can't figure out how to do the coercion. I tried coercing them directly, and even via a string.

Here's what I've tried:

Make a pari type rational function:

sage: test = gp.simplify((x+y)/y)

This is the field I want to put it in:

sage: R.<x,y> = PolynomialRing(QQ)
sage: S = R.fraction_field()

coercing directly doesn't work:

sage: S(test)
Traceback (most recent call last):
...
TypeError: unable to convert 1/y*x + 1 to a rational

So I tried making a string out of it:

sage: str(test)
'1/y*x + 1'

Of course, sage would accept that string if I typed it in directly:

sage: S(1/y*x + 1)
(x + y)/y

But it won't accept it as a string:

sage: S(str(test))
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
sage: S('1/y*x + 1')
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field

All of this works fine for polynomials (just remove the denominator of y from the example above). I think these are bugs and I will report them as such, if you agree. But in the meantime, does anyone have a workaround I can use?

2011-05-22 16:12:45 +0200 received badge  Scholar (source)
2011-05-22 16:12:45 +0200 marked best answer publish 3d plots to web?

This isn't a complete answer, but may get you or someone else started, depending on how hard you want to work:

As far as I can tell, there are basically two things you need to be able to do to display the output on a separate page. First, figure out how to load the JMol application on that page. I think this involves finding and loading a bunch of javascript files, and is probably described on the JMol Website. Second, figure out how to find the data file Sage produces to be plotted with JMol, and also load that into your webpage. To that end, I would suggest looking at the source code for your notebook page, and search for some lines like the following (I'd suggest searching for "jmol?" on the page):

<div class="cell_output_html_wrap" id="cell_output_html_112">
  <div><script>jmol_applet(500, "/home/admin/10/cells/112/sage0-size500.jmol?1290969964");</script></div>
</div>

The path specified is relative to the location of your sage notebook files. This is printed right after you start the notebook server -- the default is ".sage/sage_notebook" in your home directory:

sage: notebook()
The notebook files are stored in: sage_notebook.sagenb

Once you've found the relevant data file and copied it somewhere your page can load it, you might be finished by just using something like the <script> block above . . . except that I don't see jmol_applet as part of the JMol documentation -- the closest-looking function I've seen is jmolApplet. So if jmol_applet is defined in one of the other javascript libraries loaded in the sage notebook, then you'll have to load that library and all of its dependencies too, or figure out how to use one of the other JMol commands to load and display your data file. Looking again at the source of the notebook page with your 3d plot may give you a good idea of which javascript files to use.

Good luck, and please let us know if you make some progress on this, or find out a better way to do it!


Update:

I just noticed that if you try to plot something from the command line, sage opens up a JMol java applet which has useful options and menus like File > Export > Export to Web Page. This saves the data in a place of your choosing, but you still have to point it to the JMol .jar files.