-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslowsearch.txt
More file actions
1262 lines (1207 loc) · 44.4 KB
/
Copy pathslowsearch.txt
File metadata and controls
1262 lines (1207 loc) · 44.4 KB
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
##################################################################
##slowsearch.txt: This file is made to accompany Chapters 6 & 9 #
##of Nathan Fox's doctoral thesis #
## #
##Save this file as slowsearch.txt #
##To use it, stay in the #
##same directory, start Maple (by typing: maple <Enter> ) #
##and then type: read slowsearch.txt <Enter> #
## #
##This file depends on mapledoc.txt and nicehof.txt, which can #
##be found in the same online directory as this file #
## #
##Written by Nathan Fox, Rutgers University, #
##fox at math dot rutgers dot edu #
##Version 1.0.0 #
##################################################################
read(`nicehof.txt`):
with(NiceHof):
#mapledoc
Input:=':-Input':
Output:=':-Output':
Note:=':-Note':
__doc:=DocManager():
printf("%s\n\n%s\n\n%s@math.rutgers.edu\n\n%s\n\n%s\n%s\n%s\n%s\n%s\n",
"This is slowsearch.txt",
"It accompanies Chapters 6 and 9 of \"An Exploration of Nested Recurrences Using Experimental Mathematics\" by Nathan Fox",
"Please report bugs to fox",
"The most current version of this package is available from",
"http://github.com/nhf216/thesis/slowsearch.txt",
"For a list of the procedures in this package, along with their usage, type HelpSlow();.",
"For help with a specific procedure, type HelpSlow(procedure_name);.",
"For a brief description of a specific procedure, type Describe(procedure_name);.",
"For a description of what the coding scheme for recurrences means, type HelpSlow(CODE)."):
#Help_tanny:=proc()
# print(`FindSlowSeqs(strt::Or(integer, list):=0, stp::Or(integer, list):=infinity, {fil:=terminal, gammax::extended_numeric:=infinity, inclConway::boolean:=true, inclHof::boolean:=true, inclNonhomog::boolean:=true, maxk::extended_numeric:=infinity, mink::integer:=1, n::symbol:=':-n', perreps::integer:=10, Q::symbol:=':-Q', reportLevel::integer:=INTERESTING, sample::boolean:=true, store::boolean:=true, terms_factor::integer:=41, tune::integer:=3/4, useFirst::boolean:=false, verbose::boolean:=true})`):
#end:
#Partitons of n into exactly k parts with max part <= m
PartsExactly:=proc(n, k, m:=infinity) local ret, i, tm, tp:
ret:=[]:
if k = 0 and n = 0 then
return [[]]:
elif k = 0 or n = 0 then
return ret:
else
#Pick largest part
for i from 1 to min(n-k+1, m) do
tm:=PartsExactly(n-i, k-1, i):
for tp in tm do
ret:=[op(ret), [op(tp), i]]:
od:
od:
fi:
return ret:
end:
#Partitions of n with at LEAST k parts and max part m
Parts:=proc(n, k, m:=infinity) local ret, i, tm, tp:
ret:=[]:
if n = 0 and k <= 0 then
return [[]]:
elif n <= 0 or m = 0 then
return ret:
else
#Pick largest part
for i from 1 to min(m, n-k+1) do
tm:=Parts(n-i, k-1, i):
for tp in tm do
ret:=[op(ret), [op(tp), i]]:
od:
od:
fi:
return ret:
end:
#Slow partitions of n with at LEAST k parts and max part m
SlowParts:=proc(n, k, m:=infinity) local ret, i, tm, tp:
ret:=[]:
if n = 0 and m = 0 and k <= 0 then
return [[]]:
elif n <= 0 or m = 0 then
return ret:
else
#Pick largest part
if m = infinity then
for i from 1 to floor((-1+sqrt(8*n+1))/2) do
ret:=[op(ret), op(SlowParts(n, k, i))]:
od:
else
tm:=SlowParts(n-m, k-1, m):
for tp in tm do
ret:=[op(ret), [op(tp), m]]:
od:
tm:=SlowParts(n-m, k-1, m-1):
for tp in tm do
ret:=[op(ret), [op(tp), m]]:
od:
fi:
fi:
return ret:
end:
#Slow ICs of length k
#min term is m
SlowICs:=proc(k, m:=1) local ret, tm, tp:
ret:=[]:
if k = 0 then
return []:
elif k = 1 then
return [[m]]:
else
tm:=SlowICs(k-1, m):
for tp in tm do
ret:=[op(ret), [m, op(tp)]]:
od:
tm:=SlowICs(k-1, m+1):
for tp in tm do
ret:=[op(ret), [m, op(tp)]]:
od:
fi:
return ret:
end:
#Ordered partitions of n into exactly k parts with zeroes allowed
#m=cap on parts
#mn=min part
OrdPartsInclZeroes:=proc(n, k, m:=infinity, mn:=0) local ret, i, tm, tp:
ret:=[]:
if n = k*mn then
return [[mn$k]]:
elif n < k*mn or k = 0 then
return ret:
else
#Pick a part
for i from max(mn,0) to min(m, n) do
tm:=OrdPartsInclZeroes(n-i, k-1, m, mn):
for tp in tm do
ret:=[op(ret), [op(tp), i]]:
od:
od:
fi:
return ret:
end:
#Ordered partitions of n into exactly k parts with parts
#from set
OrdPartsSet:=proc(n, k, S, reqs::list:=[])
local ret, i, tm, tp, req, newreqs, nrs, j, ok:
ret:=[]:
if n = 0 and k = 0 then
#Make sure we're allowed to have 0 of each part
for req in reqs do
if not(0 in req[2]) then
return ret:
fi:
od:
return [[]]:
elif n < k*min(S) or k = 0 then
return ret:
else
#Pick a part
for i in S do
ok:=true:
newreqs:=[]:
for req in reqs do
if i in req[1] then
nrs:={}:
for j in req[2] do
if j > 0 then
nrs:=nrs union {j-1}:
fi:
od:
if nrs = {} then
ok:=false:
break:
fi:
newreqs:=[op(newreqs), [req[1], nrs]]:
else
newreqs:=[op(newreqs), req]:
fi:
od:
if ok then
tm:=OrdPartsSet(n-i, k-1, S, newreqs):
for tp in tm do
ret:=[op(ret), [op(tp), i]]:
od:
fi:
od:
fi:
return ret:
end:
#gamams are already in increasing order
#Check if betas are in increasing order among gammas that are equal
CheckBG:=proc(betas, gammas) local i, j, G, lasti, gval:
lasti:=1:
gval:=gammas[1]:
G:=[op(gammas), infinity]:
for i from 2 to nops(G) do
if G[i] <> gval then
for j from lasti+1 to i-1 do
if betas[j] < betas[j-1] then
return false:
fi:
od:
lasti:=i:
gval:=G[i]:
fi:
od:
return true:
end:
#Is the sequence slow?
IsSlow:=proc(L, verbose:=false) local i:
for i from 2 to nops(L) do
if not(L[i] - L[i-1] in {0,1}) then
if verbose then
return false, [i-1, i], [L[i-1], L[i]]:
else
return false:
fi:
fi:
od:
return true:
end:
#Parameters: k, beta_i, gamma_i (i from 1 to k), delta
#Need gamma_i positive, beta_i nonnegative, delta nonnegative
#ICs should be slow sequences of length at least max of gammas (if included)
#Terms can be Conway or regular
#Order by sum of parameters
TermsWithSum:=proc(sm::integer, {gammax::extended_numerc:=infinity, includeIC::boolean:=true, includeCN::boolean:=true, nonhomog::boolean:=true, maxk::extended_numeric:=infinity, mink::integer:=1})
local ret, k, gsum, gammas, betas, delta, mdelta, icsum, ic, icn, mc,mn, mcsum, csum, conway, nonho:
ret:=[]:
if includeIC then
icn:=3:
else
icn:=2:
fi:
if includeCN then
mc:=2:
mn:=1:
else
mc:=0:
mn:=0:
fi:
#Choose k
for k from mink to min(sm/icn, maxk) do
#Choose gamma values
#Iterate through all partitions of
#numbers <=sm-k with k parts
for gsum from k to sm-(icn-1)*k do
#print(k, gsum):
for gammas in PartsExactly(gsum, k, gammax) do
#print(gammas):
#Choose delta values
if nonhomog then
mdelta:=sm-gsum-(icn-1)*k:
else
mdelta:=0:
fi:
for delta from 0 to mdelta do
#Choose conway values
if includeCN then
mcsum:=min(sm-gsum-(icn-1)*k-delta, 2*k):
else
mcsum:=0:
fi:
for csum from 0 to mcsum do
for conway in OrdPartsInclZeroes(csum, k, mc) do
#Choose nh bit
for nonho from 0 to mn do
#Do IC, if necessary
if includeIC then
for icsum from max(gammas) to sm-gsum-k-delta-csum-nonho do
for ic in SlowParts(icsum, max(gammas)) do
#Choose betas
for betas in OrdPartsInclZeroes(sm-gsum-k-delta-icsum-csum-nonho, k) do
if CheckBG(betas, gammas) then
ret:=[op(ret), [k, betas, gammas, delta, conway, nonho, ic]]:
fi:
od:
od:
od:
else
#Choose beta values
#Iterate through all ordered partitions of
#sm-gsum-k-delta with k parts
#BUT, parts where gammas are equal should
#be in increasing order
for betas in OrdPartsInclZeroes(sm-gsum-k-delta-csum-nonho, k) do
if CheckBG(betas, gammas) then
ret:=[op(ret), [k, betas, gammas, delta, conway, nonho]]:
fi:
od:
fi:
od:
od:
od:
od:
od:
od:
od:
return ret:
end:
#Make sure L isn't eventually constant or linear
IsInteresting:=proc(L, nonic:=100, tune:=3/4, perreps:=10)
local LD, i, j, k, pn, ok:
#Difference Sequence
LD:=[seq(L[i]-L[i-1], i=2..nops(L))][floor(-nonic*tune)..-1]:
for i from 1 to floor(nops(LD)/perreps) do
ok:=false:
for j from 1 to i do
pn:=LD[j]:
for k from j+i by i to nops(LD) do
if LD[k] <> pn then
ok:=true:
break:
fi:
od:
if ok then
break:
fi:
od:
if not(ok) then
return false:
fi:
od:
return true:
end:
#Which ones are slow?
Slows:=proc(sm::integer, {Q::symbol:=':-Q', n::symbol:=':-n', gammax::extended_numeric:=infinity, inclConsts::boolean:=true, inclConway::boolean:=false, inclForbs::boolean:=false, includeIC::boolean:=false, includeCN::boolean:=false, nonhomog::boolean:=true, maxk::extended_numeric:=infinity, mink::integer:=1, maxones::integer:=1, report::boolean:=true, sample::boolean:=false, terms::integer:=100, verbose::boolean:=false})
local params, prm, ret, k, betas, gammas, delta, mg, i, conseq, conmax, rec, sq, ones, mo, stret, ic, forbs, TestIC, BuildRec:
BuildRec:=proc()
if conseq[-1] = 0 then
rec:=delta:
else
rec:=-delta-1:
fi:
for i from 1 to k do
if conseq[i] = 0 then
rec:=rec + Q[n-betas[i]-Q[n-gammas[i]]]:
elif conseq[i] = 1 then
rec:=rec + Q[Q[n-gammas[i]]-betas[i]]:
elif conseq[i] = 2 then
rec:=rec + Q[Q[n-gammas[i]]+betas[i]+1]:
fi:
od:
#recs:=[op(recs), rec]:
#Run the tests
forbs:={}:
if includeIC then
TestIC(ic):
else
for ones from 0 to mo do
for ic in SlowICs(mg+ones) do
#print(ic):
if inclForbs or not(ic in forbs) then
TestIC(ic):
fi:
#print(forbs, conseq):
od:
od:
fi:
end:
TestIC:=proc(ic) local ones:
if inclConway or not(ic in forbs) then
sq:=SeqQg(terms+nops(ic), ':-ic'=ic, ':-rec'=rec, ':-nodeath'=true):
stret:=rec, ic, sq:
if nops(sq) < terms+nops(ic) then
if verbose then
print("Died", stret):
fi:
elif nops(sq) = terms+nops(ic) and IsSlow(sq) then
if sq[-1] <> ic[-1] or inclConsts then
if report then
print("Slow", stret):
fi:
if sample then
ret:=[op(ret), [rec, ic, sq]]:
else
ret:=[op(ret), [rec, ic]]:
fi:
if conseq[..k] = [1$k] and not(includeIC) and not(inclForbs) and sq[-1] <> 1 then
for i from 2 to nops(sq) do
if sq[i] = 1 then
forbs:=forbs union {sq[i..i+nops(ic)-1]}:
else
break:
fi:
od:
fi:
else
if verbose then
print("Constant", stret):
fi:
fi:
else
if verbose then
print("Not Slow", stret):
fi:
fi:
#print(rec, sprintf("length %d", mg+ones), sq):
fi:
end:
ret:=[]:
params:=TermsWithSum(sm, ':-includeIC'=includeIC, ':-includeCN'=includeCN, ':-nonhomog'=nonhomog, ':-maxk'=maxk, ':-mink'=mink):
for prm in params do
#print(prm):
k:=prm[1]:
betas:=prm[2]:
gammas:=prm[3]:
delta:=prm[4]:
conseq:=[op(prm[5]), prm[6]]:
if includeIC then
ic:=prm[7]:
fi:
mg:=max(gammas):
if includeCN then
BuildRec():
else
#recs:=[]:
conseq:=[0$k,0]:
if inclConway then
conmax:=2:
mo:=maxones:
else
conmax:=0:
mo:=0:
fi:
while true do
BuildRec():
if conseq[-1] = 0 and nonhomog then
conseq[-1]:=1:
else
conseq[-1]:=0:
for i from k by -1 to 1 do
if conseq[i] = conmax then
conseq[i]:=0:
else
conseq[i]:=conseq[i]+1:
break:
fi:
od:
fi:
if conseq = [0$k,0] then
break:
fi:
od:
fi:
#if nonhomog then
# recs:=[op(recs), seq(recs[i]-2*delta-1, i=1..nops(recs))]:
#fi:
#print(prm, recs):
#for rec in recs do
# forbs:={}:
# if includeIC then
# TestIC(ic):
# else
# for ones from 0 to mo do
# for ic in SlowICs(mg+ones) do
# #print(ic):
# TestIC(ic):
# od:
# od:
# fi:
#od:
od:
return ret:
end:
#register(__doc, "NiceWrite(L, [hdr])",
# Input::"L: A code, as described by HelpSlow(CODE)",
# Input::"hdr: TODO",
# Output::"A human-readable form of the recurrence and ",
# "possible initial condition coded by L",
# Example::["TODO", "returns TODO"]
#):
NiceWrite:=proc(L, hdr:="") local ret, i:
ret:=hdr:
if hdr <> "" then
ret:=cat(ret, "\n", seq("_", i=1..length(hdr)), "\n\n"):
fi:
for i in L do
ret:=cat(ret, sprintf("REC: %a\nIC: %a", i[1], i[2])):
if nops(i) = 3 then
ret:=cat(ret, sprintf("\nSEQ: %a", i[3])):
fi:
ret:=cat(ret, "\n\n"):
od:
return ret:
end:
#Report levels
DEF_REP_LEVEL:=0:
ALL:=7:
ALIVE:=8:
INCREASING:=9:
INCREASING_AND_INTERESTING:=10:
SLOW:=11:
SLOW_AND_INTERESTING:=12:
#CODE: [3, [0,1,2], [1,2,3], 0, [0,0,0], 0, [1,1,2]] should work
#Tanny footnote 11, page 5
#Cool:
#CODE: [3, [0, 0, 0], [1, 2, 3], 0, [0, 0, 0], 0, [1, 1, 2, 3, 4, 5]]
#REC: Q[n-Q[n-1]]+Q[n-Q[n-2]]+Q[n-Q[n-3]]
#IC: [1, 1, 2, 3, 4, 5]
#Culmination of everything
#Requires ic inclusion
register(__doc, "FindSlowSeqs([strt, stp], {allowNonSlow, allowNonSlowIC, betamax, fil, force_k, force_betas, force_gammas, force_delta, force_conway, force_nonho, force_ic:, force_rec, gammax, inclConway, inclFutCon, inclFutHof, inclHof, inclNonhomog, maxCons, minCons, maxk, mink, n, perreps, Q, reportLevel, sample, silent, store, terms_factor, tune, useFirst, verbose})",
Input::"strt: an integer or list indicating where to start ",
"the search for slow sequences. The integer denotes a ",
"total weight of an exhaustive code for Hofstadter-like ",
"sequences. The list is a starting code itself. ",
"(default is 0)",
Input::"stp: an integer or list indicating where to stop ",
"the search for slow sequences. The integer denotes a ",
"total weight of an exhaustive code for Hofstadter-like ",
"sequences. The list is an ending code itself. ",
"(default is infinity, meaning run forever)",
Input::"allowNonSlow: still report about a sequence, ",
"even if it is not slow? (default is false)",
Input::"allowNonSlowIC: consider non-slow initial ",
"conditions? (default is false)",
Input::"betamax: an integer denoting the largest value ",
" for betas in the general forms of expressions ",
"(see HelpSlow(CODE)) (default is infinity)",
Input::"fil: file name or descriptor for where results ",
"are to be output (default is terminal)",
Input::"force_k: force a specific value of k? (see ",
"HelpSlow(CODE)) (default is NULL, meaning don't force)",
Input::"force_betas: force a specific list of beta values? (see ",
"HelpSlow(CODE)) (default is NULL, meaning don't force)",
Input::"force_gammas: force a specific list of gamma values? (see ",
"HelpSlow(CODE)) (default is NULL, meaning don't force)",
Input::"force_delta: force a specific delta value? (see ",
"HelpSlow(CODE)) (default is NULL, meaning don't force)",
Input::"force_conway: force a specific format (a list) for ",
"which terms are Conway-like? (see ",
"HelpSlow(CODE)) (default is NULL, meaning don't force)",
Input::"force_nonho: force nonhomogeneous terms to be nonnegative? (see ",
"HelpSlow(CODE)) (default is NULL, which is equivalent to 0)",
Input::"force_ic: force a specific initial condition list? (see ",
"HelpSlow(CODE)) (default is NULL, meaning don't force)",
Input::"force_rec: force a specific recurrence? ",
"(format described by nicehof.txt) ",
"(default is NULL, meaning don't force). This overrides ",
"the preceding \"force\" parameters, other than force_ic.",
Input::"gammax: an integer denoting the largest value ",
" for gammas in the general forms of expressions ",
"(see HelpSlow(CODE)) (default is infinity)",
Input::"inclConway: include Conway-like terms? ",
"(see HelpSlow(CODE)) (default is true)",
Input::"inclFutCon: include Conway-like terms that look into the future? ",
"(see HelpSlow(CODE)) (default is true)",
Input::"inclFutHof: include Hofstadter-like terms that look into the future? ",
"(see HelpSlow(CODE)) (default is true)",
Input::"inclHof: include Hofstadter-like terms? ",
"(see HelpSlow(CODE)) (default is true)",
Input::"inclNonhomog: include non-homogeneous recurrences? ",
"(see HelpSlow(CODE)) (default is true)",
Input::"maxCons: maximum number of Conway-like terms ",
"(see HelpSlow(CODE)) (default is infinity)",
Input::"minCons: minimum number of Conway-like terms ",
"(see HelpSlow(CODE)) (default is 0)",
Input::"maxk: maximum value of k ",
"(see HelpSlow(CODE)) (default is infinity)",
Input::"mink: minimum value of k ",
"(see HelpSlow(CODE)) (default is infinity)",
Input::"n: a symbol to use for the index in ",
"the recurrences (default is n)",
Input::"perreps: an integer technical parameter that ",
"specifies how many terms to generate to check for ",
"slowness/non-constant-ness (default is 10)",
Input::"Q: a symbol to use for the recurrences (default is Q)",
Input::"reportLevel: one of DEF_REP_LEVEL, ALL, ALIVE, ",
"INCREASING, INCREASING_AND_INTERESTING, SLOW, ",
"SLOW_AND_INTERESTING indicating which types of sequences ",
"to output. A sequence is interesting if it is not ",
"eventually constant. (default is DEF_REP_LEVEL, meaning ",
"default level, which is SLOW_AND_INTERESTING or ",
"INCREASING_AND_INTERESTING, depending on whether ",
"allowNonSlow is true or false)",
Input::"sample: include sample terms in the output? ",
"(default is true)",
Input::"silent: should we not actually output the output? ",
"(default is false)",
Input::"store: store the output and also return it in Maple ",
"format? (default is true)",
Input::"terms_factor: how many terms to generate of sequences. ",
"Generate terms_factor*nops(ic) terms. (default is 41)",
Input::"tune: a technical parameter related to checking ",
"whether the sequence is eventually constant (default is 3/4)",
Input::"useFirst: Use strt as first, if it's a list? ",
"Might not want to, as it might be the last one you ",
"already checked. In that case, use its successor first. ",
"(default is false)",
Input::"verbose: should we also output the output to ",
"terminal? Also, should we print some other stuff? ",
"(default is true)",
Output::"All the seemingly slow sequences (or whatever ",
"reporting level was specified) in the search space. ",
"If the search space was infinite, it will run forever. ",
"The output is written to fil, and, if store was true, it ",
"is also returned in Maple format.",
Example::["0, 4, verbose=false", "outputs:\nCODE: [1, [0], [1], 1, [0], 0, [1]]\nREC: 1+Q[n-Q[n-1]]\nIC: [1]\nSEQ: [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]\nSlow and Interesting\nand returns [[[1, [0], [1], 1, [0], 0, [1]], [1+Q[n-Q[n-1]], [1], [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]]]]"],
Example::["5, 8, verbose=false, minCons=1", "outputs three sequences and returns [[[2, [0, 0], [1, 1], 0, [0, 1], 0, [1, 1]], [Q[n-Q[n-1]]+Q[Q[n-1]], [1, 1], [1, 1, 2, 2, 3, 4, 4, 4, 5, 6, 7, 7, 8, 8, 8, 8, 9, 10, 11, 12, 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, 16, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 26, 27, 27, 27, 28, 29, 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 33, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 45, 46, 47]]], [[2, [1, 0], [1, 1], 0, [0, 1], 0, [1, 1]], [Q[n-1-Q[n-1]]+Q[Q[n-1]], [1, 1], [1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 19, 19, 20, 21, 21, 21, 22, 22, 23, 24, 24, 25, 26, 27, 27, 28, 29, 30, 31, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 36]]], [[2, [0, 0], [1, 1], 0, [0, 1], 0, [1, 1, 1]], [Q[n-Q[n-1]]+Q[Q[n-1]], [1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5, 5, 6, 7, 7, 8, 8, 8, 8, 8, 9, 10, 11, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 15, 16, 16, 17, 18, 18, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 22, 23, 24, 25, 25, 26, 27, 27, 28, 28, 28, 29, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 44, 45, 46, 46, 47, 47, 47, 48, 48, 48, 48, 49, 50, 50, 51, 51, 51, 52, 52, 52]]]]"]
#Output::"The first terms terms of the sequence with initial ",
#Example::["5, 20", "returns [4, N, 5, 5, N, 4, 5, 10, 10, N, 4, 10, 15, 5, N, 4, 15, 10, 15, 2*N], {17 <= N}"]
):
FindSlowSeqs:=proc(strt::Or(integer, list):=0, stp::Or(integer, list):=infinity, {allowNonSlow::boolean:=false, allowNonSlowIC::boolean:=false, betamax::extended_numeric:=infinity, fil:=terminal, force_k:=NULL, force_betas:=NULL, force_gammas:=NULL, force_delta:=NULL, force_conway:=NULL, force_nonho:=NULL, force_ic:=NULL, force_rec:=NULL, gammax::extended_numeric:=infinity, inclConway::boolean:=true, inclFutCon::boolean:=true, inclFutHof::boolean:=true, inclHof::boolean:=true, inclNonhomog::boolean:=true, maxCons::extended_numeric:=infinity, minCons::integer:=0, maxk::extended_numeric:=infinity, mink::integer:=1, n::symbol:=':-n', perreps::integer:=10, Q::symbol:=':-Q', reportLevel::integer:=DEF_REP_LEVEL, sample::boolean:=true, silent::boolean:=false, store::boolean:=true, terms_factor::integer:=41, tune:=3/4, useFirst::boolean:=false, verbose::boolean:=true})
description "Look for slow sequences with the given parameters":
local ret, k, betas, gammas, delta, conway, nonho, ic, sm, startsum, specialstart, stopsum, specialstop, rex, rec, over, gsum, csum, icsum, level,
Process_k, Process_betas, Process_gammas, Process_delta, Process_conway, Process_nonho, Process_ic, Process_ic_rec,
Proceed, BuildRec, Test:
#Analyzing Helpers
Test:=proc() local sq, stret, RetVal, terms, died, notincr, notslow, nexterm, rrec:
#Return value
RetVal:=proc(msg) local L, ret:
if sample then
L:=[rec, ic, sq]:
else
L:=[rec, ic]:
fi:
#print(rex):
ret:=sprintf("CODE: %a\n", rex):
ret:=cat(ret, sprintf("REC: %a\nIC: %a", L[1], L[2])):
if sample then
ret:=cat(ret, sprintf("\nSEQ: %a", L[3])):
fi:
ret:=cat(ret, "\n\n"):
if verbose and fil = terminal then
ret:=cat(ret[..-2], msg, "\n\n"):
fi:
if not(silent) then
fprintf(fil, "%s", ret):
fi:
if verbose and fil <> terminal then
printf("%s%s\n\n", ret[..-2], msg):
fi:
return L:
end:
rrec:=CompileRec(rec, ':-Q'=Q, ':-n'=n):
if force_rec = NULL then
terms:=max(nops(ic), max(betas), max(gammas))*terms_factor:
else
terms:=nops(ic)*terms_factor:
fi:
#sq:=SeqQg(terms, ':-ic'=ic, ':-rec'=rec, ':-failure'=true):
sq:=ic:
died:=false:
notincr:=false:
notslow:=false:
while nops(sq) < terms do
nexterm:=Qg(nops(sq)+1, ':-ic'=ic, ':-rec'=rrec, ':-failure'=true):
if nexterm = FAIL then
died:=true:
break:
elif nexterm - sq[-1] < 0 then
notincr:=true:
sq:=[op(sq), nexterm]:
break:
elif not(allowNonSlow) and nexterm - sq[-1] > 1 then
notslow:=true:
sq:=[op(sq), nexterm]:
break:
else
sq:=[op(sq), nexterm]:
fi:
od:
#if nops(sq) < terms then
if died then
if level <= ALL then
return RetVal("Died"):
fi:
#elif nops(sq) = terms and IsSlow(sq) then
elif notincr then
if level <= ALIVE then
return RetVal("Not increasing"):
fi:
elif notslow then
if level <= ALIVE then
return RetVal("Not slow"):
fi:
elif allowNonSlow then
if level <= INCREASING then
return RetVal("Increasing"):
elif level <= INCREASING_AND_INTERESTING then
if IsInteresting(sq, terms-nops(ic), tune, perreps) then
return RetVal("Increasing and Interesting"):
fi:
fi:
else
if level <= SLOW then
return RetVal("Slow"):
elif level <= SLOW_AND_INTERESTING then
if IsInteresting(sq, terms-nops(ic), tune, perreps) then
return RetVal("Slow and Interesting"):
fi:
fi:
#else
# if level <= ALIVE then
# return RetVal():
# fi:
fi:
end:
BuildRec:=proc() local i:
if nonho = 0 then
rec:=delta:
else
rec:=-delta-1:
fi:
for i from 1 to k do
if conway[i] = 0 then
rec:=rec + Q[n-betas[i]-Q[n-gammas[i]]]:
elif conway[i] = 2 then
rec:=rec + Q[n+betas[i]+1-Q[n-gammas[i]]]:
elif conway[i] = 1 then
rec:=rec + Q[Q[n-gammas[i]]-betas[i]]:
elif conway[i] = 3 then
rec:=rec + Q[Q[n-gammas[i]]+betas[i]+1]:
fi:
od:
return Test():
end:
Proceed:=proc(forcerec:=false) local rb:
if forcerec then
rb:=Test():
else
rex:=[k, betas, gammas, delta, conway, nonho, ic]:
rb:=BuildRec():
fi:
#Yay! Side effects!
if store and rb <> NULL then
ret:=[op(ret), [rex, rb]]:
fi:
if specialstop and rex = stp then
over:=true:
return:
fi:
end:
#Building Helpers
Process_betas:=proc() local ok, i:
if force_betas = NULL then
ok:=not(specialstart):
#Do the betas
for betas in OrdPartsInclZeroes(sm-gsum-k-delta-icsum-csum-nonho, k, betamax) do
if not(ok) then
ok:=evalb(betas = strt[2]):
fi:
if ok then
if specialstart and not(useFirst) then
#Skip the first one, since it's presumably the
#last one in our file and we don't want to
#repeat it
specialstart:=false:
else
specialstart:=false:
if CheckBG(betas, [seq([gammas[i], conway[i]], i=1..k)]) then
Proceed():
fi:
fi:
fi:
od:
else
betas:=force_betas:
Proceed():
fi:
end:
Process_ic_rec:=proc() local ok, sicsum, pfn:
if force_ic = NULL then
if specialstart then
ok:=false:
sicsum:=convert(strt[7], `+`):
else
ok:=true:
sicsum:=1:
fi:
if allowNonSlowIC then
pfn:=Parts:
else
pfn:=SlowParts:
fi:
#Build IC
for icsum from sicsum to infinity do
for ic in pfn(icsum, 1) do
if not(ok) then
ok:=evalb(ic = strt[7]):
fi:
if ok then
Proceed(true):
if over then
return:
fi:
fi:
od:
od:
else
ic:=force_ic:
Proceed(true):
fi:
end:
Process_ic:=proc() local ok, sicsum, pfn:
if force_ic = NULL then
if specialstart then
ok:=false:
sicsum:=convert(strt[7], `+`):
else
ok:=true:
sicsum:=k:
fi:
if allowNonSlowIC then
pfn:=Parts:
else
pfn:=SlowParts:
fi:
#Build IC
for icsum from max(gammas) to sm-gsum-k-delta-csum-nonho do
for ic in pfn(icsum, max(gammas)) do
if not(ok) then
ok:=evalb(ic = strt[7]):
fi:
if ok then
Process_betas():
if over then
return:
fi:
fi:
od:
od:
else
ic:=force_ic:
Process_betas():
fi:
end:
Process_nonho:=proc() local sn, mn:
if force_nonho = NULL then
if specialstart then
sn:=strt[6]:
else
sn:=0:
fi:
#Choose nonho values
if inclNonhomog then
mn:=1:
else
mn:=0:
fi:
for nonho from sn to mn do
Process_ic():
if over then
return:
fi:
od:
else
nonho:=force_nonho:
Process_ic():
fi:
end:
Process_conway:=proc() local ok, scsum, mcsum, cset, i, reqs:
if force_conway = NULL then
if specialstart then
ok:=false:
scsum:=convert(strt[5], `+`):
else
ok:=true:
scsum:=0:
fi:
#Choose conway values
cset:={}:
if inclHof then
#minc:=0:
cset:=cset union {0}:
if inclFutHof then
cset:=cset union {2}:
fi:
else
#minc:=1:
scsum:=max(scsum, 2*k):
fi:
if inclConway then
mcsum:=min(sm-gsum-2*k-delta, 2*k):
#mc:=2:
cset:=cset union {1}:
if inclFutCon then
cset:=cset union {3}:
fi:
else
mcsum:=0:
#mc:=0:
fi:
reqs:=[[{1,3}, {seq(i, i=max(0, minCons)..min(k, maxCons))}]]:
for csum from scsum to mcsum do
for conway in OrdPartsSet(csum, k, cset, reqs) do
if not(ok) then
ok:=evalb(conway = strt[5]):
fi:
if ok then
if CheckBG(conway, gammas) then
Process_nonho():
if over then
return:
fi:
fi:
fi:
od:
od:
else
conway:=force_conway:
csum:=convert(conway, `+`):
Process_nonho():
fi:
end:
Process_delta:=proc() local sdelta, mdelta:
if force_delta = NULL then
if specialstart then
sdelta:=strt[4]:
else
sdelta:=0:
fi:
#Choose delta values
if inclNonhomog then
mdelta:=sm-gsum-2*k:
else
mdelta:=0:
fi:
for delta from sdelta to mdelta do
Process_conway():
if over then
return:
fi:
od:
else
delta:=force_delta:
Process_conway():
fi:
end:
Process_gammas:=proc() local ok, sgsum:
if force_gammas = NULL then
if specialstart then
ok:=false:
sgsum:=convert(strt[3], `+`):
else
ok:=true:
sgsum:=k:
fi:
#Choose gamma values
#Iterate through all partitions of
#numbers <=sm-k with k parts
for gsum from sgsum to sm-2*k do
for gammas in PartsExactly(gsum, k, gammax) do
if not(ok) then
ok:=evalb(gammas = strt[3]):
fi:
if ok then
Process_delta():
if over then
return:
fi:
fi:
od:
od:
else
gammas:=force_gammas:
gsum:=convert(force_gammas, `+`):
Process_delta():
fi:
end:
Process_k:=proc() local strtk, endk:
if specialstart then
strtk:=strt[1]:
else
strtk:=mink:
fi: