Skip to content

Commit 26e9372

Browse files
author
Alex Gryzlov
committed
finalize IndProp
1 parent ff62dca commit 26e9372

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

software_foundations.ipkg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ modules = Basics
66
, Poly
77
, Tactics
88
, Logic
9+
, IndProp
910

1011
brief = "Software Foundations in Idris"
1112
version = 0.0.1.0

src/IndProp.lidr

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,8 @@ The \idr{MStar''} lemma below (combined with its converse, the \idr{MStar'}
10911091
exercise above), shows that our definition of \idr{Exp_match} for \idr{Star} is
10921092
equivalent to the informal one given previously.
10931093

1094-
> MStar'' : (s =~ Star re) ->
1095-
> (ss : List (List t) **
1094+
> MStar'' : (s =~ Star re) ->
1095+
> (ss : List (List t) **
10961096
> (s = fold (++) ss [], (s': List t) -> In s' ss -> s' =~ re)
10971097
> )
10981098
> MStar'' m = ?MStar''_rhs
@@ -1327,13 +1327,13 @@ need in this course. Try to solve this exercise without any help at all.
13271327

13281328
We say that a list "stutters" if it repeats the same element consecutively. The
13291329
property "\idr{Nostutter mylist}" means that \idr{mylist} does not stutter.
1330-
Formulate an inductive definition for \idr{nostutter}. (This is different from
1330+
Formulate an inductive definition for \idr{Nostutter}. (This is different from
13311331
the \idr{NoDup} property in the exercise below; the sequence \idr{[1,4,1]}
13321332
repeats but does not stutter.)
13331333

13341334
> data Nostutter : List t -> Type where
13351335
> -- FILL IN HERE
1336-
> RemoveMe : Nostutter [] -- needed for typechecking, shouldn't be empty
1336+
> RemoveMe : Nostutter [] -- needed for typechecking, data shouldn't be empty
13371337

13381338
Make sure each of these tests succeeds, but feel free to change the suggested
13391339
proof (in comments) if the given one doesn't work for you. Your definition might
@@ -1414,8 +1414,8 @@ and
14141414
[4,3]
14151415
```
14161416

1417-
Now, suppose we have a set \idr{x}, a function \idr{test : x->Bool}, and a list
1418-
\idr{l} of type \idr{List x}. Suppose further that \idr{l} is an in-order merge
1417+
Now, suppose we have a set \idr{t}, a function \idr{test : t->Bool}, and a list
1418+
\idr{l} of type \idr{List t}. Suppose further that \idr{l} is an in-order merge
14191419
of two lists, \idr{l1} and \idr{l2}, such that every item in \idr{l1} satisfies
14201420
\idr{test} and no item in \idr{l2} satisfies \idr{test}. Then \idr{filter test l
14211421
= l1}.
@@ -1494,22 +1494,22 @@ Recall the definition of the \idr{In} property from the \idr{Logic} chapter, whi
14941494
that a value \idr{x} appears at least once in a list \idr{l}:
14951495

14961496
```idris
1497-
In : (x : a) -> (l : List a) -> Type
1497+
In : (x : t) -> (l : List t) -> Type
14981498
In x [] = Void
14991499
In x (x' :: xs) = (x' = x) `Either` In x xs
15001500
```
15011501

1502-
Your first task is to use \idr{In} to define a proposition \idr{Disjoint {x} l1
1502+
Your first task is to use \idr{In} to define a proposition \idr{Disjoint {t} l1
15031503
l2}, which should be provable exactly when \idr{l1} and \idr{l2} are lists (with
1504-
elements of type \idr{x}) that have no elements in common.
1504+
elements of type \idr{t}) that have no elements in common.
15051505

15061506
> -- FILL IN HERE
15071507

1508-
Next, use \idr{In} to define an inductive proposition \idr{NoDup {x} l}, which
1508+
Next, use \idr{In} to define an inductive proposition \idr{NoDup {t} l}, which
15091509
should be provable exactly when \idr{l} is a list (with elements of type
1510-
\idr{x}) where every member is different from every other. For example,
1511-
\idr{NoDup {x=Nat} [1,2,3,4]} and \idr{NoDup {x=Bool} []} should be provable,
1512-
while \idr{NoDup {x=Nat} [1,2,1]} and \idr{NoDup {x=Bool} [True,True]} should
1510+
\idr{t}) where every member is different from every other. For example,
1511+
\idr{NoDup {t=Nat} [1,2,3,4]} and \idr{NoDup {t=Bool} []} should be provable,
1512+
while \idr{NoDup {t=Nat} [1,2,1]} and \idr{NoDup {t=Bool} [True,True]} should
15131513
not be.
15141514

15151515
> -- FILL IN HERE
@@ -1534,12 +1534,12 @@ First prove an easy useful lemma.
15341534
> in_split : In x l -> (l1 ** l2 ** l = l1 ++ x :: l2)
15351535
> in_split prf = ?in_split_rhs
15361536

1537-
Now define a property \idr{Repeats} such that \idr{Repeats {x} l} asserts that
1538-
\idr{l} contains at least one repeated element (of type \idr{x}).
1537+
Now define a property \idr{Repeats} such that \idr{Repeats {t} l} asserts that
1538+
\idr{l} contains at least one repeated element (of type \idr{t}).
15391539

1540-
> data Repeats : {x : Type} -> List x -> Type where
1540+
> data Repeats : List t -> Type where
15411541
> -- FILL IN HERE
1542-
> RemoveMe' : Repeats [] -- needed for typechecking, shouldn't be empty
1542+
> RemoveMe' : Repeats [] -- needed for typechecking, data shouldn't be empty
15431543

15441544
Now, here's a way to formalize the pigeonhole principle. Suppose list \idr{l2}
15451545
represents a list of pigeonhole labels, and list \idr{l1} represents the labels
@@ -1552,13 +1552,12 @@ However, it is also possible to make the proof go through _without_ assuming
15521552
that \idr{In} is decidable; if you manage to do this, you will not need the
15531553
\idr{excluded_middle} hypothesis.
15541554

1555-
> pigeonhole_principle: (l1, l2 : List a) ->
1556-
> ((x : a) -> In x l1 -> In x l2) ->
1557-
> ((length l2) <' (length l1)) ->
1558-
> Repeats l1
1559-
> pigeonhole_principle l1 l2 f prf = ?pigeonhole_principle_rhs
1555+
> pigeonhole_principle : ((x : t) -> In x l1 -> In x l2) ->
1556+
> ((length l2) <' (length l1)) ->
1557+
> Repeats l1
1558+
> pigeonhole_principle f prf = ?pigeonhole_principle_rhs
15601559
> where
1561-
> excluded_middle : (a : Type) -> a `Either` (Not a)
1560+
> excluded_middle : (p : Type) -> p `Either` (Not p)
15621561
> excluded_middle p = really_believe_me p
15631562

15641563
$\square$

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ LIDR_FILES := Preface.lidr \
1717
Lists.lidr \
1818
Poly.lidr \
1919
Tactics.lidr \
20-
Logic.lidr
20+
Logic.lidr \
21+
IndProp.lidr
2122
# TODO: Add more chapters, in order, here.
2223

2324

src/Poly.lidr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ returns `True`.
561561
> then h :: (filter test t)
562562
> else filter test t
563563

564+
(This is how it's defined in Idris's stdlib, too.)
565+
564566
For example, if we apply `filter` to the predicate `evenb` and a list of numbers
565567
`l`, it returns a list containing just the even members of `l`.
566568

0 commit comments

Comments
 (0)