1 // m = 0 : Z/mZ \isomorph Z
3 static void int_fprint (cl_heap_modint_ring* R, cl_ostream stream, const _cl_MI &x)
5 fprint(stream,R->_retract(x));
8 static const cl_I int_reduce_modulo (cl_heap_modint_ring* R, const cl_I& x)
11 return x; // reducing modulo 0 does nothing
14 // This is the only case where canonhom is injective.
15 static const _cl_MI int_canonhom (cl_heap_modint_ring* R, const cl_I& x)
20 // This is the only case where retract is surjective.
21 static const cl_I int_retract (cl_heap_modint_ring* R, const _cl_MI& x)
27 // This is the only case where random yields an error.
28 static const _cl_MI int_random (cl_heap_modint_ring* R, cl_random_state& randomstate)
32 fprint(cl_stderr, "Z / 0 Z not a finite set - no equidistributed random function.\n");
34 #if ((defined(__sparc__) || defined(__sparc64__)) && !defined(__GNUC__)) // Sun CC wants a return value
39 static const _cl_MI int_zero (cl_heap_modint_ring* R)
44 static cl_boolean int_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
50 static const _cl_MI int_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
52 return _cl_MI(R, x.rep + y.rep);
55 static const _cl_MI int_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
57 return _cl_MI(R, x.rep - y.rep);
60 static const _cl_MI int_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
62 return _cl_MI(R, - x.rep);
65 static const _cl_MI int_one (cl_heap_modint_ring* R)
70 static const _cl_MI int_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
72 return _cl_MI(R, x.rep * y.rep);
75 static const _cl_MI int_square (cl_heap_modint_ring* R, const _cl_MI& x)
77 return _cl_MI(R, square(x.rep));
80 static const cl_MI_x int_recip (cl_heap_modint_ring* R, const _cl_MI& x)
82 var const cl_I& xr = x.rep;
83 if (eq(xr,1) || eq(xr,-1)) { return cl_MI(R,x); }
84 if (zerop(xr)) { cl_error_division_by_0(); }
85 return cl_notify_composite(R,xr);
88 static const cl_MI_x int_div (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
90 var const cl_I& yr = y.rep;
91 if (eq(yr,1)) { return cl_MI(R,x.rep); }
92 if (eq(yr,-1)) { return cl_MI(R,-x.rep); }
93 if (zerop(yr)) { cl_error_division_by_0(); }
94 return cl_notify_composite(R,yr);
97 static const _cl_MI int_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
99 return _cl_MI(R, expt_pos(x.rep,y));
102 static const cl_MI_x int_expt (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
104 if (eq(x.rep,1)) { return cl_MI(R,1); }
105 if (eq(x.rep,-1)) { return cl_MI(R,evenp(y)?1:-1); }
110 return cl_MI(R,expt_pos(x.rep,y));
113 if (zerop(x.rep)) { cl_error_division_by_0(); }
114 return cl_notify_composite(R,x.rep);
117 static cl_modint_setops int_setops = {
122 static cl_modint_addops int_addops = {
129 static cl_modint_mulops int_mulops = {
142 class cl_heap_modint_ring_int : public cl_heap_modint_ring {
143 SUBCLASS_cl_heap_modint_ring()
146 cl_heap_modint_ring_int () : cl_heap_modint_ring (0, &int_setops, &int_addops, &int_mulops) {}
147 // Virtual destructor.
148 ~cl_heap_modint_ring_int () {}