# Ticket #3124(closed defect: fixed)

Opened 5 years ago

## [with patch, positive review] bug in solve_mod

Reported by: Owned by: was mhansen major sage-3.3 basic arithmetic AlexGhitza

### Description

```Hi,

I think this is a bug. Solving x == y mod 3 works fine:

sage: var('x,y')
(x, y)
sage: solve_mod([x == y], 3)
[(0, 0), (1, 1), (2, 2)]

But solving mod 2 blows up:

sage: solve_mod([x == y], 2)
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/carlo/work/sagestuff/<ipython console> in <module>()

/home/carlo/sage/local/lib/python2.5/site-packages/sage/calculus/equations.py
in solve_mod(eqns, modulus)
1339     S = MPolynomialRing(R, len(vars), vars)
1340     eqns_mod = [S(eq) if is_SymbolicExpression(eq) else \
-> 1341                   S(eq.lhs() - eq.rhs()) for eq in eqns]
1342
1343     ans = []

/home/carlo/sage/local/lib/python2.5/site-packages/sage/rings/polynomial/multi_polynomial_ring.py
in __call__(self, x, check)
380
381         elif hasattr(x, '_polynomial_'):
--> 382             return x._polynomial_(self)
383
384         elif isinstance(x, str) and x in self.variable_names():

/home/carlo/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py
in _polynomial_(self, R)
1809         if len(sub) == 0:
1810             try:
-> 1811                 return R(B(self))
1812             except TypeError:
1813                 if len(vars) == 1:

/home/carlo/sage/local/lib/python2.5/site-packages/sage/rings/integer_mod_ring.py
in __call__(self, x)
574     def __call__(self, x):
575         try:
--> 576             return integer_mod.IntegerMod(self, x)
577         except (NotImplementedError, PariError):
578             return TypeError, "error coercing to finite field"

/home/carlo/work/sagestuff/integer_mod.pyx in
sage.rings.integer_mod.IntegerMod (sage/rings/integer_mod.c:1731)()

/home/carlo/work/sagestuff/integer_mod.pyx in
sage.rings.integer_mod.IntegerMod_int.__init__
(sage/rings/integer_mod.c:10153)()

/home/carlo/work/sagestuff/integer_ring.pyx in
sage.rings.integer_ring.IntegerRing_class.__call__
(sage/rings/integer_ring.c:4473)()

<type 'exceptions.TypeError'>: unable to convert x (=x - y) to an integer

Any ideas?

--
Carlo Hamalainen
```

## Change History

### comment:1 Changed 5 years ago by mhansen

The underlying issue is that the reprs of the generators of polynomial rings over Z/2Z have minus signs and SymbolicArithmetic?._polynomial_ expects them to not have the signs. I think the appropriate fix would be to fix the printing for the generators of polynomial rings over Z/2Z

```sage: Integers(3)['x,y'].gens()
(x, y)
sage: Integers(2)['x,y'].gens()
(-x, -y)
```
```        for v in vars:
r = repr(v)
for g in G:
if repr(g) == r:
sub.append((v,g))
```

### comment:3 Changed 4 years ago by mhansen

• Owner changed from somebody to mhansen
• Status changed from new to assigned
• Summary changed from bug in solve_mod to [with patch, needs review] bug in solve_mod

This patch also fixes #3125.

### comment:4 Changed 4 years ago by mhansen

And by #3125, I mean #3135.

### comment:5 Changed 4 years ago by AlexGhitza

• Summary changed from [with patch, needs review] bug in solve_mod to [with patch, positive review] bug in solve_mod

Looks good to me.

### comment:6 Changed 4 years ago by AlexGhitza

• Milestone changed from sage-3.4.1 to sage-3.3

### comment:7 Changed 4 years ago by mabshoff

• Status changed from assigned to closed
• Resolution set to fixed

Merged in Sage 3.3.alpha1

Note: See TracTickets for help on using tickets.