From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: Exposing more math functionality Date: Fri, 27 Aug 2010 08:44:40 -0700 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1282923759 4886 80.91.229.12 (27 Aug 2010 15:42:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 27 Aug 2010 15:42:39 +0000 (UTC) Cc: guile-devel To: No Itisnt Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Aug 27 17:42:36 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Op14c-0000Lr-Tk for guile-devel@m.gmane.org; Fri, 27 Aug 2010 17:42:35 +0200 Original-Received: from localhost ([127.0.0.1]:58195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Op14b-000276-Ng for guile-devel@m.gmane.org; Fri, 27 Aug 2010 11:42:33 -0400 Original-Received: from [140.186.70.92] (port=46902 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Op13i-0001ml-Pc for guile-devel@gnu.org; Fri, 27 Aug 2010 11:41:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Op13X-0005jA-Uf for guile-devel@gnu.org; Fri, 27 Aug 2010 11:41:37 -0400 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:43593 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Op13X-0005j5-Rs for guile-devel@gnu.org; Fri, 27 Aug 2010 11:41:27 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 1C852D1481; Fri, 27 Aug 2010 11:41:27 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=eW3l/xYbdRqQ cyTw6jnMB3b4wUo=; b=TSEx0SDhxyMWFveeyzu2qoUxShgtSGdkbVwGf65Py7tJ FWl4PSsV7pdHpUHWKpR9cu9bsadgK1dKjY8digmN7uYWhyYUkb5r1sQhggZMLgPz l/3ZtLVS+6lUrkLuLD/GHI76q8s9HvSehyvgQAOahTdv8aAt0rn8qXdLlPHNM4A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=DXXS6P P0eTwmx3V6KB9G6bfynV2u/o7b4rMhynF97+CQsIZ62Rs50yos4EMBgg9xe3mxOW 4o8xkntSb2O/dao9MGbjm83XETNXCWpl88DrJGDNuwuYL8NSKg7t8niqpF2E7MyG 78mYTSJ6pZq1qXfjgNg6bxUinrk3GDITpG20M= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 09483D147F; Fri, 27 Aug 2010 11:41:26 -0400 (EDT) Original-Received: from unquote.localdomain (unknown [75.28.21.123]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 6D98BD147E; Fri, 27 Aug 2010 11:41:24 -0400 (EDT) In-Reply-To: (Andy Wingo's message of "Thu, 19 Aug 2010 09:04:22 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: 8D4A5ADA-B1F1-11DF-A602-030CEE7EF46B-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:10792 Archived-At: On Thu 19 Aug 2010 09:04, Andy Wingo writes: > Regarding modf -- it seems that the R6RS extends the definition of > `modulo' (called `mod') to be defined over the real numbers. > > (mod 10 3) =3D> 1 > (mod 10 3.0) =3D> 1.0 > (mod 10 3.1) =3D> 0.7 > > This appears to be a compatible extension of the R5RS' `modulo', so we > should just extend our definition. That way we can avoid adding another > symbol. This was a mistaken impression, something I realized while trying to implement this. From the R6RS rationale, section 11.6.6: div and mod Given arithmetic on exact integer objects of arbitrary precision, it is a trivial matter to derive signed and unsigned integer types of finite range from it by modular reduction. For example 32-bit signed two-complement arithmetic behaves like computing with the residue classes =E2=80=9Cmod 232 =E2=80=9D, where the set {=E2=88=92231= , . . . , 231 =E2=88=92 1} has been chosen to represent the residue classes. Likewise, unsigned 32-bit arithmetic also behaves like computing =E2=80=9Cmod 232 =E2=80= =9D, but with a different set of representatives {0, . . . , 232 =E2=88=92 1}. Unfortunately, the R5 RS operations quotient, remainder, and modulo are not ideal for this purpose. In the following example, remainder fails to transport the additive group structure of the integers over to the residues modulo 3. =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (remainder (+ -2 3) 3) =3D=E2=87=92 1 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (remainder (+ (remainder -2 3) (remainder 3 3)) 3) =3D=E2=87=92 -2 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 In fact, modulo should have been used, producing residues in {0, 1, 2}. For modular reduction with symmetric residues, i.e., in {=E2=88=92= 1, 0, 1} in the example, it is necessary to define a more complicated reduction altogether. =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Therefore, quotient, remainder, and modulo have been replaced in R6 RS by the div, mod, div0, and mod0 procedures, which are more useful when implementing modular reduction. The underlying mathematical functions div, mod, div0 , and mod0 (see report section 11.7.3) have been adapted from the div and mod operations by Egner et al. [11]. They differ in the representatives from the residue classes they return: div and mod always compute a nonnegative residue, whereas div0 and mod0 compute a residue from a set centered on 0. The former can be used, for example, to implement unsigned fixed-width arithmetic, whereas the latter correspond to two=E2=80=99s-complement arithmetic. =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 These operations differ slightly from the div and mod operations from Egner et al. The latter make both operations available through a single pair of operations that distinguish between the two cases for residues by the sign of the divisor (as well as returning 0 for a zero divisor). Splitting the operations into two sets of procedures avoids potential confusion. =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 The procedures modulo, remainder, and quotient from R5RS can easily be defined in terms of div and mod. =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 So I'm not sure what to do exactly. If Scheme people are happy with div and mod, as in the R6RS, then we should implement them and make them the default, implementing quotient, modulo, and remainder in terms of them. Hmm. Andy --=20 http://wingolog.org/