---
title: "Coercion"
canonical: "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/StatementsAndExpressions/coercion.html"
source: "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/StatementsAndExpressions/coercion.md"
part: "The Magma Language"
chapter: "Statements and Expressions"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "The Magma Language", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/index-magma-language.md"}
  - {"title": "Statements and Expressions", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/StatementsAndExpressions/index-statements-and-expressions.md"}
prev: {"title": "Boolean Values", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/StatementsAndExpressions/boolean.md"}
next: {"title": "The where … is Construction", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/StatementsAndExpressions/where-is.md"}
intrinsics:
  - {"name": "!", "signature": "S ! x: Str, Elt -> Elt"}
  - {"name": "IsCoercible", "signature": "IsCoercible(S, x): Str, Elt -> Bool, Elt"}
---

# Coercion

Coercion is a fundamental concept in Magma. Given a structures $A$ and $B$, there is often a natural mathematical mapping from $A$ to $B$ (e.g., embedding, projection), which allows one to transfer elements of $A$ to corresponding elements of $B$. This is known as coercion. Natural and obvious coercions are supported in Magma as much as possible; see the relevant chapters for the coercions possible between various structures.

<a id="operation-op-str-elt"></a>
## `S ! x: Str, Elt -> Elt`

Given a structure $S$ and an object $x$, attempt to coerce $x$ into $S$ and return the result if successful. If the attempt fails, an error ensues.

<a id="function-iscoercible-str-elt"></a>
## `IsCoercible(S, x): Str, Elt -> Bool, Elt`

Given a structure $S$ and an object $x$, attempt to coerce $x$ into $S$; if successful, return `true` and the result of the coercion, otherwise return `false`.
