Skip to content

Commit

Permalink
Merge a77d8a5 into 66245d4
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Apr 29, 2015
2 parents 66245d4 + a77d8a5 commit 37aac58
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 588 deletions.
6 changes: 3 additions & 3 deletions sympy/assumptions/assume.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AppliedPredicate(Boolean):
"""
__slots__ = []

def __new__(cls, predicate, arg):
def __new__(cls, predicate, arg, **kwargs):
if not isinstance(arg, bool):
# XXX: There is not yet a Basic type for True and False
arg = _sympify(arg)
Expand Down Expand Up @@ -146,8 +146,8 @@ def _hashable_content(self):
def __getnewargs__(self):
return (self.name,)

def __call__(self, expr):
return AppliedPredicate(self, expr)
def __call__(self, expr, **kwargs):
return AppliedPredicate(self, expr, **kwargs)

def add_handler(self, handler):
self.handlers.append(handler)
Expand Down
10 changes: 5 additions & 5 deletions sympy/core/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Basic(with_metaclass(ManagedProperties)):
is_Matrix = False
is_Vector = False

def __new__(cls, *args):
def __new__(cls, *args, **options):
obj = object.__new__(cls)
obj._assumptions = cls.default_assumptions
obj._mhash = None # will be set by __hash__ method.
Expand Down Expand Up @@ -1011,7 +1011,7 @@ def _eval_subs(self, old, new):
"""
return None

def xreplace(self, rule):
def xreplace(self, rule, evaluate=True):
"""
Replace occurrences of objects within the expression.
Expand Down Expand Up @@ -1077,12 +1077,12 @@ def xreplace(self, rule):
args = []
for a in self.args:
try:
args.append(a.xreplace(rule))
args.append(a.xreplace(rule, evaluate=evaluate))
except AttributeError:
args.append(a)
args = tuple(args)
if not _aresame(args, self.args):
return self.func(*args)
return self.func(*args, evaluate=evaluate)
return self

@cacheit
Expand Down Expand Up @@ -1608,7 +1608,7 @@ def matches(self, expr, repl_dict={}, old=False):
if self == expr:
return repl_dict

def xreplace(self, rule, hack2=False):
def xreplace(self, rule, evaluate=True, hack2=False):
return rule.get(self, self)

def doit(self, **hints):
Expand Down
4 changes: 2 additions & 2 deletions sympy/core/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2771,15 +2771,15 @@ def aseries(self, x, n=6, bound=0, hir=False):
xpos = Dummy('x', positive=True, finite=True)
return self.subs(x, xpos).aseries(xpos, n, bound, hir).subs(xpos, x)

omega, exps = mrv(self, x)
omega = mrv(self, x)
if x in omega:
s = self.subs(x, exp(x)).aseries(x, n, bound, hir).subs(x, log(x))
if s.getO():
o = Order(1/x**n, (x, S.Infinity))
return s + o
return s
d = Dummy('d', positive=True)
f, logw = rewrite(exps, omega, x, d)
f, logw = rewrite(self, omega, x, d)

if self in omega:
# Need to find a canonical representative
Expand Down
4 changes: 2 additions & 2 deletions sympy/core/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ class Lambda(Expr):
"""
is_Function = True

def __new__(cls, variables, expr):
def __new__(cls, variables, expr, **options):
from sympy.sets.sets import FiniteSet
try:
for v in variables if iterable(variables) else [variables]:
Expand All @@ -1372,7 +1372,7 @@ def __new__(cls, variables, expr):
if len(variables) == 1 and variables[0] == expr:
return S.IdentityFunction

obj = Expr.__new__(cls, Tuple(*variables), S(expr))
obj = Expr.__new__(cls, Tuple(*variables), S(expr), **options)
obj.nargs = FiniteSet(len(variables))
return obj

Expand Down
2 changes: 1 addition & 1 deletion sympy/core/tests/test_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def test_simultaneous_subs():
assert (x/y).subs(reps, simultaneous=True) == \
(y/x).subs(reps, simultaneous=True)
assert Derivative(x, y, z).subs(reps, simultaneous=True) == \
Subs(Derivative(0, y, z), (y,), (0,))
Subs(0, (y,), (0,))


def test_issue_6419_6421():
Expand Down
15 changes: 10 additions & 5 deletions sympy/functions/elementary/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
from sympy.logic.boolalg import (And, Boolean, distribute_and_over_or, Not, Or,
true, false)
from sympy.core.compatibility import default_sort_key, range
from sympy.core.evaluate import global_evaluate


class ExprCondPair(Tuple):
"""Represents an expression, condition pair."""

def __new__(cls, expr, cond):
if cond == True:
return Tuple.__new__(cls, expr, true)
elif cond == False:
return Tuple.__new__(cls, expr, false)
def __new__(cls, expr, cond, **options):
evaluate = options.pop('evaluate', global_evaluate[0])

if evaluate:
if cond == True:
return Tuple.__new__(cls, expr, true)
elif cond == False:
return Tuple.__new__(cls, expr, false)

return Tuple.__new__(cls, expr, cond)

@property
Expand Down
8 changes: 4 additions & 4 deletions sympy/functions/special/hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ class hyper(TupleParametersBase):
"""


def __new__(cls, ap, bq, z):
def __new__(cls, ap, bq, z, **kwargs):
# TODO should we check convergence conditions?
return Function.__new__(cls, _prep_tuple(ap), _prep_tuple(bq), z)
return Function.__new__(cls, _prep_tuple(ap), _prep_tuple(bq), z, **kwargs)

@classmethod
def eval(cls, ap, bq, z):
Expand Down Expand Up @@ -441,7 +441,7 @@ class meijerg(TupleParametersBase):
"""


def __new__(cls, *args):
def __new__(cls, *args, **kwargs):
if len(args) == 5:
args = [(args[0], args[1]), (args[2], args[3]), args[4]]
if len(args) != 3:
Expand All @@ -454,7 +454,7 @@ def tr(p):
return TupleArg(_prep_tuple(p[0]), _prep_tuple(p[1]))

# TODO should we check convergence conditions?
return Function.__new__(cls, tr(args[0]), tr(args[1]), args[2])
return Function.__new__(cls, tr(args[0]), tr(args[1]), args[2], **kwargs)

def fdiff(self, argindex=3):
if argindex != 3:
Expand Down
1 change: 0 additions & 1 deletion sympy/integrals/tests/test_heurisch.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def test_pmint_logexp():
assert ratsimp(heurisch(f, x)) == g

@slow # 8 seconds on 3.4 GHz
@XFAIL # there's a hash dependent failure lurking here
def test_pmint_erf():
f = exp(-x**2)*erf(x)/(erf(x)**3 - erf(x)**2 - erf(x) + 1)
g = sqrt(pi)*log(erf(x) - 1)/8 - sqrt(pi)*log(erf(x) + 1)/8 - sqrt(pi)/(4*erf(x) - 4)
Expand Down
2 changes: 1 addition & 1 deletion sympy/polys/rootoftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RootOf(Expr):
is_complex = True
is_number = True

def __new__(cls, f, x, index=None, radicals=True, expand=True):
def __new__(cls, f, x, index=None, radicals=True, expand=True, evaluate=None):
"""Construct a new ``RootOf`` object for ``k``-th root of ``f``. """
x = sympify(x)

Expand Down
Loading

0 comments on commit 37aac58

Please sign in to comment.