Skip to content

Instantly share code, notes, and snippets.

@achanda
Created August 7, 2015 22:50
Show Gist options
  • Select an option

  • Save achanda/ed46e7c4ca92865f9d06 to your computer and use it in GitHub Desktop.

Select an option

Save achanda/ed46e7c4ca92865f9d06 to your computer and use it in GitHub Desktop.
fn main () {
println!("{}", hg(1,8,3,4));
}
fn hg(a: i64, b: i64, c: i64, z: i64) -> i64 {
let mut j = 10;
loop {
let snp1 = inner_hg(a,b,c,z,j+1);
let sn = inner_hg(a,b,c,z,j);
if (((snp1 - sn).abs() / sn) as f64) < 0.001f64 {
return sn;
}
else {
j = j+1;
}
}
}
fn inner_hg(a: i64, b: i64, c: i64, z: i64, j: i64) -> i64 {
if (j == -1) || (j==0) {
1
}
else if j == 1 {
((a*b*z)/c)
}
else {
let rj = ((a+j-1)*(b+j-1))/(j*(c+j-1));
let sj1 = inner_hg(a,b,c,z,j-1);
return sj1 + (sj1 - inner_hg(a,b,c,z,j-2))*rj*z;
}
}
@achanda
Copy link
Author

achanda commented Aug 7, 2015

A very inefficient implementation of the hypergeometric function in rust

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