Bernstein polynomials



I have some code for the Bernstein polynomials---the code worked for what 
I needed, but I haven't put much time
into it. I might work on the code  and place it in /share or in phpBB 
(already re-spammed).  If somebody has polished 
code for the Bernstein polynomials,  send me a note.

Examples: Nounform when k or n are not explicit integers (unless 
bernstein_explicit is true)

  (%i8) bernstein_poly(k,n,x);
 (%o8) bernstein_poly(k,n,x)

 (%i10) bernstein_poly(k,n,x), bernstein_explicit : true;
 (%o10) binomial(n,k)*(1-x)^(n-k)*x^k

Numerical (via the bigfloat package)

(%i13) bernstein_poly(2,10, 1/2 + %i/3);
(%o13) (19435*%i)/186624-1719575/6718464

(%i14) bernstein_poly(2,10, 0.5b0 + %i/3);
(%o14) 1.041398748285324b-1*%i-2.559476392222983b-1

Calculus

(%i15) diff(bernstein_poly(k,n,x),x);
(%o15) (bernstein_poly(k-1,n-1,x)-bernstein_poly(k,n-1,x))*n

(%i20) integrate(bernstein_poly(k,n,x),x);
(%o20) (hypergeometric([k+1,k-n],[k+2],x)*binomial(n,k)*x^(k+1))/(k+1)

Single and multivariable uniform approximation

(%i22) bernstein_approx(f(x),[x],3);
(%o22) f(1)*x^3+3*f(2/3)*(1-x)*x^2+3*f(1/3)*(1-x)^2*x+f(0)*(1-x)^3

(%i23) bernstein_approx(f(x,y),[x,y],2);
(%o23) 
f(1,1)*x^2*y^2+2*f(1/2,1)*(1-x)*x*y^2+f(0,1)*(1-x)^2*y^2+2*f(1,1/2)*x^2*(1-y)*y+4*f(1/2,1/2)*(1-x)*x*(1-y)*y+2*f(0,1/2)*(1-x)^2*(1-y)*y+f(1,0)*x^2*(1-y)^2+2*f(1/2,0)*(1-x)*x*(1-y)^2+f(0,0)*(1-x)^2*(1-y)^2

Exact expansion of polynomials as linear combinations of Bernstein 
polynomials

(%i26) bernstein_factor(1+x*y,[x,y]);
(%o26) 2*x*y+(1-x)*y+x*(1-y)+(1-x)*(1-y)

(%i27) expand(%);
(%o27) x*y+1

Comments & suggestions are (of course) welcomed.

--Barton