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 "$@"

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.

Comments
  • 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
  • tensor: fix printing of TensMul with imaginary coefficients

    tensor: fix printing of TensMul with imaginary coefficients

    References to other Issues or PRs

    Fixes #24473

    Brief description of what is fixed or changed

    To find the sign of the coefficient, earlier the code would just compare it to zero, leading to an error for an imaginary coefficient. Now, it uses could_extract_minus_sign.

    Other comments

    After this PR:

    >>> print(-I*K(p))
    -I*K(p)
    >>> print(I*K(p))
    I*K(p)
    >>> print(K(p))
    K(p)
    >>> print(-K(p))
    -K(p)
    

    Question: should I add tests for these?

    Release Notes

    • tensor
      • Fixed bug in printing TensMul.
    opened by Kishore96in 3
  • tensor: printing tensor with imaginary coefficients fails

    tensor: printing tensor with imaginary coefficients fails

    Printing of a tensor raises an error if its coefficient is imaginary:

    >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorHead
    >>> from sympy import I
    >>> R3 = TensorIndexType('R3', dim=3)
    >>> p = tensor_indices("p", R3)
    >>> K = TensorHead("K", [R3])
    >>> print(K(p))
    K(p)
    >>> print(I*K(p))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.10/site-packages/sympy/core/_print_helpers.py", line 29, in __str__
        return sstr(self, order=None)
      File "/usr/lib/python3.10/site-packages/sympy/printing/printer.py", line 373, in __call__
        return self.__wrapped__(*args, **kwargs)
      File "/usr/lib/python3.10/site-packages/sympy/printing/str.py", line 1001, in sstr
        s = p.doprint(expr)
      File "/usr/lib/python3.10/site-packages/sympy/printing/printer.py", line 293, in doprint
        return self._str(self._print(expr))
      File "/usr/lib/python3.10/site-packages/sympy/printing/printer.py", line 332, in _print
        return printmethod(expr, **kwargs)
      File "/usr/lib/python3.10/site-packages/sympy/printing/str.py", line 486, in _print_TensMul
        sign, args = expr._get_args_for_traditional_printer()
      File "/usr/lib/python3.10/site-packages/sympy/tensor/tensor.py", line 3872, in _get_args_for_traditional_printer
        if (self.coeff < 0) == True:
      File "/usr/lib/python3.10/site-packages/sympy/core/decorators.py", line 236, in _func
        return func(self, other)
      File "/usr/lib/python3.10/site-packages/sympy/core/expr.py", line 376, in __lt__
        return StrictLessThan(self, other)
      File "/usr/lib/python3.10/site-packages/sympy/core/relational.py", line 834, in __new__
        raise TypeError("Invalid comparison of non-real %s" % me)
    TypeError: Invalid comparison of non-real I
    >>> 
    

    Sympy version: 1.11.1 Python: 3.10.9 OS: Arch Linux

    opened by Kishore96in 0
  • Experiment jupyterlite in sympy docs

    Experiment jupyterlite in sympy docs

    References to other Issues or PRs

    Brief description of what is fixed or changed

    This is an attempt to test out jupyterlite-sphinx in the official doc, such that sympy tutorials and examples can be run from everywhere with web browser I try using the tutorials inside sympy/examples

    Other comments

    Release Notes

    NO ENTRY

    Documentation 
    opened by sylee957 13
  • Improper Evaluation using sympy.vector.Del

    Improper Evaluation using sympy.vector.Del

    When evaluating $\nabla \mathbf{v}$, where $\mathbf{v}$ is a vector (defined below), the Del operator appears to be incorrectly evaluated for cylindrical coordinates. (It is also incorrect in spherical coordinates).

    import sympy as sp
    from sympy.vector import CoordSys3D, Del
    
    R = CoordSys3D('R', transformation='cartesian', vector_names=("i", "j", "k")) # rectangular coordinates
    C = CoordSys3D('C', transformation='cylindrical', vector_names=("e_r", "e_θ", "e_z"),
                                                      variable_names=('r', 'θ', 'z'))     # cylindrical coordinates
    
    t = sp.symbols('t')                             # time
    
    v_r = sp.Function('v_r')(t, C.r, C.θ, C.z)      # in general these components are functions of time and position
    v_θ = sp.Function('v_θ')(t, C.r, C.θ, C.z)
    v_z = sp.Function('v_z')(t, C.r, C.θ, C.z)
    
    v = v_r*C.e_r + v_θ*C.e_θ + v_z*C.e_z
    
    Del_v = Del()(v)
    
    for coeff in [C.e_r, C.e_θ, C.e_z]:
        _ = Del()(v).coeff(coeff).expand()
    
        display(coeff)
        display(_)
        display(_.doit())
    

    Output:

    $$ \mathbf{\hat{e_r}_{C}} $$

    $$ \left(\frac{\partial}{\partial \mathbf{{r}{C}}} v{r}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e_r}{C}} + \left(\frac{\partial}{\partial \mathbf{{r}{C}}} v{z}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e_z}{C}} + \left(\frac{\partial}{\partial \mathbf{{r}{C}}} v{\theta}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e\theta}_{C}} $$

    $$ \mathbf{\hat{e_\theta}_{C}} $$

    $$ \frac{\left(\frac{\partial}{\partial \mathbf{{\theta}{C}}} v{r}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e_r}{C}} + \left(\frac{\partial}{\partial \mathbf{{\theta}{C}}} v{z}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e_z}{C}} + \left(\frac{\partial}{\partial \mathbf{{\theta}{C}}} v{\theta}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e\theta}{C}}}{\mathbf{{r}{C}}} $$

    $$ \mathbf{\hat{e_z}_{C}} $$

    $$ \left(\frac{\partial}{\partial \mathbf{{z}{C}}} v{r}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e_r}{C}} + \left(\frac{\partial}{\partial \mathbf{{z}{C}}} v{z}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e_z}{C}} + \left(\frac{\partial}{\partial \mathbf{{z}{C}}} v{\theta}{\left(t,\mathbf{{r}{C}},\mathbf{{\theta}{C}},\mathbf{{z}{C}} \right)}\right)\mathbf{\hat{e\theta}_{C}} $$

    The output above is correct in the $r$ and $z$ directions, but in the $\theta$ direction, the derivatives of the unit vectors $ \mathbf{e}r $ and $ \mathbf{e}\theta $ are not properly evaluated.

    $$ \mathbf{e}_r = \cos{(\theta)} \mathbf{e}_x + \sin{(\theta)} \mathbf{e}_y $$

    $$ \mathbf{e}_\theta = -\sin{(\theta)} \mathbf{e}_x + \cos{(\theta)} \mathbf{e}_y $$

    $$ \frac{\partial}{\partial \theta} \left(\mathbf{e}_r \right) = -\sin{(\theta)} \mathbf{e}_x + \cos{(\theta)} \mathbf{e}y = \mathbf{e}\theta $$

    $$ \frac{\partial}{\partial \theta} \left(\mathbf{e}_\theta \right) = -\cos{(\theta)} \mathbf{e}_x - \sin{(\theta)} \mathbf{e}_y = -\mathbf{e}_r $$

    Where as Del()(v) seems to evaluate the derivatives as:

    $$ \frac{\partial}{\partial \theta} \left(\mathbf{e}r \right) = \frac{\partial}{\partial \theta} \left(\mathbf{e}\theta \right) = 0 $$

    vector 
    opened by nickbrady 2
  • Adding electron_rest_mass unit in physics.units

    Adding electron_rest_mass unit in physics.units

    References to other Issues or PRs

    Fixes #24462

    Brief description of what is fixed or changed

    The electron rest mass (symbol: me) is the mass of a stationary electron, also known as the invariant mass of the electron. It is one of the fundamental constants of physics.

    Other comments

    Release Notes

    NO ENTRY

    physics.units 
    opened by 1e9abhi1e10 2
  • Missing electron rest mass unit in physics.units

    Missing electron rest mass unit in physics.units

    The electron rest mass (symbol: me) is the mass of a stationary electron, also known as the invariant mass of the electron. It is one of the fundamental constants of physics. It has a value of about 9.109×10−31 kilograms It is not in physics.units should we add it.

    opened by 1e9abhi1e10 0
Releases(sympy-1.11.1)
Owner
SymPy
Symbolic manipulation in Python.
SymPy
A neural-based binary analysis tool

A neural-based binary analysis tool Introduction This directory contains the demo of a neural-based binary analysis tool. We test the framework using

Facebook Research 208 Dec 22, 2022
PyNHD is a part of HyRiver software stack that is designed to aid in watershed analysis through web services.

A part of HyRiver software stack that provides access to NHD+ V2 data through NLDI and WaterData web services

Taher Chegini 23 Dec 14, 2022
PipeChain is a utility library for creating functional pipelines.

PipeChain Motivation PipeChain is a utility library for creating functional pipelines. Let's start with a motivating example. We have a list of Austra

Michael Milton 2 Aug 07, 2022
Predictive Modeling & Analytics on Home Equity Line of Credit

Predictive Modeling & Analytics on Home Equity Line of Credit Data (Python) HMEQ Data Set In this assignment we will use Python to examine a data set

Dhaval Patel 1 Jan 09, 2022
Maximum Covariance Analysis in Python

xMCA | Maximum Covariance Analysis in Python The aim of this package is to provide a flexible tool for the climate science community to perform Maximu

Niclas Rieger 39 Jan 03, 2023
Data analysis and visualisation projects from a range of individual projects and applications

Python-Data-Analysis-and-Visualisation-Projects Data analysis and visualisation projects from a range of individual projects and applications. Python

Tom Ritman-Meer 1 Jan 25, 2022
Flood modeling by 2D shallow water equation

hydraulicmodel Flood modeling by 2D shallow water equation. Refer to Hunter et al (2005), Bates et al. (2010). Diffusive wave approximation Local iner

6 Nov 30, 2022
🧪 Panel-Chemistry - exploratory data analysis and build powerful data and viz tools within the domain of Chemistry using Python and HoloViz Panel.

🧪📈 🐍. The purpose of the panel-chemistry project is to make it really easy for you to do DATA ANALYSIS and build powerful DATA AND VIZ APPLICATIONS within the domain of Chemistry using using Python a

Marc Skov Madsen 97 Dec 08, 2022
Hg002-qc-snakemake - HG002 QC Snakemake

HG002 QC Snakemake To Run Resources and data specified within snakefile (hg002QC

Juniper A. Lake 2 Feb 16, 2022
In this tutorial, raster models of soil depth and soil water holding capacity for the United States will be sampled at random geographic coordinates within the state of Colorado.

Raster_Sampling_Demo (Resulting graph of this demo) Background Sampling values of a raster at specific geographic coordinates can be done with a numbe

2 Dec 13, 2022
Amundsen is a metadata driven application for improving the productivity of data analysts, data scientists and engineers when interacting with data.

Amundsen is a metadata driven application for improving the productivity of data analysts, data scientists and engineers when interacting with data.

Amundsen 3.7k Jan 03, 2023
Statistical Analysis 📈 focused on statistical analysis and exploration used on various data sets for personal and professional projects.

Statistical Analysis 📈 This repository focuses on statistical analysis and the exploration used on various data sets for personal and professional pr

Andy Pham 1 Sep 03, 2022
Elementary is an open-source data reliability framework for modern data teams. The first module of the framework is data lineage.

Data lineage made simple, reliable, and automated. Effortlessly track the flow of data, understand dependencies and analyze impact. Features Visualiza

898 Jan 09, 2023
Weather Image Recognition - Python weather application using series of data

Weather Image Recognition - Python weather application using series of data

Kushal Shingote 1 Feb 04, 2022
Parses data out of your Google Takeout (History, Activity, Youtube, Locations, etc...)

google_takeout_parser parses both the Historical HTML and new JSON format for Google Takeouts caches individual takeout results behind cachew merge mu

Sean Breckenridge 27 Dec 28, 2022
Office365 (Microsoft365) audit log analysis tool

Office365 (Microsoft365) audit log analysis tool The header describes it all WHY?? The first line of code was written long time before other colleague

Anatoly 1 Jul 27, 2022
Mortgage-loan-prediction - Show how to perform advanced Analytics and Machine Learning in Python using a full complement of PyData utilities

Mortgage-loan-prediction - Show how to perform advanced Analytics and Machine Learning in Python using a full complement of PyData utilities. This is aimed at those looking to get into the field of D

Joachim 1 Dec 26, 2021
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

915 Dec 26, 2022
Stochastic Gradient Trees implementation in Python

Stochastic Gradient Trees - Python Stochastic Gradient Trees1 by Henry Gouk, Bernhard Pfahringer, and Eibe Frank implementation in Python. Based on th

John Koumentis 2 Nov 18, 2022
A utility for functional piping in Python that allows you to access any function in any scope as a partial.

WithPartial Introduction WithPartial is a simple utility for functional piping in Python. The package exposes a context manager (used with with) calle

Michael Milton 1 Oct 26, 2021