Modular Square Root - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

NumberTheory

 ModularSquareRoot
 modular square root

 Calling Sequence ModularSquareRoot(x, n)

Parameters

 x - integer n - positive integer

Description

 • The ModularSquareRoot function computes a non-negative integer $y$ such that ${y}^{2}=x\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}n$ if possible. If not possible, an error message is displayed.
 • When x has more than one square root, any one of them may be returned.

Examples

 > $\mathrm{with}\left(\mathrm{NumberTheory}\right):$

The follow numbers have square roots modulo $37$.

 > $\mathrm{residues}≔\left\{\mathrm{seq}\left({i}^{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}37,i=0..36\right)\right\}$
 ${\mathrm{residues}}{≔}\left\{{0}{,}{1}{,}{3}{,}{4}{,}{7}{,}{9}{,}{10}{,}{11}{,}{12}{,}{16}{,}{21}{,}{25}{,}{26}{,}{27}{,}{28}{,}{30}{,}{33}{,}{34}{,}{36}\right\}$ (1)

$30$ has a square root modulo $37$.

 > $\mathrm{evalb}\left(30\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}∈\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{residues}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{ModularSquareRoot}\left(30,37\right)$
 ${17}$ (3)
 > ${17}^{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}37$
 ${30}$ (4)

$24$ does not have a square root modulo $37$ and so an error message is displayed.

 > $\mathrm{evalb}\left(24\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}∈\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{residues}\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{ModularSquareRoot}\left(24,37\right)$

Compatibility

 • The NumberTheory[ModularSquareRoot] command was introduced in Maple 2016.
 • For more information on Maple 2016 changes, see Updates in Maple 2016.