Ruud H.G. van Tol on Wed, 29 Dec 2021 14:55:51 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: factor(x+1)
- From: "Ruud H.G. van Tol" <rvtol@isolution.nl>
- Date: Wed, 29 Dec 2021 14:55:43 +0100
- Delivery-date: Wed, 29 Dec 2021 14:55:51 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=isolution.nl; s=soverin; t=1640786144; bh=9sIAjvp54HyQyC/WGAzSH4U2P7wYEBCeYINKZdSdqVs=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jl0aTAibl0Eu7qcgkAP7OSABoLpAQOSwDIHYGa95wcdmN0eY/hHBfrvfwAM4yFXCU 7ej9ODgOtzVBNKDdfS96BakdaMLTaBH98v13AtsICsxqWwJKzy5eNV0bXo5Nv3Bvc/ l6QLAzjBtPXdcAju8a7ifwHbohnrf1aWAQl6x90RmkLMwMnQgxzFNy0hQad+dhjfxm qwEqnBWVb4tK3XL2dIxbw3H2/FD6v5iVWHOttPUFfOtYTxBL8Lgxi2moY7ws8cRISo Ejo1DsnGWAg0qnvNgnRRDYtgsvVWUL0snEWowLw0sLP4c9OY8G169qRWzpmFyT4wnH 57954W/sq6I6A==
- In-reply-to: <Ycxkw8WQNTxpTHqd@seventeen>
- References: <cd638474-1b5a-ec18-2f6f-982fd5d6eb3c@isolution.nl> <Ycxkw8WQNTxpTHqd@seventeen>
On 2021-12-29 14:38, Bill Allombert wrote:
On Wed, Dec 29, 2021 at 02:12:14PM +0100, Ruud H.G. van Tol wrote:
Example:
103
-> 2^3*13
-> 2^3*(2*7-1)
-> 2^3*(2*(2^3-1)-1)
It seems to me you should only keep the exponents and work backward:
Try this:
tofp1(x)=my(v=valuation(x,2));x>>=v;if(x==1,return([v]),concat(v,tofp1(x+1)))
fromfp1(v)=my(n=1);v=Vecrev(v);for(i=1,#v,n=2^v[i]*n-1);n+1
? tofp1(103)
%18 = [0,3,1,3]
? 2^0*(2^3*(2^1*(2^3-1)-1)-1)
%20 = 103
? fromfp1([0,3,1,3])
%21 = 103
Thanks, that really helps!
I forgot to mention
that I'd like to stop at some minimal factor,
being 3 in my example. (so no 3 -> 2^2-1 step)
Am now considering using basically your approach,
with each element a factor-Vec.
With only 2 and 3 around,
I could also use 2 elements per step,
but "flattening" always bites some day.
-- Ruud
- References:
- factor(x+1)
- From: "Ruud H.G. van Tol" <rvtol@isolution.nl>
- Re: factor(x+1)
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>