Ask Your Question

petropolis's profile - activity

2025-09-03 01:19:38 +0100 received badge ● Famous Question (source)
2025-04-09 04:08:14 +0100 received badge ● Notable Question (source)
2025-04-09 04:08:14 +0100 received badge ● Famous Question (source)
2023-05-11 18:53:57 +0100 received badge ● Famous Question (source)
2022-05-19 18:10:01 +0100 received badge ● Popular Question (source)
2022-05-19 18:10:01 +0100 received badge ● Notable Question (source)
2022-01-29 18:13:19 +0100 received badge ● Popular Question (source)
2022-01-29 18:13:19 +0100 received badge ● Notable Question (source)
2021-08-07 00:20:41 +0100 received badge ● Notable Question (source)
2021-07-15 08:39:31 +0100 received badge ● Famous Question (source)
2021-07-15 08:39:31 +0100 received badge ● Popular Question (source)
2021-07-15 08:39:31 +0100 received badge ● Notable Question (source)
2021-07-15 08:34:14 +0100 received badge ● Famous Question (source)
2020-08-01 17:26:59 +0100 received badge ● Notable Question (source)
2020-08-01 17:26:59 +0100 received badge ● Popular Question (source)
2020-04-21 16:17:42 +0100 received badge ● Famous Question (source)
2020-02-11 21:29:52 +0100 received badge ● Notable Question (source)
2019-12-23 16:13:23 +0100 received badge ● Notable Question (source)
2019-08-10 15:31:34 +0100 received badge ● Famous Question (source)
2019-04-18 19:58:42 +0100 received badge ● Notable Question (source)
2018-11-16 12:39:01 +0100 received badge ● Notable Question (source)
2018-09-04 13:32:47 +0100 received badge ● Popular Question (source)
2018-05-02 23:41:20 +0100 received badge ● Popular Question (source)
2018-04-10 13:18:02 +0100 received badge ● Good Answer (source)
2018-04-10 13:18:02 +0100 received badge ● Enlightened (source)
2018-03-19 15:15:04 +0100 received badge ● Notable Question (source)
2018-03-19 15:15:04 +0100 received badge ● Popular Question (source)
2018-02-07 14:07:17 +0100 received badge ● Famous Question (source)
2018-01-24 22:26:27 +0100 received badge ● Notable Question (source)
2017-07-08 09:10:02 +0100 received badge ● Popular Question (source)
2017-05-27 12:43:24 +0100 received badge ● Popular Question (source)
2016-11-14 23:29:54 +0100 received badge ● Notable Question (source)
2016-07-10 05:14:05 +0100 received badge ● Famous Question (source)
2016-04-08 05:41:27 +0100 received badge ● Notable Question (source)
2016-04-01 21:04:11 +0100 received badge ● Popular Question (source)
2016-01-09 15:18:34 +0100 received badge ● Famous Question (source)
2015-10-26 21:11:06 +0100 received badge ● Taxonomist
2015-08-06 21:53:02 +0100 received badge ● Popular Question (source)
2015-06-07 15:37:25 +0100 received badge ● Famous Question (source)
2015-04-08 00:55:57 +0100 received badge ● Popular Question (source)
2015-03-27 04:12:18 +0100 marked best answer How to get Sage 5.4 working under the VM VirtualBox?

I installed the Sage virtual machine 5.4 today. After booting things look as described here http://wiki.sagemath.org/SageAppliance at 3.3. I can use Sage directly from there.

However, I want to use http://localhost:8000. This works, but this time I see a window like the one here: http://www.sagenb.org/ and I do not succeed to log in. What is the username and the password?

(With Sage 5.0 I did not have this problem, things looked the same either way.)

2015-03-27 04:12:09 +0100 marked best answer How to format huge reals?
print '{0:.3e}'.format(float(2.23799235765712699))
print '{0:.3e}'.format(float(2.23799235765712699e47675))

gives

2.238e+00
inf

Clearly what I want in the second case is 2.238e+47675.

How can I achieve this?

2015-03-27 04:12:06 +0100 marked best answer How to publish a worksheet in the sage doc format?

By the 'sage doc format' I mean a html page like this one: http://www.sagemath.org/doc/reference...

2015-03-27 04:12:06 +0100 marked best answer Simplification of boolean values
def F(n) : 
    return exp(log(n))

def test1(n) :
    return n == F(n)

[test1(i) for i in (4..8)]

gives [4 == 4, 5 == 5, 6 == 6, 7 == 7, 8 == 8]

def G(n) : 
    return n

def test2(n) :
    return n == G(n)

[test2(i) for i in (4..8)]

gives [True, True, True, True, True]

What do I have to do so that test1 gives the same result as test2?

2015-03-27 04:12:06 +0100 marked best answer Coefficients of a constant polynomial

If have a list A of polynomials in x and y and want the coefficients of x. Here is what I do:

var('y')

A = [x, y, xy + 3y^2]

for p in A : print p.coefficients(x)

And here is what I get:

[[1, 1]]

[[y, 0]]

[[3*y^2, 0], [y, 1]]

That's fine. My next list to process is

B = [1, x, y, xy + 3y^2]

And here is what I get:

AttributeError: 'sage.rings.integer.Integer' object has no attribute 'coefficients'.

I expected the answer 0 as the coefficient of x of the polynomial p(x, y) = 1 is 0.

How do I get around this behavior of Sage?

2015-03-27 04:12:05 +0100 marked best answer How to expand an symbolic expression.

With Maple I can write

T := proc(f,n,x) 
local v; 
add(binomial(n,v)*f(v+1)*(x)^v,v=0..n) 
end:

and then

T(f,4,x)

will give me the answer

f(1)+4*f(2)*x+6*f(3)*x^2+4*f(4)*x^3+f(5)*x^4.

If I write the same with Sage

def T(f,n,x): 
    return add(binomial(n,v)*f(v+1)*(x)^v for v in (0..n))
var('f')
T(f,4,x)

then I will get the answer

5*x^4 + 16*x^3 + 18*x^2 + 8*x + 1.

How do I have to proceed to get Maple's answer?

2015-03-27 04:09:04 +0100 marked best answer Hadamard product for the Riemann zeta function

What is the best way to compute numerically with Sage the product over the first n nontrivial zeros of the Riemann zeta function?

p(s,n) = product((1-s/rho(k))*exp(s/rho(k)) for k in (1..n))

where zeta(rho(k)) == 0 and Im(rho(k)) != 0.

Wikipedia advises: "To ensure convergence the product should be taken over 'matching pairs' of zeroes, i.e. the factors for a pair of zeroes of the form rho(k) and 1-rho(k) should be combined."

Hadamard product on MathWorld

2015-03-27 04:08:51 +0100 marked best answer Problem with infinite sum

With Maple everything is so simple.

R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...

With Sage that's another story.

def R(n):
    var('k')
    return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)

[R(i) for i in (1..5)]

TypeError: unable to convert x (=2*k) to an integer. What do I miss?

EDIT with errors deleted.

2015-03-27 04:08:43 +0100 marked best answer Maple versus Sage, porting issues

Consider the expression

if (m == 3) or (m == -3) : print n, m

Could a simple minded programmer ever expect to see an output different from n, 3 or n, -3 for some n?

No, because it is /verboten/ by logic that m can have a different value from 3 or -3!

Let's check it nevertheless with Maple:

for n from 0 to 50 do 
    m := n mod 8: 
    if (m = 3) or (m = -3) then print(n, m) fi od:

  3, 3
 11, 3
 19, 3
 27, 3
 35, 3
 43, 3

And now the same with Sage.

for n in (0..50):
    m = mod(n, 8) 
    if (m == 3) or (m == -3) : print n, m

  3 3
  5 5
 11 3
 13 5
 19 3
 21 5
 27 3
 29 5
 35 3
 37 5
 43 3
 45 5

How many simple minded Maple programmers have broken their necks with such alike?

Could someone please point to a page in the Sage documentation where this is explained and due warnings are given, if such a page exists?

2015-03-27 04:08:37 +0100 marked best answer Type error in recursion

Consider the following function:

def f(n) :
    def retfunc(x) : 
        return 1 if n == 0 else x*add(f(n-k) for k in (1..n))
    return retfunc

The test

w = f(9); print w, type(w)

gives

"function retfunc at 0x43d3de8" "type 'function'" 

which looks fine to me. However an evaluation w(3) gives

TypeError: unsupported operand type(s) for +: 'int' and 'function'

How can I get around this error?

EDIT: One solution is, as indicated by DSM,

def f(n):
    retfunc(x) = 1 if n == 0 else add(x*f(n-k) for k in (1..n))
    return retfunc

What I am trying to do here? Let's see:

for i in [1..8] : [c[0] for c in expand(f(i)(x)).coeffs()]
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]
[1, 6, 15, 20, 15, 6, 1]
[1, 7, 21, 35, 35, 21, 7, 1]