@@ -129,7 +129,7 @@ To prove a conjunction, we can use value-level pair syntax:
129
129
> and_example = (Refl , Refl )
130
130
131
131
For any propositions \ idr{a} and \ idr{b}, if we assume that \ idr{a} is true and
132
- we assume that \ idr{a } is true, we can trivially conclude that \ idr{(a,b)} is
132
+ we assume that \ idr{b } is true, we can trivially conclude that \ idr{(a,b)} is
133
133
also true.
134
134
135
135
> and_intro : a -> b -> (a, b)
@@ -160,10 +160,10 @@ You may wonder why we bothered packing the two hypotheses \idr{n = 0} and \idr{m
160
160
= 0 } into a single conjunction, since we could have also stated the theorem with
161
161
two separate premises :
162
162
163
- > and_example2'' : (n, m : Nat ) -> n = 0 -> m = 0 -> n + m = 0
164
- > and_example2'' Z Z Refl Refl = Refl
165
- > and_example2' ' (S _) _ Refl _ impossible
166
- > and_example2' ' _ (S _) _ Refl impossible
163
+ > and_example2' : (n, m : Nat ) -> n = 0 -> m = 0 -> n + m = 0
164
+ > and_example2' Z Z Refl Refl = Refl
165
+ > and_example2' (S _ ) _ Refl _ impossible
166
+ > and_example2' _ (S _ ) _ Refl impossible
167
167
168
168
For this theorem, both formulations are fine. But it's important to understand
169
169
how to work with conjunctive hypotheses because conjunctions often arise from
@@ -212,7 +212,8 @@ $\square$
212
212
213
213
=== Disjunction
214
214
215
- \ todo[inline]{Make syntax synonyms for \ idr{(,)} and \ idr{Either }? }
215
+ \ todo[inline]{Hide \ idr{Basics . Booleans } analogues and make syntax synonyms
216
+ \ idr{(/\ )} and \ idr{(\/ )} for \ idr{(,)} and \ idr{Either }? }
216
217
217
218
Another important connective is the _disjunction_, or _logical or_ of two
218
219
propositions : \idr{a `Either ` b} is true when either \idr{a} or \idr{b} is. The
@@ -267,6 +268,8 @@ course, we may also be interested in _negative_ results, showing that certain
267
268
propositions are _not_ true. In Idris , such negative statements are expressed
268
269
with the negation typelevel function \ idr{Not }.
269
270
271
+ \ todo[inline]{Add hyperlink}
272
+
270
273
To see how negation works, recall the discussion of the _principle of explosion_
271
274
from the previous chapter; it asserts that, if we assume a contradiction, then
272
275
any other proposition can be derived. Following this intuition, we could define
@@ -282,6 +285,8 @@ Not : Type -> Type
282
285
Not a = a -> Void
283
286
`` `
284
287
288
+ \ todo[inline]{Discuss difference between \ idr{void} and \ idr{absurd}}
289
+
285
290
Since \ idr{Void } is a contradictory proposition, the principle of explosion also
286
291
applies to it. If we get \ idr{Void } into the proof context, we can call
287
292
\ idr{void} or \ idr{absurd} on it to complete any goal :
@@ -333,7 +338,7 @@ warmed up.
333
338
> double_neg p notp = notp p
334
339
335
340
336
- ==== Exercise : 2 stars, advanced, recommendedM (double_neg_inf)
341
+ ==== Exercise : 2 stars, advanced, recommended (double_neg_inf)
337
342
338
343
Write an informal proof of \ idr{double_neg}:
339
344
@@ -405,7 +410,7 @@ the same truth value, is just the conjunction of two implications.
405
410
> iff : {p,q : Type } -> Type
406
411
> iff {p} {q} = (p -> q, q -> p)
407
412
408
- Idris' stdlib has a more general form of this, \ idr{Iso }, in
413
+ Idris's stdlib has a more general form of this, \ idr{Iso }, in
409
414
\ idr{Control . Isomorphism }.
410
415
411
416
> syntax [p] " <->" [q] = iff {p} {q}
@@ -450,9 +455,7 @@ Some of Idris's tactics treat iff statements specially, avoiding the need for
450
455
some low- level proof- state manipulation. In particular, rewrite and reflexivity
451
456
can be used with iff statements, not just equalities. To enable this behavior,
452
457
we need to import a special Idris library that allows rewriting with other
453
- formulas besides equality :
454
-
455
- Require Import Idris . Setoids . Setoid .
458
+ formulas besides equality (setoids).
456
459
457
460
Here is a simple example demonstrating how these tactics work with iff. First ,
458
461
let 's prove a couple of basic iff equivalences...
@@ -477,9 +480,9 @@ let's prove a couple of basic iff equivalences...
477
480
> fro (Left (Right q)) = Right $ Left q
478
481
> fro (Right r) = Right $ Right r
479
482
480
- We can now use these facts with rewrite and reflexivity to give smooth proofs of
481
- statements involving equivalences. Here is a ternary version of the previous
482
- mult_0 result :
483
+ We can now use these facts with \ idr{ rewrite} and \ idr{ Refl } to give smooth
484
+ proofs of statements involving equivalences. Here is a ternary version of the
485
+ previous \ idr{ mult_0} result :
483
486
484
487
> mult_0_3 : (n * m * p = Z) <->
485
488
> ((n = Z) `Either ` ((m = Z) `Either ` (p = Z)))
@@ -498,8 +501,8 @@ mult_0 result:
498
501
> fro {n} (Right (Left Refl )) = rewrite multZeroRightZero n in Refl
499
502
> fro {n} {m} (Right (Right Refl )) = rewrite multZeroRightZero (n* m) in Refl
500
503
501
- The apply tactic can also be used with <->. When given an equivalence as its
502
- argument, apply tries to guess which side of the equivalence to use.
504
+ The apply tactic can also be used with \ idr{ <-> } . When given an equivalence as
505
+ its argument, apply tries to guess which side of the equivalence to use.
503
506
504
507
> apply_iff_example : (n, m : Nat ) -> n * m = Z -> ((n = Z) `Either ` (m = Z))
505
508
> apply_iff_example n m = fst $ mult_0 {n} {m}
@@ -536,7 +539,7 @@ that \idr{p} holds of \idr{x}.
536
539
Prove that " \idr{p} holds for all \idr{x}" implies " there is no \idr{x} for
537
540
which \idr{p} does not hold."
538
541
539
- > dist_not_exists : {p : a -> Type } -> ((x : a) -> p x) -> Not (x ** Not $ p x)
542
+ > dist_not_exists : {p : a -> Type } -> ((x : a) -> p x) -> Not (x ** Not $ p x)
540
543
> dist_not_exists f = ? dist_not_exists_rhs
541
544
542
545
$\ square$
@@ -679,6 +682,8 @@ $\square$
679
682
One feature of Idris that distinguishes it from many other proof assistants is
680
683
that it treats _proofs_ as first- class objects.
681
684
685
+ \ todo[inline]{`nameref` the chapters when they're done}
686
+
682
687
There is a great deal to be said about this, but it is not necessary to
683
688
understand it in detail in order to use Idris . This section gives just a taste,
684
689
while a deeper exploration can be found in the optional chapters
@@ -716,23 +721,27 @@ wanted to prove the following result:
716
721
717
722
> plus_comm3 : (n, m, p : Nat ) -> n + (m + p) = (p + m) + n
718
723
719
- \ todo[inline]{Edit , we have already done this in previous chapters}
724
+ \ todo[inline]{Edit , we have already done this in previous chapters (add a
725
+ hyperlink? )}
720
726
721
727
It appears at first sight that we ought to be able to prove this by rewriting
722
728
with \ idr{plusCommutative} twice to make the two sides match. The problem,
723
729
however, is that the second \ idr{rewrite} will undo the effect of the first.
724
730
731
+ `` `coq
725
732
Proof .
726
733
intros n m p.
727
734
rewrite plus_comm.
728
735
rewrite plus_comm.
729
736
(* We are back where we started... * )
730
737
Abort .
738
+ `` `
731
739
732
740
One simple way of fixing this problem, using only tools that we already know, is
733
741
to use assert to derive a specialized version of plus_comm that can be used to
734
742
rewrite exactly where we want.
735
743
744
+ `` `coq
736
745
Lemma plus_comm3_take2 :
737
746
∀n m p, n + (m + p) = (p + m) + n.
738
747
Proof .
@@ -743,10 +752,11 @@ Proof.
743
752
rewrite H .
744
753
reflexivity.
745
754
Qed .
755
+ `` `
746
756
747
- A more elegant alternative is to apply plus_comm directly to the arguments we
748
- want to instantiate it with , in much the same way as we apply a polymorphic
749
- function to a type argument.
757
+ A more elegant alternative is to apply \ idr{plusCommutative} directly to the
758
+ arguments we want to instantiate it with , in much the same way as we apply a
759
+ polymorphic function to a type argument.
750
760
751
761
> plus_comm3 n m p = rewrite plusCommutative n (m+ p) in
752
762
> rewrite plusCommutative m p in Refl
@@ -771,7 +781,7 @@ We will see many more examples of the idioms from this section in later chapters
771
781
772
782
== Idris vs. Set Theory
773
783
774
- \ todo[inline]{Edit , Idris' core is likely some variant of MLTT }
784
+ \ todo[inline]{Edit , Idris's core is likely some variant of MLTT }
775
785
776
786
Idris's logical core, the Calculus of Inductive Constructions , differs in some
777
787
important ways from other formal systems that are used by mathematicians for
@@ -806,9 +816,9 @@ we can write propositions claiming that two _functions_ are equal to each other:
806
816
In common mathematical practice, two functions `f` and `g` are considered equal
807
817
if they produce the same outputs :
808
818
809
- \ todo[inline]{ Use proper TeX here ? }
810
-
811
- `(∀x, f x = g x) -> f = g`
819
+ \ [
820
+ \ left( \ forall x, f(x) = g(x) \ right) \ to f = g
821
+ \ ]
812
822
813
823
This is known as the principle of _functional extensionality_.
814
824
@@ -830,7 +840,7 @@ function_equality_ex2 = ?stuck
830
840
However , we can add functional extensionality to Idris's core logic using the
831
841
\ idr{really_believe_me} command.
832
842
833
- > functional_extensionality : ((x : a) -> f x = g x) -> f = g
843
+ > functional_extensionality : ((x : a) -> f x = g x) -> f = g
834
844
> functional_extensionality = really_believe_me
835
845
836
846
Using \ idr{really_believe_me} has the same effect as stating a theorem and
@@ -856,14 +866,16 @@ consistent.
856
866
\ todo[inline]{Is there such a command in Idris ? }
857
867
858
868
To check whether a particular proof relies on any additional axioms, use the
859
- Print Assumptions command.
869
+ ` Print Assumptions ` command.
860
870
871
+ `` `coq
861
872
Print Assumptions function_equality_ex2.
862
873
(* ===>
863
874
Axioms :
864
875
functional_extensionality :
865
876
forall (X Y : Type ) (f g : X -> Y),
866
877
(forall x : X, f x = g x) -> f = g *)
878
+ `` `
867
879
868
880
869
881
==== Exercise : 4 stars (tr_rev)
@@ -928,7 +940,9 @@ We often say that the boolean \idr{evenb n} _reflects_ the proposition \idr{(k
928
940
==== Exercise : 3 stars (evenb_double_conv)
929
941
930
942
> evenb_double_conv : (k ** n = if evenb n then double k else S (double k))
931
- > -- Hint: Use the \idr{evenb_S} lemma from `Induction`
943
+
944
+ * Hint *: Use the \ idr{evenb_S} lemma from \ idr{Induction }.
945
+
932
946
> evenb_double_conv = ? evenb_double_conv_rhs
933
947
934
948
$\ square$
@@ -1003,7 +1017,7 @@ Idris's core language, which is designed so that every function that it can
1003
1017
express is computable and total . One reason for this is to allow the extraction
1004
1018
of executable programs from Idris developments. As a consequence, \ idr{Type } in
1005
1019
Idris does _not_ have a universal case analysis operation telling whether any
1006
- given proposition is true or Void , since such an operation would allow us to
1020
+ given proposition is true or false , since such an operation would allow us to
1007
1021
write non- computable functions.
1008
1022
1009
1023
Although general non- computable properties cannot be phrased as boolean
@@ -1038,6 +1052,9 @@ explicitly:
1038
1052
> even_1000'' : (k ** 1000 = double k)
1039
1053
> even_1000'' = (fst $ even_bool_prop {n=1000}) Refl
1040
1054
1055
+ \t odo[inline]{Add http://www.ams.org/journals/notices/200811/tx081101382p.pdf as
1056
+ a link}
1057
+
1041
1058
Although we haven' t gained much in terms of proof size in this case , larger
1042
1059
proofs can often be made considerably simpler by the use of reflection. As an
1043
1060
extreme example, the Coq proof of the famous _4- color theorem_ uses reflection
@@ -1221,13 +1238,13 @@ constructive reasoning, but arguments by contradiction, in particular, are
1221
1238
infamous for leading to non- constructive proofs. Here's a typical example :
1222
1239
suppose that we want to show that there exists \ idr{x} with some property
1223
1240
\ idr{p}, i. e. , such that \ idr{p x}. We start by assuming that our conclusion is
1224
- false; that is, \ idr{Not (x : a ** p x)}. From this premise, it is not hard to
1225
- derive \ idr{(x : a) -> Not $ p x}. If we manage to show that this intermediate
1241
+ false; that is, \ idr{Not (x : a ** p x)}. From this premise, it is not hard to
1242
+ derive \ idr{(x : a) -> Not $ p x}. If we manage to show that this intermediate
1226
1243
fact results in a contradiction, we arrive at an existence proof without ever
1227
1244
exhibiting a value of \ idr{x} for which \ idr{p x} holds!
1228
1245
1229
1246
The technical flaw here, from a constructive standpoint, is that we claimed to
1230
- prove \ idr{(x ** p x)} using a proof of ` Not $ Not (x ** p x)}. Allowing
1247
+ prove \ idr{(x ** p x)} using a proof of \ idr{ Not $ Not (x ** p x)}. Allowing
1231
1248
ourselves to remove double negations from arbitrary statements is equivalent to
1232
1249
assuming the excluded middle, as shown in one of the exercises below. Thus , this
1233
1250
line of reasoning cannot be encoded in Idris without assuming additional axioms.
@@ -1259,6 +1276,8 @@ equivalent:
1259
1276
(x : a) -> p x
1260
1277
`` `
1261
1278
1279
+ \ todo[inline]{Add a hyperlink}
1280
+
1262
1281
The \ idr{dist_not_exists} theorem above proves one side of this equivalence.
1263
1282
Interestingly , the other direction cannot be proved in constructive logic. Your
1264
1283
job is to show that it is implied by the excluded middle.
0 commit comments