| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Modulární aritmetika</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Příručka k aplikaci Genius"><link rel="up" href="ch05.html" title="Chapter 5. Základy jazyka GEL"><link rel="prev" href="ch05s05.html" title="Komentáře"><link rel="next" href="ch05s07.html" title="Seznam operátorů GEL"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Modulární aritmetika</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05s05.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Základy jazyka GEL</th><td width="20%" align="right"> <a accesskey="n" href="ch05s07.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-modular-evaluation"></a>Modulární aritmetika</h2></div></div></div><p>Genius má implementovánu modulární aritmetiku. Když ji chcete použít, stačí přidat „mod <celé_číslo>“ za výraz. Například: <strong class="userinput"><code>2^(5!) * 3^(6!) mod 5</code></strong> Pro modulární aritmetiku by bylo možné použít i počítání s celými čísly a následně určením zbytku na konci pomocí operátoru <code class="literal">%</code>, ale to je časově náročné, ne-li nemožné, při práci s většími čísly. Například <strong class="userinput"><code>10^(10^10) % 6</code></strong> jednoduše nebude pracovat (exponent bude příliš velký), zatímco <strong class="userinput"><code>10^(10^10) mod 6</code></strong> je spočteno v mžiku. V prvním příkladu se zkusí vypočítat <strong class="userinput"><code>10^(10^10)</code></strong> a pak najít zbytek po dělení 6, zatímco v druhém příkladu se vyhodnotí vše modulo 6 už na začátku.</p><p lang="en"> |
| 2 | The inverses of numbers mod some integer are computed by writing them as |
| 3 | rational numbers (as long as the desired inverse exists, of course). |
| 4 | Examples: |
| 5 | </p><pre lang="en" class="programlisting">10^-1 mod 101 |
| 6 | 1/10 mod 101</pre><p lang="en"> |
| 7 | Modular evaluation also works with matrices including taking inverses, |
| 8 | powers, and dividing. |
| 9 | Example: |
| 10 | </p><pre lang="en" class="programlisting">A = [1,2;3,4] |
| 11 | B = A^-1 mod 5 |
| 12 | A*B mod 5</pre><p lang="en"> |
| 13 | This should yield the identity matrix as B will be the inverse of A mod 5. |
| 14 | </p><p lang="en"> |
| 15 | Some functions such as |
| 16 | <a class="link" href="ch11s05.html#gel-function-sqrt"><code class="function">sqrt</code></a> or |
| 17 | <a class="link" href="ch11s05.html#gel-function-log"><code class="function">log</code></a> |
| 18 | work in a different way when in modulo mode. These will then work like their |
| 19 | discrete versions working within the ring of integers you selected. For |
| 20 | example: |
| 21 | </p><pre lang="en" class="programlisting">genius> sqrt(4) mod 7 |
| 22 | = |
| 23 | [2, 5] |
| 24 | genius> 2*2 mod 7 |
| 25 | = 4</pre><p lang="en"> |
| 26 | <code class="function">sqrt</code> will actually return all the possible square |
| 27 | roots. |
| 28 | </p><p>Nezřetězujte operátory mod, umístěte jen jeden na konce výpočtu a všechny početní operace ve výrazu nalevo budou ošetřeny v modulární aritmetice. Když umístíte mod do mod, obdržíte neočekávané výsledky. Pokud chcete použít modulo na jediné číslo a jen zjistit, zda zůstane zbytek, je lepší použít operátor <code class="literal">%</code>. Když potřebujete zřetězit několik výrazů v modulární aritmetice s různými děliteli, může být lepší rozdělit výraz na více výrazů a použít dočasné proměnné, aby se předešlo vložení mod do mod.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05s05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch05s07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Komentáře </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Seznam operátorů GEL</td></tr></table></div></body></html> |