antic_sys/
lib.rs

1//! Bindings for the [Antic](https://github.com/wbhart/antic.git) library.
2
3#![allow(non_camel_case_types)]
4
5use libc::c_ulong;
6
7pub const NF_POWERS_CUTOFF: c_ulong = 30;
8pub const NF_GENERIC: c_ulong = 0;
9pub const NF_MONIC: c_ulong = 1;
10pub const NF_LINEAR: c_ulong = 2;
11pub const NF_QUADRATIC: c_ulong = 4;
12pub const NF_GAUSSIAN: c_ulong = 8;
13
14pub mod nf;
15pub mod nf_elem;
16pub mod qfb;
17
18#[cfg(test)]
19mod tests {
20    use crate::nf::*;
21    use crate::nf_elem::*;
22    use flint_sys::fmpz::*;
23    use flint_sys::fmpq::*;
24    use flint_sys::fmpq_poly::*;
25    use std::mem::MaybeUninit;
26
27    // Checks the norm of the element 2*x^2 - 1 of Q(x)/f where f = x^4 + 1
28    #[test]
29    fn try_it() {
30        let mut a = MaybeUninit::uninit();
31        let mut b = MaybeUninit::uninit();
32        let mut res = MaybeUninit::uninit();
33        let mut pol = MaybeUninit::uninit();
34
35        let mut x = MaybeUninit::uninit();
36        let mut nf = MaybeUninit::uninit();
37        
38        unsafe {
39            fmpz_init_set_si(a.as_mut_ptr(), -1);
40            let mut a = a.assume_init();
41            fmpz_init_set_si(b.as_mut_ptr(), 2);
42            let mut b = b.assume_init();
43
44            fmpq_poly_init(pol.as_mut_ptr());
45            let mut pol = pol.assume_init();
46
47            fmpq_poly_set_coeff_ui(&mut pol, 0, 1);
48            fmpq_poly_set_coeff_ui(&mut pol, 4, 1);
49
50            nf_init(nf.as_mut_ptr(), &pol);
51            let mut nf = nf.assume_init();
52
53            nf_elem_init(x.as_mut_ptr(), &nf);
54            let mut x = x.assume_init();
55        
56            _nf_elem_set_coeff_num_fmpz(&mut x, 0, &a, &nf);
57            _nf_elem_set_coeff_num_fmpz(&mut x, 2, &b, &nf);
58
59            fmpq_init(res.as_mut_ptr());
60            let mut res = res.assume_init();
61            nf_elem_norm(&mut res, &x, &nf);
62
63            assert!(fmpq_equal_ui(&res, 25) != 0);
64            println!("Success!");
65
66            fmpz_clear(&mut a);
67            fmpz_clear(&mut b);
68            fmpq_clear(&mut res);
69            fmpq_poly_clear(&mut pol);
70            nf_elem_clear(&mut x, &nf);
71            nf_clear(&mut nf);
72        }
73    }
74}