# Creation Functions

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

## 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`

```magma
Bits: BoolElt                    Default: false
```

Given a positive integer $p$, create and return a version $R$ of the real field ${\mathbb{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 $\lceil \log_2 {10^p} \rceil$.

### `RealField() -> FldRe`

Return the default real field.

### `ComplexField(p): RngIntElt -> FldCom`

```magma
Bits: BoolElt                    Default: false
```

Given a positive integer $p$, create and return a version $C$ of the complex field ${\mathbb{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 $\lceil \log_2 {10^p} \rceil$. 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: Create Complex Field (ex-108c46)`

It is convenient to use ${\rm 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.

```magma
> 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

### `a . becpd: RngIntElt, RngIntElt, RngIntElt -> FldReElt`

### `a . bEcPd: RngIntElt, RngIntElt, RngIntElt -> FldReElt`

### `a.bec P d: RngIntElt, RngIntElt, RngIntElt -> FldReElt`

### `a.bec p d: RngIntElt, RngIntElt, RngIntElt -> FldReElt`

### `a.b E cpd: RngIntElt, RngIntElt, RngIntElt -> FldReElt`

### `a.b e cpd: RngIntElt, RngIntElt, RngIntElt -> FldReElt`

Given a succession of literal decimal digits $a$, a succession of literal decimal digits $b$, a succession of literal decimal digits $c$, and an integer $d$, construct the real number $r=a.b \times 10^c$. If specified, the effect of $d$ is to create $r$ as an element of the real field of precision $d$. If $d$ is omitted (together with `p` or `P`), the real number will be created as an element of the default real field. Both $a$ and $c$ may include a leading sign `+` or `-`; leading zeroes in $a$ and $c$ are ignored. If $b$ consists entirely of zeroes it may be omitted together with the `.` and if $c$ is zero it may be omitted together with `E` (or `e`). But note that if all of $b$, $c$ and $d$ 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 \times 2^n$ 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{\mathrm{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 \geq 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: Create Elements (ex-356721)`

We create the real number $1.2345$ in many ways. We assume that the default real field has not been changed.

```magma
> 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

```

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`
