Goto Chapter: Top 1 2 Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

1 Decimal Approximations of Cylotomic Numbers
 1.1 Complex Numbers
 1.2 Decimal Approximations of Real Numbers

1 Decimal Approximations of Cylotomic Numbers

The FUtil package provides some functionality for computing with fixed point approximations of real numbers. The main motivation is the question of deciding if a real cyclotomic number in GAP is positive, see the function HasPositiveRealPartCyc (1.2-6).

The idea for this functionalty comes from the deposited contribution decimal.g provided by Jean Michel for GAP 3. As an enhancement the FUtil package implements an interval arithmetic with the approximate numbers, such that a comparison function as TruelyLessDecimal (1.2-5) can be implemented.

The package also provides the function ComplexNumber (1.1-2) which creates objects which have a real and imaginary part and add and multiply like complex numbers.

1.1 Complex Numbers

1.1-1 IsComplexNumber
‣ IsComplexNumber( c )( filter )

Returns: true or false.

‣ RealPart( c )( attribute )
‣ ImaginaryPart( c )( attribute )

Returns: ring elements.

IsComplexNumber returns true for additive and multiplicative elements c which have the attributes RealPart and ImaginaryPart and are added and multiplied like complex numbers.

The real and imaginary parts themselves can be any ring elements like real cyclotomic numbers, but also decimal approximations of numbers, polynomials or others.

1.1-2 ComplexNumber
‣ ComplexNumber( re, im )( operation )
‣ ComplexNumber( c )( method )

Returns: an object in IsComplexNumber (1.1-1).

In the first general form this operation returns an object a such that IsComplexNumber(a) is true and re and im are its RealPart (1.1-1) and ImaginaryPart (1.1-1), respectively.

For cyclotomic numbers (see IsCyc (???)) c the second mentioned method returns the complex number with the real and imaginary parts as cyclotomic numbers.

For other c the one argument form is equivalent to a call with arguments c and 0*ca.

gap> a := 1/2 * ComplexNumber(Sqrt(2), -Sqrt(2));
1/2*E(8)-1/2*E(8)^3-I*(1/2*E(8)+1/2*E(8)^3)
gap> a^2;
-I
gap> x := Indeterminate(Rationals, "x");;
gap> b := ComplexNumber(1+x,3-x^2);
x+1-I*(x^2+3)
gap> b^2;
-x^4+7*x^2+2*x-8-I*(2*x^3-2*x^2+6*x+6)
gap> c := ComplexNumber(E(7));
1/2*E(7)+1/2*E(7)^6+I*(1/2*E(28)^3-1/2*E(28)^11)
gap> c^7;
1

1.2 Decimal Approximations of Real Numbers

1.2-1 IsDecimalApproximation
‣ IsDecimalApproximation( a )( filter )

Returns: true or false.

‣ Mantissa( a )( attribute )
‣ Precision( a )( attribute )
‣ Epsilon( a )( attribute )

Returns: integers.

IsDecimalApproximation returns true for additive and multiplicative elements a which have attributes Mantissa, Precision and Epsilon. Such an element is interpreted as a real number which has distance at most Epsilon(a) / 10^Precision(a) from the number Mantissa(a) / 10^Precision(a). Arithmetic with such numbers is done via an interval arithmetic.

If a lot of arithmetic is done with such decimal approximations the value of Epsilon can become big, since with each operation worst case estimates for the error are done.

In arithmetic expressions we allow rational numbers as operands, they are implicitly substituted by approximations of the same precision as the other operand.

1.2-2 DecimalApproximation
‣ DecimalApproximation( c[, prec] )( operation )

Returns: an object in IsDecimalApproximation (1.2-1) or in IsComplexNumber (1.1-1) with real and imaginary part in IsDecimalApproximation (1.2-1).

With this operation real approximations can be created. If the second argument prec is given it will be the precision of the result. If it is omitted, then the current value of DefaultDecimalPrecision (which is set to 10 while loading the package) will be used instead.

There are methods for the following types of c:

real cyclotomic

returns a decimal approximation, see the comment below for what this means if c is not rational.

non-real cyclotomic

the result is in IsComplexNumber (1.1-1) and the real and imaginary parts are decimal approximations.

complex number

the result is a complex number with DecimalApproximation applied to the real and imaginary parts.

decimal approximation

returns a decimal approximation, maybe with another precision.

Note that in GAP each cyclotomic number has well defined interpretation within the complex numbers, E(n) is considered as \(e^{{2 \pi i / n}}\). So, the results of DecimalApproximation are also well defined for cyclotomic numbers.

gap> DefaultDecimalPrecision;
10
gap> a := DecimalApproximation(1/3);
0.333333333
gap> Mantissa(a); Precision(a); Epsilon(a);
3333333333
10
1
gap> 3/4*a;
0.25
gap> # see also 'SqrtDecimalApproximation'
gap> DecimalApproximation(Sqrt(3), 50); 
1.7320508075688772935274463415058723669428052538102
gap> b := DecimalApproximation(E(20));
0.951056516+I*0.309016995
gap> b^5;
-0.000000002+I*1.000000001
gap> DecimalApproximation(last, 3);
I

1.2-3 SqrtDecimalApproximation
‣ SqrtDecimalApproximation( r, prec )( function )

Returns: decimal approximation.

For a positive rational number or a positive real approximation r this function computes the square root to precision prec via Newton approximation. This can be much faster than via a representation of the square root as cyclotomic number.

gap> # use 
gap> SqrtDecimalApproximation(2, 50);
1.4142135623730950488016887242096980785696718753769
gap> # instead of
gap> DecimalApproximation(Sqrt(2), 50);
1.4142135623730950488016887242096980785696718753769

1.2-4 PiDecimalApproximation
‣ PiDecimalApproximation( prec )( function )

Returns: decimal approximation of \(\pi\).

This function computes the decimal approximation of \(\pi\) to precision prec. It uses a recursion formula with exponential convergence, seeĀ [Koe87].

gap> PiDecimalApproximation(707);
3.14159265358979323846264338327950288419716939937510582097\
4944592307816406286208998628034825342117067982148086513282\
3066470938446095505822317253594081284811174502841027019385\
2110555964462294895493038196442881097566593344612847564823\
3786783165271201909145648566923460348610454326648213393607\
2602491412737245870066063155881748815209209628292540917153\
6436789259036001133053054882046652138414695194151160943305\
7270365759591953092186117381932611793105118548074462379962\
7495673518857527248912279381830119491298336733624406566430\
8602139494639522473719070217986094370277053921717629317675\
2384674818467669405132000568127145263560827785771342757789\
6091736371787214684409012249534301465495853710507922796892\
589235420199

1.2-5 TruelyLessDecimal
‣ TruelyLessDecimal( a, b )( function )

Returns: true, false or fail.

The arguments a and b must be decimal approximations of real numbers. Recall that this means that they are real numbers which are only specified by an interval of rational numbers. This function returns fail if the interval overlap. It returns true if all numbers in the interval specifying a are strictly smaller than all numbers in the interval specifying b. Otherwise false is returned.

gap> a := SqrtDecimalApproximation(2,30);
1.41421356237309504880168872421
gap> b := SqrtDecimalApproximation(3,20);
1.7320508075688772935
gap> TruelyLessDecimal(a,b);      
true
gap> TruelyLessDecimal(a^2,b^2-1);
fail

1.2-6 HasPositiveRealPartCyc
‣ HasPositiveRealPartCyc( c )( function )

Returns: true or false.

The argument c must be a cyclotomic number. This function returns true if the real part of this number is greater than zero.

The algorithm is to compute decimal approximations of the number with growing precision until the question can be decided.

(Recall that in GAP cyclotomic numbers are considered with a well defined embedding into the complex numbers, see DecimalApproximation (1.2-2).)

gap> HasPositiveRealPartCyc(0);
false
gap> HasPositiveRealPartCyc(E(7));  
true
gap> HasPositiveRealPartCyc(E(3));
false
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 Bib Ind

generated by GAPDoc2HTML