| Bill Allombert on Wed, 24 Jan 2024 11:40:35 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: Missing functionality in forvec() |
On Wed, Jan 24, 2024 at 01:19:28AM -0800, Ilya Zakharevich wrote: > I want to use forwec() in a complicated algorithms needing a lot of > cached data. The caches should be recalculated on backtracking. I agree, forvec is nice for interactive use, but it does not lend itself to efficient code, because you have to recompute evrything from scratch for each entries. I used cache and backtracking to extrem length in my thesis. (e.g. the libpari function testpermutation) > Here I consider forvec() as if it is traversing-in-order an “ordered rooted tree”. > > While forvec() takes a lot of workload under the cover, with forvec() > it is a PITA to detect backtracking. On the other hand, I can see > that with an extra argument taking an (optional) variable reference > 'v, and reporting the details of backtracking in v, the life would be > much easier! > > The docs could go like this (I would need only one of these 3 flavors > of reporting; two others are added in anticipation of usability in > other situations): > > Let n be the number of tail counters which wrapped around after the > preceding iteration, and m be the number which will wrap around on > the next iteration. If 'v was a small/v/vector at start, put n and > m into the first two components; otherwise report n or -m, > preferring the non-0 value. (For what follows, note that with > flag=2 both n and m may be non-0 even if the trailing ranges are not > of length 1.) If 'v was 0 at start, prefer the largest of n and m, > otherwise prefer positive or negative depending on the sign of 'v at > start. Could you give an example of usage ? Maybe print all the numbers of the form x^2+2*x^2+3*x^2+...+n*x^2 ? I was considering suggesting the number of way to write a number as a sum of k squares using the naive algorithm, but this require the ability to cut branches. I am concerned the interface would be too complex to be of use. Cheers, Bill.