Created
August 7, 2015 22:50
-
-
Save achanda/ed46e7c4ca92865f9d06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A very inefficient implementation of the hypergeometric function in rust