@menu
* Functions and Variables for Bernstein::
@end menu

@node Functions and Variables for Bernstein,  , Bernstein-pkg, Bernstein-pkg
@section Functions and Variables for Bernstein

@anchor{bernstein_poly}
@deffn {Function} bernstein_poly (@var{k}, @var{n}, @var{x})

Provided @code{k} is not a negative integer, the Bernstein polynomials
are defined by @code{bernstein_poly(k,n,x) = binomial(n,k) x^k
(1-x)^(n-k)}; for a negative integer @code{k}, the Bernstein polynomial
@code{bernstein_poly(k,n,x)} vanishes.  When either @code{k} or @code{n} are
non integers, the option variable @code{bernstein_explicit}
controls the expansion of the Bernstein polynomials into its explicit form;
example:

@example
(%i1) load("bernstein")$

(%i2) bernstein_poly(k,n,x);
(%o2)                bernstein_poly(k, n, x)
(%i3) bernstein_poly(k,n,x), bernstein_explicit : true;
                                       n - k  k
(%o3)            binomial(n, k) (1 - x)      x
@end example

The Bernstein polynomials have both a gradef property and an integrate property:

@example
(%i4) diff(bernstein_poly(k,n,x),x);
(%o4) (bernstein_poly(k - 1, n - 1, x)
                                 - bernstein_poly(k, n - 1, x)) n
(%i5) integrate(bernstein_poly(k,n,x),x);
(%o5) 
                                                            k + 1
 hypergeometric([k + 1, k - n], [k + 2], x) binomial(n, k) x
 ----------------------------------------------------------------
                              k + 1
@end example

For numeric inputs, both real and complex, the Bernstein polynomials evaluate
to a numeric result:

@example
(%i6) bernstein_poly(5,9, 1/2 + %i);
                        39375 %i   39375
(%o6)                   -------- + -----
                          128       256
(%i7) bernstein_poly(5,9, 0.5b0 + %i);
(%o7)           3.076171875b2 %i + 1.5380859375b2
@end example

To use @code{bernstein_poly}, first @code{load("bernstein")}.

@end deffn


@anchor{bernstein_explicit}
@defvr {Variable} bernstein_explicit
Default value: @code{false}

When either @code{k} or @code{n} are non integers, the option variable 
@code{bernstein_explicit} controls the expansion of @code{bernstein(k,n,x)} 
into its explicit form; example:

@example
(%i1) bernstein_poly(k,n,x);
(%o1)                bernstein_poly(k, n, x)
(%i2) bernstein_poly(k,n,x), bernstein_explicit : true;
                                       n - k  k
(%o2)            binomial(n, k) (1 - x)      x
@end example
When both @code{k} and @code{n} are explicitly integers, @code{bernstein(k,n,x)} 
@emph{always} expands to its explicit form.

@end defvr


@anchor{multibernstein_poly}
@deffn {Function} multibernstein_poly (@var{[k1,k2,@dots{}, kp]}, @var{[n1,n2,@dots{}, np]}, @var{[x1,x2,@dots{}, xp]})

The multibernstein polynomial @code{multibernstein_poly (@var{[k1, k2, ..., 
kp]}, @var{[n1, n2, ..., np]}, @var{[x1, x2, ..., xp]})} is the product of
bernstein polynomials @code{bernstein_poly(k1, n1, x1)
bernstein_poly(k2, n2, x2) ... bernstein_poly(kp, np, xp)}.

To use @code{multibernstein_poly}, first @code{load("bernstein")}.

@end deffn

@anchor{bernstein_approx}
@deffn {Function} bernstein_approx (@var{f}, @var{[x1, x1, @dots{}, xn]}, n)

Return the @code{n}-th order uniform Bernstein polynomial approximation for the
function @code{(x1, x2, ..., xn) |--> f}.
Examples

@example
(%i1) bernstein_approx(f(x),[x], 2);
                 2       1                          2
(%o1)      f(1) x  + 2 f(-) (1 - x) x + f(0) (1 - x)
                         2
(%i2) bernstein_approx(f(x,y),[x,y], 2);
               2  2       1                2
(%o2) f(1, 1) x  y  + 2 f(-, 1) (1 - x) x y
                          2
                  2  2          1   2
 + f(0, 1) (1 - x)  y  + 2 f(1, -) x  (1 - y) y
                                2
       1  1                               1         2
 + 4 f(-, -) (1 - x) x (1 - y) y + 2 f(0, -) (1 - x)  (1 - y) y
       2  2                               2
            2        2       1                      2
 + f(1, 0) x  (1 - y)  + 2 f(-, 0) (1 - x) x (1 - y)
                             2
                  2        2
 + f(0, 0) (1 - x)  (1 - y)
@end example

To use @code{bernstein_approx}, first @code{load("bernstein")}.

@end deffn

@anchor{bernstein_expand}
@deffn {Function} bernstein_expand (@var{e}, @var{[x1, x1, @dots{}, xn]})

Express the @emph{polynomial} @code{e} exactly as a linear combination of multi-variable
Bernstein polynomials.

@example
(%i1) bernstein_expand(x*y+1,[x,y]);
(%o1)    2 x y + (1 - x) y + x (1 - y) + (1 - x) (1 - y)
(%i2) expand(%);
(%o2)                        x y + 1
@end example

Maxima signals an error when the first argument isn't a polynomial.

To use @code{bernstein_expand}, first @code{load("bernstein")}.

@end deffn

