Commit 2a7e28ec authored by MASSON Simon's avatar MASSON Simon
Browse files

python2 to python3 ++

parent 77166dcd
......@@ -499,6 +499,6 @@ def print_JL_polys(C,Y):
for gi in g[:-1]:
str_gx += "{:#x},".format(gi)
str_gx += "{:#x}],".format(g[-1])
print str_f
print str_gx
print str_g
print(str_f)
print(str_gx)
print(str_g)
......@@ -71,8 +71,8 @@ def cost_s_cyclo(k) :
else :
return 'not done for this embedding degree'
cyclo_s6 = 3*cost_s(2) # eprint 2009/565
cyclo_s8 = 2*cost_s(4) # eprint 2009/565 section 3.1
cyclo_s6 = 3*cost_s(2) # eprint(2009/565)
cyclo_s8 = 2*cost_s(4) # eprint(2009/565) section 3.1
compr_s12 = 12*m # BarDuq
cyclo_s12 = 18*m
cyclo_s16 = 2*cost_s(8)
......@@ -187,11 +187,11 @@ def table_costFpk(k_list):
r"\hline",
r"\end{array}$$",
]
print "% This table is generated by:"
print "%% PYTHONPATH=cocks-pinch-variant/ sage -c 'load(\"cocks-pinch-variant/cost_pairing.py\"); table_costFpk(%s)'" % (k_list)
print("% This table is generated by:")
print("%% PYTHONPATH=cocks-pinch-variant/ sage -c 'load(\"cocks-pinch-variant/cost_pairing.py\"); table_costFpk(%s)'" % (k_list))
for s in contents:
print s
print(s)
def Hw(x) :
return len(bit_positions_2naf(x))
......@@ -460,16 +460,16 @@ def finalExpoCost(C):
cost_T = (logT-1)*cost_s(k) + (HwT-1)*cost_m(k)
# see final-expo-k57.sage
c2 = (k-2)*(cost_f(k) + cost_T + 2*cost_m(k)) + cost_m(k)
logc = logp - logr
c2 += (logc -1)*cost_s(k) + (HwCofr-1)*cost_m(k)
# one inversion costs (k-1) Frobenius since norm == 1
cost_inv_torus = (k-1) * cost_f(k)
if i > 1:
c2 = (k-2)*(cost_f(k) + cost_T + 2*cost_m(k)) + cost_m(k)
logc = logp - logr
c2 += (logc -1)*cost_s(k) + (HwCofr-1)*cost_m(k)
# one inversion costs (k-1) Frobenius since norm == 1
cost_inv_torus = (k-1) * cost_f(k)
if i > 1:
c2 += cost_inv_torus
if i < k-1 and 2*i > k:
# this just happens to match the formulas that we have.
c2 += cost_inv_torus
c2 += cost_inv_torus
# cost for k=5 i=1: 1c + 3T + 7M + 3p
# cost for k=5 i=2: 1I + 1c + 3T + 7M + 3p
# cost for k=5 i=3: 2I + 1c + 3T + 7M + 3p
......@@ -490,33 +490,33 @@ def finalExpoCost(C):
# start with this:
c_exp_T = (logT-1)*cyclo_s6 + (HwT-1)*cost_m(k)
c2 = c_exp_T + cost_f(k) + cyclo_s6 + 4*cost_m(k)
if i == 5:
# extra cost for raising to the power p+t0 = p+2-T: we
# need a square...
c2 += cyclo_s6
c_exp_T = (logT-1)*cyclo_s6 + (HwT-1)*cost_m(k)
c2 = c_exp_T + cost_f(k) + cyclo_s6 + 4*cost_m(k)
if i == 5:
# extra cost for raising to the power p+t0 = p+2-T: we
# need a square...
c2 += cyclo_s6
# Then, see code/formules-familles-CocksPinch.sage
# it's a slight mess, to be honest.
assert (1 + ht + hy) % 2 == 0
if ht % 2 == 0:
hu = ht//2
hz = -1 if T%3 == 0 else 1
hw = (hy-hz)//2
else:
hu = (ht+1)//2
hw = hy//2
U = T - (T % 3)
logU=U.nbits(); HwU=Hw(U)
loghu=hu.nbits(); Hwhu=Hw(hu)
loghw=hw.nbits(); Hwhw=Hw(hw)
c_exp_U = (logU-1)*cyclo_s6 + (HwU-1)*cost_m(k)
c_exp_hu = (loghu-1)*cyclo_s6 + (Hwhu-1)*cost_m(k)
c_exp_hw = (loghw-1)*cyclo_s6 + (Hwhw-1)*cost_m(k)
c2 += 12*cost_m(k) + 2*cost_s(k) + 2*(c_exp_U + c_exp_hu + c_exp_hw)
assert (1 + ht + hy) % 2 == 0
if ht % 2 == 0:
hu = ht//2
hz = -1 if T%3 == 0 else 1
hw = (hy-hz)//2
else:
hu = (ht+1)//2
hw = hy//2
U = T - (T % 3)
logU=U.nbits(); HwU=Hw(U)
loghu=hu.nbits(); Hwhu=Hw(hu)
loghw=hw.nbits(); Hwhw=Hw(hw)
c_exp_U = (logU-1)*cyclo_s6 + (HwU-1)*cost_m(k)
c_exp_hu = (loghu-1)*cyclo_s6 + (Hwhu-1)*cost_m(k)
c_exp_hw = (loghw-1)*cyclo_s6 + (Hwhw-1)*cost_m(k)
c2 += 12*cost_m(k) + 2*cost_s(k) + 2*(c_exp_U + c_exp_hu + c_exp_hw)
elif k == 8 :
# See:
# sage: attach("formules-familles-CocksPinch.sage")
......@@ -531,31 +531,31 @@ def finalExpoCost(C):
# and maybe one multiplication less. Note also that ht+1 is
# necessarily even.
c_exp_T = (logT-1)*cyclo_s8 + (HwT-1)*cost_m(k)
# first, this: (because phi_8(p)/r = 1 + c(T^2+p^2)(p-T))
c_exp_T = (logT-1)*cyclo_s8 + (HwT-1)*cost_m(k)
# first, this: (because phi_8(p)/r = 1 + c(T^2+p^2)(p-T))
# recall that a p^2-power cost is the same as a p-power
# for the reason explained in remark \ref{frob}.
# What happen if i != 1 when the expo is to the power T^i ?
c2 = 3*c_exp_T + 2*cost_f(8) + 3*cost_m(k)
# Then, see code/formules-familles-CocksPinch.sage
# for raising to the power c, we get:
# 11M + 2u + 4T + 2y
# with one of the multiplies that (for i=3 and i=7) can be
# elided if T=0 mod 4. This is with u = multiplication by
# (h_t+1)//2.
hu = (ht+1)//2;
loghu=hu.nbits(); Hwhu=Hw(hu)
c_exp_hy = (loghy-1)*cyclo_s8 + (Hwhy-1)*cost_m(k)
c_exp_hu = (loghu-1)*cyclo_s8 + (Hwhu-1)*cost_m(k)
c2 += 4 * c_exp_T + 2 * c_exp_hu + 2 * c_exp_hy + 10 * cost_m(k)
c2 = 3*c_exp_T + 2*cost_f(8) + 3*cost_m(k)
# Then, see code/formules-familles-CocksPinch.sage
# for raising to the power c, we get:
# 11M + 2u + 4T + 2y
# with one of the multiplies that (for i=3 and i=7) can be
# elided if T=0 mod 4. This is with u = multiplication by
# (h_t+1)//2.
hu = (ht+1)//2;
loghu=hu.nbits(); Hwhu=Hw(hu)
c_exp_hy = (loghy-1)*cyclo_s8 + (Hwhy-1)*cost_m(k)
c_exp_hu = (loghu-1)*cyclo_s8 + (Hwhu-1)*cost_m(k)
c2 += 4 * c_exp_T + 2 * c_exp_hu + 2 * c_exp_hy + 10 * cost_m(k)
# Do we miss some inversions ?
if (T%4 == 2 or i == 1 or i == 5):
c2 += cost_m(k)
if (T%4 == 2 or i == 1 or i == 5):
c2 += cost_m(k)
tot_expo = c1 + c2
return tot_expo(m=1,s=1,inv=25)
......@@ -574,18 +574,18 @@ def pairingCost(C):
tot_expo = costFinalExp
time_expo = tot_expo * time_m/1000000
return dict(
k=polymorphic_get_embedding_degree(C),
D=polymorphic_get_fD(C),
k=polymorphic_get_embedding_degree(C),
D=polymorphic_get_fD(C),
name=polymorphic_get_name(C),
logp=polymorphic_get_logp(C),
time_m=time_m,
tot_miller=tot_miller,
time_miller=round(time_miller, significant_dd),
tot_expo=tot_expo,
time_expo=round(time_expo, significant_dd),
tot_pairing = tot_miller + tot_expo,
time_pairing = round(time_miller+time_expo, significant_dd),
)
logp=polymorphic_get_logp(C),
time_m=time_m,
tot_miller=tot_miller,
time_miller=round(time_miller, significant_dd),
tot_expo=tot_expo,
time_expo=round(time_expo, significant_dd),
tot_pairing = tot_miller + tot_expo,
time_pairing = round(time_miller+time_expo, significant_dd),
)
def table_cost_pairing() :
timing_recap = []
......@@ -597,8 +597,8 @@ def table_cost_pairing() :
#timing recap is generated
print "% This table is generated by:"
print "% PYTHONPATH=cocks-pinch-variant sage -c 'load(\"cocks-pinch-variant/cost_pairing.py\"); table_cost_pairing()'"
print("% This table is generated by:")
print("% PYTHONPATH=cocks-pinch-variant sage -c 'load(\"cocks-pinch-variant/cost_pairing.py\"); table_cost_pairing()'")
def wrap_cell(cell):
return "\\begin{tabular}{@{}c@{}} %s \\end{tabular}" % cell
......@@ -613,7 +613,7 @@ def table_cost_pairing() :
cell_expo = wrap_cell(cell_expo)
cell_pairing = " %d\\bfm & %sms" % (L['tot_pairing'], L['time_pairing'])
print cell0 + " & " + cell_miller + " &"
print " " + cell_expo + " & "
print " " + cell_pairing + " \\\\"
print " \\hline "
print(cell0 + " & " + cell_miller + " &")
print(" " + cell_expo + " & ")
print(" " + cell_pairing + " \\\\")
print(" \\hline ")
......@@ -225,12 +225,12 @@ def print_final_expo_k57():
res = res * cc[j].frob(p, j)
if res.val == Cp:
print "cost for k=%d i=%d: %s" % (k, i, counts.text_counts())
print("cost for k={} i={}: {}".format(k, i, counts.text_counts()))
else:
print "k=%d i=%d: wrong formula" % (k,i)
print res.val
print Cp
print C
print("k={} i={}: wrong formula".format(k,i))
print(res.val)
print(Cp)
print(C)
# Other nice expressions, but I'm not sure they're any useful.
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment