git @ Cat's Eye Technologies Maxixe / master doc / Maxixe.md
master

Tree @master (Download .tar.gz)

Maxixe.md @masterview rendered · raw · history · blame

  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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
Maxixe
======

This document describes the Maxixe proof-checking language.

It contains many examples of proofs written in Maxixe.  These examples
are written in [Falderal][] format so that, as well as illustrating the
language for human readers, they can be automatically checked and thus
serve as a test suite.

However, because these examples are designed to show what is and what
is not valid in Maxixe, these proofs are neither particularly realistic
nor particularly interesting.  For examples of proofs that are more
interesting than these, please see the [Examples.md](Examples.md) document.

Note that in these examples the `===> ok` or the `???>` line is not part
of the proof (or even part of Maxixe's syntax); these lines are for
Falderal's benefit.

[Falderal]:     http://catseye.tc/node/Falderal

    -> Tests for functionality "Check Maxixe proof"

Basic Proof Structure
---------------------

A Maxixe proof consists of 3 sections: `given`, in which rules of inference
(including axioms and premises) are defined; `show`, which declares the goal
of the proof; and `proof`, which lists the steps to derive the goal from
the rules.

This is probably the shortest possible valid proof that can be written in
Maxixe (as well as the least interesting one).  It proves exactly what is
stated as a premise.

    given
        A = |- a
    show
        a
    proof
        C = a by A
    qed
    ===> ok

### Rules ###

In Maxixe we often call rules of inference just 'rules' for short.

A rule of inference consists of a name, an equals sign (`=`), a semicolon-separated
list of zero or more hypotheses, a turnstile (`|-`), and a conclusion.

A name must start with an upper-case letter and otherwise consists of alphanumeric
characters and underscores.

    given
        foo = |- a
    show
        a
    proof
        C = a by A
    qed
    ???> Expected variable, but found atom

No two rules may have the same name.

    given
        A = |- a
        A = |- b
    show
        a
    proof
        C = a by A
    qed
    ???> name has already been used for a rule of inference

Each hypothesis is a term, and so is the conclusion.  A term is given by a _constructor_,
which starts with a lower-case letter or a decimal digit and otherwise consists of
alphanumeric characters and underscores, followed by an optional comma-separated list
of subterms enclosed in parentheses.  A term with no subterms is called an _atom_.

    given
        A = atom_1 |- atom_2
        B =        |- term(subterm(a, b), c)
    show
        term(subterm(a, b), c)
    proof
        C = term(subterm(a, b), c) by B
    qed
    ===> ok

A term may also be a _variable_, in which case it starts with an upper-case letter.
Variables play a special role in the proof-checking process.

TODO: describe pattern-matching here!

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule with S1
    qed
    ===> ok

The conclusion may not contain any variables which do not appear in the hypotheses.

    given
        Rule    = P |- and(P, Q)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule with S1
    qed
    ???> Q

### Goal ###

The term given as the goal of a proof must not contain any variables.

    given
        A = |- a
    show
        A
    proof
        C = a by A
    qed
    ???> goal is not ground

### Steps ###

Each step in a proof consists of a name, an equals sign, a term, and a justification.

    given
        A = |- a
    show
        a
    proof
        a by A
    qed
    ???> Expected variable, but found atom

A step may not have the same name as a rule of inference.

    given
        A = |- a
    show
        a
    proof
        A = a by A
    qed
    ???> name has already been used for a rule of inference

No two steps may have the same name.

    given
        A = |- a
    show
        a
    proof
        C = a by A
        C = a by A
    qed
    ???> name has already been used for a step

Each step in a proof must name the rule being used in the justification (the `by` part)
of the step.

    given
        A = |- a
    show
        a
    proof
        C = a
    qed
    ???> Expected 'by'

The term given in a step of a proof must not contain any variables.

    given
        A = |- a
    show
        a
    proof
        C = Foo by A
    qed
    ???> 

If the rule named in the step of the proof has one or more hypotheses, the step
must also give _arguments_ to use in _instantiating_ the rule.  It must give exactly
one argument for every hypothesis.

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule
    qed
    ???> Number of arguments provided (0) does not match number of hypotheses (1)

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule with S1, S1
    qed
    ???> Number of arguments provided (2) does not match number of hypotheses (1)

The rule named in the justification must be one of the defined rules of inference.

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Zanzibar_Land with S1
    qed
    ???> Zanzibar_Land

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by S1 with S1
    qed
    ???> S1

In most cases, the arguments given in the justification must be names of steps.
that occur before the current step in the proof.

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule with Zanzibar_Land
    qed
    ???> Zanzibar_Land

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule with Premise
    qed
    ???> Premise

Importantly, the steps given as arguments in a justification must occur *before*
the current step of the proof.

    given
        Rule    = P |- and(P, P)
        Premise =   |- foo
    show
        and(foo, foo)
    proof
        S1 = foo           by Premise
        S2 = and(foo, foo) by Rule with S2
    qed
    ???> In step 'S2': Step name 'S2' in with is not the name of a preceding step

Importantly, the term given in a step of a proof must follow from the rule and
arguments given in the step's justification.

    given
        A = |- a
    show
        a
    proof
        C = foo by A
    qed
    ???> foo does not follow from A

Importantly, the term in the last step in the proof must equal the term given
in `show`.

    given
        A = |- a
    show
        foo
    proof
        C = a by A
    qed
    ???> proof does not reach goal

Attributes and Substitution
---------------------------

Here is the exception to the rule that an argument in a justification must be
the name of a step.  Hypotheses may be decorated with _attributes_ in curly
braces.  If a hypothesis is given the attribute `term`, the argument may be
any ground term.

    given
        A = X{term} |- foo(X)
    show
        foo(zing(bar))
    proof
        C = foo(zing(bar)) by A with zing(bar)
    qed
    ===> ok

    given
        A = X{term} |- foo(X)
    show
        foo(zing(bar))
    proof
        C = foo(zing(bar)) by A with zing(Foo)
    qed
    ???> Not all variables replaced during rule instantiation

If a hypothesis is given the attribute `atom`, the argument may be any atom.

    given
        A = X{atom} |- foo(X)
    show
        foo(bar)
    proof
        C = foo(bar) by A with bar
    qed
    ===> ok

    given
        A = X{atom} |- foo(X)
    show
        foo(zing(bar))
    proof
        C = foo(zing(bar)) by A with zing(bar)
    qed
    ???> not an atom

The conclusion may be optionally followed by a substitution, which is a
comma-separated list of term-term pairs enclosed in square brackets.
If a substitution is given, all the terms will be replaced by the other
terms after conclusion has been derived.

    given
        A       = P ; X{atom} |- P[f->X]
        Premise =             |- foo(f)
    show
        foo(bar)
    proof
        S1 = foo(f)   by Premise
        S2 = foo(bar) by A with S1, bar
    qed
    ===> ok

    given
        A       = P ; X{atom} |- P[X->f]
        Premise =             |- foo(bar)
    show
        foo(f)
    proof
        S1 = foo(bar) by Premise
        S2 = foo(f)   by A with S1, bar
    qed
    ===> ok


Subproofs
---------

A proof may consist of nested subproofs, called _blocks_.  Each block must be introduced by
instantiating a specially-declared _block rule_.  The structure of a block rule determines
rules determine the structure of the block.

A block rule (and thus a block) consists of one or more _cases_.  Each case contains one
or two non-block rules.  The first rule must be used in the first step of the case, and
the second rule, if given, must be used in the final step of the case.

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
                C = b |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1
                S3 = c by C with S2
            end
        end
        S4 = d by D with S3
    qed
    ===> ok

If the second rule is not given, no restriction is placed on the final step of the case.

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
            end
        end
        C = b |- c
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1
                S3 = c by C with S2
            end
        end
        S4 = d by D with S3
    qed
    ===> ok

As an act of syntactic sugar, if a block contains only one case, the `case` ... `end`
may be omitted, both in the proof, and in the rule definition.

    given
        A =   |- a
        block Subproof
            B = a |- b
        end
        C = b |- c
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            S2 = b by B with S1
            S3 = c by C with S2
        end
        S4 = d by D with S3
    qed
    ===> ok

Blocks may contain other blocks.

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
                C = b |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1
                block Subproof
                    case
                        S3 = b by B with S1
                        S4 = c by C with S3
                    end
                end
                S5 = c by C with S2
            end
        end
        S6 = d by D with S5
    qed
    ===> ok

A step may refer to any preceding step in the same block, or in any
outer block (i.e. any block that contains the current block.)

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
                C = b |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        S2 = a by A
        block Subproof
            case
                S3 = b by B with S1
                S4 = b by B with S2
                S5 = c by C with S3
                S6 = c by C with S4
            end
        end
        S7 = d by D with S6
    qed
    ===> ok

However, a step may only refer to the _final_ step in any inner block
(i.e. any block that is contained by the current block.)

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
                C = b |- c
            end
        end
        D = c |- d
    show
        c
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1
                S3 = c by C with S2
            end
        end
        S4 = c by C with S2
    qed
    ???> S2 is a non-final step in an inner block

The rule in the justification of the first step in a case must be the initial
rule specified for the case in the block rule.

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
                C = b |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                Sw = a by A
                S2 = b by B with S1
                S3 = c by C with S2
            end
        end
        S4 = d by D with S3
    qed
    ???> initial step of case 1 of Subproof must use rule B

The rule in the justification of the last step in a case must be the final
rule specified for the case in the block rule.

    given
        A =   |- a
        block Subproof
            case
                B = a |- b
                C = b |- c
            end
        end
        D = c |- d
        E = a |- c
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1
                S3 = c by C with S2
                S4 = c by E with S1
            end
        end
        S5 = d by D with S4
    qed
    ???> final step of case 1 of Subproof must use rule C

A block in a proof must have the same number of cases as the block rule used.

    given
        A =   |- a
        B = a |- b
        C = a |- c
        block Subproof
            case
                D = b |- d
                E = X |- X
            end
            case
                F = c |- d
                G = X |- X
            end
        end
        H = X |- X
    show
        d
    proof
        S1 = a by A
        S2 = b by B with S1
        S3 = c by C with S1
        block Subproof
            case
                S4 = d by D with S2
                S5 = d by E with S4
            end
            case
                S6 = d by F with S3
                S7 = d by G with S6
            end
        end
        S8 = d by H with S5
    qed
    ===> ok

    given
        A =   |- a
        B = a |- b
        C = a |- c
        block Subproof
            case
                D = b |- d
                E = X |- X
            end
            case
                F = c |- d
                G = X |- X
            end
        end
        H = X |- X
    show
        d
    proof
        S1 = a by A
        S2 = b by B with S1
        S3 = c by C with S1
        block Subproof
            case
                S4 = d by D with S2
                S5 = d by E with S4
            end
        end
        S8 = d by H with S5
    qed
    ???> block must have same number of cases as block rule

    given
        A =   |- a
        B = a |- b
        C = a |- c
        block Subproof
            case
                D = b |- d
                E = X |- X
            end
        end
        H = X |- X
    show
        d
    proof
        S1 = a by A
        S2 = b by B with S1
        S3 = c by C with S1
        block Subproof
            case
                S4 = d by D with S2
                S5 = d by E with S4
            end
            case
                S6 = d by D with S3
                S7 = d by E with S6
            end
        end
        S8 = d by H with S5
    qed
    ???> block must have same number of cases as block rule

When a block has multiple cases, the last step in each case must contain
the same term.

    given
        A =   |- a
        B = a |- b
        C = a |- c
        block Subproof
            case
                D = b |- d
                E = X |- X
            end
            case
                F = c |- d
                G = X |- X
            end
        end
        H = X |- X
    show
        d
    proof
        S1 = a by A
        S2 = b by B with S1
        S3 = c by C with S1
        block Subproof
            case
                S4 = d by D with S2
                S5 = d by E with S4
            end
            case
                S6 = d by F with S3
                Sw = c by H with S3
                S7 = c by G with Sw
            end
        end
        S8 = d by H with S5
    qed
    ???> cases do not finish with same term

### Locals ###

If a hypothesis has the `local` attribute, its argument must be an atom, and that atom may
only occur in the block in which the hypothesis is invoked.  To enforce this, because outer
blocks may only access the final step of a case in a block anyway, we only need check that
it does not occur in the final step of any case of the block.

    given
        A =   |- a
        block Subproof
            case
                B = a ; Q{local atom} |- Q
                C = b                 |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1, b
                S3 = c by C with S2
            end
        end
        S4 = d by D with S3
    qed
    ===> ok

    given
        A =   |- a
        block Subproof
            case
                B = a ; Q{local atom} |- Q
                C = Any               |- Any
            end
        end
        D = Any |- Any
    show
        b
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1, b
                S3 = b by C with S2
            end
        end
        S4 = b by D with S3
    qed
    ???> Local atom 'b' cannot be used in final step of case

If a hypothesis has the `nonlocal` attribute, its argument must be a term, and that term may
not contain any atoms which are local to the block in which the hypothesis is invoked.

    given
        A =   |- a
        block Subproof
            case
                B = a ; Q{local atom}    |- Q
                C = b ; Q{nonlocal term} |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1, b
                S3 = c by C with S2, fun(c)
            end
        end
        S4 = d by D with S3
    qed
    ===> ok

    given
        A =   |- a
        block Subproof
            case
                B = a ; Q{local atom}    |- Q
                C = b ; Q{nonlocal term} |- c
            end
        end
        D = c |- d
    show
        d
    proof
        S1 = a by A
        block Subproof
            case
                S2 = b by B with S1, b
                S3 = c by C with S2, fun(b)
            end
        end
        S4 = d by D with S3
    qed
    ???> must not contain local atom 'b'