Talk:Miller–Rabin primality test: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 23: | Line 23: | ||
are helpful: an integer power function, power/2, will replace floating point power function, math:pow/2; in function |
are helpful: an integer power function, power/2, will replace floating point power function, math:pow/2; in function |
||
mr_series/4, math:pow/2 is replaced by power:power/2; in function pow_mod/3, the same replacement is made |
mr_series/4, math:pow/2 is replaced by power:power/2; in function pow_mod/3, the same replacement is made |
||
and truncations are eliminated, also the expression E/2 is replaced by E div 2. |
and truncations are eliminated, also the expression E/2 is replaced by E div 2. One final change is to replace the |
||
expression trunc(D/2) in find_ds/2 with the expression D div 2. By dogwood, 1/16/2014 @ 11:30pm. |
|||
-module(power). |
-module(power). |
||
Line 46: | Line 47: | ||
false -> (B*pow_mod(B, E-1, M)) rem M |
false -> (B*pow_mod(B, E-1, M)) rem M |
||
end |
end |
||
end. |
|||
find_ds(D, S) -> |
|||
case D rem 2 == 0 of |
|||
true -> |
|||
find_ds(D div 2, S+1); |
|||
false -> |
|||
{D, S} |
|||
end. |
end. |
||