Bill Allombert on Sun, 22 Oct 2023 22:12:32 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: sumdigits(n,B) doesn't refuse B < -1
|
- To: pari-dev@pari.math.u-bordeaux.fr
- Subject: Re: sumdigits(n,B) doesn't refuse B < -1
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Sun, 22 Oct 2023 22:12:16 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1698005537; c=relaxed/relaxed; bh=JUr0yN/44Ay0oPWa99NJicYWh1QkIesHEL/lSrcWGu0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=v/Z5ObBQ/4V/bdQnoklpyvhgQZO56gjkfn+phq1U9TMibLCYxuDrkL+wExtQ1NM3h2oVUpv4s8JwAX7zwDfnheI9Z6ef77p5vBrZE//hGfN/2HhvtaEnjy19Pa9S4gHH8NnnMorlyVap+Nqv2pith1xoloJhWm4hWP+KFN4r2ifq9EUOK9TlnpY3/n6EFY/pySrWi783nEi7TX00oVXYSe7cll3VEuHZFjAkKONwc9cHa0WXSdWx/2zwKRrp16UOtnYhpVCDijhTkIu4HwmACTBtDo2e044B8eXeNUQMVdvLYz7Whr76DJ27uJxO85TaEoG9u6P6sBk4fT22BKu5YCr4bqeM0fFibUioPm+IN5D4w+7pBl7wpfLk1+zQ70VBs+4ch/DCOwK1R3oKE48jfy7PWilfoMA6K4beHbRhglgU8pSJd1EKbOUI43GTmDyd81zbvyLZT95+rohu6+DQUiQhZgwhEfJIUwNrzOhWqzTJjecr2TzN/mTZFNRy8rF0t7REmT43LIjt1yKTn0Oa9W9C6qBr7mvDFQV8hCpwwUCpi1fTfuLHUbfnW/oenJvIVkxiZ8+Y+K/D6CHJXB7UvRyjfOhVh5YLrtFDqPp3/w3Kbk+dMzzRJHe50SrJrZYP+/iR7ZF5HvW4c7M7SHVzJa8N/k/PjIWPT8X7c7njEDE=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1698005537; cv=none; b=eOZTcY84DxiP4BhI+xwno/xQ6m1/O3rhBMBjdxqoCCrFHn79e0nttdPdixzAuF885xHl4HO1KDsNXNxlS2DTMRBPNlEzFwNPPBeM6U5ioVDzrBDbsrGKcSaOctSgFGkjbU4xyVqI9R1g3gThMuEFUmvRzCQLJUznVOEkn4L+RfSX4m380vqzj9WccvoE3QgrQXeQrfM+i3G4+jhgB1rGR90T0uYqjo57yWbmJ3GhYGSHO6usApQRPvHBdTuERgyqBhvU3sTU+ZTxLK7kihJKKZadlqw2QBqD5OEctlD4EoTm+MQ9+nyaW6zmtL5r08Oum0kqN5DFPlU8gKhELlgwrI4YB/y58C4/ntxrsDt1q/G9fQ4RoIumNgYtiL3O1geExx64IDVPKx+t6QDGhI7r9lBGo8fHgU3s0Eu0QG+o4t50hIIj9XzrU/fhlNs/kIDE8SW1m4+QdD8XxWfMYAulQvIZHht6XyU/X0QciYdcgYAC7WXSNIqDbacDUX+UGw/UJaWDtOpLX6nmNFBROyfr6RfQS/UkfMnBJ3aRNxez4J5d8LrcOPwGQMERXtv8QI6Ug9crtJXJr8xUVWSdaXpkcg3WII1khr+GfZg+mr8gYKEPdKnHv8t1CYoSdJdXF04NCvbRyCywj9T6tkF0l9olUQhq/kAYG4FcpHsh1Wk6YVs=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Delivery-date: Sun, 22 Oct 2023 22:12:33 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1698005537; bh=JUr0yN/44Ay0oPWa99NJicYWh1QkIesHEL/lSrcWGu0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=VpOhmlyXI2hAn9bOCC0NtKWdlC6YzIjBoLx8Mzltl5rFfusy2dSwvDMetRjA56npW 6mchv0r4IkuoB/ZjqKOHgTcpyOR5fExj6UKzeV3GWk5BBpcxEzXLtJXSTdU7N3iHTw w5rWUqJ2y2Z3jXelNAA4XQKalY+zsEm85DVvrbk/Ja/G99IdHskLoxWBLrBfvG7r2b 9kaJI/f4BPVJvPklD6T5CF2ddp5aburRXzNIUhcPfKtVPKiJ5pVhMbh/uF/+tku2ue iRsw3Xdihu8z2lgYynTxDH4UZj6/Fw0RZyYI5ZvnICSS04TnydEGwop/7N4yuf6GS1 ULTq01MLFdNigMQcN85CyQpW9Kc+ZHTNcbxk1w1K9dvEhOcAhJ80ovoL+WBXqYSqD1 wHDo9pjGFK9L7EztfW1xelTZ4Sn0EFtP9n/cj9QxwDgcCOhQA2OggtkCEsL732hb5H 8BG88rubHlXluQE2uC2fkd9mTeAwZZl6T/93/GPK207k/eGGp6dtubZLoxSiBpa/cf qH21TlIHHmkuY32LHNsXxKafUUon43hCVFNggH2wQCG212Voe5OtR1jA6JqSXkBWSM R+LcYEXAQBNZXorW2X0OMdI44zovvSAQPlkDRB2Yt8F0hblyXZEjWJO4TwnfNd6ugx 1aul4x+mr/xET91Gdy4zIZlc=
- In-reply-to: <20231020051242.GA16360@mellifont.in-ulm.de>
- Mail-followup-to: pari-dev@pari.math.u-bordeaux.fr
- References: <ea1efe92-0631-4bab-b934-f3d7878376a0@isolution.nl> <20231020051242.GA16360@mellifont.in-ulm.de>
On Fri, Oct 20, 2023 at 07:12:42AM +0200, Martin Becker wrote:
>
> Hello Pari Devs,
>
> On Tue, Oct 17, 2023 at 09:29:59AM +0200, Ruud H.G. van Tol wrote:
> > ? sumdigits(12345,-4)
> > % 5
> >
> > Expected:
> >
> > *** at top-level: sumdigits(12345,-4)
> > *** ^------------------
> > *** sumdigits: domain error in digits: B < 2
> > *** Break loop: type 'break' to go back to GP prompt
> > break>
>
> While Ruud is certainly right that digits() und sumdigits()
> should behave consistently, negative bases actually do make
> sense, cf. Donald E. Knuth, The art of computer programming,
> vol. 2, Seminumerical algorithms, chapter 4.1, Positional
> number systems, where he discusses, among other things,
> negative bases as well as negative digits.
>
> In base -4, 12345 would be represented as [3, 0, 1, 3, 0, 2, 1],
> as 12345 == (((((3*-4 + 0)*-4 + 1)*-4 + 3)*-4 + 0)*-4 + 2)*-4 + 1,
> and the sum of these digits is 10.
> I would like Pari to implement some of these numeral systems,
> like base -2 or balanced ternary (using base 3 with digits -1,
> 0, and 1). The former could be an extension of the input range
> of digits(), the latter a function similar to digits() named
> balanceddigits(), say.
As I say, there are too many variations.
The goal of digits() is to provide an asymptotically fast algorithm.
Once you have the result for set of digits, you can recoved the result
for other sets of digits in linear time, as negdigits shows.
Please see baldigits in the following script
https://pari.math.u-bordeaux.fr/Scripts/negdigits.gp
to handle balanced digits by the same method.
Cheers,
Bill.