Creation Functions

We describe the creation of real and complex fields and their elements.

Contents

Creation of Structures

At the time Magma is loaded, a real field

is automatically created. This is used as the default parent for literal reals and real values returned by Magma.

RealField(p) : RngIntElt -> FldRe
    Bits: BoolElt                       Default: false
Given a positive integer p, create and return a version R of the real field R in which all calculations are correct to precision p. If the parameter Bits is true, then the precision p is specified as the number of binary digits. If Bits is false, then the precision is given as the number of decimal digits --- this is translated into a binary precision of ⌈log2 (10p) ⌉.
RealField() : -> FldRe
Return the default real field.
ComplexField(p) : RngIntElt -> FldCom
    Bits: BoolElt                       Default: false
Given a positive integer p, create and return a version C of the complex field C in which all calculations are correct to precision p. If the parameter Bits is true, then the precision p is specified as the number of binary digits. If Bits is false, then the precision is given as the number of decimal digits --- this is translated into a binary precision of ⌈log2 (10p) ⌉.

By default no name is given to Sqrt( - 1); this may be changed with AssignNames. Angle brackets, e.g. C<i> := ComplexField(20), may be used to assign Sqrt( - 1) to an identifier.

ComplexField() : -> FldCom
Return the default complex field.

By default no name is given to Sqrt( - 1); this may be changed with AssignNames. Angle brackets, e.g. C<i> := ComplexField(), may be used to assign Sqrt( - 1) to an identifier.

ComplexField(R) : FldRe -> FldCom
Return the complex field which has real subfield R; in other words, return the complex field with the same precision as the real field R.

Example FldRe_CreateComplexField (H26E3)

It is convenient to use (i) to define elements of a complex field. It is also possible to change the default printing of i, using AssignNames, as follows. Note that the latter procedure does not assign to an identifier, it only changes the printing.
> C<i> := ComplexField(20);
> Pi(C)+ 1/4*i;
3.1415926535897932385 + 0.25000000000000000000*i
> AssignNames(~C, ["k"]);
> Pi(C)+ 1/4*i;
3.1415926535897932385 + 0.25000000000000000000*k
> k := Name(C, 1);
> Pi(C)+ 1/4*k;
3.1415926535897932385 + 0.25000000000000000000*k

Creation of Elements

The following generic element constructions are available; they return the 1 and 0 element of a real or complex field, where any zero elements are the "positive zero" in MPFR.

One(R) : FldRe -> FldReElt
One(R) : FldCom -> FldComElt
Identity(R) : FldRe -> FldReElt
Identity(R) : FldCom -> FldComElt
Zero(R) : FldRe -> FldReElt
Zero(R) : FldCom -> FldComElt
Representative(R) : FldRe -> FldReElt
Representative(R) : FldCom -> FldComElt
d . eefpg : RngIntElt, RngIntElt, RngIntElt -> FldReElt
d . eEfPg : RngIntElt, RngIntElt, RngIntElt -> FldReElt
d.eef P g : RngIntElt, RngIntElt, RngIntElt -> FldReElt
d.eef p g : RngIntElt, RngIntElt, RngIntElt -> FldReElt
d.e E fpg : RngIntElt, RngIntElt, RngIntElt -> FldReElt
d.e e fpg : RngIntElt, RngIntElt, RngIntElt -> FldReElt
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 10f. If specified, the effect of g is to create r as an element of the real field of precision g.

If g is omitted (together with p or P), the real number will be created as an element of the default real field.

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.

elt<R | m, n> : FldRe, FldReElt, RngIntElt -> FldReElt
Given the real field R, an element m coercible into R and an integer n, construct the real number m x 2n in R.
elt<C | x, y> : FldCom, FldReElt, FldReElt -> FldComElt
C ! [x, y] : FldCom, [FldReElt, FldReElt] -> FldComElt
Given the complex field C and elements x and y coercible into the real field underlying C, construct the complex number x + y i.
R ! a : FldRe, RngElt -> FldReElt
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 precision r and a is an element of a real field S of precision s then:

if a is an element of a real field S of 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 precision s < r, then an element of R is returned approximating a, obtained by padding with zeroes until the required precision r is reached;
C ! a : FldCom, RngElt -> FldComElt
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.

Example FldRe_CreateElements (H26E4)

We create the real number 1.2345 in many ways. We assume that the default real field has not been changed.
> x := 1.2345;
> x, Parent(x);
1.23450000000000000000000000000 Real field of precision 30
> SetDefaultRealField(RealField(20));
> x1 := 1.2345;
> x1, Parent(x1);
1.2345000000000000000 Real field of precision 20
> x2 := 12345e-4;
> x2, Parent(x2);
1.2345000000000000000 Real field of precision 20
> x3 := 1.2345p10;
> x3, Parent(x3);
1.234500000 Real field of precision 10
> x4 := 12345e-4p8;
> x4, Parent(x4);
1.2345000 Real field of precision 8
> x5 := RealField(12) ! 1.2345;
> x5, Parent(x5);
1.23450000000 Real field of precision 12
V2.28, 13 July 2023