File: ch05s06.html

package info (click to toggle)
genius 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 25,308 kB
  • sloc: ansic: 75,620; xml: 71,565; sh: 4,445; makefile: 1,927; lex: 523; yacc: 298; perl: 54
file content (28 lines) | stat: -rw-r--r-- 4,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<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 &lt;celé_číslo&gt;“ 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">
	      The inverses of numbers mod some integer are computed by writing them as
rational numbers (as long as the desired inverse exists, of course).
Examples:
</p><pre lang="en" class="programlisting">10^-1 mod 101
1/10 mod 101</pre><p lang="en">
Modular evaluation also works with matrices including taking inverses,
powers, and dividing.
Example:
</p><pre lang="en" class="programlisting">A = [1,2;3,4]
B = A^-1 mod 5
A*B mod 5</pre><p lang="en">
This should yield the identity matrix as B will be the inverse of A mod 5.
      </p><p lang="en">
Some functions such as
<a class="link" href="ch11s05.html#gel-function-sqrt"><code class="function">sqrt</code></a> or
<a class="link" href="ch11s05.html#gel-function-log"><code class="function">log</code></a>
work in a different way when in modulo mode.  These will then work like their
discrete versions working within the ring of integers you selected.  For
example:
</p><pre lang="en" class="programlisting">genius&gt; sqrt(4) mod 7
=
[2, 5]
genius&gt; 2*2 mod 7
= 4</pre><p lang="en">
	<code class="function">sqrt</code> will actually return all the possible square
	roots.
      </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>