Opened 6 years ago

# Bug with products of symbolic variables with modular integers — at Version 12

Reported by: Owned by: tmonteil major sage-duplicate/invalid/wontfix symbolics kcrisman, slelievre N/A

As reported on this ask question

```sage: _ = var('A,B')
sage: (A + 3*B)*Zmod(9)(6)
0*B
```

while the result should be `6*A`. There is even (with the 6.6 Linux tarball)

```sage: (3*A + 3*B + 1)*Zmod(9)(6)
6
sage: (3*A + 3*B)*Zmod(9)(6)
<------------ !!
sage:
```

### comment:1 Changed 6 years ago by jdemeyer

• Description modified (diff)

### comment:2 Changed 6 years ago by jdemeyer

• Description modified (diff)

### comment:3 Changed 6 years ago by jdemeyer

• Summary changed from Bug with matrice products over Symbolic Ring with modular integers to Bug with products of symbolic variables with modular integers

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

• Description modified (diff)

Thanks for isolating the problem.

### comment:5 Changed 6 years ago by kcrisman

Thanks very much to both for reporting and simplifying this.

### comment:6 follow-up: ↓ 10 Changed 6 years ago by nbruin

A different issue, but it might be related:

```sage: F=sum((i+1)*x^i for i in [0..20])
sage: G=sum(Zmod(7)(i+1)*x^i for i in [0..20])
sage: F*Zmod(7)(1) - G
x^19 + 2*x^18 + 0*x^13 + 0*x^6
sage: G*Zmod(7)(1) - G
0
```

so there seems to be something fishy with symbolic multiplication involving integers and elements of Z/n in general. It's not just a zero-divisor problem.

It's not just powers either:

```sage: V=[SR.var("x%s"%i) for i in [0..20]]
sage: F=sum((i+1)*V[i] for i in [0..20])
sage: G=sum(Zmod(7)(i+1)*V[i] for i in [0..20])
sage: sage: F*Zmod(7)(1)-G
-x0 + 0*x13 + 6*x14 + 0*x20 + 3*x3 + 0*x6
sage: F-G
14*x13 + 21*x20 + 7*x6
```

The last one is correct, since the terms with x6, x20 and x13 are really missing from G. This illustrates why mixing characteristics in SR is always going to be a mess (even if non-zero characteristic works properly otherwise).

### comment:7 Changed 6 years ago by tmonteil

It seems to be a pynac/ginac issue, right ? So what should we do on our side ? Add a stopgap during conversion/coercion Zmod(n) -> SR ?

### comment:8 Changed 6 years ago by kcrisman

(Or even just disallow it?)

### comment:9 Changed 6 years ago by rws

This is working in pynac-0.4.1 (but not 0.3.9.1).

EDIT: I meant the original case.

Last edited 6 years ago by rws (previous) (diff)

### comment:10 in reply to: ↑ 6 Changed 6 years ago by rws

It's not just powers either:

```sage: V=[SR.var("x%s"%i) for i in [0..20]]
sage: F=sum((i+1)*V[i] for i in [0..20])
sage: G=sum(Zmod(7)(i+1)*V[i] for i in [0..20])
sage: sage: F*Zmod(7)(1)-G
-x0 + 0*x13 + 6*x14 + 0*x20 + 3*x3 + 0*x6
sage: F-G
14*x13 + 21*x20 + 7*x6
```

This is different in 0.4.1:

```sage: sage: sage: F*Zmod(7)(1)-G
-x0 + 0*x13 + 0*x20 + 4*x9
sage: F-G
14*x13 + 21*x20 + 7*x6
sage: F
x0 + 2*x1 + 11*x10 + 12*x11 + 13*x12 + 14*x13 + 15*x14 + 16*x15 + 17*x16 + 18*x17 + 19*x18 + 20*x19 + 3*x2 + 21*x20 + 4*x3 + 5*x4 + 6*x5 + 7*x6 + 8*x7 + 9*x8 + 10*x9
sage: G
x0 + 2*x1 + 4*x10 + 5*x11 + 6*x12 + x14 + 2*x15 + 3*x16 + 4*x17 + 5*x18 + 6*x19 + 3*x2 + 4*x3 + 5*x4 + 6*x5 + x7 + 2*x8 + 3*x9
```

EDIT: Added `F`,`G`.

Last edited 6 years ago by rws (previous) (diff)

### comment:11 Changed 6 years ago by rws

Correction: this is not pynac-0.4.1 but pynac master. Narrowing down the reponsible change...

### comment:12 Changed 6 years ago by rws

• Description modified (diff)
Note: See TracTickets for help on using tickets.