on master help sign in
rewrite documentation for interactive theorem proving
52c8677Martin Baker
docs/image/plusReducesProof.pngnew file

Binary file not shown.

docs/image/plusReducesProof.svgnew file+339
@@ -0,0 +1,339 @@
1+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+<!-- Created with Inkscape (http://www.inkscape.org/) -->
3+
4+<svg
5+ xmlns:dc="http://purl.org/dc/elements/1.1/"
6+ xmlns:cc="http://creativecommons.org/ns#"
7+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8+ xmlns:svg="http://www.w3.org/2000/svg"
9+ xmlns="http://www.w3.org/2000/svg"
10+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
11+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
12+ width="210mm"
13+ height="297mm"
14+ viewBox="0 0 744.09448819 1052.3622047"
15+ id="svg2"
16+ version="1.1"
17+ inkscape:version="0.91 r13725"
18+ sodipodi:docname="plusReducesProof.svg">
19+ <defs
20+ id="defs4">
21+ <marker
22+ inkscape:stockid="Arrow1Mend"
23+ orient="auto"
24+ refY="0.0"
25+ refX="0.0"
26+ id="marker6540"
27+ style="overflow:visible;"
28+ inkscape:isstock="true">
29+ <path
30+ id="path6542"
31+ d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
32+ style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
33+ transform="scale(0.4) rotate(180) translate(10,0)" />
34+ </marker>
35+ <marker
36+ inkscape:stockid="Arrow1Mend"
37+ orient="auto"
38+ refY="0.0"
39+ refX="0.0"
40+ id="marker5748"
41+ style="overflow:visible;"
42+ inkscape:isstock="true">
43+ <path
44+ id="path5750"
45+ d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
46+ style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
47+ transform="scale(0.4) rotate(180) translate(10,0)" />
48+ </marker>
49+ <marker
50+ inkscape:isstock="true"
51+ style="overflow:visible;"
52+ id="marker5154"
53+ refX="0.0"
54+ refY="0.0"
55+ orient="auto"
56+ inkscape:stockid="Arrow1Mend"
57+ inkscape:collect="always">
58+ <path
59+ transform="scale(0.4) rotate(180) translate(10,0)"
60+ style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
61+ d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
62+ id="path5156" />
63+ </marker>
64+ <marker
65+ inkscape:stockid="Arrow1Mend"
66+ orient="auto"
67+ refY="0.0"
68+ refX="0.0"
69+ id="Arrow1Mend"
70+ style="overflow:visible;"
71+ inkscape:isstock="true"
72+ inkscape:collect="always">
73+ <path
74+ id="path4189"
75+ d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
76+ style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
77+ transform="scale(0.4) rotate(180) translate(10,0)" />
78+ </marker>
79+ </defs>
80+ <sodipodi:namedview
81+ id="base"
82+ pagecolor="#ffffff"
83+ bordercolor="#666666"
84+ borderopacity="1.0"
85+ inkscape:pageopacity="0.0"
86+ inkscape:pageshadow="2"
87+ inkscape:zoom="1"
88+ inkscape:cx="397.18872"
89+ inkscape:cy="520"
90+ inkscape:document-units="px"
91+ inkscape:current-layer="layer1"
92+ showgrid="false"
93+ inkscape:window-width="1110"
94+ inkscape:window-height="1011"
95+ inkscape:window-x="-4"
96+ inkscape:window-y="0"
97+ inkscape:window-maximized="0" />
98+ <metadata
99+ id="metadata7">
100+ <rdf:RDF>
101+ <cc:Work
102+ rdf:about="">
103+ <dc:format>image/svg+xml</dc:format>
104+ <dc:type
105+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
106+ <dc:title></dc:title>
107+ </cc:Work>
108+ </rdf:RDF>
109+ </metadata>
110+ <g
111+ inkscape:label="Layer 1"
112+ inkscape:groupmode="layer"
113+ id="layer1">
114+ <text
115+ xml:space="preserve"
116+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:20px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
117+ x="266"
118+ y="225.36221"
119+ id="text4136"
120+ sodipodi:linespacing="125%"><tspan
121+ sodipodi:role="line"
122+ id="tspan4138"
123+ x="266"
124+ y="225.36221">assumptions</tspan><tspan
125+ sodipodi:role="line"
126+ x="266"
127+ y="250.36221"
128+ id="tspan4140">(context)</tspan></text>
129+ <text
130+ sodipodi:linespacing="125%"
131+ id="text4142"
132+ y="238.36221"
133+ x="526"
134+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:20px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;"
135+ xml:space="preserve"><tspan
136+ id="tspan4146"
137+ y="238.36221"
138+ x="526"
139+ sodipodi:role="line">goal</tspan></text>
140+ <text
141+ xml:space="preserve"
142+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
143+ x="420"
144+ y="289.36221"
145+ id="text4150"
146+ sodipodi:linespacing="125%"><tspan
147+ sodipodi:role="line"
148+ x="420"
149+ y="289.36221"
150+ id="tspan4152">(k : Nat) -&gt; (k = plus k 0) -&gt; S k = S (plus k 0)</tspan></text>
151+ <path
152+ style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
153+ d="m 241,262.3622 428,-1"
154+ id="path4154"
155+ inkscape:connector-curvature="0" />
156+ <path
157+ inkscape:connector-curvature="0"
158+ id="path4160"
159+ d="m 241,308.3622 428,-1"
160+ style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
161+ <text
162+ sodipodi:linespacing="125%"
163+ id="text4162"
164+ y="312.36221"
165+ x="175"
166+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;"
167+ xml:space="preserve"><tspan
168+ id="tspan4164"
169+ y="312.36221"
170+ x="175"
171+ sodipodi:role="line">intro `{{k}}</tspan></text>
172+ <text
173+ sodipodi:linespacing="125%"
174+ id="text4166"
175+ y="333.36221"
176+ x="482"
177+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
178+ xml:space="preserve"><tspan
179+ id="tspan4168"
180+ y="333.36221"
181+ x="482"
182+ sodipodi:role="line">(k = plus k 0) -&gt; S k = S (plus k 0)</tspan></text>
183+ <text
184+ xml:space="preserve"
185+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
186+ x="324"
187+ y="334.36221"
188+ id="text4170"
189+ sodipodi:linespacing="125%"><tspan
190+ sodipodi:role="line"
191+ x="324"
192+ y="334.36221"
193+ id="tspan4172">k : Nat</tspan></text>
194+ <path
195+ style="fill:none;fill-rule:evenodd;stroke:#0000ff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Mend)"
196+ d="m 441,294.3622 -73,30"
197+ id="path4174"
198+ inkscape:connector-curvature="0"
199+ sodipodi:nodetypes="cc" />
200+ <path
201+ style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
202+ d="m 241,352.3622 428,-1"
203+ id="path5134"
204+ inkscape:connector-curvature="0" />
205+ <text
206+ xml:space="preserve"
207+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
208+ x="171"
209+ y="355.36221"
210+ id="text5136"
211+ sodipodi:linespacing="125%"><tspan
212+ sodipodi:role="line"
213+ x="171"
214+ y="355.36221"
215+ id="tspan5138">intro `{{ih}}</tspan></text>
216+ <text
217+ xml:space="preserve"
218+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
219+ x="570"
220+ y="372.36221"
221+ id="text5140"
222+ sodipodi:linespacing="125%"><tspan
223+ sodipodi:role="line"
224+ x="570"
225+ y="372.36221"
226+ id="tspan5142">S k = S (plus k 0)</tspan></text>
227+ <text
228+ sodipodi:linespacing="125%"
229+ id="text5144"
230+ y="378.36221"
231+ x="324"
232+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
233+ xml:space="preserve"><tspan
234+ id="tspan5146"
235+ y="378.36221"
236+ x="324"
237+ sodipodi:role="line">k : Nat</tspan></text>
238+ <text
239+ sodipodi:linespacing="125%"
240+ id="text5150"
241+ y="393.36221"
242+ x="323"
243+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
244+ xml:space="preserve"><tspan
245+ id="tspan5152"
246+ y="393.36221"
247+ x="323"
248+ sodipodi:role="line">ih : k = plus k 0</tspan></text>
249+ <path
250+ inkscape:connector-curvature="0"
251+ id="path5728"
252+ d="m 242,404.3622 428,-1"
253+ style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
254+ <text
255+ sodipodi:linespacing="125%"
256+ id="text5730"
257+ y="408.36221"
258+ x="109"
259+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
260+ xml:space="preserve"><tspan
261+ id="tspan5732"
262+ y="408.36221"
263+ x="109"
264+ sodipodi:role="line">rewriteWith (Var `{{ih}})</tspan></text>
265+ <text
266+ sodipodi:linespacing="125%"
267+ id="text5734"
268+ y="424.36221"
269+ x="587"
270+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
271+ xml:space="preserve"><tspan
272+ id="tspan5736"
273+ y="424.36221"
274+ x="587"
275+ sodipodi:role="line">S k = S k </tspan></text>
276+ <text
277+ xml:space="preserve"
278+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
279+ x="325"
280+ y="430.36221"
281+ id="text5738"
282+ sodipodi:linespacing="125%"><tspan
283+ sodipodi:role="line"
284+ x="325"
285+ y="430.36221"
286+ id="tspan5740">k : Nat</tspan></text>
287+ <path
288+ style="fill:none;fill-rule:evenodd;stroke:#0000ff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker5748)"
289+ d="m 610,379.3622 1,29"
290+ id="path5742"
291+ inkscape:connector-curvature="0"
292+ sodipodi:nodetypes="cc" />
293+ <text
294+ xml:space="preserve"
295+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
296+ x="324"
297+ y="445.36221"
298+ id="text5744"
299+ sodipodi:linespacing="125%"><tspan
300+ sodipodi:role="line"
301+ x="324"
302+ y="445.36221"
303+ id="tspan5746">ih : k = plus k 0</tspan></text>
304+ <path
305+ inkscape:connector-curvature="0"
306+ id="path7294"
307+ d="m 418,460.3622 -2,-199"
308+ style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
309+ sodipodi:nodetypes="cc" />
310+ <path
311+ sodipodi:nodetypes="cc"
312+ inkscape:connector-curvature="0"
313+ id="path5148"
314+ d="m 519,339.3622 -107,44"
315+ style="fill:none;fill-rule:evenodd;stroke:#0000ff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker5154)" />
316+ <path
317+ style="fill:none;fill-rule:evenodd;stroke:#0000ff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:12, 2;stroke-dashoffset:0;stroke-opacity:1"
318+ d="m 609,391.3622 -197,49"
319+ id="path6538"
320+ inkscape:connector-curvature="0"
321+ sodipodi:nodetypes="cc" />
322+ <path
323+ style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
324+ d="m 242,458.3622 428,-1"
325+ id="path7308"
326+ inkscape:connector-curvature="0" />
327+ <text
328+ xml:space="preserve"
329+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.5px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
330+ x="177"
331+ y="462.36221"
332+ id="text7310"
333+ sodipodi:linespacing="125%"><tspan
334+ sodipodi:role="line"
335+ x="177"
336+ y="462.36221"
337+ id="tspan7312">reflexivity</tspan></text>
338+ </g>
339+</svg>
docs/proofs/interactive.rst+192−95
@@ -1,15 +1,110 @@
1−***************************************
1+***************************
2−DEPRECATED: Interactive Theorem Proving
2+Interactive Theorem Proving
3−***************************************
3+***************************
4
4
5−.. warning::
6− The interactive theorem-proving interface documented here has been
5+Idris also supports interactive theorem proving via elaborator reflection.
7− deprecated in favor of :ref:`elaborator-reflection`.
8
6
9−Idris also supports interactive theorem proving via tactics. This
7+:ref:'elaborator-reflection' is used to convert high-level Idris code into
10−is generally not recommended to be used directly, but rather used as a
8+the core language and for customising the language.
11−mechanism for building proof automation which is beyond the scope of this
9+
12−tutorial. In this section, we briefly discus tactics.
10+Here we show how to use it to interactively construct proofs.
11+
12+Elab and Pruviloj Libraries
13+===========================
14+
15+Elaborator reflection is defined in prelude/Language/Reflection/Elab.idr
16+and pruviloj is defined in Idris-dev/libs/pruviloj/
17+
18+``Elab`` defines the basics such as: solve, attack, intro, compute,
19+rewriteWith and others.
20+``pruviloj`` defines some more advanced derived commands such as:
21+reflexivity and others.
22+
23+To use ``pruviloj`` then call Idris with the "-p pruviloj" option and add:
24+ import Pruviloj
25+ import Pruviloj.Induction
26+to the top of your file.
27+
28+Here are the basic commands from Elab that we will need for the example on
29+this page:
30+
31+.. code-block:: idris
32+
33+ ||| Substitute a guess into a hole.
34+ export
35+ solve : Elab ()
36+ solve = Prim__Solve
37+
38+.. code-block:: idris
39+
40+ ||| Convert a hole to make it suitable for bindings - that is,
41+ ||| transform it such that it has the form `?h : t . h` as opposed to
42+ ||| `?h : t . f h`.
43+ |||
44+ ||| The binding tactics require that a hole be directly under its
45+ ||| binding, or else the scopes of the generated terms won't make
46+ ||| sense. This tactic creates a new hole of the proper form, and
47+ ||| points the old hole at it.
48+ export
49+ attack : Elab ()
50+ attack = Prim__Attack
51+
52+.. code-block:: idris
53+
54+ ||| Introduce a lambda binding around the current hole and focus on
55+ ||| the body. Requires that the hole be in binding form (use
56+ ||| `attack`).
57+ |||
58+ ||| @ n the name to use for the argument
59+ export
60+ intro : (n : TTName) -> Elab ()
61+ intro n = Prim__Intro (Just n)
62+
63+.. code-block:: idris
64+
65+ ||| Normalise the goal.
66+ export
67+ compute : Elab ()
68+ compute = Prim__Compute
69+
70+.. code-block:: idris
71+
72+ ||| Attempt to rewrite the goal using an equality.
73+ |||
74+ ||| The tactic searches the goal for applicable subterms, and
75+ ||| constructs a context for `replace` using them. In some cases,
76+ ||| this is not possible, and `replace` must be called manually with
77+ ||| an appropriate context.
78+ |||
79+ ||| Because this tactic internally introduces a `let` binding, it
80+ ||| requires that the hole be immediately under its binder (use
81+ ||| `attack` if it might not be).
82+ export
83+ rewriteWith : Raw -> Elab ()
84+ rewriteWith rule = Prim__Rewrite rule
85+
86+Here is the command from pruviloj that we will need for the example on
87+this page:
88+
89+.. code-block:: idris
90+
91+ ||| A special-purpose tactic that attempts to solve a goal using
92+ ||| `Refl`. This is useful for ensuring that goals in fact are trivial
93+ ||| when developing or testing other tactics; otherwise, consider
94+ ||| using `search`.
95+ reflexivity : Elab ()
96+ reflexivity =
97+ case !goalType of
98+ `((=) {A=~a} {B=~_} ~x ~_) =>
99+ do fill `(Refl {A=~a} {x=~x})
100+ solve
101+ _ => fail [ TextPart "The goal is not an equality, so"
102+ , NamePart `{reflexivity}
103+ , TextPart "is not applicable."
104+ ]
105+
106+Interactive Example: plusReduces
107+================================
13
108
14One way to write proofs interactively is to write the general *structure* of
109One way to write proofs interactively is to write the general *structure* of
15the proof, and use the interactive mode to complete the details.
110the proof, and use the interactive mode to complete the details.
@@ -25,145 +120,147 @@ hypothesis, and insert *holes* for the rest of the definition:
25
120
26.. code-block:: idris
121.. code-block:: idris
27
122
123+ import Pruviloj
124+ import Pruviloj.Induction
125+
28 plusReducesZ' : (n:Nat) -> n = plus n Z
126 plusReducesZ' : (n:Nat) -> n = plus n Z
29 plusReducesZ' Z = ?plusredZ_Z
127 plusReducesZ' Z = ?plusredZ_Z
30 plusReducesZ' (S k) = let ih = plusReducesZ' k in
128 plusReducesZ' (S k) = let ih = plusReducesZ' k in
31 ?plusredZ_S
129 ?plusredZ_S
32
130
33On running , two global names are created, ``plusredZ_Z`` and
131On running , two global names are created, ``plusredZ_Z`` and
34−``plusredZ_S``, with no definition. We can use the ``:m`` command at the
132+``plusredZ_S``, with no definition.
35−prompt to find out which holes are still to be solved (or, more
36−precisely, which functions exist but have no definitions), then the
37−``:t`` command to see their types:
38
133
39.. code-block:: idris
134.. code-block:: idris
40
135
41− *theorems> :m
136+ *theorems> : idris plusReducesZ.idr -p pruviloj
42− Global holes:
43− [plusredZ_S,plusredZ_Z]
44
137
45−.. code-block:: idris
138+ . / _/___/ /____(_)____
139+ / // __ / ___/ / ___/ Version 1.2.0
140+ _/ // /_/ / / / (__ ) http://www.idris-lang.org/
141+ /___/\__,_/_/ /_/____/ Type :? for help
46
142
47− *theorems> :t plusredZ_Z
143+ Idris is free software with ABSOLUTELY NO WARRANTY.
48− plusredZ_Z : Z = plus Z Z
144+ For details type :warranty.
145+ Holes: Main.plusredZ_S, Main.plusredZ_Z
49
146
50− *theorems> :t plusredZ_S
147+This tells us that we have two holes Main.plusredZ_S and Main.plusredZ_Z. We can solve
51− plusredZ_S : (k : Nat) -> (k = plus k Z) -> S k = plus (S k) Z
148+these separately, ``plusredZ_Z`` is the simplest so we will do that first.
52
149
53−The ``:p`` command enters interactive proof mode, which can be used to
150+The ``:elab plusredZ_Z`` command enters interactive proof mode, which can be used to
54−complete the missing definitions.
151+complete the missing definition for plusredZ_Z.
55
152
56.. code-block:: idris
153.. code-block:: idris
57
154
58− *theorems> :p plusredZ_Z
155+ *plusReducesZ> :elab plusredZ_Z
59
156
60− ---------------------------------- (plusredZ_Z) --------
157+ ---------- Goal: ----------
61− {hole0} : Z = plus Z Z
158+ {hole_0} : 0 = 0
62
159
63−This gives us a list of premises (above the line; there are none here)
160+This has been normalised to ``0 = 0`` so now we have to prove that ``0`` equals ``0``, which
64−and the current goal (below the line; named ``{hole0}`` here). At the
161+is easy to prove by reflexivity from pruviloj library:
65−prompt we can enter tactics to direct the construction of the proof. In
66−this case, we can normalise the goal with the ``compute`` tactic:
67
162
68.. code-block:: idris
163.. code-block:: idris
164+ -Main.plusredZ_Z> reflexivity
165+ plusredZ_Z: No more goals.
69
166
70− -plusredZ_Z> compute
167+This tells us that the proof is complete. We can now leave the interactive mode which
71−
168+we entered with the ``:elab`` command. We do this with the ``:qed`` command:
72− ---------------------------------- (plusredZ_Z) --------
73− {hole0} : Z = Z
74−
75−Now we have to prove that ``Z`` equals ``Z``, which is easy to prove by
76−``Refl``. To apply a function, such as ``Refl``, we use ``refine`` which
77−introduces subgoals for each of the function’s explicit arguments
78−(``Refl`` has none):
79
169
80.. code-block:: idris
170.. code-block:: idris
81
171
82− -plusredZ_Z> refine Refl
172+ -Main.plusredZ_Z> :qed
83− plusredZ_Z: no more goals
173+ Proof completed!
174+ Main.plusredZ_Z = %runElab (do reflexivity)
175+ Holes: Main.plusredZ_S
84
176
85−Here, we could also have used the ``trivial`` tactic, which tries to
177+This gives us a trace of the proof which is ``plusredZ_Z = %runElab (do reflexivity)``. We
86−refine by ``Refl``, and if that fails, tries to refine by each name in
178+can cut & paste this into the hole in the original file. This also tells us that we
87−the local context. When a proof is complete, we use the ``qed`` tactic
179+have another hole ``Main.plusredZ_S`` remaining.
88−to add the proof to the global context, and remove the hole from the
89−unsolved holes list. This also outputs a trace of the proof:
90
180
91−.. code-block:: idris
181+This remaining proof is bit more complicated, the following diagram gives an overview:
92
182
93− -plusredZ_Z> qed
183+|image|
94− plusredZ_Z = proof
95− compute
96− refine Refl
97
184
98−.. code-block:: idris
185+We approach this remaining proof in the same way by using the ``:elab`` command:
99−
100− *theorems> :m
101− Global holes:
102− [plusredZ_S]
103−
104−The ``:addproof`` command, at the interactive prompt, will add the proof
105−to the source file (effectively in an appendix). Let us now prove the
106−other required lemma, ``plusredZ_S``:
107
186
108.. code-block:: idris
187.. code-block:: idris
109
188
110− *theorems> :p plusredZ_S
189+ *plusReducesZ> :elab plusredZ_S
190+
111
191
112− ---------------------------------- (plusredZ_S) --------
192+ ---------- Goal: ----------
113− {hole0} : (k : Nat) -> (k = plus k Z) -> S k = plus (S k) Z
193+ {hole_0} : (k : Nat) -> (k = plus k 0) -> S k = S (plus k 0)
114
194
115In this case, the goal is a function type, using ``k`` (the argument
195In this case, the goal is a function type, using ``k`` (the argument
116accessible by pattern matching) and ``ih`` — the local variable
196accessible by pattern matching) and ``ih`` — the local variable
117containing the result of the recursive call. We can introduce these as
197containing the result of the recursive call. We can introduce these as
118−premises using the ``intro`` tactic twice (or ``intros``, which
198+assumptions using the ``intro`` tactic twice. The parameter is entered as
119−introduces all arguments as premises). This gives:
199+a constant of type ``TTName`` which is entered as a backtick with double
200+braces `{{ih}}. This gives:
120
201
121.. code-block:: idris
202.. code-block:: idris
122
203
204+ -Main.plusredZ_S> intro `{{k}}
205+
206+ ---------- Assumptions: ----------
123− k : Nat
207+ k : Nat
124− ih : k = plus k Z
208+ ---------- Goal: ----------
125− ---------------------------------- (plusredZ_S) --------
209+ {hole_0} : (k = plus k 0) -> S k = S (plus k 0)
126− {hole2} : S k = plus (S k) Z
210+ -Main.plusredZ_S> intro `{{ih}}
211+
212+ ---------- Assumptions: ----------
213+ k : Nat
214+ ih : k = plus k 0
215+ ---------- Goal: ----------
216+ {hole_0} : S k = S (plus k 0)
127
217
128Since plus is defined by recursion on its first argument, the term
218Since plus is defined by recursion on its first argument, the term
129``plus (S k) Z`` in the goal can be simplified, so we use ``compute``.
219``plus (S k) Z`` in the goal can be simplified, so we use ``compute``.
130
220
131.. code-block:: idris
221.. code-block:: idris
132
222
223+ -Main.plusredZ_S> compute
224+
225+ ---------- Assumptions: ----------
133− k : Nat
226+ k : Nat
134− ih : k = plus k Z
227+ ih : k = plus k 0
135− ---------------------------------- (plusredZ_S) --------
228+ ---------- Goal: ----------
136− {hole2} : S k = S (plus k Z)
229+ {hole_0} : S k = S (plus k 0)
230+
137
231
138We know, from the type of ``ih``, that ``k = plus k Z``, so we would
232We know, from the type of ``ih``, that ``k = plus k Z``, so we would
139like to use this knowledge to replace ``plus k Z`` in the goal with
233like to use this knowledge to replace ``plus k Z`` in the goal with
140−``k``. We can achieve this with the ``rewrite`` tactic:
234+``k``. We can achieve this with the ``rewriteWith`` tactic:
141
235
142.. code-block:: idris
236.. code-block:: idris
143
237
144− -plusredZ_S> rewrite ih
238+ -Main.plusredZ_S> rewriteWith (Var `{{ih}})
145
239
240+ ---------- Assumptions: ----------
146− k : Nat
241+ k : Nat
147− ih : k = plus k Z
242+ ih : k = plus k 0
148− ---------------------------------- (plusredZ_S) --------
243+ ---------- Goal: ----------
149− {hole3} : S k = S k
244+ {hole_0} : S k = S k
150
245
151− -plusredZ_S>
152−
153−The ``rewrite`` tactic takes an equality proof as an argument, and tries
246+The ``rewriteWith`` tactic takes an equality proof as an argument, and tries
154−to rewrite the goal using that proof. Here, it results in an equality
247+to rewrite the goal using that proof. The ih value is entered as a constant
248+of type ``TTName`` which is entered as a backtick with double braces `{{ih}} but
249+``rewriteWith`` requires a ``raw`` value so we use ``Var`` to do this conversion.
155−which is trivially provable:
250+Here, it results in an equality which is trivially provable using reflexivity:
156
251
157.. code-block:: idris
252.. code-block:: idris
158
253
159− -plusredZ_S> trivial
254+ -Main.plusredZ_S> reflexivity
160− plusredZ_S: no more goals
255+ plusredZ_S: No more goals.
161− -plusredZ_S> qed
256+ -Main.plusredZ_S> :qed
257+ Proof completed!
162− plusredZ_S = proof {
258+ Main.plusredZ_S = %runElab (do intro `{{k}}
163− intros;
259+ intro `{{ih}}
164− rewrite ih;
260+ compute
165− trivial;
261+ rewriteWith (Var `{{ih}})
166− }
262+ reflexivity)
263+
264+Again, we can cut & paste this into the hole in the original file.
167
265
168−Again, we can add this proof to the end of our source file using the
266+.. |image| image:: ../image/plusReducesProof.png
169−``:addproof`` command at the interactive prompt.