2
2
3
3
> module Rel
4
4
5
+ \ todo[inline]{Add hyperlinks}
6
+
5
7
This short (and optional) chapter develops some basic definitions and a few
6
8
theorems about binary relations in Idris . The key definitions are repeated where
7
9
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
10
12
Idris's basic reasoning facilities, so it may be useful to look at this material
11
13
just after the `IndProp` chapter.
12
14
13
- Require Export IndProp .
14
-
15
15
A binary _relation_ on a set \ idr{t} is a family of propositions parameterized
16
16
by two elements of \ idr{t} — i. e. , a proposition about pairs of elements of
17
17
\ idr{t}.
18
18
19
19
> Relation : Type -> Type
20
20
> Relation t = t -> t -> Type
21
21
22
- \ todo[inline]{Edit }
22
+ \ todo[inline]{Edit , there's n- relation \ idr{Data . Rel } in \ idr{contrib}, but no
23
+ \ idr{Relation }}
23
24
24
25
Confusingly , the Idris standard library hijacks the generic term " relation" for
25
26
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
29
30
concept of a relation between any number of possibly different sets. The context
30
31
of the discussion should always make clear which is meant.
31
32
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}
34
35
35
36
An example relation on \ idr{Nat } is \ idr{Le }, the less- than- or - equal- to
36
37
relation, which we usually write \ idr{n1 <= n2}.
@@ -48,7 +49,7 @@ relation, which we usually write \idr{n1 <= n2}.
48
49
Le : Nat -> Nat -> Type
49
50
`` `
50
51
51
- \ todo[inline]{Edit , it probably doesn't matter in Idris }
52
+ \ todo[inline]{Edit to show it ( probably) doesn't matter in Idris }
52
53
53
54
(Why did we write it this way instead of starting with \ idr{data Le : Relation
54
55
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...
67
68
68
69
=== Partial Functions
69
70
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}.
73
74
74
75
> Partial_function : (r : Relation t) -> Type
75
76
> Partial_function {t} r = (x, y1, y2 : t) -> r x y1 -> r x y2 -> y1 = y2
76
77
78
+ \t odo[inline]{"Earlier" = in \idr{IndProp}, add hyperlink?}
79
+
77
80
For example, the \idr{Next_nat} relation defined earlier is a partial function.
78
81
79
82
> data Next_nat : (n : Nat) -> Nat -> Type where
@@ -98,7 +101,7 @@ so our assumption was contradictory.)
98
101
99
102
==== Exercise: 2 stars, optional
100
103
101
- \ \t odo[inline]{They mean exercises from ` IndProp` }
104
+ \ \t odo[inline]{Again, "earlier" = \idr{ IndProp} }
102
105
103
106
Show that the idr{Total_relation} defined in earlier is not a partial function.
104
107
@@ -158,25 +161,27 @@ We can also prove \idr{lt_trans} more laboriously by induction, without using
158
161
159
162
> lt_trans' : Transitive Lt
160
163
> -- 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
162
165
163
166
$\square$
164
167
165
168
166
169
==== Exercise: 2 stars, optional
167
170
171
+ \ \t odo[inline]{Not sure how is this different from \idr{lt_trans'}?}
172
+
168
173
Prove the same thing again by induction on \idr{c}.
169
174
170
175
> 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
172
177
173
178
$\square$
174
179
175
180
The transitivity of \idr{Le}, in turn, can be used to prove some facts that will
176
181
be useful later (e.g., for the proof of antisymmetry below)...
177
182
178
183
> 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)
180
185
181
186
182
187
==== Exercise: 1 star, optional
@@ -230,7 +235,7 @@ A relation \idr{r} is _symmetric_ if \idr{r a b} implies \idr{r b a}.
230
235
231
236
$\square$
232
237
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
234
239
imply \idr{a = b} — that is, if the only " cycles" in \idr{r} are trivial ones.
235
240
236
241
> Antisymmetric : (r : Relation t) -> Type
@@ -353,7 +358,8 @@ behavior of the two "missing" \idr{Clos_refl_trans} constructors.
353
358
354
359
$\square$
355
360
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.
357
363
358
364
359
365
==== Exercise: 3 stars, optional (rtc_rsc_coincide)
0 commit comments