Skip to content

Commit a084b61

Browse files
author
Alex Gryzlov
committed
WIP ImpParser
1 parent 0e999ee commit a084b61

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

src/IndProp.lidr

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ When checking argument n to IndType.Wrong_ev:
110110
Nat (Expected type)
111111
```
112112

113-
\todo[inline]{Edit the explanation, it works fine if you remove the first \idr{n
114-
->} in \idr{Wrong_ev_SS}}
113+
\todo[inline]{Edit the explanation, it works fine if you remove the first
114+
\idr{n ->} in \idr{Wrong_ev_SS}}
115115

116116
("Parameter" here is Idris jargon for an argument on the left of the colon in an
117117
Inductive definition; "index" is used to refer to arguments on the right of the
@@ -223,8 +223,8 @@ generates two subgoals. Even worse, in doing so, it keeps the final goal
223223
unchanged, failing to provide any useful information for completing the proof.
224224

225225
The inversion tactic, on the other hand, can detect (1) that the first case does
226-
not apply, and (2) that the \idr{n'} that appears on the \idr{Ev_SS} case must be the
227-
same as \idr{n}. This allows us to complete the proof
226+
not apply, and (2) that the \idr{n'} that appears on the \idr{Ev_SS} case must
227+
be the same as \idr{n}. This allows us to complete the proof
228228

229229
> evSS_ev (Ev_SS e') = e'
230230
>
@@ -283,10 +283,11 @@ trivially.
283283

284284
> ev_even Ev_0 = (Z ** Refl)
285285

286-
Unfortunately, the second case is harder. We need to show \idr{(k ** S (S n') =
287-
double k}, but the only available assumption is \idr{e'}, which states that
288-
\idr{Ev n'} holds. Since this isn't directly useful, it seems that we are stuck
289-
and that performing case analysis on \idr{Ev n} was a waste of time.
286+
Unfortunately, the second case is harder. We need to show
287+
\idr{(k ** S (S n') = double k}, but the only available assumption is \idr{e'},
288+
which states that \idr{Ev n'} holds. Since this isn't directly useful, it seems
289+
that we are stuck and that performing case analysis on \idr{Ev n} was a waste of
290+
time.
290291

291292
If we look more closely at our second goal, however, we can see that something
292293
interesting happened: By performing case analysis on \idr{Ev n}, we were able to
@@ -335,9 +336,9 @@ Let's try our current lemma again:
335336
> rewrite cprf in (S k ** Refl)
336337
>
337338

338-
Here, we can see that Idris produced an `IH` that corresponds to `E'`, the single
339-
recursive occurrence of ev in its own definition. Since E' mentions n', the
340-
induction hypothesis talks about n', as opposed to n or some other number.
339+
Here, we can see that Idris produced an `IH` that corresponds to `E'`, the
340+
single recursive occurrence of ev in its own definition. Since E' mentions n',
341+
the induction hypothesis talks about n', as opposed to n or some other number.
341342

342343
The equivalence between the second and third definitions of evenness now
343344
follows.
@@ -694,9 +695,9 @@ follows:
694695
> Star : Reg_exp t -> Reg_exp t
695696
>
696697

697-
Note that this definition is _polymorphic_: Regular expressions in \idr{Reg_exp
698-
t} describe strings with characters drawn from\idr{t} -- that is, lists of
699-
elements of \idr{t}.
698+
Note that this definition is _polymorphic_: Regular expressions in
699+
\idr{Reg_exp t} describe strings with characters drawn from\idr{t} -- that is,
700+
lists of elements of \idr{t}.
700701

701702
(We depart slightly from standard practice in that we do not require the type
702703
\idr{t} to be finite. This results in a somewhat different theory of regular
@@ -711,11 +712,11 @@ when a regular expression _matches_ some string:
711712

712713
- The expression \idr{Chr x} matches the one-character string \idr{[x]}.
713714

714-
- If \idr{re1} matches \idr{s1}, and \idr{re2} matches \idr{s2}, then \idr{App
715-
re1 re2} matches \idr{s1 ++ s2}.
715+
- If \idr{re1} matches \idr{s1}, and \idr{re2} matches \idr{s2}, then
716+
\idr{App re1 re2} matches \idr{s1 ++ s2}.
716717

717-
- If at least one of \idr{re1} and \idr{re2} matches \idr{s}, then \idr{Union
718-
re1 re2} matches \idr{s}.
718+
- If at least one of \idr{re1} and \idr{re2} matches \idr{s}, then
719+
\idr{Union re1 re2} matches \idr{s}.
719720

720721
- Finally, if we can write some string \idr{s} as the concatenation of a
721722
sequence of strings \idr{s = s_1 ++ ... ++ s_k}, and the expression \idr{re}
@@ -827,9 +828,9 @@ reg_exp_ex2 = MApp {s1=[1]} {s2=[2]} MChar MChar
827828
```
828829

829830
Notice how the last example applies \idr{MApp} to the strings \idr{[1]} and
830-
\idr{[2]} directly. While the goal mentions \idr{[1,2]} instead of \idr{[1] ++
831-
[2]}, Idris is able to figure out how to split the string on its own, so we can
832-
drop the implicits:
831+
\idr{[2]} directly. While the goal mentions \idr{[1,2]} instead of
832+
\idr{[1] ++ [2]}, Idris is able to figure out how to split the string on its
833+
own, so we can drop the implicits:
833834

834835
> reg_exp_ex2 : [1,2] =~ (App (Chr 1) (Chr 2))
835836
> reg_exp_ex2 = MApp MChar MChar
@@ -1257,11 +1258,11 @@ parameter of the whole \idr{data} declaration.
12571258

12581259
The reflect property takes two arguments: a proposition \idr{p} and a boolean
12591260
\idr{b}. Intuitively, it states that the property \idr{p} is _reflected_ in
1260-
(i.e., equivalent to) the boolean \idr{b}: \idr{p} holds if and only if \idr{b =
1261-
True}. To see this, notice that, by definition, the only way we can produce
1262-
evidence that \idr{Reflect p True} holds is by showing that \idr{p} is true and
1263-
using the \idr{ReflectT} constructor. If we invert this statement, this means
1264-
that it should be possible to extract evidence for \idr{p} from a proof of
1261+
(i.e., equivalent to) the boolean \idr{b}: \idr{p} holds if and only if
1262+
\idr{b = True}. To see this, notice that, by definition, the only way we can
1263+
produce evidence that \idr{Reflect p True} holds is by showing that \idr{p} is
1264+
true and using the \idr{ReflectT} constructor. If we invert this statement, this
1265+
means that it should be possible to extract evidence for \idr{p} from a proof of
12651266
\idr{Reflect p True}. Conversely, the only way to show \idr{Reflect p False} is
12661267
by combining evidence for \idr{Not p} with the \idr{ReflectF} constructor.
12671268

@@ -1336,9 +1337,9 @@ Use \idr{beq_natP} as above to prove the following:
13361337
$\square$
13371338

13381339
This technique gives us only a small gain in convenience for the proofs we've
1339-
seen here, but using \idr{Reflect} consistently often leads to noticeably shorter and
1340-
clearer scripts as proofs get larger. We'll see many more examples in later
1341-
chapters.
1340+
seen here, but using \idr{Reflect} consistently often leads to noticeably
1341+
shorter and clearer scripts as proofs get larger. We'll see many more examples
1342+
in later chapters.
13421343

13431344
\todo[inline]{Add http://math-comp.github.io/math-comp/ as a link}
13441345

@@ -1454,8 +1455,8 @@ and
14541455
Now, suppose we have a set \idr{t}, a function \idr{test : t->Bool}, and a list
14551456
\idr{l} of type \idr{List t}. Suppose further that \idr{l} is an in-order merge
14561457
of two lists, \idr{l1} and \idr{l2}, such that every item in \idr{l1} satisfies
1457-
\idr{test} and no item in \idr{l2} satisfies \idr{test}. Then \idr{filter test l
1458-
= l1}.
1458+
\idr{test} and no item in \idr{l2} satisfies \idr{test}. Then
1459+
\idr{filter test l = l1}.
14591460

14601461
Translate this specification into a Idris theorem and prove it. (You'll need to
14611462
begin by defining what it means for one list to be a merge of two others. Do
@@ -1531,18 +1532,19 @@ $\square$
15311532

15321533
=== Exercise: 4 stars, advanced, optional (NoDup)
15331534

1534-
Recall the definition of the \idr{In} property from the \idr{Logic} chapter, which asserts
1535-
that a value \idr{x} appears at least once in a list \idr{l}:
1535+
Recall the definition of the \idr{In} property from the \idr{Logic} chapter,
1536+
which asserts that a value \idr{x} appears at least once in a list \idr{l}:
15361537

15371538
```idris
15381539
In : (x : t) -> (l : List t) -> Type
15391540
In x [] = Void
15401541
In x (x' :: xs) = (x' = x) `Either` In x xs
15411542
```
15421543

1543-
Your first task is to use \idr{In} to define a proposition \idr{Disjoint {t} l1
1544-
l2}, which should be provable exactly when \idr{l1} and \idr{l2} are lists (with
1545-
elements of type \idr{t}) that have no elements in common.
1544+
Your first task is to use \idr{In} to define a proposition
1545+
\idr{Disjoint {t} l1 l2}, which should be provable exactly when \idr{l1} and
1546+
\idr{l2} are lists (with elements of type \idr{t}) that have no elements in
1547+
common.
15461548

15471549
> -- FILL IN HERE
15481550
>

0 commit comments

Comments
 (0)