1 // m = 0 : Z/mZ \isomorph Z
5 static void int_fprint (cl_heap_modint_ring* R, std::ostream& stream, const _cl_MI &x)
7 fprint(stream,R->_retract(x));
10 static const cl_I int_reduce_modulo (cl_heap_modint_ring* R, const cl_I& x)
13 return x; // reducing modulo 0 does nothing
16 // This is the only case where canonhom is injective.
17 static const _cl_MI int_canonhom (cl_heap_modint_ring* R, const cl_I& x)
22 // This is the only case where retract is surjective.
23 static const cl_I int_retract (cl_heap_modint_ring* R, const _cl_MI& x)
29 // This is the only case where random yields an error.
30 static const _cl_MI int_random (cl_heap_modint_ring* R, random_state& randomstate)
34 throw runtime_exception("Z / 0 Z not a finite set - no equidistributed random function.");
35 #if ((defined(__sparc__) || defined(__sparc64__)) && !defined(__GNUC__)) // Sun CC wants a return value
40 static const _cl_MI int_zero (cl_heap_modint_ring* R)
45 static bool int_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
51 static const _cl_MI int_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
53 return _cl_MI(R, x.rep + y.rep);
56 static const _cl_MI int_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
58 return _cl_MI(R, x.rep - y.rep);
61 static const _cl_MI int_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
63 return _cl_MI(R, - x.rep);
66 static const _cl_MI int_one (cl_heap_modint_ring* R)
71 static const _cl_MI int_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
73 return _cl_MI(R, x.rep * y.rep);
76 static const _cl_MI int_square (cl_heap_modint_ring* R, const _cl_MI& x)
78 return _cl_MI(R, square(x.rep));
81 static const cl_MI_x int_recip (cl_heap_modint_ring* R, const _cl_MI& x)
83 var const cl_I& xr = x.rep;
84 if (eq(xr,1) || eq(xr,-1)) { return cl_MI(R,x); }
85 if (zerop(xr)) { throw division_by_0_exception(); }
86 return cl_notify_composite(R,xr);
89 static const cl_MI_x int_div (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
91 var const cl_I& yr = y.rep;
92 if (eq(yr,1)) { return cl_MI(R,x.rep); }
93 if (eq(yr,-1)) { return cl_MI(R,-x.rep); }
94 if (zerop(yr)) { throw division_by_0_exception(); }
95 return cl_notify_composite(R,yr);
98 static const _cl_MI int_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
100 return _cl_MI(R, expt_pos(x.rep,y));
103 static const cl_MI_x int_expt (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
105 if (eq(x.rep,1)) { return cl_MI(R,1); }
106 if (eq(x.rep,-1)) { return cl_MI(R,evenp(y)?1:-1); }
111 return cl_MI(R,expt_pos(x.rep,y));
114 if (zerop(x.rep)) { throw division_by_0_exception(); }
115 return cl_notify_composite(R,x.rep);
118 static cl_modint_setops int_setops = {
123 static cl_modint_addops int_addops = {
130 static cl_modint_mulops int_mulops = {
143 class cl_heap_modint_ring_int : public cl_heap_modint_ring {
144 SUBCLASS_cl_heap_modint_ring()
147 cl_heap_modint_ring_int () : cl_heap_modint_ring (0, &int_setops, &int_addops, &int_mulops) {}
148 // Virtual destructor.
149 ~cl_heap_modint_ring_int () {}