1
1
= IndPrinciples : Induction Principles
2
2
3
3
> module IndPrinciples
4
-
4
+ >
5
+ > import IndProp
6
+ >
5
7
> % access public export
6
8
> % default total
9
+ >
7
10
8
11
With the Curry - Howard correspondence and its realization in Idris in mind, we
9
12
can now take a deeper look at induction principles.
10
13
14
+ \ \ todo[inline]{We've written all induction principles by hand throughout the
15
+ chapter, Idris doesn't generate them. Edit the text to reflect this}
11
16
12
- == Basics
13
17
14
- \ \ todo[inline]{ Edit , this is probably also made redundant by pattern matching}
18
+ == Basics
15
19
16
20
Every time we declare a new \ idr{data} type, Idris automatically generates an
17
21
_induction principle_ for this type. This induction principle is a theorem like
@@ -433,11 +437,11 @@ evidence.
433
437
For example , from what we've said so far , you might expect the inductive
434
438
definition of \idr{Ev}...
435
439
436
- \todo[inline]{ Redefine for now}
437
-
438
- > data Ev : Nat -> Type where
439
- > Ev_0 : Ev Z
440
- > Ev_SS : Ev n -> Ev (S ( S n ))
440
+ ```idris
441
+ data Ev : Nat -> Type where
442
+ Ev_0 : Ev Z
443
+ Ev_SS : Ev n -> Ev (S ( S n ))
444
+ ```
441
445
442
446
...to give rise to an induction principle that looks like this...
443
447
@@ -510,13 +514,6 @@ example, we can use it to show that \idr{Ev'} (the slightly awkward alternate
510
514
definition of evenness that we saw in an exercise in the `IndProp` chapter)
511
515
is equivalent to the cleaner inductive definition \idr{Ev}:
512
516
513
- \todo[inline]{Copy here for now }
514
-
515
- > data Ev' : Nat -> Type where
516
- > Ev'_0 : Ev' Z
517
- > Ev'_2 : Ev' 2
518
- > Ev'_sum : Ev' n -> Ev' m -> Ev' (n + m)
519
-
520
517
> ev_ev' : Ev n -> Ev' n
521
518
> ev_ev' {n} = ev_ind {P=Ev'}
522
519
> Ev'_0
@@ -539,13 +536,13 @@ argument \idr{n} is the same everywhere in the definition, so we can actually
539
536
make it a "general parameter " to the whole definition , rather than an argument
540
537
to each constructor.
541
538
542
- \todo[inline]{This doesn't seem to change anything }
543
-
544
- > data Le : (n:Nat) -> Nat -> Type where
545
- > Le_n : Le n n
546
- > Le_S : Le n m -> Le n (S m )
539
+ \todo[inline]{This doesn't actually seem to change anything in our case }
547
540
548
- > syntax [m] "<='" [n] = Le m n
541
+ ```idris
542
+ data Le : (n:Nat) -> Nat -> Type where
543
+ Le_n : Le n n
544
+ Le_S : Le n m -> Le n (S m )
545
+ ```
549
546
550
547
The second one is better, even though it looks less symmetric . Why? Because it
551
548
gives us a simpler induction principle .
@@ -655,8 +652,9 @@ this form of proof is also known as _induction on derivations_.
655
652
656
653
_Template_:
657
654
658
- - _Theorem_: <Proposition of the form "\idr{Q -> P}," where \idr{Q} is some inductively
659
- defined proposition (more generally , "For all \idr{x} \idr{y} \idr{z}, \idr{Q x y z -> P x y z }")>
655
+ - _Theorem_: <Proposition of the form "\idr{Q -> P}," where \idr{Q} is some
656
+ inductively defined proposition (more generally , "For all \idr{x} \idr{y}
657
+ \idr{z}, \idr{Q x y z -> P x y z }")>
660
658
661
659
_Proof_: By induction on a derivation of \idr{Q}. <Or, more generally ,
662
660
"Suppose we are given \idr{x}, \idr{y}, and \idr{z}. We show that
0 commit comments