---
title: "Creation of Structures"
canonical: "https://docs.magma-maths.org/v2.30-1/GlobalFields/QuadraticFields/creation.html"
source: "https://docs.magma-maths.org/v2.30-1/GlobalFields/QuadraticFields/creation.md"
part: "Global Fields"
chapter: "Quadratic Fields"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Global Fields", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/index-global-fields.md"}
  - {"title": "Quadratic Fields", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/QuadraticFields/index-quadratic-fields.md"}
prev: {"title": "Introduction", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/QuadraticFields/introduction.md"}
next: {"title": "Operations on Structures", "source": "https://docs.magma-maths.org/v2.30-1/GlobalFields/QuadraticFields/structure_ops.md"}
intrinsics:
  - {"name": "QuadraticField", "signature": "QuadraticField(m): RngIntElt -> FldQuad"}
  - {"name": "EquationOrder", "signature": "EquationOrder(F): FldQuad -> RngQuad"}
  - {"name": "MaximalOrder", "signature": "MaximalOrder(F): FldQuad -> RngQuad"}
  - {"name": "IntegerRing", "signature": "IntegerRing(F): FldQuad -> RngQuad"}
  - {"name": "RingOfIntegers", "signature": "RingOfIntegers(F): FldQuad -> RngQuad"}
  - {"name": "NumberField", "signature": "NumberField(O): RngQuad -> FldQuad"}
  - {"name": "sub", "signature": "sub< O | f >: RngQuad, RngIntElt"}
  - {"name": "IsQuadratic", "signature": "IsQuadratic(K): FldNum -> BoolElt, FldQuad"}
  - {"name": "IsQuadratic", "signature": "IsQuadratic(O): RngOrd -> BoolElt, RngQuad"}
examples:
  - "ex-a2440a"
  - "ex-6098de"
---

<a id="creation"></a>
<a id="fldquad-creation"></a>
# Creation of Structures

Squarefree integers determine quadratic fields. Associated with any quadratic field is its ring of integers (maximal order) and an equation order, and for every positive integer $f$ there exists an order of conductor $f$ inside the maximal order. For information on creating elements see Section [Creation of Elements](https://docs.magma-maths.org/v2.30-1/GlobalFields/NumberFields/creation.md#fldnum-main-elt-create).

<a id="function-fldquad-quadraticfield"></a>
## `QuadraticField(m): RngIntElt -> FldQuad`

Given an integer $m$ that is not a square, create the field ${\mathbb{Q}}(\sqrt{d})$, where $d$ is the squarefree part of $m$. It is possible to assign a name to $\sqrt{d}$ using angle brackets: `R<s> := QuadraticField(m)`.

<a id="function-equationorder-fldquad"></a>
## `EquationOrder(F): FldQuad -> RngQuad`

Creation of the order ${\mathbb{Z}}[\sqrt{d}]$ in the quadratic field $F={\mathbb{Q}}(\sqrt{d})$, with $d$ squarefree.

<a id="function-maximalorder-fldquad"></a>
## `MaximalOrder(F): FldQuad -> RngQuad`

<a id="function-integerring-fldquad"></a>
## `IntegerRing(F): FldQuad -> RngQuad`

<a id="function-ringofintegers-fldquad"></a>
## `RingOfIntegers(F): FldQuad -> RngQuad`

Given a quadratic field $F={\mathbb{Q}}(\sqrt{d})$, with $d$ squarefree, create its maximal order. This order is ${\mathbb{Z}}[\sqrt{d}]$ if $d\equiv 2, 3\bmod 4$ and ${\mathbb{Z}}[{1+\sqrt{d}\over2}]$ if $d\equiv1\bmod4$.

<a id="function-numberfield-rngquad"></a>
## `NumberField(O): RngQuad -> FldQuad`

Given a quadratic order, this returns the quadratic field of which it is an order.

<a id="constructor-constructor-sub-rngquad-rngintelt"></a>
## `sub< O | f >: RngQuad, RngIntElt`

Create the sub-order of index $f$ in the order $O$ of a quadratic field. If $O$ is maximal, this will be the unique order of conductor $f$.

<a id="function-isquadratic-fldnum"></a>
## `IsQuadratic(K): FldNum -> BoolElt, FldQuad`

<a id="function-isquadratic-rngord"></a>
## `IsQuadratic(O): RngOrd -> BoolElt, RngQuad`

Return `true` if the field $K$ or order $O$ can be created as a quadratic field or order and the quadratic field or order if so.

<a id="example-ex-a2440a"></a>
## `Example: Creating a Quadratic Field and Order (ex-a2440a)`

We create the quadratic field ${\mathbb{Q}}(\sqrt{5})$ and an order in it, and display some elements of the order in their representation as order element and as field element.

```magma
> Q<z> := QuadraticField(5);
> Q eq QuadraticField(45);
true
> O<w> := sub< MaximalOrder(Q) | 7 >;
> O;
Order of conductor 7 in Q
> w;
w
> Q ! w;
1/2*(7*z + 7)
> Eltseq(w), Eltseq(Q ! w);
[ 0, 1 ]
[ 7/2, 7/2 ]
> ( (7/2)+(7/2)*z )^2;
1/2*(49*z + 147)
>  Q ! w^2;
1/2*(49*z + 147)
> w^2;
7*w + 49
```

<a id="example-ex-6098de"></a>
## `Example: Embedding a Quadratic Field in a Cyclotomic Field (ex-6098de)`

We define an injection $\phi\colon{\mathbb{Q}}(\sqrt{5})\rightarrow{\mathbb{Q}}(\zeta_5)$. First a square root of $5$ is identified in ${\mathbb{Q}}(\zeta_5)$.

```magma
> Q<w> := QuadraticField(5);
> F<z> := CyclotomicField(5);
> C<c> := PolynomialRing(F);
> Factorization(c^2-5);
[
   <c - 2*z^3 - 2*z^2 - 1, 1>,
   <c + 2*z^3 + 2*z^2 + 1, 1>
]
> h := hom< Q -> F | -2*z^3 - 2*z^2 - 1 >;
> h(w)^2;
5
```
