[07_weird_assembly_machine] reorder main loop to make use of a faster implementation of f(g(x))
This commit is contained in:
42
res/07_weird_assembly_machine.sage
Normal file
42
res/07_weird_assembly_machine.sage
Normal file
@@ -0,0 +1,42 @@
|
||||
F = GF(2)
|
||||
R.<x> = PolynomialRing(F)
|
||||
S.<xi> = R.quotient_ring(x^64 + 1)
|
||||
T.<X> = PolynomialRing(S)
|
||||
Ti.<Xi> = T.quotient_ring(X^64 + 1)
|
||||
Tj.<Xj> = T.quotient_ring(X^64)
|
||||
|
||||
def num_to_poly(num):
|
||||
out = 0
|
||||
i = 0
|
||||
while num != 0:
|
||||
if num % 2 == 1:
|
||||
out += xi^i
|
||||
i += 1
|
||||
num //= 2
|
||||
return out
|
||||
|
||||
def poly_to_num(poly):
|
||||
out = 0
|
||||
for i in range(0, 64):
|
||||
if poly[i] == 1:
|
||||
out |= 1 << i
|
||||
return out
|
||||
|
||||
|
||||
with open("./07_weird_assembly_machine.data") as f:
|
||||
data = [int(line) for line in f.readlines() if line]
|
||||
|
||||
f = reduce(lambda a, b: a * X + b, [num_to_poly(a) for a in data[:128]])
|
||||
g = reduce(lambda a, b: a * X + b, [num_to_poly(a) for a in data[128:]])
|
||||
|
||||
fg = f(g)
|
||||
fgi = Ti([fg[i] for i in range(0, fg.degree())])
|
||||
fgj = Tj([fg[i] for i in range(0, fg.degree())])
|
||||
|
||||
print("\n\n======= f(g(x)) =======")
|
||||
for i in reversed(range(0, 64)):
|
||||
print(poly_to_num(fgi.lift()[i]))
|
||||
|
||||
print("\n\n======= f(g(x)) =======")
|
||||
for i in reversed(range(0, 64)):
|
||||
print(poly_to_num(fgj.lift()[i]))
|
||||
@@ -17,19 +17,24 @@ static DATA: LazyLock<Vec<u64>> = LazyLock::new(|| {
|
||||
data
|
||||
});
|
||||
|
||||
const N: u64 = 10000045930000000;
|
||||
const X: u64 = 16195396392266746892;
|
||||
const N: u64 = 10000117800000000;
|
||||
const X: u64 = 5905739161907566595;
|
||||
|
||||
fn main() {
|
||||
compute_async(|tx| {
|
||||
let mut n = N;
|
||||
let mut x = X;
|
||||
loop {
|
||||
for _ in 0..1_000_000 {
|
||||
n += 1;
|
||||
x = sub(f(x), n);
|
||||
|
||||
for _ in 1..1_000_000 {
|
||||
n += 1;
|
||||
x = h(x, n);
|
||||
x = sub(fg(x), n);
|
||||
}
|
||||
|
||||
x = g(x);
|
||||
|
||||
tx.send((n, x)).unwrap();
|
||||
}
|
||||
});
|
||||
@@ -47,6 +52,11 @@ fn g(x: u64) -> u64 {
|
||||
evaluate(x, &DATA[128..256])
|
||||
}
|
||||
|
||||
/// Quickly computes [`f`](f)([`g`](g)(x)).
|
||||
fn fg(x: u64) -> u64 {
|
||||
!x.rotate_left(17)
|
||||
}
|
||||
|
||||
/// Evaluates a polynomial over `GF(2)[X] / (X^64 + 1)`
|
||||
fn evaluate(x: u64, data: &[u64]) -> u64 {
|
||||
let mut out = 0;
|
||||
|
||||
Reference in New Issue
Block a user