As a part of my learning curve, I am trying to play with extending Maple's BernsteinBasis, which has only a limited support right now (BernsteinBasis  Maple Help (maplesoft.com)).
My goal is to implement basis operation on polynomials in Bernstein basis, so that derivatives, integrals and products of polynomials in BernsteinBasis would be again expressed in BernsteinBasis.
While it looks like it is relatively easy to extend diff procedure, by using `diff/BernsteinBasis`, I didn't find anything similar for the int. Is there something like `int/BernsteinBasis`?
The problem is that when I am trying to implement my own int procedure in a module that would extend standard int, it seems I need to manually implement logic for (at very least) linearity, so that int(p(x) + q(x), x) would decay into int(p(x), x) + int(q(x), x ) (I probably don't need more complex rewriting rules). So before trying this approach, is there any easy way such as with diff?
> 
read("C:\\Users\\Igor\\Maple\\BernsteinPolynomials.mpl");


(1) 
> 
# General formula
diff(BernsteinBasis(k, n, a, b, x), x);


(2) 
> 
# In expressions
diff(2*x*BernsteinBasis(1, 2, 0, 1, x) + BernsteinBasis(2, 2, 0, 1, x), x);


(3) 
> 
# Convertion to MatrixPolynomialObject works
p := diff(BernsteinBasis(1, 2, 0, 1, x) + BernsteinBasis(2, 2, 0, 1, x), x);
P := convert(p, MatrixPolynomialObject, x);
P:Value(a);


(4) 
# Now, integrataion
with(BernsteinPolynomials);

(5) 
> 
# Still works
int(x^2, x);


(6) 
> 
# Not implemented but will be added later...
int(BernsteinBasis(1, 2, 0, 1, x), x);


(7) 
> 
# This is the problem: how to implement basis properties such as linearity?
int(2 * BernsteinBasis(1, 2, 0, 1, x), x);


(8) 

BernsteinPolynomials := module()
description "Basic operations in Bernstein basis";
option package;
global BernsteinBasis, `diff/BernsteinBasis`;
export int;
BernsteinBasis := proc(k, n, a, b, x)
description "Bernstein basis polynomial";
if k::numeric then
if k < 0 then
return 0;
end if
end if;
if n::numeric then
if n < 0 then
return 0;
end if;
if k::numeric then
if k > n then
return 0;
end if;
end if;
end if;
'procname'(_passed)
end proc;
`diff/BernsteinBasis` := proc()
description "Derivative of the Bernstein basis polynomial in the Bernstein basis";
if _npassed = 6 then
if _passed[1] = _passed[2] then
_passed[2] * BernsteinBasis(_passed[1]  1, _passed[2]  1, _passed[3], _passed[4], _passed[5]) / (_passed[4]  _passed[3]) 
_passed[2] * BernsteinBasis(_passed[1], _passed[2]  1, _passed[3], _passed[4], _passed[5]) / (_passed[4]  _passed[3]);
end if;
end if;
end proc;
int := proc()
description "Integral of the Bernstein basis polynomial in the Bernstein basis";
if type(_passed[1], 'specfunc'(anything, BernsteinBasis)) then
print("Will be implemented here...");
end if;
:int(_passed)
end proc;
end module;
Download bernstein.mw