Another (major) difference with MAPLE is that MAGMA
does not like undefined variables. It is fair to say that
MAGMA can't stand the sight of an undefined variable.
For example, in MAPLE, you can type (without declaring
)
>f:=x^2; then >diff(f,x); (resp, >int(f,x);)
and you will get the derivative (resp., anti-derivavtive)
of
. However, MAGMA will complain:
> f:=x^2;
>> f:=x^2;
^
User error: Identifier 'x' has not been declared or assigned
Instead, you must declare
first, by typing something like
> P<x>:=PolynomialRing(Integers());
> f:=x^2;
> Derivative(f);
2*x
> Integral(f) ;
>> Integral(f) ;
^
Runtime error in 'Integral': Coefficient ring of argument 1 is not a field
This says, MAGMA will differentiate
> P<x>:=PolynomialRing(Rationals()); > f:=x^2; > Evaluate(f,3/2); 9/4 > Integral(f) ; 1/3*x^3
You can also do numerical integration of an improper integral:
> R := RealField();
> f := map< R -> R | x :-> x^2 >;
> Integral(f, 0, 1);
0.3333333333333333333333333331
> h:= map< R -> R | x :-> Sin(x)/x >;
> h(1/2);
0.9588510772084060005465758704
> h(0);
???(
x: 0
)
>> h:= map< R -> R | x :-> Sin(x)/x >;
^
Runtime error in '/': Division by zero
> Integral(h, 0, 1: Al := "Open");
0.9460830703671830149413533089
Here ``Open'' chooses a certain subroutine to
compute
There are also routines for infinite sums but I have not gotten some of them to work:
> g := map< Integers() -> R | x :-> 1/x^2 >; > InfiniteSum(g,1); [Interrupted] > PositiveSum(g,1); 1.644934066848226436472415163 > g2 := map< Integers() -> R | m :-> (-1)^m/(m^2+1) >; > AlternatingSum(g2,1); -0.3639854725089334185248817081 > g3 := map< Integers() -> R | m :-> (-1)^m/Exp(m) >; > InfiniteSum(g3,1); -0.268941421369995120748840758179095161053748348253
The interuption was after about 1 minute (on a 350Mhz pentium). This is probably because the series is slowly converging and MAGMA will compute the result to the default precision. However, MAGMA returned the PositiveSum(g,1); and AlternatingSum(g2,1); commands instantly.