@@ -3,17 +3,19 @@ This page attempts to explain some of the techniques used in Idris to prove prop
33Proving Propositional Equality
44==============================
55
6−We have seen that definitional equalities can be proved using Refl since they always normalise to unique values that can be compared directly.
6+We have seen that definitional equalities can be proved using ``Refl`` since they always normalise to unique values that can be compared directly.
77
8−However with propositional equalities we are using symbolic variables they do not always normalse.
8+However with propositional equalities we are using symbolic variables they do not always normalise.
99
1010So to take the previous example:
1111
12−plusReducesR : (n:Nat) -> plus n Z = n
12+.. code-block:: idris
13+
14+ plusReducesR : (n:Nat) -> plus n Z = n
1315
14−In this case 'plus n Z' does not normalise to n. Even though both sides are equal we cannot pattern match Refl.
16+In this case ``plus n Z`` does not normalise to ``n``. Even though both sides are equal we cannot pattern match ``Refl``.
1517
16−If the pattern match cannot match for all 'n' then the way around this is to separately match all possible values of 'n'. In the case of natural numbers we do this by induction.
18+If the pattern match cannot match for all ``n`` then the way around this is to separately match all possible values of ``n``. In the case of natural numbers we do this by induction.
1719
1820So here:
1921
@@ -24,19 +26,21 @@ So here:
2426 plusReducesR {n = (S k)} = let rec = plus_commutes_Z {n=k} in
2527 rewrite rec in Refl
2628
27−we don't call Refl to match on 'n = plus n 0' forall 'n' we call it for every number separately. So, in the second line, the pattern matcher knows to substitute Z for n in the type being matched. This uses 'rewrite' which is explained below.
29+we don't call ``Refl`` to match on ``n = plus n 0`` forall ``n`` we call it for every number separately. So, in the second line, the pattern matcher knows to substitute ``Z`` for ``n`` in the type being matched. This uses ``rewrite`` which is explained below.
2830
2931Replace
3032=======
3133
32−This implements the 'indiscernability of identicals' principle, if two terms are equal then they have the same properties. In other words, if x=y, then we can substitute y for x in any expression. In our proofs we can express this as:
34+This implements the *indiscernability of identicals* principle, if two terms are equal then they have the same properties. In other words, if ``x=y``, then we can substitute ``y`` for ``x`` in any expression. In our proofs we can express this as:
35+
36+.. code-block::
3337
3438 if x=y
3539 then P x = P y
3640
37−where P is a pure function representing the property. In the examples below P is an expression in some variable with a type like this: P: n -> Type
41+where ``P`` is a pure function representing the property. In the examples below ``P`` is an expression in some variable with a type like this: ``P: n -> Type``.
3842
39−So if n is a natural number variable then P could be something like 2*n + 3.
43+So if ``n`` is a natural number variable then ``P`` could be something like ``2*n + 3``.
4044
4145To use this in our proofs there is the following function in the prelude:
4246
@@ -46,14 +50,14 @@ To use this in our proofs there is the following function in the prelude:
4650 replace : {a:_} -> {x:_} -> {y:_} -> {P : a -> Type} -> x = y -> P x -> P y
4751 replace Refl prf = prf
4852
49−Removing the implicits, if we supply an equality (x=y) and a proof of a property of x (P x) then we get a proof of a property of y (P y)
53+Removing the implicits, if we supply an equality ``x=y`` and a proof of a property of ``x`` (i.e. ``P x``) then we get a proof of a property of ``y`` (i.e. ``P y``)
5054
5155.. code-block:: idris
5256
5357 > :t replace
5458 replace : (x = y) -> P x -> P y
5559
56−So, in the following example, if we supply p1 x which is a proof that x=2 and the equality x=y then we get a proof that y=2.
60+So, in the following example, if we supply ``p1 x`` which is a proof that ``x=2`` and the equality ``x=y`` then we get a proof that ``y=2``.
5761
5862.. code-block:: idris
5963
@@ -66,16 +70,16 @@ So, in the following example, if we supply p1 x which is a proof that x=2 and th
6670Rewrite
6771=======
6872
69−Similar to 'replace' above but Idris provides a nicer syntax which makes 'rewrite' easier to use in examples like plusReducesR above.
73+Similar to ``replace`` above but Idris provides a nicer syntax which makes ``rewrite`` easier to use in examples like ``plusReducesR`` above.
7074
7175.. code-block:: idris
7276
7377 rewrite__impl : (P : a -> Type) -> x = y -> P y -> P x
7478 rewrite__impl p Refl prf = prf
7579
76−The difference from 'replace' above is nicer syntax and the property p1 is explicitly supplied and it goes in the opposite direction (input and output reversed).
80+The difference from ``replace`` above is nicer syntax and the property ``p1`` is explicitly supplied and it goes in the opposite direction (input and output reversed).
7781
78−Example: again we supply p1 which is a proof that x=2 and the equality x=y then we get a proof that y=2.
82+Example: again we supply ``p1`` which is a proof that ``x=2`` and the equality ``x=y`` then we get a proof that ``y=2``.
7983
8084.. code-block:: idris
8185
@@ -87,16 +91,16 @@ Example: again we supply p1 which is a proof that x=2 and the equality x=y then
8791
8892We can think of rewrite doing this:
8993
90− * Start with a equation x=y and a property P: x -> Type
91− * Searches y in P
92− * Replaces all occurrences of y with x in P.
94+ * start with a equation ``x=y`` and a property ``P: x -> Type``;
95+ * search ``y`` in ``P``;
96+ * replace all occurrences of ``y`` with ``x`` in ``P``.
9397
9498That is, we are doing a substitution.
9599
96100Symmetry and Transitivity
97101=========================
98102
99−In addition to 'reflexivity' equality also obeys 'symmetry' and 'transitivity' and these are also included in the prelude:
103+In addition to *reflexivity* equality also obeys *symmetry* and *transitivity* and these are also included in the prelude:
100104
101105.. code-block:: idris
102106
@@ -111,7 +115,7 @@ In addition to 'reflexivity' equality also obeys 'symmetry' and 'transitivity' a
111115Heterogeneous Equality
112116======================
113117
114−Also included in the prelude:
118+Also included in the prelude:
115119
116120.. code-block:: idris
117121