Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the DiscreteLimit builtin #922

Merged
merged 5 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Major package dependencies ave been up dated to more recent releases. These incl

New features:

- ``DiscreteLimit`` #922
- ``IterationLimit``
- support for ``MATHICS_MAX_RECURSION_DEPTH``
- ``RemoveDiacritics[]``, ``Transliterate[]`` #617
Expand Down
56 changes: 56 additions & 0 deletions mathics/builtin/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,62 @@ def apply(self, expr, x, x0, evaluation, options={}):
return from_sympy(result)


class DiscreteLimit(Builtin):
"""
<dl>
<dt>'DiscreteLimit[$f$, $k$->Infinity]'
<dd>gives the limit of the sequence $f$ as $k$ tends to infinity.
</dl>

>> DiscreteLimit[n/(n + 1), n -> Infinity]
= 1

>> DiscreteLimit[f[n], n -> Infinity]
= f[Infinity]
"""

# TODO: Make this work
"""
>> DiscreteLimit[(n/(n + 2)) E^(-m/(m + 1)), {m -> Infinity, n -> Infinity}]
= 1 / E
"""

attributes = ('Listable',)

options = {
'Trials': '5',
}

messages = {
'dltrials': "The value of Trials should be a positive integer",
}

def apply(self, f, n, n0, evaluation, options={}):
'DiscreteLimit[f_, n_->n0_, OptionsPattern[DiscreteLimit]]'

f = f.to_sympy(convert_all_global_functions=True)
n = n.to_sympy()
n0 = n0.to_sympy()

if n0 != sympy.oo:
return

if f is None or n is None:
return

trials = options['System`Trials'].get_int_value()

if trials is None or trials <= 0:
evaluation.message('DiscreteLimit', 'dltrials')
trials = 5

try:
return from_sympy(sympy.limit_seq(f, n, trials))
except:
pass



class FindRoot(Builtin):
r"""
<dl>
Expand Down