Opened 14 years ago

Closed 14 years ago

# [with patch, positive review] make bernoulli_polynomial independent of maxima

Reported by: Owned by: was craigcitro major sage-3.3 calculus mhansen

### Description

I wanted to verify that Sage could symbolically compute the derivative of Bn(x), the nth Bernoulli polynomial in (x): Dx[Bn(x)]=n*Bn-1(x). The following code causes Sage to lockup:

```Bn = bernoulli_polynomial(x,n)
```

The command "bernpoly(x,n)" in Maxima does not lock up but Maxima will not compute symbolically.

```sage: B3 = bernoulli_polynomial(x,3)
sage: B4 = bernoulli_polynomial(x,4)
sage: DxB4 = diff(B4,x)
sage: print expand(DxB4-4*B3)
0
sage: Bn = bernoulli_polynomial(x,n)
Traceback (most recent call last):
...
KeyboardInterrupt
>>>
>>>
```

### comment:1 Changed 14 years ago by was

• Summary changed from bug in bernoulli_polynomial to bug in bernoulli_polynomial (possibly invalid?)

I forgot to define (n) as a variable in the above session. Now, Sage does not lockup but instead gives the traceback.

```var('y,x,n')
y = bernoulli_polynomial(x,n)

Exception (click to the left for traceback):
...
NameError: name 'bernpoly' is not defined

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/server2/sage_notebook/worksheets/5463/24/code/18.py",
line 7, in <module>
y = bernoulli_polynomial(x,n)
File "/usr/local/sage/local/lib/python2.5/site-packages/sympy/
plotting/", line 1, in <module>

File "/usr/local/sage/local/lib/python2.5/site-packages/sage/
combinat/combinat.py", line 1806, in bernoulli_polynomial
return sage_eval(maxima.eval("bernpoly(x,%s)"%n), {'x':x})
File "/usr/local/sage/local/lib/python2.5/site-packages/sage/misc/
sage_eval.py", line 110, in sage_eval
return eval(p, sage.all.__dict__, locals)
File "<string>", line 1, in <module>
NameError: name 'bernpoly' is not defined
```

### comment:2 Changed 14 years ago by mabshoff

Since combinat.py is involved I am CCind Mike Hansen :)

Cheers,

Michael

### comment:3 Changed 14 years ago by mabshoff

• Summary changed from bug in bernoulli_polynomial (possibly invalid?) to bug in bernoulli_polynomial

Oh, and definitely not invalid.

Cheers,

Michael

### comment:4 Changed 14 years ago by craigcitro

• Owner changed from was to craigcitro
• Status changed from new to assigned
• Summary changed from bug in bernoulli_polynomial to [with patch, needs review] make bernoulli_polynomial independent of maxima

The attached patch rewrites `bernoulli_polynomial` to avoid Maxima completely. This gives roughly a factor of 10 speedup.

Unfortunately, the originial request doesn't quite make sense -- `bernoulli_polynomial(x,n)` for `n` a symbolic variable would have to return a polynomial of variable degree. As it stands, we don't have any sort of "symbolic sum" to use for that kind of thing. I did add the formula for the `n`th Bernoulli polynomial to the docstring, though.

### comment:5 Changed 14 years ago by was

• Summary changed from [with patch, needs review] make bernoulli_polynomial independent of maxima to [with patch, positive review] make bernoulli_polynomial independent of maxima

positive review;

it could be optimized by using horner's rule

### comment:6 Changed 14 years ago by mabshoff

• Milestone changed from sage-3.4.1 to sage-3.3
• Resolution set to fixed
• Status changed from assigned to closed

Merged in Sage 3.3.alpha1

Note: See TracTickets for help on using tickets.