Which programming language or a library can process Infinite Series?

后端 未结 13 1401
情书的邮戳
情书的邮戳 2021-02-03 23:46

Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatica

相关标签:
13条回答
  • 2021-02-03 23:52

    You can solve the series problem in Sage (a free Python-based math software system) exactly as follows:

    sage: k = var('k'); sum((-1)^k/(2*k+1), k, 1, infinity)
    1/4*pi - 1
    

    Behind the scenes, this is really using Maxima (a component of Sage).

    0 讨论(0)
  • 2021-02-03 23:54

    You need something that can do a symbolic computation like Mathematica. You can also consider quering wolframaplha: sum((-1)^i*1/i, i, 1 , inf)

    0 讨论(0)
  • 2021-02-03 23:54

    There are two tools available in Haskell for this beyond simply supporting infinite lists.

    First there is a module that supports looking up sequences in OEIS. This can be applied to the first few terms of your series and can help you identify a series for which you don't know the closed form, etc. The other is the 'CReal' library of computable reals. If you have the ability to generate an ever improving bound on your value (i.e. by summing over the prefix, you can declare that as a computable real number which admits a partial ordering, etc. In many ways this gives you a value that you can use like the sum above.

    However in general computing the equality of two streams requires an oracle for the halting problem, so no language will do what you want in full generality, though some computer algebra systems like Mathematica can try.

    0 讨论(0)
  • 2021-02-03 23:57

    This can be done in for instance sympy and sage (among open source alternatives) In the following, a few examples using sympy:

    In [10]: summation(1/k**2,(k,1,oo)) Out[10]: 2 π ── 6

    In [11]: summation(1/k**4, (k,1,oo)) Out[11]: 4 π ── 90

    In [12]: summation( (-1)**k/k, (k,1,oo)) Out[12]: -log(2)

    In [13]: summation( (-1)**(k+1)/k, (k,1,oo)) Out[13]: log(2)

    Behind the scenes, this is using the theory for hypergeometric series, a nice introduction is the book "A=B" by Marko Petkovˇeks, Herbert S. Wilf and Doron Zeilberger which you can find by googling. ¿What is a hypergeometric series?

    Everybody knows what an geometric series is: $X_1, x_2, x_3, \dots, x_k, \dots $ is geometric if the contecutive terms ratio $x_{k+1}/x_k$ is constant. It is hypergeometric if the consecutive terms ratio is a rational function in $k$! sympy can handle basically all infinite sums where this last condition is fulfilled, but only very few others.

    0 讨论(0)
  • 2021-02-03 23:59

    Just install sympy on your computer. Then do the following code:

    from sympy.abc import i, k, m, n, x
    from sympy import Sum, factorial, oo, IndexedBase, Function
    Sum((-1)**k/(2*k+1), (k, 0, oo)).doit()
    

    Result will be: pi/4

    0 讨论(0)
  • 2021-02-04 00:00

    Most functional languages which evaluate lazily can simulate the processing of infinite series. Of course, on a finite computer it is not possible to process infinite series, as I am sure you are aware. Off the top of my head, I guess Mathematica can do most of what you might want, I suspect that Maple can too, maybe Sage and other computer-algebra systems and I'd be surprised if you can't find a Haskell implementation that suits you.

    EDIT to clarify for OP: I do not propose generating infinite loops. Lazy evaluation allows you to write programs (or functions) which simulate infinite series, programs which themselves are finite in time and space. With such languages you can determine many of the properties, such as convergence, of the simulated infinite series with considerable accuracy and some degree of certainty. Try Mathematica or, if you don't have access to it, try Wolfram Alpha to see what one system can do for you.

    0 讨论(0)
提交回复
热议问题