Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-2008, 06:49 PM
cmlb cmlb is offline
Newbie
 
Join Date: Feb 2008
Posts: 3
Rep Power: 0
cmlb is on a distinguished road
Unhappy Need help with this simple Algorithm

function b=genArray(a,d)

The function genArray(a,d) has two parameters in which a is an array and d is the nonlinearity degree and the output is a new array b.

The function does the following job

For example:

a=[a1 a2 a3];

if d=1
b=[a1 a2 a3];

if d=2
b=[a1 a2 a3 a1*a1 a1*a2 a1*a3 a2*a2 a2*a3 a3*a3];

if d=3
b=[a1 a2 a3 a1*a1 a1*a2 a1*a3 a2*a2 a2*a3 a3*a3
a1*a1*a1 a1*a1*a2 a1*a1*a3 a1*a2*a2 a1*a2*a3 a1*a3*a3 a2*a2*a2 a2*a2*a3 a2*a3*a3 a3*a3*a3];

if d=4
and so on.....

I have been thinking this for a couple of days, but not able to form a solution... any ideas will be much appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-19-2008, 06:59 AM
vAC's Avatar   
vAC vAC is offline
Newbie
 
Join Date: Feb 2008
Location: Russia, Moscow
Age: 23
Posts: 7
Rep Power: 0
vAC is on a distinguished road
Send a message via ICQ to vAC Send a message via Skype™ to vAC
Default

First of all, let's count the number of array elements in each multiplication group separately.
Suppose:
n - count of elements in array a (in your example n=3);
k - number of efficients in group (i'll call it 'order', e.g. 1 for output [a1 a2 a3], 2 for output [a1*a1 a1*a2, a1*a3, a2*a2 a2*a3 a3*a3]...);

If you want to pre-allocate array b, you need to know it's size, so, number of combinations must be computed.
Number of multiplication combinations for each 'order' in your case are given by classic combinatoric formula
(urn and balls, selection with return and without order account):
C(n-1, n+k-1),
where
C(x, y) = y! / (x! * (y-x)!);

so we have:
(n+k-1)! / ((n-1)! * k!) combinations;
for n=3, k=1:
(3+1-1)! / ((3-1)! * 1!) = 3! / (2!*1!) = 6 / 2 = 3;
for n=3, k=2:
(3+2-1)! / ((3-1)! * 2!) = 4! / (2!*2!) = 24 / 4 = 6;
for n=3, k=3:
(3+3-1)! / ((3-1)! * 3!) = 5! / (2!*3!) = 120 / 12 = 10;

So, you can compute total size of array b by adding sizes of each 'order'.

Next step is filling single 'order' k with vaues.
Let's define additional k-element array ind, that represent index of elements in array a, which should be
multiplied to compute single element in b array. Let's suppose that b represent only one 'order', it's simpler.
Pseudo-cpp-code of this step will be:
Code:
ind.resize(k);
ind = [0, 0, ...0];
for (i = 0; i < C(n-1, n+k-1); i++)
{
	b[i] = 1;
	for (j = 0; j < k; j++)
	{
		b[i] *= a[ind[j]];
	}
	// generate next ind array
}
I think that you'll consider how to generate next ind
__________________
Sorry for my poor English

Last edited by vAC; 02-19-2008 at 07:19 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2008, 05:30 AM
cmlb cmlb is offline
Newbie
 
Join Date: Feb 2008
Posts: 3
Rep Power: 0
cmlb is on a distinguished road
Default

hi, vAC, thank you very much for your kind solution. It makes the problem much clearer to me now.

If we suppose that k=2 in the code, my understanding is that ind should beome
[0,0]
[0,1]
[0,2]
[1,1]
[1,2]
[2,2]
in the loop

is this correct?

But i am still thinking about how to write the code to implement it. Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-20-2008, 06:19 AM
vAC's Avatar   
vAC vAC is offline
Newbie
 
Join Date: Feb 2008
Location: Russia, Moscow
Age: 23
Posts: 7
Rep Power: 0
vAC is on a distinguished road
Send a message via ICQ to vAC Send a message via Skype™ to vAC
Default

quite right
and make this job in separate function or class method (it doesn't matter). For begin it's declaration may be looks like this:
Code:
void fill_order(int n, double *p_a, int k, double *p_b);
by n and p_a you know all about size and values a[i],
by k and p_b you know where to place results and size of array ind.
That's enought for one order filling.

Then, from outside you call this function/method for each 'order', passing the same n and p_a (in your example n=3, p_a - pointer to first element of array a=[a1 a2 a3]), and correcting k (incrementing) and p_d (should pointing to place of 'order' k in b array).
That's simplest solution.
__________________
Sorry for my poor English

Last edited by vAC; 02-20-2008 at 06:21 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-20-2008, 11:00 AM
cmlb cmlb is offline
Newbie
 
Join Date: Feb 2008
Posts: 3
Rep Power: 0
cmlb is on a distinguished road
Default

Hi, vAC, you are great !!! I have solved the problem with your help.. All the best....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Code: Simple Encryption Algorithm Void PHP Tutorials 11 11-05-2008 05:08 PM
Tutorial - A Simple Stropwatch! travy92 VB Tutorials 17 10-26-2008 11:10 AM
Peterson's Algorithm zm1723 C# Programming 1 12-13-2007 11:47 AM
Help : days algorithm rivci Java Help 4 12-13-2007 05:57 AM
Algorithms - The Basics (PART 2) TcM Security Tutorials 0 11-24-2007 11:33 AM


All times are GMT -5. The time now is 05:52 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads