mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Updated automorphism from permuation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use itertools::izip;
|
||||
use math::automorphism::AutomorphismPermutation;
|
||||
use math::poly::Poly;
|
||||
use math::ring::Ring;
|
||||
|
||||
@@ -10,11 +11,18 @@ fn automorphism_u64() {
|
||||
let q_power: usize = 1usize;
|
||||
let ring: Ring<u64> = Ring::new(n, q_base, q_power);
|
||||
|
||||
sub_test("test_automorphism_u64::<NTT:false>", || {
|
||||
test_automorphism_u64::<false>(&ring, nth_root)
|
||||
sub_test("test_automorphism_native_u64::<NTT:false>", || {
|
||||
test_automorphism_native_u64::<false>(&ring, nth_root)
|
||||
});
|
||||
sub_test("test_automorphism_u64::<NTT:true>", || {
|
||||
test_automorphism_u64::<true>(&ring, nth_root)
|
||||
sub_test("test_automorphism_native_u64::<NTT:true>", || {
|
||||
test_automorphism_native_u64::<true>(&ring, nth_root)
|
||||
});
|
||||
|
||||
sub_test("test_automorphism_from_perm_u64::<NTT:false>", || {
|
||||
test_automorphism_from_perm_u64::<false>(&ring, nth_root)
|
||||
});
|
||||
sub_test("test_automorphism_from_perm_u64::<NTT:true>", || {
|
||||
test_automorphism_from_perm_u64::<true>(&ring, nth_root)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +31,7 @@ fn sub_test<F: FnOnce()>(name: &str, f: F) {
|
||||
f();
|
||||
}
|
||||
|
||||
fn test_automorphism_u64<const NTT: bool>(ring: &Ring<u64>, nth_root: usize) {
|
||||
fn test_automorphism_native_u64<const NTT: bool>(ring: &Ring<u64>, nth_root: usize) {
|
||||
let n: usize = ring.n();
|
||||
let q: u64 = ring.modulus.q;
|
||||
|
||||
@@ -38,7 +46,42 @@ fn test_automorphism_u64<const NTT: bool>(ring: &Ring<u64>, nth_root: usize) {
|
||||
ring.ntt_inplace::<false>(&mut p0);
|
||||
}
|
||||
|
||||
ring.a_apply_automorphism_into_b::<NTT>(&p0, 2 * n - 1, nth_root, &mut p1);
|
||||
let gal_el: usize = 2 * nth_root - 1;
|
||||
|
||||
ring.a_apply_automorphism_native_into_b::<NTT>(&p0, gal_el, nth_root, &mut p1);
|
||||
|
||||
if NTT {
|
||||
ring.intt_inplace::<false>(&mut p1);
|
||||
}
|
||||
|
||||
p0.0[0] = 0;
|
||||
for i in 1..p0.n() {
|
||||
p0.0[i] = q - (n - i) as u64
|
||||
}
|
||||
|
||||
izip!(p0.0, p1.0).for_each(|(a, b)| assert_eq!(a, b));
|
||||
}
|
||||
|
||||
fn test_automorphism_from_perm_u64<const NTT: bool>(ring: &Ring<u64>, nth_root: usize) {
|
||||
let n: usize = ring.n();
|
||||
let q: u64 = ring.modulus.q;
|
||||
|
||||
let mut p0: Poly<u64> = ring.new_poly();
|
||||
let mut p1: Poly<u64> = ring.new_poly();
|
||||
|
||||
for i in 0..p0.n() {
|
||||
p0.0[i] = i as u64
|
||||
}
|
||||
|
||||
if NTT {
|
||||
ring.ntt_inplace::<false>(&mut p0);
|
||||
}
|
||||
|
||||
let gal_el: usize = 2 * nth_root - 1;
|
||||
|
||||
let auto_perm = AutomorphismPermutation::new::<NTT>(n, gal_el, nth_root);
|
||||
|
||||
ring.a_apply_automorphism_from_perm_into_b::<NTT>(&p0, &auto_perm, &mut p1);
|
||||
|
||||
if NTT {
|
||||
ring.intt_inplace::<false>(&mut p1);
|
||||
|
||||
Reference in New Issue
Block a user