/
curves_by_height.sage
757 lines (671 loc) · 21.2 KB
/
curves_by_height.sage
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
# A more systematic attempt at code for generating statistics of invariants
# of elliptic curves ordered by height.
from sage.interfaces.all import magma
import time
import numpy as np
import sys
attach four_selmer.sage
def height_iterator(M,N,model):
if model == "short_weierstrass":
return height_iterator_short_weierstrass(M,N)
elif model == "rank_one":
return height_iterator_rank_one(M,N)
elif model == "rank_two":
return height_iterator_rank_two(M,N)
elif model == "two_torsion":
return height_iterator_two_torsion(M,N)
elif model == "three_torsion":
return height_iterator_three_torsion(M,N)
elif model == "full_weierstrass":
return height_iterator_full_weierstrass(M,N)
elif model == "F_1(2)":
return height_iterator_F_12(M,N)
else: raise IOError("Please enter recognized Weierstrass family of curves.")
def height_increment(coeffs,pows):
I = range(len(coeffs))
J = [(coeffs[i]+1)^(pows[i]) for i in I]
H = min(J)
K = []
coeffs2 = deepcopy(coeffs)
for i in I:
if J[i]==H:
coeffs2[i] += 1
K.append(i)
return (H,coeffs2,K)
def height_iterator2(M,N,model):
if model=="short_weierstrass":
pows = [3,2]
elif model=="rank_one":
pows = [6,4,3]
elif model=="rank_two":
pows = [6,3,3,2]
elif model=="two_torsion":
pows = []
elif model=="three_torsion":
pows = []
elif model=="full_weierstrass":
pows = []
elif model=="":
pows = []
elif model=="":
pows = []
coeffs = [floor(M^(1/n)) for n in pows]
H = max([coeffs[i]^(pows[i]) for i in range(len(pows))])
L = []
while H <= N:
C = height_increment(coeffs,pows)
if C[0]>N:
break
else:
H = C[0]
coeffs = C[1]
L.append(C)
return L
def height_iterator_short_weierstrass2(M,N):
L = []
a = floor(M^(1/3))
b = floor(M^(1/2))
H = max([a^3,b^2])
while H <= N:
C = height_increment([a,b],[3,2])
if C[0]>N:
break
else:
H = C[0]
a = C[1][0]
b = C[1][1]
L.append(C)
return L
def height_iterator_short_weierstrass(M,N):
L = []
a = floor(M^(1/3))
b = floor(M^(1/2))
H = max([a^3,b^2])
while H <= N:
a2 = (a+1)^3
b2 = (b+1)^2
if min([a2,b2]) > N:
break
if a2 < b2:
a += 1
H = a2
bbound = floor(H^(1/2))
L.append((H,[a,bbound],[0]))
elif b2 < a2:
b += 1
H = b2
abound = floor(H^(1/3))
L.append((H,[abound,b],[1]))
elif a2 == b2:
a += 1
b += 1
H = a2
L.append((H,[a,b],[0,1]))
return L
def height_iterator_rank_one(M,N):
L = []
x2 = floor(M^(1/6))
x3 = floor(M^(1/4))
x4 = floor((M)^(1/3))
H = max([x2^6,x3^4,x4^3])
while H <= N:
y2 = (x2+1)^6
y3 = (x3+1)^4
y4 = (x4+1)^3
yl = [y2,y3,y4]
if min([y2,y3,y4]) > N:
break
if y2 < min(y3,y4):
x2 += 1
H = y2
x3bound = floor((H)^(1/4))
x4bound = floor((H)^(1/3))
L.append((H,[x2,x3bound,x4bound],[0]))
if y3 < min(y2,y4):
x3 += 1
H = y3
x2bound = floor((H)^(1/6))
x4bound = floor((H)^(1/3))
L.append((H,[x2bound,x3,x4bound],[1]))
if y4 < min(y2,y3):
x4 += 1
H = y4
x2bound = floor((H)^(1/6))
x3bound = floor((H)^(1/4))
L.append((H,[x2bound,x3bound,x4],[2]))
if y2 == y3 and y2 < y4:
x2 += 1
x3 += 1
H = y2
x4bound = floor((H)^(1/3))
L.append((H,[x2,x3,x4bound],[0,1]))
if y2 == y4 and y2 < y3:
x2 += 1
x4 += 1
H = y2
x3bound = floor((H)^(1/4))
L.append((H,[x2,x3bound,x4],[0,2]))
if y3 == y4 and y3 < y2:
x3 += 1
x4 += 1
H = y2
x2bound = floor((H)^(1/6))
L.append((H,[x2bound,x2,x4],[1,2]))
if y2 == y3 and y2 == y4:
x2 += 1
x3 += 1
x4 += 1
H = y2
L.append((H,[x2,x3,x4],[0,1,2]))
return L
def height_iterator_rank_two(M,N):
L = []
x2 = floor(M^(1/6))
x4 = floor((M)^(1/3))
xp4 = floor((M)^(1/3))
x6 = floor((M)^(1/2))
H = max([x2^6,x4^3,xp4^3,x6^2])
while H <= N:
y2 = (x2+1)^6
y4 = (x4+1)^3
yp4 = (xp4+1)^3
y6 = (x6+1)^2
yl = [y2,y4,yp4,y6]
if min(yl) > N:
break
if y2 < min(y4,yp4,y6):
x2 += 1
H = y2
x4bound = floor((H)^(1/3))
xp4bound = floor((H)^(1/3))
x6bound = floor((H)^(1/2))
L.append((H,(x2,x4bound,xp4bound,x6bound),[0]))
if y4 < min(y2,yp4,y6):
x4 += 1
H = y4
x2bound = floor((H)^(1/6))
xp4bound = floor((H)^(1/3))
x6bound = floor((H)^(1/2))
L.append((H,(x2bound,x4,xp4bound,x6bound),[1]))
if yp4 < min(y2,y4,y6):
xp4 += 1
H = yp4
x2bound = floor((H)^(1/6))
x4bound = floor((H)^(1/3))
x6bound = floor((H)^(1/2))
L.append((H,(x2bound,x4bound,xp4,x6bound),[2]))
if y6 < min(y2,y4,yp4):
x6 += 1
H = y6
x2bound = floor((H)^(1/6))
x4bound = floor((H)^(1/3))
xp4bound = floor((H)^(1/3))
L.append((H,(x2bound,x4bound,xp4bound,x6),[3]))
if y2 == y4 and y2 < min(yp4,y6):
x2 += 1
x4 += 1
H = y2
xp4bound = floor((H)^(1/3))
x6bound = floor((H)^(1/2))
L.append((H,(x2,x4,xp4bound,x6bound),[0,1]))
if y2 == yp4 and y2 < min(y4,y6):
x2 += 1
xp4 += 1
H = y2
x4bound = floor((H)^(1/3))
x6bound = floor((H)^(1/2))
L.append((H,(x2,x4bound,xp4,x6bound),[0,2]))
if y2 == y6 and y2 < min(y4,yp4):
x2 += 1
x6 += 1
H = y2
x4bound = floor((H)^(1/3))
xp4bound = floor((H)^(1/3))
L.append((H,(x2,x4bound,xp4bound,x6),[0,3]))
if y4 == yp4 and y4 < min(y2,y6):
x4 += 1
xp4 += 1
H = y4
x2bound = floor((H)^(1/6))
x6bound = floor((H)^(1/2))
L.append((H,(x2bound,x4,xp4,x6bound),[1,2]))
if y4 == y6 and y4 < min(y2,yp4):
x4 += 1
x6 += 1
H = y4
x2bound = floor((H)^(1/6))
xp4bound = floor((H)^(1/3))
L.append((H,(x2bound,x4,xp4bound,x6),[1,3]))
if yp4 == y6 and yp4 < min(y2,y4):
xp4 += 1
x6 += 1
H = y4
x2bound = floor((H)^(1/6))
x4bound = floor((H)^(1/3))
L.append((H,(x2bound,x4bound,xp4,x6),[2,3]))
if y2 == y4 and y4 == yp4 and y2 < y6:
x2 += 1
x4 += 1
xp4 += 1
H = y2
x6bound = floor((H)^(1/2))
L.append((H,(x2,x4,xp4,x6bound),[0,1,2]))
if y2 == y4 and y4 == y6 and y2 < yp4:
x2 += 1
x4 += 1
x6 += 1
H = y2
xp4bound = floor((H)^(1/3))
L.append((H,(x2,x4,xp4bound,x6),[0,1,3]))
if y2 == yp4 and y2 == y6 and y2 < y4:
x2 += 1
xp4 += 1
x6 += 1
H = y2
x4bound = floor((H)^(1/3))
L.append((H,(x2,x4bound,x4,x6),[0,2,3]))
if y4 == yp4 and y4 == y6 and y4 < y2:
x4 += 1
xp4 += 1
x6 += 1
H = y4
x2bound = floor((H)^(1/6))
L.append((H,(x2bound,x4,xp4,x6),[1,2,3]))
if y2 == y4 and y2 == yp4 and y2 == y6:
x2 += 1
x4 += 1
xp4 += 1
x6 += 1
H = y2
L.append((H,(x2,x4,xp4,x6),[0,1,2,3]))
return L
def height_iterator_two_torsion(M,N):
L = []
x2 = floor((M)^(1/6))
x4 = floor((M)^(1/3))
H = max([x2^6,x4^3])
while H <= N:
y2 = (x2+1)^6
y4 = (x4+1)^3
if min([y2,y4]) > N:
break
if y2 < y4:
x2 += 1
H = y2
x4bound = floor((H)^(1/3))
L.append((H,[x2,x4bound],[0]))
if y4 < y2:
x4 += 1
H = y4
x2bound = floor((H)^(1/6))
L.append((H,[x2bound,x4],[1]))
if y2 == y4:
x2 += 1
x4 += 1
H = y2
L.append((H,[x2,x4],[0,1]))
return L
def height_iterator_three_torsion(M,N):
L = []
x1 = floor((M)^(1/12))
x3 = floor((M)^(1/4))
H = max([x1^12,x3^4])
while H <= N:
y1 = (x1+1)^12
y3 = (x3+1)^4
if min([y1,y3]) > N:
break
if y1 < y3:
x1 += 1
H = y1
x3bound = floor((H)^(1/4))
L.append((H,[x1,x3bound],[0]))
if y3 < y1:
x3 += 1
H = y3
x1bound = floor((H)^(1/12))
L.append((H,[x1bound,x3],[1]))
if y1 == y3:
x1 += 1
x3 += 1
H = y1
L.append((H,[x1,x3],[0,1]))
return L
def height_iterator_full_weierstrass(M,N):
raise NotImplementedError("Not yet implemented.")
def height_iterator_F_12(M,N):
"""
Curve family of the form y^2 = x^3 + (a1^2-a2-a2')*x^2 + a2*a2'*x
with distinguished points (0,0), (a2,a1,a2) and (a2',a1,a2').
Height given by max{|a1|,|a2|^(1/2),|a2'|^(1/2)}.
"""
L = []
x2 = M
x3 = floor(M^(1/2))
x4 = floor(M^(1/2))
H = max([x2,x3^2,x4^2])
while H <= N:
y2 = x2+1
y3 = (x3+1)^2
y4 = (x4+1)^2
d = min([y2,y3,y4])
if min([y2,y3,y4]) > N:
break
if y2 < min(y3,y4):
x2 += 1
H = y2
x3bound = floor((H)^(1/2))
x4bound = floor((H)^(1/2))
L.append((H,[x2,x3bound,x4bound],[0]))
if y3 < min(y2,y4):
x3 += 1
H = y3
x2bound = H
x4bound = floor((H)^(1/2))
L.append((H,[x2bound,x3,x4bound],[1]))
if y4 < min(y2,y3):
x4 += 1
H = y4
x2bound = H
x3bound = floor((H)^(1/2))
L.append((H,[x2bound,x3bound,x4],[2]))
if y2 == y3 and y2 < y4:
x2 += 1
x3 += 1
H = y2
x4bound = floor((H)^(1/2))
L.append((H,[x2,x3,x4bound],[0,1]))
if y2 == y4 and y2 < y3:
x2 += 1
x4 += 1
H = y2
x3bound = floor((H)^(1/2))
L.append((H,[x2,x3bound,x4],[0,2]))
if y3 == y4 and y3 < y2:
x3 += 1
x4 += 1
H = y2
x2bound = H
L.append((H,[x2bound,x2,x4],[1,2]))
if y2 == y3 and y2 == y4:
x2 += 1
x3 += 1
x4 += 1
H = y2
L.append((H,[x2,x3,x4],[0,1,2]))
return L
def coefficients_over_height_range(L,model):
L2 = []
for C in L:
L2 += coefficients_from_height(C[0],C[1],C[2],model)
return L2
def coefficients_from_height(H,coeffs,indices,model):
L = []
for S in list(powerset(indices))[1:]:
B = []
for j in range(len(coeffs)):
if j in S:
B.append([-coeffs[j],coeffs[j]])
elif j in indices:
B.append(srange(-coeffs[j]+1,coeffs[j]))
else:
B.append(srange(-coeffs[j],coeffs[j]+1))
C = CartesianProduct(*B).list()
for c in C:
L.append(c)
L2 = []
for c in L:
C = coeffs_to_a_invariants(c,model)
if not is_singular(C):
L2.append((H,C))
return L2
def coeffs_to_a_invariants(c,model):
if model == "short_weierstrass":
C = [0,0,0,c[0],c[1]]
elif model == "rank_one":
C = [0,c[0],c[1],c[2],0]
elif model == "rank_two":
a2,a4,b4,a6 = c[0],c[1],c[2],c[3]
I = 3*a4^2+b4^2-3*a2*a6
J = -27/4*a2^2*a4^2+18*a4^2*b4 - 2*b4^3 + 9*a2*b4*a6 - 27*a6^2
if J.denominator()==4:
I = I*16
J = J*64
C = [0,0,0,-27*I,-27*J]
elif model == "two_torsion":
C = [0,c[0],0,c[1],0]
elif model == "three_torsion":
C = [c[0],0,c[1],0,0]
elif model == "full_weierstrass":
raise NotImplementedError("Not yet implemented.")
elif model == "height_iterator_F_1(2)":
# Need proper form here
C = [0,c[0]^2-c[1]-c[2],0,c[1]*c[2],0]
else: raise IOError("Please enter recognized Weierstrass family of curves.")
return C
def is_singular(C):
a1 = C[0]
a2 = C[1]
a3 = C[2]
a4 = C[3]
a6 = C[4]
b2 = a1^2 + 4*a2
b4 = 2*a4 + a1*a3
b6 = a3^2 + 4*a6
b8 = a1^2*a6 + 4*a2*a6 - a1*a3*a4 + a2*a3^2 - a4^2
Delta = -b2^2*b8 - 8*b4^3 - 27*b6^2 + 9*b2*b4*b6
return Delta==0
def set_magma_class_group_bounds(proof = True):
if proof == False:
magma.eval('SetClassGroupBounds("GRH")')
else:
magma.eval('SetClassGroupBounds("PARI")')
def data_by_height(L,inv="two_selmer",proof=True):
def _invariant(inv):
if inv == "rank":
def f(E): return E.rank(use_database=True, only_use_mwrank = False)
elif inv == "sha_order":
@fork
def f(E): return E.sha().an_numerical(prec=14)
elif inv == "two_selmer_size":
def f(E): return 2^(E.selmer_rank())
elif inv == "two_selmer_rank":
def f(E): return E.selmer_rank()
elif inv == "reduced_two_selmer_size":
def f(E): return 2^(E.selmer_rank()-E.two_torsion_rank())
elif inv == "reduced_two_selmer_rank":
def f(E): return E.selmer_rank()-E.two_torsion_rank()
elif inv == "three_selmer_size":
def f(E): return 3^(E.three_selmer_rank())
elif inv == "three_selmer_rank":
def f(E): return E.three_selmer_rank()
elif inv == "reduced_three_selmer_size":
def f(E): return 3^(E.three_selmer_rank()-valuation(E.torsion_order(),3))
elif inv == "reduced_three_selmer_rank":
def f(E): return E.three_selmer_rank()-valuation(E.torsion_order(),3)
elif inv == "four_selmer_size":
def f(E): return four_selmer_size(E)
elif inv == "two_torsion_size":
def f(E): return 2^(E.two_torsion_rank())
elif inv == "two_torsion_rank":
def f(E): return E.two_torsion_rank()
elif inv == "three_torsion_size":
def f(E): return 3^(valuation(E.torsion_order(),3))
elif inv == "three_torsion_rank":
def f(E): return valuation(E.torsion_order(),3)
else: raise NotImplementedError('Invariant not yet Implemented')
return f
if inv in ["three_selmer_rank","three_selmer_size",\
"reduced_three_selmer_size",\
"reduced_three_selmer_rank"]:
set_magma_class_group_bounds(proof)
f = _invariant(inv)
t=time.time()
output = []
problems = []
for C in L:
try:
E = EllipticCurve(C[1])
output.append((C[0],C[1],f(E)))
except:
problems.append(C)
print(time.time()-t)
return output,problems
def data_by_height2(L,inv="two_selmer",proof=True,return_data=False,\
output_filename="output.txt",problems_filename="problems.txt"):
def _invariant(inv):
if inv == "rank":
def f(E): return E.rank(use_database=True, only_use_mwrank = False)
elif inv == "sha_order":
@fork
def f(E): return E.sha().an_numerical(prec=14)
elif inv == "two_selmer_size":
def f(E): return 2^(E.selmer_rank())
elif inv == "two_selmer_rank":
def f(E): return E.selmer_rank()
elif inv == "reduced_two_selmer_size":
def f(E): return 2^(E.selmer_rank()-E.two_torsion_rank())
elif inv == "reduced_two_selmer_rank":
def f(E): return E.selmer_rank()-E.two_torsion_rank()
elif inv == "three_selmer_size":
def f(E): return 3^(E.three_selmer_rank())
elif inv == "three_selmer_rank":
def f(E): return E.three_selmer_rank()
elif inv == "reduced_three_selmer_size":
def f(E): return 3^(E.three_selmer_rank()-valuation(E.torsion_order(),3))
elif inv == "reduced_three_selmer_rank":
def f(E): return E.three_selmer_rank()-valuation(E.torsion_order(),3)
elif inv == "four_selmer_size":
def f(E): return four_selmer_size(E)
elif inv == "two_torsion_size":
def f(E): return 2^(E.two_torsion_rank())
elif inv == "two_torsion_rank":
def f(E): return E.two_torsion_rank()
elif inv == "three_torsion_size":
def f(E): return 3^(valuation(E.torsion_order(),3))
elif inv == "three_torsion_rank":
def f(E): return valuation(E.torsion_order(),3)
else: raise NotImplementedError('Invariant not yet Implemented')
return f
if inv in ["three_selmer_rank","three_selmer_size",\
"reduced_three_selmer_size",\
"reduced_three_selmer_rank"]:
set_magma_class_group_bounds(proof)
f = _invariant(inv)
t=time.time()
out_file = open(output_filename,"w")
prob_file = open(problems_filename,"w")
if return_data:
output = []
problems = []
for C in L:
try:
E = EllipticCurve(C[1])
d = f(E)
out_file.write(str(C[0])+"\t")
for a in C[1]:
out_file.write(str(a)+"\t")
out_file.write(str(d)+"\n")
if return_data:
output.append((C[0],C[1],f(E)))
except:
prob_file.write(str(C[0])+"\t")
for a in C[1]:
prob_file.write(str(a)+"\t")
prob_file.write("\n")
if return_data:
problems.append(C)
sys.stdout.flush()
out_file.close()
prob_file.close()
print(time.time()-t)
if return_data:
return output,problems
def good_primes_by_height(cbh,start,stop):
t=time.time()
output = []
problems = []
for C in cbh:
E = EllipticCurve(C[1])
L = []
for p in primes(start,stop):
S = [ZZ(E.is_ordinary(p)),
ZZ(E.has_good_reduction(p)),
ZZ(E.galois_representation().is_surjective(p))]
L.append(S)
output.append((C[0],C[1],L))
print(time.time()-t)
return output
def averaged_data(L, filename, return_data=False):
"""
INPUT:
-- L: list of tuples (H, coeffs, data), where
H: height
coeffs: list of coefficients of elliptic curve giving that height
data: the type of data that's being averaged, e.g., 2-Selmer, 3-Selmer
-- filename: name of output file, passed in as a string
OUTPUT:
-- writes the averaged data to file
-- (optional) returns numpy array of dimension len(list) x 2,
where the first column has heights,
and the second the averaged data up to that height
"""
X = np.array([C[0] for C in L])
V = np.array([C[2] for C in L])
N = np.arange(1,X.shape[0]+1,dtype=np.float64)
Y = np.cumsum(V)/N
I = X[:-1] != X[1:]
I = np.append(I,True)
Z = np.vstack([X[I],Y[I]]).T
np.savetxt(filename, Z)
if return_data:
return Z
def averaged_data2(infile, outfile="average_data.txt", return_data=False):
"""
INPUT:
-- infile: file of array of data, where each line is
H, a1, a2, a3, a4, a6, d
H: curve height
a1..a6: list of a-invariants of elliptic curve giving that height
d: the type of data that's being averaged, e.g., 2-Selmer, 3-Selmer
-- outfile: name of output file, passed in as a string
OUTPUT:
-- writes the averaged data to file
-- (optional) returns numpy array of dimension len(list) x 2,
where the first column has heights,
and the second the averaged data up to that height
"""
data = np.loadtxt(infile)
X = data[:,0]
V = data[:,6:]
N = np.arange(1,X.shape[0]+1,dtype=np.float64)
N = (np.ones((V.shape[1],1))*N).T
Y = np.cumsum(V,0)/N
I = X[:-1] != X[1:]
I = np.append(I,True)
Z = np.vstack([X[I],Y[I,:].T]).T
np.savetxt(outfile, Z)
if return_data:
return Z
@parallel
def compute_data(height_bound,model,invariant,filename1="output.txt",\
filename2="raw_data.txt",filename3="problems.txt",
proof=True):
L1 = height_iterator(0,height_bound,model)
L2 = []
for C in L1:
L2 += coefficients_from_height(C[0],C[1],C[2],model)
L3 = data_by_height(L2,invariant,proof)
averaged_data(L3[0],filename1)
L4 = [flatten(C) for C in L3[0]]
np.savetxt(filename2,L4)
L5 = [flatten(C) for C in L3[1]]
np.savetxt(filename3,L5)
@parallel
def crunch(height_bound,model,invariant,raw_data_file="raw_data.txt",\
problems_file="prob_data.txt",average_data_file="avg_data.txt"):
L1 = height_iterator(0,height_bound,model)
L2 = coefficients_over_height_range(L1,model)
data_by_height2(L2,inv=invariant,output_filename=raw_data_file,\
problems_filename=problems_file)
averaged_data2(infile=raw_data_file,outfile=average_data_file)