| 2556 | Check if multiplication works when content is in `F_{2^k}`, |
| 2557 | examples from :trac:`13107`:: |
| 2558 | |
| 2559 | sage: var('c1,c2,c3,r1,r2') |
| 2560 | (c1, c2, c3, r1, r2) |
| 2561 | sage: ff.<z> = GF(2**8, 'z') |
| 2562 | sage: ex = -(c1 + r2 - c2*r1)/c3 |
| 2563 | sage: ex.substitute(r1=z, r2=z) |
| 2564 | -(c1 + z*c2 + z)/c3 |
| 2565 | |
| 2566 | Note the content and the leading coefficient of the numerator after |
| 2567 | the substitution:: |
| 2568 | |
| 2569 | sage: num = ex.op[0].subs({r1: z, r2: z}); num |
| 2570 | -c1 + z*c2 + z |
| 2571 | sage: num.leading_coefficient(c1) |
| 2572 | -1 |
| 2573 | sage: num.content(c1) |
| 2574 | 1 |
| 2575 | sage: num.content(c1).pyobject().parent() |
| 2576 | Finite Field in z of size 2^8 |
| 2577 | |
| 2578 | The leading coefficient is a negative number. The normalization process |
| 2579 | tries to convert it to a positive number and extract the content, by |
| 2580 | multiplying by ``-1/c``. However, the content is in a field of |
| 2581 | characteristic 2, so negating it does not change the leading |
| 2582 | coefficient. |
| 2583 | |
| 2584 | Another example where there is no problem:: |
| 2585 | |
| 2586 | sage: ex = -(r2 - c2*r1)/c3 |
| 2587 | sage: num = ex.op[0].subs({r1: z, r2: z}); num |
| 2588 | z*c2 + z |
| 2589 | sage: num.leading_coefficient(c2) |
| 2590 | z |
| 2591 | sage: num.content(c2) |
| 2592 | 1 |
| 2593 | sage: num.content(c2).pyobject().parent() |
| 2594 | Finite Field in z of size 2^8 |
| 2595 | |
| 2596 | Since the leading coefficient is not negative, no normalization is |
| 2597 | performed. |
| 2598 | |
| 2599 | The leading coefficient of the expression depends on the order of the |
| 2600 | variables, which is chosen to be lexicographic in Sage. Hence, using |
| 2601 | different variable names may change behavior and hide the bug. To cover |
| 2602 | these cases we test with different variable names:: |
| 2603 | |
| 2604 | sage: var('a,b') |
| 2605 | (a, b) |
| 2606 | sage: ex = -(c1 + b - c2*a)/c3 |
| 2607 | sage: ex.substitute(a=z, b=z) |
| 2608 | -(c1 + z*c2 + z)/c3 |
| 2609 | sage: var('x1,x2,x3') |
| 2610 | (x1, x2, x3) |
| 2611 | sage: ex = -(x1 + r2 - x2*r1)/x3 |
| 2612 | sage: ex.substitute(a=z, b=z) |
| 2613 | (r1*x2 - r2 - x1)/x3 |