Anyone with knowledge of the euclid algorithm

Discuss problems and solutions.
Post Reply
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Anyone with knowledge of the euclid algorithm

Post 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.
Attachments
euclidtest.jzml
(10.11 KiB) Downloaded 62 times
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Anyone with knowledge of the euclid algorithm

Post 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.
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Anyone with knowledge of the euclid algorithm

Post by electrofux »

Damn, i hate recursions, makes my brain twist. Now i have to dig deep into this ;-)
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Anyone with knowledge of the euclid algorithm

Post 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);
		}
}

electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Anyone with knowledge of the euclid algorithm

Post 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;
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Anyone with knowledge of the euclid algorithm

Post 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)
electrofux
Regular
Posts: 294
Joined: 24 Jan 2012 18:22

Re: Anyone with knowledge of the euclid algorithm

Post 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
Post Reply