L-3 MCS 320 Friday 26 August 2005
| > | restart; |
1. Integer and Rational Numbers
| > | n1 := (3^4)^5; |
| > | n2 := 3^(4^5); |
![]()
![]()
![]()
![]()
| > | md := kernelopts(maxdigits); |
| > | huge := 10^md: |
Error, Cannot reallocate memory (old_size=224 new_size=113246220)
| > | ?maxdigits; |
For very large numbers, Maple uses the GNU multiple precision library. Of course, memory consumption is one of the big problems in computer algebra.
Important numbers are prime numbers:
| > | n := 2^301-1; |
| > | isprime(n); |
| > | n1 := nextprime(n); |
| > | isprime(n1); |
Factoring a number as a product of primes is very hard. But detecting whether a number is prime is easier.
| > | n2 := nextprime(n1); |
| > | a := n1*n2; |
![]()
| > | ifactor(a); |
Warning, computation interrupted
| > | isprime(a); |
Maple simplifies automatically the rational numbers:
| > | b := 1234/2480; # 2 is certainly a divisor |
| > | gcd(numer(b),denom(b)); |
The simplification is done by dividing numerator and denominator by the greatest common divisor.
2. Irrational and Floating-Point Numbers
We know already that Maple is case sensitive, so we write Pi and not pi:
| > | evalf(Pi); |
The number of decimal places excludes the leading zeros:
| > | evalf(Pi/10^80); # scientific notation |
| > | evalf(Pi/1000); # writes the leading zeros |
Roots are another application where floating-point and approximate arithmetic is used:
| > | r := 5^(1/3); |
| > | approximate_r := evalf(r); |
| > | approximate_r^3; |
The error on the approximate root is of the magnitude the working precision (which is by default 10 decimal places).
The first way to extend the precision is via evalf:
| > | r30 := evalf(r,30); |
This is just executed locally:
| > | r30^3; |
To make the power work out more accurately, we also need
| > | evalf[30](r30^3); # other way of 30 decimal places arithmetic |
| > | evalf(5-%,40); |
Doing this globally inside a worksheet is by assigning to Digits:
| > | Digits := 20; |
| > | evalf(r30^3); |
| > | %-5; |
The third way is to use the File/Preferences.
The evalf is software driven floating-point arithmetic which is typically a magnitude slower than the machine arithmetic.
| > | Digits := 10; |
| > | evalhf(r30); # evaluates using the double float |
| > | evalhf(Digits); |
| > | ?UseHardwareFloats; |
| > | UseHardwareFloats := true; # request always hardware floats |
| > | evalf(r); # still displays 10 decimal places |
| > | evalf(r30^3); # also calculates with 10 decimal places ... |