Ewan Delanoy on Mon, 12 Nov 2012 18:35:45 +0100


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

Using Mod inside functions


Hello all,

 below is  some PARI-GP code showing a function called âcleaner_for_leading_coefficient
â that does not work.
 Surprisingly, however, everything goes fine if one executes all the instructions wrapped inside the function step by step, as shown in the code below.
  Judging from the error message, the problem is related to my use of âModâ inside the function.
 Thanks in advance for any help.

Ewan

                 GP/PARI CALCULATOR Version 2.5.2 (released)
          i386 running darwin (x86-64/GMP-5.0.4 kernel) 64-bit version
           compiled: Sep 18 2012, gcc-4.5.4 (MacPorts gcc45 4.5.4_5)
                 (readline v6.2 enabled, extended help enabled)

                     Copyright (C) 2000-2011 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes
WITHOUT ANY WARRANTY WHATSOEVER.

Type ? for help, \q to quit.
Type ?12 for how to get moral (and possibly technical) support.

parisize = 8000000, primelimit = 500509
? paul1=(-6566965496*beth^5 + 1069572966280*beth^3 - 23940418649316*beth)*nuu^3 + (3283482748*beth^6 - 703675242270*beth^4 + 26192533760510*beth^2 + 184509608906896)*nuu^2 + (-938137928*beth^7 + 379974579348*beth^5 - 34472816584284*beth^3 + 39850128820580*beth)*nuu + (117267241*beth^8 - 63329096558*beth^6 + 8591936284087*beth^4 - 17222997429586*beth^2 - 15148802119203)
%1 = 117267241*beth^8 - 938137928*nuu*beth^7 + (3283482748*nuu^2 - 63329096558)*beth^6 + (-6566965496*nuu^3 + 379974579348*nuu)*beth^5 + (-703675242270*nuu^2 + 8591936284087)*beth^4 + (1069572966280*nuu^3 - 34472816584284*nuu)*beth^3 + (26192533760510*nuu^2 - 17222997429586)*beth^2 + (-23940418649316*nuu^3 + 39850128820580*nuu)*beth + (184509608906896*nuu^2 - 15148802119203)
? paul2=30020413696*beth^8 - 1801531152512*beth^6 + 27258536763952*beth^4 - 7293106986984*beth^2 + 468152903089
%2 = 30020413696*beth^8 - 1801531152512*beth^6 + 27258536763952*beth^4 - 7293106986984*beth^2 + 468152903089
?
?
?   cleaner_for_leading_coefficient(pol,annulator,var_x,var_y)=
{
  local(symb,temp,temp2,temp3,agatha);
  symb=Mod(agatha,subst(annulator,var_x,agatha));
  temp=pollead(pol,var_y);
  temp2=subst(temp,var_x,symb);
  temp3=1/temp2;
  return(lift(temp3));

}
?
? first_trial=cleaner_for_leading_coefficient(paul1,paul2,beth,nuu)
  ***   at top-level: first_trial=cleaner_for_leading_
  ***                             ^--------------------
  ***   in function cleaner_for_leading_coefficient:
  ***   ...(temp,var_x,symb);temp3=1/temp2;return(lift(t
  ***                               ^--------------------
  *** _/_: impossible inverse modulo: Mod(0, 468152903089).
  ***   Break loop: type 'break' to go back to GP
break>
break> break

? pol=paul1
%4 = 117267241*beth^8 - 938137928*nuu*beth^7 + (3283482748*nuu^2 - 63329096558)*beth^6 + (-6566965496*nuu^3 + 379974579348*nuu)*beth^5 + (-703675242270*nuu^2 + 8591936284087)*beth^4 + (1069572966280*nuu^3 - 34472816584284*nuu)*beth^3 + (26192533760510*nuu^2 - 17222997429586)*beth^2 + (-23940418649316*nuu^3 + 39850128820580*nuu)*beth + (184509608906896*nuu^2 - 15148802119203)
?   annulator=paul2
%5 = 30020413696*beth^8 - 1801531152512*beth^6 + 27258536763952*beth^4 - 7293106986984*beth^2 + 468152903089
?   var_x=beth
%6 = beth
?   var_y=nuu
%7 = nuu
?   symb=Mod(agatha,subst(annulator,var_x,agatha))
%8 = Mod(agatha, 30020413696*agatha^8 - 1801531152512*agatha^6 + 27258536763952*agatha^4 - 7293106986984*agatha^2 + 468152903089)
?   temp=pollead(pol,var_y)
%9 = -6566965496*beth^5 + 1069572966280*beth^3 - 23940418649316*beth
?   temp2=subst(temp,var_x,symb)
%10 = Mod(-6566965496*agatha^5 + 1069572966280*agatha^3 - 23940418649316*agatha, 30020413696*agatha^8 - 1801531152512*agatha^6 + 27258536763952*agatha^4 - 7293106986984*agatha^2 + 468152903089)
?   temp3=1/temp2
%11 = Mod(20969910094342573625112778762878346210816/7852515084056523941826305327703635391125038356414739097*agatha^7 - 1260104881146110861084127972946836114952704/7852515084056523941826305327703635391125038356414739097*agatha^5 + 19097036931589896718062702970453586827359488/7852515084056523941826305327703635391125038356414739097*agatha^3 - 5124393596497362934274073300552845177336080/7852515084056523941826305327703635391125038356414739097*agatha, 30020413696*agatha^8 - 1801531152512*agatha^6 + 27258536763952*agatha^4 - 7293106986984*agatha^2 + 468152903089)
?   second_trial=lift(temp3)
%12 = 20969910094342573625112778762878346210816/7852515084056523941826305327703635391125038356414739097*agatha^7 - 1260104881146110861084127972946836114952704/7852515084056523941826305327703635391125038356414739097*agatha^5 + 19097036931589896718062702970453586827359488/7852515084056523941826305327703635391125038356414739097*agatha^3 - 5124393596497362934274073300552845177336080/7852515084056523941826305327703635391125038356414739097*agatha