| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 |
<HTML> |
| 3 |
<HEAD> |
| 4 |
<TITLE>Function EXPT-MOD</TITLE> |
| 5 |
<LINK REL="stylesheet" HREF="style.css" type="text/css"> |
| 6 |
</HEAD> |
| 7 |
<BODY> |
| 8 |
|
| 9 |
<p><p><i>Function</i> <b>EXPT-MOD</b></a></a> <p> |
| 10 |
<p><b>Syntax:</b><p> |
| 11 |
|
| 12 |
<p><b>expt-mod</b> <i>n exponent divisor</i> => <i>result</i> |
| 13 |
<p> |
| 14 |
<p><b>Arguments and Values:</b><p> |
| 15 |
<p> |
| 16 |
<i>n</i>---a <i>number</i></a>. <p> |
| 17 |
|
| 18 |
<i>exponent</i>---a <i>number</i></a>. <p> |
| 19 |
|
| 20 |
<i>divisor</i>---a <i>number</i></a>. <p> |
| 21 |
|
| 22 |
<i>result</i>---a <i>number</i></a>. <p> |
| 23 |
|
| 24 |
<p> |
| 25 |
<p><b>Description:</b><p> |
| 26 |
<p> |
| 27 |
<b>expt-mod</b> returns <i>n</i> raised to the <i>exponent</i> power, |
| 28 |
modulo <i>divisor</i>. <tt>(expt-mod n exponent divisor)</tt> is |
| 29 |
equivalent to <tt>(mod (expt n exponent) divisor)</tt>. |
| 30 |
|
| 31 |
<p> |
| 32 |
<p><b>Exceptional situations:</b><p> |
| 33 |
<p> |
| 34 |
|
| 35 |
<p>The exceptional situations are the same as those for <tt>(mod (expt |
| 36 |
n exponent) divisor)</tt>. |
| 37 |
|
| 38 |
<p><p><b>Notes:</b></p> |
| 39 |
|
| 40 |
<p>One might wonder why we shouldn't simply write <tt>(mod (expt n |
| 41 |
exponent) divisor)</tt>. This function exists because the naïve |
| 42 |
way of evaluating <tt>(mod (expt n exponent) divisor)</tt> produces a |
| 43 |
gigantic intermediate result, which kills performance in applications |
| 44 |
which use this operation heavily. The operation can be done much more |
| 45 |
efficiently. Usually the compiler does this optimization |
| 46 |
automatically, producing very fast code. However, we can't |
| 47 |
<i>depend</i> on this behavior if we want to produce code that is |
| 48 |
guaranteed not to perform abysmally on some Lisp implementations. |
| 49 |
|
| 50 |
<p>Therefore cl-utilities provides a standard interface to this |
| 51 |
composite operation which uses mediocre code by default. Specific |
| 52 |
implementations can usually do much better, but some do much |
| 53 |
worse. We can get the best of both by simply using the same interface |
| 54 |
and doing read-time conditionalization within cl-utilities to get |
| 55 |
better performance on compilers like SBCL and Allegro CL which |
| 56 |
optimize this operation. |
| 57 |
|
| 58 |
<p class="footer"><hr><a href="index.html">Manual Index</a></p> |
| 59 |
|
| 60 |
</body></html> |