-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathigor-interactive.ey
11367 lines (10142 loc) · 398 KB
/
igor-interactive.ey
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
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<
# For debugging where unclear crash is from:
# 0 ==debugIndent
# { ==name ==f
# { [| debugIndent _ 1 add =debugIndent { " " } rep name |] dump }
# f ;
# { [| debugIndent 1 sub _ =debugIndent { " " } rep "/" name |] dump } ;
# name
# } |deffst ; /deffst deffst
# OPTIMIZATION ONLY
{ "{ =*p [ -01 { _ p not \"--\" | rep }' each ] } *" includeLine } /grep defq
# END OF OPTIMIZATION
{ =*p ==input
0 input len range ==buffer 0 ==i
input { _ p
{
i _ 1 add =i buffer =[]
} "--" | ? *
} each
0 i range _ ==output { ==j
j buffer * j output =[]
} each
output
} /largegrep deffst
{ [ } "[|" deffd sys .asmroutines .|assemblestr "|]" deffd
emptyBlock ==renderContext
emptyBlock ==userContext
emptyBlock ==proofContext
0 ==silent
{ <
0 128 range ==data
0 ==top
{ # ==elem
top data len ge { data _ cat =data } rep
top data =[]
top 1 add =top
} /push deffst
{
top 1 sub _ 0 lt { "export stack underflow" die } rep
_ =top
data *
} /pop deffst
{
top 1 sub data *
} /peek deffst
{ top } /has deffst
> } /stack deffst
{ <
0 128 range ==data
0 ==read
0 ==write
{ # ==elem
write data len ge { data _ cat =data } rep
write data =[]
write 1 add =write
} /push deffst
{
read write eq { "export fifo underflow" die } rep
read _ 1 add =read
data *
} /pop deffst
{ read write lt } /has deffst
> } /fifo deffst
<
map ==:renderNameCache
"" ==name
{ =name
name renderNameCache .has not {
[
{ name constants .has } {
[| "\e[37m" name "\e[0m" |]
}
{ name assertions .has } {
name assertions * ==a
[
{ a .type "p" eq } { [| "\e[36m" name "\e[0m" |] }
{ a .type "a" eq } { [| "\e[31m" name "\e[0m" |] }
{ 1 } { name }
] conds
}
{ name renderContext isVar } { [| "\e[32m" name "\e[0m" |] }
{ 0 name * 0 "$" * eq } { [| "\e[33m" name "\e[0m" |] }
{ 1 } { name }
] conds
name renderNameCache =[] } rep
name renderNameCache *
}'
> -- τrenderName /renderName deffd
"" ==inputBuffer
{
{ ==s
s "" neq {
0 ==i { i s len lt i s * 10 neq and } { i 1 add =i } loop
i s len lt {
i 1 add s str .postfix
i 1 add s str .prefix
1
} { 0 } ? *
} { 0 } ? *
} /extractFirstLine deffst
0 ==eof
{ eof not { inputBuffer extractFirstLine not } andif } {
65536 sys .in .read _ ==input "" eq =eof
inputBuffer input cat =inputBuffer
} loop eof { "" } { -01 =inputBuffer } ? *
} /inputLine deffd
[ ] ==loadedInputWrappers
{
"" ==cmd "" ==args
inputLine ==input
input "" eq {
"quit" =cmd
} {
1 neg input str .prefix =input
input len 0 gt {
0 { _ _ input len lt -01 input * 32 eq and } { 1 add } loop input str .postfix =input
input len 0 gt {
0 { _ _ input len lt -01 input * 32 neq and } { 1 add } loop _ input str .prefix =cmd input str .postfix =input
input len 0 gt {
0 { _ _ input len lt -01 input * 32 eq and } { 1 add } loop input str .postfix =args
} rep
} rep
} rep
} ? *
args cmd loadedInputWrappers "*" | each
} /inputCmd deffd
0 ==messages
sys .out .|writeall /out deffd
{ ==msg [| "\e[31m" msg "\e[0m\n" |] out messages 1 add =messages } /err deffd
{ ==msg [| "\e[1;33m" msg "\e[0m\n" |] out messages 1 add =messages } /warn deffd
{ -- } /showBlock deffd
{ ==a
a .ctx _ =renderContext _ =userContext showBlock
[| "assuming:\n" |] out
a .hyps { ==hyp
[
{ hyp userContext isEHyp } {
[| "$e " hyp renderName "\n" |] out
[| hyp userContext getEHyp { renderName " " } each "\n" |] out
}
{ hyp userContext isFHyp } {
[| "$f " hyp renderName "\n" |] out
[| hyp userContext getFHyp { renderName " " } each "\n" |] out
}
{ 1 } {
[| "\e[31mcould not resolve hypothesis:\e[0m " hyp "\n" |] out
}
] conds
} each
[| "gives:\n" |] out
[| a .thm { renderName " " } each "\n" |] out
" " ==sep
[| "mandatory disjunct:" a .disj { =*d sep ", " =sep 0 d renderName " <!> " 1 d renderName } each "\n" |] out
" " =sep
[| "all disjunct:" a .allDisj { =*d sep ", " =sep 0 d renderName " <!> " 1 d renderName } each "\n" |] out
} /showAssertion deffd
{ ==p
p showAssertion
} /showProposition deffd
{ ==name
[
{ name constants .has } {
[| "$c " name renderName "\n" |] out
}
{ name assertions .has } {
name assertions * ==a
[
{ a .type "p" eq } { [| "$p " name renderName "\n" |] out a showProposition }
{ a .type "a" eq } { [| "$a " name renderName "\n" |] out a showAssertion }
{ 1 } { [| name " is an assertion of unknown type (probably a bug)\n" |] out }
] conds
}
{ name userContext isEHyp } {
[| "$e " name renderName "\n" |] out
[| name userContext getEHyp { renderName " " } each "\n" |] out
}
{ name userContext isFHyp } {
[| "$f " name renderName "\n" |] out
[| name userContext getFHyp { renderName " " } each "\n" |] out
}
{ name userContext isVar } {
[| "$v " name renderName "\n" |] out
}
{ 1 } {
[| name " is not known" "\n" |] out
}
] conds
} /show deffd
{ ==prompt
0 ==numberRead
{ numberRead not } {
prompt "> " cat sys .out .writeall
inputLine ==input
input "^ *(\\d+)\n" regex { 1 =numberRead txt .consume .u } rep
} loop
} /readNumber deffd
{ ==n n 0 lt {
[ "-u" ] n neg printNumber cat
} {
n txt .produce .u ==s
[
s len 1 sub { ";" } rep
s { [ -01 ] str .fromArray } each
]
} ? *
} /printNumber deffd
0 ==debuggingPossibleSubstitutions
{ ==assertionTokens ==assertionParse ==tokens ==tokensParse map ==substitution
1 ==valid
0 ==i
{ ==assertionParse ==tokensParse
assertionParse logicNonTerminal ==nt
[
{ nt "" eq } { # terminal
tokensParse logicRange tokens * ==new
assertionParse logicStart assertionTokens * ==var
var substitution .has {
var substitution * ==old
old new arrEq _ valid and =valid not {
debuggingPossibleSubstitutions {
[| "Failed to unify (later variable usage):\n" |] out
[| old { " " } each "\n" |] out
[| new { " " } each "\n" |] out
} rep
} rep
} {
new var substitution =[]
} ? *
}
{ nt tokensParse logicNonTerminal eq } {
0 assertionParse logicChildCount range { ==i
i tokensParse * i assertionParse * recurse
} each
}
{ 1 } {
0 =valid
debuggingPossibleSubstitutions {
[| "Failed to unify (parse):\n" |] out
[| tokensParse logicRange tokens * { " " } each "\n" |] out
[| assertionParse logicRange assertionTokens * { " " } each "\n" |] out
} rep
{ -- -- } =recurse
}
] conds
} /recurse deffst
tokensParse assertionParse recurse
valid { substitution } rep valid
} τpossibleSubstitutionsParsesScalar /possibleSubstitutionsForParsesScalar deffd
{
possibleSubstitutionsForParsesScalar { [ -01 ] } { [ ] } ? *
} τpossibleSubstitutionsParses /possibleSubstitutionsForParses deffd
{ ==start ==rootNonterminal ==assertionTokens ==tokens ==tokensParse
start assertionTokens rootNonterminal logicParsers * * not {
[ ]
debuggingPossibleSubstitutions {
[| "Failed to parse as: " rootNonterminal "\n" |] out
[| start assertionTokens len range assertionTokens * { " " } each "\n" |] out
} rep
} { ==assertionParse
tokensParse tokens assertionParse assertionTokens possibleSubstitutionsForParses
} ? *
} τpossibleSubstitutionsParse /possibleSubstitutionsForParse deffd
{ ==start ==rootNonterminal ==assertionTokens ==tokens
start tokens rootNonterminal logicParsers * * not {
[ ]
debuggingPossibleSubstitutions {
[| "Failed to parse as: " rootNonterminal "\n" |] out
[| start tokens len range tokens * { " " } each "\n" |] out
} rep
} { # ==tokensParse
tokens assertionTokens rootNonterminal start possibleSubstitutionsForParse
} ? *
} τpossibleSubstitutions /possibleSubstitutionsForToks deffd
{
1 =debuggingPossibleSubstitutions
possibleSubstitutionsForToks --
0 =debuggingPossibleSubstitutions
} /debugPossibleSubstitutionsForToks deffd
{ .thm ==assertionTokens ==tokens
0 assertionTokens * 0 tokens * eq {
0 tokens * "|-" eq /wff 0 tokens * ? ==rootNonterminal
tokens assertionTokens rootNonterminal 1 possibleSubstitutionsForToks
} {
[ ] # no substitutions
} ? *
} /possibleSubstitutions deffd
{ ==substitution ==tokens
[ tokens { _ substitution .has { substitution * _ len dearray } rep } each ]
} τapplySubstitution /applySubstitution deffst
{ ==proposition
< "a" ==type emptyBlock ==ctx "?" ==thm { "Fake theorem is fake" die }" =*proof "?" ==name
list _ _ ==hyps ==disj ==allDisj > ==:fakeTheorem
< fakeTheorem ==theorem [ ] ==hypotheses > ==:fakeResolution
{ < ==theorem ==hypotheses > } /step deffst
< < > ==s
{ =s [ -01 ] s .parents cat /parents s .set } /addParent defmst
{ =s < > /resolution s .set 1 /isopen s .set } /open defmst
{ ==s
s .isopen {
/resolution s .set
0 /isopen s .set
s .resolution .hypotheses { s -01 .addParent } each
s amendClosedGoalIndex
} {
==resolution # we could just ignore the re-close, but it points to a missing abort condition in some automation
resolution keys dump
resolution .theorem dump
resolution .theorem keys dump
resolution .theorem .name dump
[| "\e[31mSome tactics tried to re-close a closed goal\e[0m\n" |] die
} ? *
} τclose /close defmst
{ ==s fakeResolution /resolution s .set 0 /isopen s .set
s amendClosedGoalIndex
} /fakeclose defmst
{ =s /autohint s .set } /hint defmst
{
==thm [ ] ==parents < > ==resolution 1 ==isopen "" ==autohint
{ = }' =*set scope
}
> -- /goal deffst
map ==disj map ==nonDisj
{ ==x ==y
x y gt { x y =x =y } rep
x disj .has not { map x disj =[] } rep
1 y x disj * =[]
} /markDisj deffst
{ ==x ==y
x y gt { x y =x =y } rep
x disj .has {
y x disj * .has
} { 0 } ? *
} /mustDisj deffst
{ ==x ==y
x y gt { x y =x =y } rep
x nonDisj .has not { map x nonDisj =[] } rep
1 y x nonDisj * =[]
} /markNonDisj deffst
{ ==x ==y
x y gt { x y =x =y } rep
x nonDisj .has {
y x nonDisj * .has
} { 0 } ? *
} /mustNotDisj deffst
proposition .ctx _ =proofContext
proposition .thm goal ==mainGoal
0 ==selectedGoal
0 ==nextMetaVariable
map ==lastMetaVariables
map ==allMetaVariables
map ==metaSubstitution
1 ==redisplay
[ ] ==lastSearch
[ ] ==loadedCommands
[ ] ==loadedAutomations
[ ] ==loadedTrivialities
[ ] ==loadedDisplays
{ _ metaSubstitution .has {
metaSubstitution * |expandMetaToken each
}" rep }' /expandMetaToken deffst
<
"" ==s
{ [ -01 { _ =s 0 s * 36 eq { expandMetaToken }" rep }" each ] }'
> -- τexpandMeta /expandMeta deffst
{ ==theorem ==substitution
theorem mandatoryVariables dom { ==var
var constants .has not {
var substitution .has not {
[| "$" var "." nextMetaVariable _ 1 add =nextMetaVariable txt .produce .u |] ==newVar
newVar var lastMetaVariables =[]
1 newVar allMetaVariables =[]
[ newVar ] var substitution =[]
} rep
} rep
} each
} τintroduceMetaVars /introduceMetaVars deffst
{ ==closedGoal ==substitution ==theorem
silent not {
[| "applying with:\n" |] out
substitution dom { ==name
[| name " = " name substitution * { renderName " " } each "\n" |] out
} τinfo1 each
} rep
substitution theorem introduceMetaVars
0 ==disjunctionsViolated
theorem .disj { 2 dearray ==x ==y
x substitution * { ==xTok
xTok constants .has not {
y substitution * { ==yTok
yTok constants .has not {
xTok yTok eq {
1 =disjunctionsViolated
[| "\e[31mproposed application would violate\e[0m " x renderName " <!> " y renderName "\n" |] out
0 =redisplay
} rep
xTok yTok mustNotDisj {
1 =disjunctionsViolated
[| "\e[31mproposed application would violate\e[0m " x renderName " <=> " y renderName "\n" |] out
0 =redisplay
} rep
} rep
} each
} rep
} each
} each
disjunctionsViolated not {
theorem .disj { 2 dearray ==x ==y
x substitution * { ==xTok
xTok constants .has not {
y substitution * { ==yTok
yTok constants .has not { xTok yTok markDisj } rep
} each
} rep
} each
} each
[
theorem .hyps { ==name
[
{ name theorem .ctx isEHyp } { name theorem .ctx getEHyp substitution applySubstitution goal }
{ name theorem .ctx isFHyp } { name theorem .ctx getFHyp substitution applySubstitution goal }
{ 1 } {
[| "hypothesis " name " cannot be resolved" "\n" |] out
}
] conds
} each
] ==hypotheses
hypotheses theorem step closedGoal .close
} rep
} τapplyTheorem /applyTheorem deffst
{ ==assertion ==substitution
silent not {
[| "using e-hyp for: " assertion .name "\n" |] out
substitution dom { ==v
[| v " = " v substitution * { renderName " " } each "\n" |] out
} each
} rep
assertion .hyps { assertion .ctx isEHyp } grep { ==name
name assertion .ctx getEHyp ==toks
0 toks * "|-" eq { 1 toks /wff logicParsers * * } andif { ==parse
parse logicNonTerminal /wi eq
{ 0 parse * logicNonTerminal /wceq eq } andif
{ 1 parse * logicNonTerminal /wb eq } andif {
0 0 parse * * logicRange toks * ==leftVar
1 0 parse * * logicRange toks * ==rightVar
0 1 parse * * logicRange toks * ==leftTerm
1 1 parse * * logicRange toks * ==rightTerm
leftVar len 1 eq
{ rightVar len 1 eq } andif
{ 0 leftVar * substitution .has } andif
{ 0 rightVar * substitution .has } andif {
leftTerm len 1 eq
{ 0 leftTerm * substitution .has } andif
{ 0 rightTerm * substitution .has not } andif {
0 leftTerm * substitution * 0 leftVar * substitution * 0 rightVar * substitution * rewriteTokens
0 rightTerm * substitution =[]
} rep
rightTerm len 1 eq
{ 0 rightTerm * substitution .has } andif
{ 0 leftTerm * substitution .has not } andif {
0 rightTerm * substitution * 0 rightVar * substitution * 0 leftVar * substitution * rewriteTokens
0 leftTerm * substitution =[]
} rep
} rep
} rep
} rep
} each
} τresolveEhypSubstitutions /resolveEhypSubstitutions deffst
{ ==allowIndirectUsage ==goal ==name
silent not {
[| "using: " name "\n" |] out
} rep
[
{ name assertions .has } {
name assertions * ==a
[
{ a .type "p" eq a .type "a" eq or } {
goal .thm expandMeta ==goalToks
goalToks a possibleSubstitutions ==choices
0 ==indirectUsage
allowIndirectUsage
{ choices len 0 eq } andif
{ 0 goalToks * "|-" eq } andif
{ 1 goalToks /wff logicParsers * * } andif { ==goalParse
0 a .thm * "|-" eq
{ 1 a .thm /wff logicParsers * * } andif { ==assertionParse
goalParse logicNonTerminal /wi eq {
[ "|-" ] 1 goalParse * logicRange goalToks * cat a possibleSubstitutions ==implChoices
implChoices len 1 eq {
/a1i goal use
goal .isopen not {
1 =indirectUsage
2 goal .resolution .hypotheses * ==g
g .isopen { name g use } rep
} rep
} rep
} rep
indirectUsage not {
0 ==hasAntes
goalParse logicNonTerminal /wi eq {
1 goalParse * 1 =hasAntes
} {
goalParse
} ? * ==relevantGoalParse
assertionParse ==i [ ] ==path
{ ==path ==goal ==substitution
path reverse { ==step
hasAntes {
/syl goal use
goal .isopen not {
step logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
4 goal .resolution .hypotheses * =goal
} rep
} {
/ax-mp goal use
goal .isopen not {
step logicRange a .thm * substitution applySubstitution /ph lastMetaVariables * let
name 3 goal .resolution .hypotheses * =goal
} rep
} ? *
} each
goal
} /resolvePath deffst
{ ==goal ==name
goal .isopen {
name goal -1010 .thm expandMeta canUse { use } { .hint } ? *
} rep
} /useOrHint deffst
{
[
{ goal .isopen not } { 0 } # success already
{ i logicNonTerminal /wb eq } {
relevantGoalParse goalToks 1 i * logicRange a .thm * /wff 0 possibleSubstitutionsForParse ==rightChoices
relevantGoalParse goalToks 0 i * logicRange a .thm * /wff 0 possibleSubstitutionsForParse ==leftChoices
# prefer substitutions with more variables known (i.e. better match)
rightChoices len 1 eq { leftChoices len 1 eq { 0 leftChoices * dom len 0 rightChoices * dom len gt } andif not } andif {
0 rightChoices * ==substitution
substitution a resolveEhypSubstitutions
substitution a introduceMetaVars
1 =indirectUsage
hasAntes {
path len {
/mpbid goal use
goal .isopen not {
0 i * logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
substitution 4 goal .resolution .hypotheses * path resolvePath ==subgoal
name subgoal useOrHint
} rep
} {
/sylib goal use
goal .isopen not {
0 i * logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
name 4 goal .resolution .hypotheses * useOrHint
} rep
} ? *
} {
/mpbi goal use
goal .isopen not {
0 i * logicRange a .thm * substitution applySubstitution /ph lastMetaVariables * let
name 3 goal .resolution .hypotheses * useOrHint
} rep
} ? *
} {
leftChoices len 1 eq {
0 leftChoices * ==substitution
substitution a resolveEhypSubstitutions
substitution a introduceMetaVars
1 =indirectUsage
hasAntes {
path len {
/mpbird goal use
goal .isopen not {
1 i * logicRange a .thm * substitution applySubstitution /ch lastMetaVariables * let
substitution 4 goal .resolution .hypotheses * path resolvePath ==subgoal
name subgoal useOrHint
} rep
} {
/sylibr goal use
goal .isopen not {
1 i * logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
name 4 goal .resolution .hypotheses * useOrHint
} rep
} ? *
} {
/mpbir goal use
goal .isopen not {
1 i * logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
name 3 goal .resolution .hypotheses * useOrHint
} rep
} ? *
} rep
} ? *
0
}
{ i logicNonTerminal /wi eq } {
relevantGoalParse goalToks 1 i * logicRange a .thm * /wff 0 possibleSubstitutionsForParse ==rightChoices
rightChoices len 1 eq {
0 rightChoices * ==substitution
substitution a resolveEhypSubstitutions
substitution a introduceMetaVars
1 =indirectUsage
hasAntes {
path len {
/mpd goal use
goal .isopen not {
0 i * logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
name 4 goal .resolution .hypotheses * useOrHint
} rep
} {
/syl goal use
goal .isopen not {
0 i * logicRange a .thm * substitution applySubstitution /ps lastMetaVariables * let
name 4 goal .resolution .hypotheses * useOrHint
} rep
} ? *
} {
/ax-mp goal use
goal .isopen not {
0 i * logicRange a .thm * substitution applySubstitution /ph lastMetaVariables * let
name 3 goal .resolution .hypotheses * useOrHint
} rep
} ? *
0
} {
path [ 0 i * ] cat =path
1 i * =i
1
} ? *
}
{ 1 } { 0 }
] conds
} { } loop
} rep
} rep
} rep
indirectUsage not {
[
{ choices len 1 eq } {
a 0 choices * goal applyTheorem
}
{ choices len 0 eq } {
[| "\e[31mno possible substitutions\e[0m\n" |] out
0 =redisplay
name show
}
{ choices len 1 ge } {
[| "\e[31mmultiple substitutions possible\e[0m\n" |] out
0 =redisplay
name show
0 choices len range { ==i
[| i txt .produce .u ") " a .thm i choices * applySubstitution { renderName " " } each "\n" |] out
[| "(with " i choices * dom { ==v v "=" v i choices * * { " " } each " " } each ")\n" |] out
} each
a "choice" readNumber choices * goal applyTheorem
}
] conds
} rep
}
{ 1 } { [| name " is an assertion of unknown type (probably a bug)\n" |] out }
] conds
}
{ name userContext isEHyp } {
goal .thm expandMeta name userContext getEHyp arrEq {
[ ] < "f" ==type userContext ==ctx name userContext getEHyp ==thm { "no proof" die } =*proof name ==name >
step goal .close
} {
[| "\e[31mnot applicable:\e[0m $f " name renderName "\n" |] out
0 =redisplay
} ? *
}
{ name userContext isFHyp } {
goal .thm expandMeta name userContext getFHyp arrEq {
[ ] < "f" ==type userContext ==ctx name userContext getFHyp ==thm { "no proof" die } =*proof name ==name >
step goal .close
} {
[| "\e[31mnot applicable:\e[0m $f " name renderName "\n" |] out
0 =redisplay
} ? *
}
{ 1 } {
[| name " is not usable" "\n" |] out
name show
}
] conds
} τuseGeneric /useGeneric deffst
{ 0 useGeneric } /use deffst
{ 1 useGeneric } /tacUse deffst
{ ==tokens ==name
0 ==usable
[
{ name assertions .has } {
name assertions * ==a
a .type "p" eq a .type "a" eq or {
tokens a possibleSubstitutions ==choices
choices len 1 ge =usable
} rep
}
{ name userContext isEHyp } {
tokens name userContext getEHyp arrEq =usable
}
{ name userContext isFHyp } {
tokens name userContext getFHyp arrEq =usable
}
] conds
usable
} τcanUse /canUse deffst
{ ==metaVar ==tokens
0 ==disjunctionsViolated
metaVar "^\\$([^.]+)$" regex { ==stem
stem lastMetaVariables .has { stem lastMetaVariables * =metaVar } rep
metaVar metaSubstitution .has {
allMetaVariables dom { ==v
v metaSubstitution .has not {
v "^\\$([^.]+)\\.[0-9]+$" regex { stem eq {
v =metaVar
} rep } rep
} rep
} each
} rep
} rep
tokens { ==x metaVar ==y
x y gt { x y =x =y } rep
x disj .has {
y x disj * .has {
1 =disjunctionsViolated
[| "\e[31mproposed let would violate\e[0m " x renderName " <!> " y renderName "\n" |] out
0 =redisplay
} rep
} rep
x nonDisj .has {
y x nonDisj * .has {
1 =disjunctionsViolated
[| "\e[31mproposed let would violate\e[0m " x renderName " <=> " y renderName "\n" |] out
0 =redisplay
} rep
} rep
} each
disjunctionsViolated not {
tokens metaVar metaSubstitution =[]
disj dom { ==x
x disj * dom { ==y
x metaVar eq { tokens { ==t t constants .has not { t y markDisj } rep } each } rep
y metaVar eq { tokens { ==t t constants .has not { t x markDisj } rep } each } rep
} each
} each
} rep
} τlet /let deffst
[ ] ==allOpenGoals 0 ==allOpenGoalsValid
{ # ==goal
objset ==goals
{ _ dump _ keys dump
_ .isopen { goals .put } { .resolution .hypotheses |collect each } ? *
} /collect deffst
collect goals dom
} /openGoalsRecursive deffst
{ ==goal
goal sys .asm .rawAddress mainGoal sys .asm .rawAddress eq {
allOpenGoalsValid not {
mainGoal openGoalsRecursive _ =allOpenGoals 1 =allOpenGoalsValid
} {
[ allOpenGoals { openGoalsRecursive _ len dearray } each ] _ =allOpenGoals 1 =allOpenGoalsValid
} ? *
} {
goal openGoalsRecursive
} ? *
} τopenGoals /openGoals deffst
{ map _ ==directTheoremIndex # returned
[| "Indexing theorems by text...\n" |] out
assertions dom { ==name
name assertions * .ctx collectEHyps dom len not { name proposition .name neq } andif {
name [| name assertions * .thm { " " } each |] directTheoremIndex =[]
} rep
} each
[ |collectEHyps |collectFHyps ] { =*collect
proofContext collect ==hyps hyps dom { ==name
name [| name hyps * { " " } each |] directTheoremIndex =[]
} each
} each
} memoized /directTheoremIndex deffst
map ==closedGoalIndex
{ ==newlyClosedGoal
{ ==goal
[| goal .thm expandMeta { " " } each |] ==txt
txt closedGoalIndex .has not {
goal txt closedGoalIndex =[]
0 goal .thm * "|-" eq {
goal recordSolution
} rep
} rep
} /addClosedGoal deffst
{ ==goal
goal .resolution .hypotheses _ =*hyps len 1 sub ==i
1 { _ i 0 ge and } {
i hyps ==hyp
hyp .isopen { -- 0 } {
[| hyp .thm expandMeta { " " } each |] ==txt
-- txt closedGoalIndex .has
} ? *
i 1 sub =i
} loop {
goal addClosedGoal
goal .parents |recurse each
} rep
} /recurse deffst
newlyClosedGoal recurse
} τclosedGoalIndex /amendClosedGoalIndex deffst
{ map =closedGoalIndex
{ ==goal
goal .isopen { 1 } {
[| goal .thm expandMeta { " " } each |] ==txt
txt closedGoalIndex .has { 0 } {
[ goal .resolution .hypotheses |recurse each ] any { 1 } {
goal txt closedGoalIndex =[]
0
} ? *
} ? *
} ? *
} /recurse deffst
mainGoal recurse --
} τclosedGoalIndex /rebuildClosedGoalIndex deffst
{ ==toTry ==goal
goal .isopen not {
toTry { =*f
goal .resolution .hypotheses { ==g g .isopen { g f } rep } each
} each
} rep
} τtacAttemptNext /tacAttemptNext deffst
{ ==goal ==toTry
goal openGoals { ==g
toTry { =*f
g .isopen {
g f
g .isopen not {
toTry g tacAttemptRecursive
} rep
} rep
} each
} each
} τtacAttemptRecursive /tacAttemptRecursive deffst
{ ==tokens ==parse
parse logicRange tokens * ==thing
[
[ "NN0" "NN" "RR" "CC" ] { ==numbers
{ thing len 1 eq { [| [ "|-" 0 thing * "e." numbers ] { " " } each |] directTheoremIndex .has } andif } { numbers }
} each
{ parse logicNonTerminal /cdc eq { 0 parse * tokens classify "NN0" eq } andif { 1 parse * tokens classify "NN0" eq } andif } { "NN0" }
{ 1 } { "" }
] conds
} τclassify /classify deffst
{ ==goal
goal .isopen {
goal .thm expandMeta ==tokens
[| tokens { " " }" each |] ==txt
[
{ txt closedGoalIndex .has } {
silent not { [| "re-using earlier proof\n" |] out } rep
txt closedGoalIndex * .resolution goal .close
} τauto1
{ txt directTheoremIndex .has } {
txt directTheoremIndex * goal use
goal [ |auto ] tacAttemptNext
} τauto2
{ 0 tokens * logicParsers .has { tokens tokenIsMetaVar any not } andif } {
{ [| "\e[31mautomatic parser available, but did not parse. probably not satisfiable\e[0m\n" |] out } =*failed
1 tokens 0 tokens * logicParsers * * { ==parse
faketrivialities { goal .fakeclose } {
# parse tree order is by token sequence, but hypothesis order is by set.mm
# only apply topmost parse rule and handle rest via big recursion
parse logicNonTerminal goal use
goal [ |auto ] tacAttemptNext
} ? *
} |failed ? *
} τauto3
{ goal .autohint "" neq { goal .autohint tokens canUse } andif } {
goal .autohint goal use
goal [ |auto ] tacAttemptNext
} τauto6
{ 0 tokens * "|-" eq { 1 tokens /wff logicParsers * * } andif } τauto4 { ==parse
{ ==parse =*preparation
goal .isopen { parse logicNonTerminal /wi eq } andif { 0 parse * logicRange tokens * 1 parse * logicRange tokens * arrEq } andif {
goal preparation ==goal
goal .isopen {
/id goal use
goal [ |auto ] tacAttemptNext
} rep
} rep
goal .isopen { parse logicNonTerminal /wb eq } andif { 0 parse * logicRange tokens * 1 parse * logicRange tokens * arrEq } andif {
goal preparation ==goal
goal .isopen {
/biid goal use
goal [ |auto ] tacAttemptNext
} rep
} rep
goal .isopen { parse logicNonTerminal /wi eq } andif { 1 parse * logicNonTerminal /wal eq } andif
{ 0 parse * logicRange tokens * 1 1 parse * * logicRange tokens * arrEq } andif {
goal preparation ==goal
goal .isopen {
/ax-17 assertions * ==theorem
tokens theorem possibleSubstitutions ==substitutions
substitutions len 1 eq { 0 substitutions * ==substitution
0 ==disjunctionsViolated
theorem .disj { 2 dearray ==x ==y
x substitution * { ==xTok
xTok constants .has not {
y substitution * { ==yTok
yTok constants .has not {
xTok yTok eq {
1 =disjunctionsViolated
} rep
xTok yTok mustNotDisj {