Calculate the Riemann Zeta Function

4

0

Calculate the Riemann zeta function to the maximum primitive precision in your language (for C-family, that would be double or long double, var in JS, etc.) No need for BigDecimal or the like unless you need it to use a double-equivalent precision.

  1. Efficiency (be sane) doesn't matter.
  2. If it's not in a common language, I can't test it, but I hope somebody does.
  3. No libraries or built-in math functions.
  4. Recursion is cool!

See my JS entry for a sample program.

Simon Kuang

Posted 2014-08-04T17:51:28.357

Reputation: 168

Question was closed 2014-08-04T20:16:52.933

3Judging by your example implementation it only needs to work for real inputs greater 1? – Martin Ender – 2014-08-04T18:13:24.887

@MartinBüttner Yes. – Simon Kuang – 2014-08-04T19:23:08.590

2And what about those math functions? You're using the power function yourself. Which math functions are allowed and which aren't? – Martin Ender – 2014-08-04T19:24:45.273

How is input/output to be handled? Examples? – Kyle Kanos – 2014-08-04T19:37:20.187

@MartinBüttner Okay. Only basic math functions equivalent to Java/JS's Math. – Simon Kuang – 2014-08-04T19:46:13.767

I think without power function you will be pretty lost, and many programming languages do not require a math library for calculating powers! The next thing that is unclear: how dos double apply to complex arguments? (Since the zeta function is defined for Re(z)>0 where z is complex.) – flawr – 2014-08-04T19:54:23.677

@SimonKuang You may want to list those functions in your question. – The Guy with The Hat – 2014-08-04T20:16:46.627

2I was hovering over the submit post button right when it got closed. That's life I guess :P – Qwix – 2014-08-04T20:18:35.097

Answers

-1

JavaScript (Chrome): 78

function zeta(r){for(var t=0,a=1,n=1;t!=a;a=t,t+=1/Math.pow(n++,r));return t}

Simon Kuang

Posted 2014-08-04T17:51:28.357

Reputation: 168

5No math libraries – proud haskeller – 2014-08-04T18:16:36.763

And apart from that I think it will fail for r=1+epsilon where epsilon>0 small enough. Even though one summand might be smaller than working precision, the sum of the following summands can be bigger. Best example for this is the series sum 1/n for n=1 to infinity = zeta(1). – flawr – 2014-08-04T19:51:06.150