[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-math] newbie type problem
From: |
Martin Rubey |
Subject: |
Re: [Axiom-math] newbie type problem |
Date: |
Mon, 20 Dec 2004 11:45:07 +0100 |
Frank Thieme writes:
> I'm brand new to axiom, trying to solve my homework.
Welcome!
> My idea is to have a function abl(f,x) which simply does n*x^m ->
> n*m*x^(m-1). So I defined:
>
> apl(f,x) == coefficient(f,degree(f,x))*degree(f,x)*x^(degree(f,x)-1)
>
> the same thing works great with maxima (but I can't get any rules defined
> there). But axiom does some error messages when I try abl(x^5,x) but then the
> correct result is displayed 5x^4
>
> When I try abl(x,x) it does not work, abl(5,x) either...
The reason, that abl(x,x) does not work is displayed by axiom:
There are 7 exposed and 5 unexposed library operations named
coefficient having 2 argument(s) but none was determined to be
applicable. Use HyperDoc Browse, or issue
)display op coefficient
to learn more about the available operations. Perhaps
package-calling the operation or using coercions on the arguments
will allow you to apply the operation.
Cannot find a definition or applicable library operation named
coefficient with argument type(s)
Variable x
PositiveInteger
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
So, what does this mean? if you look at the output of
)di op coefficient
axiom will respond with a (long) list of operations called
"coefficient". Usually, you are only interested in the "exposed" operations,
that is, those that are available "directly". (I could expand on this, but I
think for the moment it should be enough)
There are 11 exposed functions called coefficient :
[1] (D,D2) -> D1 from D
if D has AMR(D1,D2) and D2 has OAMON and D1 has RING
[2] (CliffordAlgebra(D3,D1,D4),List PositiveInteger) -> D1
from CliffordAlgebra(D3,D1,D4)
if D1 has FIELD and D3: PI and D4: QFORM(D3,D1)
[3] (D2,D) -> D1 from D
if D has FAMONC(D2,D1) and D2 has SETCAT and D1 has CABMON
[4] (D,D2) -> D1 from D
if D has FMCAT(D1,D2) and D2 has SETCAT and D1 has RING
[5] (D,NonNegativeInteger) -> D1 from D if D has MLO D1 and D1 has
RING
[6] (D,List D4,List NonNegativeInteger) -> D from D
if D has MTSCAT(D3,D4) and D3 has RING and D4 has ORDSET
[7] (D,D1,NonNegativeInteger) -> D from D
if D has MTSCAT(D3,D1) and D3 has RING and D1 has ORDSET
[8] (D,NonNegativeInteger) -> D1 from D
if D has OREPCAT D1 and D1 has RING
[9] (D,List D5,List NonNegativeInteger) -> D from D
if D has POLYCAT(D3,D4,D5) and D3 has RING and D4 has
OAMONS and D5 has ORDSET
[10] (D,D1,NonNegativeInteger) -> D from D
if D has POLYCAT(D3,D4,D1) and D3 has RING and D4 has
OAMONS and D1 has ORDSET
[11] (TaylorSeries D3,NonNegativeInteger) -> Polynomial D3
from TaylorSeries D3 if D3 has RING
Note that they are all different, they take different numbers of arguments, and
the types of those arguments are also different. For example, [11] takes a
(univariate) TaylorSeries over a Ring as first, and a NonNegativeInteger as
second argument.
Your rule gave axiom a "Variable x" as first and a PositiveInteger as second
argument. In the list above, there are seven operations with two arguments:
[1],[2],[3],[4],[5],[8],and [11], but none of them applies.
So, this is the low level reason. The "real", high level reason is: what would
you expect as answer from
coefficient(x*y,1) ?
Surely, you should make your question more precise, by specifying the variable:
coefficient(x*y,x,1).
So, I'd write:
abl(f,x) == coefficient(f,x,degree(f,x))*degree(f,x)*x^(degree(f,x)-1)
or, perhaps better
abl(f:POLY FRAC INT,x:Symbol):POLY FRAC INT ==
coefficient(f,x,degree(f,x))*degree(f,x)*x^(degree(f,x)-1)
This makes sure that the first argument must be a polynomial, guarding against
input like abl(sin(x),x). On the other hand, the second variant won't work with
abl(2.0*x^2,x), whereas the first version does. The "correct" answer to this
problem is to define a package (which has to be put into a file and compiled):
)abbrev package ABL ableitung
ableitung(R:Ring): Exports == Implementation where
Exports == with
abl: (Polynomial R, Symbol) -> Polynomial R
Implementation == add
abl(f,x) ==
d := degree(f,x)
if zero? d
then 0
else coefficient(f,x,d)
*monomial(d::Polynomial R,x,(d-1)::NonNegativeInteger)
There are several things to notice:
* this definition works for any polynomial ring
* we had to check whether the degree of f is zero, because otherwise d-1 might
be -1 and x^(-1) is not a polynomial anymore
* we have to tell the compiler explicitely that d-1 is nonnegative by
(d-1)::NonNegativeInteger
* we had to use the operation "monomial" from the domain "Polynomial R" because
the compiler is not smart enough to understand x^((d-1)::NonNegativeInteger)
* we have to write d::Polynomial R, because d is an integer, and the ring R
could be anything. However, an integer can always be "coerced" into an
element of a ring. Alternatively, we could write d*1. (In this case, the
compiler would be smart enough to understand that 1 comes from the ring)
Martin