From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7A52DBBAF for ; Tue, 10 Aug 2010 15:21:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMEAM/vYEzUNQQjmWdsb2JhbACTYYx2FQEBAQEBCAsKBxEiBAMBArMvAY8pBYU6iT4 X-IronPort-AV: E=Sophos;i="4.55,348,1278280800"; d="scan'208";a="67462746" Received: from relay02ant.iops.be ([212.53.4.35]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Aug 2010 15:21:32 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by relay02ant.iops.be (Postfix) with ESMTP id 2934C4020395; Tue, 10 Aug 2010 15:21:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iops.be; h= content-transfer-encoding:content-type:content-type:mime-version :x-mailer:organization:references:in-reply-to:from:from:subject :subject:message-id:date:date:received:received:received; s= scooby; i=postadmin@iops.be; t=1281446489; bh=t9FtLFvYdD6TOhALDd dfnmp7RWDXPzd279zph9bPjlM=; b=tAhyDJ39XUMcfGF8se3yMrpsMj71cEH0Cw O3CQGv3UUEJbv6L49fFvfLBhM4CwkIW3AE4i8VGlItUnlG8qSD7E1jr7UO6WDJ5Z a+oHqd3wfnSzhP/pg7DZnsaS+Xajrk1OnCqhgZ2cxRnWsEs+uzjPRuZ0mZy1SRaI B1Z3jvF6M= X-Virus-Scanned: amavisd-new at iops.be Received: from relay02ant.iops.be ([127.0.0.1]) by localhost (bdell035.dcn.iops.be [127.0.0.1]) (amavisd-new, port 10026) with LMTP id OSNU0V7w2IN4; Tue, 10 Aug 2010 15:21:29 +0200 (CEST) Received: from poincare (cust-7-186-109-94.dyn.as47377.net [94.109.186.7]) by relay02ant.iops.be (Postfix) with ESMTP id CBF2E40202BD; Tue, 10 Aug 2010 15:21:29 +0200 (CEST) Received: from localhost ([::1]) by poincare with esmtp (Exim 4.72) (envelope-from ) id 1Oiolk-0001fL-PI; Tue, 10 Aug 2010 15:21:28 +0200 Date: Tue, 10 Aug 2010 15:21:28 +0200 (CEST) Message-Id: <20100810.152128.473385361362799721.Christophe.Troestler+ocaml@umons.ac.be> To: lists+caml@jimpryor.net Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Errors in Bignum arithmetic? From: Christophe TROESTLER In-Reply-To: <20100810123410.GC16292@vaio.jimpryor.net> References: <20100810123410.GC16292@vaio.jimpryor.net> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons Return-Receipt-To: Christophe.Troestler@umons.ac.be Disposition-Notification-To: Christophe.Troestler@umons.ac.be X-Mailer: Mew version 7.0.50 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; bignum:01 christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 ocaml:01 val:01 val:01 pred:01 bool:01 bool:01 delimited:01 overloading:01 toplevel:01 On Tue, 10 Aug 2010 08:34:10 -0400, Jim Pryor wrote: >=20 > 3**(561-1) mod 561 =3D 1 > 5**(1105-1) mod 1105 =3D 1 > 5**(2465-1) mod 2465 =3D 1 > 5**(10585-1) mod 10585 =3D 1 >=20 > However, in (my manual Linux x86_64 build of) OCaml 3.12, all of those = fail: >=20 > # open Num;; > # let b1,b3,b5 =3D num_of_int 1,num_of_int 3, num_of_int 5;; > val b1 : Num.num =3D > val b3 : Num.num =3D > val b5 : Num.num =3D > # let check p a =3D let bp,ba =3D num_of_int p,num_of_int a in > let x =3D mod_num (power_num ba (pred_num bp)) bp in > eq_num x b1;; > val check : int -> int -> bool =3D > # List.map (fun (p,a) -> check p a) [(561,3);(1105,5);(2465,5);(10585,5= )];; > - : bool list =3D [false; false; false; false] As a side remark, with Delimited overloading , your code can read much clearer: let check p a =3D Num.(let p =3D of_int p in (of_int a)**(p - 1) mod p =3D 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 =3D My 0.02=A4, C.