Ask Your Question

marco's profile - activity

2020-08-05 02:40:54 +0200 received badge  Notable Question (source)
2019-01-04 16:18:58 +0200 received badge  Popular Question (source)
2017-10-16 16:24:23 +0200 received badge  Popular Question (source)
2017-02-22 16:56:50 +0200 received badge  Notable Question (source)
2017-01-10 06:58:45 +0200 received badge  Famous Question (source)
2016-03-17 02:17:26 +0200 received badge  Famous Question (source)
2016-02-02 14:55:18 +0200 received badge  Notable Question (source)
2014-06-29 03:15:29 +0200 marked best answer Mystery white border around Graphics object

If you try to show() a sage.plot.graphics.Graphics object, you will find something extremely bizarre: there is a white border around the .png image which is 30 pixels wide (on some sides, 31 pixels wide). There is no documentation of this and it seems to be impossible to remove with any documented options to show() or to the settings of a Graphics object.

Does anyone know how to get rid of this bug?

The best thing I came up with was to do

show(MyObject, axes=False, axes_pad=0)

This only reduced the number of pixels but didn't remove the border entirely.
Also note that you can sometimes make the graphics object transparent (though not through show()), but this does not remove the border, it only makes it transparent, which causes even more problems when I pipe this into other software.

Example:

polygon([(0,0),(1,0),(1,1),(0,1)],aspect_ratio=1,axes=False,figsize=1,axes_pad=0)

yields:

example

2014-06-29 03:15:29 +0200 marked best answer speed and order of operations with CDF

Why is the absolute value of the exponential of z:

f = fast_callable(exp(z).abs(),domain=CDF,vars='z')

about twice as fast as the exponential of the real part of z:

g = fast_callable(exp(z.real()), domain=CDF, vars='z')

Should I ignore this kind of thing in sage, or is there a good reason in this particular case?


Data:

z = var('z')
f = fast_callable(exp(z).abs(),domain=CDF,vars='z')
g = fast_callable(exp(z.real()), domain=CDF, vars='z') 
timeit('f(4+2*I)')

625 loops, best of 3: 2.94 µs per loop

timeit('g(4+2*I)')

625 loops, best of 3: 5.87 µs per loop


Non-fast_callable times, in case you are interested:

z = var('z')
fs(z) = exp(z).abs()
gs(z) = exp(z.real())
timeit('fs(4+2*I)')

625 loops, best of 3: 1.02 ms per loop

timeit('gs(4+2*I)')

625 loops, best of 3: 988 µs per loop

2014-06-29 03:14:36 +0200 marked best answer "Abstract" linear algebra

This is more of a general question about whether we can do with Sage what we normally do as mathematicians on paper and in our minds. For example, if I do

V = VectorSpace(QQ,4)

W = VectorSpace(QQ,4)

V==W

I get: True. This is quite disturbing - while V and W are isomorphic they should not be identical. As I understand it, a vectorspace over QQ for Sage is just QQ^4, that's it. In other words, the Linear algebra package, while excellent, is not really about vector spaces but rather about arrays of numbers.

Any thoughts on this desire of mine to have a genuine "coordinate-free" approach?

2013-12-17 00:09:45 +0200 received badge  Notable Question (source)
2013-11-19 00:13:17 +0200 received badge  Popular Question (source)
2013-05-20 23:52:13 +0200 received badge  Popular Question (source)
2013-05-13 18:55:20 +0200 marked best answer multivariate power series computation with recognition

First, a personal comment:

For technical implementation of power series, there is a difference between "lazy" power series and "truncated" power series. It sounds like you're interested in the former, but Sage implements the latter. There are different tradeoffs for the two approaches; please don't suggest that one is "improper" unless you're prepared to make a very thorough case that it is uniformly inferior. To have real weight, such a case would probably need to be accompanied by an actual implementation of the other approach.


Now on to your specific question:

I think the calculations you're interested in can be done just fine with truncated power series. The essential paradigm change is that you need to decide at the outset how many coefficients you're interested in actually computing. This will be the "precision" of the power series that you work with. For multivariable power series, the precision limits the total degree of terms. So in a power series with precision 5, terms like x^3*y^3 would be dropped because they have total degree greater than 5. Some elements can have infinite precision, but only those which are actually polynomials (that is, they have only finitely many nonzero coefficients).

Every power series ring (in Sage) has a default precision -- the precision that it assigns by default to elements that don't already have one. This is only important in your case because exp uses the default precision for the parent ring of its arguments.

Here is some code that would carry out your calculation through total degree 4:

sage: prec = 5                                                                 
sage: R.<x,y> = PowerSeriesRing(QQ, default_prec=prec); R
Multivariate Power Series Ring in x, y over Rational Field
sage: h = sum(factorial(m)*4^n*x^m*y^n for m in range(prec) for n in range(pre>
sage: k = sum((m+n)*x^m*y^n for m in range(prec) for n in range(prec))
sage: exp(x*y)
1 + x*y + 1/2*x^2*y^2 + O(x, y)^5
sage: H = h(x,exp(x*y)*y)
sage: H
1 + x + 4*y + 2*x^2 + 4*x*y + 16*y^2 + 6*x^3 + 8*x^2*y + 20*x*y^2 + 64*y^3 + 24*x^4 + 24*x^3*y + 36*x^2*y^2 + 96*x*y^3 + 256*y^4 + O(x, y)^5
sage: H*k
x + y + 3*x^2 + 7*x*y + 6*y^2 + 7*x^3 + 19*x^2*y + 33*x*y^2 + 27*y^3 + 17*x^4 + 45*x^3*y + 91*x^2*y^2 + 143*x*y^3 + 112*y^4 + 46*x^5 + 119*x^4*y + 219*x^3*y^2 + 407*x^2*y^3 + 605*x*y^4 + 448*y^5 + O(x, y)^6

If you really only need exp(x*y), you could define this just as h and k are defined, and thereby avoid ...

(more)
2013-05-02 02:25:32 +0200 asked a question multivariate power series computation with recognition

I would like to do a computation in Sage involving formal power series but I believe some (all?) steps may be impossible:

  1. define a couple of formal power series in two variables (x,y) by defining the coefficient function a(m,n) (the coefficients involve gamma functions and such, and are rational). As far as I can see there is no way to do even this step in Sage.

  2. do a change of variables, something like (x,y) = (g(x,y),y), obtaining new power series. The function g(x,y) may be a polynomial or possibly itself an infinite power series.

  3. multiply the resulting power series

  4. Simplify the expression for the coefficients of the resulting power series c(m,n) in terms of classical quantities like gamma functions.

Which of these steps do you believe is possible in Sage? I could write my own software to deal with formal power series properly, but then I would not be able to recognize or simplify the resulting coefficients.

As an example:

  1. h(x,y) is a sum of (m!)(4^n)x^m y^n with indices running from 0 to infinity, and k(x,y) is a sum of (m+n)x^m y^n,

  2. do a substitution H(x,y) = h(x,exp(xy)y)

  3. multiply H*k

  4. simplify the coefficients of H*k.

2013-03-29 11:03:24 +0200 received badge  Nice Question (source)
2012-12-14 04:16:29 +0200 received badge  Nice Question (source)
2012-11-29 01:03:49 +0200 marked best answer how to tell if a function is admissible as a 'symbolic' function
sage: type(airy_ai)
<type 'function'>
sage: type(gamma)
<type 'function'>
sage: type(sin)
<class 'sage.functions.trig.Function_sin'>
sage: type(log_gamma)
<class 'sage.functions.other.Function_log_gamma'>

Actually, this is somewhat misleading, since gamma uses

sage: type(sage.functions.other.gamma1)
<class 'sage.functions.other.Function_gamma'>

under the hood, but I hope you get the point.

See also Trac 12455 for this very issue - maybe you can help?

2012-11-28 11:12:31 +0200 received badge  Commentator
2012-11-28 11:12:31 +0200 commented answer how to tell if a function is admissible as a 'symbolic' function

This helps but actually gives an even better example of my problem: sage: type(airy_ai); type(gamma) type 'function' type 'function' sage: taylor(gamma(x),x,1) -(x - 1)*euler_gamma + 1 sage: taylor(airy_ai(x),x,2) TypeError: Cannot evaluate symbolic expression to a numeric value.

2012-11-28 00:34:06 +0200 asked a question how to tell if a function is admissible as a 'symbolic' function

Sorry for the wording of the question. Functions in sage.functions.special, such as airy_ai, seem not to be true functions, e.g. you can't apply taylor() to them. On the other hand, maxima.airy_ai seems to be OK. How can I tell what "status" a function has, or whether I can pass it to operations such as taylor()?

taylor(maxima.airy_ai(x),x,0,4)

-1/363^(2/3)x^4/gamma(1/3) + 1/183^(1/3)x^3/gamma(2/3) - 1/33^(2/3)x/gamma(1/3) + 1/3*3^(1/3)/gamma(2/3)

taylor(sage.functions.special.airy_ai(x),x,0,4)

Traceback (click to the left of this block for traceback) ... TypeError: Cannot evaluate symbolic expression to a numeric value.

2012-11-28 00:20:38 +0200 commented answer Keeping sage worksheets in sync across computers

thanks, that makes it even easier.

2012-11-24 14:16:25 +0200 received badge  Student (source)
2012-11-24 14:16:24 +0200 received badge  Teacher (source)
2012-11-24 14:16:24 +0200 received badge  Self-Learner (source)
2012-11-24 12:33:34 +0200 answered a question Keeping sage worksheets in sync across computers

One thing that seems to work is to start the sage notebook from the terminal session with

sage: notebook('/Users/.../Dropbox/Sage')

to create a notebook in the specified directory and then use the same command for any other linked computer. I've tried this out and it seems to work perfectly using Dropbox.

2012-11-24 11:55:18 +0200 commented answer Mystery white border around Graphics object

I think the plot must contain the information of its dimensions, so perhaps we can programmatically do this

2012-11-24 01:18:02 +0200 asked a question Keeping sage worksheets in sync across computers

I have been using Sage through the notebook interface. I usually keep my other working documents in sync using Dropbox. What do you think is an efficient way of working on notebooks from different computers? Currently I export and import .sws files. I thought of perhaps changing the DATA path to a folder on Dropbox, but I don't know enough about the internals of Sage to see if this would be a horrible idea.

2012-11-23 02:19:42 +0200 marked best answer Mystery white border around Graphics object

This seems to be a feature from matplotlib. You can try your best, turning off everything in matplotlib like this:

import matplotlib.pyplot as plt
plt.plot(range(10), range(10))
plt.axis('off')
plt.savefig('/tmp/a.png', bbox_inches='tight')

The outcome of the plot will be the same as the following code in Sage:

list_plot(range(10), plotjoined=True, axes=False)

So there is not much that can be done on Sage side. Eventually, the generation of the figure and the saving is handled by matplotlib.

Update:

There is a way to do it in matplotlib.

sage: import matplotlib.pyplot as plt
sage: plt.plot(range(10), range(10), '-o')
sage: plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
sage: plt.axis('off')
sage: plt.savefig('/tmp/a.png', bbox_inches=0)
2012-11-22 18:01:16 +0200 marked best answer "Abstract" linear algebra

I like coordinate-free linear algebra, but your issue here may simply be that == is not the "is identical" operator. Consider the following examples:

sage: 3 == Mod(3,7)
True
sage: 3 == Mod(3,5)
True
sage: Mod(3,5) == Mod(3,7)
False
sage: Q = PolynomialRing(QQ,'t')
sage: 3 == Q(3)
True
sage: 3 in Q
True
sage: R = PolynomialRing(RR,'w,v')
sage: 3 == R(3)
True
sage: Q(3) == R(3)
False

Given this behavior, I don't find it particularly surprising that V == W returns True above!

Of course, id(V) == id(W) also returns True, which is a little more surprising (to me). And the free module documentation includes the following note:

Note: In Sage it is the case that there is only one dense and one sparse free ambient module of rank n over R.

So it seems it's not even _possible_ to make two separate copies of a free module with a given rank. That seems a little limiting, which is your original point, I guess :) Maybe it's more accurate to think of VectorSpace as short for "VectorSpaceWithCanonicalBasis".