-
Notifications
You must be signed in to change notification settings - Fork 0
/
generalize.rkt
1205 lines (1175 loc) · 49.9 KB
/
generalize.rkt
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
#lang at-exp 2d racket
(require
2d/match
racket/struct
scribble/srcdoc
(only-in "abstract-analysis.rkt" tree-label? tree-label-conjunction generalization?)
cclp/abstract-multi-domain
(only-in "abstract-domain-ordering.rkt" renames?)
(only-in "abstraction-inspection-utils.rkt" assemble-var-indices extract-subscripted-variables extract-variables get-multi-id)
(only-in "abstract-renaming.rkt" offset-vars)
(only-in "abstract-unify.rkt" abstract-unify)
(only-in "abstract-substitution.rkt" abstract-equality apply-substitution)
(only-in "data-utils.rkt" some-v)
cclp/gen-graph-structs
cclp/genealogical-graph
(only-in "multi-folding-unfolding.rkt" remove-multi-subscripts)
(only-in "multi-unfolding.rkt" unfold-multi-many unfold-multi-many-bounded unfold-multi-many-right)
(only-in racket-list-utils/utils replace-sublist map-accumulatel group-by)
cclp/clustering
graph)
(require (for-doc scribble/manual))
(define gen-range-descending? (compose not gen-range-ascending?))
;; gets the origin from either a generation or a generation range
(define (gen-thing-origin gen-thing)
(match gen-thing
[(? gen-range?) (gen-range-origin gen-thing)]
[(? gen?) (gen-origin gen-thing)]))
;; accumulator struct used when folding over a level of identified gen nodes
(struct grouping (completed potential current-gen next-multi-id dummy-id lvl)
#:methods
gen:custom-write
[(define write-proc
(make-constructor-style-printer
(λ (obj) 'grouping)
(λ (obj) (list (grouping-completed obj)
(grouping-potential obj)
(grouping-current-gen obj)
(grouping-next-multi-id obj)
(grouping-dummy-id obj)
(grouping-lvl obj)))))])
(define (prefix-subscripts multi-id idx var)
(define curried (curry prefix-subscripts multi-id idx))
(match var
[(? list?) (map curried var)]
[(abstract-atom sym args)
(abstract-atom* sym (map curried args))]
[(abstract-function sym args)
(abstract-function* sym (map curried args))]
[(a i) (a* multi-id idx i)]
[(g i) (g* multi-id idx i)]))
(define (multi-id m)
(define vars (extract-subscripted-variables m))
(abstract-variable*-multi-id (first vars)))
(define (generalized-ranges pre post)
(define post-ids (map gen-node-id post))
(define (aux id acc)
(match-let ([(cons idx rngs) acc])
(if (member id post-ids)
(cons (add1 idx) rngs)
(match rngs
[(list-rest (index-range hs he) t)
#:when (eqv? idx he)
(cons (add1 idx) (cons (index-range hs (add1 he)) t))]
[_ (cons (add1 idx) (cons (index-range idx (add1 idx)) rngs))]))))
(reverse (cdr (foldl aux (cons 0 '()) (map gen-node-id pre)))))
(module+ test
(check-equal?
(generalized-ranges
(list
(gen-node (abstract-atom 'integers '()) 2 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'filter '()) 3 (gen 1 1) #f #t)
(gen-node (abstract-atom 'filter '()) 4 (gen 2 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 4) (abstract-function 'cons (list (g 5) (a 3) (a 4))) (a 5))) 5 (gen 3 1) #f #t)
(gen-node (abstract-atom 'filter '()) 6 (gen 4 1) #f #t)
(gen-node (abstract-atom 'filter '()) 7 (gen 5 1) #f #t)
(gen-node (abstract-atom 'filter '()) 8 (gen 6 1) #f #t)
(gen-node (abstract-atom 'sift '()) 9 (gen 6 1) #f #t)
(gen-node (abstract-atom 'len '()) 10 (gen 0 #f) #f #t))
(list
(gen-node (abstract-atom 'integers '()) 2 (gen 0 #f) #f #t)
(gen-node (multi '() #t (init '()) (consecutive '()) (final '())) 11 (gen-range 1 2 1 #t) #f #t)
(gen-node (abstract-atom 'filter (list (g 4) (abstract-function 'cons (list (g 5) (a 3) (a 4))) (a 5))) 5 (gen 3 1) #f #t)
(gen-node (multi '() #t (init '()) (consecutive '()) (final '())) 12 (gen-range 4 5 1 #t) #f #t)
(gen-node (abstract-atom 'filter '()) 8 (gen 6 1) #f #t)
(gen-node (abstract-atom 'sift '()) 9 (gen 6 1) #f #t)
(gen-node (abstract-atom 'len '()) 10 (gen 0 #f) #f #t)))
(list (index-range 1 3) (index-range 4 6))))
;; this turns the "growing abstraction" into a single multi abstraction
;; that is, a single generation stays a single generation
;; a single multi stays a single multi
;; three consecutive generations become a single multi (two would introduce undesired aliasing when the multi is unfolded to a single conjunction)
;; a generation and a multi (in either order) become a single multi
;; two multis become a single multi
;; note that this should never fail
;; if a conjunct is in the growing abstraction, it belongs there and it respects the pattern
;; also returns the next valid fresh id for a multi (which may be the input id if it was not needed)
(define (group-sequential-generations potential fresh-id dummy-id lvl)
;; !!!!! POTENTIAL HERE IS NOT THE POTENTIAL FIELD OF A GROUPING BUT AN EXTENSION !!!!!
;; RENAME!
;; TODO: simplify, this thing is bloated
(define partitioning (group-by gen-node-range potential))
(define (aux partitioning)
(match partitioning
[(list
(and (list-rest (gen-node (? abstract-atom?) _ (gen genn-1 id) _ _) first-rest) lvl-1)
(and (list-rest (gen-node (? abstract-atom?) _ (gen genn-2 id) _ _) second-rest) lvl-2))
(cons
(let* ([gen-1 (map gen-node-conjunct lvl-1)]
[gen-2 (map gen-node-conjunct lvl-2)]
[offset (apply max (cons 0 (assemble-var-indices (λ (_) #t) (append gen-1 gen-2))))]
[offset-gen-2 (offset-vars gen-2 offset offset)]
[subst-1 (some-v (abstract-unify (map abstract-equality gen-1 offset-gen-2) 0))]
[shared (filter (match-lambda [(abstract-equality v1 v2) (and (member (offset-vars v2 (- offset) (- offset)) (extract-variables gen-1)) (member (offset-vars v2 (- offset) (- offset)) (extract-variables gen-2)))]) subst-1)]
[new-consecutive (map (match-lambda [(abstract-equality (a idx1) (a idx2)) (cons (a* fresh-id 'i+1 idx1) (a* fresh-id 'i (- idx2 offset)))] [(abstract-equality (g idx1) (g idx2)) (cons (g* fresh-id 'i+1 idx1) (g* fresh-id 'i (- idx2 offset)))]) shared)]
[context (foldr (λ (el acc) (if (or (member el lvl-1) (member el lvl-2)) acc (cons el acc))) '() lvl)]
[context-vars (extract-variables (map gen-node-conjunct context))]
[new-init (map (λ (v) (cons (prefix-subscripts fresh-id 1 v) v)) (filter (λ (v) (member v context-vars)) (extract-variables (map gen-node-conjunct lvl-1))))]
[new-final (foldr (λ (el acc)
(match el
[(abstract-equality (a idx1) (a idx2)) (if (member (a (- idx2 offset)) context-vars) (cons (cons (a* fresh-id 'L idx1) (a (- idx2 offset))) acc) acc)]
[(abstract-equality (g idx1) (g idx2)) (if (member (g (- idx2 offset)) context-vars) (cons (cons (g* fresh-id 'L idx1) (g (- idx2 offset))) acc) acc)])) '() subst-1)])
(list
(gen-node
(multi
(prefix-subscripts fresh-id 'i (map gen-node-conjunct lvl-1))
(gen-number< genn-1 genn-2)
(init new-init)
(consecutive new-consecutive)
(final new-final)
id)
dummy-id
(gen-range genn-1 genn-2 id (gen-number< genn-1 genn-2))
#f
#t)))
(add1 fresh-id))]
[(list
(and (list-rest (gen-node (? abstract-atom?) _ (gen n id) _ _) first-rest) lvl-1)
(and (list (gen-node (and (? multi?) existing-multi) _ (gen-range m o id asc?) _ _)) lvl-2))
(let* ([existing-instance (map gen-node-conjunct lvl-1)]
[subscriptless-instance (remove-multi-subscripts (multi-conjunction existing-multi))]
[offset (apply max (cons 0 (assemble-var-indices (λ (_) #t) (append subscriptless-instance (map gen-node-conjunct lvl-1)))))]
[unifiable-instance (offset-vars subscriptless-instance offset offset)]
[unification (some-v (abstract-unify (list (abstract-equality unifiable-instance existing-instance)) 0))]
[context (foldr (λ (el acc) (if (or (member el lvl-1) (member el lvl-2)) acc (cons el acc))) '() lvl)]
[context-vars (extract-variables (map gen-node-conjunct context))]
[new-init
(init
(filter
(match-lambda [(cons v1 v2) (member v2 context-vars)])
(map
(match-lambda
[(abstract-equality var1 var2)
(cons
(prefix-subscripts (multi-id existing-multi) 1 (offset-vars var1 (- offset) (- offset)))
var2)])
unification)))])
(cons (list (gen-node (struct-copy multi existing-multi [init new-init]) dummy-id (gen-range n o id asc?) #f #t)) fresh-id))]
[(list
(and (list (gen-node (and (? multi?) existing-multi) _ (gen-range m o id asc?) _ _)) lvl-1)
(and (list-rest (gen-node (? abstract-atom?) _ (gen n id) _ _) first-rest) lvl-2))
(let* ([existing-instance (map gen-node-conjunct lvl-2)]
[subscriptless-instance (remove-multi-subscripts (multi-conjunction existing-multi))]
[offset (apply max (cons 0 (assemble-var-indices (λ (_) #t) (append subscriptless-instance (map gen-node-conjunct lvl-2)))))]
[unifiable-instance (offset-vars subscriptless-instance offset offset)]
[unification (some-v (abstract-unify (list (abstract-equality unifiable-instance existing-instance)) 0))]
[context (foldr (λ (el acc) (if (or (member el lvl-1) (member el lvl-2)) acc (cons el acc))) '() lvl)]
[context-vars (extract-variables (map gen-node-conjunct context))]
; only this is different wrt previous case
[new-final
(final
(filter
(match-lambda [(cons v1 v2) (member v2 context-vars)])
(map
(match-lambda
[(abstract-equality var1 var2)
(cons
(prefix-subscripts (multi-id existing-multi) 'L (offset-vars var1 (- offset) (- offset)))
var2)])
unification)))])
(cons (list (gen-node (struct-copy multi existing-multi [final new-final]) dummy-id (gen-range m n id asc?) #f #t)) fresh-id))]
[(list
(list (gen-node (and (? multi?) existing-multi-1) _ (gen-range n m id asc?) _ _))
(list (gen-node (multi placeholder-2 _ _ _ final-2 rta) _ (gen-range o p id asc?) _ _)))
(let* ([placeholder-1 (multi-conjunction existing-multi-1)]
[subscriptless-instance-1 (remove-multi-subscripts placeholder-1)]
[subscriptless-instance-2 (remove-multi-subscripts placeholder-2)]
[offset (apply max (cons 0 (append (assemble-var-indices (λ (_) #t) subscriptless-instance-1) (assemble-var-indices (λ (_) #t) subscriptless-instance-2))))]
[offset-instance-2 (offset-vars subscriptless-instance-2 offset offset)]
[subst (some-v (abstract-unify (list (abstract-equality offset-instance-2 subscriptless-instance-1)) 0))]
[new-final
(final
(map
(match-lambda
[(cons lhs rhs)
(cons (prefix-subscripts (multi-id existing-multi-1) 'L (apply-substitution subst (offset-vars (remove-multi-subscripts lhs) offset offset)))
rhs)])
(final-constraints final-2)))])
(cons (list (gen-node (struct-copy multi existing-multi-1 [final new-final]) dummy-id (gen-range n p id asc?) #f #t)) fresh-id))]
[(or (list _) (list _ _))
(cons potential fresh-id)]))
(aux partitioning))
;(module+ test
; (check-equal?
; (group-sequential-generations
; (list
; (gen-node (abstract-atom 'filter (list (g 1) (a 1) (a 2))) 2 (gen 1 1) #f #t))
; 1)
; (cons
; (list
; (gen-node (abstract-atom 'filter (list (g 1) (a 1) (a 2))) 2 (gen 1 1) #f #t))
; 1))
; (check-equal?
; (group-sequential-generations
; (list (gen-node (multi (list) #t (init (list)) (consecutive (list)) (final (list))) 2 (gen-range 1 'l 1 #t) #f #t)) 1)
; (cons
; (list (multi (list) #t (init (list)) (consecutive (list)) (final (list)))) 1))
; (check-equal?
; (group-sequential-generations
; (list
; (gen-node (abstract-atom 'filter (list (g 1) (a 1) (a 2))) 2 (gen 1 1) #f #t)
; (gen-node (abstract-atom 'filter (list (g 2) (a 2) (a 3))) 3 (gen 2 1) #f #t))
; 1)
; (cons
; (list
; (multi
; (list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
; #t
; (init
; (list
; (cons (g* 1 1 1) (g 1))
; (cons (a* 1 1 1) (a 1))
; (cons (a* 1 1 2) (a 2))))
; (consecutive (list (cons (a* 1 'i+1 1) (a* 1 'i 2))))
; (final
; (list
; (cons (g* 1 'L 1) (g 2))
; (cons (a* 1 'L 1) (a 2))
; (cons (a* 1 'L 2) (a 3))))))
; 2))
; (check-equal?
; (group-sequential-generations
; (list
; (gen-node (abstract-atom 'collect (list (g 1) (a 1))) 2 (gen (symsum 'l 1) 1) #f #t)
; (gen-node (abstract-atom 'append (list (a 2) (a 1) (a 3))) 3 (gen (symsum 'l 1) 1) #f #t)
; (gen-node
; (multi
; (list
; (abstract-atom* 'collect (list (g* 1 'i 1) (a* 1 'i 1)))
; (abstract-atom* 'append (list (a* 1 'i 2) (a* 1 'i 1) (a* 1 'i 3))))
; #f
; (init
; (list (cons (a* 1 1 2) (a 3))))
; (consecutive
; (list (cons (a* 1 'i+1 2) (a* 1 'i 3))))
; (final ; doesn't matter
; (list)))
; 4 (gen-range 'l 1 1 #f) #f #t))
; 2)
; (cons
; (list
; (multi
; (list
; (abstract-atom* 'collect (list (g* 1 'i 1) (a* 1 'i 1)))
; (abstract-atom* 'append (list (a* 1 'i 2) (a* 1 'i 1) (a* 1 'i 3))))
; #f
; (init
; (list
; (cons (g* 1 1 1) (g 1))
; (cons (a* 1 1 1) (a 1))
; (cons (a* 1 1 2) (a 2))
; (cons (a* 1 1 3) (a 3))))
; (consecutive
; (list (cons (a* 1 'i+1 2) (a* 1 'i 3))))
; (final
; (list))))
; 2))
; (check-equal?
; (group-sequential-generations
; (list
; (gen-node
; (multi
; (list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
; #t
; (init
; (list
; (cons (g* 1 1 1) (g 1))
; (cons (a* 1 1 1) (a 1))
; (cons (a* 1 1 2) (a 2))))
; (consecutive (list (cons (a* 1 'i+1 1) (a* 1 'i 2))))
; (final
; (list
; (cons (g* 1 'L 1) (g 3))
; (cons (a* 1 'L 1) (a 3))
; (cons (a* 1 'L 2) (a 4))))) 2 (gen-range 1 'l 1 #t) #f #t)
; (gen-node
; (multi
; (list (abstract-atom* 'filter (list (g* 2 'i 1) (a* 2 'i 1) (a* 2 'i 2))))
; #t
; (init
; (list
; (cons (a* 2 1 1) (a 4))))
; (consecutive (list (cons (a* 2 'i+1 1) (a* 2 'i 2))))
; (final
; (list
; (cons (g* 2 'L 1) (g 4))
; (cons (a* 2 'L 1) (a 5))
; (cons (a* 2 'L 2) (a 6))))) 3 (gen-range (symsum 'l 1) 'n 1 #t) #f #t))
; 3)
; (cons
; (list
; (multi
; (list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
; #t
; (init
; (list
; (cons (g* 1 1 1) (g 1))
; (cons (a* 1 1 1) (a 1))
; (cons (a* 1 1 2) (a 2))))
; (consecutive (list (cons (a* 1 'i+1 1) (a* 1 'i 2))))
; (final
; (list
; (cons (g* 1 'L 1) (g 4))
; (cons (a* 1 'L 1) (a 5))
; (cons (a* 1 'L 2) (a 6)))))) 3))
; (check-equal?
; (group-sequential-generations
; (list
; (gen-node
; (multi
; (list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
; #t
; (init
; (list
; (cons (a* 1 1 1) (a 1))))
; (consecutive (list (cons (a* 1 'i+1 1) (a* 1 'i 2))))
; (final
; (list
; (cons (a* 1 'L 2) (a 4)))))
; 4 (gen-range 1 'l 1 #t) #f #t)
; (gen-node (abstract-atom 'filter (list (g 4) (a 4) (a 5))) 5 (gen (symsum 'l 1) 1) #f #t))
; 2)
; (cons
; (list
; (multi
; (list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
; #t
; (init
; (list
; (cons (a* 1 1 1) (a 1))))
; (consecutive (list (cons (a* 1 'i+1 1) (a* 1 'i 2))))
; (final
; (list
; (cons (g* 1 'L 1) (g 4))
; (cons (a* 1 'L 1) (a 4))
; (cons (a* 1 'L 2) (a 5))))))
; 2)))
;; folding could keep some conjuncts in current-gen or potential
;; these should be considered completed, as well
(define (finalize g)
(log-debug "finalizing grouping: ~a" g)
(match g
[(grouping co #f cu _ _ _)
(append co cu)]
[(grouping co po cu _ _ _)
(append co po cu)]))
;; some elements can never go in the current-gen component, regardless of current state
(define (can-be-in-current-gen? node)
(and (not (multi? (gen-node-conjunct node)))
(not (equal? (gen-node-range node)
(gen 0 #f)))
(gen-node-foldable? node)))
;; whether we can append also depends on contents of current gen
(define (can-append-to-current-gen? current-gen node)
(and (can-be-in-current-gen? node)
(or (null? current-gen)
(equal? (gen-node-range (first current-gen)) (gen-node-range node)))))
(define (next-current-gen current-gen node)
(cond
[(can-append-to-current-gen? current-gen node)
(append current-gen (list node))]
[(can-be-in-current-gen? node)
(list node)]
[else empty]))
(define (can-group?/pcgn potential current-gen node)
(and (multi? (gen-node-conjunct node))
(strung-together? current-gen node) ; implies not current-gen not empty
(let ([combined
(caar
(group-sequential-generations
(append current-gen (list node))
(add1 (get-multi-id (gen-node-conjunct node)))
1 ; dummy ID is irrelevant here
(append (or potential empty) current-gen (list node))))])
(strung-together? potential combined))))
(define (can-group? potential current-gen node)
(and (not (can-append-to-current-gen? current-gen node))
(or
(can-group?/pcgn potential current-gen node)
(if (null? current-gen)
(strung-together? potential node)
(or (strung-together? potential current-gen)
(strung-together? current-gen node))))))
(define (next-dummy-id potential current-gen node dummy-id)
(if (can-group? potential current-gen node)
(add1 dummy-id)
dummy-id))
(define (needs-new-multi-id? potential current-gen node)
(and (can-group? potential current-gen node)
(not (or (multi? (gen-node-conjunct node))
(multi? (gen-node-conjunct (first potential)))))))
(define (next-multi-id potential current-gen node multi-id)
(if (needs-new-multi-id? potential current-gen node)
(add1 multi-id)
multi-id))
(define (resets-potential? potential current-gen node)
(or (not (gen-node-foldable? node))
(equal? (gen-node-range node) (gen 0 #f))
;; cannot append to current gen -> has to be shifted if possible
;; no point shifting current gen -> even if we can group with current-gen, potential becomes #f
(and (not (null? current-gen))
(not (can-append-to-current-gen? current-gen node))
(not (subsequent-gens?
(gen-node-range (first current-gen))
(gen-node-range node)))
(not (multi? (gen-node-conjunct node))))
(and potential
(null? current-gen) ; implies potential is multi
(not (subsequent-gens?
(gen-node-range (first potential))
(gen-node-range node))))))
(provide
(proc-doc/names
resets-potential?
(-> (or/c (listof abstract-atom?) (listof multi?))
(listof gen-node?)
gen-node?
boolean?)
(potential current-gen node)
@{Tests whether the current combination of a potential abstraction @racket[potential], a current generation @racket[current-gen] and a node @racket[node] being processed leads to the complete absence of a potential abstraction in the next step, represented as @racket[#f].}))
(define (next-potential potential current-gen node fresh-multi-id fresh-dummy-id lvl)
(define (group h t lvl)
(car
(group-sequential-generations
(append h t)
fresh-multi-id
fresh-dummy-id
lvl)))
(cond
[(resets-potential? potential current-gen node) (cons #f 'reset)] ; only case for #f
[(and (not (can-append-to-current-gen? current-gen node))
(can-group?/pcgn potential current-gen node))
(let ([first-grouping (group current-gen (list node) lvl)])
(cons (group potential first-grouping (replace-sublist lvl (append current-gen (list node)) first-grouping)) 'extended))]
[(and (not (can-append-to-current-gen? current-gen node))
(not (null? current-gen))
(strung-together? potential current-gen)
(not (multi? (gen-node-conjunct node))))
(cons (group potential current-gen lvl) 'extended)]
[(and (null? current-gen)
(strung-together? potential node))
(cons (group potential (list node) lvl) 'extended)]
[(and (multi? (gen-node-conjunct node))
(not (null? current-gen))
(strung-together? current-gen node))
(cons (group current-gen (list node) lvl) 'replaced-by-cgn)]
[(and
(not (null? current-gen))
(abstract-atom? (gen-node-conjunct node))
(subsequent-gens? (gen-node-range (first current-gen)) (gen-node-range node)))
(cons current-gen 'replaced-by-current-gen)] ; only case leading to list of atoms
[(multi? (gen-node-conjunct node))
(cons (list node) 'replaced-by-node)]
[(can-append-to-current-gen? current-gen node)
(cons potential 'retained)]
[else (error "missing an option")]))
(define (strung-together? potential suffix)
(define (atoms-join-atoms? a1 a2)
(and (or (equal?
(gen-increment (gen-node-range (first a1)))
(gen-node-range (first a2)))
(equal?
(gen-decrement (gen-node-range (first a1)))
(gen-node-range (first a2))))
(renames?
(map gen-node-conjunct a1)
(map gen-node-conjunct a2))))
(define (atoms-join-multi? a m)
(match* (a m)
[((list-rest
(gen-node _ _ (gen n r) _ _) _)
(gen-node (multi conjunct asc? i c f rta) _ (gen-range l _ r asc?) _ _))
(and
(or
(and asc? (equal? (gen-add1 n) l))
(and (not asc?) (equal? (gen-sub1 n) l)))
(let ([offset (apply max (cons 0 (assemble-var-indices (λ (_) #t) (map gen-node-conjunct (cons m a)))))])
(renames?
(append (map gen-node-conjunct potential) (list (multi conjunct asc? i c f rta)))
(unfold-multi-many (multi conjunct asc? i c f rta) offset offset))))]
[(_ _) #f]))
(define (multi-joins-atoms? m a)
(match* (m a)
[((gen-node (multi conjunct asc? i c f rta) _ (gen-range _ l r asc?) _ _)
(list-rest
(gen-node _ _ (gen n r) _ _) _))
(and
(or
(and asc? (equal? (gen-add1 l) n))
(and (not asc?) (equal? (gen-sub1 l) n)))
(let ([offset (apply max (cons 0 (assemble-var-indices (λ (_) #t) (map gen-node-conjunct (cons m a)))))])
(renames?
(unfold-multi-many-right (multi conjunct asc? i c f rta) offset offset)
(append (map gen-node-conjunct potential) (map gen-node-conjunct a)))))]
[(_ _) #f]))
(define (multi-joins-multi? m1 m2)
(match* (m1 m2)
[((list (gen-node (and (multi _ asc? _ _ _ rta) conjunct-1) _ (gen-range _ m r asc?) _ _))
(gen-node (and (multi _ asc? _ _ _ rta) conjunct-2) _ (gen-range o _ r asc?) _ _))
(let ([offset (apply max (cons 0 (assemble-var-indices (λ (_) #t) (cons conjunct-2 (map gen-node-conjunct m1)))))])
(and
(or (and asc? (equal? o (gen-add1 m))) (and (not asc?) (equal? o (gen-sub1 m))))
(renames? (append (drop (unfold-multi-many-right conjunct-1 offset offset) 1) (list conjunct-2)) (unfold-multi-many conjunct-2 offset offset))))]
[(_ _) #f]))
#2dmatch
╔══════════════════════════════════════════════════════╦═════════════════════════════════════════════════════════════╦════════════════════════════════════════════════╦════╗
║ potential suffix ║ (list-rest (gen-node (? abstract-atom?) _ _ _ _) _) ║ (gen-node (? multi?) _ _ _ _) ║ _ ║
╠══════════════════════════════════════════════════════╬═════════════════════════════════════════════════════════════╬════════════════════════════════════════════════╬════╣
║ (list-rest (gen-node (? abstract-atom?) _ _ _ _) _) ║ (atoms-join-atoms? potential suffix) ║ (atoms-join-multi? potential suffix) ║ ║
╠══════════════════════════════════════════════════════╬═════════════════════════════════════════════════════════════╬════════════════════════════════════════════════╣ ║
║ (list-rest (gen-node (? multi?) _ _ _ _) _) ║ (multi-joins-atoms? (first potential) suffix) ║ (multi-joins-multi? (first potential) suffix) ║ ║
╠══════════════════════════════════════════════════════╬═════════════════════════════════════════════════════════════╩════════════════════════════════════════════════╝ ║
║ _ ║ #f ║
╚══════════════════════════════════════════════════════╩═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝)
(define (next-completed completed potential current-gen node expl fresh-multi-id fresh-dummy-id lvl)
(define (eq-any? e0 e1 . es)
(or (eq? e0 e1)
(ormap (λ (e) (eq? e0 e)) es)))
(append
completed
(cond
[(or
(not potential)
(eq-any? expl 'extended 'retained)) empty]
[(and
(eq-any? expl 'replaced-by-node 'reset)
(strung-together? potential current-gen)) ; length is that associated with potential + length of current-gen
(car (group-sequential-generations (append potential current-gen) fresh-multi-id fresh-dummy-id lvl))]
[(eq-any? expl 'replaced-by-node 'reset 'replaced-by-current-gen 'replaced-by-cgn) ; length is that associated with potential
potential])
(if
(and
(not (null? current-gen)) ; so (first current-gen) is safe after this
(and
(or ; can't append new node to current-gen
(not
(equal?
(gen-node-range (first current-gen))
(gen-node-range node)))
(and
(equal?
(gen-node-range (first current-gen))
(gen-node-range node))
(not
(gen-node-foldable? node))))
(not ; can't shift current-gen to become next potential
(and
(subsequent-gens?
(gen-node-range (first current-gen))
(gen-node-range node))
(gen-node-foldable? node)
(abstract-atom?
(gen-node-conjunct node))))
(not ; can't subsume in any way: we know current-gen is not null so it must be part of group
(can-group?
potential
current-gen
node))))
current-gen
empty)
;; not the same as "can-be-in-current-gen?" because that includes multi
(if (or (equal? (gen-node-range node) (gen 0 #f))
(not (gen-node-foldable? node)))
(list node)
empty)))
(define (group-conjuncts node acc)
(match-let* ([(and (grouping completed potential current-gen fresh-multi-id fresh-dummy-id lvl) acc-grouping) acc]
[(cons next-potential-value next-potential-explanation)
(next-potential potential current-gen node fresh-multi-id fresh-dummy-id lvl)])
(struct-copy
grouping
acc-grouping
[completed (next-completed completed potential current-gen node next-potential-explanation fresh-multi-id fresh-dummy-id lvl)]
[potential next-potential-value]
[current-gen (next-current-gen current-gen node)]
[next-multi-id (next-multi-id potential current-gen node fresh-multi-id)]
[dummy-id (next-dummy-id potential current-gen node fresh-dummy-id)])))
(define (generalize-level lvl)
(define multis (filter multi? (map gen-node-conjunct lvl)))
(define multivars
(apply append (map extract-subscripted-variables multis)))
(define next-multi-id
(if (not (null? multivars))
(add1 (apply max (map abstract-variable*-multi-id multivars)))
1))
(define dummy-id (add1 (apply max (map gen-node-id lvl))))
(finalize ; move stragglers to completed
(foldl
group-conjuncts
(grouping (list) #f (list) next-multi-id dummy-id lvl)
(sort lvl < #:key gen-node-id))))
(module+ test
(require rackunit)
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'collect (list (g 1) (a 1))) 2 (gen 3 1) #f #t)
(gen-node (abstract-atom 'collect (list (g 2) (a 2))) 3 (gen 3 1) #f #t)
(gen-node (abstract-atom 'append (list (a 1) (a 2) (a 3))) 4 (gen 3 1) #f #t)
(gen-node (abstract-atom 'collect (list (g 4) (a 4))) 5 (gen 2 1) #f #t)
(gen-node (abstract-atom 'append (list (a 3) (a 4) (a 5))) 6 (gen 2 1) #f #t)
(gen-node (abstract-atom 'collect (list (g 6) (a 6))) 7 (gen 1 1) #f #t)
(gen-node (abstract-atom 'append (list (a 5) (a 6) (a 7))) 8 (gen 1 1) #f #t)
(gen-node (abstract-atom 'collect (list (g 8) (a 8))) 9 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'eq (list (a 7) (a 8))) 10 (gen 0 #f) #f #t))))
(list
(abstract-atom 'collect (list (g 1) (a 1)))
(abstract-atom 'collect (list (g 2) (a 2)))
(abstract-atom 'append (list (a 1) (a 2) (a 3)))
(multi
(list
(abstract-atom* 'collect (list (g* 1 'i 4) (a* 1 'i 4)))
(abstract-atom* 'append (list (a* 1 'i 3) (a* 1 'i 4) (a* 1 'i 5))))
#f
(init
(list (cons (a* 1 1 3) (a 3))))
(consecutive
(list (cons (a* 1 'i+1 3) (a* 1 'i 5))))
(final
(list (cons (a* 1 'L 5) (a 7))))
1)
(abstract-atom 'collect (list (g 8) (a 8)))
(abstract-atom 'eq (list (a 7) (a 8)))))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'integers (list (g 1) (a 1))) 2 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'filter (list (g 2) (a 1) (a 2))) 3 (gen 1 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 3) (a 2) (a 3))) 4 (gen 2 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 4) (abstract-function 'cons (list (g 5) (a 3) (a 4))) (a 5))) 5 (gen 3 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 6) (a 5) (a 6))) 6 (gen 4 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 7) (a 6) (a 7))) 7 (gen 5 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 8) (a 7) (a 8))) 8 (gen 6 1) #f #t)
(gen-node (abstract-atom 'sift (list (a 8) (a 9))) 9 (gen 6 1) #f #t)
(gen-node (abstract-atom 'len (list (a 9) (g 9))) 10 (gen 0 #f) #f #t))))
(list
(abstract-atom 'integers (list (g 1) (a 1)))
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 2) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (a 1))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 3))))
1)
(abstract-atom 'filter (list (g 4) (abstract-function 'cons (list (g 5) (a 3) (a 4))) (a 5)))
(multi
(list (abstract-atom* 'filter (list (g* 2 'i 6) (a* 2 'i 5) (a* 2 'i 6))))
#t
(init
(list
(cons (a* 2 1 5) (a 5))))
(consecutive
(list
(cons (a* 2 'i+1 5) (a* 2 'i 6))))
(final
(list
(cons (a* 2 'L 6) (a 7))))
1)
(abstract-atom 'filter (list (g 8) (a 7) (a 8)))
(abstract-atom 'sift (list (a 8) (a 9)))
(abstract-atom 'len (list (a 9) (g 9)))))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'integers (list (g 1) (a 1))) 2 (gen 0 #f) #f #t)
(gen-node
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (a 1))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 4))))
1)
3
(gen-range 1 3 1 #t)
#f
#t)
(gen-node (abstract-atom 'filter (list (g 4) (a 4) (a 5))) 4 (gen 4 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 10) (abstract-function 'cons (list (g 5) (a 5))) (a 6))) 5 (gen 5 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 6) (a 6) (a 7))) 6 (gen 6 1) #f #t)
(gen-node (abstract-atom 'sift (list (a 7) (a 8))) 7 (gen 6 1) #f #t)
(gen-node (abstract-atom 'len (list (a 8) (g 7))) 8 (gen 0 #f) #f #t))))
(list
(abstract-atom 'integers (list (g 1) (a 1)))
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (a 1))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 5))))
1)
(abstract-atom 'filter (list (g 10) (abstract-function 'cons (list (g 5) (a 5))) (a 6)))
(abstract-atom 'filter (list (g 6) (a 6) (a 7)))
(abstract-atom 'sift (list (a 7) (a 8)))
(abstract-atom 'len (list (a 8) (g 7)))))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'integers (list (g 1) (a 1))) 2 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'filter (list (g 2) (a 1) (a 2))) 3 (gen 1 1) #f #t)
(gen-node
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (abstract-function 'cons (list (g 3) (a 2))))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 3))))
1)
3
(gen-range 2 'n 1 #t)
#f
#t)
(gen-node (abstract-atom 'filter (list (g 4) (a 3) (a 4))) 4 (gen (symsum 'n 1) 1) #f #t)
(gen-node (abstract-atom 'sift (list (a 4) (a 5))) 5 (gen (symsum 'n 1) 1) #f #t)
(gen-node (abstract-atom 'len (list (a 5) (g 6))) 6 (gen 0 #f) #f #t))))
(list
(abstract-atom 'integers (list (g 1) (a 1)))
(abstract-atom 'filter (list (g 2) (a 1) (a 2)))
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (abstract-function 'cons (list (g 3) (a 2))))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 3))))
1)
(abstract-atom 'filter (list (g 4) (a 3) (a 4)))
(abstract-atom 'sift (list (a 4) (a 5)))
(abstract-atom 'len (list (a 5) (g 6)))))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'collect (list (g 1) (a 1))) 2 (gen 5 1) #f #t)
(gen-node (abstract-atom 'collect (list (g 2) (a 2))) 3 (gen 5 1) #f #t)
(gen-node (abstract-atom 'append (list (a 1) (a 2) (a 3))) 4 (gen 5 1) #f #t)
(gen-node (abstract-atom 'collect (list (g 4) (a 4))) 5 (gen 4 1) #f #t)
(gen-node (abstract-atom 'append (list (a 3) (a 4) (a 5))) 6 (gen 4 1) #f #t)
(gen-node
(multi
(list
(abstract-atom* 'collect (list (g* 1 'i 1) (a* 1 'i 1)))
(abstract-atom* 'append (list (a* 1 'i 2) (a* 1 'i 1) (a* 1 'i 3))))
#f
(init
(list
(cons (a* 1 1 2) (a 5))))
(consecutive
(list (cons (a* 1 'i+1 2) (a* 1 'i 3))))
(final
(list
(cons (a* 1 'L 3) (a 10))))
1)
7
(gen-range 3 1 1 #f)
#f
#t)
(gen-node (abstract-atom 'collect (list (g 11) (a 11))) 8 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'eq (list (a 10) (a 11))) 9 (gen 0 #f) #f #t))))
(list
(abstract-atom 'collect (list (g 1) (a 1)))
(abstract-atom 'collect (list (g 2) (a 2)))
(abstract-atom 'append (list (a 1) (a 2) (a 3)))
(multi
(list
(abstract-atom* 'collect (list (g* 1 'i 1) (a* 1 'i 1)))
(abstract-atom* 'append (list (a* 1 'i 2) (a* 1 'i 1) (a* 1 'i 3))))
#f
(init
(list
(cons (a* 1 1 2) (a 3))))
(consecutive
(list (cons (a* 1 'i+1 2) (a* 1 'i 3))))
(final
(list
(cons (a* 1 'L 3) (a 10))))
1)
(abstract-atom 'collect (list (g 11) (a 11)))
(abstract-atom 'eq (list (a 10) (a 11)))))
(let ([node1 (gen-node (abstract-atom 'allsafe (list (g 1) (g 2) (g 3) (abstract-function 'cons (list (g 4) (a 1))))) 2 (gen 1 1) #f #f)]
[node2
(gen-node
(multi
(list
(abstract-atom* 'allsafe (list (g* 1 'i 1) (g* 1 'i 2) (g* 1 'i 3) (abstract-function* 'cons (list (g* 1 'i 4) (a* 1 'i 1))))))
#t
(init (list (cons (g* 1 1 4) (g 4))))
(consecutive
(list
(cons (g* 1 'i+1 4) (g* 1 'i 4))
(cons (a* 1 'i+1 1) (a* 1 'i 1))))
(final (list))
1)
3
(gen-range 2 5 1 #t)
#f
#f)])
(check-equal?
(generalize-level (list node1 node2))
(list node1 node2)))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'integers (list (g 1) (a 1))) 2 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'filter (list (g 2) (a 1) (a 2))) 3 (gen 1 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 3) (a 2) (a 3))) 4 (gen 2 1) #f #t)
(gen-node
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (a 3))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 4))))
1)
5
(gen-range 3 'n 1 #t)
#f
#t)
(gen-node (abstract-atom 'filter (list (g 4) (a 4) (a 5))) 6 (gen (symsum 'n 1) 1) #f #t)
(gen-node (abstract-atom 'sift (list (a 5) (a 6))) 7 (gen (symsum 'n 1) 1) #f #t)
(gen-node (abstract-atom 'len (list (a 6) (g 5))) 8 (gen 0 #f) #f #t))))
(list
(abstract-atom 'integers (list (g 1) (a 1)))
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (a 1))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 4))))
1)
(abstract-atom 'filter (list (g 4) (a 4) (a 5)))
(abstract-atom 'sift (list (a 5) (a 6)))
(abstract-atom 'len (list (a 6) (g 5)))))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'integers (list (g 1) (a 1))) 2 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'filter (list (g 2) (a 1) (a 2))) 3 (gen 1 1) #f #t)
(gen-node (abstract-atom 'filter (list (g 3) (a 2) (a 3))) 4 (gen 2 1) #f #t)
(gen-node
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (abstract-function 'cons (list (g 4) (a 3))))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 4))))
1)
5
(gen-range 3 'n 1 #t)
#f
#t)
(gen-node (abstract-atom 'filter (list (g 5) (a 4) (a 5))) 6 (gen (symsum 'n 1) 1) #f #t)
(gen-node (abstract-atom 'sift (list (a 5) (a 6))) 7 (gen (symsum 'n 1) 1) #f #t)
(gen-node (abstract-atom 'len (list (a 6) (g 6))) 8 (gen 0 #f) #f #t))))
(list
(abstract-atom 'integers (list (g 1) (a 1)))
(multi
(list (abstract-atom* 'filter (list (g* 2 'i 2) (a* 2 'i 1) (a* 2 'i 2))))
#t
(init
(list
(cons (a* 2 1 1) (a 1))))
(consecutive
(list
(cons (a* 2 'i+1 1) (a* 2 'i 2))))
(final
(list
(cons (a* 2 'L 2) (a 3))))
1)
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init
(list
(cons (a* 1 1 1) (abstract-function 'cons (list (g 4) (a 3))))))
(consecutive
(list
(cons (a* 1 'i+1 1) (a* 1 'i 2))))
(final
(list
(cons (a* 1 'L 2) (a 4))))
1)
(abstract-atom 'filter (list (g 5) (a 4) (a 5)))
(abstract-atom 'sift (list (a 5) (a 6)))
(abstract-atom 'len (list (a 6) (g 6)))))
(check-equal?
(map
gen-node-conjunct
(generalize-level
(list
(gen-node (abstract-atom 'integers (list (g 1) (a 1))) 2 (gen 0 #f) #f #t)
(gen-node (abstract-atom 'filter (list (g 2) (a 1) (a 2))) 3 (gen 1 1) #f #t)
(gen-node
(multi
(list (abstract-atom* 'filter (list (g* 1 'i 1) (a* 1 'i 1) (a* 1 'i 2))))
#t
(init