Page 1 of 1
Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 16:36
by electrofux
I am trying to generate an array were Pulses/Gates are distributed over a number of Steps according to the euclidian algorithm
(Pages 3 and 4 in this PDF
https://ics-web.sns.ornl.gov/timing/Rep ... 20Note.pdf)
I have therefore built an project with a Steps and Pulse Switch for selecting the number of pulses and steps and 2 functions according to the abstract (euclid(steps,pulses) and makearray(level).
Now it generates something but it is all rubbish. If anyone ever came across that algorithm and can check if i have done something obviously wrong, that would be cool.
Re: Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 16:51
by oldgearguy
I think the problem is something I also ran into some time ago. Lemur and it's frame-oriented approach to executing scripts doesn't handle recursion.
One of my many open questions to Liine tech support is about recursion. I have not received any answers to any of my detailed "How does Lemur work?" questions.
You'll have to find a non-recursive implementation of makearray() to get this to work.
Re: Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 18:20
by electrofux
Damn, i hate recursions, makes my brain twist. Now i have to dig deep into this
Re: Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 19:44
by electrofux
Puh, did some research but i doubt i can make the function iterative. It is even a double recursion, no way i get my head around this :/
But maybe we have some genius in here?
This is the recursive function found in the makearray script which builds the array:
Code: Select all
decl i;
if (level == -1)
{
euclidarray={euclidarray,0};
}
else if (level == -2)
{
euclidarray={euclidarray,1};
}
else
{
for (i=0; i < count[level]; i++)
{
makearray (level-1);
if (remainder[level] != 0)
makearray (level-2);
}
}
Re: Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 20:45
by electrofux
Found a good thread and got it solved. Alot easier than the Bjorklund algorithm and it works with pulses>steps/2 which the bjorklund doesnt do.
Looks good so far:
Code: Select all
decl i,Error,Result,size,ReturnResult;
Error=0;
Result=0;
for (i=0;i<steps;i++)
{
Error=Error+pulses;
if (Error>0)
{
Result={Result,1};
Error=Error-steps;
}
else
{
Result={Result,0};
}
}
size=sizeof(Result)-1;
ReturnResult=subarray(Result,1,size);
return ReturnResult;
Re: Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 21:06
by oldgearguy
I missed this first time around, sorry.
your else clause should be:
Code: Select all
else
{
for (i=0; i < count[level]; i++)
makearray (level-1);
if (remainder[level] != 0)
makearray (level-2);
}
There were braces around the entire makearray(level-1) and makearray(level-2)
So recursion appears to work in this case (probably because it can all execute inside a single frame)
Re: Anyone with knowledge of the euclid algorithm
Posted: 11 Aug 2014 23:14
by electrofux
wow, you are right it works. Only needed to add a floor in:
count[level] = floor(divisor / remainder[level]);
Now i have two working versions
Thanks