Opgave 1 -------- > List ListAttributes ListSignatures ListVerbose ListCategories ListTypes > ListTypes; Intrinsic 'ListTypes' Signatures: () List all the categories of Magma. Opgave 2 -------- > x := -11; y := 0; z := 11; > Type(x), Parent(x); RngIntElt Integer Ring Opgave 5 -------- > m := -11 mod 4; > Type(m); RngIntElt Opgave 6 -------- > Type(-12/2); FldRatElt > i := Integers() ! (-12/2); > Type(i); RngIntElt > d := -12 div 2; > d, Type(d); -6 RngIntElt > -13 div 2; -7 Opgave 7 -------- > a := 3.0; > b := RealField() ! 3; > c := RealField() ! (3/1); > a eq b and b eq c; true Opgave 8 -------- > Type(a), Type(b), Type(c); FldReElt FldReElt FldReElt > a, Precision(a); 3.00000000000000000000000000000 30 > b, Precision(b); 3.00000000000000000000000000000 30 > c, Precision(c); 3.00000000000000000000000000000 30 Opgave 9 -------- > pi := Pi(RealField()); > pi^2/4; 2.46740110027233965470862274997 Opgave 10 -------- > Cos(pi/4); 0.707106781186547524400844362105 > Precision($1); 30 > Arccos(1/2); 1.04719755119659774615421446109 > Precision($1); 30 Opgave 11 --------- > e := Exp(1); > e; 2.71828182845904523536028747135 Opgave 12 --------- > Log(e); 0.999999999999999999999999999999 > Log(10, e); 0.434294481903251827651128918916 Opgave 13 --------- > C := ComplexField(); > 3 + j; 3.00000000000000000000000000000 + 1.00000000000000000000000000000*j > Pi(C); 3.14159265358979323846264338328 > Pi(C)/(1+j); 1.57079632679489661923132169164 - 1.57079632679489661923132169164*j Opgave 14 --------- > j, Type(j), Parent(j); 1.00000000000000000000000000000*j FldComElt Complex field of precision 30 Opgave 15 --------- > i, i^2, i^2 eq -1; 1.00000000000000000000000000000*j -1.00000000000000000000000000000 true Opgave 16 --------- > Root; Intrinsic 'Root' Signatures: ( x, n) -> FldComElt ( x, n) -> FldComElt ( x, n) -> FldPrElt ( x, n) -> OFldReElt ( x, n) -> FldReElt The n-th root of x. > Root(7, 2); 2.64575131106459059050161575360 > Iroot(7, 2); 2 > Sqrt(7); 2.64575131106459059050161575364 > Isqrt(7); 2 Opgave 17 --------- > 5 lt 4 eq not true; true Opgave 18 --------- > Type(true); BoolElt Opgave 19 --------- > print "welkom bij Magma!"; welkom bij Magma! > "welkom bij Magma!"; welkom bij Magma! Opgave 20 --------- > "\"Hartelijk welkom\"\n\t nieuwe Magmagebruiker"; "Hartelijk welkom" nieuwe Magmagebruiker Opgave 21 --------- > ("73" * "9" * "42" eq "7" * "3942") eq (73 * 9 * 42 eq 7* 3942); true > ("73" * "9" * "41" eq "7" * "3941") eq (73 * 9 * 42 eq 7* 3941); false > > 73 * 9 * 42, 7* 3942; 27594 27594 > 73 * 9 * 41, 7* 3941; 26937 27587 Opgave 22 --------- > Factorization(1155/7); >> Factorization(1155/7); ^ Runtime error in 'Factorization': Bad argument types Argument types given: FldRatElt > Factorization( Integers() ! (1155/7)); [ <3, 1>, <5, 1>, <11, 1> ] Opgave 23 --------- > RealField() ! Factorial(5); 120 Opgave 24 --------- > drie := {1, 1/2, 1.0}; > #drie; 2 > Universe(drie); Real Field Opgave 25 --------- > { p : p in [2..1003] | (p mod 8 eq 5) and IsPrime(p) }; { 5, 13, 29, 37, 53, 61, 101, 109, 149, 157, 173, 181, 197, 229, 269, 277, 293, 317, 349, 373, 389, 397, 421, 461, 509, 541, 557, 613, 653, 661, 677, 701, 709, 733, 757, 773, 797, 821, 829, 853, 877, 941, 997 } Opgave 26 --------- > #{ p : p in [2..10000] | IsPrime(p) }; 1229 > time #{ p : p in [2..10^6] | IsPrime(p) }; 78498 Time: 2.440 Opgave 27 --------- > { g : g in [100..200] | g mod 11 eq 0 }; { 110, 121, 132, 143, 154, 165, 176, 187, 198 } > { g : g in [110..200 by 11] | g mod 11 eq 0 }; { 110, 121, 132, 143, 154, 165, 176, 187, 198 } Opgave 28 --------- > { g : g in [501..600 by 2] | (g mod 7 ne 0) and (g mod 11 eq 0 or g mod 13 e\ q 0) }; { 507, 517, 533, 559, 561, 583, 585 } Opgave 29 --------- > #{ x^2 + y^2 : x in [1..10 by 2], y in [0..10 by 2] }; 27 > #{ s : s in S | #[ [x,y] : x in [1..10 by 2], y in [0..10 by 2] | x^2 + y^2 \ eq s ] gt 1 }; 3 > {* x^2 + y^2 : x in [1..10 by 2], y in [0..10 by 2] *}; {* 29, 145, 1, 117, 89, 61, 149, 5, 65^^2, 181, 37, 9, 125, 97, 41, 13, 101, 73,45, 17, 49, 109, 81, 53, 25^^2, 113, 85^^2 *} Opgave 30 --------- > #{ PrimeBasis(n) : n in [1..1000] }/1000; 76/125 > $1 * 1.0; 0.60799999999999999999999999999 Opgave 31 --------- > s := [1, 2]; Append(~s, 3); s[#s+2] := 5; s[#s+2] := 8; s; > > s; [ 1, 2, 3, undef, 5, undef, 8 ] Opgave 32 --------- > {1,2,3,4} eq {1,3,2,4}; true > [1,2,3,4] eq [1,3,2,4]; false Opgave 33 --------- > Q := [ q : q in [ p : p in [2..1000] | IsPrime(p) ] | IsPrime(q-4) or IsPrime(q+4) ]; > Q; [ 2, 3, 7, 11, 13, 17, 19, 23, 37, 41, 43, 47, 67, 71, 79, 83, 97, 101, 103, 107, 109, 113, 127, 131, 163, 167, 193, 197, 223, 227, 229, 233, 277, 281, 307, 311, 313, 317, 349, 353, 379, 383, 397, 401, 439, 443, 457, 461, 463, 467, 487, 491, 499, 503, 613, 617, 643, 647, 673, 677, 739, 743, 757, 761, 769, 773, 823, 827, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 937, 941, 967, 971 ] > {863, 911} subset Q; true > IsSubsequence([863, 911], Q); false Opgave 34 --------- > L := [ q mod 10 : q in Q ]; > L; [ 2, 3, 7, 1, 3, 7, 9, 3, 7, 1, 3, 7, 7, 1, 9, 3, 7, 1, 3, 7, 9, 3, 7, 1, 3, 7, 3, 7, 3, 7, 9, 3, 7, 1, 7, 1, 3, 7, 9, 3, 9, 3, 7, 1, 9, 3, 7, 1, 3, 7, 7, 1, 9,3, 3, 7, 3, 7, 3, 7, 9, 3, 7, 1, 9, 3, 3, 7, 3, 7, 9, 3, 7, 1, 3, 7, 7, 1, 7, 1,7, 1 ] > Ltel := [ [ c, #[ l : l in L | l eq c ] ] : c in Seqset(L) ]; > Ltel; [ [ 1, 15 ], [ 2, 1 ], [ 3, 26 ], [ 7, 29 ], [ 9, 11 ] ] Opgave 35 --------- slecht geformuleerde opgave. Misschien zoiets: > q := NextPrime(12345); > { p : p in [ 1 .. (q-1) div 2] | IsPrime(p) and (q-1) mod p eq 0 }; { 2, 6173 } Opgave 36 --------- > S := { n : n in [1..10000] | DivisorSigma(0, n) eq 48 }; > S; { 2520, 3360, 3780, 3960, 4200, 4320, 4620, 4680, 5280, 5400, 5460, 5544, 5760, 5880, 5940, 6048, 6120, 6240, 6552, 6600, 6840, 6930, 7020, 7140, 7392, 7800, 7980, 8064, 8160, 8190, 8280, 8316, 8568, 8580, 8736, 9000, 9120, 9180, 9450, 9504, 9576, 9600, 9660, 9720, 9828 } > { s : s in S | #PrimeBasis(s) eq 3 }; { 4320, 5400, 5760, 6048, 8064, 9000, 9504, 9600, 9720 } ter vergelijking: > time S meet { m : m in [1..10000] | #PrimeBasis(m) eq 3 }; { 4320, 5400, 5760, 6048, 8064, 9000, 9504, 9600, 9720 } Time: 0.480 > time { s : s in S | #PrimeBasis(s) eq 3 }; { 4320, 5400, 5760, 6048, 8064, 9000, 9504, 9600, 9720 } Time: 0.000 Opgave 37 --------- > R := [ 1, 1]; > Setseq(Seqset(R)); [ 1 ] Opgave 38 --------- > C := { x : x in CartesianProduct([-10..10], [-10..10]) | not IsZero(x[2]) an\ d x[1]/x[2] ne 1 }; > #C; 400 Opgave 39 --------- > for x in [ p : p in [50..150] | IsPrime(p) ] do for> printf "%3o", x; for> end for; 53 59 61 67 71 73 79 83 89 97101103107109113127131137139149 Opgave 40 --------- > t := []; > t[3] := 7; > t; [ undef, undef, 7 ] > t[1]; >> t[1]; ^ Runtime error in '[]': Sequence element 1 not defined > #t; 3 Opgave 41 --------- > &*[ (n^3-1)/(n^2-1) : n in { p*q : p,q in [ r : r in [2..50] | IsPrime(r) ] \ | p*q lt 100 } ]; 7008971620785554094398491535714232666857387802418797908384744553787860638656176\ 259096702699/6028903054168650608227123200000000000 Opgave 42 --------- > P2 := { p*q : p,q in [ r : r in [2..50] | IsPrime(r) ] \ > | p*q lt 100 } ; > prod := 1; > for n in P2 do for> prod *:= (n^3-1)/(n^2-1); for> end for; > prod; 7008971620785554094398491535714232666857387802418797908384744553787860638656176\259096702699/6028903054168650608227123200000000000 Opgave 43 --------- Opgave 44 --------- > Sign(0.01); 1 Opgave 45 --------- > x := Random([-1,0,1])*Sqrt(11); -3.316624790355399849114932736659 > (x ge 0) select ((x gt 0) select 1 else 0) else -1; Opgave 46 --------- > sign := func< x | (x ge 0) select ((x gt 0) select 1 else 0) else -1>; Opgave 47 --------- > fib := function(n) function> if n in [1,2] then return 1; function|if> else return $$(n-1) + $$(n-2); function|if> end if; function> end function; heel inefficient! Opgave 48 --------- > [ n in [1,2] select 1 else Self(n-1) + Self(n-2) : n in [1..100] ];