Aurel . Page on Tue, 20 Jan 2015 11:21:43 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Mixing variables in Mod expressions


What about a warning when having to take gcd of moduli ? It would keep the current behaviour but a student should understand he is doing something wrong.

Aurel

Quoting John Cremona <john.cremona@gmail.com>:

The link does explain the first output in a way that makes sense to
me:   the two moduli are coprime so the common quotient is mod 1 hence
0.

For a beginner, a run-time error might be more informative though,
along the lines of "invalid summands" or "incompatible moduli" -- but
I think that the policy might be to always allow addition between
objects of the same type?

John

On 20 January 2015 at 09:53, Karim Belabas
<Karim.Belabas@math.u-bordeaux.fr> wrote:
Dear John,

* John Cremona [2015-01-20 10:20]:
I am trying to understand the following.  The answer might well be
something like "if you try to do something stupid then you must expect
a stupid answer"

? Mod(x,x^2-3) + Mod(x,x^2-5)
%1 = 0

This is by design. And (IMHO) impossible to fix to get "expected"
results (e.g. POLMOD variables being treated as "mute" variables).

Does the following FAQ explain the situation in a satisfactory way ?

  http://pari.math.u-bordeaux1.fr/faq.html#modular

-- but I was pretending to be a student trying to find the polynomial
satisfied by sqrt(3)+sqrt(5) and doing what seemed natural.

There are various ways to achieve this:

(10:42) gp > algdep(sqrt(3)+sqrt(5), 4)
%1 = x^4 - 16*x^2 + 4

(10:43) gp > polcompositum(x^2-3, x^2-5)
%2 = [x^4 - 16*x^2 + 4]

(10:43) gp > rnfequation(y^2-3, x^2-5)
%3 = x^4 - 16*x^2 + 4

[ all 3 methods can break in various ways, but they can all be made to
work (provably) with extra effort ]

This version works:

? Mod(x,x^2-3) + Mod(y,y^2-5)
%2 = Mod(x + Mod(y, y^2 - 5), x^2 - 3)
? a = Mod(x,x^2-3) + Mod(y,y^2-5)
%3 = Mod(x + Mod(y, y^2 - 5), x^2 - 3)
? a^2-8
%4 = Mod(Mod(2*y, y^2 - 5)*x, x^2 - 3)
? (a^2-8)^2
%5 = Mod(Mod(60, y^2 - 5), x^2 - 3)
? (a^2-8)^2-60
%6 = 0
but that is not the point;  result %1 is surely going to confuse people.

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`