Hi all,
i am facing a strange problem with an MFC appliation.
The problem is the application is giving different ouputs for the same input on different runs.
what might be the cause for this unpredictabiligy?
Appliations takes in 2^n bits input and computes walsh transform.
when i run the application first time i have one output
when i run the application with the same input i had different output
Could u tell some possible reasons for this unpredictability.
The application reads two inputs from the user n and a file consists of only one line of bits.
The code has given below:
The functin onButtonClicked() contains the following
{
UpdateData(TRUE);
int *W_f,x, *Bfun,i;
x=pow(2,n);
fstream fpout,fpin;
fpin.open("truthtable.txt",ios::in);
fpout.open("output.txt",ios::out);
//Allocate memory
W_f =new int [x];
Bfun = new int [x];
//Read truth table of boolean funciton f from the file
string fs;
getline(fpin,fs);
for( i =0;i<x;i++)
{
if(fs[i]=='1')
f[i]=1;
else
f[i]=0;
}
//Compute fast walsh transform
FastWalshTranform(Bfun, n, W_f);
for(i=0;i<x;i++)
fpout<<W_f[i]<<"\n";
}
void FastWalshTranform(int *Bfun, int n, int &W_f)
{
*int UD,A,B;
int i,j,x,x_half,k,l,b,w,p;
x=(int)pow(2,n);
x_half=x/2;
UD=new int [x];
//CopyTruth table of f into UD
for(i=0;i<x;i++)
{
if(Bfun[i]==1)
UD[i]=1;
else
UD[i]=0;
}
//FastWalshTransform
for(k=0;k<n;k++)
{
l=(int)pow(2,k);
b=x/l;
p=b/2;
A=new int [l];
B=new int [l];
for(i=0,j=0; i<p; i++,j=j+2*l)
{
for(w=0;w<l;w++)
{
A[w]=UD[j+w];
B[w]=UD[j+l+w];
}
for(w=0;w<l;w++)
{
UD[j+w]=A[w]+B[w];
UD[j+l+w]=A[w]-B[w];
}
}//end of for(i=0;j=0; i<p; i++,j=j+2*l)
delete A[];
delete B[];
}//end of for(k=0;k<n;k++)
//COmpute Walsh Transform
W_f[0]=x-2*UD[0];
for(w=1;w<x;w++)
W_f[w]=x - 2*( UD[w]+x_half );
//Free space for UD
delete UD [];
}
with regards
Ganesh Y