Repository navigation
Expand file tree
/
Copy pathch2_splitG2_random.mag
More file actions
154 lines (137 loc) · 5.29 KB
/
Copy pathch2_splitG2_random.mag
File metadata and controls
154 lines (137 loc) · 5.29 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
clear;
///////////////////////////////////////////////////////////////////////////////
///////// TESTING SPLIT MODEL DIVISOR ARITHMETIC OVER CHAR TWO FIELDS /////////
///////////////////////////////////////////////////////////////////////////////
//
// Sebastian Lindner, 2020
//-----------------------------------------------------------------------------
// OVERVIEW
//-----------------------------------------------------------------------------
// This script tests divisor arithmetic functions from ch2_splitG2_UTL.mag,
// ch2_splitG2_DBL.mag, and ch2_splitG2_ADD.mag.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//LOAD FILES
///////////////////////////////////////////////////////////////////////////////
UTL_DEBUG:= false;
DBL_DEBUG:= false;
ADD_DEBUG:= false;
load "reduced_basis_arithmetic.mag";
load "g2Formulas/ch2_splitG2_UTL.mag";
load "g2Formulas/ch2_splitG2_DBL.mag";
load "g2Formulas/ch2_splitG2_ADD.mag";
" ";
///////////////////////////////////////////////////////////////////////////////
//GLOBAL TESTING VARIABLES
///////////////////////////////////////////////////////////////////////////////
//Field sizes below 32 for random testing
//Split curves do not exist for FF(2)
FIELDS:= {4,8,16,32};
DIVISORS:= 250; //Number of divisor additions and doubling to test per curve
TRIALS:= #FIELDS;
DEBUG:= false;
TEST_DBL:= true;
TEST_ADD:= true;
///////////////////////////////////////////////////////////////////////////////
//REPRODUCIBILITY
///////////////////////////////////////////////////////////////////////////////
// These testers never set or reported a seed, so a failure in a rarely-drawn
// branch could not be replayed -- and a failure you cannot replay is a failure
// you cannot diagnose. The seed and step are printed in the banner below;
// RND_SEED=<n> reruns that draw sequence exactly.
if GetEnv("RND_SEED") ne "" then
SetSeed(StringToInteger(GetEnv("RND_SEED")));
end if;
/////////////////////////////////////////////////////////
///////////////////// TEST LOOPS ////////////////////////
/////////////////////////////////////////////////////////
printf "///////////////////////////////////////////////////////////////////////\n";
printf "//\n";
printf "// - Small finite field and curve picked at random for each trial. \n";
printf "// - %o total trials. \n", TRIALS;
printf "// - %o divisor additions and doubles each per trial. \n", DIVISORS;
sd, st:= GetSeed();
printf "// - Random seed %o, step %o. Replay this run with RND_SEED=%o\n", sd, st, sd;
printf "//";
trial:=1;
errorFlag:= false;
nCmp:= 0;
for F in FIELDS do
printf "\n// Trail # %o over FF(%o).", trial, F;
trial+:=1;
// Random finite field FF and polynomial ring over FF
FF:=GF(F);
R<x>:=PolynomialRing(FF);
f,h:= RandomChar2G2SplitCurve(F);
V:= -ComputeVpl(f,h,2) - h;
curveConst:= Precompute(f,h,F);
if DEBUG then
"\n";
FF, "f is: ", f, "h is: ", h, "V- is: ", V, "V+ is: ", -V-h;
" ";
end if;
divisor:= 0;
while divisor le DIVISORS do
divisor+:=1;
/////////////////////////////////////////////////////
///RANDOM DIVISORS
/////////////////////////////////////////////////////
D1:= RandomDivisor_SPLIT_NEG(f,h,V,2);
U1:= D1[1];
V1:= D1[2];
N1:= D1[4];
D2:= RandomDivisor_SPLIT_NEG(f,h,V,2);
U2:= D2[1];
V2:= D2[2];
N2:= D2[4];
/////////////////////////////////////////////////////
///TEST FORMULAS ON DIVISORS
/////////////////////////////////////////////////////
if DEBUG then " "; end if;
if TEST_DBL then
nU2,nU1, nU0, nV1, nV0, nN := DBL(U1,V1,N1,curveConst);
nCmp+:= 1;
nU:= R ! nU2*x^2 + nU1*x + nU0;
nV:= R ! Coeff(V,3)*x^3 + Coeff(V,2)*x^2 + nV1*x + nV0;
cantor:= Double_SPLIT_NEG(D1,f,h,V,2);
result := <nU,nV,ExactQuotient(f - nV*(nV + h),nU), nN>;
if result ne cantor then
printf "Doubling %o failed over finite field FF(%o) where f = %o and h = %o \n", D1, F, f, h;
errorFlag:= true;
end if;
end if;
if TEST_ADD then
if D1 ne D2 then
nU2,nU1, nU0, nV1, nV0, nN := ADD(U1,V1,N1,U2,V2,N2,curveConst);
nCmp+:= 1;
nU:= R ! nU2*x^2 + nU1*x + nU0;
nV:= R ! Coeff(V,3)*x^3 + Coeff(V,2)*x^2 + nV1*x + nV0;
cantor:= Add_SPLIT_NEG(D1,D2,f,h,V,2);
//cantor;
result := <nU,nV,ExactQuotient(f - nV*(nV + h),nU), nN>;
//result;
if result ne cantor then
printf "Adding %o with %o failed over finite field FF(%o) where f = %o and h = %o \n", D1, D2, F, f, h;
errorFlag:= true;
end if;
end if;
end if;
end while;
end for;
printf "\n//";
// E12: a tester that loaded nothing used to print the same green
// summary as one that verified everything, because TEST_ADD/TEST_DBL
// are configuration switches and "No errors." is true by vacuity.
// The count makes an empty run loud, and the assert makes it fatal:
// test_all.sh greps for "Runtime error|Assertion failed".
printf "\n// Comparisons: %o", nCmp;
assert nCmp gt 0;
if errorFlag then
printf "\n// Errors occured.";
else
printf "\n// No errors.";
end if;
printf "\n//";
printf "\n///////////////////////////////////////////////////////////////////////\n";
quit;