Skip to content

Commit de9dd37

Browse files
authored
Merge pull request #922 from GarkGarcia/discrete-limit
Implement the DiscreteLimit builtin
2 parents f59afe2 + d376073 commit de9dd37

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Major package dependencies ave been up dated to more recent releases. These incl
1212

1313
New features:
1414

15+
- ``DiscreteLimit`` #922
1516
- ``IterationLimit``
1617
- support for ``MATHICS_MAX_RECURSION_DEPTH``
1718
- ``RemoveDiacritics[]``, ``Transliterate[]`` #617

mathics/builtin/calculus.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,62 @@ def apply(self, expr, x, x0, evaluation, options={}):
962962
return from_sympy(result)
963963

964964

965+
class DiscreteLimit(Builtin):
966+
"""
967+
<dl>
968+
<dt>'DiscreteLimit[$f$, $k$->Infinity]'
969+
<dd>gives the limit of the sequence $f$ as $k$ tends to infinity.
970+
</dl>
971+
972+
>> DiscreteLimit[n/(n + 1), n -> Infinity]
973+
= 1
974+
975+
>> DiscreteLimit[f[n], n -> Infinity]
976+
= f[Infinity]
977+
"""
978+
979+
# TODO: Make this work
980+
"""
981+
>> DiscreteLimit[(n/(n + 2)) E^(-m/(m + 1)), {m -> Infinity, n -> Infinity}]
982+
= 1 / E
983+
"""
984+
985+
attributes = ('Listable',)
986+
987+
options = {
988+
'Trials': '5',
989+
}
990+
991+
messages = {
992+
'dltrials': "The value of Trials should be a positive integer",
993+
}
994+
995+
def apply(self, f, n, n0, evaluation, options={}):
996+
'DiscreteLimit[f_, n_->n0_, OptionsPattern[DiscreteLimit]]'
997+
998+
f = f.to_sympy(convert_all_global_functions=True)
999+
n = n.to_sympy()
1000+
n0 = n0.to_sympy()
1001+
1002+
if n0 != sympy.oo:
1003+
return
1004+
1005+
if f is None or n is None:
1006+
return
1007+
1008+
trials = options['System`Trials'].get_int_value()
1009+
1010+
if trials is None or trials <= 0:
1011+
evaluation.message('DiscreteLimit', 'dltrials')
1012+
trials = 5
1013+
1014+
try:
1015+
return from_sympy(sympy.limit_seq(f, n, trials))
1016+
except:
1017+
pass
1018+
1019+
1020+
9651021
class FindRoot(Builtin):
9661022
r"""
9671023
<dl>

0 commit comments

Comments
 (0)