Karim Belabas on Sun, 27 Nov 2022 11:22:34 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
- To: Michael Day <mike_liz.day@tiscali.co.uk>
- Subject: Re: A071521(n)
- From: Karim Belabas <Karim.Belabas@math.u-bordeaux.fr>
- Date: Sun, 27 Nov 2022 11:21:14 +0100
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1669544474; c=relaxed/relaxed; bh=wm+36rBDCGFignUxq+GKOp4MbhKH4MfyLg42MIWYOaU=; h=DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; b=1UOFZpuJ2ZoDLsb9ZcERHlslpK/PFGqPO9A+w8VSFrV2ay0xrtS33/FbnMyYlOz+o7LAoM2eva+13uP/1KdYF41zUxnidwiv9OLVzXi1AVgD5pOMB+pSj8JJXU49ksy4VVMXIEEoDEdmAjoa/9nFnIDWqE2kKHwxE8qVGHFAwM3OA/HfCvNfMgFd01v+90KJPtkU0KqJNUSAw4HtHWzfnb0h1ahNhaOeRUov7MdxxDUVrwL9jxAjmYR4CrR/mplrz5keXW8+EgYK0cc5CNzg+8SzytPmxgC02GGq1N91NvWMp1OsTKQ/qIMxEIWXgp40DTIanUi6CckHPwMCuBrLVCwYILughhe2RoY5I6J8lxSXj61RG57t4ZxTojkHlcq5wDz+79WhAPylFFFaAZefxtYsZnXrn8mtGKVk0wE929OKIpdPsMtPmOTk2AhcoiXBj9iJuSJuHIb4dXCaqADgv8Vu0cizpbzsr+K8Qf/tBioyWzKWpSm9bRIEpxrXPxq5clHakG6AnSS2aHanzBAKX0ple3J4E+VLSMt1GCUwoBa5xjia5ihyor5E2PDpW9W6khT+eZNTonSkK0cQC6Cp/nKqCxYUVwDion5Jp2UMREO8w5tCLz/2cBarufSKUt09J7pUhtWGjGLgQ8rJNR1io73nPIuvvls5mkJRgIdBDaw=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1669544474; cv=none; b=hVoUYWR1xSYHohsoKsHZZaXJUcib02wnOfje9E+2QoX1SwmY+Hhz6S/KhI46juh3u1lfbe4EfT6XbL1BcXseoYuiXap57/KT1gurLRx1QBHJzgHC3sC75I9bqwL9noowxa/9//kDy+TOEoy+0hQnGP4n3p3G7osjbVi+BlhqzDRL5VtkBlKSboGf7wQD4Cy0gn5ePMX4SuystMA/2KvNIakL/WsMk8BjSk9jwcGYb1gds/rzCiitzA+nLkPHL0OEUdVbeVk8p26EbosHTkLfczIC+xFkDeRIevj8Y2aPll0UY/oMrKEoBgQMaMy+uXb53OQmflKQhYTW64F7fR/2olpnca657falYaG3WGTEWImDgtYKQ0wlkH394am8eR9Md88E+4tXQtp/vYC8jZ30sYNrv7ebeenns+pdOTS96bZRn6AQ6Ocg4ZdTVH7sRIthKpKJZBmnIuM6HTgMMrnFhBp4QbBV0R8fixEZyyIUWULDzH7BNcIz6iZJpS3CXNEgYyEfr9MPkpBk3mS6OEkbBenrHythyKyMiS2N+99KevsbpnkvWYKpJqP9pS32WqI6kg0hrYhuM9CoDCOrKpjQyUpBwjaVbfDY6ir1U/duSYnMxmUjFhaR6NFoa5t4BmnBffjl9y7jI0tYa1HifvVHgnvKjPzl0NY46CJwWh3YgkQ=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Cc: pari-users <pari-users@pari.math.u-bordeaux.fr>
- Delivery-date: Sun, 27 Nov 2022 11:22:34 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1669544474; bh=wm+36rBDCGFignUxq+GKOp4MbhKH4MfyLg42MIWYOaU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aXLXaPpv0d9xBAK0YrBAkZOsuJ0sZowPlDzRbEJ5pmzQwWyWbN/AYxJlmfe0KhD8m FEadAdN5QP9P8iE2SFrfeOTgRlzQVQNsYr1hAMxhhZ4HxoZMCnWGfMdX4pBwBFMtuv zyaTl5lTsZ5ypUHUifGABsXHfOvrx67kTK4BEd0IGEXdDyg6tmLARK8Bhaxy1mIrtr wSIXlDqFDLIgzg3epY96B/E6iWs9IMNHofuueHwLwPb5vH5qL4FHKHN+MDQxeYZ7TZ DefKs22WJZ8L6bTwSSUQMdbseFho1KJqJ0gNYn3ceQlJrE3wgFIw7gjdLzfxSAj0w7 rHWXzMMRww2LnpSkJc8EuhitehJqEYDSor7VufdElnHsmsHP4wTm7OyGE4oVzG5Soh 2R7L3U+hYzi0S0XjTx2Tk2NZj5+XdbqvjZxSe6rd9R9/f0hR7tpN9Ljbyi7InEWBIN 1BTVY6RBu2CwnQ9h7SKQykfluIJ3SYnC501O/mmmnOpmaih5C7g1wRBSWvZazfvcxV FKTcssrtGyc0NyiLXMQRYqfifCMuYbzVk4EyDs8NpIFxhkI8AAz4fDN9My8pazlP2L CCxZXPW9AsGESaHAJN1bqilcQj9yoPCAtVyhxJlts/eNOzU8QeRl8DC1nsmTuk53G9 Rx9fpwGm1HZh5tugNpky1/3Y=
- In-reply-to: <5d29da71-27a8-982d-61c8-c00b63e303c2@tiscali.co.uk>
- Mail-followup-to: Michael Day <mike_liz.day@tiscali.co.uk>, pari-users <pari-users@pari.math.u-bordeaux.fr>
- References: <cb566377-20f1-1d17-4350-a314d47dba6e@isolution.nl> <8857ab0f-bb8b-b955-e87f-69361e246c74@isolution.nl> <5d29da71-27a8-982d-61c8-c00b63e303c2@tiscali.co.uk>
Hi,
I didn't check the definition of A071521 in OEIS but I guess the
problem is the unexpected (if one is used to C) semantic of the 'a op= b'
operator in PARI/GP, whose value is A = a op b (and not 'a' !). I.e. in
A071521(n)= my(t=1);sum(k=1,logint(n,3),logint(n\t*=3,2)+1)
when k = 1, we set t = 3 and compute logint(n \ 3, 2), where it was probably
expected to compute logint(n \ 1, 2). If so, a corrected version would be
A071521bis(n) = my(t=1/3); sum(k=1,logint(n,3),logint(n\t*=3,2)+1) + 1;
(the final + 1 is for k = 0). We then have
(11:15) gp > A071521bis(2000000000000000000000000000000)
%1 = 3278
While I'm at it, here's a simpler and slightly faster version of a2():
a3(n) = sum(k=0, logint(n, 2), logint(n >> k, 3) + 1)
(11:15) gp > a3(2000000000000000000000000000000)
%2 = 3278
A071521bis remains a little faster of course, so this is of marginal interest.
(Good for debugging, maybe.)
Cheers,
K.B.
* Michael Day [2022-11-27 10:49]:
> I mostly use Pari GP when I need better precision than I can get with J, so
> I'm no expert!
>
> I had a look at this to see if I could get a nice answer in J, but noticed
> that
> Charles' function has a pleasing variant which replaces the multiply by 3
> with a doubling by addition, so I've called it a2:
>
> a2(n)=my(t=1/2); sum(k=0, logint(n, 2), t+=t; logint(n\t, 3)+1)
>
> So instead of a loop on powers of 3, we've got rather more loops on
> powers of 2.
>
> Unfortunately, on the way, I found what seems to be a problem with your
> suggestion (Ruud van Tol); perhaps there's a typo?
>
> (18:04) gp > a(2000000000000000000000000000000)
> %28 = 3278
> (18:04) gp > a2(2000000000000000000000000000000)
> %29 = 3278
> (18:04) gp > A071521(2000000000000000000000000000000)
> %30 = 3177
>
> A071521 does seem a tad faster than a, while a2 is a little slower than a,
> as to be expected.
>
> (I'm relieved to say that my J function, n3sm, works ok for this argument:
> n3sm 2000000000000000000000000000000
> 3278
> )
>
> Cheers,
>
> Mike
>
> On 26/11/2022 10:29, Ruud H.G. van Tol wrote:
> >
> > "A071521 Number of 3-smooth numbers <= n"
> > https://oeis.org/A071521
> >
> > The (to me very educational) PARI-code
> > from Charles, on that page, looks to me
> > like a variant of a formula shown in
> > the "Raphael Schumacher" link.
> >
> > I would now probably write it as:
> > A071521(n)= my(t=1);sum(k=1,logint(n,3),logint(n\t*=3,2)+1)
> >
> > (just trying to shave off another millisecond,
> > though I was blown away by its speed already:
> > a 3^k variant takes 40x as long)
> >
> > -- Ruud
> >
> > P.S. As n could be any ridiculous integer,
> > a "powers()" approach isn't applicable.
> > A "Power(b,e)=exp(e*log(b))" approach might be feasible,
> > but that probably just takes longer,
> > and will add precision treats.
> >
>
>
>
K.B.
--
Karim Belabas / U. Bordeaux, vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/
`