@@ -3,17 +3,19 @@ This page attempts to explain some of the techniques used in Idris to prove prop
3Proving Propositional Equality
3Proving Propositional Equality
4==============================
4==============================
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.
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.
10So to take the previous example:
10So to take the previous example:
12−plusReducesR : (n:Nat) -> plus n Z = n
14+ plusReducesR : (n:Nat) -> plus n Z = n
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``.
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.
@@ -24,19 +26,21 @@ So here:
24 plusReducesR {n = (S k)} = let rec = plus_commutes_Z {n=k} in
26 plusReducesR {n = (S k)} = let rec = plus_commutes_Z {n=k} in
25 rewrite rec in Refl
27 rewrite rec in Refl
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.
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 then P x = P y
39 then P x = P y
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``.
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``.
41To use this in our proofs there is the following function in the prelude:
45To use this in our proofs there is the following function in the prelude:
@@ -46,14 +50,14 @@ To use this in our proofs there is the following function in the prelude:
46 replace : {a:_} -> {x:_} -> {y:_} -> {P : a -> Type} -> x = y -> P x -> P y
50 replace : {a:_} -> {x:_} -> {y:_} -> {P : a -> Type} -> x = y -> P x -> P y
47 replace Refl prf = prf
51 replace Refl prf = prf
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``)
51.. code-block:: idris
55.. code-block:: idris
53 > :t replace
57 > :t replace
54 replace : (x = y) -> P x -> P y
58 replace : (x = y) -> P x -> P y
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``.
58.. code-block:: idris
62.. code-block:: idris
@@ -66,16 +70,16 @@ So, in the following example, if we supply p1 x which is a proof that x=2 and th
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.
71.. code-block:: idris
75.. code-block:: idris
73 rewrite__impl : (P : a -> Type) -> x = y -> P y -> P x
77 rewrite__impl : (P : a -> Type) -> x = y -> P y -> P x
74 rewrite__impl p Refl prf = prf
78 rewrite__impl p Refl prf = prf
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).
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``.
80.. code-block:: idris
84.. code-block:: idris
@@ -87,16 +91,16 @@ Example: again we supply p1 which is a proof that x=2 and the equality x=y then
88We can think of rewrite doing this:
92We can think of rewrite doing this:
90− * Start with a equation x=y and a property P: x -> Type
94+ * start with a equation ``x=y`` and a property ``P: x -> Type``;
91− * Searches y in P
95+ * search ``y`` in ``P``;
92− * Replaces all occurrences of y with x in P.
96+ * replace all occurrences of ``y`` with ``x`` in ``P``.
94That is, we are doing a substitution.
98That is, we are doing a substitution.
96Symmetry and Transitivity
100Symmetry and Transitivity
97=========================
101=========================
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:
101.. code-block:: idris
105.. code-block:: idris
@@ -111,7 +115,7 @@ In addition to 'reflexivity' equality also obeys 'symmetry' and 'transitivity' a
111Heterogeneous Equality
115Heterogeneous Equality
112======================
116======================
114−Also included in the prelude:
118+Also included in the prelude:
116.. code-block:: idris
120.. code-block:: idris