next up previous contents
Next: Bibliography Up: Simple exercises in MAGMA Previous: Plane curves   Contents

Solutions to exercises

Solution 1  
> P<a,t>:=PolynomialRing(Rationals(),2);         
> g:=t^2+t/2+a;
> Derivative(g,t);                               
2*t + 1/2
> Integral(g,t);   
a*t + 1/3*t^3 + 1/4*t^2

Solution 2  
> R := RealField();                
> f := map< R -> R | x :-> Cos(x) >;   
> Integral(f,0,1);   
0.8414709848078965066525023234

Solution 3  
> f := map< Integers() -> R | x :-> 1/2^x >;   
> InfiniteSum(f,1);
10141204801825835211973625643007/10141204801825835211973625643008

for the fractional approximation and

> f := map< Integers() -> R | x :-> (1.0)/2^x >;   
> InfiniteSum(f,1);                             
0.99999999999999999999999999999990139238

for the decimal approximation.

Solution 4  
> S:=[i : i in [-20..20]];
> T:=[j : j in S | j/2 in Integers()];
> T;
[ -20, -18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 
18, 20 ]

Solution 5  
> S:=[i : i in [-20..20]];            
> RS:=Reverse(S);                     
> RS0:=Exclude(RS,0); 
> RS0;
[ 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2,
-3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, 
-20 ]

Solution 6  
> L:=[];
> for x in [1..20] do           
for> L:=Append(L,[x,NextPrime(x)]);
for> end for;
> L;
[
    [ 1, 2 ],
    [ 2, 3 ],
    [ 3, 5 ],
    [ 4, 5 ],
    [ 5, 7 ],
    [ 6, 7 ],
    [ 7, 11 ],
    [ 8, 11 ],
    [ 9, 11 ],
    [ 10, 11 ],
    [ 11, 13 ],
    [ 12, 13 ],
    [ 13, 17 ],
    [ 14, 17 ],
    [ 15, 17 ],
    [ 16, 17 ],
    [ 17, 19 ],
    [ 18, 19 ],
    [ 19, 23 ],
    [ 20, 23 ]
]

Solution 7  
> L:=[];                   
> for x in S do
for> if not(x/2 in Integers()) then
for|if> L:=Append(L,x);
for|if> end if;
for> end for;
> L;
[ -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19
]

Solution 8  
> function whattype(n)
function> if n/2 in Integers() then return "even"; end if;
function> if not(n/2 in Integers()) then return "odd"; end if; 
function> end function;
> whattype(3);
odd
> whattype(10);
even

Solution 9  
> for i:= 1 to 10 do   
for> print i,i^2,"\n";
for> end for;
1 1 

2 4 

3 9 

4 16 

5 25 

6 36 

7 49 

8 64 

9 81 

10 100

This discussion has only given an overview of some of the most basic features of MAGMA. Think of MAGMA as a very large onion and we have only begun to peel off the first layer!

For more details, see the documentation [MAGMA], or the papers [Magma1], [Magma2].



David Joyner 2001-08-22