@@ -1245,42 +1245,42 @@ the following theorem:
1245
1245
1246
1246
\todo[inline]{Copy here for now }
1247
1247
1248
- > beq_nat_true : beq_nat n m = True -> n = m
1248
+ > beq_nat_true : {n, m : Nat} -> n == m = True -> n = m
1249
1249
> beq_nat_true {n=Z} {m=Z} _ = Refl
1250
1250
> beq_nat_true {n=(S _ )} {m=Z} Refl impossible
1251
1251
> beq_nat_true {n=Z} {m=(S _ )} Refl impossible
1252
1252
> beq_nat_true {n=(S n' )} {m=(S m' )} eq =
1253
1253
> rewrite beq_nat_true {n=n'} {m=m'} eq in Refl
1254
1254
>
1255
- > filter_not_empty_In : Not (filter (beq_nat n ) l = []) -> In n l
1255
+ > filter_not_empty_In : {n : Nat} -> Not (filter ((==) n) l = []) -> In n l
1256
1256
> filter_not_empty_In {l=[]} contra = contra Refl
1257
- > filter_not_empty_In {l=(x::_)} {n} contra with (beq_nat n x) proof h
1257
+ > filter_not_empty_In {l=(x::_)} {n} contra with (n == x) proof h
1258
1258
> filter_not_empty_In contra | True =
1259
1259
> Left $ sym $ beq_nat_true $ sym h
1260
1260
> filter_not_empty_In contra | False =
1261
1261
> Right $ filter_not_empty_In contra
1262
1262
>
1263
1263
1264
1264
In the second case we explicitly apply the \idr{beq_nat_true} lemma to the
1265
- equation generated by doing a dependent match on \idr{beq_nat n x}, to convert
1266
- the assumption \idr{beq_nat n x = True} into the assumption \idr{n = m}.
1265
+ equation generated by doing a dependent match on \idr{n == x}, to convert the
1266
+ assumption \idr{n == x = True} into the assumption \idr{n = m}.
1267
1267
1268
1268
We can streamline this by defining an inductive proposition that yields a better
1269
- case-analysis principle for \idr{beq_nat n m}. Instead of generating an equation
1270
- such as \idr{beq_nat n m = True}, which is generally not directly useful , this
1271
- principle gives us right away the assumption we really need : \idr{n = m}.
1269
+ case-analysis principle for \idr{n == m}. Instead of generating an equation such
1270
+ as \idr{n == m = True}, which is generally not directly useful , this principle
1271
+ gives us right away the assumption we really need: \idr{n = m}.
1272
1272
1273
1273
We'll actually define something a bit more general , which can be used with
1274
1274
arbitrary properties (and not just equalities ):
1275
1275
1276
+ \todo[inline]{Update the text: seems that additional \idr{(b=...)} constructor
1277
+ parameter is needed for this to work in Idris.}
1278
+
1276
1279
```idris
1277
1280
data Reflect : Type -> Bool -> Type where
1278
- ReflectT : (p : Type) -> Reflect p True
1279
- ReflectF : (p : Type) -> (Not p ) -> Reflect p False
1280
- ```
1281
-
1282
- \todo[inline]{Seems that additional `(b=True/False)` constructor parameter is
1283
- needed for this to work in Idris. Update the text.`}
1281
+ ReflectT : (p : Type) -> (b=True) -> Reflect p b
1282
+ ReflectF : (p : Type) -> (Not p ) -> (b=False) -> Reflect p b
1283
+ ```
1284
1284
1285
1285
Before explaining this, let's rearrange it a little: Since the types of both
1286
1286
\idr{ReflectT} and \idr{ReflectF} begin with \idr{(p : Type)}, we can make the
@@ -1327,18 +1327,18 @@ the second).
1327
1327
1328
1328
\todo[inline]{Copy here for now }
1329
1329
1330
- > beq_nat_true_iff : (n1, n2 : Nat) -> (beq_nat n1 n2 = True) <-> (n1 = n2)
1330
+ > beq_nat_true_iff : (n1, n2 : Nat) -> (n1 == n2 = True) <-> (n1 = n2)
1331
1331
> beq_nat_true_iff n1 n2 = (to, fro n1 n2)
1332
1332
> where
1333
- > to : (beq_nat n1 n2 = True) -> (n1 = n2)
1333
+ > to : (n1 == n2 = True) -> (n1 = n2)
1334
1334
> to = beq_nat_true {n=n1} {m=n2}
1335
- > fro : (n1, n2 : Nat) -> (n1 = n2) -> (beq_nat n1 n2 = True)
1335
+ > fro : (n1, n2 : Nat) -> (n1 = n2) -> (n1 == n2 = True)
1336
1336
> fro n1 n1 Refl = sym $ beq_nat_refl n1
1337
1337
>
1338
1338
> iff_sym : (p <-> q) -> (q <-> p)
1339
1339
> iff_sym (pq, qp) = (qp, pq)
1340
1340
>
1341
- > beq_natP : Reflect (n = m) (beq_nat n m)
1341
+ > beq_natP : {n, m : Nat} -> Reflect (n = m) (n == m)
1342
1342
> beq_natP {n} {m} = iff_reflect $ iff_sym $ beq_nat_true_iff n m
1343
1343
>
1344
1344
@@ -1352,7 +1352,7 @@ calls to destruct and apply are combined into a single call to destruct.
1352
1352
Idris and observe the differences in proof state at the beginning of the first
1353
1353
case of the destruct .)
1354
1354
1355
- > filter_not_empty_In' : Not (filter (beq_nat n ) l = []) -> In n l
1355
+ > filter_not_empty_In' : {n : Nat} -> Not (filter ((==) n) l = []) -> In n l
1356
1356
> filter_not_empty_In' {l=[]} contra = contra Refl
1357
1357
> filter_not_empty_In' {n} {l=(x::xs)} contra with (beq_natP {n} {m=x})
1358
1358
> filter_not_empty_In' _ | (ReflectT eq _) = Left $ sym eq
@@ -1364,8 +1364,8 @@ case of the destruct.)
1364
1364
> contra' = replace notbeq contra
1365
1365
> {P = \a =>
1366
1366
> Not ((if a
1367
- > then x :: filter (beq_nat n ) xs
1368
- > else filter (beq_nat n ) xs) = [])}
1367
+ > then x :: filter ((==) n) xs
1368
+ > else filter ((==) n) xs) = [])}
1369
1369
> in
1370
1370
> Right $ filter_not_empty_In' contra'
1371
1371
>
@@ -1377,7 +1377,7 @@ Use \idr{beq_natP} as above to prove the following:
1377
1377
1378
1378
> count : (n : Nat) -> (l : List Nat ) -> Nat
1379
1379
> count _ [] = 0
1380
- > count n (x :: xs) = (if beq_nat n x then 1 else 0 ) + count n xs
1380
+ > count n (x :: xs) = (if n == x then 1 else 0) + count n xs
1381
1381
>
1382
1382
> beq_natP_practice : count n l = 0 -> Not (In n l)
1383
1383
> beq_natP_practice prf = ?beq_natP_practice_rhs
0 commit comments