Question: Is there an "easy" way to extend Maple's standard int procedure ?

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?
 

restart;

read("C:\\Users\\Igor\\Maple\\BernsteinPolynomials.mpl");

_m2141342686560

(1)

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

n*BernsteinBasis(k-1, n-1, a, b, x)/(b-a)-n*BernsteinBasis(k, n-1, a, b, x)/(b-a)

(2)

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

2*BernsteinBasis(1, 2, 0, 1, x)+2*x*(2*BernsteinBasis(0, 1, 0, 1, x)-2*BernsteinBasis(1, 1, 0, 1, x))+2*BernsteinBasis(1, 1, 0, 1, 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);

p := 2*BernsteinBasis(0, 1, 0, 1, x)

 

P := Record(Value = Default[value], Variable = x, Degree = 1, Coefficient = coe, Dimension = [1, 1], Basis = BernsteinBasis, BasisParameters = [1, 0, 1], IsMonic = mon, OutputOptions = [shape = [], storage = rectangular, order = Fortran_order, fill = 0, attributes = []])

 

Matrix(%id = 36893490288797933188)

(4)

# Now, integrataion
with(BernsteinPolynomials);

[int]

(5)

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

(1/3)*x^3

(6)

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

"Will be implemented here..."

 

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);

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

Please Wait...