# Why can't the Bernstein Bears work normally?

Bug introduced in 7.0 and fixed in 9.0

I want to use the built-in BernsteinBasis[] to learn about Bezier curves. I tried the following code:

Plot[Evaluate @ Table[D[BernsteinBasis[3, k, u], u], {k, 0, 3}], {u, 0, 1}]


I tried many workrounds. Finally, I added PiecewiseExpand[] before BernsteinBasis[], then it works well.

Plot[Evaluate @
Table[D[PiecewiseExpand @ BernsteinBasis[3, k, u], u],
{k, 0, 3}], {u, 0, 1}]


Bug fixed

• Evaluated->True does the trick. You may search this site about it. Plot[Table[D[BernsteinBasis[3, k, u], u], {k, 0, 3}], {u, 0, 1}, Evaluated -> True] Sep 29, 2014 at 3:41
• @belisarius, In V8,Plot[Table[D[BernsteinBasis[3, k, u], u], {k, 0, 3}], {u, 0, 1}, Evaluated -> True] cannot give the result as OP shown.
– user8336
Sep 29, 2014 at 5:20
• This is version/system dependent. In v10.0.1 on a Mac, original input works fine without Evaluated -> True or PiecewiseExpand. Sep 29, 2014 at 5:34
• I have no answer to this, but I wanted to comment that out of the corner of my eye I thought the question was "Why can't the Berenstain Bears work normally", which you must admit is pretty intriguing. Apr 15, 2016 at 16:15
• I'm sorry, you've misspelt Berenstain.
– user484
Apr 16, 2016 at 2:33

The problem in V8.0.4 is that

D[BernsteinBasis[3, 0, u], u]


evaluates as

3 (BernsteinBasis[2, -1, u] - BernsteinBasis[2, 0, u])


A negative second argument is disallowed. The problem (i.e., bug) is that the general rule

D[BernsteinBasis[3, k, u], u]
(* 3 (BernsteinBasis[2, -1 + k, u] - BernsteinBasis[2, k, u]) *)


is applied when it is incorrect (e.g., for k == 0 and k == 3).

This is fixed in V9 and V10.

It is interesting, if inexplicable, that it is accounted for when applying PiecewiseExpand to the result of the differentiation in V8.0.4:

PiecewiseExpand@D[BernsteinBasis[3, k, u], u]