Working with Gaussian Integers - Maple Help

Home : Support : Online Help : Mathematics : Number Theory : Examples : Working with Gaussian Integers

Working with Complex Integers Using the GaussInt Package

Getting Started

While any command in the package can be referred to using the long form, for example, GaussInt:-GIgcd, it is often easier to load the package and then use the short form command names.

 > restart;
 > with(GaussInt):

Examples

The GaussInt package provides routines for working with Gaussian integers. Many of these commands are similar to commands from the NumberTheory package, but are designed to work with complex integers. The symbol capital $I$ is reserved for one of the square roots of -1: $I$ = $\sqrt{-1}$.

Simple operators with complex integers are possible without any commands in the GaussInt package:

 > $1+2I+\left(3-I\right)$
 ${4}{+}{I}$ (1)
 > $\left(3+2I\right)\left(5-3I\right)$
 ${21}{+}{I}$ (2)
 > $\frac{3+2I}{5-3I}$
 $\frac{{9}}{{34}}{+}\frac{{19}{}{I}}{{34}}$ (3)

The GIquo command computes the integer quotient of m divided by n.

 > $\mathrm{GIquo}\left(3+2I,5-3I\right)$
 ${I}$ (4)

The GIrem command computes the integer remainder of m divided by n.

 > $\mathrm{GIrem}\left(3+2I,5-3I\right)$
 ${-}{3}{}{I}$ (5)

If the GIquo command is called with an optional third argument that specifies a name, the result for the remainder is stored in the given name. The converse is also true for the GIrem command:

 > $\mathrm{GIrem}\left(1+2I,3-I,'\mathrm{quot}'\right)$
 ${-I}$ (6)
 > $\mathrm{quot}$
 ${I}$ (7)
 > $\mathrm{quot}\left(3-I\right)+\left(-I\right)$
 ${1}{+}{2}{}{I}$ (8)

The GIgcd command calculates the greatest common divisor of a sequence of Gaussian integers:

 > $\mathrm{GIgcd}\left(-3+5I,4+8I\right)$
 ${1}{+}{I}$ (9)
 > $\mathrm{GIquo}\left(-3+5I,1+I\right)$
 ${1}{+}{4}{}{I}$ (10)
 > $\mathrm{GIrem}\left(-3+5I,1+I\right)$
 ${0}$ (11)

The GIdivisor command computes a set of divisors that are in the first quadrant of its Gaussian integer argument:

 > $\mathrm{GIdivisor}\left(-3+5I\right)$
 $\left\{{1}{,}{1}{+}{I}{,}{1}{+}{4}{}{I}{,}{5}{+}{3}{}{I}\right\}$ (12)

The GIfactor command returns the Gaussian integer factorization of c:

 > $\mathrm{GIfactor}\left(-36+50I\right)$
 ${\left({1}{+}{I}\right)}^{{2}}{}\left({-3}{+}{2}{}{I}\right){}\left({-3}{-}{8}{}{I}\right)$ (13)
 > $\mathrm{expand}\left({\left(1+I\right)}^{2}\left(-3+2I\right)\left(-3-8I\right)\right)$
 ${-36}{+}{50}{}{I}$ (14)

The GIprime command tests a value, z, for primality.

 > $\mathrm{GIprime}\left(19\right)$
 ${\mathrm{true}}$ (15)
 > $\mathrm{GIprime}\left(4+9I\right)$
 ${\mathrm{true}}$ (16)
 > $\mathrm{GIprime}\left(4+8I\right)$
 ${\mathrm{false}}$ (17)

The GInorm command computes the norm of the Gaussian integer, z. The norm of a Gaussian integer $z$ = $a+Ib$ is defined as ||z|| = $\left(a+Ib\right)\left(a-Ib\right)$ = ${a}^{2}+{b}^{2}$

 > $\mathrm{GInorm}\left(4-2I\right)$
 ${20}$ (18)
 > ${4}^{2}+{\left(-2\right)}^{2}$
 ${20}$ (19)