Check-in [018383954d]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added proof demo example.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bc-subst
Files: files | file ages | folders
SHA1:018383954d3aa610ecdf07390cedd31633f8f22c
User & Date: andy 2015-04-21 16:25:19
Context
2015-04-21
16:25
Removed hover styles from premise/conclusion classes (this should be handled in JS, so that it can be disabled when the proof is complete). check-in: 6feebbe110 user: andy tags: bc-subst
16:25
Added proof demo example. check-in: 018383954d user: andy tags: bc-subst
15:47
Fixed everything else to work with the new goal/clausal expansion. check-in: 52b0f899a0 user: andy tags: bc-subst, working
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added examples/proof-mockup.html.













































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Proof mockup</title>

    <link rel="stylesheet" href="../res/reset.css">
    <link rel="stylesheet" href="../res/base.css">

    <style type="text/css">

        #specification {
            position: absolute;
            top: 0;
            left: 0;
            width: 400px;
            text-align: center;
        }

        #rules {
            position: fixed;
            top: 0;
            left: 0;
            width: 400px;
            bottom: 0;
            overflow: scroll;
        }

        #proofs {
            position: absolute;
            left: 416px;
            right: 0;
            top: 0;
            padding-top: 32px;
            padding-right: 16px;
        }

        .proof {
            min-height: 600px;
            left: 16px;
            right: 32px;
            background: rgb(95%,95%,95%);
            border-radius: 16px;
            text-align: center;
        }

        .done {
            position:absolute;
            right: 32px;
            color: white;
            font-size: 200pt;
            margin-right: 16px;
            margin-top: 16px;
            z-index: 1;
        }

        #output {
            z-index: 2;
        }

        .statement {
            margin-bottom: 1em;
            line-height: 1.5;
        }

        .stmt {
            color: rgb(25%,25%,25%);
        }

    </style>

    <script src="../js/pengines.js"></script>
    <script src="../lib/jquery-2.1.1.min.js"></script>
    <script src="../lib/jquery.color-2.1.2.min.js"></script>

    <script src="repl.js"></script>

    <!-- Core Arend module -->
    <script src="../src/core.js"></script>

    <!-- Utility libraries -->
    <script src="../lib/lodash.js"></script>
    <script src="../lib/nodash.js"></script>
    <script src="../lib/fin.js"></script>

    <!-- Arend libraries -->
    <script src="../src/terms.js"></script>
    <script src="../src/proof.js"></script>
    <script src="../src/term_render.js"></script>
    <script src="../src/syntax.peg.js"></script>
    <script src="../src/parser.js"></script>

    <script type="text/javascript">

        var renderer;

        var specification;

        // For some stupid reason you need to allocate a different pengine
        // for each set of callbacks. This means that, although you can use
        // the same engine for different ask() requests, you cannot distinguish
        // between them in the onsuccess() functions. So we have to manually
        // keep track of what kind of request is in-flight.
        var pengine; 
        var request_type;

        var locked = false;

        // Technically we shouldn't be using the specification parser for this,
        // but it will do for now.
        var statement = arend.parser.parse("nat(X) -> add(X,0,X)", 
                                           {startRule: "term"});

        // Unlock/lock input, for when a request is in-flight.
        function unlock() {

            locked = false;
        }

        function lock() {

            locked = true;
        }

        // Update the display of the proof.
        function updateProof() {
            $("#output").html(renderer.renderProof(proof));
        }

        // Just recheck the proof as it currently is
        function recheck() {
            var pterm = arend.terms.toPrologString(proof);
            pengine.ask('check(' + pterm + ')');
        }

        // Send the proof to the server together with an elaborate request
        // and update the proof when the request returns
        function elaborate(path, what, data) {
            console.log("Path: " + path.toString());
            console.log("What: " + what);

            // Construct terms for Prolog
            //path = arend.terms.toList(path.map(function(e) {
            //    return new arend.terms.Atom(e);
            //}));
            path = '[' + path.join(",") + ']';

            // What can be either "goal" or "ctx". Data can be either a number
            // (if the target is a disjunction) or "ind" (for "goal") indicating
            // that we should backchain on the IH.
            what = new arend.terms.Atom(what);
            what = arend.terms.toPrologString(what);

            // We need *something* in data that is a valid Prolog term.
            data = typeof data === "undefined" ? 0 : data;
            data = new arend.terms.Atom(data);
            data = arend.terms.toPrologString(data);

            var pterm = arend.terms.toPrologString(proof);
            var query = "elaborate(" + pterm + "," + 
                                    path + "," + 
                                    what + "," +
                                    data + "," + 
                                    "Result)";

            console.log(query);

            lock();
            request_type = "elaborate";
            pengine.ask(query);
        }

        /* renderSpecification()
         * After the specification has been received, render it to the page.
         */
        function renderSpecification() {
        
            var spec = $("#specification");

            specification.forEach(function(r) {
                spec.append(renderer.renderRule(r));
                spec.append("<br>");
            });
        }

        function completeProof() {
            $(".done").fadeIn();
            $(".proof").animate({"backgroundColor" : "#D9F9D4"});
        }

        function checkCompleteness() {
            var pterm = arend.terms.toPrologString(proof);
            request_type = "complete";
            pengine.ask("complete(" + pterm + ")");
        }

        function onsuccess() {
            switch(request_type) {
                case "elaborate":
                    proof = arend.terms.fromJSON(this.data[0]['Result']);
                    updateProof();

                    // TODO: run another request to check for completeness
                    checkCompleteness();

                    unlock();
                    break;

                case "complete":
                    // onsuccess will only be called if the complete() query
                    // succeeded, so it's safe to mark the proof as complete.
                    completeProof();

                    // Intentionally leave it locked.
                    lock();
                    break;

            }
        }

        // Start everything up.
        $(document).ready(function() {

            pengine = new Pengine({
                destroy: false,
                application: "passist",
                onsuccess: onsuccess,

                // Make sure the controls get unlocked if something goes wrong.
                onfailure: function() { console.log("fail"); unlock() },
                ondestroy: function() { console.log("Destroy " + this.id); }
                //onerror: unlock 
            });

            renderer = new Renderer({
                // Setup the renderer so that proofs are elaborated when we
                // double-click an antecedant or consequent.
                premiseHook : function(e,path,i) {
                    var term = this;
                    $(e).dblclick(function(e) {
                            console.log('elaborate ctx');
                            console.log("path " + path);
                            console.log("index " + i);
                            console.log("prem " + term.toString());

                            elaborate(path,"ctx",i);
                            e.preventDefault();
                        })
                        .hover(function() { 
                                if(!locked)
                                    $(this).css( "background", "#E3ECF2");
                            },
                               function() { 
                                    if(!locked)
                                        $(this).css( "background", "");
                            });

                    return e;
                },

                conclusionHook : function(e,path) {
                    var term = this;
                    $(e).dblclick(function(e) {
                            // TODO: If the goal expands into more than one
                            // clause, this doesn't work well (it basically
                            // just chooses the first silently). 
                            if(e.which === 1) {

                                console.log("elaborate goal");
                                console.log(path);

                                elaborate(path,"goal","bc");

                                e.preventDefault();
                            }
                        }).keypress(function(e) {
                            // Press 'i' to apply IH
                            if(e.which === 105) {
                                console.log("elaborate IH");
                                console.log(path);

                                elaborate(path,"goal","ind");

                                e.preventDefault();
                            }
                            // Press 'a' to use the assumption rule.
                            else if(e.which === 97) {
                                console.log("elaborate ctxmem");

                                elaborate(path,"goal","asm");

                                e.preventDefault();
                            }
                        })
                        .hover(function() { 
                                if(!locked)
                                    $(this).css( "background", "#E3ECF2");
                            },
                               function() { 
                                    if(!locked)
                                        $(this).css( "background", "");
                            });

                    return e;
                },

                disjunctHook : function(e,path,i) {
                    var term = this;
                    $(e).dblclick(function(e) {
                        console.log(path);
                        e.preventDefault();
                    })
                }
            });   

            // Load the specification from the server
            var p1 = new Pengine({
                application: "passist",
                ask: "get_spec(Program)",
                onsuccess: function() {
                    specification = arend.terms.toArray(
                        arend.terms.fromJSON(
                            this.data[0]['Program']));

                    console.log(specification);

                    renderSpecification();
                    //p1.destroy();
                },
                onerror: function() {
                    $('#output').text(this.data);
                    //p1.destroy();
                }
            });

            // Load the initial proof from the server
            var p2 = new Pengine({
                application: "passist",
                ask: "demo_proof(Proof)",
                onsuccess: function() {
                    //var data = this.data[0]['Proof'];
                    proof = arend.terms.fromJSON(this.data[0]['Proof']);
                    console.log(proof.toString());
                    updateProof();
                    //p2.destroy();
                }
            });
        })

    </script>

  </head>
  <body>

    <!-- container for propositions+proofs -->
    <div id="proofs">
        <div class='statement'>Prove
            <span class='stmt'>&forall;X: 
                <span class='goal'>nat</span>(X) &rarr; 
            <span class='goal'>add</span>(X,z,X)</span>
        </div>
        <div class='proof'>
            <span id="output"></span>
            <span class="done" style="display: none">&#10003;</span>
        </div>
    </div>

    <!-- container for the rules (incl. IH) of the current spec. -->
    <div id="rules">
        <div id="specification"></div>
    </div>

  </body>
</html>