We describe the creation of real and complex fields and their elements.
At the time Magma is loaded, a version of the free real field
is automatically created. This is used
as default parents for literal reals and real values returned by Magma.
RealField(p) : RngIntElt -> FldRe
Given a positive integer p, create and return a version R of the real field R in which all calculations are correct to p' decimal digits, where p'=4.Ceiling((p/4)) is the smallest multiple of 4 greater than or equal to p.
Create the free real field.
Given a positive integer p, create and return a version C of the complex field C in which all calculations are correct to p' decimal digits, where p'=4.Ceiling((p/4)) is the smallest multiple of 4 greater than or equal to p.The name i is given to sqrt(-1); this may be changed with AssignNames. Angle brackets may be used to assign sqrt(-1) to an identifier, e.g. C<i>:=ComplexField(20).
Create the free complex field.The name i is given to sqrt(-1); this may be changed with AssignNames. Angle brackets may be used to assign sqrt(-1) to an identifier, e.g. C<i>:=ComplexField().
> C<i> := ComplexField(32); > Pi(C)+ 1/4*i; 3.1415926535897932384626433833 + 0.25 i > AssignNames( C, ["k"]); > print Pi(C)+ 1/4*i; 3.1415926535897932384626433833 + 0.25 k > k := Name(C, 1); > Pi(C)+ 1/4*k; 3.1415926535897932384626433833 + 0.25*k
The following generic element constructions are available; they return the 1 and 0 element of a real or complex field.
Given a succession of literal decimal digits d, a succession of literal decimal digits e, a succession of literal decimal digits f, and an integer g, construct the real number r=d.e x 10^f; the effect of g depends on the default real field: if the default real field has fixed precision, r will be created as an element of the real field of precision g' (where g' is the smallest multiple of 4 greater than or equal to g), but if the default real field is free then g determines the precision to which r is constructed as a free real number.If g is omitted (together with p or P), the real number will be created as an element of the default real field. If the default field is the free real field, in the absence of p the maximum of the default precision and the number of decimal digits supplied is used in the creation of the free real number r.
Both d and f may include a leading sign + or -; leading zeroes in d and f are ignored. If e consists entirely of zeroes it may be omitted together with the . and if f is zero it may be omitted together with E (or e). But note that if all of e, f and g are omitted the result will be an integer.
Given the real field R, an element m coercible into R and an integer n, construct the real number m x 10^n in R.
Given the complex field C and elements x and y coercible into the real field underlying C, construct the complex number x + y i.
Given an integer, a rational number, a quadratic or cyclotomic number field element a, this returns an element from the real field R that best approximates a. An error results if a is a non-real quadratic or cyclotomic field element.If R is a field of fixed precision r and a is an element of a real field S of fixed precision s then:
If R is a free real field and a is a fixed precision real number again an element in R approximating a as well as possible to the default precision of R is returned.
- if a is an element of a real field S of fixed precision s >= r, then an element of R approximating a to r digits is returned;
- if a is an element of a real field S of fixed precision s < r, then an element of R is returned approximating a, obtained by padding with zeroes until the required precision r is reached;
- if a is an element of the free real field then an element of R best approximating a is returned (because of the different radix representations of free and fixed precision reals the result may not coincide digit-by-digit with a to the available accuracy).
Given an integer, a rational number, a quadratic or cyclotomic number field element a, this returns an element from the complex field C that best approximates a. The rules of coercion for the real and imaginary parts are the same as those for coercion into a real field.
> x := 1.2345; > x, Parent(x); 1.234499999999999999999999999 Field of Pari-style reals > SetDefaultRealField(RealField(20)); > x1 := 1.2345; > x1, Parent(x1); 1.2345 Real Field of Precision 20 > x2 := 12345e-4; > x2, Parent(x2); 1.2345 Real Field of Precision 20 > x3 := 1.2345p50; > x3, Parent(x3); 1.2345 Real Field of Precision 52 > x4 := 12345e-4p8; > x4, Parent(x4); 1.2345 Real Field of Precision 8 > x5 := RealField(12) ! 1.2345; > x5, Parent(x5); 1.2345 Real Field of Precision 12 > x6 := elt< RealField(100) | 12345, -4 >; > x6, Parent(x6); 1.2345 Real Field of Precision 100