Macaulay2 Engine
Loading...
Searching...
No Matches
aring-zzp-flint.cpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
3#include "aring-zzp.hpp"
4#include "ringmap.hpp"
5
6#include "aring-zzp-flint.hpp"
7
8namespace M2 {
9
11{
12 nmod_init(&mModulus, p0);
14 fmpz_init(mFmpzCharac);
15 fmpz_set_ui(mFmpzCharac, mCharac);
16 mGenerator = n_primitive_root_prime(mCharac);
17}
18
24
26{
27 o << "AZZFlint/" << characteristic();
28}
29
32 bool p_one,
33 bool p_plus,
34 bool p_parens) const
35{
36 (void) p_parens;
37 long n = coerceToLongInteger(a);
38 if (n < 0)
39 {
40 o << '-';
41 n = -n;
42 }
43 else if (p_plus)
44 o << '+';
45 if (p_one || n != 1) o << n;
46}
47
49 const elem f,
50 int first_var,
51 ring_elem &result) const
52{
53 (void) first_var;
54 long a = coerceToLongInteger(f);
55 result = map->get_ring()->from_long(a);
56}
57
58long ARingZZpFlint::discreteLog(const elem &a) const
59{
60 if (is_zero(a)) return -1;
61 long result = n_discrete_log_bsgs(a, mGenerator, mCharac);
62 return result;
63}
64};
65
66// Local Variables:
67// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
68// indent-tabs-mode: nil
69// End:
M2::ARingZZpFlint — Z/p via FLINT's nmod_t precomputed-reciprocal reduction.
M2::ARingZZp — portable Z/p for small primes via log / exp tables.
#define FLINT_RAND_INIT(x)
Definition aring.hpp:59
#define FLINT_RAND_CLEAR(x)
Definition aring.hpp:60
long coerceToLongInteger(const elem &f) const
void elem_text_out(buffer &o, ElementType a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
flint_rand_t mRandomState
void eval(const RingMap *map, const ElementType f, int first_var, ring_elem &result) const
bool is_zero(ElementType f) const
ARingZZpFlint(size_t prime)
size_t characteristic() const
long discreteLog(const elem &a) const
void text_out(buffer &o) const
virtual ring_elem from_long(long n) const =0
const Ring * get_ring() const
Definition ringmap.hpp:111
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
VALGRIND_MAKE_MEM_DEFINED & result(result)
Definition aring-CC.cpp:3
RingMap — engine representation of a ring homomorphism.