Skip to content

Commit 5896027

Browse files
author
Alex Gryzlov
committed
fix Reflect and finish filter_not_empty_In'
1 parent b195470 commit 5896027

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/IndProp.lidr

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
> import Induction
77

88
> %hide Basics.Numbers.pred
9+
> %hide Prelude.Stream.(::)
910

1011

1112
== Inductively Defined Propositions
@@ -1208,14 +1209,16 @@ data Reflect : Type -> Bool -> Type where
12081209
ReflectF : (p : Type) -> (Not p) -> Reflect p False
12091210
```
12101211

1212+
\todo[inline]{Edit for new definition of `Reflect`}
1213+
12111214
Before explaining this, let's rearrange it a little: Since the types of both
12121215
\idr{ReflectT} and \idr{ReflectF} begin with \idr{(p : Type)}, we can make the
12131216
definition a bit more readable and easier to work with by making \idr{p} a
12141217
parameter of the whole \idr{data} declaration.
12151218

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
12191222

12201223
The reflect property takes two arguments: a proposition \idr{p} and a boolean
12211224
\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
12311234
indeed equivalent:
12321235

12331236
> 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
12361239

12371240

12381241
==== Exercise: 2 stars, recommended (reflect_iff)
@@ -1264,7 +1267,7 @@ the second).
12641267
> beq_natP : Reflect (n = m) (beq_nat n m)
12651268
> beq_natP {n} {m} = iff_reflect $ iff_sym $ beq_nat_true_iff n m
12661269

1267-
\todo[inline]{Edit text and finish the theorem}
1270+
\todo[inline]{Edit}
12681271

12691272
The new proof of filter_not_empty_In now goes as follows. Notice how the calls
12701273
to destruct and apply are combined into a single call to destruct.
@@ -1275,22 +1278,16 @@ the destruct.)
12751278

12761279
> filter_not_empty_In' : Not (filter (beq_nat n) l = []) -> In n l
12771280
> 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
12821284

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'
12941291

12951292

12961293
==== Exercise: 3 stars, recommended (beq_natP_practice)

0 commit comments

Comments
 (0)