Skip to content

Instantly share code, notes, and snippets.

@grassa
Created August 31, 2011 18:50
Show Gist options
  • Save grassa/1184362 to your computer and use it in GitHub Desktop.
Save grassa/1184362 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
long fact(int n){
if(n == 0){
return 1;
}
else{
return n * fact(n-1);
}
}
double laa( int n1, int n2, int n3, int n4, float e ){
int nsum;
double sampling;
double aa;
nsum = n1 + n2 + n3 + n4;
sampling = fact(nsum) / ( fact( n1 ) * fact( n2 ) * fact( n3 ) * fact( n4 ) );
aa = ((sampling) * ( pow(( 1.0 - ( (3*e)/4) ),n1) ) * ( pow((e/4),(n2 + n3 + n4)) ));
return aa;
}
double lab( int n1, int n2, int n3, int n4, float e ){
int nsum;
double sampling;
double ab;
nsum = n1 + n2 + n3 + n4;
sampling = fact(nsum) / ( fact( n1 ) * fact( n2 ) * fact( n3 ) * fact( n4 ) );
ab = ((sampling) * ( pow(( 0.5 - (e/4) ),(n1 + n2)) ) * ( pow((e/4),(n3 + n4)) ));
return ab;
}
main(){
int na;
int nt;
int ng;
int nc;
float e;
na = 5;
nt = 1;
ng = 0;
nc = 0;
e = 0.001;
double aa;
double ab;
aa = laa(na,nt,ng,nc,e);
ab = lab(na,nt,ng,nc,e);
printf("%e\t%e\n", aa, ab );
/* sampling = fact(nS) / ( fact(n1) * fact(n2) * fact(n3) * fact(n4) ); */
/* $L11 = $sampling * ( ( 1 - ((3*$E)/4) )**$n1 ) * ( ($E/4)**($n2 + $n3 + $n4) ); */
/* $L12 = $sampling * ( ( 0.5 - ($E/4) )**($n1 + $n2) ) * ( ($E/4)**($n3 + $n4) ); */
}
@grassa
Copy link
Author

grassa commented Aug 31, 2011

lines 45, 47, and 49 of https://gist.github.com/1090505, implemented in c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment