Note: this is from the sympy/sympy wiki
- Sympy Cheat Sheet Pdf
- Sympy Cheat Sheet
- Sympy Cheat Sheet Free
- Sympy Cheat Sheet 2020
- Sympy Cheat Sheet
- Sympy Cheat Sheet 2019
The sympy git server is at https://github.com/sympy/sympy . The main Sympy repository may be cloned with 'git clone git://github.com/sympy/sympy.git'.
The first and the most important thing is that you should understand that git is ''different''. For example it uses staging area (so called index) for iteratively preparing commits. This and other great and unique features of git make it the preference of many developers, so go read its documentation - you would not regret!
This Python cheat sheet is a quick reference for NumPy beginners. Given the fact that it's one of the fundamental packages for scientific computing, NumPy is one of the packages that you must be able to use and know if you want to do data science with Python. It offers a great alternative to Python lists, as NumPy arrays are more compact, allow faster access in reading and writing items, and are more.
- Git / Mercurial Rosetta Stone. GitHub Gist: instantly share code, notes, and snippets.
- The Jupyter notebook cheat sheet. We often want nice rational functions, but sympy doesn’t make expressions rational by default 10: chareq = GvGpGm. Gc + 1 chareq.
git project page http://git.or.cz/
git faq explaining many things http://git.or.cz/gitwiki/GitFaq*: make sure you read mails referenced from the faq - they are really brilliant, e.g. this mail by Linus about git and renames: http://permalink.gmane.org/gmane.comp.version-control.git/217
git wiki http://git.or.cz/gitwiki
git documentation http://git.or.cz/gitwiki/GitDocumentation
Here is a nice cheatsheet which will probably make your life easier in the beginning: http://jan-krueger.net/development/git-cheat-sheet-extended-edition
Being said all this, now comes a 'simplified' mapping between hg commands and git commands. Use it with care -- there are some semantic differences ...
If you know how to use hg very well and just looking at how to do the same things in git, this page is right for you. Use it like a dictionary hg -> git.Some equivalent git commands may seem more complex than the corresponding hg counterparts; that's because the natural flow of work in git doesn't map 1:1 to Mercurial. But the point here is that if you are used to some specific workflow in hg, it can be directly translated to git using the table below and it does exactly the same thing as you are expecting it to.
When editing this wiki page, please only add an exact equivalent to some hg command; a full explanation can always be found somewhere else on the net.
Rosetta Stone
{| border='0' cellspacing='5' cellpadding='5' align='top'! width='50%' | hg! width='50%' | git|-| hg cat -r rev some_file
git show rev:some_file |
---|
hg clone http://hg.sympy.org/sympy-git.hg |
git clone git://git.sympy.org/sympy.git |
- |
hg clone -U http://hg.sympy.org/sympy-git.hg |
git clone --bare git://git.sympy.org/sympy.git |
- |
hg diff |
git diff HEAD |
- |
hg status |
git status |
- |
hg status -c |
git ls-files -t |
- |
hg manifest |
git ls-tree -r --name-only --full-tree HEAD |
- |
hg parents |
git show --pretty=format:'%P' -s |
- |
hg commit |
git commit -a |
- |
hg record |
git add -p; git commit # or, for a more detailed interface: git add -i; git commit |
- |
[http://mercurial.selenic.com/wiki/PatchbombExtension hg email -r tip] |
git send-email HEAD^ # or: git format-patch HEAD^ ; git send-email 0001-Add-whitespace.patch |
- |
hg view |
gitk, git gui |
- |
hg help command |
git help command |
- |
~/.hgrc |
~/.gitconfig |
- |
.hg/hgrc |
.git/config |
- |
hg paths |
git remote -v |
- |
editing paths in .hg/hgrc |
git remote add name url # see 'git help remote' for more info how to edit paths; alternatively, you can edit them by hand in .git/config too |
- |
.hgignore |
[http://www.kernel.org/pub/software/scm/git/docs/gitignore.html .gitignore] |
- |
[http://mercurial.selenic.com/wiki/TipsAndTricks#Ignore_files_in_local_working_copy_only .hg/hgrc [ui] ignore] |
[http://stackoverflow.com/a/6117232/3829 .git/info/exclude] |
- |
hg add |
git add (note, it adds content to index; can work on a hunk-by-hunk basis with -p!) |
- |
hg rm |
git rm |
- |
hg push |
git push |
- |
hg pull |
git fetch |
- |
hg pull -u |
git pull |
- |
hg addremove |
XXX |
- |
hg revert -a |
git reset --hard |
- |
hg revert some_file |
git checkout some_file |
- |
hg purge |
git clean -fd |
- |
hg purge --all |
git clean -fdx |
- |
[http://mercurial.selenic.com/wiki/Strip hg strip 2fccd4c] |
git reset --hard 2fccd4c^ |
- |
hg export |
git format-patch |
- |
hg import --no-commit some.patch |
git apply some.patch |
- |
hg import some.patch |
git am some.patch |
- |
hg out |
git fetch && git log FETCH_HEAD..master |
- |
hg in |
git fetch && git log master..FETCH_HEAD |
- |
hg update tip |
git checkout HEAD # or this: 'git checkout master', or 'git merge FETCH_HEAD', depending on what you did before this |
- |
hg update -C |
git checkout -f |
- |
hg update some.branch |
git checkout some.branch # 'Note that 'git branch some.branch' is ''not'' the same as this.' |
- |
hg up --date 2014-01-01 |
git checkout git rev-list -n 1 --before='2014-01-01' master |
- |
hg qimport |
stg something (A separate patch manager extension is probably not necessary in git -- normal workflow combined with git rebase -i should cover your needs) |
- |
hg qpush |
(see hg qimport) |
- |
hg qpop |
(see hg qimport) |
- |
hg qimport -r tip |
? |
- |
hg qnew -f some.patch |
? |
- |
hg resolve -a -m |
git add -u |
- |
hg glog |
git log --graph --all --decorate # or: git log --graph --all; |
- |
hg verify |
git fsck |
- |
hg branches |
git branch -a |
- |
hg rollback |
git reset HEAD~ |
} |
Setup
~/.hgrc:
~/.gitconfig:
More Information
One can find some info here:
and at many other pages.
Tips
use gitk to visualize history (much more capable than 'hg vi')
use git gui to visually stage/unstage what you are preparing for committo index (it too can work on hunk-by-hunk basis)
git stash is your friend
git rebase --interactive is your friend too :)
windows users: either use cygwin or msysgit:http://code.google.com/p/msysgit/
don't try to project your usual habits - open your mind, and maybe you'lldiscover much more superior workflow. (yes, this needs hard work and RTFM,and being ready that FM sometimes differ from what software actually does)
Add this
parse_git_branch() {git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/(1)/'
}PS1='w$(parse_git_branch) $ '
to your promptstring to show current branch when in a git-tracked directory.(see http://b.lesseverything.com/2008/3/25/got-git-howto-git-and-github)
git -> hg conversion
You can use this script:
to convert all patches between master..HEAD to mercurial repository sitting at ~/repos/sympy.hg/.
how to checkout remote branch
Start with some repository, for example create a new one from scratch:
or clone our official repository:
Now let's say you want to checkout some branch from git://github.com/certik/sympy.git. The canonical way is to add it to your remotes:
Then fetch all branches from there into your remote branches:
You can now list them with 'git branch -r', or examine them with 'git log ondrej/some_branch'. Finally, to checkout the mpmath5 branch, do:
This article shows how to solve math equations and expressions symbolically, in Python. Thanks to the Sympy library, this turns out to be an extremely easy task.
However, as you will see in the following examples, the number of tools and functions provided by this library is huge. Thanks to all its features, Sympy represents a really powerful algebra system with which we can solve in a very immediate way, mathematical expressions, equations, inequalities and even systems of equations/inequalities.
For these reasons, Sympy represents a fundamental tool for solving a plethora of math related problems. The article is divided into different sections, each of which deals with a specific Sympy function. If you are interested in the topic, you can find the documentation about all the herein described functions (and lots of others) at https://www.sympy.org/en/index.html.
Importing Sympy
The first step involves importing into our script the Simpy library; since multiple different packages will be used throughout this example, we import them all by writing the following code line (to import Sympy you must have previously installed it, if you have not done it yet, type “pip install sympy
” in your terminal).
Defining variables and functions
We start by defining the variables that we want to use in our calculations. To do this, we exploit the Sympy function symbols()
which takes as input a string and turns it into a Sympy variable; we then assign the value of the function to a variable with the same name of the chosen string. In the following code lines, we initialize two variables “x
” and “y
”.
A similar procedure can be employed to define the name of the functions that will be used in the script; this time, the Sympy function that serves to the purpose is Function()
and works in the same way as symbols()
. We hence initialize a function called “f
”, from this moment, every time we type “f
” on the script, we are referring to a function.
Using Sympy in your computer terminal
Sympy can be even used directly from your terminal; it is here that its capability of symbolically solve mathematical equations and functions expresses its best. We will now see how to initialize and directly use Sympy in the terminal. The first thing to do, is to open your terminal and import Sympy in a similar way as did before. We hence type “import sympy” and press enter. After this, we enter the following command “sympy.init_session()
”, the following lines contain the two just described commands and the output that is prompted by your terminal.
As you can see, after the sympy.init_session()
command, multiple Sympy packages were imported; moreover, the letters “x”, “y”, “z” and “t” were initialized as Sympy variables, “k”, “m” and “n” as integer parameters, while the letters “f”, “g” and “h” as functions.
All these tasks were executed automatically within the sympy.init_session()
command, which basically initiated a Sympy session with some pre-defined functions and variables.
The advantage of using the terminal over the text editor is that it will prompt all the functions and equations using an improved graphical style, making them (as we will see) more immediate. Most of the commands that will follow in the next sections, can be typed both in the script and in the terminal, I will specify when some specific functions will not work on one of the two platforms.
Expanding and simplifying mathematical expressions
Sympy Cheat Sheet Pdf
In this section we will learn how to use Sympy to expand or simplify a mathematical expression. Both the tasks can be done automatically and instantaneously by just exploiting the functions expand()
and factor()
.
To see how the expand()
function works, we first define a function f = (3x + 5y2 – 6)2 and then we pass it as the only input parameter of the function expand()
. The following lines are typed within the terminal in order to obtain a better graphical output; however, they work in the very same way when typed within the script.
As you can see from the reported results, the function expand()
has calculated the expression defined within the function f and printed it in an improved graphical way, avoiding the asterisks and placing the exponents as apices. The presenting style may vary among different terminals, but it generally improves with respect to the input one.
On the other hand, the function factor()
works in the exact opposite way, it simplify the expression that is passed within its brackets. You can see an example in the following lines.
Solving equations and inequalities
Sympy Cheat Sheet
Another useful feature offered by Sympy is the possibility to find the solution to algebraic equations by exploiting the function .solve()
.
Sympy Cheat Sheet Free
This function takes as input two different parameters, the equation that we want to solve and the variable for which we want to solve it, respectively.
This is particularly useful in the case of symbolic solutions of equations with multiple variables in which we might be interested in obtaining the symbolic solution with respect to one of the two unknowns. The following lines report either the numerical solution of a one-variable equation and the symbolic solution of a two-variables equation with respect to the variable “y
”.
In a similar way we can also obtain the numerical and/or symbolical solution of higher order equation or inequalities. Both the tasks are displayed in the following lines.
Solving systems of equations/inequalities
Sympy can be used to solve systems of equations/inequalities as well. For doing this, we will exploit, again, the function solve()
. In the case of a system of equations, we enter the equations as elements of a list; the following lines describes the solution of a system of three linear equations by using solve()
.
Sympy Cheat Sheet 2020
As can be seen, the output of the solve()
function are the values of the three different system variables. In the same way, we can also obtain the solution of systems of inequalities; it is sufficient to enter the inequalities as elements of a list; this time the “>” “<” symbols have to be specified for both the inequalities.
Sympy Cheat Sheet
As usual, the solution is printed right under our command, exploiting Boolean symbols for the operator “and”, “or”.
Sympy Cheat Sheet 2019
Conclusion
This article presented some of the basic functions provided by the Sympy library. In particular, we saw how to exploit Sympy to define variables and functions; how to symbolically expand and simplify mathematical expressions and how to use this library for solving equations, inequalities and even systems of equations/inequalities. The functions shown in the article can be typed both in the text of the script but also directly in the terminal (or Jupyter notebooks) in order to obtain an immediate evaluation and a better graphical representation of the performed calculations.