# The Homomorphism Type

Magma has a special type for a homomorphism between two $R$-modules. The type of such a homomorphism is `ModMPolHom`. In general, functions such as [`Morphism`](sub-quo.md#function-pmod-morphism) return a homomorphism of type `ModMPolHom`, while the boundary maps of complexes are also of type `ModMPolHom` (see the function [`FreeResolution`](free-resolution.md#function-pmod-freeresolution)). A homomorphism $f: M \rightarrow N$ is represented by a matrix $A$. There are two ways in which $A$ can be defined:

**(a)**
$A$ is an **ambient** matrix: in this case, $A$ gives the explicit map on the *ambient* modules of $M$ and $N$. Thus $A$ is $m\times n$, where $m=$`Degree(M)`, $n=$`Degree(N)`.

**(b)**
$A$ is a **presentation** matrix: in this case, $A$ gives the explicit map on the *presentation* modules of $M$ and $N$. Thus $A$ is $m\times n$, where $m=$`Degree(Presentation(M))`, $n=$`Degree(Presentation(N))`.

If $M$ and $N$ are reduced (a common case), then they equal their respective presentation modules, so there is no difference between the above two cases (the ambient matrix and the presentation matrix are identical). So the only difference between (a) and (b) occurs when at least one of $M$ and $N$ is a non-ambient (proper) submodule of an embedded module.

When $M$ and $N$ are graded - that is, generated by elements homogeneous with respect to the ambient column weightings and with a relation module that is also generated by homogeneous elements - all homomorphisms as non-graded modules are still allowed. However there are functions to test if a given homomorphism preserves the gradings on the domain and codomain up to a constant degree shift. See `IsHomogeneous` and `Degree` below.

## `Homomorphism(M, N, A): ModMPol, ModMPol, Mtrx -> ModMPolHom`

```magma
Presentation: BoolElt                    Default: true
```

Given $R$-modules $M$ and $N$ and an $m\times n$ matrix $A$ over $R$, construct the homomorphism $f:M \rightarrow N$ (with type `ModMPolHom`) defined by $A$. By default, $A$ is assumed to be a presentation matrix (see the comments above), in which case $m$ and $n$ must equal the degrees of the presentation modules of $M$ and $N$, respectively. Alternatively, setting the parameter `Presentation` to `false` specifies that $A$ is an ambient matrix; in this case, $m$ and $n$ must equal the degrees of $M$ and $N$, respectively.

## `Domain(f): ModMPolHom -> ModMPol`

Given a module homomorphism $f:M \rightarrow N$, return the domain $M$.

## `Codomain(f): ModMPolHom -> ModMPol`

Given a module homomorphism $f:M \rightarrow N$, return the codomain $N$.

## `PresentationMatrix(f): ModMPolHom -> ModMatRngElt`

## `Matrix(f): ModMPolHom -> ModMatRngElt`

Given a module homomorphism $f:M \rightarrow N$, return the presentation matrix $A_P$ of $f$ as an $m\times n$ matrix corresponding to the presentation modules of $M$ and $N$, respectively. This presentation matrix is always well-defined and computed, even if $f$ is constructed via an ambient matrix.

## `AmbientMatrix(f): ModMPolHom -> ModMatRngElt`

## `Matrix(f): ModMPolHom -> ModMatRngElt`

Given a module homomorphism $f:M \rightarrow N$, return the ambient matrix $A_A$ of $f$ as an $m\times n$ corresponding to the ambient modules of $M$ and $N$, respectively. If $M$ and $N$ are reduced (as commonly happens), this will be the same as the presentation matrix above. But if $M$ and $N$ are not reduced and $f$ is constructed via a presentation matrix, then an error may result (since it may be impossible to give a matrix over the base ring $R$ which gives the mapping for the ambient modules).

## `f(v): ModMPolHom, RngMPolElt -> RngMPolElt`

## `v * f: ModMPolHom, RngMPolElt -> RngMPolElt`

Given a module homomorphism $f:M \rightarrow N$ and an element $v$ of $M$, return the image of $v$ under $f$, as an element of $N$.

## `f[i]: ModMPolHom, RngIntElt -> RngMPolElt`

Given a module homomorphism $f:M \rightarrow N$ and an integer $i$, return the element of $N$ corresponding to the $i$-th row of the ambient matrix of $f$.

## `Image(f): ModMPolHom -> ModMPol`

Given a module homomorphism $f:M \rightarrow N$, return the image of $f$ as a submodule of $N$ (which will be reduced iff $N$ is).

## `Kernel(f): ModMPolHom -> ModMPol`

Given a module homomorphism $f:M \rightarrow N$, return the kernel of $f$ as a submodule of $M$ (which will be reduced iff $M$ is).

## `Cokernel(f): ModMPolHom -> ModMPol`

Given a module homomorphism $f:M \rightarrow N$, return the cokernel of $f$ as a quotient module of $N$ (which will be reduced iff $N$ is).

## `IsZero(f): ModMPolHom -> BoolElt`

Given a module homomorphism $f:M \rightarrow N$, return whether $f$ is the zero map. Note that $f$ may be the zero map even if the presentation or ambient matrices of $f$ are non-zero.

## `IsInjective(f): ModMPolHom -> BoolElt`

Given a module homomorphism $f:M \rightarrow N$, return whether $f$ is injective (whether the kernel of $f$ is the zero module).

## `IsSurjective(f): ModMPolHom -> BoolElt`

Given a module homomorphism $f:M \rightarrow N$, return whether $f$ is surjective (whether the image of $f$ equals $N$).

## `IsBijective(f): ModMPolHom -> BoolElt`

Given a module homomorphism $f:M \rightarrow N$, return whether $f$ is bijective (injective and surjective).

## `IsGraded(f): ModMPolHom -> BoolElt`

## `IsHomogeneous(f): ModMPolHom -> BoolElt`

Given a module homomorphism $f:M \rightarrow N$, where $M$ and $N$ are graded modules, return whether $f$ is homogeneous of some degree $d$; that is, whether for every pure degree element $v\in M$, $f(v)=0$ or `Degree`$(f(v))$ equals `Degree`$(v)+d$.

## `Degree(f): ModMPolHom -> RngIntElt`

Given a module homomorphism $f:M \rightarrow N$, return the degree of $f$, which is the maximum $d$ such that an element of $M$ of degree $e$ is mapped via $f$ to zero or an element of degree $e+d$. If $f$ is homogeneous, then the ‘maximum’ concept is unnecessary, since the degree will be consistent for all elements of $M$ (see the previous function).

## `Example: Homomorphism Embedded (ex-ce742b)`

We illustrate some homomorphism functionality by looking at the explicit inclusion homomorphism between two submodules of a rank 3 free module over ${\mathbb{Q}}[x, y]$. We define this in non-presentational form by the identity matrix. Then we can retrieve the corresponding defining matrix for the map between the internal presentations of the two submodules. The two submodules being graded submodules, we check that the inclusion is indeed homogeneous of degree 0 (as it must be, obviously preserving degrees of elements).

```magma
> R<x,y> := PolynomialRing(RationalField(), 2, "grevlex");
> F := EModule(R, 3);
> // get a submodule M1 generated by a single non-zero element of F
> M1 := sub<F|[x^2,y^2,x*y]>;
> // and a second submodule M2 containing M1
> M2 := sub<F|[x,0,y],[0,y,0]>;
> incl_hm :=  Homomorphism(M1,M2,IdentityMatrix(R,3) :
>               Presentation := false);
> incl_hm;
Module homomorphism (3 by 3)
Ambient matrix:
[1 0 0]
[0 1 0]
[0 0 1]

```

Now the corresponding presentation matrix of the inclusion map is the obvious one coming from the expression of the natural generator of M1 in terms of the two natural generators of M2

```magma
>  PresentationMatrix(incl_hm);
[y x]
> // check homogeneity of incl_hm
> IsHomogeneous(incl_hm);
true
> Degree(incl_hm);
0

```
