Skip to content

Commit

Permalink
Removed SeqFunc, sequence api similar to Sum
Browse files Browse the repository at this point in the history
  • Loading branch information
leosartaj committed Jun 11, 2015
1 parent 72c60c4 commit 94f46c5
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 586 deletions.
25 changes: 10 additions & 15 deletions sympy/core/tests/test_args.py
Expand Up @@ -3015,44 +3015,39 @@ def test_sympy__series__sequences__EmptySequence():
assert _test_args(EmptySequence())


@SKIP('Abstract Class')
def test_sympy__series__sequences__SeqExpr():
from sympy.series.sequences import SeqExpr
assert _test_args(SeqExpr((1, 2, 3), (0, 10)))
pass


def test_sympy__series__sequences__SeqPer():
from sympy.series.sequences import SeqPer
assert _test_args(SeqPer((1, 2, 3), (0, 10, 2)))
assert _test_args(SeqPer((1, 2, 3), (0, 10)))


def test_sympy__series__sequences__SeqFormula():
from sympy.series.sequences import SeqFormula
assert _test_args(SeqFormula((x**2, x), (0, 10, 2)))


def test_sympy__series__sequences__SeqFunc():
from sympy.series.sequences import SeqFunc
assert _test_args(SeqFunc(Lambda(x, x**2), (0, 10, 2)))
assert _test_args(SeqFormula(x**2, (0, 10)))


def test_sympy__series__sequences__SeqExprOp():
from sympy.series.sequences import SeqExprOp, sequence
s1 = sequence(periodical=(1, 2, 3))
s2 = sequence(func=Lambda(x, x**2))
s1 = sequence((1, 2, 3))
s2 = sequence(x**2)
assert _test_args(SeqExprOp(s1, s2))


def test_sympy__series__sequences__SeqAdd():
from sympy.series.sequences import SeqAdd, sequence
s1 = sequence(periodical=(1, 2, 3))
s2 = sequence(func=Lambda(x, x**2))
s1 = sequence((1, 2, 3))
s2 = sequence(x**2)
assert _test_args(SeqAdd(s1, s2))


def test_sympy__series__sequences__SeqMul():
from sympy.series.sequences import SeqMul, sequence
s1 = sequence(periodical=(1, 2, 3))
s2 = sequence(func=Lambda(x, x**2))
s1 = sequence((1, 2, 3))
s2 = sequence(x**2)
assert _test_args(SeqMul(s1, s2))


Expand Down
2 changes: 0 additions & 2 deletions sympy/printing/latex.py
Expand Up @@ -1503,7 +1503,6 @@ def _print_SeqFormula(self, s):
printset = ('\ldots', s.coeff(stop - 3), s.coeff(stop - 2),
s.coeff(stop - 1), s.coeff(stop))
elif s.stop is S.Infinity or s.length > 4:
it = iter(s)
printset = s[:4]
printset.append('\ldots')
else:
Expand All @@ -1514,7 +1513,6 @@ def _print_SeqFormula(self, s):
+ r"\right\]")

_print_SeqPer = _print_SeqFormula
_print_SeqFunc = _print_SeqFormula
_print_SeqAdd = _print_SeqFormula
_print_SeqMul = _print_SeqFormula

Expand Down
2 changes: 0 additions & 2 deletions sympy/printing/pretty/pretty.py
Expand Up @@ -1528,7 +1528,6 @@ def _print_SeqFormula(self, s):
printset = (dots, s.coeff(stop - 3), s.coeff(stop - 2),
s.coeff(stop - 1), s.coeff(stop))
elif s.stop is S.Infinity or s.length > 4:
it = iter(s)
printset = s[:4]
printset.append(dots)
printset = tuple(printset)
Expand All @@ -1537,7 +1536,6 @@ def _print_SeqFormula(self, s):
return self._print_list(printset)

_print_SeqPer = _print_SeqFormula
_print_SeqFunc = _print_SeqFormula
_print_SeqAdd = _print_SeqFormula
_print_SeqMul = _print_SeqFormula

Expand Down
108 changes: 41 additions & 67 deletions sympy/printing/pretty/tests/test_pretty.py
Expand Up @@ -7,7 +7,7 @@
Pow, Product, QQ, RR, Rational, Ray, RootOf, RootSum, S,
Segment, Subs, Sum, Symbol, Tuple, Xor, ZZ, conjugate,
groebner, oo, pi, symbols, ilex, grlex, Range, Contains,
Lambda, SeqPer, SeqFunc, SeqFormula, SeqAdd, SeqMul)
SeqPer, SeqFormula, SeqAdd, SeqMul)
from sympy.functions import (Abs, Chi, Ci, Ei, KroneckerDelta,
Piecewise, Shi, Si, atan2, binomial, catalan, ceiling, cos,
euler, exp, expint, factorial, factorial2, floor, gamma, hyper, log,
Expand Down Expand Up @@ -3102,108 +3102,82 @@ def test_pretty_sets():

def test_pretty_sequences():
s1 = SeqFormula(a**2, (0, oo))
s2 = SeqFunc(Lambda(a, a**2), (0, oo))
s3 = SeqPer((1, 2))
s2 = SeqPer((1, 2))

ascii_str = '[0, 1, 4, 9, ...]'
ucode_str = u('[0, 1, 4, 9, …]')

assert pretty(s1) == ascii_str
assert upretty(s1) == ucode_str
assert pretty(s2) == ascii_str
assert upretty(s2) == ucode_str

ascii_str = '[1, 2, 1, 2, ...]'
ucode_str = u('[1, 2, 1, 2, …]')
assert pretty(s3) == ascii_str
assert upretty(s3) == ucode_str
assert pretty(s2) == ascii_str
assert upretty(s2) == ucode_str

s4 = SeqFormula(a**2, (0, 2))
s5 = SeqFunc(Lambda(a, a**2), (0, 2))
s6 = SeqPer((1, 2), (0, 2))
s3 = SeqFormula(a**2, (0, 2))
s4 = SeqPer((1, 2), (0, 2))

ascii_str = '[0, 1, 4]'
ucode_str = u('[0, 1, 4]')

assert pretty(s4) == ascii_str
assert upretty(s4) == ucode_str
assert pretty(s5) == ascii_str
assert upretty(s5) == ucode_str
assert pretty(s3) == ascii_str
assert upretty(s3) == ucode_str

ascii_str = '[1, 2, 1]'
ucode_str = u('[1, 2, 1]')
assert pretty(s6) == ascii_str
assert upretty(s6) == ucode_str
assert pretty(s4) == ascii_str
assert upretty(s4) == ucode_str

s5 = SeqFormula(a**2, (-oo, 0))
s6 = SeqPer((1, 2), (-oo, 0))

ascii_str = '[..., 9, 4, 1, 0]'
ucode_str = u('[…, 9, 4, 1, 0]')

s7 = SeqFormula(a**2, (-oo, 0))
s8 = SeqFunc(Lambda(a, a**2), (-oo, 0))
s9 = SeqPer((1, 2), (-oo, 0))

assert pretty(s7) == ascii_str
assert upretty(s7) == ucode_str
assert pretty(s8) == ascii_str
assert upretty(s8) == ucode_str
assert pretty(s5) == ascii_str
assert upretty(s5) == ucode_str

ascii_str = '[..., 2, 1, 2, 1]'
ucode_str = u('[…, 2, 1, 2, 1]')
assert pretty(s9) == ascii_str
assert upretty(s9) == ucode_str

s10 = SeqFormula(a**2, (0, oo, 2))
s11 = SeqFunc(Lambda(a, a**2), (0, oo, 2))
s12 = SeqPer((1, 2), (0, oo, 2))

ascii_str = '[0, 4, 16, 36, ...]'
ucode_str = u('[0, 4, 16, 36, …]')

assert pretty(s10) == ascii_str
assert upretty(s10) == ucode_str
assert pretty(s11) == ascii_str
assert upretty(s11) == ucode_str

ascii_str = '[1, 1, 1, 1, ...]'
ucode_str = u('[1, 1, 1, 1, …]')
assert pretty(s12) == ascii_str
assert upretty(s12) == ucode_str
assert pretty(s6) == ascii_str
assert upretty(s6) == ucode_str

ascii_str = '[1, 4, 9, 20, ...]'
ucode_str = u('[1, 4, 9, 20, …]')
ascii_str = '[1, 3, 5, 11, ...]'
ucode_str = u('[1, 3, 5, 11, …]')

assert pretty(SeqAdd(s1, s2, s3)) == ascii_str
assert upretty(SeqAdd(s1, s2, s3)) == ucode_str
assert pretty(SeqAdd(s1, s2)) == ascii_str
assert upretty(SeqAdd(s1, s2)) == ucode_str

ascii_str = '[1, 4, 9]'
ucode_str = u('[1, 4, 9]')
ascii_str = '[1, 3, 5]'
ucode_str = u('[1, 3, 5]')

assert pretty(SeqAdd(s4, s5, s6)) == ascii_str
assert upretty(SeqAdd(s4, s5, s6)) == ucode_str
assert pretty(SeqAdd(s3, s4)) == ascii_str
assert upretty(SeqAdd(s3, s4)) == ucode_str

ascii_str = '[..., 20, 9, 4, 1]'
ucode_str = u('[…, 20, 9, 4, 1]')
ascii_str = '[..., 11, 5, 3, 1]'
ucode_str = u('[…, 11, 5, 3, 1]')

assert pretty(SeqAdd(s7, s8, s9)) == ascii_str
assert upretty(SeqAdd(s7, s8, s9)) == ucode_str
assert pretty(SeqAdd(s5, s6)) == ascii_str
assert upretty(SeqAdd(s5, s6)) == ucode_str

ascii_str = '[0, 2, 16, 162, ...]'
ucode_str = u('[0, 2, 16, 162, …]')
ascii_str = '[0, 2, 4, 18, ...]'
ucode_str = u('[0, 2, 4, 18, …]')

assert pretty(SeqMul(s1, s2, s3)) == ascii_str
assert upretty(SeqMul(s1, s2, s3)) == ucode_str
assert pretty(SeqMul(s1, s2)) == ascii_str
assert upretty(SeqMul(s1, s2)) == ucode_str

ascii_str = '[0, 2, 16]'
ucode_str = u('[0, 2, 16]')
ascii_str = '[0, 2, 4]'
ucode_str = u('[0, 2, 4]')

assert pretty(SeqMul(s4, s5, s6)) == ascii_str
assert upretty(SeqMul(s4, s5, s6)) == ucode_str
assert pretty(SeqMul(s3, s4)) == ascii_str
assert upretty(SeqMul(s3, s4)) == ucode_str

ascii_str = '[..., 162, 16, 2, 0]'
ucode_str = u('[…, 162, 16, 2, 0]')
ascii_str = '[..., 18, 4, 2, 0]'
ucode_str = u('[…, 18, 4, 2, 0]')

assert pretty(SeqMul(s7, s8, s9)) == ascii_str
assert upretty(SeqMul(s7, s8, s9)) == ucode_str
assert pretty(SeqMul(s5, s6)) == ascii_str
assert upretty(SeqMul(s5, s6)) == ucode_str


def test_pretty_limits():
Expand Down
65 changes: 24 additions & 41 deletions sympy/printing/tests/test_latex.py
Expand Up @@ -14,8 +14,8 @@
meijerg, oo, polar_lift, polylog, re, root, sin, sqrt, symbols,
uppergamma, zeta, subfactorial, totient, elliptic_k, elliptic_f,
elliptic_e, elliptic_pi, cos, tan, Wild, true, false, Equivalent, Not,
Contains, divisor_sigma, SymmetricDifference, Lambda, SeqPer, SeqFormula,
SeqFunc, SeqAdd, SeqMul)
Contains, divisor_sigma, SymmetricDifference, SeqPer, SeqFormula,
SeqAdd, SeqMul)

from sympy.abc import mu, tau
from sympy.printing.latex import latex, translate
Expand Down Expand Up @@ -486,66 +486,49 @@ def test_latex_Range():

def test_latex_sequences():
s1 = SeqFormula(a**2, (0, oo))
s2 = SeqFunc(Lambda(a, a**2), (0, oo))
s3 = SeqPer((1, 2))
s2 = SeqPer((1, 2))

latex_str = r'\left\[0, 1, 4, 9, \ldots\right\]'
assert latex(s1) == latex_str
assert latex(s2) == latex_str

latex_str = r'\left\[1, 2, 1, 2, \ldots\right\]'
assert latex(s3) == latex_str
assert latex(s2) == latex_str

s4 = SeqFormula(a**2, (0, 2))
s5 = SeqFunc(Lambda(a, a**2), (0, 2))
s6 = SeqPer((1, 2), (0, 2))
s3 = SeqFormula(a**2, (0, 2))
s4 = SeqPer((1, 2), (0, 2))

latex_str = r'\left\[0, 1, 4\right\]'
assert latex(s4) == latex_str
assert latex(s5) == latex_str
assert latex(s3) == latex_str

latex_str = r'\left\[1, 2, 1\right\]'
assert latex(s6) == latex_str
assert latex(s4) == latex_str

s7 = SeqFormula(a**2, (-oo, 0))
s8 = SeqFunc(Lambda(a, a**2), (-oo, 0))
s9 = SeqPer((1, 2), (-oo, 0))
s5 = SeqFormula(a**2, (-oo, 0))
s6 = SeqPer((1, 2), (-oo, 0))

latex_str = r'\left\[\ldots, 9, 4, 1, 0\right\]'
assert latex(s7) == latex_str
assert latex(s8) == latex_str
assert latex(s5) == latex_str

latex_str = r'\left\[\ldots, 2, 1, 2, 1\right\]'
assert latex(s9) == latex_str

s10 = SeqFormula(a**2, (0, oo, 2))
s11 = SeqFunc(Lambda(a, a**2), (0, oo, 2))
s12 = SeqPer((1, 2), (0, oo, 2))

latex_str = r'\left\[0, 4, 16, 36, \ldots\right\]'
assert latex(s10) == latex_str
assert latex(s11) == latex_str

latex_str = r'\left\[1, 1, 1, 1, \ldots\right\]'
assert latex(s12) == latex_str
assert latex(s6) == latex_str

latex_str = r'\left\[1, 4, 9, 20, \ldots\right\]'
assert latex(SeqAdd(s1, s2, s3)) == latex_str
latex_str = r'\left\[1, 3, 5, 11, \ldots\right\]'
assert latex(SeqAdd(s1, s2)) == latex_str

latex_str = r'\left\[1, 4, 9\right\]'
assert latex(SeqAdd(s4, s5, s6)) == latex_str
latex_str = r'\left\[1, 3, 5\right\]'
assert latex(SeqAdd(s3, s4)) == latex_str

latex_str = r'\left\[\ldots, 20, 9, 4, 1\right\]'
assert latex(SeqAdd(s7, s8, s9)) == latex_str
latex_str = r'\left\[\ldots, 11, 5, 3, 1\right\]'
assert latex(SeqAdd(s5, s6)) == latex_str

latex_str = r'\left\[0, 2, 16, 162, \ldots\right\]'
assert latex(SeqMul(s1, s2, s3)) == latex_str
latex_str = r'\left\[0, 2, 4, 18, \ldots\right\]'
assert latex(SeqMul(s1, s2)) == latex_str

latex_str = r'\left\[0, 2, 16\right\]'
assert latex(SeqMul(s4, s5, s6)) == latex_str
latex_str = r'\left\[0, 2, 4\right\]'
assert latex(SeqMul(s3, s4)) == latex_str

latex_str = r'\left\[\ldots, 162, 16, 2, 0\right\]'
assert latex(SeqMul(s7, s8, s9)) == latex_str
latex_str = r'\left\[\ldots, 18, 4, 2, 0\right\]'
assert latex(SeqMul(s5, s6)) == latex_str


def test_latex_intervals():
Expand Down
6 changes: 3 additions & 3 deletions sympy/series/__init__.py
Expand Up @@ -5,11 +5,11 @@
from .gruntz import gruntz
from .series import series
from .residues import residue
from .sequences import (EmptySequence, SeqPer, SeqFormula, SeqFunc, sequence,
SeqAdd, SeqMul)
from .sequences import (EmptySequence, SeqPer, SeqFormula, sequence, SeqAdd,
SeqMul)

O = Order

__all__ = ['Order', 'O', 'limit', 'Limit', 'gruntz', 'series', 'residue',
'EmptySequence', 'SeqPer', 'SeqFormula', 'SeqFunc', 'sequence',
'EmptySequence', 'SeqPer', 'SeqFormula', 'sequence',
'SeqAdd', 'SeqMul']

0 comments on commit 94f46c5

Please sign in to comment.