Ask Your Question

parzan's profile - activity

2024-04-06 23:08:41 +0200 received badge  Famous Question (source)
2022-08-06 00:47:05 +0200 received badge  Popular Question (source)
2022-04-02 02:47:43 +0200 received badge  Notable Question (source)
2019-01-29 22:34:36 +0200 received badge  Nice Answer (source)
2019-01-28 07:51:50 +0200 commented answer Bug in series expansion?

After playing with it a bit more, I realized that sage has this too:

sage: f.taylor(q,oo,2)
4/q + 12/q^2 + 1

So I consider the case closed (except for that fact that series should have done the same?)

2019-01-27 20:52:08 +0200 commented answer Bug in series expansion?

That's not what had in mind (an infinite sum), but using your approach this does work:

sage: f.maxima_methods().taylor(q,oo,2)

4/q + 12/q^2 + 1

2019-01-27 16:43:47 +0200 answered a question Convert real matrix into Integer matrix

It seems that the most efficient method is A.apply_map(ZZ,ZZ) (in terms of running time).

Note this will not work if you have non-integers in the matrix, then you can use A.apply_map(int,ZZ) or A.apply_map(round,ZZ) to round the entries.

2019-01-27 13:40:58 +0200 answered a question implicit_plot plot of a list

It seems that implicit_plot is not happy about receiving a list of functions. You can do this:

F2=sum([implicit_plot(y^2 - x^2 -c ==0, (x,-5,5), (y,-5,5), color="blue" ) for c in [-5..5]])

which should work for the purpose of displaying or saving the plot.

2019-01-27 13:00:00 +0200 asked a question Bug in series expansion?

I'm trying to expand $(q + 1)/(q - 3)$ at $q=\infty$. This doesn't work:

sage: f=(q + 1)/(q - 3)
sage: f.series(q==infinity,3)
Order(-Infinity)

This also doesn't:

sage: f.subs(q==1/q).series(q==0,3).subs(q==1/q)
-1/2/q - 1/2

(the value is wrong, it should be 1 as $q$ goes to infinity, not $-1/2$).

This works:

sage: f.subs(q==1/q).simplify_rational().series(q==0,3).subs(q==1/q)
4/q + 12/q^2 + 1

But is not very friendly. Any ideas?

2016-12-08 17:24:25 +0200 received badge  Popular Question (source)
2016-02-22 18:41:54 +0200 received badge  Notable Question (source)
2015-02-18 18:02:55 +0200 received badge  Popular Question (source)
2014-06-29 17:31:41 +0200 received badge  Famous Question (source)
2014-06-29 17:31:41 +0200 received badge  Notable Question (source)
2014-06-29 03:14:50 +0200 marked best answer gap calls seem to consume a lot of time

I am trying to migrate some code from GAP to sage, and the overhead for calls to GAP procedures is enormous. Here is an example:

----------------------------------------------------------------------
| Sage Version 4.6.2, Release Date: 2011-02-25                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: def test1():
....:     for x in xrange(100): gap.eval('G:=Group([(1,2,3)])')
....:     
sage: def test2():
....:     gap.eval('for x in [1..100] do G:=Group([(1,2,3)]);od')
....:     
sage: timeit('test1()')
5 loops, best of 3: 810 ms per loop
sage: timeit('test2()')
25 loops, best of 3: 12.6 ms per loop

Is there anything I am doing wrong?

I tried some profiling, which indicated that most of the time is consumed by "select.select".

Any help will be most welcome.

2014-05-03 11:11:02 +0200 received badge  Famous Question (source)
2014-05-02 21:42:40 +0200 received badge  Popular Question (source)
2013-12-29 23:09:29 +0200 received badge  Nice Answer (source)
2012-11-14 17:53:20 +0200 received badge  Good Answer (source)
2012-10-24 01:09:15 +0200 received badge  Notable Question (source)
2012-08-06 10:36:28 +0200 received badge  Guru (source)
2012-08-06 10:36:28 +0200 received badge  Great Answer (source)
2012-05-09 03:51:59 +0200 asked a question All decompositions of a prime as a sum of four squares

Jacobi showed that a prime $p$ has $8(p+1)$ decompositions as a sum of four squares. sage.rings.arith.four_squares computes one such decomposition. Is there a way to compute all of them?

2012-03-28 17:41:41 +0200 answered a question Display variable value

Some options:

sage: print 'A=',A
A= 10
sage: print 'A='+`A`
A=10
sage: print 'A=%03d'%A
A=010
2012-02-21 09:15:39 +0200 received badge  Nice Answer (source)
2012-02-21 05:27:05 +0200 answered a question Strange result of a relational expression

See here: http://ask.sagemath.org/question/1144... and here: http://ask.sagemath.org/question/605/...

Quoting from DSM's answer:

"False" doesn't necessarily mean false, it might only mean "Sage couldn't figure out how to prove it was true.

2012-02-12 08:55:43 +0200 received badge  Nice Answer (source)
2012-02-11 06:10:13 +0200 answered a question Linear transformation from polynomials

How is this?

sage: dim=4                                
sage: F = PolynomialRing(QQ, dim,'X')      
sage: I = F.ideal([x*y for x,y in tuples(F.gens(),2)])
sage: pol = [I.reduce(F.random_element()) for i in range(dim)]
sage: pol
[-3*X2, -39/2*X1 - 1/18*X2, -1/10*X0 - 3*X1 - X2 - 1/5*X3, X2 + 6*X3]
sage: matrix(dim,lambda i,j:pol[i].coefficient(F.gen(j)))
[    0     0    -3     0]
[    0 -39/2 -1/18     0]
[-1/10    -3    -1  -1/5]
[    0     0     1     6]
2012-01-17 10:52:51 +0200 received badge  Taxonomist
2012-01-16 04:31:10 +0200 received badge  Popular Question (source)
2012-01-04 12:57:00 +0200 answered a question Segmentation fault when evaluating 3^3^3^3

Note the order of actions is not the one you would have expected (I think):

sage: ((3^3)^3)^3
7625597484987
sage: 3^(3^(3^3))
---------------------------------------------------------------------------
RuntimeError: exponent must be at most 2147483647
2011-12-21 23:41:52 +0200 received badge  Nice Answer (source)
2011-12-21 17:02:04 +0200 answered a question sqaure root type

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: RR(sqrt(3)) % 1
-0.267949192431123
sage: RR(sqrt(3)).frac()
0.732050807568877

I guess you want the latter. Actually %1 is a bit weird:

sage: [RR((2*k+1)/2)%1 for k in range(10)]
[0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000]
2011-12-21 16:09:29 +0200 commented answer sqaure root type

Did you really use y=x.real_part ? You need y=x.real_part()

2011-12-09 17:20:55 +0200 answered a question Is there a way to save to to animations in the same avi file

This is based on http://www.imagemagick.org/Usage/anim... . Naturally, you need imagemagick installed.

Say you created pic1.gif and pic2.gif, with the same number of frames:

sage: animate([sin(x + float(k)) for k in srange(0,2*pi,0.3)],xmin=0, xmax=2*pi, figsize=[2,1]).save('pic1.gif')
sage: animate([cos(x + float(k)) for k in srange(0,2*pi,0.3)],xmin=0, xmax=2*pi, figsize=[2,1]).save('pic2.gif')

Download and make executable the scripts here and here. Execute the following, changing NUM_FRAMES to the number of frames (21 here, look at the files generated by gif2anim if you are not sure):

gif2anim -c pic1.gif 
gif2anim -c pic2.gif 
for i in `seq -f '%03g' 1 NUM_FRAMES`; do convert pic1_$i.gif pic2_$i.gif -append pic3_$i.gif; done
anim2gif -c -g -b pic3 pic1.anim

You should have pic3.gif with the two animation vertically stacked. If you change -append to +append you get them side by side.