Skip to content

Release Notes for 1.9

SymPy Bot edited this page Oct 18, 2021 · 169 revisions

These are the release notes for SymPy 1.9. You can also find release notes for previous versions.

SymPy 1.9 was released on 9th October 2021

This version of SymPy has been tested on Python 3.6, 3.7, 3.8, 3.9, 3.10 and PyPy. See our Python version support policy for more information on when we plan to drop support for older Python versions.

Note in particular that SymPy 1.5.1 was the last release to support Python 2.7. SymPy 1.9 will not work on Python 2.7. Python 2.7 users should install SymPy 1.5.1 and will not be able to install any further SymPy updates without updating to Python 3.

Install SymPy with

pip install -U sympy

or if you use Anaconda

conda install sympy

Highlights

  • The internal implementation of Matrix and other matrix classes (SparseMatrix etc) is now DomainMatrix. The ZZ and QQ domains are used for matrices with only integer or rational elements. Otherwise the new EXRAW domain is used. This should be backwards compatible although many internal methods and attributes are changed. At the time of this change the DomainMatrix routines are only used for addition and multiplication of matrices and some other simple low-level operations. Further changes will use DomainMatrix routines for operations like rref, det, lu etc and are expected to lead to big speedups for these computations. At this stage those big speedups are not realised but some basic operations such as indexing a matrix like M[0, 0] could potentially be slower. The new implementation can be much faster for most operations and is expected to lead to significant speed ups over the next few SymPy releases. (#21626 by @oscarbenjamin)

  • Leading term methods now raise PoleError at singularities. There was a long-standing issue of incorrect handling of leading term at singularities, where earlier, for compatibility reasons, the original expression itself was incorrectly returned. exp(1/x).as_leading_term(x) returned exp(1/x), but it does not have any leading term as x->0, so an error must be raised. Note that leadterm used to throw a ValueError even in the previous implementation as the original expression depends on the symbol x. A few examples of functions where this change would be visible - Pow, exp, log, factorial and gamma. (#21589 by @0sidharth)

There are many changes in 1.9 (see below).

Backwards compatibility breaks and deprecations

Please manually add any backwards compatibility breaks or deprecations here, in addition to the automatic listing below.

There are a number of changes and deprecations listed below. Most of these are really internal changes but they are listed here because in some cases it is hard to know if e.g. a downstream library has subclassed a SymPy class and modified its internals in an unexpected way. Few of the changes affect documented usage of SymPy.

  • The next version of SymPy will be 1.10. If your code checks sympy.__version__ be sure it will handle this version properly.

  • assumptions

    • CHANGE: The func property of AppliedPredicate returns AppliedPredicate class instead of unapplied predicate object. User must use function property to get the predicate. (#20847 by @JSS95 and @oscarbenjamin)

    • CHANGE: The args property of AppliedPredicate returns unapplied predicate object and arguments. User must use arguments property to get the arguments without the unapplied predicate. This breaks backwards compatibility. (#20847 by @JSS95 and @oscarbenjamin)

  • core

    • CHANGE: rewrite() method is redesigned. It is now encouraged to define _eval_rewrite() method instead of _eval_rewrite_as_[...]() method. @JSS95

    • _rewrite() method is defined for Basic. If user code had defined _rewrite() method, this change may raise backwards incompatibility issue.

  • functions

    • CHANGE: Heaviside(0) now returns 1/2 instead of being undefined. (#21452 by @hanspi42)
  • integrals

    • DEPRECATION: Using laplace_transform with a Matrix and without passing noconds=True is now deprecated. The behaviour of this function will change in future to return the conditions separately from the Matrix. The new behaviour can be obtained by passing the keyword argument legacy_matrix=False. (#21496 by @oscarbenjamin)
  • matrices

    • DEPRECATION: Using non-Expr elements in a Matrix is now deprecated. (#21496 by @oscarbenjamin)

    • INCOMPATIBLE CHANGE: The smith_normal_form function now requires an ordinary Matrix as input rather than a RawMatrix. (#21402 by @oscarbenjamin)

    • INCOMPATIBLE CHANGE: The RawMatrix class has been removed. Use Matrix, DomainMatrix or PolyMatrix instead depending on the application. (#21402 by @oscarbenjamin)

  • physics.matrices

    • DEPRECATION: mdft was deprecated, use DFT from matrices.fourier instead. See #20246.
  • polys

    • INCOMPATIBLE CHANGE: The (internal) PolyMatrix class has been changed and now requires generators to be provided on construction. (#21441 by @oscarbenjamin)
  • stats

    • INCOMPATIBLE CHANGE: sample now returns samples as float and arrays instead of an iterator. This restores and extends the behavior from SymPy 1.6 which was changed to an iterator in 1.7. Use sample_iter to get an iterator consistently in all versions of SymPy. (#21590 by @mostlyaman)

    • DEPRECATION: numsamples parameter in sample function is now deprecated. The parameter was added in SymPy 1.7 and continues to work but will emit a DeprecationWarning. The parameter will be removed in a future release. (#21590 by @mostlyaman)

Changes

  • algebras

  • assumptions

    • func property of AppliedPredicate returns AppliedPredicate class instead of unapplied predicate object. User must use function property to get the predicate. This breaks backwards compatibility. (#20847 by @JSS95 and @oscarbenjamin)

    • args property of AppliedPredicate returns unapplied predicate object and arguments. User must use arguments property to get the arguments without unapplied predicate. This breaks backwards compatibility. (#20847 by @JSS95 and @oscarbenjamin)

    • Q.positive_infinite() and Q.negative_infinite() predicates are introduced. (#21279 by @JSS95)

    • Q.extended_positive(), Q.extended_negative(), Q.extended_nonzero(), Q.extended_nonpositive(), and Q.extended_nonnegative() predicates are introduced. (#21279 by @JSS95)

    • Q.positive() and Q.negative() now correctly implies the argument being finite. (#21279 by @JSS95)

    • Incorrect results from Q.hermitian() and Q.antihermitian() are fixed. (#21279 by @JSS95)

  • calculus

    • AccumBounds will be handled if possible as exponents (#21516 by @smichr)

    • fix bug in AccumBounds.mul (#21523 by @smichr)

    • continuous_domain returns results for any power with even denominator, not just 2 (#21276 by @smichr)

  • codegen

  • core

    • Fixed unpickling of pickles created using older versions (<1.9) of SymPy. (#22245 by @oscarbenjamin)
    • A bug that preventing Float from being unpickled in SageMath was fixed. (#21996 by @mkoeppe)

    • The _sage_ SymPy/Sage interface methods are no longer included with SymPy, but are now initialized on the first use of a _sage_ method from within Sage. (#21958 by @mkoeppe and @oscarbenjamin)

    • better detection of odd/even/integer for expressions with symbolic powers of even bases (#21952 by @smichr)

    • Fixes PoleError by invoking aseries() when series() fails (#21948 by @P-Kshitij)

    • Fixed issue where is_integer returned incorrectly for multiplications. (#21928 by @oscargus)

    • Rational**Rational works better for large numbers. (#21900 by @oscargus)

    • Fix the internal caching code to not run a cached function twice if it raises a TypeError. (#21799 by @asmeurer)
    • rewrite() method is redesigned. It is now encouraged to define _eval_rewrite() method instead of _eval_rewrite_as_[...]() method. If user code had overridden _eval_rewrite() method, this change may raise backwards incompatibility issue. (#21472 by @JSS95)

    • _rewrite() method is defined for Basic. If user code had defined _rewrite() method, this change may raise backwards incompatibility issue. (#21472 by @JSS95)

    • Add missing bitwise operator implementations to sympy.core.numbers.Integer and register with numbers.Integral (#21699 by @posita)

    • Pow._eval_as_leading_term now raises PoleError when the argument is unbounded (#21589 by @0sidharth)

    • leadterm now takes logx argument (#21589 by @0sidharth)

    • kind attribute of Derivative class now returns the kind of its argument (#21614 by @Davide-sd)

    • check_assumptions now properly tests against 0 (#21586 by @smichr)

    • Leading term methods of Add and Pow now simplify irrational and imaginary expressions (#21253 by @0sidharth)

    • removed expr_free_symbols property (#21485 by @smichr)

    • _keep_coeff will distribute coeff on non-rational if doing so does not produce a rational (#21518 by @smichr)

    • replace uses exact equality testing so 0.5 can be changed to 1/2 (#21508 by @smichr)

    • Rational exponents of I are now less than 2 (#21400 by @smichr)

    • Catch PolynomialError for Piecewise expressions in Mod (#21379 by @craymichael)

    • Fixed pickling for a number of Basic subclasses (such as a Symbol with assumptions) for protocol 2 or higher. Removed support for pickling with protocol 0 or 1. (#21260 by @oscarbenjamin)

    • is_ge, is_le, is_gt, is_lt now takes assumptions (#21309 by @JSS95)

    • ordered() made faster for large expressions (#20635 by @kc611)
    • is_neq now takes assumptions (#21203 by @JSS95)

    • sympify() now obeys evaluate flag in case of iterable inputs. (#21553 by @mostlyaman)

    • Eq and Ne can be refined by predicates such as Q.positive, Q.zero, etc. (#21203 by @JSS95)

  • diffgeom

    • CoordinateSymbol now can be rewritten to the expression containing the coordinate symbols of other coordinate system. (#21781 by @JSS95)

    • Bug in indirect transformation between coordinate systems is fixed. (#21476 by @JSS95)

    • Transform relation between coordinate systems now consists of two tuples instead of Lambda. (#21476 by @JSS95)

    • Fixed a bug in the CoordSystem._inverse_transformation method. (#21366 by @Halfogerty)

  • external

    • No longer use deprecated distutils. Previously a deprecation warning was seen when importing sympy on Python 3.10. (#22039 by @oscarbenjamin)
  • functions

    • The derivatives of sinc(x) no longer return Piecewise results, which were previously incorrect at x=0. The value of the derivatives at x=0 can be computed with limit. (#21568 by @asmeurer)
    • doit/simplify should no longer be needed to evaluate limits after Piecewise integration in some cases (#21554 by @smichr)

    • Leading term methods of tan and cot now work for angles outside their principle domain (#21253 by @0sidharth)

    • Fixed a bug in MaxMin of elementary functions (#21547 by @shashankks0987 and @smichr)

    • expand_trig no longer expands functions with integer args, e.g. cos(2) is unchanged (#21507 by @oostben and @smichr)

    • Add _eval_expand_trig method for tanh. (#21380 by @oostben and @smichr)

    • Heaviside(0) now returns 1/2 instead of being undefined. (#21452 by @hanspi42)

  • holonomic

    • The holonomic module now uses DomainMatrix instead of NewMatrix. The NewMatrix class is removed. (#21427 by @oscarbenjamin)
  • integrals

    • inverse_laplace_transform can now transform a wider range of rational functions (#21566 by @hanspi42)

    • laplace_transform(DiracDelta(t),t,s) now gives 1 as expected. (#21469 by @hanspi42)

    • DEPRECATION: Using laplace_transform with a Matrix and without passing noconds=True is now deprecated. The behaviour of this function will change in future to return the conditions separately from the Matrix. The new behaviour can be obtained by passing the keyword argument legacy_matrix=False. (#21496 by @oscarbenjamin)

    • Fixed a bug in the heurisch module (#21404 by @jainachal03)

    • The heurisch integration routine was made faster. (#21354 by @oscarbenjamin)

  • interactive

  • logic

    • subs works better when replacing parts of a Boolean expression. (#21976 by @oscargus and @smichr)

    • Pattern based logic simplification is actually used when doing simplify with relations. (#21854 by @oscargus)

    • Improved logic simplification, dealing better with some symmetric cases and always producing consistent results. (#21854 by @oscargus)

    • The relational simplification no longer results in symbolic Min/Max. (#21854 by @oscargus)

    • Fixed simplification bug when equalities contained certain non-linear expressions. (#21873 by @oscargus and @smichr)

  • matrices

    • A bug that raised an exception when inverting an explicit matrix derived from a MatrixSymbol was fixed. (#20691 by @oscarbenjamin, @sidhu1012, and @Upabjojr)

    • fixed bug in is_positive_semidefinite() in eigen.py. (#21901 by @praneethratna)

    • The internal implementation of Matrix and other matrix classes (SparseMatrix etc) is now DomainMatrix. The ZZ and QQ domains are used for matrices with only integer or rational elements. Otherwise the new EXRAW domain is used. This should be backwards compatible although many internal methods and attributes are changed. At the time of this change the DomainMatrix routines are only used for addition and multiplication of matrices and some other simple low-level operations. Further changes will use DomainMatrix routines for operations like rref, det, lu etc and are expected to lead to big speedups for these computations. At this stage those big speedups are not realised but some basic operations such as indexing a matrix like M[0, 0] could potentially be slower. The new implementation can be much faster for most operations and is expected to lead to significant speed ups over the next few SymPy releases. (#21626 by @oscarbenjamin)

    • DEPRECATION: Using non-Expr elements in a Matrix is now deprecated. (#21496 by @oscarbenjamin)

    • Added Matrix.strongly_connected_components and Matrix.strongly_connected_components_decomposition for computing block triangulation of the matrix. (#21474 by @sylee957)
    • The smith_normal_form function now expects in ordinary Matrix as input rather than a RawMatrix (#21402 by @oscarbenjamin)
  • ntheory

    • Updated wiki link for describing deterministic Miller-Rabin test (#21765 by @jeffro256)

    • primerange now accepts a single argument, a, which gives the range [2, a) (#21321 by @smichr)

  • parsing

    • parse_expr will no longer cast Symbols in local_dict to Function (#21586 by @smichr)

    • parse_latex does not introduce a factor of -1 on numbers (#21518 by @smichr)

    • Fixed a bug in parse_latex function for rendering of -1 Mul to not evaluate in Add operation (#21499 by @gxyd)

  • physics.continuum_mechanics

  • physics.control

  • physics.matrices

    • Deprecated mdft, use DFT from matrices.fourier instead. (#20247 by @oscargus)
  • physics.mechanics

    • JointsMethod is implemented to formulate equations of motion using Body and Joint objects. (#21759 by @sahilshekhawat and @sidhu1012)

    • Add .loads and bodies property to KanesMethod and LagrangesMethod. (#21759 by @sahilshekhawat and @sidhu1012)

    • is_rigidbody property is added to class Body. (#21759 by @sahilshekhawat and @sidhu1012)

    • KanesMethod can now take body list and force list in object instantiation. (#21778 by @sidhu1012)

    • KanesMethod.kanes_equations both parameters are optional and can be taken automaticaly if they are passed at object instantiation. (#21778 by @sidhu1012)

    • .bodies attribute is added to KanesMethod which is advised to use instead of .bodylist attribute. (#21778 by @sidhu1012)

    • Update apply_force function of class Body to apply force on one body, or equal and opposite forces on two bodies. (#21712 by @sidhu1012)

    • Update apply_torque function of class Body to apply torque on one body, or equal and opposite torques on two bodies. (#21712 by @sidhu1012)

    • Body.loads is now an immutable attribute. (#21712 by @sidhu1012)

    • Add clear_loads function to class Body to clear Body's load list. (#21712 by @sidhu1012)

    • Add remove_load function to Body to remove a load from Body's load list. (#21712 by @sidhu1012)

    • Implemented a PrismaticJoint class that generate the kinematics of a prismatic joint. (#21674 by @sidhu1012)

    • Joint class is implemented which could be inherited to create custom joints. (#21564 by @moorepants, @sahilshekhawat, and @sidhu1012)

    • PinJoint has been implemented which can form KDEs, orient frames, set linear and angular velocities all by itself. (#21564 by @moorepants, @sahilshekhawat, and @sidhu1012)

    • Add basis vectors to Body. (#21700 by @sidhu1012)

    • Add masscenter_vel() to class Body to calculate velocity of one body's masscenter wrt other body's frame. (#21689 by @sidhu1012)

    • Add ang_vel_in() to class Body to calculate angular velocity of one body's frame wrt other body's frame. (#21689 by @sidhu1012)

    • Add dcm() to class Body to calculate dcm of one body's frame wrt other body's frame. (#21689 by @sidhu1012)

  • physics.quantum

    • Added a precedence attribute to CG to fix latex rendering (#21769 by @redeboer)

    • Fixed argument order of the math in the CG documentation (#21769 by @redeboer)

  • physics.vector

    • Vector.angle_between() has a new section Warnings. (#21749 by @sidhu1012)

    • Vector.magnitude() has a new section Warnings. (#21749 by @sidhu1012)

    • Point.vel() checks velocity in intermediate frames before taking derivative of position vector. (#21730 by @sidhu1012)

    • The orient_axis() works if the order of axis and angle is swapped. (#21662 by @sidhu1012)

    • Added a new function, angle_between to Vector class to calculate angle between two vectors. (#21600 by @sidhu1012)

    • Warning is raised if orientation of frames is looped. (#21436 by @sidhu1012)

    • Reference frames can be oriented in arbitrary order. (#21271 by @sidhu1012)

  • plotting

  • polys

    • Made DomainMatrix.hstack, DomainMatrix.vstack and DomainMatrix.unify work with N-ary arguments. (#21755 by @sylee957)

    • Made DDM.hstack and DDM.vstack work with n-ary arguments (#21745 by @sylee957)

    • The (internal) PolyMatrix class has been changed and now requires generators to be provided on construction. (#21441 by @oscarbenjamin)

    • _minpoly_tan method is added for calculating minimal polynomial for tan(n*pi), if n is rational. (#21442 by @hyadav2k)

    • Fixed KeyError raised while computing powers of PolyElement. (#21412 by @sylee957)
    • Added Documentation for SDM class (#21163 by @ks147)

    • The RawMatrix class has been removed. Use Matrix, DomainMatrix or PolyMatrix instead depending on the application. (#21402 by @oscarbenjamin)

    • The accuracy of the minpoly algorithm was improved to handle complicated algebraic expressions more reliably. (#21370 by @oscarbenjamin)

    • from_Matrix choose internal representation automatically from DDM and SDM (#21322 by @ks147)

    • added a function ones to DomainMatrix and DDM class (#21106 by @ks147)

    • gcd over the Gaussian integers (ZZ_I) is now canonicalised with respect to multiplication by I. (#21353 by @oscarbenjamin)

    • The polynomials module now only supports using gmpy2 as an accelerator for the ZZ and QQ domains (gmpy 1.x is no longer supported). (#21016 by @oscarbenjamin)

    • roots_quintic better detects non-rational coefficients (#21276 by @smichr)

    • roots_cubic results are simpler for cubics that can be written (or rewritten) as x**3 + y = 0 (#21276 by @smichr)

    • corner-case bugs fixed in to_rational_coeffs (#21276 by @smichr)

  • printing

    • Fix help() not displaying the docstring for various printing functions (latex, sstr, etc.). (#22038 by @oscarbenjamin)
    • FiniteSet now prints as {...} instead of FiniteSet(...) in the string printer, unless it contains a FiniteSet. (#21931 by @oscargus)

    • Corrected LaTeX-printing of Bd etc from physics.secondquant (#21930 by @oscargus)

    • Fixed a bug in _print_LambertW when LambertW function is raised to some power (#21849 by @BalasubramanyamEvani)

    • Fixed issue with generating latex for some unevaluated negative powers of rational numbers. (#20264 by @theanshm)

    • fixed parenthesizing issue of denominators that are powers (#21612 by @ArunSanganal)

    • NumExprPrinter now properly supports expressions containing ITE (#21386 by @craymichael)

    • fixed bug that caused factors in unevaluated expressions to be swapped (#21390 by @dsaw and @smichr)

    • powers with negative signs in the exponent are now printed in the denominator (#21390 by @dsaw and @smichr)

    • parentheses no longer appear on first factors in unevaluated Mul that have a negative sign (#21390 by @dsaw and @smichr)

    • Amended a test case of TheanoPrinter constant and complex functions (#20500 by @craymichael)

  • series

    • Limit now throws NotImplementedError if the point contains the variable wrt which limit is being found (#21775 by @0sidharth)

    • Limit code has better handling of sign (#21589 by @0sidharth)

  • sets

    • Better support for symbolic Range. (#21932 by @oscargus and @smichr)

    • Fixed a bug in is_subset() (#21596 by @shashankks0987 and @smichr)

    • Fixed a bug in is_subset() (#21580 by @shashankks0987)

    • Range involving symbols will be made more canonical (correcting a bug in calculation of sup) and errors will be raised when trying to compute attributes that are not known due to limitations of assumptions on the arguments. (#21286 by @smichr)

    • imageset involving Integers will not make linear expressions canonical when they contain Floats (#21313 by @smichr)

  • simplify

    • fixed bug in radsimp. (#21887 by @praneethratna)

    • cse will no longer generate an error when passed an unevaluated 2-arg Mul with a Rational arg (#21518 by @smichr); in addition the expression can be returned as the same type of the input with keyword list=False (#21546 by @robinechuca

    • bottom_up uses exact equality testing so 0.5 can be changed to 1/2 (#21508 by @smichr)

    • use of force=True with powdenest is more effective (#21432 by @smichr)

    • Modified the Fu transformation _TR56 to handle odd powers (#21332 by @meganly)

  • solvers

    • use of match was removed to make solving more reliable (#22079 by @Maelstrom6 and @smichr)

    • nonlinsolve properly handles instances of Eq in systems of equations (#21989 by @alijosephine and @smichr)

    • fixed a bug in nonlinsolve() method in solveset. (#21929 by @praneethratna)

    • fixed bug in solvers.polysys (#22005 by @praneethratna)

    • A bug when splitting separable systems of equations in solve was fixed. (#21883 by @oscarbenjamin and @smichr)

    • Better handling of Piecewise of Piecewise in solveset. (#21924 by @oscargus)

    • fixed bug in solvers.solve_linear (#21862 by @praneethratna)

    • dsolve: A new solver for Riccati ODEs has been added. Riccati ODEs which have atleast one rational particular solution can now be solved. This solver is a step towards Kovacic's algorithm for second order linear homogeneous ODEs. (#21459 by @naveensaigit)

    • nonlinsolve now recognizes Equalities that may already be true or false (#21602 by @shashankks0987 and @smichr)

    • Added a new solver, Minisat22, for the satisfiability problem (#21510 by @migueltorrescosta)

    • Some bugs in the new implementation of linsolve are fixed by the dense RREF implementation instead of the sparse implemention. These bugs previously led to incorrect results being returned linsolve. (#21527 by @oscarbenjamin)

    • Refactor exact EDO solving into the FirstExact class. (#21124 by @habitzreuter and @invalid-email-address)

    • Fixed bug in solveset (#21326 by @l-johnston and @smichr)

    • Fixed a bug where solving Liouville ODE with multiple terms fails. (#21327 by @YaserAlOsh)

    • unrad better detects radicals to be removed even when they are hidden as bases of rational powers (#21276 by @smichr)

    • unrad no longer makes the highest order term positive when making sign canonical (#21276 by @smichr)

    • _has_rational_power (a private function) is no longer used and is removed (#21276 by @smichr)

    • _solve_as_rational now fully expands the expression to be solved (#21276 by @smichr)

    • the signature of _solve_radical was changed to accept the unrad form of f (#21276 by @smichr)

    • _solveset will now use unrad to see if an equation needs to use _solve_radical before doing so (#21276 by @smichr)

    • solveset now uses factor as a last-resort (#21276 by @smichr)

  • stats

    • Added support for positive semi-definite covariance matrix in joint Multivariate normal distribution. (#21817 by @praneethratna)

    • Moment no more has None in args. (#21472 by @JSS95)

    • CentralMoment no more has None in args. (#21472 by @JSS95)

    • Fixed a bug regarding symbolic arguments to the multivariate normal distribution. (#21650 by @InfProbSciX)

    • BACKWARDS COMPATIBILITY: sample now returns samples as float and arrays instead of an iterator. This restores and extends the behavior from SymPy 1.6 which was changed to an iterator in 1.7. Use sample_iter to get an iterator consistently in all versions of SymPy. (#21590 by @mostlyaman)

    • DEPRECATION: numsamples parameter in sample function is now deprecated. The parameter was added in SymPy 1.7 and continues to work but will emit a DeprecationWarning. The parameter will be removed in a future release. (#21590 by @mostlyaman)

    • PyMC3 library implementation in sample function has been fixed. (#21590 by @mostlyaman)

  • tensor

  • utilities

Authors

Clone this wiki locally