6
6
> import Induction
7
7
8
8
> % hide Basics . Numbers . pred
9
+ > % hide Prelude . Stream . (:: )
9
10
10
11
11
12
== Inductively Defined Propositions
@@ -1208,14 +1209,16 @@ data Reflect : Type -> Bool -> Type where
1208
1209
ReflectF : (p : Type) -> (Not p ) -> Reflect p False
1209
1210
```
1210
1211
1212
+ \todo[inline]{Edit for new definition of `Reflect`}
1213
+
1211
1214
Before explaining this, let's rearrange it a little: Since the types of both
1212
1215
\idr{ReflectT} and \idr{ReflectF} begin with \idr{(p : Type)}, we can make the
1213
1216
definition a bit more readable and easier to work with by making \idr{p} a
1214
1217
parameter of the whole \idr{data} declaration.
1215
1218
1216
- > data Reflect : (p : Type) -> Bool -> Type where
1217
- > ReflectT : p -> Reflect p True
1218
- > ReflectF : (Not p ) -> Reflect p False
1219
+ > data Reflect : (p : Type) -> (b : Bool) -> Type where
1220
+ > ReflectT : p -> (b=True) -> Reflect p b
1221
+ > ReflectF : (Not p ) -> (b=False) -> Reflect p b
1219
1222
1220
1223
The reflect property takes two arguments : a proposition \idr{p} and a boolean
1221
1224
\idr{b}. Intuitively, it states that the property \idr{p} is _reflected_ in
@@ -1231,8 +1234,8 @@ It is easy to formalize this intuition and show that the two statements are
1231
1234
indeed equivalent :
1232
1235
1233
1236
> iff_reflect : (p <-> (b = True)) -> Reflect p b
1234
- > iff_reflect {b = True } (_, bp ) = ReflectT $ bp Refl
1235
- > iff_reflect {b = False } (pb, _ ) = ReflectF $ uninhabited . pb
1237
+ > iff_reflect {b = False } (pb, _ ) = ReflectF (uninhabited . pb) Refl
1238
+ > iff_reflect {b = True } (_, bp ) = ReflectT ( bp Refl ) Refl
1236
1239
1237
1240
1238
1241
==== Exercise: 2 stars , recommended (reflect_iff)
@@ -1264,7 +1267,7 @@ the second).
1264
1267
> beq_natP : Reflect (n = m) (beq_nat n m)
1265
1268
> beq_natP {n} {m} = iff_reflect $ iff_sym $ beq_nat_true_iff n m
1266
1269
1267
- \todo[inline]{Edit text and finish the theorem }
1270
+ \todo[inline]{Edit}
1268
1271
1269
1272
The new proof of filter_not_empty_In now goes as follows. Notice how the calls
1270
1273
to destruct and apply are combined into a single call to destruct .
@@ -1275,22 +1278,16 @@ the destruct.)
1275
1278
1276
1279
> filter_not_empty_In' : Not (filter (beq_nat n ) l = []) -> In n l
1277
1280
> filter_not_empty_In' {l=[]} contra = contra Refl
1278
- > filter_not_empty_In' {n} {l=(x::xs)} contra =
1279
- > let
1280
- > bq = beq_natP {n} {m=x}
1281
- > in ?aa
1281
+ > filter_not_empty_In' {n} {l=(x::xs)} contra with (beq_natP {n} {m=x})
1282
+ > filter_not_empty_In' _ | (ReflectT eq _) = Left $ sym eq
1283
+ > filter_not_empty_In' {n} {l=(x::xs)} contra | (ReflectF _ notbeq) = let
1282
1284
1283
- Proof.
1284
- intros n l. induction l as [|m l' IHl'].
1285
- - (* l = *)
1286
- simpl. intros H . apply H . reflexivity.
1287
- - (* l = m :: l' *)
1288
- simpl. destruct (beq_natP n m) as [H | H].
1289
- + (* n = m *)
1290
- intros _ . rewrite H . left. reflexivity.
1291
- + (* n <> m *)
1292
- intros H' . right. apply IHl' . apply H' .
1293
- Qed.
1285
+ \todo[inline]{How to rewrite more neatly here ?}
1286
+
1287
+ > contra' = replace notbeq contra {P = \a => Not ((if a
1288
+ > then x :: filter (beq_nat n ) xs
1289
+ > else filter (beq_nat n ) xs) = [])}
1290
+ > in Right $ filter_not_empty_In' contra'
1294
1291
1295
1292
1296
1293
==== Exercise: 3 stars , recommended (beq_natP_practice)
0 commit comments