Skip to content

Commit f014151

Browse files
author
Alex Gryzlov
committed
finish Rel
1 parent 46daa5c commit f014151

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/Rel.lidr

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
> module Rel
44

5+
\todo[inline]{Add hyperlinks}
6+
57
This short (and optional) chapter develops some basic definitions and a few
68
theorems about binary relations in Idris. The key definitions are repeated where
79
they are actually used (in the `Smallstep` chapter), so readers who are already
@@ -10,16 +12,15 @@ relations are also a good source of exercises for developing facility with
1012
Idris's basic reasoning facilities, so it may be useful to look at this material
1113
just after the `IndProp` chapter.
1214

13-
Require Export IndProp.
14-
1515
A binary _relation_ on a set \idr{t} is a family of propositions parameterized
1616
by two elements of \idr{t} — i.e., a proposition about pairs of elements of
1717
\idr{t}.
1818

1919
> Relation : Type -> Type
2020
> Relation t = t -> t -> Type
2121

22-
\todo[inline]{Edit}
22+
\todo[inline]{Edit, there's n-relation \idr{Data.Rel} in \idr{contrib}, but no
23+
\idr{Relation}}
2324

2425
Confusingly, the Idris standard library hijacks the generic term "relation" for
2526
this specific instance of the idea. To maintain consistency with the library, we
@@ -29,8 +30,8 @@ refer to a binary relation between some set and itself, whereas the English word
2930
concept of a relation between any number of possibly different sets. The context
3031
of the discussion should always make clear which is meant.
3132

32-
\todo[inline]{Called \idr{LTE} in \idr{Prelude.Nat}, but defined via induction
33-
from zero there}
33+
\todo[inline]{There's a similar concept called \idr{LTE} in \idr{Prelude.Nat},
34+
but it's defined by induction from zero}
3435

3536
An example relation on \idr{Nat} is \idr{Le}, the less-than-or-equal-to
3637
relation, which we usually write \idr{n1 <= n2}.
@@ -48,7 +49,7 @@ relation, which we usually write \idr{n1 <= n2}.
4849
Le : Nat -> Nat -> Type
4950
```
5051

51-
\todo[inline]{Edit, it probably doesn't matter in Idris}
52+
\todo[inline]{Edit to show it (probably) doesn't matter in Idris}
5253

5354
(Why did we write it this way instead of starting with \idr{data Le : Relation
5455
Nat ...}? Because we wanted to put the first \idr{Nat} to the left of the
@@ -67,13 +68,15 @@ relation from another, etc. For example...
6768
6869
=== Partial Functions
6970
70-
A relation \idr{r} on a set \idr{t} is a partial function if, for every \idr{x},
71-
there is at most one \idr{y} such that \idr{r x y} — i.e., \idr{r x y1} and
72-
\idr{r x y2} together imply \idr{y1 = y2}.
71+
A relation \idr{r} on a set \idr{t} is a _partial function_ if, for every
72+
\idr{x}, there is at most one \idr{y} such that \idr{r x y} — i.e., \idr{r x y1}
73+
and \idr{r x y2} together imply \idr{y1 = y2}.
7374
7475
> Partial_function : (r : Relation t) -> Type
7576
> Partial_function {t} r = (x, y1, y2 : t) -> r x y1 -> r x y2 -> y1 = y2
7677
78+
\todo[inline]{"Earlier" = in \idr{IndProp}, add hyperlink?}
79+
7780
For example, the \idr{Next_nat} relation defined earlier is a partial function.
7881
7982
> data Next_nat : (n : Nat) -> Nat -> Type where
@@ -98,7 +101,7 @@ so our assumption was contradictory.)
98101
99102
==== Exercise: 2 stars, optional
100103
101-
\ \todo[inline]{They mean exercises from `IndProp`}
104+
\ \todo[inline]{Again, "earlier" = \idr{IndProp}}
102105
103106
Show that the idr{Total_relation} defined in earlier is not a partial function.
104107
@@ -158,25 +161,27 @@ We can also prove \idr{lt_trans} more laboriously by induction, without using
158161
159162
> lt_trans' : Transitive Lt
160163
> -- Prove this by induction on evidence that a is less than c.
161-
> lt_trans' a b c lab lbc = ?lt_trans'_rhs
164+
> lt_trans' a b c lab lbc = ?lt_trans__rhs
162165
163166
$\square$
164167
165168
166169
==== Exercise: 2 stars, optional
167170
171+
\ \todo[inline]{Not sure how is this different from \idr{lt_trans'}?}
172+
168173
Prove the same thing again by induction on \idr{c}.
169174
170175
> lt_trans'' : Transitive Lt
171-
> lt_trans'' a b c lab lbc = ?lt_trans'_rhs
176+
> lt_trans'' a b c lab lbc = ?lt_trans___rhs
172177
173178
$\square$
174179
175180
The transitivity of \idr{Le}, in turn, can be used to prove some facts that will
176181
be useful later (e.g., for the proof of antisymmetry below)...
177182
178183
> le_Sn_le : ((S n) <=' m) -> (n <=' m)
179-
> le_Sn_le {n} {m} les = le_trans n (S n) m (Le_S Le_n) les
184+
> le_Sn_le {n} {m} = le_trans n (S n) m (Le_S Le_n)
180185
181186
182187
==== Exercise: 1 star, optional
@@ -230,7 +235,7 @@ A relation \idr{r} is _symmetric_ if \idr{r a b} implies \idr{r b a}.
230235
231236
$\square$
232237
233-
A relation \idr{r} is _antisymmetric_ if \idr{r a b{} and \idr{r b a} together
238+
A relation \idr{r} is _antisymmetric_ if \idr{r a b} and \idr{r b a} together
234239
imply \idr{a = b} — that is, if the only "cycles" in \idr{r} are trivial ones.
235240
236241
> Antisymmetric : (r : Relation t) -> Type
@@ -353,7 +358,8 @@ behavior of the two "missing" \idr{Clos_refl_trans} constructors.
353358
354359
$\square$
355360
356-
Then we use these facts to prove that the two definitions of reflexive, transitive closure do indeed define the same relation.
361+
Then we use these facts to prove that the two definitions of reflexive,
362+
transitive closure do indeed define the same relation.
357363
358364
359365
==== Exercise: 3 stars, optional (rtc_rsc_coincide)

0 commit comments

Comments
 (0)