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

70 lines
No EOL
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. 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>Data.Sum</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">-- Sums (disjoint unions)</a>
<a id="132" class="Comment">------------------------------------------------------------------------</a>
<a id="206" class="Symbol">{-#</a> <a id="210" class="Keyword">OPTIONS</a> <a id="218" class="Pragma">--cubical-compatible</a> <a id="239" class="Pragma">--safe</a> <a id="246" class="Symbol">#-}</a>
<a id="251" class="Keyword">module</a> <a id="258" href="Data.Sum.html" class="Module">Data.Sum</a> <a id="267" class="Keyword">where</a>
<a id="274" class="Keyword">open</a> <a id="279" class="Keyword">import</a> <a id="286" href="Agda.Builtin.Equality.html" class="Module">Agda.Builtin.Equality</a>
<a id="309" class="Keyword">open</a> <a id="314" class="Keyword">import</a> <a id="321" href="Data.Bool.Base.html" class="Module">Data.Bool.Base</a> <a id="336" class="Keyword">using</a> <a id="342" class="Symbol">(</a><a id="343" href="Agda.Builtin.Bool.html#198" class="InductiveConstructor">true</a><a id="347" class="Symbol">;</a> <a id="349" href="Agda.Builtin.Bool.html#192" class="InductiveConstructor">false</a><a id="354" class="Symbol">)</a>
<a id="356" class="Keyword">open</a> <a id="361" class="Keyword">import</a> <a id="368" href="Data.Unit.Polymorphic.Base.html" class="Module">Data.Unit.Polymorphic.Base</a> <a id="395" class="Keyword">using</a> <a id="401" class="Symbol">(</a><a id="402" href="Data.Unit.Polymorphic.Base.html#489" class="Function"></a><a id="403" class="Symbol">;</a> <a id="405" href="Data.Unit.Polymorphic.Base.html#533" class="Function">tt</a><a id="407" class="Symbol">)</a>
<a id="409" class="Keyword">open</a> <a id="414" class="Keyword">import</a> <a id="421" href="Data.Maybe.Base.html" class="Module">Data.Maybe.Base</a> <a id="437" class="Keyword">using</a> <a id="443" class="Symbol">(</a><a id="444" href="Agda.Builtin.Maybe.html#135" class="Datatype">Maybe</a><a id="449" class="Symbol">;</a> <a id="451" href="Agda.Builtin.Maybe.html#173" class="InductiveConstructor">just</a><a id="455" class="Symbol">;</a> <a id="457" href="Agda.Builtin.Maybe.html#194" class="InductiveConstructor">nothing</a><a id="464" class="Symbol">)</a>
<a id="466" class="Keyword">open</a> <a id="471" class="Keyword">import</a> <a id="478" href="Function.Base.html" class="Module">Function.Base</a>
<a id="492" class="Keyword">open</a> <a id="497" class="Keyword">import</a> <a id="504" href="Level.html" class="Module">Level</a>
<a id="510" class="Keyword">open</a> <a id="515" class="Keyword">import</a> <a id="522" href="Relation.Nullary.Reflects.html" class="Module">Relation.Nullary.Reflects</a> <a id="548" class="Keyword">using</a> <a id="554" class="Symbol">(</a><a id="555" href="Relation.Nullary.Reflects.html#1582" class="Function">invert</a><a id="561" class="Symbol">)</a>
<a id="563" class="Keyword">open</a> <a id="568" class="Keyword">import</a> <a id="575" href="Relation.Nullary.html" class="Module">Relation.Nullary</a> <a id="592" class="Keyword">using</a> <a id="598" class="Symbol">(</a><a id="599" href="Relation.Nullary.Decidable.Core.html#1485" class="Record">Dec</a><a id="602" class="Symbol">;</a> <a id="604" href="Relation.Nullary.Decidable.Core.html#1618" class="InductiveConstructor">yes</a><a id="607" class="Symbol">;</a> <a id="609" href="Relation.Nullary.Decidable.Core.html#1655" class="InductiveConstructor">no</a><a id="611" class="Symbol">;</a> <a id="613" href="Relation.Nullary.Decidable.Core.html#1529" class="InductiveConstructor Operator">_because_</a><a id="622" class="Symbol">;</a> <a id="624" href="Relation.Nullary.Negation.Core.html#698" class="Function Operator">¬_</a><a id="626" class="Symbol">)</a>
<a id="629" class="Keyword">private</a>
<a id="639" class="Keyword">variable</a>
<a id="652" href="Data.Sum.html#652" class="Generalizable">a</a> <a id="654" href="Data.Sum.html#654" class="Generalizable">b</a> <a id="656" class="Symbol">:</a> <a id="658" href="Agda.Primitive.html#742" class="Postulate">Level</a>
<a id="668" href="Data.Sum.html#668" class="Generalizable">A</a> <a id="670" href="Data.Sum.html#670" class="Generalizable">B</a> <a id="672" class="Symbol">:</a> <a id="674" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="678" href="Data.Sum.html#652" class="Generalizable">a</a>
<a id="681" class="Comment">------------------------------------------------------------------------</a>
<a id="754" class="Comment">-- Re-export content from base module</a>
<a id="793" class="Keyword">open</a> <a id="798" class="Keyword">import</a> <a id="805" href="Data.Sum.Base.html" class="Module">Data.Sum.Base</a> <a id="819" class="Keyword">public</a>
<a id="827" class="Comment">------------------------------------------------------------------------</a>
<a id="900" class="Comment">-- Additional functions</a>
<a id="925" class="Keyword">module</a> <a id="932" href="Data.Sum.html#932" class="Module">_</a> <a id="934" class="Symbol">{</a><a id="935" href="Data.Sum.html#935" class="Bound">a</a> <a id="937" href="Data.Sum.html#937" class="Bound">b</a><a id="938" class="Symbol">}</a> <a id="940" class="Symbol">{</a><a id="941" href="Data.Sum.html#941" class="Bound">A</a> <a id="943" class="Symbol">:</a> <a id="945" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="949" href="Data.Sum.html#935" class="Bound">a</a><a id="950" class="Symbol">}</a> <a id="952" class="Symbol">{</a><a id="953" href="Data.Sum.html#953" class="Bound">B</a> <a id="955" class="Symbol">:</a> <a id="957" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="961" href="Data.Sum.html#937" class="Bound">b</a><a id="962" class="Symbol">}</a> <a id="964" class="Keyword">where</a>
<a id="973" href="Data.Sum.html#973" class="Function">isInj₁</a> <a id="980" class="Symbol">:</a> <a id="982" href="Data.Sum.html#941" class="Bound">A</a> <a id="984" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="986" href="Data.Sum.html#953" class="Bound">B</a> <a id="988" class="Symbol"></a> <a id="990" href="Agda.Builtin.Maybe.html#135" class="Datatype">Maybe</a> <a id="996" href="Data.Sum.html#941" class="Bound">A</a>
<a id="1000" href="Data.Sum.html#973" class="Function">isInj₁</a> <a id="1007" class="Symbol">(</a><a id="1008" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1013" href="Data.Sum.html#1013" class="Bound">x</a><a id="1014" class="Symbol">)</a> <a id="1016" class="Symbol">=</a> <a id="1018" href="Agda.Builtin.Maybe.html#173" class="InductiveConstructor">just</a> <a id="1023" href="Data.Sum.html#1013" class="Bound">x</a>
<a id="1027" href="Data.Sum.html#973" class="Function">isInj₁</a> <a id="1034" class="Symbol">(</a><a id="1035" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1040" href="Data.Sum.html#1040" class="Bound">y</a><a id="1041" class="Symbol">)</a> <a id="1043" class="Symbol">=</a> <a id="1045" href="Agda.Builtin.Maybe.html#194" class="InductiveConstructor">nothing</a>
<a id="1056" href="Data.Sum.html#1056" class="Function">isInj₂</a> <a id="1063" class="Symbol">:</a> <a id="1065" href="Data.Sum.html#941" class="Bound">A</a> <a id="1067" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1069" href="Data.Sum.html#953" class="Bound">B</a> <a id="1071" class="Symbol"></a> <a id="1073" href="Agda.Builtin.Maybe.html#135" class="Datatype">Maybe</a> <a id="1079" href="Data.Sum.html#953" class="Bound">B</a>
<a id="1083" href="Data.Sum.html#1056" class="Function">isInj₂</a> <a id="1090" class="Symbol">(</a><a id="1091" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1096" href="Data.Sum.html#1096" class="Bound">x</a><a id="1097" class="Symbol">)</a> <a id="1099" class="Symbol">=</a> <a id="1101" href="Agda.Builtin.Maybe.html#194" class="InductiveConstructor">nothing</a>
<a id="1111" href="Data.Sum.html#1056" class="Function">isInj₂</a> <a id="1118" class="Symbol">(</a><a id="1119" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1124" href="Data.Sum.html#1124" class="Bound">y</a><a id="1125" class="Symbol">)</a> <a id="1127" class="Symbol">=</a> <a id="1129" href="Agda.Builtin.Maybe.html#173" class="InductiveConstructor">just</a> <a id="1134" href="Data.Sum.html#1124" class="Bound">y</a>
<a id="1139" href="Data.Sum.html#1139" class="Function">From-inj₁</a> <a id="1149" class="Symbol">:</a> <a id="1151" href="Data.Sum.html#941" class="Bound">A</a> <a id="1153" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1155" href="Data.Sum.html#953" class="Bound">B</a> <a id="1157" class="Symbol"></a> <a id="1159" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1163" href="Data.Sum.html#935" class="Bound">a</a>
<a id="1167" href="Data.Sum.html#1139" class="Function">From-inj₁</a> <a id="1177" class="Symbol">(</a><a id="1178" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1183" class="Symbol">_)</a> <a id="1186" class="Symbol">=</a> <a id="1188" href="Data.Sum.html#941" class="Bound">A</a>
<a id="1192" href="Data.Sum.html#1139" class="Function">From-inj₁</a> <a id="1202" class="Symbol">(</a><a id="1203" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1208" class="Symbol">_)</a> <a id="1211" class="Symbol">=</a> <a id="1213" href="Data.Unit.Polymorphic.Base.html#489" class="Function"></a>
<a id="1218" href="Data.Sum.html#1218" class="Function">from-inj₁</a> <a id="1228" class="Symbol">:</a> <a id="1230" class="Symbol">(</a><a id="1231" href="Data.Sum.html#1231" class="Bound">x</a> <a id="1233" class="Symbol">:</a> <a id="1235" href="Data.Sum.html#941" class="Bound">A</a> <a id="1237" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1239" href="Data.Sum.html#953" class="Bound">B</a><a id="1240" class="Symbol">)</a> <a id="1242" class="Symbol"></a> <a id="1244" href="Data.Sum.html#1139" class="Function">From-inj₁</a> <a id="1254" href="Data.Sum.html#1231" class="Bound">x</a>
<a id="1258" href="Data.Sum.html#1218" class="Function">from-inj₁</a> <a id="1268" class="Symbol">(</a><a id="1269" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1274" href="Data.Sum.html#1274" class="Bound">x</a><a id="1275" class="Symbol">)</a> <a id="1277" class="Symbol">=</a> <a id="1279" href="Data.Sum.html#1274" class="Bound">x</a>
<a id="1283" href="Data.Sum.html#1218" class="Function">from-inj₁</a> <a id="1293" class="Symbol">(</a><a id="1294" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1299" class="Symbol">_)</a> <a id="1302" class="Symbol">=</a> <a id="1304" class="Symbol">_</a>
<a id="1309" href="Data.Sum.html#1309" class="Function">From-inj₂</a> <a id="1319" class="Symbol">:</a> <a id="1321" href="Data.Sum.html#941" class="Bound">A</a> <a id="1323" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1325" href="Data.Sum.html#953" class="Bound">B</a> <a id="1327" class="Symbol"></a> <a id="1329" href="Agda.Primitive.html#388" class="Primitive">Set</a> <a id="1333" href="Data.Sum.html#937" class="Bound">b</a>
<a id="1337" href="Data.Sum.html#1309" class="Function">From-inj₂</a> <a id="1347" class="Symbol">(</a><a id="1348" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1353" class="Symbol">_)</a> <a id="1356" class="Symbol">=</a> <a id="1358" href="Data.Unit.Polymorphic.Base.html#489" class="Function"></a>
<a id="1362" href="Data.Sum.html#1309" class="Function">From-inj₂</a> <a id="1372" class="Symbol">(</a><a id="1373" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1378" class="Symbol">_)</a> <a id="1381" class="Symbol">=</a> <a id="1383" href="Data.Sum.html#953" class="Bound">B</a>
<a id="1388" href="Data.Sum.html#1388" class="Function">from-inj₂</a> <a id="1398" class="Symbol">:</a> <a id="1400" class="Symbol">(</a><a id="1401" href="Data.Sum.html#1401" class="Bound">x</a> <a id="1403" class="Symbol">:</a> <a id="1405" href="Data.Sum.html#941" class="Bound">A</a> <a id="1407" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1409" href="Data.Sum.html#953" class="Bound">B</a><a id="1410" class="Symbol">)</a> <a id="1412" class="Symbol"></a> <a id="1414" href="Data.Sum.html#1309" class="Function">From-inj₂</a> <a id="1424" href="Data.Sum.html#1401" class="Bound">x</a>
<a id="1428" href="Data.Sum.html#1388" class="Function">from-inj₂</a> <a id="1438" class="Symbol">(</a><a id="1439" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1444" class="Symbol">_)</a> <a id="1447" class="Symbol">=</a> <a id="1449" class="Symbol">_</a>
<a id="1453" href="Data.Sum.html#1388" class="Function">from-inj₂</a> <a id="1463" class="Symbol">(</a><a id="1464" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1469" href="Data.Sum.html#1469" class="Bound">x</a><a id="1470" class="Symbol">)</a> <a id="1472" class="Symbol">=</a> <a id="1474" href="Data.Sum.html#1469" class="Bound">x</a>
<a id="1477" class="Comment">-- Conversion back and forth with Dec</a>
<a id="fromDec"></a><a id="1516" href="Data.Sum.html#1516" class="Function">fromDec</a> <a id="1524" class="Symbol">:</a> <a id="1526" href="Relation.Nullary.Decidable.Core.html#1485" class="Record">Dec</a> <a id="1530" href="Data.Sum.html#668" class="Generalizable">A</a> <a id="1532" class="Symbol"></a> <a id="1534" href="Data.Sum.html#668" class="Generalizable">A</a> <a id="1536" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1538" href="Relation.Nullary.Negation.Core.html#698" class="Function Operator">¬</a> <a id="1540" href="Data.Sum.html#668" class="Generalizable">A</a>
<a id="1542" href="Data.Sum.html#1516" class="Function">fromDec</a> <a id="1550" class="Symbol">(</a> <a id="1552" href="Agda.Builtin.Bool.html#198" class="InductiveConstructor">true</a> <a id="1557" href="Relation.Nullary.Decidable.Core.html#1529" class="InductiveConstructor Operator">because</a> <a id="1566" href="Data.Sum.html#1566" class="Bound">[p]</a><a id="1569" class="Symbol">)</a> <a id="1571" class="Symbol">=</a> <a id="1573" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1578" class="Symbol">(</a><a id="1579" href="Relation.Nullary.Reflects.html#1582" class="Function">invert</a> <a id="1587" href="Data.Sum.html#1566" class="Bound">[p]</a><a id="1590" class="Symbol">)</a>
<a id="1592" href="Data.Sum.html#1516" class="Function">fromDec</a> <a id="1600" class="Symbol">(</a><a id="1601" href="Agda.Builtin.Bool.html#192" class="InductiveConstructor">false</a> <a id="1607" href="Relation.Nullary.Decidable.Core.html#1529" class="InductiveConstructor Operator">because</a> <a id="1615" href="Data.Sum.html#1615" class="Bound">[¬p]</a><a id="1619" class="Symbol">)</a> <a id="1621" class="Symbol">=</a> <a id="1623" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1628" class="Symbol">(</a><a id="1629" href="Relation.Nullary.Reflects.html#1582" class="Function">invert</a> <a id="1636" href="Data.Sum.html#1615" class="Bound">[¬p]</a><a id="1640" class="Symbol">)</a>
<a id="toDec"></a><a id="1643" href="Data.Sum.html#1643" class="Function">toDec</a> <a id="1649" class="Symbol">:</a> <a id="1651" href="Data.Sum.html#668" class="Generalizable">A</a> <a id="1653" href="Data.Sum.Base.html#625" class="Datatype Operator"></a> <a id="1655" href="Relation.Nullary.Negation.Core.html#698" class="Function Operator">¬</a> <a id="1657" href="Data.Sum.html#668" class="Generalizable">A</a> <a id="1659" class="Symbol"></a> <a id="1661" href="Relation.Nullary.Decidable.Core.html#1485" class="Record">Dec</a> <a id="1665" href="Data.Sum.html#668" class="Generalizable">A</a>
<a id="1667" href="Data.Sum.html#1643" class="Function">toDec</a> <a id="1673" class="Symbol">(</a><a id="1674" href="Data.Sum.Base.html#675" class="InductiveConstructor">inj₁</a> <a id="1679" href="Data.Sum.html#1679" class="Bound">p</a><a id="1680" class="Symbol">)</a> <a id="1683" class="Symbol">=</a> <a id="1685" href="Relation.Nullary.Decidable.Core.html#1618" class="InductiveConstructor">yes</a> <a id="1689" href="Data.Sum.html#1679" class="Bound">p</a>
<a id="1691" href="Data.Sum.html#1643" class="Function">toDec</a> <a id="1697" class="Symbol">(</a><a id="1698" href="Data.Sum.Base.html#700" class="InductiveConstructor">inj₂</a> <a id="1703" href="Data.Sum.html#1703" class="Bound">¬p</a><a id="1705" class="Symbol">)</a> <a id="1707" class="Symbol">=</a> <a id="1709" href="Relation.Nullary.Decidable.Core.html#1655" class="InductiveConstructor">no</a> <a id="1712" href="Data.Sum.html#1703" class="Bound">¬p</a>
</pre></body></html>