mirror of
https://git8.cs.fau.de/theses/bsc-leon-vatthauer.git
synced 2024-05-31 07:28:34 +02:00
136 lines
No EOL
23 KiB
HTML
136 lines
No EOL
23 KiB
HTML
<!DOCTYPE HTML>
|
|
<html><head><meta charset="utf-8"><title>Agda.Builtin.Nat</title><link rel="stylesheet" href="Agda.css"></head><body><pre class="Agda"><a id="1" class="Symbol">{-#</a> <a id="5" class="Keyword">OPTIONS</a> <a id="13" class="Pragma">--cubical-compatible</a> <a id="34" class="Pragma">--safe</a> <a id="41" class="Pragma">--no-universe-polymorphism</a>
|
|
<a id="80" class="Pragma">--no-sized-types</a> <a id="97" class="Pragma">--no-guardedness</a> <a id="114" class="Symbol">#-}</a>
|
|
|
|
<a id="119" class="Keyword">module</a> <a id="126" href="Agda.Builtin.Nat.html" class="Module">Agda.Builtin.Nat</a> <a id="143" class="Keyword">where</a>
|
|
|
|
<a id="150" class="Keyword">open</a> <a id="155" class="Keyword">import</a> <a id="162" href="Agda.Builtin.Bool.html" class="Module">Agda.Builtin.Bool</a>
|
|
|
|
<a id="181" class="Keyword">data</a> <a id="Nat"></a><a id="186" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="190" class="Symbol">:</a> <a id="192" href="Agda.Primitive.html#320" class="Primitive">Set</a> <a id="196" class="Keyword">where</a>
|
|
<a id="Nat.zero"></a><a id="204" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="209" class="Symbol">:</a> <a id="211" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
<a id="Nat.suc"></a><a id="217" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="222" class="Symbol">:</a> <a id="224" class="Symbol">(</a><a id="225" href="Agda.Builtin.Nat.html#225" class="Bound">n</a> <a id="227" class="Symbol">:</a> <a id="229" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a><a id="232" class="Symbol">)</a> <a id="234" class="Symbol">→</a> <a id="236" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
|
|
<a id="241" class="Symbol">{-#</a> <a id="245" class="Keyword">BUILTIN</a> <a id="253" class="Keyword">NATURAL</a> <a id="261" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="265" class="Symbol">#-}</a>
|
|
|
|
<a id="270" class="Keyword">infix</a> <a id="277" class="Number">4</a> <a id="279" href="Agda.Builtin.Nat.html#614" class="Primitive Operator">_==_</a> <a id="284" href="Agda.Builtin.Nat.html#740" class="Primitive Operator">_<_</a>
|
|
<a id="288" class="Keyword">infixl</a> <a id="295" class="Number">6</a> <a id="297" href="Agda.Builtin.Nat.html#319" class="Primitive Operator">_+_</a> <a id="301" href="Agda.Builtin.Nat.html#409" class="Primitive Operator">_-_</a>
|
|
<a id="305" class="Keyword">infixl</a> <a id="312" class="Number">7</a> <a id="314" href="Agda.Builtin.Nat.html#522" class="Primitive Operator">_*_</a>
|
|
|
|
<a id="_+_"></a><a id="319" href="Agda.Builtin.Nat.html#319" class="Function Operator">_+_</a> <a id="323" class="Symbol">:</a> <a id="325" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="329" class="Symbol">→</a> <a id="331" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="335" class="Symbol">→</a> <a id="337" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
<a id="341" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="347" href="Agda.Builtin.Nat.html#319" class="Function Operator">+</a> <a id="349" href="Agda.Builtin.Nat.html#349" class="Bound">m</a> <a id="351" class="Symbol">=</a> <a id="353" href="Agda.Builtin.Nat.html#349" class="Bound">m</a>
|
|
<a id="355" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="359" href="Agda.Builtin.Nat.html#359" class="Bound">n</a> <a id="361" href="Agda.Builtin.Nat.html#319" class="Function Operator">+</a> <a id="363" href="Agda.Builtin.Nat.html#363" class="Bound">m</a> <a id="365" class="Symbol">=</a> <a id="367" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="371" class="Symbol">(</a><a id="372" href="Agda.Builtin.Nat.html#359" class="Bound">n</a> <a id="374" href="Agda.Builtin.Nat.html#319" class="Function Operator">+</a> <a id="376" href="Agda.Builtin.Nat.html#363" class="Bound">m</a><a id="377" class="Symbol">)</a>
|
|
|
|
<a id="380" class="Symbol">{-#</a> <a id="384" class="Keyword">BUILTIN</a> <a id="392" class="Keyword">NATPLUS</a> <a id="400" href="Agda.Builtin.Nat.html#319" class="Primitive Operator">_+_</a> <a id="404" class="Symbol">#-}</a>
|
|
|
|
<a id="_-_"></a><a id="409" href="Agda.Builtin.Nat.html#409" class="Function Operator">_-_</a> <a id="413" class="Symbol">:</a> <a id="415" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="419" class="Symbol">→</a> <a id="421" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="425" class="Symbol">→</a> <a id="427" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
<a id="431" href="Agda.Builtin.Nat.html#431" class="Bound">n</a> <a id="437" href="Agda.Builtin.Nat.html#409" class="Function Operator">-</a> <a id="439" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="444" class="Symbol">=</a> <a id="446" href="Agda.Builtin.Nat.html#431" class="Bound">n</a>
|
|
<a id="448" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="454" href="Agda.Builtin.Nat.html#409" class="Function Operator">-</a> <a id="456" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="460" href="Agda.Builtin.Nat.html#460" class="Bound">m</a> <a id="462" class="Symbol">=</a> <a id="464" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a>
|
|
<a id="469" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="473" href="Agda.Builtin.Nat.html#473" class="Bound">n</a> <a id="475" href="Agda.Builtin.Nat.html#409" class="Function Operator">-</a> <a id="477" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="481" href="Agda.Builtin.Nat.html#481" class="Bound">m</a> <a id="483" class="Symbol">=</a> <a id="485" href="Agda.Builtin.Nat.html#473" class="Bound">n</a> <a id="487" href="Agda.Builtin.Nat.html#409" class="Function Operator">-</a> <a id="489" href="Agda.Builtin.Nat.html#481" class="Bound">m</a>
|
|
|
|
<a id="492" class="Symbol">{-#</a> <a id="496" class="Keyword">BUILTIN</a> <a id="504" class="Keyword">NATMINUS</a> <a id="513" href="Agda.Builtin.Nat.html#409" class="Primitive Operator">_-_</a> <a id="517" class="Symbol">#-}</a>
|
|
|
|
<a id="_*_"></a><a id="522" href="Agda.Builtin.Nat.html#522" class="Function Operator">_*_</a> <a id="526" class="Symbol">:</a> <a id="528" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="532" class="Symbol">→</a> <a id="534" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="538" class="Symbol">→</a> <a id="540" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
<a id="544" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="550" href="Agda.Builtin.Nat.html#522" class="Function Operator">*</a> <a id="552" href="Agda.Builtin.Nat.html#552" class="Bound">m</a> <a id="554" class="Symbol">=</a> <a id="556" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a>
|
|
<a id="561" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="565" href="Agda.Builtin.Nat.html#565" class="Bound">n</a> <a id="567" href="Agda.Builtin.Nat.html#522" class="Function Operator">*</a> <a id="569" href="Agda.Builtin.Nat.html#569" class="Bound">m</a> <a id="571" class="Symbol">=</a> <a id="573" href="Agda.Builtin.Nat.html#569" class="Bound">m</a> <a id="575" href="Agda.Builtin.Nat.html#319" class="Primitive Operator">+</a> <a id="577" href="Agda.Builtin.Nat.html#565" class="Bound">n</a> <a id="579" href="Agda.Builtin.Nat.html#522" class="Function Operator">*</a> <a id="581" href="Agda.Builtin.Nat.html#569" class="Bound">m</a>
|
|
|
|
<a id="584" class="Symbol">{-#</a> <a id="588" class="Keyword">BUILTIN</a> <a id="596" class="Keyword">NATTIMES</a> <a id="605" href="Agda.Builtin.Nat.html#522" class="Primitive Operator">_*_</a> <a id="609" class="Symbol">#-}</a>
|
|
|
|
<a id="_==_"></a><a id="614" href="Agda.Builtin.Nat.html#614" class="Function Operator">_==_</a> <a id="619" class="Symbol">:</a> <a id="621" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="625" class="Symbol">→</a> <a id="627" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="631" class="Symbol">→</a> <a id="633" href="Agda.Builtin.Bool.html#156" class="Datatype">Bool</a>
|
|
<a id="638" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="644" href="Agda.Builtin.Nat.html#614" class="Function Operator">==</a> <a id="647" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="653" class="Symbol">=</a> <a id="655" href="Agda.Builtin.Bool.html#181" class="InductiveConstructor">true</a>
|
|
<a id="660" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="664" href="Agda.Builtin.Nat.html#664" class="Bound">n</a> <a id="666" href="Agda.Builtin.Nat.html#614" class="Function Operator">==</a> <a id="669" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="673" href="Agda.Builtin.Nat.html#673" class="Bound">m</a> <a id="675" class="Symbol">=</a> <a id="677" href="Agda.Builtin.Nat.html#664" class="Bound">n</a> <a id="679" href="Agda.Builtin.Nat.html#614" class="Function Operator">==</a> <a id="682" href="Agda.Builtin.Nat.html#673" class="Bound">m</a>
|
|
<a id="684" class="CatchallClause Symbol">_</a><a id="685" class="CatchallClause"> </a><a id="690" href="Agda.Builtin.Nat.html#614" class="CatchallClause Function Operator">==</a><a id="692" class="CatchallClause"> </a><a id="693" class="CatchallClause Symbol">_</a> <a id="699" class="Symbol">=</a> <a id="701" href="Agda.Builtin.Bool.html#175" class="InductiveConstructor">false</a>
|
|
|
|
<a id="708" class="Symbol">{-#</a> <a id="712" class="Keyword">BUILTIN</a> <a id="720" class="Keyword">NATEQUALS</a> <a id="730" href="Agda.Builtin.Nat.html#614" class="Primitive Operator">_==_</a> <a id="735" class="Symbol">#-}</a>
|
|
|
|
<a id="_<_"></a><a id="740" href="Agda.Builtin.Nat.html#740" class="Function Operator">_<_</a> <a id="744" class="Symbol">:</a> <a id="746" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="750" class="Symbol">→</a> <a id="752" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a> <a id="756" class="Symbol">→</a> <a id="758" href="Agda.Builtin.Bool.html#156" class="Datatype">Bool</a>
|
|
<a id="763" class="Symbol">_</a> <a id="769" href="Agda.Builtin.Nat.html#740" class="Function Operator"><</a> <a id="771" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="777" class="Symbol">=</a> <a id="779" href="Agda.Builtin.Bool.html#175" class="InductiveConstructor">false</a>
|
|
<a id="785" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="791" href="Agda.Builtin.Nat.html#740" class="Function Operator"><</a> <a id="793" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="797" class="Symbol">_</a> <a id="799" class="Symbol">=</a> <a id="801" href="Agda.Builtin.Bool.html#181" class="InductiveConstructor">true</a>
|
|
<a id="806" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="810" href="Agda.Builtin.Nat.html#810" class="Bound">n</a> <a id="812" href="Agda.Builtin.Nat.html#740" class="Function Operator"><</a> <a id="814" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="818" href="Agda.Builtin.Nat.html#818" class="Bound">m</a> <a id="820" class="Symbol">=</a> <a id="822" href="Agda.Builtin.Nat.html#810" class="Bound">n</a> <a id="824" href="Agda.Builtin.Nat.html#740" class="Function Operator"><</a> <a id="826" href="Agda.Builtin.Nat.html#818" class="Bound">m</a>
|
|
|
|
<a id="829" class="Symbol">{-#</a> <a id="833" class="Keyword">BUILTIN</a> <a id="841" class="Keyword">NATLESS</a> <a id="849" href="Agda.Builtin.Nat.html#740" class="Primitive Operator">_<_</a> <a id="853" class="Symbol">#-}</a>
|
|
|
|
<a id="858" class="Comment">-- Helper function div-helper for Euclidean division.</a>
|
|
<a id="914" class="Comment">---------------------------------------------------------------------------</a>
|
|
<a id="990" class="Comment">--</a>
|
|
<a id="993" class="Comment">-- div-helper computes n / 1+m via iteration on n.</a>
|
|
<a id="1044" class="Comment">--</a>
|
|
<a id="1047" class="Comment">-- n div (suc m) = div-helper 0 m n m</a>
|
|
<a id="1087" class="Comment">--</a>
|
|
<a id="1090" class="Comment">-- The state of the iterator has two accumulator variables:</a>
|
|
<a id="1150" class="Comment">--</a>
|
|
<a id="1153" class="Comment">-- k: The quotient, returned once n=0. Initialized to 0.</a>
|
|
<a id="1213" class="Comment">--</a>
|
|
<a id="1216" class="Comment">-- j: A counter, initialized to the divisor m, decreased on each iteration step.</a>
|
|
<a id="1299" class="Comment">-- Once it reaches 0, the quotient k is increased and j reset to m,</a>
|
|
<a id="1372" class="Comment">-- starting the next countdown.</a>
|
|
<a id="1409" class="Comment">--</a>
|
|
<a id="1412" class="Comment">-- Under the precondition j ≤ m, the invariant is</a>
|
|
<a id="1462" class="Comment">--</a>
|
|
<a id="1465" class="Comment">-- div-helper k m n j = k + (n + m - j) div (1 + m)</a>
|
|
|
|
<a id="div-helper"></a><a id="1520" href="Agda.Builtin.Nat.html#1520" class="Function">div-helper</a> <a id="1531" class="Symbol">:</a> <a id="1533" class="Symbol">(</a><a id="1534" href="Agda.Builtin.Nat.html#1534" class="Bound">k</a> <a id="1536" href="Agda.Builtin.Nat.html#1536" class="Bound">m</a> <a id="1538" href="Agda.Builtin.Nat.html#1538" class="Bound">n</a> <a id="1540" href="Agda.Builtin.Nat.html#1540" class="Bound">j</a> <a id="1542" class="Symbol">:</a> <a id="1544" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a><a id="1547" class="Symbol">)</a> <a id="1549" class="Symbol">→</a> <a id="1551" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
<a id="1555" href="Agda.Builtin.Nat.html#1520" class="Function">div-helper</a> <a id="1566" href="Agda.Builtin.Nat.html#1566" class="Bound">k</a> <a id="1568" href="Agda.Builtin.Nat.html#1568" class="Bound">m</a> <a id="1571" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="1579" href="Agda.Builtin.Nat.html#1579" class="Bound">j</a> <a id="1586" class="Symbol">=</a> <a id="1588" href="Agda.Builtin.Nat.html#1566" class="Bound">k</a>
|
|
<a id="1590" href="Agda.Builtin.Nat.html#1520" class="Function">div-helper</a> <a id="1601" href="Agda.Builtin.Nat.html#1601" class="Bound">k</a> <a id="1603" href="Agda.Builtin.Nat.html#1603" class="Bound">m</a> <a id="1605" class="Symbol">(</a><a id="1606" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="1610" href="Agda.Builtin.Nat.html#1610" class="Bound">n</a><a id="1611" class="Symbol">)</a> <a id="1614" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="1621" class="Symbol">=</a> <a id="1623" href="Agda.Builtin.Nat.html#1520" class="Function">div-helper</a> <a id="1634" class="Symbol">(</a><a id="1635" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="1639" href="Agda.Builtin.Nat.html#1601" class="Bound">k</a><a id="1640" class="Symbol">)</a> <a id="1642" href="Agda.Builtin.Nat.html#1603" class="Bound">m</a> <a id="1644" href="Agda.Builtin.Nat.html#1610" class="Bound">n</a> <a id="1646" href="Agda.Builtin.Nat.html#1603" class="Bound">m</a>
|
|
<a id="1648" href="Agda.Builtin.Nat.html#1520" class="Function">div-helper</a> <a id="1659" href="Agda.Builtin.Nat.html#1659" class="Bound">k</a> <a id="1661" href="Agda.Builtin.Nat.html#1661" class="Bound">m</a> <a id="1663" class="Symbol">(</a><a id="1664" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="1668" href="Agda.Builtin.Nat.html#1668" class="Bound">n</a><a id="1669" class="Symbol">)</a> <a id="1671" class="Symbol">(</a><a id="1672" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="1676" href="Agda.Builtin.Nat.html#1676" class="Bound">j</a><a id="1677" class="Symbol">)</a> <a id="1679" class="Symbol">=</a> <a id="1681" href="Agda.Builtin.Nat.html#1520" class="Function">div-helper</a> <a id="1692" href="Agda.Builtin.Nat.html#1659" class="Bound">k</a> <a id="1700" href="Agda.Builtin.Nat.html#1661" class="Bound">m</a> <a id="1702" href="Agda.Builtin.Nat.html#1668" class="Bound">n</a> <a id="1704" href="Agda.Builtin.Nat.html#1676" class="Bound">j</a>
|
|
|
|
<a id="1707" class="Symbol">{-#</a> <a id="1711" class="Keyword">BUILTIN</a> <a id="1719" class="Keyword">NATDIVSUCAUX</a> <a id="1732" href="Agda.Builtin.Nat.html#1520" class="Primitive">div-helper</a> <a id="1743" class="Symbol">#-}</a>
|
|
|
|
<a id="1748" class="Comment">-- Proof of the invariant by induction on n.</a>
|
|
<a id="1793" class="Comment">--</a>
|
|
<a id="1796" class="Comment">-- clause 1: div-helper k m 0 j</a>
|
|
<a id="1830" class="Comment">-- = k by definition</a>
|
|
<a id="1900" class="Comment">-- = k + (0 + m - j) div (1 + m) since m - j < 1 + m</a>
|
|
<a id="1976" class="Comment">--</a>
|
|
<a id="1979" class="Comment">-- clause 2: div-helper k m (1 + n) 0</a>
|
|
<a id="2019" class="Comment">-- = div-helper (1 + k) m n m by definition</a>
|
|
<a id="2089" class="Comment">-- = 1 + k + (n + m - m) div (1 + m) by induction hypothesis</a>
|
|
<a id="2169" class="Comment">-- = 1 + k + n div (1 + m) by simplification</a>
|
|
<a id="2243" class="Comment">-- = k + (n + (1 + m)) div (1 + m) by expansion</a>
|
|
<a id="2312" class="Comment">-- = k + (1 + n + m - 0) div (1 + m) by expansion</a>
|
|
<a id="2381" class="Comment">--</a>
|
|
<a id="2384" class="Comment">-- clause 3: div-helper k m (1 + n) (1 + j)</a>
|
|
<a id="2430" class="Comment">-- = div-helper k m n j by definition</a>
|
|
<a id="2500" class="Comment">-- = k + (n + m - j) div (1 + m) by induction hypothesis</a>
|
|
<a id="2580" class="Comment">-- = k + ((1 + n) + m - (1 + j)) div (1 + m) by expansion</a>
|
|
<a id="2649" class="Comment">--</a>
|
|
<a id="2652" class="Comment">-- Q.e.d.</a>
|
|
|
|
<a id="2663" class="Comment">-- Helper function mod-helper for the remainder computation.</a>
|
|
<a id="2726" class="Comment">---------------------------------------------------------------------------</a>
|
|
<a id="2802" class="Comment">--</a>
|
|
<a id="2805" class="Comment">-- (Analogous to div-helper.)</a>
|
|
<a id="2835" class="Comment">--</a>
|
|
<a id="2838" class="Comment">-- mod-helper computes n % 1+m via iteration on n.</a>
|
|
<a id="2889" class="Comment">--</a>
|
|
<a id="2892" class="Comment">-- n mod (suc m) = mod-helper 0 m n m</a>
|
|
<a id="2932" class="Comment">--</a>
|
|
<a id="2935" class="Comment">-- The invariant is:</a>
|
|
<a id="2956" class="Comment">--</a>
|
|
<a id="2959" class="Comment">-- m = k + j ==> mod-helper k m n j = (n + k) mod (1 + m).</a>
|
|
|
|
<a id="mod-helper"></a><a id="3023" href="Agda.Builtin.Nat.html#3023" class="Function">mod-helper</a> <a id="3034" class="Symbol">:</a> <a id="3036" class="Symbol">(</a><a id="3037" href="Agda.Builtin.Nat.html#3037" class="Bound">k</a> <a id="3039" href="Agda.Builtin.Nat.html#3039" class="Bound">m</a> <a id="3041" href="Agda.Builtin.Nat.html#3041" class="Bound">n</a> <a id="3043" href="Agda.Builtin.Nat.html#3043" class="Bound">j</a> <a id="3045" class="Symbol">:</a> <a id="3047" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a><a id="3050" class="Symbol">)</a> <a id="3052" class="Symbol">→</a> <a id="3054" href="Agda.Builtin.Nat.html#186" class="Datatype">Nat</a>
|
|
<a id="3058" href="Agda.Builtin.Nat.html#3023" class="Function">mod-helper</a> <a id="3069" href="Agda.Builtin.Nat.html#3069" class="Bound">k</a> <a id="3071" href="Agda.Builtin.Nat.html#3071" class="Bound">m</a> <a id="3074" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="3082" href="Agda.Builtin.Nat.html#3082" class="Bound">j</a> <a id="3089" class="Symbol">=</a> <a id="3091" href="Agda.Builtin.Nat.html#3069" class="Bound">k</a>
|
|
<a id="3093" href="Agda.Builtin.Nat.html#3023" class="Function">mod-helper</a> <a id="3104" href="Agda.Builtin.Nat.html#3104" class="Bound">k</a> <a id="3106" href="Agda.Builtin.Nat.html#3106" class="Bound">m</a> <a id="3108" class="Symbol">(</a><a id="3109" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="3113" href="Agda.Builtin.Nat.html#3113" class="Bound">n</a><a id="3114" class="Symbol">)</a> <a id="3117" href="Agda.Builtin.Nat.html#204" class="InductiveConstructor">zero</a> <a id="3124" class="Symbol">=</a> <a id="3126" href="Agda.Builtin.Nat.html#3023" class="Function">mod-helper</a> <a id="3137" class="Number">0</a> <a id="3145" href="Agda.Builtin.Nat.html#3106" class="Bound">m</a> <a id="3147" href="Agda.Builtin.Nat.html#3113" class="Bound">n</a> <a id="3149" href="Agda.Builtin.Nat.html#3106" class="Bound">m</a>
|
|
<a id="3151" href="Agda.Builtin.Nat.html#3023" class="Function">mod-helper</a> <a id="3162" href="Agda.Builtin.Nat.html#3162" class="Bound">k</a> <a id="3164" href="Agda.Builtin.Nat.html#3164" class="Bound">m</a> <a id="3166" class="Symbol">(</a><a id="3167" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="3171" href="Agda.Builtin.Nat.html#3171" class="Bound">n</a><a id="3172" class="Symbol">)</a> <a id="3174" class="Symbol">(</a><a id="3175" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="3179" href="Agda.Builtin.Nat.html#3179" class="Bound">j</a><a id="3180" class="Symbol">)</a> <a id="3182" class="Symbol">=</a> <a id="3184" href="Agda.Builtin.Nat.html#3023" class="Function">mod-helper</a> <a id="3195" class="Symbol">(</a><a id="3196" href="Agda.Builtin.Nat.html#217" class="InductiveConstructor">suc</a> <a id="3200" href="Agda.Builtin.Nat.html#3162" class="Bound">k</a><a id="3201" class="Symbol">)</a> <a id="3203" href="Agda.Builtin.Nat.html#3164" class="Bound">m</a> <a id="3205" href="Agda.Builtin.Nat.html#3171" class="Bound">n</a> <a id="3207" href="Agda.Builtin.Nat.html#3179" class="Bound">j</a>
|
|
|
|
<a id="3210" class="Symbol">{-#</a> <a id="3214" class="Keyword">BUILTIN</a> <a id="3222" class="Keyword">NATMODSUCAUX</a> <a id="3235" href="Agda.Builtin.Nat.html#3023" class="Primitive">mod-helper</a> <a id="3246" class="Symbol">#-}</a>
|
|
|
|
<a id="3251" class="Comment">-- Proof of the invariant by induction on n.</a>
|
|
<a id="3296" class="Comment">--</a>
|
|
<a id="3299" class="Comment">-- clause 1: mod-helper k m 0 j</a>
|
|
<a id="3333" class="Comment">-- = k by definition</a>
|
|
<a id="3394" class="Comment">-- = (0 + k) mod (1 + m) since m = k + j, thus k < m</a>
|
|
<a id="3469" class="Comment">--</a>
|
|
<a id="3472" class="Comment">-- clause 2: mod-helper k m (1 + n) 0</a>
|
|
<a id="3512" class="Comment">-- = mod-helper 0 m n m by definition</a>
|
|
<a id="3573" class="Comment">-- = (n + 0) mod (1 + m) by induction hypothesis</a>
|
|
<a id="3644" class="Comment">-- = (n + (1 + m)) mod (1 + m) by expansion</a>
|
|
<a id="3704" class="Comment">-- = (1 + n) + k) mod (1 + m) since k = m (as l = 0)</a>
|
|
<a id="3774" class="Comment">--</a>
|
|
<a id="3777" class="Comment">-- clause 3: mod-helper k m (1 + n) (1 + j)</a>
|
|
<a id="3823" class="Comment">-- = mod-helper (1 + k) m n j by definition</a>
|
|
<a id="3884" class="Comment">-- = (n + (1 + k)) mod (1 + m) by induction hypothesis</a>
|
|
<a id="3955" class="Comment">-- = ((1 + n) + k) mod (1 + m) by commutativity</a>
|
|
<a id="4019" class="Comment">--</a>
|
|
<a id="4022" class="Comment">-- Q.e.d.</a>
|
|
</pre></body></html> |