Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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?


In reply to Using modular numbers with Math::Pari by hv

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2018-06-20 23:33 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (117 votes). Check out past polls.