Modular arithmetic: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 560: | Line 560: | ||
<pre> |
<pre> |
||
\ We would normally define operators that have a suffix `m' in order |
\ We would normally define operators that have a suffix `m' in order |
||
\ not be confused: +m -m *m /m **m |
\ not to be confused: +m -m *m /m **m |
||
\ Also useful is %:m reduce a number modulo. |
\ Also useful is %:m reduce a number modulo. |
||
Line 585: | Line 585: | ||
: _reduce_1- 1- >R >R R@ *m R> R> ; |
: _reduce_1- 1- >R >R R@ *m R> R> ; |
||
: _reduce_2/ 2/ >R DUP *m R> ; |
: _reduce_2/ 2/ >R DUP *m R> ; |
||
( a b -- apowbn ) |
|||
: **m 1 ROT ROT BEGIN DUP 1 AND IF _reduce_1- THEN |
: **m 1 ROT ROT BEGIN DUP 1 AND IF _reduce_1- THEN |
||
_reduce_2/ DUP 0= UNTIL 2DROP ; |
_reduce_2/ DUP 0= UNTIL 2DROP ; |
||
\ The solution is |
\ The solution is |
||
13 set-modulus |
13 set-modulus |
||
10 DUP 100 **m +m 1 +m . CR |
10 DUP 100 **m +m 1 +m . CR |
||
Line 609: | Line 610: | ||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
Go does not allow redefinition of operators. That element of the task cannot be done in Go. The element of defining f so that it can be used with any ring however can be done, just not with the syntactic sugar of operator redefinition. |
Go does not allow redefinition of operators. That element of the task cannot be done in Go. The element of defining f so that it can be used with any ring however can be done, just not with the syntactic sugar of operator redefinition. |