forked from cbehan/pycftboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.py
More file actions
1917 lines (1661 loc) · 86.3 KB
/
Copy pathbootstrap.py
File metadata and controls
1917 lines (1661 loc) · 86.3 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
#!/usr/bin/env python2
"""
PyCFTBoot is an interface for the numerical bootstrap in arbitrary dimension,
a field that was initiated in 2008 by Rattazzi, Rychkov, Tonni and Vichi in
arXiv:0807.0004. Starting from the analytic structure of conformal blocks, the
code formulates semidefinite programs without any proprietary software. The
actual optimization step must be performed by David Simmons-Duffin's program
SDPB available at https://github.com/davidsd/sdpb.
PyCFTBoot may be used to find bounds on OPE coefficients and allowed regions in
the space of scaling dimensions for various CFT operators. All operators used in
the explicit correlators must be scalars, but they may have different scaling
dimensions and transform in arbitrary representations of a global symmetry.
"""
from __future__ import print_function
import xml.dom.minidom
import numpy.polynomial
import mpmath
import re
import os
# Use regular sympy sparingly because it is slow
# Every time we explicitly use it, we should consider implementing such a line in C++
from symengine import *
from symengine.lib.symengine_wrapper import *
import sympy
if have_mpfr == False:
print("Symengine must be compiled with MPFR support")
quit(1)
cutoff = 0
prec = 660
mpmath.mp.dps = int((3.0 / 10.0) * prec)
rho_cross = 3 - 2 * mpmath.sqrt(2)
r_cross = eval_mpfr(3 - 2 * sqrt(2), prec)
ell = symbols('ell')
delta = symbols('delta')
delta_ext = symbols('delta_ext')
aux = symbols('aux')
def dump_table_contents(block_table, name):
dump_file = open(name, 'w')
dump_file.write("self.dim = " + block_table.dim.__str__() + "\n")
dump_file.write("self.k_max = " + block_table.k_max.__str__() + "\n")
dump_file.write("self.l_max = " + block_table.l_max.__str__() + "\n")
dump_file.write("self.m_max = " + block_table.m_max.__str__() + "\n")
dump_file.write("self.n_max = " + block_table.n_max.__str__() + "\n")
dump_file.write("self.delta_12 = " + block_table.delta_12.__str__() + "\n")
dump_file.write("self.delta_34 = " + block_table.delta_34.__str__() + "\n")
dump_file.write("self.odd_spins = " + block_table.odd_spins.__str__() + "\n")
dump_file.write("self.m_order = " + block_table.m_order.__str__() + "\n")
dump_file.write("self.n_order = " + block_table.n_order.__str__() + "\n")
dump_file.write("self.table = []\n")
for l in range(0, len(block_table.table)):
dump_file.write("derivatives = []\n")
for i in range(0, len(block_table.table[0].vector)):
poly_string = block_table.table[l].vector[i].__str__()
poly_string = re.sub("([0-9]+\.[0-9]+e?-?[0-9]+)", r"eval_mpfr(\1, prec)", poly_string)
dump_file.write("derivatives.append(" + poly_string + ")\n")
dump_file.write("self.table.append(PolynomialVector(derivatives, " + block_table.table[l].label.__str__() + ", " + block_table.table[l].poles.__str__() + "))\n")
dump_file.close()
def unitarity_bound(dim, spin):
if spin == 0:
return sympy.Rational(dim, 2) - 1
else:
return dim + spin - 2
def omit_all(poles, special_poles, var):
expression = 1
for p in poles:
if not p in special_poles:
expression *= (var - p)
return expression
def delta_pole(nu, k, l, series):
if nu % 1 == 0:
nu = int(nu)
if series == 1:
pole = 1 - l - k
elif series == 2:
pole = 1 + nu - k
if nu % 1 == 0:
pole += aux
else:
pole = 1 + l + 2 * nu - k
if nu % 1 == 0:
pole += 2 * aux
if nu % 1 == 0:
return pole
else:
return eval_mpfr(pole, prec)
class LeadingBlockVector:
def __init__(self, dim, l, m_max, n_max, delta_12, delta_34):
self.spin = l
self.m_max = m_max
self.n_max = n_max
self.chunks = []
r = symbols('r')
eta = symbols('eta')
nu = sympy.Rational(dim, 2) - 1
derivative_order = m_max + 2 * n_max
# With only a derivatives, we never need eta derivatives
off_diag_order = derivative_order
if n_max == 0:
off_diag_order = 0
# We cache derivatives as we go
# This is because csympy can only compute them one at a time, but it's faster anyway
old_expression = self.leading_block(nu, r, eta, l, delta_12, delta_34)
for n in range(0, off_diag_order + 1):
chunk = []
for m in range(0, derivative_order - n + 1):
if n == 0 and m == 0:
expression = old_expression
elif m == 0:
old_expression = old_expression.diff(eta)
expression = old_expression
else:
expression = expression.diff(r)
chunk.append(expression.subs({r : r_cross, eta : 1}))
self.chunks.append(DenseMatrix(len(chunk), 1, chunk))
def leading_block(self, nu, r, eta, l, delta_12, delta_34):
if self.n_max == 0:
ret = 1
elif nu == 0:
ret = sympy.chebyshevt(l, eta)
else:
ret = factorial(l) * sympy.gegenbauer(l, nu, eta) / sympy.rf(2 * nu, l)
one = eval_mpfr(1, prec)
two = eval_mpfr(2, prec)
# Time saving special case
if delta_12 == delta_34:
return ((-1) ** l) * ret / (((1 - r ** 2) ** nu) * sqrt((1 + r ** 2) ** 2 - 4 * (r * eta) ** 2))
else:
return ((-1) ** l) * ret / (((1 - r ** 2) ** nu) * ((1 + r ** 2 + 2 * r * eta) ** ((one + delta_12 - delta_34) / two)) * ((1 + r ** 2 - 2 * r * eta) ** ((one - delta_12 + delta_34) / two)))
class MeromorphicBlockVector:
def __init__(self, leading_block):
# A chunk is a set of r derivatives for one eta derivative
# The matrix that should multiply a chunk is just R restricted to the right length
self.chunks = []
for j in range(0, len(leading_block.chunks)):
rows = leading_block.chunks[j].nrows()
self.chunks.append(DenseMatrix(rows, 1, [0] * rows))
for n in range(0, rows):
self.chunks[j].set(n, 0, leading_block.chunks[j].get(n, 0))
class ConformalBlockVector:
def __init__(self, dim, l, delta_12, delta_34, derivative_order, kept_pole_order, s_matrix, leading_block, pol_list, res_list):
self.large_poles = []
self.small_poles = []
self.chunks = []
nu = sympy.Rational(dim, 2) - 1
old_list = MeromorphicBlockVector(leading_block)
for k in range(0, len(pol_list)):
pole = delta_pole(nu, pol_list[k][1], l, pol_list[k][3])
if "subs" in dir(pole):
pole = pole.subs(aux, 0)
if abs(float(res_list[k].chunks[0].get(0, 0))) < cutoff:
self.small_poles.append(pole)
else:
self.large_poles.append(pole)
matrix = []
if self.small_poles != []:
for i in range(0, len(self.large_poles) // 2):
for j in range(0, len(self.large_poles)):
matrix.append(1 / ((cutoff + unitarity_bound(dim, l) - self.large_poles[j]) ** (i + 1)))
for i in range(0, len(self.large_poles) - (len(self.large_poles) // 2)):
for j in range(0, len(self.large_poles)):
matrix.append(1 / (((1 / cutoff) - self.large_poles[j]) ** (i + 1)))
matrix = DenseMatrix(len(self.large_poles), len(self.large_poles), matrix)
matrix = matrix.inv()
for j in range(0, len(leading_block.chunks)):
self.chunks.append(leading_block.chunks[j])
for p in self.large_poles:
self.chunks[j] = self.chunks[j].mul_scalar(delta - p)
for k in range(0, len(pol_list)):
pole = delta_pole(nu, pol_list[k][1], l, pol_list[k][3])
if "subs"in dir(pole):
pole = pole.subs(aux, 0)
if pole in self.large_poles:
for j in range(0, len(self.chunks)):
self.chunks[j] = self.chunks[j].add_matrix(res_list[k].chunks[j].mul_scalar(omit_all(self.large_poles, [pole], delta)))
else:
vector = []
for i in range(0, len(self.large_poles) // 2):
vector.append(1 / ((unitarity_bound(dim, l) - pole) ** (i + 1)))
for i in range(0, len(self.large_poles) - (len(self.large_poles) // 2)):
vector.append(1 / (((1 / cutoff) - pole) ** (i + 1)))
vector = DenseMatrix(len(self.large_poles), 1, vector)
vector = matrix.mul_matrix(vector)
for i in range(0, len(self.large_poles)):
for j in range(0, len(self.chunks)):
self.chunks[j] = self.chunks[j].add_matrix(res_list[k].chunks[j].mul_scalar(vector.get(i, 0) * omit_all(self.large_poles, [self.large_poles[i]], delta)))
for j in range(0, len(self.chunks)):
s_sub = s_matrix.submatrix(0, derivative_order - j, 0, derivative_order - j)
self.chunks[j] = s_sub.mul_matrix(self.chunks[j])
class PolynomialVector:
"""
The main class for vectors on which the functionals being found by SDPB may act.
Attributes
----------
vector: A list of the components, expected to be polynomials in `delta`. The
number of components is dictated by the number of derivatives kept in
the search space.
label: A two element list where the first element is the spin and the second
is a user-defined label for the representation of some global symmetry
(or 0 if none have been set yet).
poles: A list of roots of the common denominator shared by all entries in
`vector`. This allows one to go back to the original rational functions
instead of the more convenient polynomials.
"""
def __init__(self, derivatives, spin_irrep, poles):
if type(spin_irrep) == type(1):
spin_irrep = [spin_irrep, 0]
self.vector = derivatives
self.label = spin_irrep
self.poles = poles
class ConformalBlockTableSeed:
"""
A class which calculates tables of conformal block derivatives from scratch.
Usually, it will not be necessary for the user to call it. Instead,
`ConformalBlockTable` calls it automatically for `m_max = 3` and `n_max = 0`.
For people wanting to call it with different values of `m_max` and `n_max`,
the parameters and attributes are the same as those of `ConformalBlockTable`.
It also supports the `dump` method.
"""
def __init__(self, dim, k_max, l_max, m_max, n_max, delta_12 = 0, delta_34 = 0, odd_spins = False, name = None):
self.dim = dim
self.k_max = k_max
self.l_max = l_max
self.m_max = m_max
self.n_max = n_max
self.delta_12 = delta_12
self.delta_34 = delta_34
self.odd_spins = odd_spins
self.m_order = []
self.n_order = []
self.table = []
if odd_spins:
step = 1
else:
step = 2
if name != None:
dump_file = open(name, 'r')
command = dump_file.read()
exec(command)
return
derivative_order = m_max + 2 * n_max
nu = sympy.Rational(dim, 2) - 1
# The matrix for how derivatives are affected when one multiplies by r
r_powers = []
identity = [0] * ((derivative_order + 1) ** 2)
lower_band = [0] * ((derivative_order + 1) ** 2)
for i in range(0, derivative_order + 1):
identity[i * (derivative_order + 1) + i] = 1
for i in range(1, derivative_order + 1):
lower_band[i * (derivative_order + 1) + i - 1] = i
identity = DenseMatrix(derivative_order + 1, derivative_order + 1, identity)
lower_band = DenseMatrix(derivative_order + 1, derivative_order + 1, lower_band)
r_matrix = identity.mul_scalar(r_cross).add_matrix(lower_band)
r_powers.append(identity)
r_powers.append(r_matrix)
conformal_blocks = []
leading_blocks = []
pol_list = []
res_list = []
pow_list = []
den_list = []
new_res_list = []
old_den_list = []
# Find out which residues we will ever need to include
for l in range(0, l_max + k_max + 1):
lb = LeadingBlockVector(dim, l, m_max, n_max, delta_12, delta_34)
leading_blocks.append(lb)
current_pol_list = []
for k in range(1, k_max + 1):
if l <= l_max:
if self.delta_residue(nu, k, l, delta_12, delta_34, 1) != 0:
current_pol_list.append((k, k, l + k, 1))
if k % 2 == 0:
if self.delta_residue(nu, k // 2, l, delta_12, delta_34, 2) != 0:
current_pol_list.append((k, k // 2, l, 2))
if k <= l:
if self.delta_residue(nu, k, l, delta_12, delta_34, 3) != 0:
current_pol_list.append((k, k, l - k, 3))
if l == 0:
r_powers.append(r_powers[k].mul_matrix(r_powers[1]))
# These are in the format (n, k, l, series)
pol_list.append(current_pol_list)
res_list.append([])
pow_list.append([])
den_list.append([])
new_res_list.append([])
old_den_list.append([])
old_res_list = MeromorphicBlockVector(leading_blocks[0])
# Initialize the residues at the appropriate leading blocks
for l in range(0, l_max + k_max + 1):
for i in range(0, len(pol_list[l])):
l_new = pol_list[l][i][2]
res_list[l].append(MeromorphicBlockVector(leading_blocks[l_new]))
pow_list[l].append(0)
den_list[l].append(1)
new_res_list[l].append(0)
old_den_list[l].append(1)
for k in range(1, k_max + 1):
for l in range(0, l_max + k_max + 1):
for i in range(0, len(res_list[l])):
if pow_list[l][i] >= k_max:
continue
res = self.delta_residue(nu, pol_list[l][i][1], l, delta_12, delta_34, pol_list[l][i][3])
pow_list[l][i] += pol_list[l][i][0]
for j in range(0, len(res_list[l][i].chunks)):
r_sub = r_powers[pol_list[l][i][0]].submatrix(0, derivative_order - j, 0, derivative_order - j)
res_list[l][i].chunks[j] = r_sub.mul_matrix(res_list[l][i].chunks[j]).mul_scalar(res)
for l in range(0, l_max + k_max + 1):
for i in range(0, len(res_list[l])):
if pow_list[l][i] >= k_max:
continue
l_new = pol_list[l][i][2]
new_res_list[l][i] = MeromorphicBlockVector(leading_blocks[l_new])
prod = 1
current_pol_list = []
pole1 = delta_pole(nu, pol_list[l][i][1], l, pol_list[l][i][3]) + pol_list[l][i][0]
if dim % 2 == 0:
for i_new in range(0, len(res_list[l_new])):
pole2 = delta_pole(nu, pol_list[l_new][i_new][1], l_new, pol_list[l_new][i_new][3])
current_pol_list.append(pole2)
prod *= (pole1 - pole2) * old_den_list[l_new][i_new]
den_list[l][i] = prod
for j in range(0, len(new_res_list[l][i].chunks)):
new_res_list[l][i].chunks[j] = new_res_list[l][i].chunks[j].mul_scalar(prod)
for i_new in range(0, len(res_list[l_new])):
pole2 = delta_pole(nu, pol_list[l_new][i_new][1], l_new, pol_list[l_new][i_new][3])
if dim % 2 == 0:
fact = omit_all(current_pol_list, [pole2], pole1)
for i_other in range(0, len(res_list[l_new])):
if i_other != i_new:
fact *= old_den_list[l_new][i_other]
else:
fact = eval_mpfr(1, prec) / eval_mpfr(pole1 - pole2, prec)
for j in range(0, len(old_res_list.chunks)):
for n in range(0, old_res_list.chunks[j].nrows()):
element = res_list[l_new][i_new].chunks[j].get(n, 0)
element = element * fact
element = element.expand()
old_res_list.chunks[j].set(n, 0, element)
new_res_list[l][i].chunks[j] = new_res_list[l][i].chunks[j].add_matrix(old_res_list.chunks[j])
for l in range(0, l_max + k_max + 1):
for i in range(0, len(res_list[l])):
if pow_list[l][i] >= k_max:
continue
if "expand" in dir(den_list[l][i]):
den_list[l][i] = den_list[l][i].expand()
old_den_list[l][i] = den_list[l][i]
for j in range(0, len(res_list[l][i].chunks)):
res_list[l][i].chunks[j] = new_res_list[l][i].chunks[j]
# Divide by the common denominator again
if dim % 2 == 0:
for l in range(0, l_max + k_max + 1):
for i in range(0, len(res_list[l])):
if "expand" in dir(den_list[l][i]):
den_list[l][i] = den_list[l][i].expand()
for j in range(0, len(res_list[l][i].chunks)):
for n in range(0, res_list[l][i].chunks[j].nrows()):
element = res_list[l][i].chunks[j].get(n, 0)
element = element.expand()
element = element / den_list[l][i]
element = element.expand()
element = element.subs(aux, 0)
res_list[l][i].chunks[j].set(n, 0, element)
# Perhaps poorly named, S keeps track of a linear combination of derivatives
# We get this by including the essential singularity, then stripping it off again
s_matrix = DenseMatrix(derivative_order + 1, derivative_order + 1, [0] * ((derivative_order + 1) ** 2))
for i in range(0, derivative_order + 1):
new_element = 1
for j in range(i, -1, -1):
s_matrix.set(i, j, new_element)
new_element *= (j / ((i - j + 1) * r_cross)) * (delta - (i - j))
for l in range(0, l_max + 1, step):
conformal_block = ConformalBlockVector(dim, l, delta_12, delta_34, m_max + 2 * n_max, k_max, s_matrix, leading_blocks[l], pol_list[l], res_list[l])
conformal_blocks.append(conformal_block)
self.table.append(PolynomialVector([], [l, 0], conformal_block.large_poles))
a = symbols('a')
b = symbols('b')
hack = symbols('hack')
old_coeff_grid = []
rules1 = []
rules2 = []
old_expression1 = sqrt(a ** 2 - b) / (hack + sqrt((hack - a) ** 2 - b) + hack * sqrt(hack - a + sqrt((hack - a) ** 2 - b)))
old_expression2 = (hack - sqrt((hack - a) ** 2 - b)) / sqrt(a ** 2 - b)
for n in range(0, m_max + 2 * n_max + 1):
old_coeff_grid.append([0] * (m_max + 2 * n_max + 1))
for n in range(0, n_max + 1):
for m in range(0, 2 * (n_max - n) + m_max + 1):
if n == 0 and m == 0:
expression1 = old_expression1
expression2 = old_expression2
elif m == 0:
old_expression1 = old_expression1.diff(b)
old_expression2 = old_expression2.diff(b)
expression1 = old_expression1
expression2 = old_expression2
else:
expression1 = expression1.diff(a)
expression2 = expression2.diff(a)
rules1.append(expression1.subs({hack : eval_mpfr(2, prec), a : 1, b : 0}))
rules2.append(expression2.subs({hack : eval_mpfr(2, prec), a : 1, b : 0}))
self.m_order.append(m)
self.n_order.append(n)
# If b is always 0, then eta is always 1
if n_max == 0:
_x = symbols('_x')
r = function_symbol('r', a)
g = function_symbol('g', r)
for m in range(0, derivative_order + 1):
if m == 0:
old_expression = g
g = function_symbol('g', _x)
else:
old_expression = old_expression.diff(a)
expression = old_expression
for i in range(1, m + 1):
expression = expression.subs(Derivative(r, [a] * i), rules1[i])
for l in range(0, len(conformal_blocks)):
new_deriv = expression
for i in range(1, m + 1):
new_deriv = new_deriv.subs(Subs(Derivative(g, [_x] * i), [_x], [r]), conformal_blocks[l].chunks[0].get(i, 0))
if m == 0:
new_deriv = conformal_blocks[l].chunks[0].get(0, 0)
self.table[l].vector.append(new_deriv.expand())
# Prevent further execution
n_max = -1
r = function_symbol('r', a, b)
eta = function_symbol('eta', a, b)
old_coeff_grid[0][0] = 1
order = 0
for n in range(0, n_max + 1):
for m in range(0, 2 * (n_max - n) + m_max + 1):
# Hack implementation of the g(r(a, b), eta(a, b)) chain rule
if n == 0 and m == 0:
coeff_grid = self.deepcopy(old_coeff_grid)
elif m == 0:
for i in range(m + n - 1, -1, -1):
for j in range(m + n - i - 1, -1, -1):
coeff = old_coeff_grid[i][j]
if type(coeff) == type(1):
coeff_deriv = 0
else:
coeff_deriv = coeff.diff(b)
old_coeff_grid[i + 1][j] += coeff * r.diff(b)
old_coeff_grid[i][j + 1] += coeff * eta.diff(b)
old_coeff_grid[i][j] = coeff_deriv
coeff_grid = self.deepcopy(old_coeff_grid)
else:
for i in range(m + n - 1, -1, -1):
for j in range(m + n - i - 1, -1, -1):
coeff = coeff_grid[i][j]
if type(coeff) == type(1):
coeff_deriv = 0
else:
coeff_deriv = coeff.diff(a)
coeff_grid[i + 1][j] += coeff * r.diff(a)
coeff_grid[i][j + 1] += coeff * eta.diff(a)
coeff_grid[i][j] = coeff_deriv
# Replace r and eta derivatives with the rules found above
deriv = self.deepcopy(coeff_grid)
for l in range(order, 0, -1):
for i in range(0, m + n + 1):
for j in range(0, m + n - i + 1):
if type(deriv[i][j]) != type(1):
deriv[i][j] = deriv[i][j].subs(Derivative(r, [a] * self.m_order[l] + [b] * self.n_order[l]), rules1[l])
deriv[i][j] = deriv[i][j].subs(Derivative(r, [b] * self.n_order[l] + [a] * self.m_order[l]), rules1[l])
deriv[i][j] = deriv[i][j].subs(Derivative(eta, [a] * self.m_order[l] + [b] * self.n_order[l]), rules2[l])
deriv[i][j] = deriv[i][j].subs(Derivative(eta, [b] * self.n_order[l] + [a] * self.m_order[l]), rules2[l])
# Replace conformal block derivatives similarly for each spin
for l in range(0, len(conformal_blocks)):
new_deriv = 0
for i in range(0, m + n + 1):
for j in range(0, m + n - i + 1):
new_deriv += deriv[i][j] * conformal_blocks[l].chunks[j].get(i, 0)
self.table[l].vector.append(new_deriv.expand())
order += 1
def dump(self, name):
dump_table_contents(self, name)
def deepcopy(self, array):
ret = []
for el in array:
ret.append(list(el))
return ret
def delta_residue(self, nu, k, l, delta_12, delta_34, series):
"""
Returns the residue of a meromorphic global conformal block at a particular
pole in `delta`. These residues were found by Kos, Poland and Simmons-Duffin
in arXiv:1406.4858.
Parameters
----------
nu: `(d - 2) / 2` where d is the spatial dimension. If this number is
not an integer, the residue will always be strictly between 0 and
inf. Otherwise, the code might encounter factors of 0 in the
numerator or denominator. These are replaced by `aux` which is the
fractional part of `nu`.
k: The parameter k indexing the various poles. As described in
arXiv:1406.4858, it may be any positive integer unless `series`
is 3.
l: The spin.
delta_12: The difference between the external scaling dimensions of operator
1 and operator 2.
delta_34: The difference between the external scaling dimensions of operator
3 and operator 4.
series: The parameter i desribing the three types of poles in
arXiv:1406.4858.
"""
zero = 0
two = eval_mpfr(2, prec)
check_numerator = False
# Time saving special case
if series != 2 and k % 2 != 0 and delta_12 == 0 and delta_34 == 0:
return 0
elif nu % 1 == 0:
nu = int(nu)
zero = aux
if series == 1:
ret = - ((k * (-4) ** k) / (factorial(k) ** 2)) * sympy.rf((1 - k + delta_12) / two, k) * sympy.rf((1 - k + delta_34) / two, k)
if l == 0 and nu == 0:
# Take l to 0, then nu
return ret * 2
else:
return ret * (sympy.rf(l + 2 * nu, k) / sympy.rf(l + nu, k))
elif series == 2:
ret = ((k * sympy.rf(nu + 1, k - 1)) / (factorial(k) ** 2))
factors = [l + nu + 1 - delta_12, l + nu + 1 + delta_12, l + nu + 1 - delta_34, l + nu + 1 + delta_34]
if l + nu == k:
ret *= zero / (l + nu + k)
else:
ret *= (l + nu - k) / (l + nu + k)
if k >= l + nu and (l + nu - k) % 2 == 0:
ret *= -4 * sympy.rf(-nu, nu) * factorial(k - nu) / (zero * (sympy.rf((l + nu - k + 1) / 2, k) * sympy.rf((l + nu - k) / 2, (k - l - nu) / 2) * factorial(((l + nu - k) / 2) + (k - 1))) ** 2)
elif k >= l + nu + 1 and (l + nu + 1 - k) % 2 == 0:
ret *= -4 * sympy.rf(-nu, nu) * factorial(k - nu) / (zero * (sympy.rf((l + nu - k) / 2, k) * sympy.rf((l + nu - k + 1) / 2, (k - 1 - l - nu) / 2) * factorial(((l + nu - k + 1) / 2) + (k - 1))) ** 2)
elif k >= nu and nu % 1 == 0:
ret *= -sympy.rf(-nu, nu) * factorial(k - nu) * zero / ((sympy.rf((l + nu - k + 1) / 2, k) * sympy.rf((l + nu - k) / 2, k)) ** 2)
else:
ret *= sympy.rf(-nu, k + 1) / ((sympy.rf((l + nu - k + 1) / 2, k) * sympy.rf((l + nu - k) / 2, k)) ** 2)
for f in factors:
if -k < f <= k and (f - k) % 2 == 0:
ret *= sympy.rf((f - k) / 2, (k - f) / 2) * factorial(((f + k) / 2) - 1) * zero / 2
else:
ret *= sympy.rf((f - k) / 2, k)
return ret.expand()
else:
return - ((k * (-4) ** k) / (factorial(k) ** 2)) * (sympy.rf(1 + l - k, k) * sympy.rf((1 - k + delta_12) / two, k) * sympy.rf((1 - k + delta_34) / two, k) / sympy.rf(1 + nu + l - k, k))
class ConformalBlockTable:
"""
A class which calculates tables of conformal block derivatives when initialized.
This uses recursion relations on the diagonal found by Hogervorst, Osborn and
Rychkov in arXiv:1305.1321.
Parameters
----------
dim: The spatial dimension. If even dimensions are of interest, floating
point numbers with small fractional parts are recommended.
k_max: Number controlling the accuracy of the rational approximation.
Specifically, it is the maximum power of the crossing symmetric value
of the radial co-ordinate as described in arXiv:1406.4858.
l_max: The maximum spin to include in the table.
m_max: Number controlling how many `a` derivatives to include where the
standard co-ordinates are expressed as `(a + sqrt(b)) / 2` and
`(a - sqrt(b)) / 2`. As explained in arXiv:1412.4127, a value of 0
does not necessarily eliminate all `a` derivatives.
n_max: The number of `b` derivatives to include where the standard
co-ordinates are expressed as `(a + sqrt(b)) / 2` and
`(a - sqrt(b)) / 2`.
delta_12: [Optional] The difference between the external scaling dimensions of
operator 1 and operator 2. Defaults to 0.
delta_34: [Optional] The difference between the external scaling dimensions of
operator 3 and operator 4. Defaults to 0.
odd_spins: [Optional] Whether to include 0, 1, 2, 3, ..., `l_max` instead of
just 0, 2, 4, ..., `l_max`. Defaults to `False`.
name: [Optional] The name of a file containing conformal blocks that have
already been calculated. If this is specified, all other parameters
passed to the class are overwritten by the ones in the table.
Attributes
----------
table: A list of `PolynomialVector`s. A block's position in the table is
equal to its spin if `odd_spins` is True. Otherwise it is equal to
half of the spin.
m_order: A list with the same number of components as the `PolynomialVector`s
in `table`. Any `i`-th entry in a `PolynomialVector` is a particular
derivative of a conformal block, but to remember which one, just look
at the `i`-th entry of `m_order` which is the number of `a`
derivatives.
n_order: A list with the same number of components as the `PolynomialVector`s
in `table`. Any `i`-th entry in a `PolynomialVector` is a particular
derivative of a conformal block, but to remember which one, just look
at the `i`-th entry of `n_order` which is the number of `b`
derivatives.
"""
def __init__(self, dim, k_max, l_max, m_max, n_max, delta_12 = 0, delta_34 = 0, odd_spins = False, name = None):
self.dim = dim
self.k_max = k_max
self.l_max = l_max
self.m_max = m_max
self.n_max = n_max
self.delta_12 = delta_12
self.delta_34 = delta_34
self.odd_spins = odd_spins
if name != None:
dump_file = open(name, 'r')
command = dump_file.read()
exec(command)
return
small_table = ConformalBlockTableSeed(dim, k_max, l_max, min(m_max + 2 * n_max, 3), 0, delta_12, delta_34, odd_spins)
self.m_order = small_table.m_order
self.n_order = small_table.n_order
self.table = small_table.table
a = symbols('a')
nu = eval_mpfr(sympy.Rational(dim, 2) - 1, prec)
c_2 = (ell * (ell + 2 * nu) + delta * (delta - 2 * nu - 2)) / 2
c_4 = ell * (ell + 2 * nu) * (delta - 1) * (delta - 2 * nu - 1)
polys = [0, 0, 0, 0, 0]
poly_derivs = [[], [], [], [], []]
delta_prod = delta_12 * delta_34 / (eval_mpfr(-2, prec))
delta_sum = (delta_12 - delta_34) / (eval_mpfr(-2, prec))
# Polynomial 0 goes with the lowest order derivative on the right hand side
# Polynomial 3 goes with the highest order derivative on the right hand side
# Polynomial 4 goes with the derivative for which we are solving
polys[0] += (a ** 0) * (16 * c_2 * (2 * nu + 1) - 8 * c_4)
polys[0] += (a ** 1) * (4 * (c_4 + 2 * (2 * nu + 1) * (c_2 * delta_sum - c_2 + nu * delta_prod)))
polys[0] += (a ** 2) * (2 * (delta_sum - nu) * (c_2 * (2 * delta_sum - 1) + delta_prod * (6 * nu - 1)))
polys[0] += (a ** 3) * (2 * delta_prod * (delta_sum - nu) * (delta_sum - nu + 1))
polys[1] += (a ** 1) * (-16 * c_2 * (2 * nu + 1))
polys[1] += (a ** 2) * (4 * delta_prod - 24 * nu * delta_prod + 8 * nu * (2 * nu - 1) * (2 * delta_sum + 1) + 4 * c_2 * (1 - 4 * delta_sum + 6 * nu))
polys[1] += (a ** 3) * (2 * c_2 * (4 * delta_sum - 2 * nu + 1) + 4 * (2 * nu - 1) * (2 * delta_sum + 1) * (delta_sum - nu + 1) + 2 * delta_prod * (10 * nu - 5 - 4 * delta_sum))
polys[1] += (a ** 4) * ((delta_sum - nu + 1) * (4 * delta_prod + (2 * delta_sum + 1) * (delta_sum - nu + 2)))
polys[2] += (a ** 2) * (16 * c_2 + 16 * nu - 32 * nu * nu)
polys[2] += (a ** 3) * (8 * delta_prod - 8 * (3 * delta_sum - nu + 3) * (2 * nu - 1) - 16 * c_2 - 8 * nu + 16 * nu * nu)
polys[2] += (a ** 4) * (4 * (c_2 - delta_prod + (3 * delta_sum - nu + 3) * (2 * nu - 1)) - 4 * delta_prod - 2 * (delta_sum - nu + 2) * (5 * delta_sum - nu + 5))
polys[2] += (a ** 5) * (2 * delta_prod + (delta_sum - nu + 2) * (5 * delta_sum - nu + 5))
polys[3] += (a ** 3) * (32 * nu - 16)
polys[3] += (a ** 4) * (16 - 32 * nu + 4 * (4 * delta_sum - 2 * nu + 7))
polys[3] += (a ** 5) * (4 * (2 * nu - 1) - 4 * (4 * delta_sum - 2 * nu + 7))
polys[3] += (a ** 6) * (4 * delta_sum - 2 * nu + 7)
polys[4] += (a ** 7) - 6 * (a ** 6) + 12 * (a ** 5) - 8 * (a ** 4)
# Store all possible derivatives of these polynomials
for i in range(0, 5):
for j in range(0, i + 4):
poly_derivs[i].append(polys[i].subs(a, 1))
polys[i] = polys[i].diff(a)
for m in range(self.m_order[-1] + 1, m_max + 2 * n_max + 1):
for l in range(0, len(small_table.table)):
new_deriv = 0
for i in range(m - 1, max(m - 8, -1), -1):
coeff = 0
index = max(m - i - 4, 0)
prefactor = eval_mpfr(1, prec)
for k in range(0, index):
prefactor *= (m - 4 - k)
prefactor /= k + 1
k = max(4 + i - m, 0)
while k <= 4 and index <= (m - 4):
coeff += prefactor * poly_derivs[k][index]
prefactor *= (m - 4 - index)
prefactor /= index + 1
index += 1
k += 1
if type(coeff) != type(1):
coeff = coeff.subs(ell, small_table.table[l].label[0])
new_deriv -= coeff * self.table[l].vector[i]
new_deriv = new_deriv / poly_derivs[4][0]
self.table[l].vector.append(new_deriv.expand())
self.m_order.append(m)
self.n_order.append(0)
# This is just an alternative to storing derivatives as a doubly-indexed list
index = m_max + 2 * n_max + 1
index_map = [range(0, m_max + 2 * n_max + 1)]
for n in range(1, n_max + 1):
index_map.append([])
for m in range(0, 2 * (n_max - n) + m_max + 1):
index_map[n].append(index)
coeff1 = m * (-1) * (2 - 4 * n - 4 * nu)
coeff2 = m * (m - 1) * (2 - 4 * n - 4 * nu)
coeff3 = m * (m - 1) * (m - 2) * (2 - 4 * n - 4 * nu)
coeff4 = 1
coeff5 = (-6 + m + 4 * n - 2 * nu - 2 * delta_sum)
coeff6 = (-1) * (4 * c_2 + m * m + 8 * m * n - 5 * m + 4 * n * n - 2 * n - 2 - 4 * nu * (1 - m - n) + 4 * delta_sum * (m + 2 * n - 2) + 2 * delta_prod)
coeff7 = m * (-1) * (m * m + 12 * m * n - 13 * m + 12 * n * n - 34 * n + 22 - 2 * nu * (2 * n - m - 1) + 2 * delta_sum * (m + 4 * n - 5) + 2 * delta_prod)
coeff8 = (1 - n)
coeff9 = (1 - n) * (-6 + 3 * m + 4 * n - 2 * nu + 2 * delta_sum)
for l in range(0, len(small_table.table)):
new_deriv = 0
if m > 0:
new_deriv += coeff1 * self.table[l].vector[index_map[n][m - 1]]
if m > 1:
new_deriv += coeff2 * self.table[l].vector[index_map[n][m - 2]]
if m > 2:
new_deriv += coeff3 * self.table[l].vector[index_map[n][m - 3]]
new_deriv += coeff4 * self.table[l].vector[index_map[n - 1][m + 2]]
new_deriv += coeff5 * self.table[l].vector[index_map[n - 1][m + 1]]
new_deriv += coeff6.subs(ell, small_table.table[l].label[0]) * self.table[l].vector[index_map[n - 1][m]]
new_deriv += coeff7 * self.table[l].vector[index_map[n - 1][m - 1]]
if n > 1:
new_deriv += coeff8 * self.table[l].vector[index_map[n - 2][m + 2]]
new_deriv += coeff9 * self.table[l].vector[index_map[n - 2][m + 1]]
new_deriv = new_deriv / (2 - 4 * n - 4 * nu)
self.table[l].vector.append(new_deriv.expand())
self.m_order.append(m)
self.n_order.append(n)
index += 1
def dump(self, name):
"""
Saves a table of conformal block derivatives to a file. The file is valid
Python code which manually populates the entries of `table` when executed.
Parameters
----------
name: The path to use for output.
"""
dump_table_contents(self, name)
class ConvolvedBlockTable:
"""
A class which produces the functions that need to be linearly dependent in a
crossing symmetric CFT. If a `ConformalBlockTable` does not need to be changed
after a change to the external dimensions, a `ConvolvedBlockTable` does not
either. This is because external dimensions only appear symbolically through a
symbol called `delta_ext`.
Parameters
----------
block_table: A `ConformalBlockTable` from which to produce the convolved blocks.
odd_spins: [Optional] A parameter telling the class to keep odd spins which is
only used if `odd_spins` is True for `block_table`. Defaults to
`True`.
symmetric: [Optional] Whether to add blocks in two different channels instead
of subtract them. Defaults to `False`.
content: [Optional] A list of ordered triples that are used to produce
user-defined linear combinations of convolved conformal blocks
instead of just individual convolved conformal blocks where all the
coefficients are 1. Elements of a triple are taken to be the
coefficient, the dimension shift and the spin shift respectively.
It should always make sense to include a triple whose second and
third entries are 0 and 0 since this corresponds to a convolved
conformal block with scaling dimension `delta` and spin `ell`.
However, if other blocks in the multiplet have `delta + 1` and
`ell - 1` relative to this, another triple should be included whose
second and third entries are 1 and -1. The coefficient (first
entry) may be a polynomial in `delta` with coefficients depending
on `ell`.
Attributes
----------
dim: The spatial dimension, inherited from `block_table`.
k_max: Numer controlling the accuracy of the rational approximation,
inherited from `block_table`.
l_max: The highest spin kept in the convolved block table. This is at most
the `l_max` of `block_table`.
m_max: Number controlling how many `a` derivatives there are where the
standard co-ordinates are expressed as `(a + sqrt(b)) / 2` and
`(a - sqrt(b)) / 2`. This is at most the `m_max` of `block_table`.
n_max: The number of `b` derivatives there are where the standard
co-ordinates are expressed as `(a + sqrt(b)) / 2` and
`(a - sqrt(b)) / 2`. This is at most the `n_max` of `block_table`.
table: A list of `PolynomialVector`s. A block's position in the table is
equal to its spin if `odd_spins` is `True`. Otherwise it is equal
to half of the spin.
m_order: A list stating how many `a` derivatives are being described by the
corresponding entry in a `PolynomialVector` in `table`. Different
from the `m_order` of `block_table` because some derivatives vanish
by symmetry.
n_order: A list stating how many `b` derivatives are being described by the
corresponding entry in a `PolynomialVector` in `table`.
"""
def __init__(self, block_table, odd_spins = True, symmetric = False, content = [[1, 0, 0]]):
# Copying everything but the unconvolved table is fine from a memory standpoint
self.dim = block_table.dim
self.k_max = block_table.k_max
self.l_max = block_table.l_max
self.m_max = block_table.m_max
self.n_max = block_table.n_max
self.m_order = []
self.n_order = []
self.table = []
max_spin_shift = 0
for trip in content:
max_spin_shift = max(max_spin_shift, trip[2])
self.l_max -= max_spin_shift
# We can restrict to even spin when the provided table has odd spin but not vice-versa
if odd_spins == False and block_table.odd_spins == True:
self.odd_spins = False
else:
self.odd_spins = block_table.odd_spins
if block_table.odd_spins == True:
step = 1
else:
step = 2
symbol_array = []
for n in range(0, block_table.n_max + 1):
symbol_list = []
for m in range(0, 2 * (block_table.n_max - n) + block_table.m_max + 1):
symbol_list.append(symbols('g_' + n.__str__() + '_' + m.__str__()))
symbol_array.append(symbol_list)
derivatives = []
for n in range(0, block_table.n_max + 1):
for m in range(0, 2 * (block_table.n_max - n) + block_table.m_max + 1):
# Skip the ones that will vanish
if (symmetric == False and m % 2 == 0) or (symmetric == True and m % 2 == 1):
continue
self.m_order.append(m)
self.n_order.append(n)
expression = 0
old_coeff = eval_mpfr(sympy.Rational(1, 4), prec) ** delta_ext
for j in range(0, n + 1):
coeff = old_coeff
for i in range(0, m + 1):
expression += coeff * symbol_array[n - j][m - i]
coeff *= (i + 2 * j - 2 * delta_ext) * (m - i) / (i + 1)
old_coeff *= (j - delta_ext) * (n - j) / (j + 1)
deriv = expression / (factorial(m) * factorial(n))
derivatives.append(deriv)
spin = 0
combined_block_table = []
while spin <= self.l_max:
vector = []
l = spin // step
# Different blocks in the linear combination may be divided by different poles
all_poles = []
for trip in content:
del_shift = trip[1]
ell_shift = trip[2] // step
if l + ell_shift >= 0:
for p in block_table.table[l + ell_shift].poles:
new = True
for q in all_poles:
if abs(float(p - del_shift - q)) < 1e-10:
new = False
break
if new:
all_poles.append(p - del_shift)
for i in range(0, len(block_table.table[l].vector)):
entry = 0
for trip in content:
if "subs" in dir(trip[0]):
coeff = trip[0].subs(ell, spin)
else:
coeff = trip[0]
del_shift = trip[1]
ell_shift = trip[2] // step
if l + ell_shift >= 0:
for p in all_poles:
new = True
for q in block_table.table[l + ell_shift].poles:
if abs(float(p + del_shift - q)) < 1e-10:
new = False
break
if new:
coeff *= delta - p
entry += coeff * block_table.table[l + ell_shift].vector[i].subs(delta, delta + del_shift)
vector.append(entry.expand())
combined_block_table.append(PolynomialVector(vector, [spin, 0], all_poles))
if self.odd_spins:
spin += 1
else:
spin += 2
for l in range(0, len(combined_block_table)):
new_derivs = []
for i in range(0, len(derivatives)):
deriv = derivatives[i]
for j in range(len(combined_block_table[l].vector) - 1, 0, -1):
deriv = deriv.subs(symbol_array[block_table.n_order[j]][block_table.m_order[j]], combined_block_table[l].vector[j])
new_derivs.append(2 * deriv.subs(symbol_array[0][0], combined_block_table[l].vector[0]))
self.table.append(PolynomialVector(new_derivs, combined_block_table[l].label, combined_block_table[l].poles))
class SDP:
"""
A class where convolved conformal blocks are augmented by crossing equations
which allow numerical bounds to be derived. All calls to `SDPB` happen through
this class.