You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/proofs/propositional.rst
+23-19Lines changed: 23 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,19 @@ This page attempts to explain some of the techniques used in Idris to prove prop
3
3
Proving Propositional Equality
4
4
==============================
5
5
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.
7
7
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.
9
9
10
10
So to take the previous example:
11
11
12
-
plusReducesR : (n:Nat) -> plus n Z = n
12
+
.. code-block:: idris
13
+
14
+
plusReducesR : (n:Nat) -> plus n Z = n
13
15
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``.
15
17
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.
17
19
18
20
So here:
19
21
@@ -24,19 +26,21 @@ So here:
24
26
plusReducesR {n = (S k)} = let rec = plus_commutes_Z {n=k} in
25
27
rewrite rec in Refl
26
28
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.
28
30
29
31
Replace
30
32
=======
31
33
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::
33
37
34
38
if x=y
35
39
then P x = P y
36
40
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``.
38
42
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``.
40
44
41
45
To use this in our proofs there is the following function in the prelude:
42
46
@@ -46,14 +50,14 @@ To use this in our proofs there is the following function in the prelude:
46
50
replace : {a:_} -> {x:_} -> {y:_} -> {P : a -> Type} -> x = y -> P x -> P y
47
51
replace Refl prf = prf
48
52
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``)
50
54
51
55
.. code-block:: idris
52
56
53
57
> :t replace
54
58
replace : (x = y) -> P x -> P y
55
59
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``.
57
61
58
62
.. code-block:: idris
59
63
@@ -66,16 +70,16 @@ So, in the following example, if we supply p1 x which is a proof that x=2 and th
66
70
Rewrite
67
71
=======
68
72
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.
70
74
71
75
.. code-block:: idris
72
76
73
77
rewrite__impl : (P : a -> Type) -> x = y -> P y -> P x
74
78
rewrite__impl p Refl prf = prf
75
79
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).
77
81
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``.
79
83
80
84
.. code-block:: idris
81
85
@@ -87,16 +91,16 @@ Example: again we supply p1 which is a proof that x=2 and the equality x=y then
87
91
88
92
We can think of rewrite doing this:
89
93
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``.
93
97
94
98
That is, we are doing a substitution.
95
99
96
100
Symmetry and Transitivity
97
101
=========================
98
102
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:
100
104
101
105
.. code-block:: idris
102
106
@@ -111,7 +115,7 @@ In addition to 'reflexivity' equality also obeys 'symmetry' and 'transitivity' a
0 commit comments