A computer algebra system written in pure Python

Overview

SymPy

pypi version Build status Join the chat at https://gitter.im/sympy/sympy Zenodo Badge codecov Badge

SymPy Banner

See the AUTHORS file for the list of authors.

And many more people helped on the SymPy mailing list, reported bugs, helped organize SymPy's participation in the Google Summer of Code, the Google Highly Open Participation Contest, Google Code-In, wrote and blogged about SymPy...

License: New BSD License (see the LICENSE file for details) covers all files in the sympy repository unless stated otherwise.

Our mailing list is at https://groups.google.com/forum/?fromgroups#!forum/sympy.

We have community chat at Gitter. Feel free to ask us anything there. We have a very welcoming and helpful community.

Download

The recommended installation method is through Anaconda, https://www.anaconda.com/download/

You can also get the latest version of SymPy from https://pypi.python.org/pypi/sympy/

To get the git version do

$ git clone git://github.com/sympy/sympy.git

For other options (tarballs, debs, etc.), see https://docs.sympy.org/dev/install.html.

Documentation and Usage

For in-depth instructions on installation and building the documentation, see the SymPy Documentation Style Guide.

Everything is at:

https://docs.sympy.org/

You can generate everything at the above site in your local copy of SymPy by:

$ cd doc
$ make html

Then the docs will be in _build/html. If you don't want to read that, here is a short usage:

From this directory, start Python and:

>>> from sympy import Symbol, cos
>>> x = Symbol('x')
>>> e = 1/cos(x)
>>> print(e.series(x, 0, 10))
1 + x**2/2 + 5*x**4/24 + 61*x**6/720 + 277*x**8/8064 + O(x**10)

SymPy also comes with a console that is a simple wrapper around the classic python console (or IPython when available) that loads the SymPy namespace and executes some common commands for you.

To start it, issue:

$ bin/isympy

from this directory, if SymPy is not installed or simply:

$ isympy

if SymPy is installed.

Installation

SymPy has a hard dependency on the mpmath library (version >= 0.19). You should install it first, please refer to the mpmath installation guide:

https://github.com/fredrik-johansson/mpmath#1-download--installation

To install SymPy using PyPI, run the following command:

$ pip install sympy

To install SymPy using Anaconda, run the following command:

$ conda install -c anaconda sympy

To install SymPy from GitHub source, first clone SymPy using git:

$ git clone https://github.com/sympy/sympy.git

Then, in the sympy repository that you cloned, simply run:

$ python setup.py install

See https://docs.sympy.org/dev/install.html for more information.

Contributing

We welcome contributions from anyone, even if you are new to open source. Please read our Introduction to Contributing page and the SymPy Documentation Style Guide. If you are new and looking for some way to contribute, a good place to start is to look at the issues tagged Easy to Fix.

Please note that all participants in this project are expected to follow our Code of Conduct. By participating in this project you agree to abide by its terms. See CODE_OF_CONDUCT.md.

Tests

To execute all tests, run:

$./setup.py test

in the current directory.

For the more fine-grained running of tests or doctests, use bin/test or respectively bin/doctest. The master branch is automatically tested by Travis CI.

To test pull requests, use sympy-bot.

Regenerate Experimental LaTeX Parser/Lexer

The parser and lexer generated with the ANTLR4 toolchain in sympy/parsing/latex/_antlr and checked into the repo. Presently, most users should not need to regenerate these files, but if you plan to work on this feature, you will need the antlr4 command-line tool (and you must ensure that it is in your PATH). One way to get it is:

$ conda install -c conda-forge antlr=4.7.2

Alternatively, follow the instructions on the ANTLR website and download the antlr-4.7.2-complete.jar. Then export the CLASSPATH as instructed and instead of creating antlr4 as an alias, make it an executable file with the following contents:

#!/bin/bash
java -jar /usr/local/lib/antlr-4.7.2-complete.jar "[email protected]"

After making changes to sympy/parsing/latex/LaTeX.g4, run:

$ ./setup.py antlr

Clean

To clean everything (thus getting the same tree as in the repository):

$ ./setup.py clean

You can also clean things with git using:

$ git clean -Xdf

which will clear everything ignored by .gitignore, and:

$ git clean -df

to clear all untracked files. You can revert the most recent changes in git with:

$ git reset --hard

WARNING: The above commands will all clear changes you may have made, and you will lose them forever. Be sure to check things with git status, git diff, git clean -Xn and git clean -n before doing any of those.

Bugs

Our issue tracker is at https://github.com/sympy/sympy/issues. Please report any bugs that you find. Or, even better, fork the repository on GitHub and create a pull request. We welcome all changes, big or small, and we will help you make the pull request if you are new to git (just ask on our mailing list or Gitter Channel). If you further have any queries, you can find answers on Stack Overflow using the sympy tag.

Brief History

SymPy was started by Ondřej Čertík in 2005, he wrote some code during the summer, then he wrote some more code during summer 2006. In February 2007, Fabian Pedregosa joined the project and helped fixed many things, contributed documentation and made it alive again. 5 students (Mateusz Paprocki, Brian Jorgensen, Jason Gedge, Robert Schwarz, and Chris Wu) improved SymPy incredibly during summer 2007 as part of the Google Summer of Code. Pearu Peterson joined the development during the summer 2007 and he has made SymPy much more competitive by rewriting the core from scratch, that has made it from 10x to 100x faster. Jurjen N.E. Bos has contributed pretty-printing and other patches. Fredrik Johansson has written mpmath and contributed a lot of patches.

SymPy has participated in every Google Summer of Code since 2007. You can see https://github.com/sympy/sympy/wiki#google-summer-of-code for full details. Each year has improved SymPy by bounds. Most of SymPy's development has come from Google Summer of Code students.

In 2011, Ondřej Čertík stepped down as lead developer, with Aaron Meurer, who also started as a Google Summer of Code student, taking his place. Ondřej Čertík is still active in the community but is too busy with work and family to play a lead development role.

Since then, a lot more people have joined the development and some people have also left. You can see the full list in doc/src/aboutus.rst, or online at:

https://docs.sympy.org/dev/aboutus.html#sympy-development-team

The git history goes back to 2007 when development moved from svn to hg. To see the history before that point, look at https://github.com/sympy/sympy-old.

You can use git to see the biggest developers. The command:

$ git shortlog -ns

will show each developer, sorted by commits to the project. The command:

$ git shortlog -ns --since="1 year"

will show the top developers from the last year.

Citation

To cite SymPy in publications use

Meurer A, Smith CP, Paprocki M, Čertík O, Kirpichev SB, Rocklin M, Kumar A, Ivanov S, Moore JK, Singh S, Rathnayake T, Vig S, Granger BE, Muller RP, Bonazzi F, Gupta H, Vats S, Johansson F, Pedregosa F, Curry MJ, Terrel AR, Roučka Š, Saboo A, Fernando I, Kulal S, Cimrman R, Scopatz A. (2017) SymPy: symbolic computing in Python. PeerJ Computer Science 3:e103 https://doi.org/10.7717/peerj-cs.103

A BibTeX entry for LaTeX users is

@article{10.7717/peerj-cs.103,
 title = {SymPy: symbolic computing in Python},
 author = {Meurer, Aaron and Smith, Christopher P. and Paprocki, Mateusz and \v{C}ert\'{i}k, Ond\v{r}ej and Kirpichev, Sergey B. and Rocklin, Matthew and Kumar, Amit and Ivanov, Sergiu and Moore, Jason K. and Singh, Sartaj and Rathnayake, Thilina and Vig, Sean and Granger, Brian E. and Muller, Richard P. and Bonazzi, Francesco and Gupta, Harsh and Vats, Shivam and Johansson, Fredrik and Pedregosa, Fabian and Curry, Matthew J. and Terrel, Andy R. and Rou\v{c}ka, \v{S}t\v{e}p\'{a}n and Saboo, Ashutosh and Fernando, Isuru and Kulal, Sumith and Cimrman, Robert and Scopatz, Anthony},
 year = 2017,
 month = Jan,
 keywords = {Python, Computer algebra system, Symbolics},
 abstract = {
            SymPy is an open-source computer algebra system written in pure Python. It is built with a focus on extensibility and ease of use, through both interactive and programmatic applications. These characteristics have led SymPy to become a popular symbolic library for the scientific Python ecosystem. This paper presents the architecture of SymPy, a description of its features, and a discussion of select submodules. The supplementary material provides additional examples and further outlines details of the architecture and features of SymPy.
         },
 volume = 3,
 pages = {e103},
 journal = {PeerJ Computer Science},
 issn = {2376-5992},
 url = {https://doi.org/10.7717/peerj-cs.103},
 doi = {10.7717/peerj-cs.103}
}

SymPy is BSD licensed, so you are free to use it whatever you like, be it academic, commercial, creating forks or derivatives, as long as you copy the BSD statement if you redistribute it (see the LICENSE file for details). That said, although not required by the SymPy license, if it is convenient for you, please cite SymPy when using it in your work and also consider contributing all your changes back, so that we can incorporate it and all of us will benefit in the end.

Issues
  • solve has many issues with fractions

    solve has many issues with fractions

    >>> import sympy
    >>> x=sympy.var('x')
    
    Zero is sometimes wrongly reported as a solution.
    
    >>> sympy.solve(-(1 + x)/(2 + x)**2 + 1/(2 + x), x)
    [0]
    
    There is a corresponding "TODO" in the source code, but it would be easy to
    verify if 0 is an effective solution.
    (# TODO: we might have introduced unwanted solutions when multiplied by x**-m)
    
    
    Note that some calculus also lead to infinite recursion.
    
    >>> sympy.solve(1/x,x)
    [...]
    <type 'exceptions.RuntimeError'>: maximum recursion depth exceeded
    
    
    I've patched my own sympy installation ; if I manage to find some time,
    I'll try to deal with all the git stuff to produce a proper sympy patch.
    

    Original issue for #4793: http://code.google.com/p/sympy/issues/detail?id=1694 Original author: https://code.google.com/u/117997262464115802198/ Referenced issues: #4871, #5117, #5016, #5086, #5091, #5226, #5035, #4463, #4464, #5171, #4922, #5098 Original owner: https://code.google.com/u/117997262464115802198/

    imported Bug Needs Review solvers 
    opened by wxgeo 180
  • Introduce rewrite rules

    Introduce rewrite rules

    This introduces basic rewrite rules and strategies to SymPy.

    It also uses these rewrite rules to refactor the MatrixExpressions module

    TODO

    1. ~~Rename as_factor_mul. Merge with as_coeff_mmul~~
    2. ~~rewrite linear_factors (uses a lot of Expr functionality)~~ I've removed this all-together. The definition isn't consistent. I'll work on this in a future PR. Currently only work in other branches of mine uses this sympy.stats.mvnrv
    3. MatMul/MatAdd don't simplify by default (maybe?) (I'm going to wait on this.)
    4. ~~simplification in MatMul/MatAdd doesn't have to traverse entire tree~~
    rr/rl.py         - some fundamental rules
    rr/strat_pure.py - strategies that have nothing to do with SymPy
    rr/traverse.py   - strategies that traverse a SymPy AST
    rr/strat.py      - some conglomerate strategies that do depend on SymPy
    

    matrices/expressions/mat(add/mul).py - Some rules written in normal python language and the use of strategies to combine those rules. Can we replace these by something higher level written in the SymPy language? If so what? These files provide examples of the sorts of rules we'll want to write. The rules are at the bottom matrices/expressions/blockmatrix.py -- I replaced block_collapse (a giant function) with rules. This is a good change but could have been done just as easily by adding methods to existing classes. This is a more aggressive example of using rules to program SymPy. It's rules-for-transformation rather than just rules-for-canonicalization.

    opened by mrocklin 178
  • Gsoc 3

    Gsoc 3

    This is my final pull request of GSOC code. I understand that the gsoc-2 pull request is still being reviewed (which makes this one look quite monstrous, with >80 commits..), but as suggested elsewhere I'm trying to submit all pull requests (i.e. this one) before the soft pencils down deadline. Also submitting this pull request is my pledge not to rebase the branch more often than absolutely necessary.

    The commits in this pull request can be separated roughly into three categories (and in principle I could submit separate pull requests for each of these, although I'm not sure if this is helpful):

    • new special functions (polylog, lerchphi, exponential integrals; with varying degree of support for integration)
    • general improvements to integration (neater output, more clever heurstics)
    • performance improvements

    Over the next few days I will go through and label all the commits (according to a consistent scheme to be come up with...) in order to make reviewing easier (which will of course mean rebasing...)

    opened by ness01 151
  • Added function to calculate Cauchy's principal value in sympy/integrals/integrals.py

    Added function to calculate Cauchy's principal value in sympy/integrals/integrals.py

    Added function cauchy_principal_value in sympy/integrals/integrals.py to implement calculation of Cauchy's principal value

    Took help (code) and reviews by @asmeurer in #14538

    Note : I found this PR (#14538) quite helpful, and since there wasn't any on-going activity for quite some time, I decided to take it up and fix the issues and also add the reviews given by @asmeurer in the original PR.

    Also, If required, I will add more tests and examples for the same.

    Please review this PR and give me a feedback. Thanks

    Release Notes

    • integrals
      • added method principal_value to class Integral to calculate Cauchy's principal value along with tests.
    opened by avishrivastava11 145
  • Issue 3275

    Issue 3275

    Application of qapply(Rotation(alpha,beta,gamma)*JzKet(1,1)) [define the symbols alpha beta and gamma](And these are dummy) would ask for the inputs of alpha,beta,gamma.The parameters used in calling the function must be used to in the method and this is not happening so I had to ask for the input.Is there anyway that I could get it working without the use of asking for input.The issue is not completely solved because the same method has to be written for every spin state.

    opened by amitjamadagni 138
  • [GSoC] Add TransferFunction, Series, Parallel and Feedback classes for control package

    [GSoC] Add TransferFunction, Series, Parallel and Feedback classes for control package

    References to other Issues or PRs

    Built upon #18436.

    Brief description of what is fixed or changed

    This PR adds a class for representing LTI systems in transfer function form.

    Other comments

    TODO:

    • [x] adding TransferFunction class along with its functionality.

    • [x] Rewrite unit-tests and make sure they pass.

    • [x] Adding documentation.

    Release Notes

    • physics.control
      • Add TransferFunction, Series, Parallel, and Feedback class for physics.control submodule
    GSoC physics.control 
    opened by namannimmo10 134
  • Solving solvable quintics: First implementation

    Solving solvable quintics: First implementation

    Please see this: http://code.google.com/p/sympy/issues/detail?id=3548

    Also, see this: https://groups.google.com/forum/?fromgroups=#!topic/sympy/xXyiOUWH0SU

    According to the discussions on above links, this PR introduces solving quintics exactly (not numerically) when they are solvable.

    There are a lot of constants involved. So, I created a new file and made a new class for quintics containing required constants. Also note that solving quintics exactly takes( for x5 + 15*x +12 =0 ) ~ 40 secs. The long time is attributed to solving five equations of the form x5 - R =0 somewhere in the middle of the code.

    Also, I have used simplify a few times. It seems that the code became almost 3 times as fast with using simplify, than without it.

    There is an extra flag; quintics. When set to true, the new roots_quintic method is called and if the quintic is solvable, the solution is returned. I am attaching a screenshot : sympy

    Here you can see the solution of x*_5 + 15_x +12 = 0.

    I have not added any tests. @asmeurer Please look at the code. Let me know for changes required.

    opened by prasoon2211 131
  • Proof of concept for the new assumptions

    Proof of concept for the new assumptions

    Here is a proof of concept of how I think the new assumptions should be done, as per https://code.google.com/p/sympy/issues/detail?id=3929. Take a read of the commit messages. The basic idea is that instead of writing handlers that look for expressions like Q.zero(x*y) and return new expressions that it knows are true like Q.zero(x) and Q.zero(y), the handler system returns a set of predicate statements, and everything is done using satisfiable(). This not only makes things cleaner, and gives us a single point of contact to make the assumptions faster (the dpll algorithm), it also allows computing things that are impossible to do under the current handler system. For instance

    >>> from sympy.assumptions.newask import newask
    >>> newask(Q.zero(x) | Q.zero(y), Q.zero(x*y))
    True
    >>> newask(Implies(Q.zero(x), Q.zero(x*y)))
    True
    >>> newask(Q.zero(x) | Q.zero(y), Q.nonzero(x*y))
    False
    >>> ask(Q.zero(x) | Q.zero(y), Q.zero(x*y))
    >>> ask(Implies(Q.zero(x), Q.zero(x*y)))
    >>> ask(Q.zero(x) | Q.zero(y), Q.nonzero(x*y))
    

    It's impossible to write a handler that says "x is zero or y is zero, but we don't know which one".

    I would like some feedback at this point. This code is completely proof of concept. The API is terrible (basically nonexistant). What I've got now is completely unscalable. It already is getting out of hand, and I've only got four assumptions, real, positive, zero, and nonzero.

    I've completely ignored the existing ask() code, because I didn't want to spend a lot of time at this point trying to understand it (it's quite complicated), so I basically wrote the prototype from scratch. Even so, it's quite simple, and I think once you grok how the satisfiable bit works, it is easy to understand the rest.

    So my biggest questions now are, do people like this idea? Do you foresee any major issues with it? Most importantly, what would be a good way to organize the new-style "handlers" (relevant fact extraction) so that it is scalable, extensible, and readable?

    Update: newask has been changed to satask

    assumptions 
    opened by asmeurer 128
  • Rewriting the Univariate Solver

    Rewriting the Univariate Solver

    This PR aims to rewrite a cleaner and robust univariate equation solver.

    • [x] polynomial
    • [x] rational
    • [x] real trigonometric
    • [x] write 4 tests to complete coverage
    • [x] correct typo
    • [x] correct this failure

    Nonblocking todo

    • [ ] functions solvable by LambertW
    • [ ] functions that can be recast as polynomials with a change of variables this, for example; this can be factored out of solve where multiple generators are handled
    • [ ] use something like this to handle the XFAILed test test_real_imag_splitting1, this will be handled in the set module.
    solvers GSoC solvers.solveset 
    opened by hargup 127
  • Ideas to introduce indexed objects (possibly representing tensors)

    Ideas to introduce indexed objects (possibly representing tensors)

    Hi there! I'm currently writing a system of indexed n-dimensional arrays and valued tensors.

    BUGS AND ISSUES:

    • [ ] put more comments about the code.
    • [ ] create TensorIndexType.from_data( ) / TensorIndexType.from_symmetry( ) methods.
    • [x] missing tests for .applyfunc on TensExpr.
    • [x] create .strip( )
    • [x] test .strip( )
    • [ ] repeat all of Pernici's tests on valued tensors as well (or maybe not really all of them).
    • [ ] mark all autodrop points with comments.
    • [x] check that MultiArray never replaces TensorSymmetry in all objects' args.
    • [x] MultiArray shall never autodrop.
    • [ ] test many NumericIndices on the same tensor.
    • [x] create tests with non-diagonal metric.
    • [ ] create tests for MultiArray of rank zero.
    • [ ] correct args in TensMul, and everywhere else
    • [ ] remove @XFAIL from core tests.
    • [x] NumericContravariant and NumericCovariant: only int indices
    • [ ] Decide if NumericContravariant and NumericCovariant are to be subclasses of Basic.
    • [x] direct_sum in MultiArray
    • [x] create tests for direct_sum
    • [ ] direct sum of tensors
    • [ ] tensor product of tensor indices (and method on tensors as well).
    • [ ] check args in TensorIndexType and TensorIndex
    • [ ] check args in valued TensorIndexType
    • [ ] generator MultiArray.create( … ) for rank 0 ?
    • [ ] extend MultiArray to higher rank?
    • [ ] Why in TensorHead isn't comm passed to Basic's constructor?
    • [ ] more control for wrong data in constructors.
    • [ ] test type( … *args ) in NumericContravariant
    • [ ] construct new data from self.args and check equality and hash compatibility with original data.
    • [ ] find all TODO and solve the problems
    • [ ] remove all TODO
    • [ ] should MultiArray be renamed NDArray or something else?
    • [ ] can we inspect numpy's code for their implementation of nDarrays, and import some features here?
    opened by Upabjojr 127
  • Introduce general add, mul, and pow function

    Introduce general add, mul, and pow function

    References to other Issues or PRs

    Closes #18769 Fixes #18768

    Brief description of what is fixed or changed

    Other comments

    Release Notes

    • core
      • Extensible add, mul and power functions are introduced to allow sympy objects to define what classes should be used for them in place of Add, Mul and Pow (e.g. matrices use MatAdd). This is an experimental approach aimed at enabling the behaviour of core routines (expand, collect, etc) to be customised by user-defined types (e.g. MatAdd rather than Add). This mechanism is still experimental, is not fully implemented across the core and might be changed or removed in a future release of sympy.
    core 
    opened by mcpl-sympy 125
  • [WIP] Optimize evaluation for float arguments

    [WIP] Optimize evaluation for float arguments

    References to other Issues or PRs

    See #23541

    Brief description of what is fixed or changed

    Improve performance of evaluation for float arguments.

    Other comments

    Release Notes

    WIP

    opened by eendebakpt 2
  • Series expansion of `airyai` at infinity undefined

    Series expansion of `airyai` at infinity undefined

    A colleague asked if SymPy could handle this but apparently it cannot:

    In [13]: series(airyai(x), x, oo)
    ---------------------------------------------------------------------------
    PoleError: 
    Asymptotic expansion of airyai around [oo] is not implemented.
    > /home/oscar/current/sympy/sympy.git/sympy/core/function.py(658)_eval_aseries()
        656         """
        657         from sympy.utilities.misc import filldedent
    --> 658         raise PoleError(filldedent('''
        659             Asymptotic expansion of %s around %s is
        660             not implemented.''' % (type(self), args0)))
    

    Also I don't know what this is:

    In [14]: series(airyai(x), x, zoo)
    Out[14]: Ai(zoo)
    
    In [15]: series(exp(x), x, zoo)
    Out[15]: nan
    

    Should expansion at zoo be the same as at oo?

    series 
    opened by oscarbenjamin 3
  • In new version of sympy, dsolve does not give a solution when another derivative is involved

    In new version of sympy, dsolve does not give a solution when another derivative is involved

    Hi, In sympy 1.7.1, this computation was giving the expected result:

    import sympy as sp
    x,y = sp.symbols('x y')
    f = sp.Function('f')
    g = sp.Function('g')
    sp.dsolve(sp.diff(f(x),x)+g(y),f(x))
    

    $f{\left(x \right)} = C_{1} - x g{\left(y \right)}$

    sp.dsolve(sp.diff(f(x),x)+sp.diff(g(y),y),f(x))
    

    $f{\left(x \right)} = C_{1} - x \frac{d}{d y} g{\left(y \right)}$

    But, when sympy 1.10.1 is used, it raises an error for the second command:

    sp.dsolve(sp.diff(f(x),x)+sp.diff(g(y),y),f(x))
    
    ----------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    Input In [4], in <cell line: 1>()
    ----> 1 sp.dsolve(sp.diff(f(x),x)+sp.diff(g(y),y),f(x))
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/solvers/ode/ode.py:640, in dsolve(eq, func, hint, simplify, ics, xi, eta, x0, n, **kwargs)
        637 else:
        638     # The key 'hint' stores the hint needed to be solved for.
        639     hint = hints['hint']
    --> 640     return _helper_simplify(eq, hint, hints, simplify, ics=ics)
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/solvers/ode/ode.py:669, in _helper_simplify(eq, hint, match, simplify, ics, **kwargs)
        664 if simplify:
        665     # odesimp() will attempt to integrate, if necessary, apply constantsimp(),
        666     # attempt to solve for func, and apply any other hint specific
        667     # simplifications
        668     if isinstance(solvefunc, SingleODESolver):
    --> 669         sols = solvefunc.get_general_solution()
        670     else:
        671         sols = solvefunc(eq, func, order, match)
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/solvers/ode/single.py:296, in SingleODESolver.get_general_solution(self, simplify)
        294     msg = "%s solver cannot solve:\n%s"
        295     raise ODEMatchError(msg % (self.hint, self.ode_problem.eq))
    --> 296 return self._get_general_solution(simplify_flag=simplify)
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/solvers/ode/single.py:2398, in NthLinearConstantCoeffUndeterminedCoefficients._get_general_solution(self, simplify_flag)
       2396 gsol = _solve_undetermined_coefficients(eq, f(x), order, self.r, self.trialset)
       2397 if simplify_flag:
    -> 2398     gsol = _get_simplified_sol([gsol], f(x), collectterms)
       2399 return [gsol]
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/solvers/ode/nonhomogeneous.py:271, in _get_simplified_sol(sol, func, collectterms)
        269 for i, reroot, imroot in collectterms:
        270     sol = collect(sol, x**i*exp(reroot*x)*sin(abs(imroot)*x))
    --> 271     sol = collect(sol, x**i*exp(reroot*x)*cos(imroot*x))
        272 for i, reroot, imroot in collectterms:
        273     sol = collect(sol, x**i*exp(reroot*x))
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:175, in collect(expr, syms, func, evaluate, exact, distribute_order_term)
        173 reps = dict(zip(nonsyms, [Dummy(**assumptions(i)) for i in nonsyms]))
        174 syms = [reps.get(s, s) for s in syms]
    --> 175 rv = collect(expr.subs(reps), syms,
        176     func=func, evaluate=evaluate, exact=exact,
        177     distribute_order_term=distribute_order_term)
        178 urep = {v: k for k, v in reps.items()}
        179 if not isinstance(rv, dict):
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:360, in collect(expr, syms, func, evaluate, exact, distribute_order_term)
        358 if expr.is_Add:
        359     o = expr.getO() or 0
    --> 360     expr = expr.func(*[
        361             collect(a, syms, func, True, exact, distribute_order_term)
        362             for a in expr.args if a != o]) + o
        363 elif expr.is_Mul:
        364     return expr.func(*[
        365         collect(term, syms, func, True, exact, distribute_order_term)
        366         for term in expr.args])
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:361, in <listcomp>(.0)
        358 if expr.is_Add:
        359     o = expr.getO() or 0
        360     expr = expr.func(*[
    --> 361             collect(a, syms, func, True, exact, distribute_order_term)
        362             for a in expr.args if a != o]) + o
        363 elif expr.is_Mul:
        364     return expr.func(*[
        365         collect(term, syms, func, True, exact, distribute_order_term)
        366         for term in expr.args])
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:364, in collect(expr, syms, func, evaluate, exact, distribute_order_term)
        360     expr = expr.func(*[
        361             collect(a, syms, func, True, exact, distribute_order_term)
        362             for a in expr.args if a != o]) + o
        363 elif expr.is_Mul:
    --> 364     return expr.func(*[
        365         collect(term, syms, func, True, exact, distribute_order_term)
        366         for term in expr.args])
        367 elif expr.is_Pow:
        368     b = collect(
        369         expr.base, syms, func, True, exact, distribute_order_term)
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:365, in <listcomp>(.0)
        360     expr = expr.func(*[
        361             collect(a, syms, func, True, exact, distribute_order_term)
        362             for a in expr.args if a != o]) + o
        363 elif expr.is_Mul:
        364     return expr.func(*[
    --> 365         collect(term, syms, func, True, exact, distribute_order_term)
        366         for term in expr.args])
        367 elif expr.is_Pow:
        368     b = collect(
        369         expr.base, syms, func, True, exact, distribute_order_term)
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:391, in collect(expr, syms, func, evaluate, exact, distribute_order_term)
        389 c, nc = product.args_cnc(split_1=False)
        390 args = list(ordered(c)) + nc
    --> 391 terms = [parse_term(i) for i in args]
        392 small_first = True
        394 for symbol in syms:
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:391, in <listcomp>(.0)
        389 c, nc = product.args_cnc(split_1=False)
        390 args = list(ordered(c)) + nc
    --> 391 terms = [parse_term(i) for i in args]
        392 small_first = True
        394 for symbol in syms:
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:281, in collect.<locals>.parse_term(expr)
        279         sexpr, rat_expo = exp(tail), coeff
        280 elif isinstance(expr, Derivative):
    --> 281     sexpr, deriv = parse_derivative(expr)
        283 return sexpr, rat_expo, sym_expo, deriv
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/simplify/radsimp.py:211, in collect.<locals>.parse_derivative(deriv)
        208 def parse_derivative(deriv):
        209     # scan derivatives tower in the input expression and return
        210     # underlying function and maximal differentiation order
    --> 211     expr, sym, order = deriv.expr, deriv.variables[0], 1
        213     for s in deriv.variables[1:]:
        214         if s == sym:
    
    File ~/anaconda3/lib/python3.9/site-packages/sympy/core/function.py:1664, in Derivative.variables(self)
       1662 for v, count in self.variable_count:
       1663     if not count.is_Integer:
    -> 1664         raise TypeError(filldedent('''
       1665         Cannot give expansion for symbolic count. If you just
       1666         want a list of all variables of differentiation, use
       1667         _wrt_variables.'''))
       1668     rv.extend([v]*count)
       1669 return tuple(rv)
    
    TypeError: 
    Cannot give expansion for symbolic count. If you just want a list of
    all variables of differentiation, use _wrt_variables.
    

    It looks like previous versions of sympy was working better in this case.

    simplify solvers.dsolve 
    opened by rclUPC 4
  • do not use solve in idiff

    do not use solve in idiff

    References to other Issues or PRs

    closes #23554

    Brief description of what is fixed or changed

    A more optimized internal solving process is used to calculate the derivatives. The existing tests already run faster. The expression below runs about 4X faster relative to master:

    eq=x**3 + y**3 - (3*x*y**2 - x - 1)*(x**2 + x*y + y**2 - 10)
    t=time()
    y1=idiff(eq, y,x)
    time()-t
    t=time()
    y2=idiff(eq, y,x,2)
    time()-t
    

    The equation given on the issue page runs about 200X faster.

    Other comments

    It seems like this should be faster than it is.... Would using cse help in any way?

    Release Notes

    • geometry
      • idiff is more efficient at calculating derivatives
    opened by smichr 2
  • manualintegrate x**n*diff(f, x, n+1)

    manualintegrate x**n*diff(f, x, n+1)

    References to other Issues or PRs

    Fixes #23495 Fixes #16161

    Brief description of what is fixed or changed

    $\int x^n f^{(n+1)}(x)\mathrm{d}x=\int x^n\mathrm{d}f^{(n)}(x)$ $=x^n f^{(n)}(x)-n\int x^{n-1}f^{(n)}(x)\mathrm{d}x$ $=x^n f^{(n)}(x)-nx^{n-1}f^{(n-1)}(x)+n(n-1)x^{n-2}f^{(n-2)}(x)-\cdots+(-1)^{n}n!f(x)$ $=\Sigma_{i=0}^n (-1)^{i}\frac{n!}{(n-i)!}x^{n-i} f^{(n-i)}(x)$

    Other comments

    Release Notes

    • integrals
      • Support integrate(x**n*diff(f(x), x, n+1)) for Integer n
    integrals.manualintegrate 
    opened by eagleoflqj 2
  • Unexpected plot() behavior: won't in range defined by xlim

    Unexpected plot() behavior: won't in range defined by xlim

    from sympy import *
    x = Symbol('x')
    
    f = x - 10
    plot(f, xlim=[10, 20], backend='text')
    

    Produces:

          0 |                                                     ..
            |                                                  ...  
            |                                                ..     
            |                                             ...       
            |                                          ...          
            |                                        ..             
            |                                     ...               
            |                                  ...                  
            |                                ..                     
            |                             ...                       
        -10 |--------------------------...--------------------------
            |                       ...                             
            |                     ..                                
            |                  ...                                  
            |               ...                                     
            |             ..                                        
            |          ...                                          
            |       ...                                             
            |     ..                                                
            |  ...                                                  
        -20 |_______________________________________________________
             -10                        0                          10
    

    Which is unexpected. Why plotting [-10, 10], when I ask from [10, 20]? Similarly, the matplotlib backend fails. sympy.__version__ '1.10.1'. Tested on debianLinux local 5.10.0-14-amd64 sympy/sympy.github.com#1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux. Python version 3.9.2

    opened by mindey 1
Releases(sympy-1.10.1)
Owner
SymPy
Symbolic manipulation in Python.
SymPy
PyPSA: Python for Power System Analysis

1 Python for Power System Analysis Contents 1 Python for Power System Analysis 1.1 About 1.2 Documentation 1.3 Functionality 1.4 Example scripts as Ju

null 666 May 31, 2022
Tuplex is a parallel big data processing framework that runs data science pipelines written in Python at the speed of compiled code

Tuplex is a parallel big data processing framework that runs data science pipelines written in Python at the speed of compiled code. Tuplex has similar Python APIs to Apache Spark or Dask, but rather than invoking the Python interpreter, Tuplex generates optimized LLVM bytecode for the given pipeline and input data set.

Tuplex 758 May 16, 2022
Very basic but functional Kakuro solver written in Python.

kakuro.py Very basic but functional Kakuro solver written in Python. It uses a reduction to exact set cover and Ali Assaf's elegant implementation of

Louis Abraham 4 Jan 15, 2022
Datashredder is a simple data corruption engine written in python. You can corrupt anything text, images and video.

Datashredder is a simple data corruption engine written in python. You can corrupt anything text, images and video. You can chose the cha

null 3 Jan 3, 2022
Evidence enables analysts to deliver a polished business intelligence system using SQL and markdown.

Evidence enables analysts to deliver a polished business intelligence system using SQL and markdown

null 672 May 30, 2022
A forecasting system dedicated to smart city data

smart-city-predictions System prognostyczny dedykowany dla danych inteligentnych miast Praca inżynierska realizowana przez Michała Stawikowskiego and

Kevin Lai 1 Nov 8, 2021
Galvanalyser is a system for automatically storing data generated by battery cycling machines in a database

Galvanalyser is a system for automatically storing data generated by battery cycling machines in a database, using a set of "harvesters", whose job it

Battery Intelligence Lab 18 May 27, 2022
PySpark bindings for H3, a hierarchical hexagonal geospatial indexing system

h3-pyspark: Uber's H3 Hexagonal Hierarchical Geospatial Indexing System in PySpark PySpark bindings for the H3 core library. For available functions,

Kevin Schaich 5 Apr 19, 2022
songplays datamart provide details about the musical taste of our customers and can help us to improve our recomendation system

Songplays User activity datamart The following document describes the model used to build the songplays datamart table and the respective ETL process.

Leandro Kellermann de Oliveira 1 Jul 13, 2021
A 2-dimensional physics engine written in Cairo

A 2-dimensional physics engine written in Cairo

Topology 30 May 25, 2022
Example Of Splunk Search Query With Python And Splunk Python SDK

SSQAuto (Splunk Search Query Automation) Example Of Splunk Search Query With Python And Splunk Python SDK installation: ➜ ~ git clone https://github.c

AmirHoseinTangsiriNET 1 Nov 14, 2021
Business Intelligence (BI) in Python, OLAP

Open Mining Business Intelligence (BI) Application Server written in Python Requirements Python 2.7 (Backend) Lua 5.2 or LuaJIT 5.1 (OML backend) Mong

Open Mining 1.2k May 20, 2022
Incubator for useful bioinformatics code, primarily in Python and R

Collection of useful code related to biological analysis. Much of this is discussed with examples at Blue collar bioinformatics. All code, images and

Brad Chapman 544 May 26, 2022
Karate Club: An API Oriented Open-source Python Framework for Unsupervised Learning on Graphs (CIKM 2020)

Karate Club is an unsupervised machine learning extension library for NetworkX. Please look at the Documentation, relevant Paper, Promo Video, and Ext

Benedek Rozemberczki 1.6k May 30, 2022
Probabilistic Programming in Python: Bayesian Modeling and Probabilistic Machine Learning with Theano

PyMC3 is a Python package for Bayesian statistical modeling and Probabilistic Machine Learning focusing on advanced Markov chain Monte Carlo (MCMC) an

PyMC 6.6k May 31, 2022
Statsmodels: statistical modeling and econometrics in Python

About statsmodels statsmodels is a Python package that provides a complement to scipy for statistical computations including descriptive statistics an

statsmodels 7.4k May 29, 2022
ForecastGA is a Python tool to forecast Google Analytics data using several popular time series models.

ForecastGA is a tool that combines a couple of popular libraries, Atspy and googleanalytics, with a few enhancements.

JR Oakes 32 Apr 13, 2022
Multiple Pairwise Comparisons (Post Hoc) Tests in Python

scikit-posthocs is a Python package that provides post hoc tests for pairwise multiple comparisons that are usually performed in statistical data anal

Maksim Terpilowski 241 May 31, 2022