-
Notifications
You must be signed in to change notification settings - Fork 1
/
muscadet-en.pl
2938 lines (2642 loc) · 106 KB
/
muscadet-en.pl
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
%% Copyright 2008 Crip5 Dominique Pastre
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Muscadet version 4.7.6 %%
%% 09/03/2018 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% muscadet-en is the English Prolog version of MUSCADET
%% the script musca-en calls swi-prolog and loads muscadet-en
%%%%%%%%%%%%%%%%%%
%% declarations %%
%%%%%%%%%%%%%%%%%%
%% (sub-)th N points at the (sub-)theorem numbered N
%% hyp(N,H,E) : H is a hypothesis of (sub-)th N introduced à step E
:-dynamic hyp/3.
:-dynamic hyp_traite/2.
:-dynamic ou_applique/1.
%% concl(N,C,E) : C is the concliusion of (sub-)th N at step E
:-dynamic concl/3.
:-dynamic lien/2.
%% subth(N,N1) : N1 is the number of a subth of the (sub-)th N
:-dynamic subth/2.
%% objet(N,O) : O est un objet du (sous-)th N
:-dynamic objet/2.
%% rulactiv(N,LNR) : LR is the list of the active rules names for the (sub-)th N
:-dynamic rulactiv/2.
:-dynamic rule/2.
:-dynamic concept/1.
:-dynamic fonction/2.
:-dynamic type/2.
:-dynamic avecseulile/0.
:-dynamic definition/2.
:-dynamic definition/1.
:-dynamic definition1/2. %1.
:-dynamic lemme/2.
:-dynamic lemme1/2.
:-dynamic version/1.
:-dynamic writebuildrules/0.
:-dynamic timelimit/1.
:-dynamic tempspasse/1.
:-dynamic temps_debut/1.
:-dynamic conjecture/2.
:-dynamic seulile/1.
:-dynamic include/1.
:-dynamic fof/3.
:-dynamic fof_traitee/3.
:-multifile fof/3.
:- dynamic probleme/1.
:- dynamic priorite/2.
:- dynamic priorites/1.
:- dynamic step/1.
:- dynamic nbhypexi/1.
:- dynamic lengthmaxpr/1.
:- dynamic display/1.
:- dynamic lang/1.
:- dynamic chemin/1.
:- dynamic res/1.
:- dynamic theoreme/1.
:- dynamic th/1.
:- dynamic theoreme/2.
:- dynamic theorem/2.
:- dynamic include/1.
nbhypexi(0). %% to count existential hypotheses
lengthmaxpr(12000). %% limit for the length of displayed proofs
%% priorites(sans).
priorites(avec).
probleme(pas_encore_de_probleme).
%% direct | th | tptp | (tptp & casc)
%% version(direct).
%% version(th).
%% version(tptp).
%% version(casc).
%% default time limit
timelimit(20).
tempspasse(0).
temps_debut(0).
conjecture(false,false).
seulile(niouininon).
avecseulile.
lang(en).
fr :- assign(lang(fr)).
en :- assign(lang(en)).
%% default
% display(tr).
display(pr).
%% display(szs).
:-op(70,fx,'$$').
:-op(80,fx,'$').
:-op(90,xfx,/).
:-op(100,fx,++).
:-op(100,fx,--).
:-op(100,xf,'!').
:-op(400,xfx,'..').
:-op(400,fy,!).
:-op(400,fx,?).
:-op(400,fx,^).
:-op(400,fx,'!>').
:-op(400,fx,'?*').
:-op(400,fx,'@-').
:-op(400,fx,'@+').
:-op(405,xfx,'=').
:-op(440,xfy,>).
:-op(450,xfx,'<<').
:-op(450,xfy,:).
:-op(450,fx,:=).
:-op(450,fx,'!!').
:-op(450,fx,'??').
:-op(450,fy,~).
:-op(480,yfx,*).
:-op(480,yfx,+).
:-op(501,yfx,@).
%% :-op(502,xfy,'|').
%% for SWI-Prolog until 5.10.1
%% SWI-Prolog from 5.10.2 displays Error but works
:- (system_mode(true),op(502,xfy,'|'),system_mode(false)).
%% for SWI-Prolog from 5.10.2
%% old SWI-Prolog only displays Error, and works
%% both lines may be left
:-op(100,fx,+++).
:-op(502,xfx,'~|').
:-op(503,xfy,&).
:-op(503,xfx,~&).
:-op(504,xfx,=>).
:-op(504,xfx,<=).
:-op(505,xfx,<=>).
:-op(505,xfx,<~>).
:-op(510,xfx,-->).
:-op(550,xfx,:=).
:-op(450,xfy,::).
:-op(450,fy,..).
:-op(405,xfx,'~=').
:- op(600,fx,si).
:- op(610,xfx,alors).
:- op(600,fx,if).
:- op(610,xfx,then).
c :- buildrules.
l(P) :- listing(P).
rule(Nom) :- clause(rule(_,Nom ),Q), ecrire1(Q).
%%%%%%%%%%%%%%%%%%%%%%%%
%% inference engine %%
%%%%%%%%%%%%%%%%%%%%%%%%
%% ++++++++++++++++++++ applyrulactiv(N) +++++++++++++++++
%% apply all active rules to the (sub_)theorem N
%% until true or timout or no more rules to apply
%% an old recursive version has been retired
applyrulactiv(N) :-
repeat,
( concl(N, true, _) -> demontre(N)
; concl(N, _/timeout, _) -> message(aaaaaaaaaaaaaaa),!, nondemontre(N)
; rulactiv(N,LR) -> ( applyrul(N,LR)-> fail ;! )
) .
%% +++
%% ++++++++++++++++++++ applyrul(N,LR_) +++++++++++++++++++
%% apply the rules of LR (list of their names) to the (sub_)theorem N
%% stop if time out
%% if no rule has been successively applied,
%% applireg fails,appliregactiv succeeds
applyrul(N,_) :- time_exceeded(N,applireg),!,nondemontre(N),fail.
applyrul(N,[R|RR]) :-
(rule(N,R) -> acrire_tirets(tr,[rule,R])
; applyrul(N,RR)
) .
applyrul(N,[]) :- nondemontre(N), fail.
%% +++
%% ++++++++++++++++++++ time_exceeded(N,Marqueur) +++++++++++++++
%% interruption + message if over time limit
time_exceeded(N,Marqueur) :-
statistics(cputime,T),!,
tempspasse(TP),timelimit(TL), TT is TP+TL , T>TT,
( concl(N,C, _) -> newconcl(N,C/timeout, _)
; true
),
ME =('time over N='),
ES =(' in '),
SS =('\ntheorem not proved'),
SA =('in'),
AG =('seconds (timeout)\n'),
MESSAGE = [ME,N,ES,Marqueur,SS,SA,T,AG],
message(MESSAGE),nl,
(N = -1 -> probleme(P),atom_concat(res_,P,RES),tell(RES)
; true),
acrire1(tr,MESSAGE),nl,
! ,
nondemontre(0),
break
.
%% ++++++++++++++++++++ demontre(N) ++++++++++++++++++++++
%%
%% displays (or not) the success if the (sub-)theorem numbered N is proved
%% according to the value of N (N=0 for the initial theorem)
%% ans the option (tptp, th, szs, casc,...)
%% if N=0, displays (according to version) the spent time
%% and optionally extracts the useful proof and time for this extraction
demontre(N) :-
( N=0 -> ( version(tptp),conjecture(false,_) ->
message('no conjecture, problem proved unsatisfiable')
; message('theorem proved')
),
( display(tr) -> acrire1(tr,[theorem,proved])
; version(casc) -> true
; ecrire1('theorem proved ')
),
probleme(P),
temps_debut(TD),
statistics(cputime,Tapresdem),Tdem is Tapresdem-TD,
(version(direct) -> true
; nomdutheoreme(Nomdutheoreme),
concat_atom(['(',Nomdutheoreme,')'],Texte)
),
(version(casc) ->true
; Nomdutheoreme=direct -> true
; ecrire(Texte)
),
(version(casc)-> true
; messagetemps(Tdem),
(version(tptp) -> ecrire1([problem,P,solved]),
ecrire1('== == == == == == == == == == ')
; true
)
),
ligne(szs),
(display(szs) -> ( conjecture(false,_) ->
ecrire1('SZS status Unsatisfiable for ')
; ecrire1('SZS status Theorem for ')
),
probleme(P),ecrire(P)
; true
),
( display(pr) ->
ligne, statistics(cputime,Tavantutile),
%% searches and displays the useful trace
tracedemutile,
( version(casc) -> true
; statistics(cputime,Tapresutile),
Tutile is Tapresutile-Tavantutile,
ecrire1('extracted proof'),
message('extracted proof'),
messagetemps(Tutile),
message('')
)
; true
)
; %% N>0
acrire1(tr,[theorem,N,proved])
) .
%% +++
%% ++++++++++++++++++++ demontre(N) ++++++++++++++++++++++
%%
%% nondemontre(N) displays failing for the (sub-)theorem numbered N
%% if N=0 displays spent time (according to options)
nondemontre(N) :-
( N=0 -> ecrire1etmessage('theorem not proved'),
probleme(P),
temps_debut(TD),
statistics(cputime,Tapresdem),Tdem is Tapresdem-TD,
(version(direct) -> true
; nomdutheoreme(Nomdutheoreme),
concat_atom(['(',Nomdutheoreme,')'],Texte)
),
(version(casc) ->true
; Nomdutheoreme=direct -> true
; ecrire(Texte), message0(Texte)
),
( version(casc)-> true
; messagetemps(Tdem),
( version(tptp) -> ecrire1([problem,P,not,solved]),
ecrire1('== == == == == == == == == == ')
; true
)
),
ligne(szs),
(display(szs) -> nl,nl, write('SZS status GaveUp for '),
probleme(P),write(P)
; true
)
;
acrire1(tr,[theorem,N,not,proved])
),
!.
%%%%%%%%%%%%%%%%%%%%%%%%%
%% some functions %%
%%%%%%%%%%%%%%%%%%%%%%%%%
varatom(X) :-
%% X is a variable or an atom
%% /!\ [] is or is not an atom according versions of Prolog
(var(X);atom(X)).
vars([X|L]) :-
%% L is a list (possibly empty) of variables
var(X), vars(L).
vars([]).
%% searches if X may be unified with a (sub-)element of E
element(X,E) :-
%% X appears in E , at whatever level :
%% X may be unified with E or one of its (sub-)formulas
%% or with a (sub-)formula of a list of formulas
%% used in lire, avecseuile and ecrireV (X constant)
(X=E -> true %% always if X is a simple variable
; E=[] -> fail
; E=[A|_], X == A -> true
; E=[A|_],\+ atom(A),\+ var(A),\+ number(A),element(X,A)
-> true
; E=[_|L] -> element(X,L)
; E=..L -> element(X,L)
).
%% To scan the elements of a list, at the first level,
%% the predefined predicate member(X,L) is used
%% scan the elements of the sequence (at 1st level)
elt_seq(X,(X,_)).
elt_seq(X,(_,S)) :- elt_seq(X,S).
elt_seq(X,X) :- \+ X=(_,_).
%% seq_der(S,S_X,X) returns the last element X of a sequence S
%% and S_X the sequence without X
seq_der((S1,S2,S3),(S1,SS),X) :- seq_der((S2,S3),SS,X),!.
seq_der((S1,S2),S1,S2):-!.
seq_der(S,S,S) :- message([S, 'has only one element']).
%% adds _ at the end of an atom ending in a digit
%% (so that it does not end in a digit)
denumlast(Atom,Atom1) :- atom(Atom), name(Atom,L),last(L,D),
D>47,D<58, !,
append(L,[95],L1),name(Atom1,L1).
denumlast(Atom,Atom).
%% display, with indentations, big dis/conjunctive formulas
%% no longer used, but might be useful
arbre(E) :- arbre(E,0).
arbre(E,Indent) :- E=..[Op,A,B],(Op='|';Op='&'),nl,indent(Indent),
write(Op),I is Indent+1,arbre(A,I),arbre(B,I),!.
arbre([],_) .
arbre(E,Indent) :- nl,indent(Indent),write(E).
indent(N) :- write(' '),(N>0 -> N1 is N-1, indent(N1);true).
%% creates a new atom X1 from X
%% if the atom X does not end in a number, adds 1
%% else adds 1 to this last number
%% (replaced par gensym, except in "create_name_rule")
suc(X,X1) :- name(X,L),sucliste(L,L1),name(X1,L1).
sucliste(X,X1):-
last(X,D),
D>=48,
D=<56,D1 is D+1,
append(Y,[D],X),
append(Y,[D1],X1),!.
sucliste(X,X1) :- last(X,57),append(Y,[57],X),sucliste(Y,Y1),
append(Y1,[48],X1),!.
sucliste(X,X1):- append(X,[49],X1).
%% ajoufin(L,A,L1) adds A in the end of the list L
ajoufin([X|L],A,[X|L1]) :- ajoufin(L,A,L1).
ajoufin([],A,[A]).
%% adds A in the end of the sequence S
ajoufinseq(S,A,SA) :- ( S = (X,L) -> ajoufinseq(L,A,L1), SA = (X,L1)
; S = [] -> SA = A
; SA = (S,A)
).
%% adds a condition A, in a sequence S before the conditions obj_ct
%% i.e. : at the end if it is a condition obj_ct
%% or if there is not yet any conditions obj_ct
%% else before the conditions obj_ct
%% SA is the new sequence
ajouseqavantobjet(S,A,SA) :-
( A = obj_ct(_,_) -> ajoufinseq(S,A,SA)
; S=(obj_ct(_,_),_L) -> SA = (A,S)
; S = (X,L) -> ajouseqavantobjet(L,A,L1), SA = (X,L1)
; S = [] -> SA = A
; S = obj_ct(_,_) -> SA = (A,S)
; SA = (S,A)
)
.
%% returns objects X first those of sub-theorem N instantiated
%% then objects occurring in data (N=-1)
obj_ct(N,X) :-
objet(N,X) ; objet(-1,X).
%% adds a clause P(...) with arity 0, 1, 2 or 3
%% (to be generalized if necessary
%% after having removed any other clause P(...)
assign(X) :-
X =.. [P,_],Y=..[P,_],retractall(Y),assert(X),!.
assign(X) :- X =.. [P,_,_],Y=..[P,_,_],retractall(Y),assert(X),!.
assign(X) :- X =.. [P,A,_,_],Y=..[P,A,_,_],retractall(Y),assert(X),!.
%% increments the number of existential hypotheses (nbhypexi)
incrementer_nbhypexi(N1) :- nbhypexi(N), N1 is N+1, assign(nbhypexi(N1)).
%% returns E1 if E1 is an atom (step number),
%% else creates a new step E1
step_action(E1) :-
( var(E1),step(E0) -> E1 is E0+1,assign(step(E1))
; true).
%% flattens formulas
%% example : f(g(a, b), h(c), K) becomes f_g_a_b_h_c_var
%% no longer used (unreadable because too long for some formulas)
%% instead objects z1, z2, ... are created (rule concl_only)
%% could be used for small formulas
plat(E,E1) :- ( (atom(E) ; number(E) ) -> E1 = E
; var(E) -> E1=var
; E = [X,Y|L] -> plat(X,X1),plat([Y|L],L1),
atom_concat(X1,'_',E2), atom_concat(E2,L1,E1)
; E = [X] -> plat(X,E1)
; E =..L, plat(L,E1)
) .
tartip(X1,X2) :- name(X1,L1),compareg1ter(L1,L2),name(X2,L2).
%% searches if E, possibly quantified, is closed
%% else ground is used, clos is only used in buildrules
clos(E) :- not(var(E)),
( E=[] -> true
; E=[X|L] -> clos(X),clos(L)
; E=(![X|XX]:EX) -> remplacer(EX,X,x,Exx),
( XX=[] -> Ex=Exx
; Ex=(!XX:Exx)
),
clos(Ex)
; E=(?[X|XX]:EX) -> remplacer(EX,X,x,Exx),
( XX=[] -> Ex=Exx
; Ex=(?XX:Exx)
),
clos(Ex)
; E=seul(FX::X,PX) -> clos(FX),remplacer(PX,X,x,Px),clos(Px)
; E=..[_|L]-> clos(L)
; acrire1(tr,clos-E-non)
).
%% From swi-prolog version 5, telling does not return
%% the filename of the current output but rather the stream identifier
%% of the form <stream>(0x81ea8c8) that I cannot find
%% So I defined a dynamic predicate fichier and predicates telll,
%% toldd, tellling and appendd, to replace (but not exactly the same)
%% tell, told, telling et append
:- dynamic fichier/1.
telll(F) :- tell(F), retractall(fichier(_)), assert(fichier(F)).
toldd :- retractall(fichier(_)),told.
tellling(F) :- fichier(F),!.
tellling(user).
appendd(F) :- append(F), retractall(fichier(_)), assert(fichier(F)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% super-actions %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ++++++++++++++++++++++++ travail1 ++++++++++++++++++++++++
%% builds rules from definitions,
%% after having removed functional symbols from them
%% if detailed displaying has been asked (writebuildrules),
%% the trace is in the file tracebuildrules[_<name of the problem>]
%% or in res_[_<name of the problem>] for local rules
travail1 :- (probleme(P) -> atom_concat(tracebuildrules_,P,Tracebuildrules)
; Tracebuildrules=tracebuildrules
),
(writebuildrules -> telll(Tracebuildrules);true),
elifundef,
buildrules,
typesdonnees,
told.
%% +++++++++++++++++++++++ writebuildrules ++++++++++++++++++
%% activates the option of detailed display of rules building
writebuildrules :-
display(reg).
typesdonnees :- clause(rule(_,Nom),_), \+ type(Nom,_),
assert(type(Nom,donnee)),fail.
typesdonnees.
%% +++++++++++++++++++++ demontr(Theoreme) +++++++++++++++++++
%% core of the prover : initialisations, displays
%% activates and applies rules
demontr(_Theoreme) :-
%% stop if limit time out
time_exceeded(0, ['time out even before considering the theorem']).
demontr(Theoreme) :-
( version(casc) -> true
; ecrire1('****************************************'),
ecrire('****************************************'),
ecrire1(['theorem to be proved']),
ecrire1([Theoreme]),
ecrire_tirets('')
%% nl, write(Theoreme) %% if you want entire display
),
preambule,
assign(step(0)), %% 1st step
newconcl(0, Theoreme, E), %% E=1
%% first line of the useful trace
traces(0, action(ini), %% name of action
[], newconcl(0 , Theoreme, E), %% action made
E,'initial theorem',[] %% explanation
),
acrire_tirets(tr,[action,ini]), %% ------------------------------
\+ time_exceeded(0, 'time out even before activating the rules'),
activrul, %% activates rules
\+ time_exceeded(0, 'time out after having activated the rules'),
%% applies rules to the initial theorem numbered 0
applyrulactiv(0),
!
.
%% +++++++++++++++++++++ creersubth(N,N1,A,E) +++++++++++++++++
%% creates N1, subtheorem of N, with conclusion A, at step E
%% other items are those of N (copitem)
creersubth(N,N1,A,E) :-
assert(subth(N,N1)),
ligne(tr),acrire1(tr,[************************************************]),
acrire(tr,[subtheorem, N1,*****]),
newconcl(N1,A,E), copitem(N,N1).
%% proconj(N,C,Econj,Efin), at step Econj, searches to prove (recursively)
%% the conclusion C=AandB of (sub)th numbered N=n1-n2-...-ni
%% or C=A for the last call
%% creation (new step Ecreationsousth) of subth with conclusion A
%% and numbered N1=n1-n2-...-ni-1 puis -2, -3 etc
%% if theorem N1 is proved (concl true) at step Edemsousth
%% then A is removed from the concl of N (step Eretourth)
%% if it was the last subth to be proved (B=true),
%% return in Efin the last step number (Eretourth)
%% else call demconj for the concl B of N of the step Eretourth
proconj(N,C,Econj, Efin) :-
( C = (A & B) -> true ; (C=A,B=true) ),
atom_concat(N,-,N0), gensym(N0,N1), %% N1=...-1, ...-2, ...-3, ...
creersubth(N,N1,A,Ecreationsousth),
(B=true -> Cond=[],
Expli=('proof of the last element of the conjunction')
; Cond=concl(N, C, Econj),
Expli=['to prove a conjunction',
'prove all the elements of the conjunction']
),
traces(N1, %% number of subth
action(proconj), %% name of the action
Cond, %% condition
[creersubth(N,N1,A,Ecreationsousth), %% actions creation N1
newconcl(N1,A,Ecreationsousth)], %% conclusion
(Ecreationsousth), %% step
Expli, %% explanation
([Econj]) %% antecedents
),
acrire_tirets(tr,[action,proconj]),
applyrulactiv(N1), %% proof (try) of N1
!,
concl(N1,true,Edemsousth), %% N1 has been proved
newconcl(N,B,Eretourth), %% A, just proved, is removed
traces(N,
action(returnpro),
concl(N1,true,Edemsousth),
newconcl(N,B,Eretourth),
(Eretourth),
['the conclusion', A,
'of (sub)theorem', N,
'has been proved (subtheorem', N1,')'
],
([Econj , Ecreationsousth,Edemsousth])
),
acrire_tirets(tr,[action,returnpro]),
( B = true -> Eretourth=Efin ; proconj(N,B,Eretourth,Efin))
.
%% ++++++++++++++++++++++ demdij(N,C,N,C,Edij,Efin) +++++++++++++++++++++++
%% demdij(N,C,Edij, Efin), at step Edij searches to prove (recursively)
%% the conclusion C=AorB of (sub)th N
%% or C=A for the last call
%% creation (new step Ecreationsousth) of subth N1=N+i with concl A
%% if sub-theorem N1 is proved (concl true) at step Edemsousth
%% then N is proved (step Eretourth)
%% if it was the last subth to be proved (B=true),
%% return in Efin the last step number (Eretourth)
%% else call demconj for the concl B of N of the step Eretourth
demdij(N,C,Edij, Efin) :-
message('demdij-C-Edij-Efin'-demdij-C-Edij-Efin),
( C = (A | B) | (C = A , B=true)),
atom_concat(N,+,N0), gensym(N0,N1), %% N1=N+1, N+2, ..., N+i, ...
creersubth(N,N1,A,Ecreationsousth),
traces(N,action(propij),(concl(N, C, Edij)),
creersubth(N,N1,A,Ecreationsousth),
(Ecreationsousth),
['creation of subtheorem',
N1,
'with conclusion',
A],
([Edij])),
acrire_tirets(tr,[action,demdij]),
applyrulactiv(N1), %% proof (try) of N1
!,
concl(N1,C1,Edemsousth),
( C1=true -> %% N1 has been proved
newconcl(N,true,Eretourth), %% then N also
traces(N, action(returnpropij), (sousthdem),
newconcl(N,true,Eretourth),
(Eretourth),
['the conclusion',
A,
'of (sub)theorem',
N,
'has been proved'],
([Edij , Edemsousth])
),
acrire_tirets(tr,[action,returnpropij])
; B \=true -> acrire_tirets(tr,[action,retourdemdij]),
acrire1(tr,'the following disjunction is tried'),
demdij(N,B,Edij,Efin)
; acrire1(tr,'la disjonction n\'a pas ete demontree')
)
.
%% ++++++++++++++++++++++++ copitem(N,M) +++++++++++++++++++++++++
%% copies items hyp, hyp_traite, objet and rulactiv of (sub)theorem N
%% to subtheorem M
copitem(N,M) :- hyp(N, H,I), assert(hyp(M,H,I)), fail.
copitem(N,M) :- hyp_traite(N, H), assert(hyp_traite(M,H)), fail.
copitem(N,M) :- objet(N, H), assert(objet(M,H)),fail.
copitem(N,M) :- rulactiv(N, LR), assert(rulactiv(M,LR)), fail.
copitem(_, _) .
%%
%% ++++++++++++++++ proconclexi(N, C, E, F) +++++++++++++++++++++++++++
%% tries to prove the existential conclusion C of (sub-)theorem N at step E
%% in case of success, F is the new step number
%%
proconclexi(N, ? [X|XX]:C, Eexi, Efin):-
%% Ob is an objet which has already been introduced
obj_ct(N,Ob),
acrire1(tr,
['***',Ob,'is tried','***']
),
%% the number of the new sub-theorem will be the string N1=N+1(then 2,3,...)
%% its conclusion C1 and the step number Ecreationsousth (if success)
atom_concat(N,+,N0), gensym(N0,N1),
remplacer(C,X,Ob,C0),
(XX=[] -> C1=C0 ; C1= (?XX:C0)),
creersubth(N,N1,C1,Ecreationsousth),
traces(N1, action(proconclexi),
concl(N, ? [X]:C, Eexi),
[creersubth(N,N1,C1,Ecreationsousth),
newconcl(N1,C1,Ecreationsousth)],
Ecreationsousth,
[Ob,'is tried for the existential variable'],
[Eexi]
),
acrire_tirets(tr,[action,proconclexi]),
%% proof of the sub-theorem N1, in case of success, its conclusion
%% is put at true ans the final step is Efin
applyrulactiv(N1),
(concl(N1, true, E1) -> newconcl(N,true,Efin),
traces(N,
action(returnproexi),
concl(N1, true, E1),
newconcl(N,true, Efin),
Efin,
['the conclusion of (sub)theorem',
N,
'has been proved (subtheorem',
N1,
')'
],
[Eexi, E1]
)
; acrire1(tr,'the following object is tried'),
fail
).
%% +++++++++++++++++++++ newconcl(N,C,E) ++++++++++++++++++++++++++++
%%
%% if the conclusion of (sub-)theorem with number N is not C (closed formula)
%% the conclusion of (sub-)theorem with number N becomes C
%% - at step E if E was already instantiated (current step)
%% - at a new step E if E was a variable (step to be created),
%% +++++++++++++++++++++
newconcl(N,C, E) :-
\+ concl(N, C, _),
step_action(E),
%% new step if E is a variable, else unchanged
%% for second order, R having been instantiated
(C = (..[R, X, Y]) -> C1 =..[R, X, Y] ; C1=C),
assign(concl(N,C1,E)),
acrire1(tr,[E:N,newconcl(C1)]).
%% +++++++++++++++++++++ addhyp(N, H, E2) ++++++++++++++++++++++++++++
%%
%% if H is trivial, does nothing
%% if H is a conjunction, adds all the element of the conjunction
%% if H is a universal hypothesis, or a no-existence,
%% creates one or more local rules, as from definitions
%% other particular cases are detailed in comment below
%% else the hypothesis H is simply added
addhyp(N, H, E2) :-
%% if E2 is instantiated, it is the current step,
%% else a new step E2 is created
step_action(E2),
( H = (A & B) ->
%% recursive call for a conjunction
addhyp(N, A, E2), addhyp(N,B, E2)
;
%% H is already a hypothesis
hyp(N, H,_) -> acrire1(tr,[E2:N,H]),
acrire1(tr,'is already a hypothesis'),
true
;
%% H is a disjunction containing a hypothesis
hyp_true(N,H,T) -> assert(hyp(N, H,E2)), acrire1(tr,[E2:N,addhyp(H)]),
acrire1(tr,['useless since there is already hyp(',T,')']),
ajhyp_traite(N,H)
;
%% H is a trivial equality
H = (X = X) -> acrire1(tr,[E2:N,addhyp(H)]),
acrire(tr,'which is a trivial equality')
;
H =(X,A) ->
%% such formulas appear during handling definitions such as h(X)=f(g(X))
%% see buildrules, elifun, elifundef &&&&&&&&&&&&&&
step(I), I1 is I+1, assign(step(I1)),
assert(hyp(N,H,I1)),
create_objet(N,z,X1), remplacer(A,X,X1,A1),
addhyp(N,A1,I1)
;
%% equalities are normalized : the 1st term is the smallest,
%% lexicographically, except for created objects where
%% the order is the order of creation (numerical)
H = (Y=X), atom(X), atom(Y), before(X,Y), addhyp(N,(X=Y),E2)
;
%% (for pseudo-second order) if H is ..[r,X,Y], r(X,Y) is added
H = (..[R, X, Y]) -> (H1 =..[R, X, Y]), addhyp(N, H1, E2)
;
H = (..[F, X]::Y) ->
%% (for pseudo-second order) if H is ..[f,x]::y, f(x):y is added
(Y1 =..[F, X]), addhyp(N, Y1:Y, E2),addhyp(N, Y1::Y, E2)
;
H=seul(A::X,Y)->
%% (pseudo-2nd order) if H is only(f(x)::A,p(x,A)) [coming from p(x,f(x))]
%% adds the hypothesis p(x1) where x1 is an object
%% either already introduced (hypothesis f(x)::x1)
%% either created and the hypothesis f(x)::x1 added
( hyp(N,A::X1,_I) -> acrire1(tr,[remplacer,X,par,X1,dans,Y])
; create_objet(N,z,X1),addhyp(N,A::X1, E2)
),
remplacer(Y,X,X1,Y1),addhyp(N,Y1,E2)
;
H = (~ seul(FX::Y,P)) ->
%% if x has been instanciated,p(f(x) may be replaced by ?x:(f(x)::y & p(y)
%% or !x:(f(x)::y => p(y)), the right choice depends on the parity of
%% its depth in the formula, a negation modifies this parity,
%% seul(f(x)::y,p(x)) comes from p(f(x)) which has been replaced by
%% ?y(f(x)::y & p(y) could have been replaced by
%% !y:(f(x)::y => p(y)) equivalent to ~ ?y (f(x)::y & ~ p(y))
%% so ~ seul(f(x)::y,p(x)) may be remplaced by
%% ?y (f(x)::y & ~ p(y)) that is only(f(x)::y,p(y)
addhyp(N,seul(FX::Y, ~ P ), E2)
;
H = (!_: _) -> %% ++++++++++++++++++++++++++++++++++++++++++++++++++
%% creation of local rules named r_hyp_univ_<step> from
%% universal hypotheses and from implications
ecrire1(ajhypE2=E2),
atom_concat(r_hyp_univ_,E2,ReghypE2),
atom_concat(ReghypE2,'_',Reghyp),
acrire1(tr,[E2:N,'treat the universal hypothesis (not added)',
H]),
create_name_rule(Reghyp,Nom), %% Name=r_hyp_<step>_
%% calls buildrules for the statement H (1st argument)
%% the expression N+H as the 4rd argument playing the role of Concept
buildrules(H, _,_,N+H,Nom,[],[E2])
; H = (~ (?XX:A)) ->
%% ~ ?x:p(x) is handled as !x:~p(x)
atom_concat(r_hyp_noexi_,E2,ReghypE2),
atom_concat(ReghypE2,'_',Reghyp),
create_name_rule(Reghyp,Nom), %% Name=r_hyp_noexi_<step>_
buildrules( (!XX:(~ A)), _, _Nomfof, N+H, Nom, [],[])
; H = (_A =>_B) ->
%% building local rules named r_hyp_impl-<step>
atom_concat(r_hyp_impl_,E2,ReghypE2),
atom_concat(ReghypE2,'_',Reghyp),
create_name_rule(Reghyp,Nom), %% Name=r_hyp_impl_<step>_
buildrules( H,_, _Nomfof,N+H,Nom,[],[])
;
%% in all other cases H is added as a new hypothesis
( var(E2) -> step(E0), E2 is E0+1, assign(step(E2))
; true
),
assert(hyp(N, H,E2)), acrire1(tr,[E2:N,addhyp(H)])
) .
before(Z1,Z2) :-
( name(Z1,[122|L1]), name(N1,L1), number(N1),
name(Z2,[122|L2]), name(N2,L2), number(N2) -> N1<N2
; Z1 @< Z2).
ajhyp_traite(N, H) :- assert(hyp_traite(N, H)).
ajhyp_traite(N, H,E) :- ajhyp_traite(N, H),
message(z_ajhyp_traite_a_3_arg,N+H+E).
ajobjet(N, X) :-
( objet(N, X) -> true
; assert(objet(N, X)
),
( N=(-1)-> true
; step(E), acrire1(tr,[E:N, 'add object',X]))
) .
ajconcept(P) :- (concept(P) -> true; assert(concept(P))).
ajfonction(F,N) :- (fonction(F,N)-> true;assert(fonction(F,N))).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% b u i l d i n g r u l e s %%
%% buildrules/0and7 ajoucond ajoureg ajoureglocale %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% buldrules/7 builds rules from a statement
%% buldrules/0 builds the statements to be sent to buildrules/7
%% from definitions and lemmas, according to their form
%% ++++++++++ buildrules ++++++++++
%% removes old rules previously built
buildrules :-
effacer_regcons,fail.
%% if A has a negative definition ~B, in addition to the normal building,
%% 2 new definitions are added : nonA defined by B
%% and A defined by the negation of B
%% (see manual-en.pdf § 6. Definitions and lemmas
buildrules :- definition(Nomfof,A<=> ~ B),
A=..[P|L], vars(L),
ajconcept(P),
atom_concat(non,P,NonP),ajconcept(NonP),
NonA =.. [NonP|L],
\+ NonA = B,
asserta(definition(Nomfof,A <=> ~ NonA)),
asserta(definition(Nomfof,NonA <=> B)),
denumlast(P,P1),
create_name_rule(P1,Nom),
assert((rule(_,Nom):- hyp(N,~ A,I), \+ hyp(N,NonA,_),
addhyp(N,NonA,_),
traces(N,rule(Nom),
hyp(N,~ A,I), addhyp(N,NonA,E),E,
[because,P,et,NonP],
[I]
)
)),
assert(type(Nom,P)),
fail.
%% definitions of functional symbols (see manual-en.pdf)
buildrules :- definition(Nomfof, A<=>B),
not(var(A)),
(writebuildrules-> ecrire1('\nbuildrules'-definition(Nomfof,A<=>B));true),
( A=(C::_) -> C =..[P|_]
; A=..[_,_,E],not(var(E)),E=..[_|_] -> fail
; A=..[P|_]
),
(writebuildrules-> ecrire1(definitionapres(A<=>B)+'P'=P);true),
ajconcept(P),
denumlast(P,P1),
create_name_rule(P1,Nom),
(A=(X=Y)-> remplacer(B,Y,X,B1),buildrules(B1,N,Nomfof,P,Nom,objet(N,X),[])
; buildrules(A=>B,_,Nomfof,P,Nom,[],[]),
(B = (_ | _) -> (writebuildrules ->
ecrire1('buildrules def contraposee de ':(A=>B))
;true),
buildrules(B=>A,_,Nomfof,P,Nom,[],[]);true)
),
fail.
buildrules :- definition(Nomfof,A=B), not(B=[_,_]),
A =.. [F|_], ajconcept(F),
denumlast(F,F1),
create_name_rule(F1,Nom),
elifun4(B::X,B1X), buildrules(A::X => B1X,_,Nomfof,F,Nom,[],[]),
fail.
%% set theory definitions
buildrules :- definition(Nomfof,A<=>D),
(writebuildrules -> ecrire1(\nbuildrules-def-elt-definition(Nomfof,(A<=D)))
;true),
( A =..[R,X,E],not(var(E)),E=..[F|_]
) ,
ajconcept(F),
denumlast(F,F1),
create_name_rule(F1,Nom),
(atom(E) ->
(writebuildrules -> ecrire1(buildrules-def-elt-apres1:(![X]:(A =>D)));true),
buildrules((![X]:(A =>D)),_,Nomfof,F,Nom,[],[])
; XappW =.. [R,X,W],
(writebuildrules ->
ecrire1(buildrules-def-elt-apres2:((E::W)=>![X]:(XappW <=>D)))
;true),
buildrules((E::W)=>![X]:(XappW <=>D),_,Nomfof,F,Nom,[],[])
),
fail.
%% from lemmas
buildrules :- lemme(Nomfof,E),atom_concat(Nomfof,'_',Nom0),
create_name_rule(Nom0,Nom1),buildrules(E,_,Nomfof,lemme,Nom1,[],[]),fail.
buildrules.
%% +++++++++++++ buildrules(E,N,Nomfof,Concept,Nom,Cond,Antecedents) ++++++++++
%%
%% recursive building of rules from a statement E
%% - N is either a not instantiated variable, if it is (or comes from)
%% a definition or a lemma, either a (sub-)theoreme number if E is
%% one of its hypothese(s)
%% - Nomfof and Concept are keywords contained in the initial statement
%% and will be parts of the names of the rules beeing built
%% - Nom will be the prefixe of the final name given to the rules beeing built
%% - Cond is the conditions part, empty at th beginning, built step by step
%% - Antecedents is the list step numbers of the already built conditions
%% for a detailed display of the building (option writebuildrules)
buildrules(E,N,Nomfof,Concept,Nom,Cond,Antecedants):- writebuildrules, nl,