Happens to work for me, in 2013a, but I think that is not the point, as that is probably coincidental for this particular example.
The problem with the _mult method you defined is that when you overload a function like _mult in MuPAD, you're actually responsible for the full multiplication, not just that of two arguments. I.e., in your last call, Bx::_mult is called with four arguments: 6, Bx(5,4), 3, Bx(4,3). It has to handle that, since MuPAD doesn't know whether you even want things like commutativity with numbers.
Here's what I think the structure you'll want could look like:
Bx::mult2 := proc(a : Bx, b : Bx)
...
end_proc:
Bx::multBx := proc() // multiply arbitrarily many Bx
local n, left, right;
begin
case args(0)
of 0 do return(1);
of 1 do return(args(1));
of 2 do return(Bx::mult2(args()));
otherwise
n := floor(args(0)/2);
left := Bx::multBx(args(1..n));
right := Bs::multBx(args(n+1..args(0)));
return(Bx::mult2(left, right));
end_case;
end_proc:
Bx::_mult := proc()
local Bxes, others, dummy;
begin
[Bxes, others, dummy] := split([args()], testtype, Bx);
assert(dummy = []);
others := _mult(op(others));
Bxes := Bx::multBx(op(Bxes));
if others = 1 then
return(Bxes);
elif Bxes = 1 then
return(others);
else
return(hold(_mult)(Bxes, others));
end_if;
end_proc:
Best Answer