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 fprint(std::cerr, "Z / 0 Z not a finite set - no equidistributed random function.\n");
36 #if ((defined(__sparc__) || defined(__sparc64__)) && !defined(__GNUC__)) // Sun CC wants a return value
41 static const _cl_MI int_zero (cl_heap_modint_ring* R)
46 static cl_boolean int_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
52 static const _cl_MI int_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
54 return _cl_MI(R, x.rep + y.rep);
57 static const _cl_MI int_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
59 return _cl_MI(R, x.rep - y.rep);
62 static const _cl_MI int_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
64 return _cl_MI(R, - x.rep);
67 static const _cl_MI int_one (cl_heap_modint_ring* R)
72 static const _cl_MI int_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
74 return _cl_MI(R, x.rep * y.rep);
77 static const _cl_MI int_square (cl_heap_modint_ring* R, const _cl_MI& x)
79 return _cl_MI(R, square(x.rep));
82 static const cl_MI_x int_recip (cl_heap_modint_ring* R, const _cl_MI& x)
84 var const cl_I& xr = x.rep;
85 if (eq(xr,1) || eq(xr,-1)) { return cl_MI(R,x); }
86 if (zerop(xr)) { cl_error_division_by_0(); }
87 return cl_notify_composite(R,xr);
90 static const cl_MI_x int_div (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
92 var const cl_I& yr = y.rep;
93 if (eq(yr,1)) { return cl_MI(R,x.rep); }
94 if (eq(yr,-1)) { return cl_MI(R,-x.rep); }
95 if (zerop(yr)) { cl_error_division_by_0(); }
96 return cl_notify_composite(R,yr);
99 static const _cl_MI int_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
101 return _cl_MI(R, expt_pos(x.rep,y));
104 static const cl_MI_x int_expt (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
106 if (eq(x.rep,1)) { return cl_MI(R,1); }
107 if (eq(x.rep,-1)) { return cl_MI(R,evenp(y)?1:-1); }
112 return cl_MI(R,expt_pos(x.rep,y));
115 if (zerop(x.rep)) { cl_error_division_by_0(); }
116 return cl_notify_composite(R,x.rep);
119 static cl_modint_setops int_setops = {
124 static cl_modint_addops int_addops = {
131 static cl_modint_mulops int_mulops = {
144 class cl_heap_modint_ring_int : public cl_heap_modint_ring {
145 SUBCLASS_cl_heap_modint_ring()
148 cl_heap_modint_ring_int () : cl_heap_modint_ring (0, &int_setops, &int_addops, &int_mulops) {}
149 // Virtual destructor.
150 ~cl_heap_modint_ring_int () {}