SymPy Tutorial
Aaron Meurer, Ondrej Certık, Amit Kumar, Jason Moore,Sartaj Singh, Harsh Gupta
July 11, 2016
All materials for today’s tutorial are athttp://www.sympy.org/scipy-2016-tutorial/1 / 21
Outline
SymPy Introduction
� Goal
� Features
� History
� Present
� Future
Tutorial
� Intro to SymPy and Basic features
� Solving real life problems
2 / 21
SymPy Goal
GoalProvide a symbolic manipulation library in Python.
“SymPy is an open source Python library for symbolic mathematics.It aims to become a full-featured computer algebra system (CAS)while keeping the code as simple as possible in order to becomprehensible and easily extensible. SymPy is written entirely inPython and does not require any external libraries.”
3 / 21
SymPy Goal
GoalProvide a symbolic manipulation library in Python.
“SymPy is an open source Python library for symbolic mathematics.It aims to become a full-featured computer algebra system (CAS)while keeping the code as simple as possible in order to becomprehensible and easily extensible. SymPy is written entirely inPython and does not require any external libraries.”
3 / 21
Why SymPy?
� Standalone
� Full featured
� BSD licensed
� Embraces Python
� Usable as a library
4 / 21
Features
� Core Capabilities� Basic arithmetic: Support for operators such as
+, -, *, /, ** (power)� Simplification� Expansion� Functions: trigonometric, hyperbolic,
exponential, roots, logarithms, absolute value,spherical harmonics, factorials and gammafunctions, zeta functions, polynomials, specialfunctions, . . .
� Substitution� Numbers: arbitrary precision integers, rationals,
and floats� Noncommutative symbols� Pattern matching
� Polynomials� Basic arithmetic: division, gcd, . . .� Factorization� Square-free decomposition� Grobner bases� Partial fraction decomposition� Resultants
� Calculus
� Limits: limx→0 x log(x) = 0� Differentiation� Integration: It uses extended Risch-Norman
heuristic� Taylor (Laurent) series
� Solving equations
� Polynomial equations� Algebraic equations� Differential equations� Difference equations� Systems of equations
� Combinatorics
� Permutations� Combinations� Partitions� Subsets� Permutation Groups: Polyhedral, Rubik,
Symmetric, . . .� Prufer and Gray Codes
5 / 21
Features
� Discrete math
� Binomial coefficients� Summations� Products� Number theory: generating prime numbers,
primality testing, integer factorization, . . .� Logic expressions
� Matrices
� Basic arithmetic� Eigenvalues/eigenvectors� Determinants� Inversion� Solving� Abstract expressions
� Geometric Algebra
� Geometry
� points, lines, rays, segments, ellipses, circles,polygons, . . .
� Intersection� Tangency� Similarity
� Plotting
� Coordinate modes� Plotting Geometric Entities� 2D and 3D� Interactive interface� Colors
� Physics
� Units� Mechanics� Quantum� Gaussian Optics� Pauli Algebra
� Statistics
� Normal distributions� Uniform distributions� Probability
� Printing
� Pretty printing: ASCII/Unicode pretty printing,LaTeX
� Code generation: C, Fortran, Python
6 / 21
History
History
� Ondrej Certık started the project in 2006.
� Development took off in 2007 when SymPy first participated inGoogle Summer of Code. We have participated in every GoogleSummer of Code since.
� In 2011, Aaron Meurer (who also joined from Google Summer ofCode) took over as lead developer.
7 / 21
Present
Current Status
� Over 450 contributors.
� Current code base has over 400,000 lines of code anddocumentation.
� We have crossed the point of “sympy a toy” to “sympy a tool”
8 / 21
Future
GSoC (1/2)
These are our current GSoC projects. Expect to see these features bythe end of the summer.� Group Theory, Gaurav Dhingra
� Extending solveset, Kshitij Saraogi
� Completing Solveset, Shekhar Prasad Rajak
� Implementation of Holonomic Functions, Shubham Tibra
� Implementation of Singularity Functions to solve Beam Bendingproblems, Sampad Kumar Saha
9 / 21
Future
GSoC (2/2)
These are our current GSoC projects. Expect to see these features bythe end of the summer.� Adding to SymEngine’s Polynomial functionality and interfacing it
with FLINT & Piranha Srajan Garg
� Implementing Finite Fields and Set module in SymEngine NishantNikhil
10 / 21
Future
Other Plans
� New assumptions
� Make things faster
� SymEngine (https://github.com/symengine)
� Implement more algorithms, so we can compute more things (andalso make them faster)
� Replacing solve with solveset
� Encourage people to use SymPy for many applications
� https://github.com/sympy/sympy/wiki/gsoc-2016-ideas
for full list of things we want done
11 / 21
Projects Using SymPy
� Sage: A CAS, visioned to be a viable free open source alternativeto Magma, Maple, Mathematica and MATLAB. Sage includesmany open source mathematical libraries, including SymPy.
� SageMathCloud: SageMathCloud is a web-based cloudcomputing and course management platform for computationalmathematics.
� Mathpix: An iOS App, that detects handwritten math as input,and uses SymPy Gamma to evaluate the math input and generatethe relevant steps to solve the problem.
� PyDy: Multibody Dynamics with Python.
� IKFast: IKFast is a robot kinematics compiler provided byOpenRAVE. It analytically solves robot inverse kinematicsequations and generates optimized C++ files. It uses SymPy forits internal symbolic mathematics.
12 / 21
Projects Using SymPy
� Octave Symbolic: The Octave-Forge Symbolic package addssymbolic calculation features to GNU Octave. These includecommon CAS tools such as algebraic operations, calculus, equationsolving, Fourier and Laplace transforms, variable precisionarithmetic, and other features.
� galgebra: Geometric algebra (previously sympy.galgebra).
� SymPy.jl: Provides a Julia interface to SymPy using PyCall.
� Mathics: Mathics is a free, general-purpose online CAS featuringMathematica compatible syntax and functions. It is backed byhighly extensible Python code, relying on SymPy for mostmathematical tasks.
� SfePy: Simple finite elements in Python.
13 / 21
Projects Using SymPy
� Quameon: Quantum Monte Carlo in Python.
� Lcapy: Experimental Python package for teaching linear circuitanalysis.
� Quantum Programming in Python: Quantum 1D SimpleHarmonic Oscillator and Quantum Mapping Gate.
� LaTeX Expression project: Easy LATEX typesetting of algebraicexpressions in symbolic form with automatic substitution and resultcomputation.
� Symbolic statistical modeling: Adding statistical operations tocomplex physical models.
14 / 21
Authors
Ondrej CertıkFabian PedregosaJurjen N.E. BosMateusz PaprockiMarc-EtienneM.LeveilleBrian JorgensenJason GedgeRobert SchwarzPearu PetersonFredrik JohanssonChris WuUlrich HechtGouthamLakshminarayanDavid LawrenceJaroslaw TworekDavid MarekBernhard R. LinkAndrej TokarcıkOr DvorySaroj AdhikariPauli VirtanenRobert Kern
James AspnesNimish TelangAbderrahim KitouniPan PengFriedrich HagedornElrond derElbenfuerstRizgar MellaFelix KaiserRoberto NobregaDavid RobertsSebastian KramerVinzent SteinbergRiccardo GoriCase Van HorsenStepan RouckaAli Raza SyedStefano MaggioloRobert CimrmanBastian WeberSebastian KrauseSebastian KreftDanAlan Bromborsky
Boris TimokhinRobertAndy R. TerrelHubert TsangKonrad MeyerHenrik JohanssonPriit LaesFreddie WitherdenBrian E. GrangerAndrew StrawKaifeng ZhuTed HorstAndrew DochertyAkshay SrinivasanAaron MeurerBarry WardellTomasz BuchertVinay KumarJohannCohen-TanugiJochen VossLuke PetersonChris SmithThomas Sidoti
Florian MicklerNicolas PourcelotBen GoodrichToon VerstraelenRonan LamyJames AbbatielloRyan KraussBill FlynnKevin GoodsellJorn BaayenEh TanRenato CoutinhoOscar BenjaminØyvind JensenJulio Idichekop Filho Lukasz PankowskiChu-Ching HuangFernando PerezRaffaele De FeoChristian MuiseMatt CurryKazuo ThowChristian SchubertJezreel Ng
James PearsonMatthew BrettAddison CuginiNicholas J.S. KinarHarold ErbinThomas DixonCristovao SousaAndre de FortierSmitMark DewingAlexey U.GudchenkoGary KerrSherjil OzairOleksandr GituliarSean VigPrafullkumar P. TaleVladimir PericTom BachmannYuri Karadzhov
15 / 21
Authors (continued)
Vladimir LagunovMatthew RocklinSaptarshi MandalGilbert GedeAnatolii KovalTomo LazovichPavel FedotovJack McCafferyJeremias YehdeghoKibeom KimGregory KsiondaTomas BambasRaymond WongLuca WeihsShai ’Deshe’WyborskiThomas WieckiOscar NajeraMario PerniciBenjamin McDonaldSam MaguraStefan KrastanovBradley Froehle
Min Ragan-KelleyEmma HoganNikhil SardaJulien RiouxRoberto Colistete,Jr.Raoul BourquinGert-Ludwig IngoldSrinivas VasudevanJason MooreMiha MaroltTim LaheyLuis GarciaMatt RajcaDavid LiAlexandr GudulinBilal AkhtarGrzegorz SwirskiMatt HabelDavid JuNichita UtiuNikolay LazarovSteve Anton
Imran AhmedManzoorLjubisa MocicPiotr KorgulJim ZhangSam Sleighttsmars15Chancellor ArkantosStepan SimsaTobias LenzSiddhanathanShanmugamTiffany ZhuTristan HumeAlexey SubachJoan CreusGeoffry SongPuneeth ChagantiMarcin KostrzewaNatalia NawaravishalShruti MangipudiDavy Mao
Swapnil AgarwalKendhiajerryma1121Joachim DurchholzMartin PoviserSiddhant JainKevin HunterMichael MayorovNathan AlisonChristian BuhlerCarsten KnollBharath M RMatthias ToewsSergiu IvanovJorge E. CardonaSanket AgarwalManoj Babu K.Sai NikhilAleksandar MakelovSachin IrukulaRaphael MichelAshwini OrugantiAndreas Kloeckner
Prateek PapriwalArpit GoyalAngadh NanjangudComer DuncanJens H. NielsenJoseph Doughertymarshall2389Guru DevanlaGeorge WaksmanAlexandr PopovTarun GabaTakafumi ArakakiSaurabh JhaRom le ClairAngus GriffithTimothy RelugaBrian StephanikAlexanderEberspacherSachin JoglekarTyler PirtleVasily PovalyaevColleen Lee
16 / 21
Authors (continued)
Matthew HoffNiklas ThorneHuijun MaiMarek SuppaRamana VenkataPrasoon ShuklaStefen YinThomas HischMadeleine BallCase Van HorsenMary ClarkRishabh DixitManoj KumarAkshit AgarwalCJ CareyPatrick LacasseAnanya HTarang PatelChristopher DembiaBenjamin FishbeinSean GeAmit JamadagniAnkit Agrawal
Bjorn DahlgrenChristopheSaint-JeanDemian WassermannKhagesh PatelStephen LoohmPatrick PoitrasKatja Sophie HotzVarun JoshiChetna GuptaThilina RathnayakeMax HutchinsonShravas K RaoMatthew TaddAlexander HirzelRandy HeydonOliver LeeSeshagiri PrabhuPradyumnaErik WelchEric NelsonRoland Puntaier
Chris ConleyTim SwastDmitry BatkovichFrancesco BonazziYuriy DemidovRick MullerManish GillMarkus MullerAmit SahaJeremyQuaBooStefan van der WaltDavid JoynerLars BuitinckAlkiviadis G. AkritasVinit RavishankarMike BoyleHeiner KirchhofferPablo PuenteJames FiedlerHarsh GuptaTuomas AiraksinenPaul Strickland
James GoppertrathmannAvichal DayalPaul ScottShipra BangaPramod ChAkshayBuck ShlegerisJonathan MillerEdward SchemborRajath ShashidharaZamrath NizamAditya ShahRajat AggarwalSambuddha BasuZeel ShahAbhinav ChandaJim CristSudhanshu MishraAnurag SharmaSoumya DiptaBiswasSushant Hiray
Ben LucatoKunal AroraHenry GebhardtDamminaSahabanduShuklaRalph BeanrichierichrawrJohn ConnorJuan Luis CanoRodrıguezSahil ShekhawatKundan KumarStas KelvichsevaaderDhruvesh VijayParikhVenkatesh HalliLennart FrickeVlad SegheteShashank AgarwalcarstimonPierre Haessig
17 / 21
Authors (continued)
Maciej BaranskiBenjamin GudehusFaisal AneesMark ShoulsonRobert JohanssonKalevi SuominenKaushik VaranasiFawaz AlazemiAmbar MehrotraDavid P. SandersPeter BradyJohn V. SirattSarwar ChahalNathan WoodsColin B. MacdonaldMarcus NaslundClemens NovakMridul SethCraig A. StoudtRajMihai A. IonescuimmerrrChai Wah Wu
Leonid BlouvshteinPeleg Michaelick Luxzsc347Hamish DicksonMichael GallaspyRoman InflianskasDuane NykampTed DokosSunny AggarwalVictor BrebenarAkshat JainShivam VatsLongqi WangJuan Felipe OsorioGitRayLukas ZorichEric MillerVenkata RamanaCody HerbstNishith ShahAMiT KumarYury G. Kudryashov
Guillaume GayRay CathcartMihir WadwekarTuan Manh LaiAsish PandaDarshan ChaudharyAlec KalininRalf StephanAaditya NairJayesh LahoriHarshil GoelLuv AgarwalJason LyLokesh SharmaSartaj SinghChris SwierczewskiKonstantin TogoiParam SinghSumithJuha RemesPhilippe BouafiaPeter SchmidtJiaxing Liang
Lucas JonesGregory AshtonJennifer WhiteRenato OrsinoMichael BoyleAlistair LynnGovind SahaiAdam BloomstonKyle McDanielNguyen Truong DuyAlex LindsayMathew ChongJason SiefkenGaurav DhingraGao, XiangKevin Ventullomao8Isuru FernandoShivam TyagiRichard OtisRich LaSotadustyrockpyleAnton Akhmerov
Michael ZingaleChak-Pong ChungDavid TPhil RuffwindSebastian KoslowskiKumar KrishnaAgrawalDustin GadaloperteYu KobayashiShashank KumarTimothy CyrusDevyani KotaKeval ShahDzhelil RufatPastafarianistSourav SinghJacob GarberVinay
18 / 21
Authors (continued)
GolimarOurHeroPrashant TyagiMatthew DavisTschijnmo TSCHAUAlexander BentkampMoo VIJack KempKshitij SaraogiThomas BaruchelNicolasGuarın-ZapataJens JørgenMortensenSampad Kumar SahaEva Charlotte MayerLaura DomineJustin BlytheMeghana
MadhyasthaTanu Hari DixitShekhar PrasadRajakAqnouchMohammedArafat Dad KhanBoris AtamanovskiySam TygierJai LuthraGuo XingjianSandeep VeethuArchit VermaShubham TibraAshutosh SabooMichael S. HansenAnish ShahHarshil Goel
Guillaume JacquenotBhautik MavaniMicha l RadwanskiJerry LiPablo ZubietaCurious72Chaitanya SaiAlaparthiarihant parsoyaRuslan PisarevAkash TrehanNishant NikhilVladimir PoluhsinAkshay NagarJames BrandonMilamAbhinav AgarwalRishabh Daal
Sanya KhuranaAman DeepAravind ReddyAbhishek VermaMatthew ParnellThomas HickmanAkshay SiramdasYiDing JiangJatin YadavMatthew ThomasRehas SachdevaMichael MuellerSrajan GargPrabhjot SinghHaruki MoriguchiTom GijselinckNitin ChaudharyAlex Argunov
Nathan MusokeAbhishek GargDana JacobsenVasiliy DommesPhillip BerndtHaimo ZhangSubham TibraAnthony ScopatzbluebrookNormal HumanJosh BurkartDimitra KonomiChristinaZografouFiachAntawLangston BarrettKrit KaranG. D. McBainPrempal Singh
19 / 21
Here at SciPy
Talks
� Jason Moore, Simulating Robot, Vehicle, Spacecraft, and AnimalMotion with Python (Advanced) (Tutorial).Monday 1:30 PM - 5:30 PM - Room 103
� Aaron Meurer, Anthony Scopatz SymPy Code Generation.Thursday 11:30 PM - 12:00 PM - Room 204
� Ondrej Certık, Isuru Fernando, Thilina Rathnayake, AbhinavAgarwal SymEngine: A Fast Symbolic Manipulation Library.Friday 3:30 - 4:00 - Room 204
20 / 21
Let’s begin!
21 / 21
Top Related