Bill Allombert on Tue, 17 Jan 2023 16:35:55 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: probable bug of "ispower" function in GP: FALSE, apologies!
|
- To: pari-dev@pari.math.u-bordeaux.fr
- Subject: Re: probable bug of "ispower" function in GP: FALSE, apologies!
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Tue, 17 Jan 2023 16:34:43 +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=1673969682; c=relaxed/relaxed; bh=v3p2J1iOiRVqYlSCVuImBUhVTAUl3Pp/uuM84Edly0o=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=d8JeNtI2BdRjXc7S+PoLGoIYQed4BGGBmtGqOqGCNHZ8A7zbNmeWccjan5sV6iKuAJC/JDxIE+u3HJEoILjUGEIT0RL+Tl2PpKTGupDDVtmoI+YKQ5kFk3arpLng2om2p6gxHXPZseUl8QAGForUabXY/BxZSAqdUu0rLlURDpLw6LyGNSX/u0rWW90gF7VLe74jmxZZiuFLX8YVPC/5mZifzL39FOQ0P0PpVJNY8qjj0uDOxDG3IcA86m6CyJIhlZtUh8OYWXSyYudM851Lrf4VQKabG0POITPCjBX6IQm52kHJkFcCA29LLZcSO+zf2L+RecG65YoIkynvBlM+gJPW1WxoRVtrvG2UNSEBvmZbAlVPZbKpCMU2B2Sg2eKkfrLIPV7yqiwuXktNEii7lw8UMBZSCDcI4BxmlYY95NAt2y/gABkqKgOOD/LbSPhUp7kS5+VZX0kqIEdB/yh8OZlvqAsQb6Z9fo5b8lbIVxuy9yfrS7aohLFDW510G9Y6fpPw47LZ9fWWKJREH69n8pGezqBE+gI9BdUQ4lO1n5WVeK7fFRbBiCMUlfEtqH/VMm2mTKJJ/Qp4r5lXET4t03kFOTjvi8QKxlcHhrKcKBsKuIb+V9iaBYC5Omu8GNW+6SUOLDiSUtBKUX7jhnm2/it4672LVLM2uA5cA03SL+g=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1673969682; cv=none; b=I1mK7ABI7PcpO+5Ty/iljGYxrnXd632EdSvwHckpE0nXpst9LpZLpx0CpNcOrxAm5tZLXznoApVPvKrrQtmx2roD382OR4lfrda/wIPoWrXs1Iy+nP3riT/qgGNbhgAF4e1jxvPZZ5yHVLriCLN8cImHDc617jin5ck2mRVWAufJ4eUjoAfVXh/BmnXapSnU00KQK+KgKcA4NODFIMTTJj/SQbxeshfpYq8m/sHaFP9bJSL6iCQFl+4AG63rYZsP4hHHQp1u738NEd831PHOb7Vy1Vo75O28aoJ/ayxdXz/cr6MWm15LeiTDUSq+PJd/EypbGxylZ2G7CmYfs2SlLXu00Vv9mHggoU3XL3wSapu70sx2N+rXpBvxS+aAf5RBCOE2irrj4nBOId9fxH+T0z7MHrC+hh9D5BPlDHfAfBlWlDOSPEdRbhrQRSU/9a5k1wSoMSjJqSbvCuQt3A/JCfytDnZ1FBYNOajA1PAthuJR9AJmsGtCdbb1HbmTQHaNqJEyYtaGnEcbPcLdaAM9KUm4pmcbrFFTBl8y+HUj9Yg8OK9/gRuhviDWkNSHA6WXv01FkfyC8JKFcy2tLx9zNvz98yJEjImV8ppRmM/u82XUtx8HfgtsG8m4zwKS5CtgKKxb22/hLrHpg7DgFDWzJvcP7G+QprOwZJtSpuh7f7A=
- Authentication-results: smail; arc=none
- Delivery-date: Tue, 17 Jan 2023 16:35:55 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1673969682; bh=v3p2J1iOiRVqYlSCVuImBUhVTAUl3Pp/uuM84Edly0o=; h=Date:From:To:Subject:References:In-Reply-To:From; b=WSSBaOeBVnHSga/n5g3CTWWqOpHIaAazRYgBWu15j1CCaZ2R9J0qs4nWJETGmwQPb IvfSGpqLzHvj+oMzqhLozprfkSZLB6lrlL3FpQoQbXg8W3O9q0c9Y9Z6gIKPfENxls McyP899Uwgvd1ecZcKodsFUWLVh1gkgwTrCFuJiec4FH1du2Kz1yVHkXa8BUw6dPJC jMdbF8vLd+ganmkhvASjBq3cPowPYS7NrS1oVsdakb8iT0z+/wYjMoU6bEhUn1nCb2 HnUkJM6okyffZyoBfog3mJiVWK21wsjjfsnktZyU9tjLs/ulWKjfUsEYnZEw8z0yQ2 zm0lUywIsr9ZEn7OCh14wlTAfDzrX/8AdoZ8lw45X3FOy5omTDLL8WaRAnJP3pO8jA 2jhNLr3o3t+DnWwdVdTQj7cqi/60Gwn+lttsu+hNpnoc8yUIRhj1bKEsfGmp857D4s 1x6Ya5T0OpXLG6XJ5Co+kTGosRo1y+9+bw8MUqCTCZfhmqqLprZVZwcFjD3WHauYM8 9XkQDqgL80IxMqLl6lBoQkzgmc7L0OmOPt6uz3jSUBAjwB3965Eqo7H3vrErxHKq4J 34iVn5wi4ob4CrLyt26jRrQJWhIES8xJq1KMnx3YrfTHZflqkUrMpmD5+MCJbiDdGD 4cnGqNAK8ky4RuNvMBAMWgeg=
- In-reply-to: <Y7/5YisNRCNzI/C9@math.u-bordeaux.fr>
- Mail-followup-to: pari-dev@pari.math.u-bordeaux.fr
- References: <20221015110556.Horde.DzRB347NPa1ivF_tMR97m6u@webmail.math.cnrs.fr> <Y0sXHmbHi3ZArXpG@seventeen> <20230112121305.Horde.KDGYfCiJflyFSjcbXnamB00@webmail.math.cnrs.fr> <20230112123109.Horde.sK95S0mK7_BhhK_9PxG6uTU@webmail.math.cnrs.fr> <20230112114055.GD9012@zira.vinc17.org> <Y7/5YisNRCNzI/C9@math.u-bordeaux.fr>
On Thu, Jan 12, 2023 at 01:13:22PM +0100, Karim Belabas wrote:
> * Vincent Lefevre [2023-01-12 12:40]:
> > On 2023-01-12 12:31:09 +0100, luis.gallardo@math.cnrs.fr wrote:
> > > I misunderstood the definition of "ispower"!
> > >
> > > I wanted a function that identify directly if some integer is a power of 2
> >
> > I suppose that you can use something like
> >
> > ispower(64,,&n)
> >
> > and check that n is 2. But I suppose that for large numbers, this may
> > be inefficient because ispower() will not just check for powers of 2.
>
> Use hammingweight(N) == 1.
>
> Or v = valuation(N,2); N >> v == 1 if you need the exact power. (Will be
> a little slower.)
You can also use
N == 1<<logint(N,2)
Whether this is faster depend whether you expect N to be prime or not
(valuation(N,2) is very fast if N is odd!)
N=2^1000;
#
for(i=1,10^6,hammingweight(N) == 1)
for(i=1,10^6,N>>valuation(N,2) == 1)
for(i=1,10^6,N == 1<<logint(N,2))
for(i=1,10^6,valuation(N,2) == logint(N,2))
N=random(2^1000);
for(i=1,10^6,hammingweight(N) == 1)
for(i=1,10^6,N>>valuation(N,2) == 1)
for(i=1,10^6,N == 1<<logint(N,2))
for(i=1,10^6,valuation(N,2) == logint(N,2))
which gives
time = 98 ms.
time = 94 ms.
time = 89 ms.
time = 95 ms.
time = 133 ms.
time = 101 ms.
time = 85 ms.
time = 90 ms.
Cheers,
Bill.