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)
33 cl_unused randomstate;
34 throw runtime_exception("Z / 0 Z not a finite set - no equidistributed random function.");
37 static const _cl_MI int_zero (cl_heap_modint_ring* R)
42 static bool int_zerop (cl_heap_modint_ring* R, const _cl_MI& x)
48 static const _cl_MI int_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
50 return _cl_MI(R, x.rep + y.rep);
53 static const _cl_MI int_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
55 return _cl_MI(R, x.rep - y.rep);
58 static const _cl_MI int_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
60 return _cl_MI(R, - x.rep);
63 static const _cl_MI int_one (cl_heap_modint_ring* R)
68 static const _cl_MI int_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
70 return _cl_MI(R, x.rep * y.rep);
73 static const _cl_MI int_square (cl_heap_modint_ring* R, const _cl_MI& x)
75 return _cl_MI(R, square(x.rep));
78 static const cl_MI_x int_recip (cl_heap_modint_ring* R, const _cl_MI& x)
80 var const cl_I& xr = x.rep;
81 if (eq(xr,1) || eq(xr,-1)) { return cl_MI(R,x); }
82 if (zerop(xr)) { throw division_by_0_exception(); }
83 return cl_notify_composite(R,xr);
86 static const cl_MI_x int_div (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
88 var const cl_I& yr = y.rep;
89 if (eq(yr,1)) { return cl_MI(R,x.rep); }
90 if (eq(yr,-1)) { return cl_MI(R,-x.rep); }
91 if (zerop(yr)) { throw division_by_0_exception(); }
92 return cl_notify_composite(R,yr);
95 static const _cl_MI int_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
97 return _cl_MI(R, expt_pos(x.rep,y));
100 static const cl_MI_x int_expt (cl_heap_modint_ring* R, const _cl_MI& x, const cl_I& y)
102 if (eq(x.rep,1)) { return cl_MI(R,1); }
103 if (eq(x.rep,-1)) { return cl_MI(R,evenp(y)?1:-1); }
108 return cl_MI(R,expt_pos(x.rep,y));
111 if (zerop(x.rep)) { throw division_by_0_exception(); }
112 return cl_notify_composite(R,x.rep);
115 static cl_modint_setops int_setops = {
120 static cl_modint_addops int_addops = {
127 static cl_modint_mulops int_mulops = {
140 class cl_heap_modint_ring_int : public cl_heap_modint_ring {
141 SUBCLASS_cl_heap_modint_ring()
144 cl_heap_modint_ring_int () : cl_heap_modint_ring (0, &int_setops, &int_addops, &int_mulops) {}
145 // Virtual destructor.
146 ~cl_heap_modint_ring_int () {}