-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjall.ml
4599 lines (4225 loc) · 180 KB
/
jall.ml
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
(*
* JProver first-order automated prover. See the interface file
* for more information and a list of references for JProver.
*
* ----------------------------------------------------------------
*
* This file is part of MetaPRL, a modular, higher order
* logical framework that provides a logical programming
* environment for OCaml and other languages.
*
* See the file doc/index.html for information on Nuprl,
* OCaml, and more information about this system.
*
* Copyright (C) 2000 Stephan Schmitt
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Stephan Schmitt <[email protected]>
* Modified by: Aleksey Nogin <[email protected]>
*)
open Jterm
open Opname
open Jlogic
open Jtunify
let ruletable = Jlogic.ruletable
let free_var_op = make_opname ["free_variable"; "Jprover"]
let jprover_op = make_opname ["jprover"; "string"]
module JProver (JLogic : JLogicSig) =
struct
type polarity = I | O
type connective = And | Or | Neg | Imp | All | Ex | At | Null
type ptype = Alpha | Beta | Gamma | Delta | Phi | Psi | PNull
type stype =
Alpha_1 | Alpha_2 | Beta_1 | Beta_2 | Gamma_0 | Delta_0
| Phi_0 | Psi_0 | PNull_0
type pos = {name : string;
address : int list;
op : connective;
pol : polarity;
pt : ptype;
st : stype;
label : term}
type 'pos ftree =
Empty
| NodeAt of 'pos
| NodeA of 'pos * ('pos ftree) array
type atom = {aname : string;
aaddress : int list;
aprefix : string list;
apredicate : operator;
apol : polarity;
ast : stype;
alabel : term}
type atom_relations = atom * atom list * atom list
(* all atoms except atom occur in [alpha_set] and [beta_set] of atom*)
(* beta proofs *)
type bproof = BEmpty
| RNode of string list * bproof
| CNode of (string * string)
| BNode of string * (string list * bproof) * (string list * bproof)
| AtNode of string * (string * string)
(* Assume only constants for instantiations, not adapted to terms yet *)
type inf = rule * term * term
(* proof tree for pretty print and permutation *)
type 'inf ptree =
PEmpty
| PNodeAx of 'inf
| PNodeA of 'inf * 'inf ptree
| PNodeB of 'inf * 'inf ptree * 'inf ptree
module OrderedAtom =
struct
type t = atom
let compare a1 a2 = if (a1.aname) = (a2.aname) then 0 else
if (a1.aname) < (a2.aname) then -1 else 1
end
module AtomSet = Set.Make(OrderedAtom)
module OrderedString =
struct
type t = string
let compare a1 a2 = if a1 = a2 then 0 else
if a1 < a2 then -1 else 1
end
module StringSet = Set.Make(OrderedString)
(*i let _ =
show_loading "Loading Jall%t" i*)
let debug_jprover =
create_debug (**)
{ debug_name = "jprover";
debug_description = "Display Jprover operations";
debug_value = false
}
let jprover_bug = Invalid_argument "Jprover bug (Jall module)"
(*****************************************************************)
(************* printing function *************************************)
(************ printing T-string unifiers ****************************)
(* ******* printing ********** *)
let rec list_to_string s =
match s with
[] -> ""
| f::r ->
f^"."^(list_to_string r)
let rec print_eqlist eqlist =
match eqlist with
[] ->
print_endline ""
| (atnames,f)::r ->
let (s,t) = f in
let ls = list_to_string s
and lt = list_to_string t in
begin
print_endline ("Atom names: "^(list_to_string atnames));
print_endline (ls^" = "^lt);
print_eqlist r
end
let print_equations eqlist =
begin
Format.open_box 0;
Format.force_newline ();
print_endline "Equations:";
print_eqlist eqlist;
Format.force_newline ();
end
let rec print_subst sigma =
match sigma with
[] ->
print_endline ""
| f::r ->
let (v,s) = f in
let ls = list_to_string s in
begin
print_endline (v^" = "^ls);
print_subst r
end
let print_tunify sigma =
let (n,subst) = sigma in
begin
print_endline " ";
print_endline ("MaxVar = "^(string_of_int (n-1)));
print_endline " ";
print_endline "Substitution:";
print_subst subst;
print_endline " "
end
(*****************************************************)
(********* printing atoms and their relations ***********************)
let print_stype st =
match st with
Alpha_1 -> Format.print_string "Alpha_1"
| Alpha_2 -> Format.print_string "Alpha_2"
| Beta_1 -> Format.print_string "Beta_1"
| Beta_2 -> Format.print_string "Beta_2"
| Gamma_0 -> Format.print_string "Gamma_0"
| Delta_0 -> Format.print_string "Delta_0"
| Phi_0 -> Format.print_string "Phi_0"
| Psi_0 -> Format.print_string "Psi_0"
| PNull_0 -> Format.print_string "PNull_0"
let print_pol pol =
if pol = O then
Format.print_string "O"
else
Format.print_string "I"
let rec print_address int_list =
match int_list with
[] ->
Format.print_string ""
| hd::rest ->
begin
Format.print_int hd;
print_address rest
end
let rec print_prefix prefix_list =
match prefix_list with
[] -> Format.print_string ""
| f::r ->
begin
Format.print_string f;
print_prefix r
end
let print_atom at tab =
let ({aname=x; aaddress=y; aprefix=z; apredicate=p; apol=a; ast=b; alabel=label}) = at in
begin
Format.print_string ("{aname="^x^"; address=");
print_address y;
Format.print_string "; ";
Format.force_newline ();
Format.print_break (tab+1) (tab+1);
Format.print_string "prefix=";
print_prefix z;
Format.print_string "; predicate=<abstr>; ";
Format.print_break (tab+1) (tab+1);
Format.print_break (tab+1) (tab+1);
Format.print_string "pol=";
print_pol a;
Format.print_string "; stype=";
print_stype b;
Format.print_string "; arguments=[<abstr>]";
Format.print_string "\n alabel=";
print_term stdout label;
Format.print_string "}"
end
let rec print_atom_list set tab =
match set with
[] -> Format.print_string ""
| (f::r) ->
begin
Format.force_newline ();
Format.print_break (tab) (tab);
print_atom f tab;
print_atom_list r (tab)
end
let rec print_atom_info atom_relation =
match atom_relation with
[] -> Format.print_string ""
| (a,b,c)::r ->
begin
Format.print_string "atom:";
Format.force_newline ();
Format.print_break 3 3;
print_atom a 3;
Format.force_newline ();
Format.print_break 0 0;
Format.print_string "alpha_set:";
print_atom_list b 3;
Format.force_newline ();
Format.print_break 0 0;
Format.print_string "beta_set:";
print_atom_list c 3;
Format.force_newline ();
Format.force_newline ();
Format.print_break 0 0;
print_atom_info r
end
(*************** print formula tree, tree ordering etc. ***********)
let print_ptype pt =
match pt with
Alpha -> Format.print_string "Alpha"
| Beta -> Format.print_string "Beta"
| Gamma -> Format.print_string "Gamma"
| Delta -> Format.print_string "Delta"
| Phi -> Format.print_string "Phi"
| Psi -> Format.print_string "Psi"
| PNull -> Format.print_string "PNull"
let print_op op =
match op with
At -> Format.print_string "Atom"
| Neg -> Format.print_string "Neg"
| And -> Format.print_string "And"
| Or -> Format.print_string "Or"
| Imp -> Format.print_string "Imp"
| Ex -> Format.print_string "Ex"
| All -> Format.print_string "All"
| Null -> Format.print_string "Null"
let print_position position tab =
let ({name=x; address=y; op=z; pol=a; pt=b; st=c; label=t}) = position in
begin
Format.print_string ("{name="^x^"; address=");
print_address y;
Format.print_string "; ";
Format.force_newline ();
Format.print_break (tab+1) 0;
(* Format.print_break 0 3; *)
Format.print_string "op=";
print_op z;
Format.print_string "; pol=";
print_pol a;
Format.print_string "; ptype=";
print_ptype b;
Format.print_string "; stype=";
print_stype c;
Format.print_string ";";
Format.force_newline ();
Format.print_break (tab+1) 0;
Format.print_string "label=";
Format.print_break 0 0;
Format.force_newline ();
Format.print_break tab 0;
print_term stdout t;
Format.print_string "}"
end
let rec pp_ftree_list tree_list tab =
let rec pp_ftree ftree new_tab =
let dummy = String.make (new_tab-2) ' ' in
match ftree with
Empty -> Format.print_string ""
| NodeAt(position) ->
begin
Format.force_newline ();
Format.print_break new_tab 0;
print_string (dummy^"AtomNode: ");
(* Format.force_newline ();
Format.print_break 0 3;
*)
print_position position new_tab;
Format.force_newline ();
Format.print_break new_tab 0
end
| NodeA(position,subtrees) ->
let tree_list = Array.to_list subtrees in
begin
Format.force_newline ();
Format.print_break new_tab 0;
Format.print_break 0 0;
print_string (dummy^"InnerNode: ");
print_position position new_tab;
Format.force_newline ();
Format.print_break 0 0;
pp_ftree_list tree_list (new_tab-3)
end
in
let new_tab = tab+5 in
match tree_list with
[] -> Format.print_string ""
| first::rest ->
begin
pp_ftree first new_tab;
pp_ftree_list rest tab
end
let print_ftree ftree =
begin
Format.open_box 0;
Format.print_break 3 0;
pp_ftree_list [ftree] 0;
Format.print_flush ()
end
let rec stringlist_to_string stringlist =
match stringlist with
[] -> "."
| f::r ->
let rest_s = stringlist_to_string r in
(f^"."^rest_s)
let rec print_stringlist slist =
match slist with
[] ->
Format.print_string ""
| f::r ->
begin
Format.print_string (f^".");
print_stringlist r
end
let rec pp_bproof_list tree_list tab =
let rec pp_bproof ftree new_tab =
let dummy = String.make (new_tab-2) ' ' in
match ftree with
BEmpty -> Format.print_string ""
| CNode((c1,c2)) ->
begin
Format.open_box 0;
Format.force_newline ();
Format.print_break (new_tab-10) 0;
Format.open_box 0;
Format.force_newline ();
Format.print_string (dummy^"CloseNode: connection = ("^c1^","^c2^")");
Format.print_flush();
(* Format.force_newline ();
Format.print_break 0 3;
*)
Format.open_box 0;
Format.print_break new_tab 0;
Format.print_flush()
end
| AtNode(posname,(c1,c2)) ->
begin
Format.open_box 0;
Format.force_newline ();
Format.print_break (new_tab-10) 0;
Format.open_box 0;
Format.force_newline ();
Format.print_string (dummy^"AtNode: pos = "^posname^" conneciton = ("^c1^","^c2^")");
Format.print_flush();
(* Format.force_newline ();
Format.print_break 0 3;
*)
Format.open_box 0;
Format.print_break new_tab 0;
Format.print_flush()
end
| RNode(alpha_layer,bproof) ->
let alpha_string = stringlist_to_string alpha_layer in
begin
Format.open_box 0;
Format.force_newline ();
Format.print_break new_tab 0;
Format.print_break 0 0;
Format.force_newline ();
Format.print_flush();
Format.open_box 0;
print_string (dummy^"RootNode: "^alpha_string);
Format.print_flush();
Format.open_box 0;
Format.print_break 0 0;
Format.print_flush();
pp_bproof_list [bproof] (new_tab-3)
end
| BNode(posname,(alph1,bproof1),(alph2,bproof2)) ->
let alpha_string1 = stringlist_to_string alph1
and alpha_string2 = stringlist_to_string alph2 in
begin
Format.open_box 0;
Format.force_newline ();
Format.print_break new_tab 0;
Format.print_break 0 0;
Format.force_newline ();
Format.print_flush();
Format.open_box 0;
print_string (dummy^"BetaNode: pos = "^posname^" layer1 = "^alpha_string1^" layer2 = "^alpha_string2);
Format.print_flush();
Format.open_box 0;
Format.print_break 0 0;
Format.print_flush();
pp_bproof_list [bproof1;bproof2] (new_tab-3)
end
in
let new_tab = tab+5 in
match tree_list with
[] -> Format.print_string ""
| first::rest ->
begin
pp_bproof first new_tab;
pp_bproof_list rest tab
end
let rec print_pairlist pairlist =
match pairlist with
[] -> Format.print_string ""
| (a,b)::rest ->
begin
Format.print_break 1 1;
Format.print_string ("("^a^","^b^")");
print_pairlist rest
end
let print_beta_proof bproof =
begin
Format.open_box 0;
Format.force_newline ();
Format.force_newline ();
Format.print_break 3 0;
pp_bproof_list [bproof] 0;
Format.force_newline ();
Format.force_newline ();
Format.force_newline ();
Format.print_flush ()
end
let rec print_treelist treelist =
match treelist with
[] ->
print_endline "END";
| f::r ->
begin
print_ftree f;
Format.open_box 0;
print_endline "";
print_endline "";
print_endline "NEXT TREE";
print_endline "";
print_endline "";
print_treelist r;
Format.print_flush ()
end
let rec print_set_list set_list =
match set_list with
[] -> ""
| f::r ->
(f.aname)^" "^(print_set_list r)
let print_set set =
let set_list = AtomSet.elements set in
if set_list = [] then "empty"
else
print_set_list set_list
let print_string_set set =
let set_list = StringSet.elements set in
print_stringlist set_list
let rec print_list_sets list_of_sets =
match list_of_sets with
[] -> Format.print_string ""
| (pos,fset)::r ->
begin
Format.print_string (pos^": "); (* first element = node which successors depend on *)
print_stringlist (StringSet.elements fset);
Format.force_newline ();
print_list_sets r
end
let print_ordering list_of_sets =
begin
Format.open_box 0;
print_list_sets list_of_sets;
Format.print_flush ()
end
let rec print_triplelist triplelist =
match triplelist with
[] -> Format.print_string ""
| ((a,b),i)::rest ->
begin
Format.print_break 1 1;
Format.print_string ("(("^a^","^b^"),"^(string_of_int i)^")");
print_triplelist rest
end
let print_pos_n pos_n =
Format.print_int pos_n
let print_formula_info ftree ordering pos_n =
begin
print_ftree ftree;
Format.open_box 0;
Format.force_newline ();
print_ordering ordering;
Format.force_newline ();
Format.force_newline ();
Format.print_string "number of positions: ";
print_pos_n pos_n;
Format.force_newline ();
print_endline "";
print_endline "";
Format.print_flush ()
end
(* print sequent proof tree *)
let pp_rule (pos,r,formula,term) tab =
let rep = ruletable r in
if List.mem rep ["Alll";"Allr";"Exl";"Exr"] then
begin
Format.open_box 0;
(* Format.force_newline (); *)
Format.print_break tab 0;
Format.print_string (pos^": "^rep^" ");
Format.print_flush ();
(* Format.print_break tab 0;
Format.force_newline ();
Format.print_break tab 0;
*)
Format.open_box 0;
print_term stdout formula;
Format.print_flush ();
Format.open_box 0;
Format.print_string " ";
Format.print_flush ();
Format.open_box 0;
print_term stdout term;
Format.force_newline ();
Format.force_newline ();
Format.print_flush ()
end
else
begin
Format.open_box 0;
Format.print_break tab 0;
Format.print_string (pos^": "^rep^" ");
Format.print_flush ();
Format.open_box 0;
(* Format.print_break tab 0; *)
Format.force_newline ();
(* Format.print_break tab 0; *)
print_term stdout formula;
Format.force_newline ()
end
let last addr =
if addr = ""
then ""
else
String.make 1 (String.get addr (String.length addr-1))
let rest addr =
if addr = ""
then ""
else
String.sub addr 0 ((String.length addr) - 1)
let rec get_r_chain addr =
if addr = "" then
0
else
let l = last addr in
if l = "l" then
0
else (* l = "r" *)
let rs = rest addr in
1 + (get_r_chain rs)
let rec tpp seqtree tab addr =
match seqtree with
| PEmpty -> raise jprover_bug
| PNodeAx(rule) ->
let (pos,r,p,pa) = rule in
begin
pp_rule (pos,r,p,pa) tab;
(* Format.force_newline (); *)
(* let mult = get_r_chain addr in *)
(* Format.print_break 100 (tab - (3 * mult)) *)
end
| PNodeA(rule,left) ->
let (pos,r,p,pa) = rule in
begin
pp_rule (pos,r,p,pa) tab;
tpp left tab addr
end
| PNodeB(rule,left,right) ->
let (pos,r,p,pa) = rule in
let newtab = tab + 3 in
begin
pp_rule (pos,r,p,pa) tab;
(* Format.force_newline (); *)
(* Format.print_break 100 newtab; *)
(tpp left newtab (addr^"l"));
(tpp right newtab (addr^"r"))
end
let tt seqtree =
begin
Format.open_box 0;
tpp seqtree 0 "";
Format.force_newline ();
Format.close_box ();
Format.print_newline ()
end
(************ END printing functions *********************************)
(************ Beta proofs and redundancy deletion **********************)
let rec remove_dups_connections connection_list =
match connection_list with
[] -> []
| (c1,c2)::r ->
if (List.mem (c1,c2) r) or (List.mem (c2,c1) r) then
(* only one direction variant of a connection stays *)
remove_dups_connections r
else
(c1,c2)::(remove_dups_connections r)
let rec remove_dups_list list =
match list with
[] -> []
| f::r ->
if List.mem f r then
remove_dups_list r
else
f::(remove_dups_list r)
let beta_pure alpha_layer connections beta_expansions =
let (l1,l2) = List.split connections in
let test_list = l1 @ l2 @ beta_expansions in
begin
(* Format.open_box 0;
print_endline "";
print_stringlist alpha_layer;
Format.print_flush();
Format.open_box 0;
print_endline "";
print_stringlist test_list;
print_endline "";
Format.print_flush();
*)
not (List.exists (fun x -> (List.mem x test_list)) alpha_layer)
end
let rec apply_bproof_purity bproof =
match bproof with
BEmpty ->
raise jprover_bug
| CNode((c1,c2)) ->
bproof,[(c1,c2)],[]
| AtNode(_,(c1,c2)) ->
bproof,[(c1,c2)],[]
| RNode(alpha_layer,subproof) ->
let (opt_subproof,min_connections,beta_expansions) =
apply_bproof_purity subproof in
(RNode(alpha_layer,opt_subproof),min_connections,beta_expansions)
| BNode(pos,(alph1,subp1),(alph2,subp2)) ->
let (opt_subp1,min_conn1,beta_exp1) = apply_bproof_purity subp1 in
if beta_pure alph1 min_conn1 beta_exp1 then
begin
(* print_endline ("Left layer of "^pos); *)
(opt_subp1,min_conn1,beta_exp1)
end
else
let (opt_subp2,min_conn2,beta_exp2) = apply_bproof_purity subp2 in
if beta_pure alph2 min_conn2 beta_exp2 then
begin
(* print_endline ("Right layer of "^pos); *)
(opt_subp2,min_conn2,beta_exp2)
end
else
let min_conn = remove_dups_connections (min_conn1 @ min_conn2)
and beta_exp = remove_dups_list ([pos] @ beta_exp1 @ beta_exp2) in
(BNode(pos,(alph1,opt_subp1),(alph2,opt_subp2)),min_conn,beta_exp)
let bproof_purity bproof =
let (opt_bproof,min_connections,_) = apply_bproof_purity bproof in
opt_bproof,min_connections
(*********** split permutation *****************)
let rec apply_permutation bproof rep_name direction act_blayer =
match bproof with
BEmpty | RNode(_,_) ->
raise jprover_bug
| AtNode(cx,(c1,c2)) ->
bproof,act_blayer
| CNode((c1,c2)) ->
bproof,act_blayer
| BNode(pos,(alph1,subp1),(alph2,subp2)) ->
if rep_name = pos then
let (new_blayer,replace_branch) =
if direction = "left" then
(alph1,subp1)
else (* direciton = "right" *)
(alph2,subp2)
in
(match replace_branch with
CNode((c1,c2)) ->
(AtNode(c1,(c1,c2))),new_blayer (* perform atom expansion at c1 *)
| _ ->
replace_branch,new_blayer
)
else
let pproof1,new_blayer1 = apply_permutation subp1 rep_name direction act_blayer in
let pproof2,new_blayer2 = apply_permutation subp2 rep_name direction new_blayer1 in
(BNode(pos,(alph1,pproof1),(alph2,pproof2))),new_blayer2
let split_permutation pname opt_bproof =
match opt_bproof with
RNode(alayer,BNode(pos,(alph1,opt_subp1),(alph2,opt_subp2))) ->
if pos = pname then
(* if topmost beta expansion agrees with pname, then *)
(* only split the beta proof and give back the two subproofs *)
let (osubp1,min_con1) = bproof_purity opt_subp1
and (osubp2,min_con2) = bproof_purity opt_subp2 in
(* there will be no purity reductions in the beta subproofs. We use this *)
(* predicate to collect the set of used leaf-connections in each subproof*)
((RNode((alayer @ alph1),osubp1),min_con1),
(RNode((alayer @ alph2),osubp2),min_con2)
)
(* we combine the branch after topmost beta expansion at pos into one root alpha layer *)
(* -- the beta expansion node pos will not be needed in this root layer *)
else
let perm_bproof1,balph1 = apply_permutation
(BNode(pos,(alph1,opt_subp1),(alph2,opt_subp2))) pname "left" []
and perm_bproof2,balph2 = apply_permutation
(BNode(pos,(alph1,opt_subp1),(alph2,opt_subp2))) pname "right" [] in
begin
(* print_endline " ";
print_beta_proof perm_bproof1;
print_endline" " ;
print_beta_proof perm_bproof2;
print_endline" ";
*)
let (osubp1,min_con1) = bproof_purity perm_bproof1
and (osubp2,min_con2) = bproof_purity perm_bproof2 in
((RNode((alayer @ balph1),osubp1),min_con1),
(RNode((alayer @ balph2),osubp2),min_con2)
)
end
(* we combine the branch after the NEW topmost beta expansion at bpos *)
(* into one root alpha layer -- the beta expansion node bpos will not be *)
(* needed in this root layer *)
| _ ->
raise jprover_bug
(*********** END split permutation *****************)
let rec list_del list_el el_list =
match el_list with
[] ->
raise jprover_bug
| f::r ->
if list_el = f then
r
else
f::(list_del list_el r)
let rec list_diff del_list check_list =
match del_list with
[] ->
[]
| f::r ->
if List.mem f check_list then
list_diff r check_list
else
f::(list_diff r check_list)
(* let rec compute_alpha_layer ftree_list =
match ftree_list with
[] ->
[],[],[]
| f::r ->
(match f with
Empty ->
raise jprover_bug
| NodeAt(pos) ->
let pn = pos.name
and (rnode,ratom,borderings) = compute_alpha_layer r in
((pn::rnode),(pn::ratom),borderings)
| NodeA(pos,suctrees) ->
let pn = pos.name in
if pos.pt = Beta then
let (rnode,ratom,borderings) = compute_alpha_layer r in
((pn::rnode),(ratom),(f::borderings))
else
let suclist = Array.to_list suctrees in
compute_alpha_layer (suclist @ r)
)
let rec compute_connection alpha_layer union_atoms connections =
match connections with
[] -> ("none","none")
| (c,d)::r ->
if (List.mem c union_atoms) & (List.mem d union_atoms) then
let (c1,c2) =
if List.mem c alpha_layer then
(c,d)
else
if List.mem d alpha_layer then
(d,c) (* then, d is supposed to occur in [alpha_layer] *)
else
raise (Invalid_argument "Jprover bug: connection match failure")
in
(c1,c2)
else
compute_connection alpha_layer union_atoms r
let get_beta_suctrees btree =
match btree with
Empty | NodeAt(_) -> raise jprover_bug
| NodeA(pos,suctrees) ->
let b1tree = suctrees.(0)
and b2tree = suctrees.(1) in
(pos.name,b1tree,b2tree)
let rec build_beta_proof alpha_layer union_atoms beta_orderings connections =
let (c1,c2) = compute_connection alpha_layer union_atoms connections in
(* [c1] is supposed to occur in the lowmost alpha layer of the branch, *)
(* i.e. [aplha_layer] *)
if (c1,c2) = ("none","none") then
(match beta_orderings with
[] -> raise jprover_bug
| btree::r ->
let (beta_pos,suctree1,suctree2) = get_beta_suctrees btree in
let (alpha_layer1, atoms1, bordering1) = compute_alpha_layer [suctree1]
and (alpha_layer2, atoms2, bordering2) = compute_alpha_layer [suctree2] in
let bproof1,beta1,closure1 =
build_beta_proof alpha_layer1 (atoms1 @ union_atoms)
(bordering1 @ r) connections
in
let bproof2,beta2,closure2 =
build_beta_proof alpha_layer2 (atoms2 @ union_atoms)
(bordering2 @ r) connections in
(BNode(beta_pos,(alpha_layer1,bproof1),(alpha_layer2,bproof2))),(1+beta1+beta2),(closure1+closure2)
)
else
CNode((c1,c2)),0,1
let construct_beta_proof ftree connections =
let (root_node,root_atoms,beta_orderings) = compute_alpha_layer [ftree]
in
let beta_proof,beta_exp,closures =
build_beta_proof root_node root_atoms beta_orderings connections in
(RNode(root_node,beta_proof)),beta_exp,closures
*)
(* *********** New Version with direct computation from extension proof **** *)
(* follows a DIRECT step from proof histories via pr-connection orderings to opt. beta-proofs *)
let rec compute_alpha_layer ftree_list =
match ftree_list with
[] ->
[]
| f::r ->
(match f with
Empty ->
raise jprover_bug
| NodeAt(pos) ->
let rnode = compute_alpha_layer r in
(pos.name::rnode)
| NodeA(pos,suctrees) ->
if pos.pt = Beta then
let rnode = compute_alpha_layer r in
(pos.name::rnode)
else
let suclist = Array.to_list suctrees in
compute_alpha_layer (suclist @ r)
)
let rec compute_beta_difference c1_context c2_context act_context =
match c1_context,c2_context with
([],c2_context) ->
(list_diff c2_context act_context)
(* both connection partners in the same submatrix; [c1] already isolated *)
| ((fc1::rc1),[]) ->
[] (* [c2] is a reduction step, i.e. isolated before [c1] *)
| ((fc1::rc1),(fc2::rc2)) ->
if fc1 = fc2 then (* common initial beta-expansions *)
compute_beta_difference rc1 rc2 act_context
else
(list_diff c2_context act_context)
let rec non_closed beta_proof_list =
match beta_proof_list with
[] ->
false
| bpf::rbpf ->
(match bpf with
RNode(_,_) -> raise (Invalid_argument "Jprover bug: invalid beta-proof")
| AtNode(_,_) -> raise (Invalid_argument "Jprover bug: invalid beta-proof")
| BEmpty -> true
| CNode(_) -> non_closed rbpf
| BNode(pos,(_,bp1),(_,bp2)) -> non_closed ([bp1;bp2] @ rbpf)
)
let rec cut_context pos context =
match context with
[] ->
raise (Invalid_argument "Jprover bug: invalid context element")
| (f,num)::r ->
if pos = f then
context
else
cut_context pos r
let compute_tree_difference beta_proof c1_context =
match beta_proof with
RNode(_,_) -> raise (Invalid_argument "Jprover bug: invalid beta-proof")
| CNode(_) -> raise (Invalid_argument "Jprover bug: invalid beta-proof")
| AtNode(_,_) -> raise (Invalid_argument "Jprover bug: invalid beta-proof")
| BEmpty -> c1_context
| BNode(pos,_,_) ->
(* print_endline ("actual root: "^pos); *)