I can get a modular reciprocal with Pari easily enough, eg:
use Math::Pari qw/ PARI Mod /;
my($n, $p) = map PARI($_), (3, 17);
my $recip = PARI(1) / Mod($n, $p);
print "1 / $n == $recip\n";
1 / 3 == Mod(6,17)
The result "Mod(6,17)" is a modular value, representing the equivalence class of integers equivalent to 6 (mod 17), and that's great.
However I now want to get the "6" out of there as an integer for further work, i.e. to get the "common residue" of that modular number. I haven't found anything in the Math::Pari or Pari/GP docs that tells how to do that, and everything I've tried gives an error:
$int = int($recip);
PARI: *** incorrect type in comparison. at -e line 1.
$int = pari2num($recip);
PARI: *** forbidden assignment t_INTMOD --> t_REAL. at -e line 1.
$int = pari2iv($recip);
PARI: *** incorrect type in gtolong. at -e line 1.
I could pull the value out with a regexp, but that would be silly. Surely there is a simple, efficient way to do this?
Hugo
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.