Troubleshooting

Anyone with knowledge of the euclid algorithm

Started by electrofux on .

Sign in or create an account to join the conversation.

7 posts

Topic starter
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-Rate%20Tech%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.

euclidtest.jzml
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.
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:
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);
		}
}
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:
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;
I missed this first time around, sorry.

your else clause should be:
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)