From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bengt Richter Newsgroups: gmane.lisp.guile.bugs Subject: bug#40744: guile-2.2.4 (integer-length 0) erroneously returns 0, not 1 Date: Sat, 24 Jul 2021 19:12:08 +0200 Message-ID: <20210724171208.GA11765@LionPure> References: <20200421130344.GA9369@LionPure> <20200425213350.GA10462@LionPure> <20200428200810.7d619d27@alma-ubu> <20200428204110.50e47ad0@alma-ubu> <87pmvjarn7.fsf@trouble.defaultvalue.org> Reply-To: Bengt Richter Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15868"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: =?UTF-8?Q?Bj=C3=B6rn_?= =?UTF-8?Q?H=C3=B6fling?= , 40744@debbugs.gnu.org To: Rob Browning Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat Jul 24 19:13:07 2021 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m7LD0-0003xT-VY for guile-bugs@m.gmane-mx.org; Sat, 24 Jul 2021 19:13:07 +0200 Original-Received: from localhost ([::1]:57980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m7LD0-0003hu-2O for guile-bugs@m.gmane-mx.org; Sat, 24 Jul 2021 13:13:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m7LCw-0003hk-Jw for bug-guile@gnu.org; Sat, 24 Jul 2021 13:13:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m7LCw-0003oz-CZ for bug-guile@gnu.org; Sat, 24 Jul 2021 13:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m7LCw-0007Ct-9Y for bug-guile@gnu.org; Sat, 24 Jul 2021 13:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bengt Richter Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 24 Jul 2021 17:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40744 X-GNU-PR-Package: guile Original-Received: via spool by 40744-submit@debbugs.gnu.org id=B40744.162714675327665 (code B ref 40744); Sat, 24 Jul 2021 17:13:02 +0000 Original-Received: (at 40744) by debbugs.gnu.org; 24 Jul 2021 17:12:33 +0000 Original-Received: from localhost ([127.0.0.1]:46859 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m7LCS-0007C9-RO for submit@debbugs.gnu.org; Sat, 24 Jul 2021 13:12:33 -0400 Original-Received: from imta-37.everyone.net ([216.200.145.37]:40896 helo=imta-38.everyone.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m7LCO-0007Bw-K1 for 40744@debbugs.gnu.org; Sat, 24 Jul 2021 13:12:32 -0400 Original-Received: from pps.filterd (omta004.sj2.proofpoint.com [127.0.0.1]) by imta-38.everyone.net (8.16.0.43/8.16.0.43) with SMTP id 16OH2nxC011413; Sat, 24 Jul 2021 10:12:21 -0700 X-Eon-Originating-Account: GbEDZzLWbb_YO25mu4qgqkK_ND2YCn4vH_chHbP7IFY X-Eon-Dm: m0116787.ppops.net Original-Received: by m0116787.mta.everyone.net (EON-AUTHRELAY2 - 53b921d1) id m0116787.60d3a85b.1d137c; Sat, 24 Jul 2021 10:12:19 -0700 X-Eon-Sig: AQMHrIJg/EnzWa7ezAIAAAAD,55694c33662f9e3165e2bde066b10c20 X-Eip: ouclBmbJ_1VdFqkrorB0RvZY7VH8eCtaMvcLX9k5aGI Content-Disposition: inline In-Reply-To: <87pmvjarn7.fsf@trouble.defaultvalue.org> X-Proofpoint-ORIG-GUID: sZKi0eG9RWc1gRynKj02cuD3oQ57jsam X-Proofpoint-GUID: sZKi0eG9RWc1gRynKj02cuD3oQ57jsam X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-24_11:2021-07-23, 2021-07-24 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107240104 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10157 Archived-At: Oops, forgot to reply-all -- sorry about the dup, Rob ;/ On +2021-07-15 22:01:32 -0500, Rob Browning wrote: > > Hmm, the zero result appears to be intentional, i.e. it's mentioned in > the examples here: > > https://www.gnu.org/software/guile/manual/guile.html#Arithmetic > > and is also specified by Chez Scheme and SRFI-60: > > https://www.scheme.com/csug8/numeric.html > https://srfi.schemers.org/srfi-60/srfi-60.html > > -- > Rob Browning > rlb @defaultvalue.org and @debian.org > GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A > GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 I tried to make a pitch for (integer-length 0) =-> 1 in [1] https://lists.gnu.org/archive/html/bug-guile/2020-04/msg00027.html though I now think integer-length is a useful measure of mathematical integervalues that can be generalized to any rational numbers and complex numbers with rational real and imaginary parts. Also their printed representations can have any rational radix other than 1 and negative generalized integer-lengths can be meaningful for length of 1/x vs x (which brings in the zero issue). For the "integer-length" I compute in [1], I would now suggest an alternate name: integer-digits -- the number of concrete digit-value representations it take to represent the polynomial coefficient values in the mathematical polynomial series. I should update [1] to reflect what I am saying here to remove complaints about integer-length 0 etc and talk about integer-digits (or maybe rational-digits or even numeric-digits?) I think scheme's integer-length basically solves for minimum L in in a mapping of rational numbers (limited to integers in its case) for + and minus like [0..2**L) for positive and [-2**L..0) for negative. Those half-open sets correspond, so we can just use the absolute value like abslen here: --8<---------------cut here---------------start------------->8--- #!/usr/bin/env -S guile --no-auto-compile -e main -s !# (use-modules (ice-9 format)) (define (abslen absint) (begin (let*((absval absint) (lm (lambda (aval) (begin (let inner ((n 0) (av aval)) (begin (if (< (integer-expt 2 n) av) (inner (+ 1 n) av) n))))))) (lm absval)))) (define (main args) (begin (or (false-if-exception (begin (display (abslen (abs (string->number (cadr args))))) (newline))) (begin (format #t "\nUsage: ~a NUM -- where NUM is [+ - ] POSITIVE_INTEGER\n" (car args))) (newline)))) --8<---------------cut here---------------end--------------->8--- You might want to call the above something other than integer-length, but it should compute the same result (modulo very limited testing :). As mentioned in Tom's reply to [1], zero makes for a special problem in the general mathematical case, where I think you have to special-case which set of points it should belong to. In the general case numbers map into half-open annuli in the complex plane, where inside and outside the unit circle corresponds to x and 1/x, and 1/0 has to be special-cased. The annulus edge circles are at powers of a rational base, 2 in the binary case, but 4/3 can work. Just not irrationals. (Maybe as named unit values though?) Conventional signed number mappings split an annulus in two to map them, with positives < the splitting circle and negatives >= Something analogous to abslen can be done to find the power of the base that will be the diameter of a circle containing (> not >=) both parts of the split annulus. I haven't done it yet :) Complex numbers have both cartesian and polar representations, so that brings in interesting stuff too. The negative of a complex number as a point in the complex plane is diametrically opposite the origin, but zero has no direction to an opposite of itself :) Defining -0 to be 0 has consequences. (Note that fp hardware does represent -0 :) You might find it amusing to play with the scheme program included in [1] (after you inspect it -- no warranties :). -- Regards, Bengt Richter PS. Shouldn't euclidean-quotient always produce an exact integer? (Inexactness if any can be carried by the remainder)