Question: How to define a linear function?

I ran into a problem with define that I traced to the 'linear' option in the define statement, and I would like to know whether this is my lack of understanding define, or a bug.

I want to define a function called avg(parm) (which I never will need to use explicitly but  I need to be able to manipulate). This function has the property of being linear, and terms not depending on x can be pulled out. Also, avg(parm)=parm unless parm depends on x. (Yes, it stands for a kind of averaging, but that is not relevant here).

So I programmed it in this way:

define(avg,'linear','conditional'(avg(a::algebraic) = a, _type(a, freeof(x))),\
'conditional'(avg(a::(nonunit(algebraic))*b::(nonunit(algebraic))) = a*avg(b), _type(a, freeof(x))));

For the heck of it I could not get it to work. Basically, none of the equations in the definition were ever used, except that constant numeric factors were pulled out, as they should.

Eventually I found that the 'linear' option was the culprit. Once I got rid of that, the definition of avg did what I wanted it to do (like avg(a*x) => a*avg(x); avg(a) => a). The reason a constant numeric factor was pulled out before is because the 'linear' option does that; it never gets to my definitions (one can see that when printing avg).

Am I missing something fundamental here, or is define not working right?

For the record, I did this in Maple 15 on a PPC Mac. I don't have my Maple 2015 handy to test on that version.

Any insights?

Mac Dude

Please Wait...