bsc-leon-vatthauer/agda/bsc-thesis/Induction.html
2024-02-09 17:53:52 +01:00

63 lines
No EOL
18 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML>
<html><head><meta charset="utf-8"><title>Induction</title><link rel="stylesheet" href="Agda.css"></head><body><pre class="Agda"><a id="1" class="Comment">------------------------------------------------------------------------</a>
<a id="74" class="Comment">-- The Agda standard library</a>
<a id="103" class="Comment">--</a>
<a id="106" class="Comment">-- An abstraction of various forms of recursion/induction</a>
<a id="164" class="Comment">------------------------------------------------------------------------</a>
<a id="238" class="Comment">-- The idea underlying Induction.* comes from Epigram 1, see Section 4</a>
<a id="309" class="Comment">-- of &quot;The view from the left&quot; by McBride and McKinna.</a>
<a id="365" class="Comment">-- Note: The types in this module can perhaps be easier to understand</a>
<a id="435" class="Comment">-- if they are normalised. Note also that Agda can do the</a>
<a id="493" class="Comment">-- normalisation for you.</a>
<a id="520" class="Symbol">{-#</a> <a id="524" class="Keyword">OPTIONS</a> <a id="532" class="Pragma">--cubical-compatible</a> <a id="553" class="Pragma">--safe</a> <a id="560" class="Symbol">#-}</a>
<a id="565" class="Keyword">module</a> <a id="572" href="Induction.html" class="Module">Induction</a> <a id="582" class="Keyword">where</a>
<a id="589" class="Keyword">open</a> <a id="594" class="Keyword">import</a> <a id="601" href="Level.html" class="Module">Level</a>
<a id="607" class="Keyword">open</a> <a id="612" class="Keyword">import</a> <a id="619" href="Relation.Unary.html" class="Module">Relation.Unary</a>
<a id="635" class="Comment">-- A RecStruct describes the allowed structure of recursion. The</a>
<a id="700" class="Comment">-- examples in Data.Nat.Induction should explain what this is all</a>
<a id="766" class="Comment">-- about.</a>
<a id="RecStruct"></a><a id="777" href="Induction.html#777" class="Function">RecStruct</a> <a id="787" class="Symbol">:</a> <a id="789" class="Symbol"></a> <a id="791" class="Symbol">{</a><a id="792" href="Induction.html#792" class="Bound">a</a><a id="793" class="Symbol">}</a> <a id="795" class="Symbol"></a> <a id="797" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="801" href="Induction.html#792" class="Bound">a</a> <a id="803" class="Symbol"></a> <a id="805" class="Symbol">(</a><a id="806" href="Induction.html#806" class="Bound">ℓ₁</a> <a id="809" href="Induction.html#809" class="Bound">ℓ₂</a> <a id="812" class="Symbol">:</a> <a id="814" href="Agda.Primitive.html#742" class="Postulate">Level</a><a id="819" class="Symbol">)</a> <a id="821" class="Symbol"></a> <a id="823" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="827" class="Symbol">_</a>
<a id="829" href="Induction.html#777" class="Function">RecStruct</a> <a id="839" href="Induction.html#839" class="Bound">A</a> <a id="841" href="Induction.html#841" class="Bound">ℓ₁</a> <a id="844" href="Induction.html#844" class="Bound">ℓ₂</a> <a id="847" class="Symbol">=</a> <a id="849" href="Relation.Unary.html#1232" class="Function">Pred</a> <a id="854" href="Induction.html#839" class="Bound">A</a> <a id="856" href="Induction.html#841" class="Bound">ℓ₁</a> <a id="859" class="Symbol"></a> <a id="861" href="Relation.Unary.html#1232" class="Function">Pred</a> <a id="866" href="Induction.html#839" class="Bound">A</a> <a id="868" href="Induction.html#844" class="Bound">ℓ₂</a>
<a id="872" class="Comment">-- A recursor builder constructs an instance of a recursion structure</a>
<a id="942" class="Comment">-- for a given input.</a>
<a id="RecursorBuilder"></a><a id="965" href="Induction.html#965" class="Function">RecursorBuilder</a> <a id="981" class="Symbol">:</a> <a id="983" class="Symbol"></a> <a id="985" class="Symbol">{</a><a id="986" href="Induction.html#986" class="Bound">a</a> <a id="988" href="Induction.html#988" class="Bound">ℓ₁</a> <a id="991" href="Induction.html#991" class="Bound">ℓ₂</a><a id="993" class="Symbol">}</a> <a id="995" class="Symbol">{</a><a id="996" href="Induction.html#996" class="Bound">A</a> <a id="998" class="Symbol">:</a> <a id="1000" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1004" href="Induction.html#986" class="Bound">a</a><a id="1005" class="Symbol">}</a> <a id="1007" class="Symbol"></a> <a id="1009" href="Induction.html#777" class="Function">RecStruct</a> <a id="1019" href="Induction.html#996" class="Bound">A</a> <a id="1021" href="Induction.html#988" class="Bound">ℓ₁</a> <a id="1024" href="Induction.html#991" class="Bound">ℓ₂</a> <a id="1027" class="Symbol"></a> <a id="1029" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1033" class="Symbol">_</a>
<a id="1035" href="Induction.html#965" class="Function">RecursorBuilder</a> <a id="1051" href="Induction.html#1051" class="Bound">Rec</a> <a id="1055" class="Symbol">=</a> <a id="1057" class="Symbol"></a> <a id="1059" href="Induction.html#1059" class="Bound">P</a> <a id="1061" class="Symbol"></a> <a id="1063" href="Induction.html#1051" class="Bound">Rec</a> <a id="1067" href="Induction.html#1059" class="Bound">P</a> <a id="1069" href="Relation.Unary.html#2539" class="Function Operator">⊆′</a> <a id="1072" href="Induction.html#1059" class="Bound">P</a> <a id="1074" class="Symbol"></a> <a id="1076" href="Relation.Unary.html#3491" class="Function">Universal</a> <a id="1086" class="Symbol">(</a><a id="1087" href="Induction.html#1051" class="Bound">Rec</a> <a id="1091" href="Induction.html#1059" class="Bound">P</a><a id="1092" class="Symbol">)</a>
<a id="1095" class="Comment">-- A recursor can be used to actually compute/prove something useful.</a>
<a id="Recursor"></a><a id="1166" href="Induction.html#1166" class="Function">Recursor</a> <a id="1175" class="Symbol">:</a> <a id="1177" class="Symbol"></a> <a id="1179" class="Symbol">{</a><a id="1180" href="Induction.html#1180" class="Bound">a</a> <a id="1182" href="Induction.html#1182" class="Bound">ℓ₁</a> <a id="1185" href="Induction.html#1185" class="Bound">ℓ₂</a><a id="1187" class="Symbol">}</a> <a id="1189" class="Symbol">{</a><a id="1190" href="Induction.html#1190" class="Bound">A</a> <a id="1192" class="Symbol">:</a> <a id="1194" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1198" href="Induction.html#1180" class="Bound">a</a><a id="1199" class="Symbol">}</a> <a id="1201" class="Symbol"></a> <a id="1203" href="Induction.html#777" class="Function">RecStruct</a> <a id="1213" href="Induction.html#1190" class="Bound">A</a> <a id="1215" href="Induction.html#1182" class="Bound">ℓ₁</a> <a id="1218" href="Induction.html#1185" class="Bound">ℓ₂</a> <a id="1221" class="Symbol"></a> <a id="1223" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1227" class="Symbol">_</a>
<a id="1229" href="Induction.html#1166" class="Function">Recursor</a> <a id="1238" href="Induction.html#1238" class="Bound">Rec</a> <a id="1242" class="Symbol">=</a> <a id="1244" class="Symbol"></a> <a id="1246" href="Induction.html#1246" class="Bound">P</a> <a id="1248" class="Symbol"></a> <a id="1250" href="Induction.html#1238" class="Bound">Rec</a> <a id="1254" href="Induction.html#1246" class="Bound">P</a> <a id="1256" href="Relation.Unary.html#2539" class="Function Operator">⊆′</a> <a id="1259" href="Induction.html#1246" class="Bound">P</a> <a id="1261" class="Symbol"></a> <a id="1263" href="Relation.Unary.html#3491" class="Function">Universal</a> <a id="1273" href="Induction.html#1246" class="Bound">P</a>
<a id="1276" class="Comment">-- And recursors can be constructed from recursor builders.</a>
<a id="build"></a><a id="1337" href="Induction.html#1337" class="Function">build</a> <a id="1343" class="Symbol">:</a> <a id="1345" class="Symbol"></a> <a id="1347" class="Symbol">{</a><a id="1348" href="Induction.html#1348" class="Bound">a</a> <a id="1350" href="Induction.html#1350" class="Bound">ℓ₁</a> <a id="1353" href="Induction.html#1353" class="Bound">ℓ₂</a><a id="1355" class="Symbol">}</a> <a id="1357" class="Symbol">{</a><a id="1358" href="Induction.html#1358" class="Bound">A</a> <a id="1360" class="Symbol">:</a> <a id="1362" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1366" href="Induction.html#1348" class="Bound">a</a><a id="1367" class="Symbol">}</a> <a id="1369" class="Symbol">{</a><a id="1370" href="Induction.html#1370" class="Bound">Rec</a> <a id="1374" class="Symbol">:</a> <a id="1376" href="Induction.html#777" class="Function">RecStruct</a> <a id="1386" href="Induction.html#1358" class="Bound">A</a> <a id="1388" href="Induction.html#1350" class="Bound">ℓ₁</a> <a id="1391" href="Induction.html#1353" class="Bound">ℓ₂</a><a id="1393" class="Symbol">}</a> <a id="1395" class="Symbol"></a>
<a id="1405" href="Induction.html#965" class="Function">RecursorBuilder</a> <a id="1421" href="Induction.html#1370" class="Bound">Rec</a> <a id="1425" class="Symbol"></a>
<a id="1435" href="Induction.html#1166" class="Function">Recursor</a> <a id="1444" href="Induction.html#1370" class="Bound">Rec</a>
<a id="1448" href="Induction.html#1337" class="Function">build</a> <a id="1454" href="Induction.html#1454" class="Bound">builder</a> <a id="1462" href="Induction.html#1462" class="Bound">P</a> <a id="1464" href="Induction.html#1464" class="Bound">f</a> <a id="1466" href="Induction.html#1466" class="Bound">x</a> <a id="1468" class="Symbol">=</a> <a id="1470" href="Induction.html#1464" class="Bound">f</a> <a id="1472" href="Induction.html#1466" class="Bound">x</a> <a id="1474" class="Symbol">(</a><a id="1475" href="Induction.html#1454" class="Bound">builder</a> <a id="1483" href="Induction.html#1462" class="Bound">P</a> <a id="1485" href="Induction.html#1464" class="Bound">f</a> <a id="1487" href="Induction.html#1466" class="Bound">x</a><a id="1488" class="Symbol">)</a>
<a id="1491" class="Comment">-- We can repeat the exercise above for subsets of the type we are</a>
<a id="1558" class="Comment">-- recursing over.</a>
<a id="SubsetRecursorBuilder"></a><a id="1578" href="Induction.html#1578" class="Function">SubsetRecursorBuilder</a> <a id="1600" class="Symbol">:</a> <a id="1602" class="Symbol"></a> <a id="1604" class="Symbol">{</a><a id="1605" href="Induction.html#1605" class="Bound">a</a> <a id="1607" href="Induction.html#1607" class="Bound">ℓ₁</a> <a id="1610" href="Induction.html#1610" class="Bound">ℓ₂</a> <a id="1613" href="Induction.html#1613" class="Bound">ℓ₃</a><a id="1615" class="Symbol">}</a> <a id="1617" class="Symbol">{</a><a id="1618" href="Induction.html#1618" class="Bound">A</a> <a id="1620" class="Symbol">:</a> <a id="1622" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1626" href="Induction.html#1605" class="Bound">a</a><a id="1627" class="Symbol">}</a> <a id="1629" class="Symbol"></a>
<a id="1655" href="Relation.Unary.html#1232" class="Function">Pred</a> <a id="1660" href="Induction.html#1618" class="Bound">A</a> <a id="1662" href="Induction.html#1607" class="Bound">ℓ₁</a> <a id="1665" class="Symbol"></a> <a id="1667" href="Induction.html#777" class="Function">RecStruct</a> <a id="1677" href="Induction.html#1618" class="Bound">A</a> <a id="1679" href="Induction.html#1610" class="Bound">ℓ₂</a> <a id="1682" href="Induction.html#1613" class="Bound">ℓ₃</a> <a id="1685" class="Symbol"></a> <a id="1687" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1691" class="Symbol">_</a>
<a id="1693" href="Induction.html#1578" class="Function">SubsetRecursorBuilder</a> <a id="1715" href="Induction.html#1715" class="Bound">Q</a> <a id="1717" href="Induction.html#1717" class="Bound">Rec</a> <a id="1721" class="Symbol">=</a> <a id="1723" class="Symbol"></a> <a id="1725" href="Induction.html#1725" class="Bound">P</a> <a id="1727" class="Symbol"></a> <a id="1729" href="Induction.html#1717" class="Bound">Rec</a> <a id="1733" href="Induction.html#1725" class="Bound">P</a> <a id="1735" href="Relation.Unary.html#2539" class="Function Operator">⊆′</a> <a id="1738" href="Induction.html#1725" class="Bound">P</a> <a id="1740" class="Symbol"></a> <a id="1742" href="Induction.html#1715" class="Bound">Q</a> <a id="1744" href="Relation.Unary.html#2539" class="Function Operator">⊆′</a> <a id="1747" href="Induction.html#1717" class="Bound">Rec</a> <a id="1751" href="Induction.html#1725" class="Bound">P</a>
<a id="SubsetRecursor"></a><a id="1754" href="Induction.html#1754" class="Function">SubsetRecursor</a> <a id="1769" class="Symbol">:</a> <a id="1771" class="Symbol"></a> <a id="1773" class="Symbol">{</a><a id="1774" href="Induction.html#1774" class="Bound">a</a> <a id="1776" href="Induction.html#1776" class="Bound">ℓ₁</a> <a id="1779" href="Induction.html#1779" class="Bound">ℓ₂</a> <a id="1782" href="Induction.html#1782" class="Bound">ℓ₃</a><a id="1784" class="Symbol">}</a> <a id="1786" class="Symbol">{</a><a id="1787" href="Induction.html#1787" class="Bound">A</a> <a id="1789" class="Symbol">:</a> <a id="1791" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1795" href="Induction.html#1774" class="Bound">a</a><a id="1796" class="Symbol">}</a> <a id="1798" class="Symbol"></a>
<a id="1817" href="Relation.Unary.html#1232" class="Function">Pred</a> <a id="1822" href="Induction.html#1787" class="Bound">A</a> <a id="1824" href="Induction.html#1776" class="Bound">ℓ₁</a> <a id="1827" class="Symbol"></a> <a id="1829" href="Induction.html#777" class="Function">RecStruct</a> <a id="1839" href="Induction.html#1787" class="Bound">A</a> <a id="1841" href="Induction.html#1779" class="Bound">ℓ₂</a> <a id="1844" href="Induction.html#1782" class="Bound">ℓ₃</a> <a id="1847" class="Symbol"></a> <a id="1849" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1853" class="Symbol">_</a>
<a id="1855" href="Induction.html#1754" class="Function">SubsetRecursor</a> <a id="1870" href="Induction.html#1870" class="Bound">Q</a> <a id="1872" href="Induction.html#1872" class="Bound">Rec</a> <a id="1876" class="Symbol">=</a> <a id="1878" class="Symbol"></a> <a id="1880" href="Induction.html#1880" class="Bound">P</a> <a id="1882" class="Symbol"></a> <a id="1884" href="Induction.html#1872" class="Bound">Rec</a> <a id="1888" href="Induction.html#1880" class="Bound">P</a> <a id="1890" href="Relation.Unary.html#2539" class="Function Operator">⊆′</a> <a id="1893" href="Induction.html#1880" class="Bound">P</a> <a id="1895" class="Symbol"></a> <a id="1897" href="Induction.html#1870" class="Bound">Q</a> <a id="1899" href="Relation.Unary.html#2539" class="Function Operator">⊆′</a> <a id="1902" href="Induction.html#1880" class="Bound">P</a>
<a id="subsetBuild"></a><a id="1905" href="Induction.html#1905" class="Function">subsetBuild</a> <a id="1917" class="Symbol">:</a> <a id="1919" class="Symbol"></a> <a id="1921" class="Symbol">{</a><a id="1922" href="Induction.html#1922" class="Bound">a</a> <a id="1924" href="Induction.html#1924" class="Bound">ℓ₁</a> <a id="1927" href="Induction.html#1927" class="Bound">ℓ₂</a> <a id="1930" href="Induction.html#1930" class="Bound">ℓ₃</a><a id="1932" class="Symbol">}</a>
<a id="1950" class="Symbol">{</a><a id="1951" href="Induction.html#1951" class="Bound">A</a> <a id="1953" class="Symbol">:</a> <a id="1955" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1959" href="Induction.html#1922" class="Bound">a</a><a id="1960" class="Symbol">}</a> <a id="1962" class="Symbol">{</a><a id="1963" href="Induction.html#1963" class="Bound">Q</a> <a id="1965" class="Symbol">:</a> <a id="1967" href="Relation.Unary.html#1232" class="Function">Pred</a> <a id="1972" href="Induction.html#1951" class="Bound">A</a> <a id="1974" href="Induction.html#1924" class="Bound">ℓ₁</a><a id="1976" class="Symbol">}</a> <a id="1978" class="Symbol">{</a><a id="1979" href="Induction.html#1979" class="Bound">Rec</a> <a id="1983" class="Symbol">:</a> <a id="1985" href="Induction.html#777" class="Function">RecStruct</a> <a id="1995" href="Induction.html#1951" class="Bound">A</a> <a id="1997" href="Induction.html#1927" class="Bound">ℓ₂</a> <a id="2000" href="Induction.html#1930" class="Bound">ℓ₃</a><a id="2002" class="Symbol">}</a> <a id="2004" class="Symbol"></a>
<a id="2022" href="Induction.html#1578" class="Function">SubsetRecursorBuilder</a> <a id="2044" href="Induction.html#1963" class="Bound">Q</a> <a id="2046" href="Induction.html#1979" class="Bound">Rec</a> <a id="2050" class="Symbol"></a>
<a id="2068" href="Induction.html#1754" class="Function">SubsetRecursor</a> <a id="2083" href="Induction.html#1963" class="Bound">Q</a> <a id="2085" href="Induction.html#1979" class="Bound">Rec</a>
<a id="2089" href="Induction.html#1905" class="Function">subsetBuild</a> <a id="2101" href="Induction.html#2101" class="Bound">builder</a> <a id="2109" href="Induction.html#2109" class="Bound">P</a> <a id="2111" href="Induction.html#2111" class="Bound">f</a> <a id="2113" href="Induction.html#2113" class="Bound">x</a> <a id="2115" href="Induction.html#2115" class="Bound">q</a> <a id="2117" class="Symbol">=</a> <a id="2119" href="Induction.html#2111" class="Bound">f</a> <a id="2121" href="Induction.html#2113" class="Bound">x</a> <a id="2123" class="Symbol">(</a><a id="2124" href="Induction.html#2101" class="Bound">builder</a> <a id="2132" href="Induction.html#2109" class="Bound">P</a> <a id="2134" href="Induction.html#2111" class="Bound">f</a> <a id="2136" href="Induction.html#2113" class="Bound">x</a> <a id="2138" href="Induction.html#2115" class="Bound">q</a><a id="2139" class="Symbol">)</a>
</pre></body></html>