Skip to content

Commit fd64ba8

Browse files
author
Alex Gryzlov
committed
changes after review
1 parent 90dd102 commit fd64ba8

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

src/Logic.lidr

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ To prove a conjunction, we can use value-level pair syntax:
129129
> and_example = (Refl, Refl)
130130

131131
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
133133
also true.
134134

135135
> 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
160160
= 0} into a single conjunction, since we could have also stated the theorem with
161161
two separate premises:
162162

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
167167

168168
For this theorem, both formulations are fine. But it's important to understand
169169
how to work with conjunctive hypotheses because conjunctions often arise from
@@ -212,7 +212,8 @@ $\square$
212212

213213
=== Disjunction
214214

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}?}
216217

217218
Another important connective is the _disjunction_, or _logical or_ of two
218219
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
267268
propositions are _not_ true. In Idris, such negative statements are expressed
268269
with the negation typelevel function \idr{Not}.
269270

271+
\todo[inline]{Add hyperlink}
272+
270273
To see how negation works, recall the discussion of the _principle of explosion_
271274
from the previous chapter; it asserts that, if we assume a contradiction, then
272275
any other proposition can be derived. Following this intuition, we could define
@@ -282,6 +285,8 @@ Not : Type -> Type
282285
Not a = a -> Void
283286
```
284287

288+
\todo[inline]{Discuss difference between \idr{void} and \idr{absurd}}
289+
285290
Since \idr{Void} is a contradictory proposition, the principle of explosion also
286291
applies to it. If we get \idr{Void} into the proof context, we can call
287292
\idr{void} or \idr{absurd} on it to complete any goal:
@@ -333,7 +338,7 @@ warmed up.
333338
> double_neg p notp = notp p
334339

335340

336-
==== Exercise: 2 stars, advanced, recommendedM (double_neg_inf)
341+
==== Exercise: 2 stars, advanced, recommended (double_neg_inf)
337342

338343
Write an informal proof of \idr{double_neg}:
339344

@@ -405,7 +410,7 @@ the same truth value, is just the conjunction of two implications.
405410
> iff : {p,q : Type} -> Type
406411
> iff {p} {q} = (p -> q, q -> p)
407412

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
409414
\idr{Control.Isomorphism}.
410415

411416
> syntax [p] "<->" [q] = iff {p} {q}
@@ -450,9 +455,7 @@ Some of Idris's tactics treat iff statements specially, avoiding the need for
450455
some low-level proof-state manipulation. In particular, rewrite and reflexivity
451456
can be used with iff statements, not just equalities. To enable this behavior,
452457
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).
456459

457460
Here is a simple example demonstrating how these tactics work with iff. First,
458461
let's prove a couple of basic iff equivalences...
@@ -477,9 +480,9 @@ let's prove a couple of basic iff equivalences...
477480
> fro (Left (Right q)) = Right $ Left q
478481
> fro (Right r) = Right $ Right r
479482

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:
483486

484487
> mult_0_3 : (n * m * p = Z) <->
485488
> ((n = Z) `Either` ((m = Z) `Either` (p = Z)))
@@ -498,8 +501,8 @@ mult_0 result:
498501
> fro {n} (Right (Left Refl)) = rewrite multZeroRightZero n in Refl
499502
> fro {n} {m} (Right (Right Refl)) = rewrite multZeroRightZero (n*m) in Refl
500503

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.
503506

504507
> apply_iff_example : (n, m : Nat) -> n * m = Z -> ((n = Z) `Either` (m = Z))
505508
> apply_iff_example n m = fst $ mult_0 {n} {m}
@@ -536,7 +539,7 @@ that \idr{p} holds of \idr{x}.
536539
Prove that "\idr{p} holds for all \idr{x}" implies "there is no \idr{x} for
537540
which \idr{p} does not hold."
538541

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)
540543
> dist_not_exists f = ?dist_not_exists_rhs
541544

542545
$\square$
@@ -679,6 +682,8 @@ $\square$
679682
One feature of Idris that distinguishes it from many other proof assistants is
680683
that it treats _proofs_ as first-class objects.
681684

685+
\todo[inline]{`nameref` the chapters when they're done}
686+
682687
There is a great deal to be said about this, but it is not necessary to
683688
understand it in detail in order to use Idris. This section gives just a taste,
684689
while a deeper exploration can be found in the optional chapters
@@ -716,23 +721,27 @@ wanted to prove the following result:
716721

717722
> plus_comm3 : (n, m, p : Nat) -> n + (m + p) = (p + m) + n
718723

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?)}
720726

721727
It appears at first sight that we ought to be able to prove this by rewriting
722728
with \idr{plusCommutative} twice to make the two sides match. The problem,
723729
however, is that the second \idr{rewrite} will undo the effect of the first.
724730

731+
```coq
725732
Proof.
726733
intros n m p.
727734
rewrite plus_comm.
728735
rewrite plus_comm.
729736
(* We are back where we started... *)
730737
Abort.
738+
```
731739

732740
One simple way of fixing this problem, using only tools that we already know, is
733741
to use assert to derive a specialized version of plus_comm that can be used to
734742
rewrite exactly where we want.
735743

744+
```coq
736745
Lemma plus_comm3_take2 :
737746
∀n m p, n + (m + p) = (p + m) + n.
738747
Proof.
@@ -743,10 +752,11 @@ Proof.
743752
rewrite H.
744753
reflexivity.
745754
Qed.
755+
```
746756

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.
750760

751761
> plus_comm3 n m p = rewrite plusCommutative n (m+p) in
752762
> 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
771781

772782
== Idris vs. Set Theory
773783

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}
775785

776786
Idris's logical core, the Calculus of Inductive Constructions, differs in some
777787
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:
806816
In common mathematical practice, two functions `f` and `g` are considered equal
807817
if they produce the same outputs:
808818

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+
\]
812822

813823
This is known as the principle of _functional extensionality_.
814824

@@ -830,7 +840,7 @@ function_equality_ex2 = ?stuck
830840
However, we can add functional extensionality to Idris's core logic using the
831841
\idr{really_believe_me} command.
832842

833-
> functional_extensionality : ((x:a) -> f x = g x) -> f = g
843+
> functional_extensionality : ((x : a) -> f x = g x) -> f = g
834844
> functional_extensionality = really_believe_me
835845

836846
Using \idr{really_believe_me} has the same effect as stating a theorem and
@@ -856,14 +866,16 @@ consistent.
856866
\todo[inline]{Is there such a command in Idris?}
857867

858868
To check whether a particular proof relies on any additional axioms, use the
859-
Print Assumptions command.
869+
`Print Assumptions` command.
860870

871+
```coq
861872
Print Assumptions function_equality_ex2.
862873
(* ===>
863874
Axioms:
864875
functional_extensionality :
865876
forall (X Y : Type) (f g : X -> Y),
866877
(forall x : X, f x = g x) -> f = g *)
878+
```
867879

868880

869881
==== Exercise: 4 stars (tr_rev)
@@ -928,7 +940,9 @@ We often say that the boolean \idr{evenb n} _reflects_ the proposition \idr{(k
928940
==== Exercise: 3 stars (evenb_double_conv)
929941

930942
> 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+
932946
> evenb_double_conv = ?evenb_double_conv_rhs
933947

934948
$\square$
@@ -1003,7 +1017,7 @@ Idris's core language, which is designed so that every function that it can
10031017
express is computable and total. One reason for this is to allow the extraction
10041018
of executable programs from Idris developments. As a consequence, \idr{Type} in
10051019
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
10071021
write non-computable functions.
10081022

10091023
Although general non-computable properties cannot be phrased as boolean
@@ -1038,6 +1052,9 @@ explicitly:
10381052
> even_1000'' : (k ** 1000 = double k)
10391053
> even_1000'' = (fst $ even_bool_prop {n=1000}) Refl
10401054
1055+
\todo[inline]{Add http://www.ams.org/journals/notices/200811/tx081101382p.pdf as
1056+
a link}
1057+
10411058
Although we haven't gained much in terms of proof size in this case, larger
10421059
proofs can often be made considerably simpler by the use of reflection. As an
10431060
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
12211238
infamous for leading to non-constructive proofs. Here's a typical example:
12221239
suppose that we want to show that there exists \idr{x} with some property
12231240
\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
12261243
fact results in a contradiction, we arrive at an existence proof without ever
12271244
exhibiting a value of \idr{x} for which \idr{p x} holds!
12281245

12291246
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
12311248
ourselves to remove double negations from arbitrary statements is equivalent to
12321249
assuming the excluded middle, as shown in one of the exercises below. Thus, this
12331250
line of reasoning cannot be encoded in Idris without assuming additional axioms.
@@ -1259,6 +1276,8 @@ equivalent:
12591276
(x : a) -> p x
12601277
```
12611278

1279+
\todo[inline]{Add a hyperlink}
1280+
12621281
The \idr{dist_not_exists} theorem above proves one side of this equivalence.
12631282
Interestingly, the other direction cannot be proved in constructive logic. Your
12641283
job is to show that it is implied by the excluded middle.

0 commit comments

Comments
 (0)