caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe TROESTLER <Christophe.Troestler+ocaml@umh.ac.be>
To: lists+caml@jimpryor.net
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Errors in Bignum arithmetic?
Date: Tue, 10 Aug 2010 15:21:28 +0200 (CEST)	[thread overview]
Message-ID: <20100810.152128.473385361362799721.Christophe.Troestler+ocaml@umons.ac.be> (raw)
In-Reply-To: <20100810123410.GC16292@vaio.jimpryor.net>

On Tue, 10 Aug 2010 08:34:10 -0400, Jim Pryor wrote:
> 
> 3**(561-1) mod 561 = 1
> 5**(1105-1) mod 1105 = 1
> 5**(2465-1) mod 2465 = 1
> 5**(10585-1) mod 10585 = 1
> 
> However, in (my manual Linux x86_64 build of) OCaml 3.12, all of those fail:
> 
> # open Num;;
> # let b1,b3,b5 = num_of_int 1,num_of_int 3, num_of_int 5;;
> val b1 : Num.num = <num 1>
> val b3 : Num.num = <num 3>
> val b5 : Num.num = <num 5>
> # let check p a = let bp,ba = num_of_int p,num_of_int a in
>     let x = mod_num (power_num ba (pred_num bp)) bp in
>     eq_num x b1;;
> val check : int -> int -> bool = <fun>
> # List.map (fun (p,a) -> check p a) [(561,3);(1105,5);(2465,5);(10585,5)];;
> - : bool list = [false; false; false; false]

As a side remark, with Delimited overloading
<https://forge.ocamlcore.org/projects/pa-do/>, your code can read much
clearer:

let check p a =
  Num.(let p = of_int p in
       (of_int a)**(p - 1) mod p = 1);;

You can also easily check your examples in the toplevel -- after
issuing #require "pa_do.num" --

# Num.(3**(561-1) mod 561);;
- : Num.num = <num 375>

My 0.02€,
C.


      parent reply	other threads:[~2010-08-10 13:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-10 12:34 Jim Pryor
2010-08-10 12:41 ` [Caml-list] " Thomas Fischbacher
2010-08-10 12:46 ` David House
2010-08-10 13:42   ` Jim Pryor
2010-08-10 12:52 ` Ronan Le Hy
2010-08-10 13:21 ` Christophe TROESTLER [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100810.152128.473385361362799721.Christophe.Troestler+ocaml@umons.ac.be \
    --to=christophe.troestler+ocaml@umh.ac.be \
    --cc=caml-list@yquem.inria.fr \
    --cc=lists+caml@jimpryor.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).