sympy tutorial - sidhant nagpalsympy goal goal provide a symbolic manipulation library in python....

22
SymPy Tutorial Sidhant Nagpal July 11, 2018 Workshop Content for tutorial is at https://git.io/sympy-tutorial 1 / 21

Upload: others

Post on 27-Jan-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

SymPy Tutorial

Sidhant Nagpal

July 11, 2018

Workshop Content for tutorial is athttps://git.io/sympy-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 600 contributors.

� Over 5000 stars.

� Current code base has over 500,000 lines of code anddocumentation.

� We have crossed the point of “sympy a toy” to “sympy a tool”

8 / 21

Git Commits Plots

All Time

0 50 100 150 200 250 300individual people

100

101

102

103

104

tota

l num

ber

of

patc

hes

sympy all

ipython all

numpy all

matplotlib all

sklearn all

pandas all

scipy all

9 / 21

Git Commit Plots

All Time

� SymPy has more total contributors1

� SymPy has a very welcome and friendly community, which is open,and actively encourages contributions.

� The SymPy code base is very approachable to new contributors.

� To be fair, Google Code-In accounts for a lot of this. . .

1some of the other projects are actually exaggerated, because they don’t use.mailmap

10 / 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.

11 / 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.

12 / 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.

13 / 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

14 / 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 SleighttborisovaChancellor ArkantosStepan SimsaTobias LenzSiddhanathanShanmugamTiffany ZhuTristan HumeAlexey SubachJoan CreusGeoffry SongPuneeth ChagantiMarcin KostrzewaNatalia NawaravishalShruti MangipudiDavy Mao

Swapnil AgarwalDhia Kennouchejerryma1121Joachim 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 DoughertyElliot MarshallGuru DevanlaGeorge WaksmanAlexandr PopovTarun GabaTakafumi ArakakiSaurabh JhaRom le ClairAngus GriffithTimothy RelugaBrian StephanikAlexanderEberspacherSachin JoglekarTyler PirtleVasily PovalyaevColleen Lee

15 / 21

Authors (continued)

Matthew HoffNiklas ThorneHuijun MaiMarek SuppaRamana VenkataPrasoon ShuklaStefen YinThomas HischMadeleine BallMary ClarkRishabh DixitManoj KumarAkshit AgarwalCJ CareyPatrick LacasseAnanya HTarang PatelChristopher DembiaBenjamin FishbeinSean GeAmit JamadagniAnkit AgrawalBjorn Dahlgren

ChristopheSaint-JeanDemian WassermannKhagesh PatelStephen LoohmPatrick PoitrasKatja Sophie HotzVarun JoshiChetna GuptaThilina RathnayakeMax HutchinsonShravas K RaoMatthew TaddAlexander HirzelRandy HeydonOliver LeeSeshagiri PrabhuPradyumnaErik WelchEric NelsonRoland PuntaierChris Conley

Tim SwastDmitry BatkovichFrancesco BonazziYuriy DemidovRick MullerManish GillMarkus MullerAmit SahaJeremyQuaBooStefan van der WaltDavid JoynerLars BuitinckAlkiviadis G. AkritasVinit RavishankarMike BoyleHeiner KirchhofferPablo PuenteJames FiedlerHarsh GuptaTuomas AiraksinenPaul StricklandJames Goppert

rathmannAvichal DayalPaul ScottShipra BangaPramod ChAkshayBuck ShlegerisJonathan MillerEdward SchemborRajath ShashidharaZamrath NizamAditya ShahRajat AggarwalSambuddha BasuZeel ShahAbhinav ChandaJim CristSudhanshu MishraAnurag SharmaSoumya DiptaBiswasSushant HirayBen Lucato

Kunal AroraHenry GebhardtDamminaSahabanduManish ShuklaRalph BeanrichierichrawrJohn ConnorJuan Luis CanoRodrıguezSahil ShekhawatKundan KumarStas KelvichsevaaderDhruvesh VijayParikhVenkatesh HalliLennart FrickeVlad SegheteShashank AgarwalcarstimonPierre HaessigMaciej Baranski

16 / 21

Authors (continued)

Benjamin 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 WuLeonid Blouvshtein

Peleg Michaelick Luxzsc347Hamish DicksonMichael GallaspyRoman InflianskasDuane NykampTed DokosSunny AggarwalVictor BrebenarAkshat JainShivam VatsLongqi WangJuan Felipe OsorioRay CathcartLukas ZorichEric MillerCody HerbstNishith ShahAmit KumarYury G. KudryashovGuillaume GayMihir Wadwekar

Tuan Manh LaiAsish PandaDarshan ChaudharyAlec KalininRalf StephanAaditya NairJayesh LahoriHarshil GoelLuv AgarwalJason LyLokesh SharmaSartaj SinghChris SwierczewskiKonstantin TogoiParam SinghSumith KulalJuha RemesPhilippe BouafiaPeter SchmidtJiaxing LiangLucas JonesGregory AshtonJennifer White

Renato OrsinoMichael BoyleAlistair LynnGovind SahaiAdam BloomstonKyle McDanielNguyen Truong DuyAlex LindsayMathew ChongJason SiefkenGaurav DhingraGao, XiangKevin Ventullomao8Isuru FernandoShivam TyagiRichard OtisRich LaSotadustyrockpyleAnton AkhmerovMichael ZingaleChak-Pong ChungDavid T

Phil RuffwindSebastian KoslowskiKumar KrishnaAgrawalDustin GadalJoao MouraYu KobayashiShashank KumarTimothy CyrusDevyani KotaKeval ShahDzhelil RufatPastafarianistSourav SinghJacob GarberVinay SinghGolimarOurHeroPrashant TyagiMatthew Davis

17 / 21

Authors (continued)

Tschijnmo TSCHAUAlexander BentkampJack KempKshitij SaraogiThomas BaruchelNicolasGuarın-ZapataJens JørgenMortensenSampad Kumar SahaEva Charlotte MayerLaura DomineJustin BlytheMeghanaMadhyasthaTanu Hari DixitShekhar PrasadRajakAqnouchMohammedArafat Dad KhanBoris AtamanovskiySam TygierJai LuthraGuo Xingjian

Sandeep VeethuArchit VermaShubham TibraAshutosh SabooMichael S. HansenAnish ShahGuillaume JacquenotBhautik MavaniMicha l RadwanskiJerry LiPablo ZubietaShivam AgarwalChaitanya SaiAlaparthiArihant ParsoyaRuslan PisarevAkash TrehanNishant NikhilVladimir PoluhsinAkshay NagarJames BrandonMilamAbhinav AgarwalRishabh DaalSanya Khurana

Aman DeepAravind ReddyAbhishek VermaMatthew ParnellThomas HickmanAkshay SiramdasYiDing JiangJatin YadavMatthew ThomasRehas SachdevaMichael MuellerSrajan GargPrabhjot SinghHaruki MoriguchiTom GijselinckNitin ChaudharyAlex ArgunovNathan MusokeAbhishek GargDana JacobsenVasiliy DommesPhillip BerndtHaimo ZhangAnthony Scopatzbluebrook

Leonid KovalevJosh BurkartDimitra KonomiChristina ZografouFiach AntawLangston BarrettKrit KaranG. D. McBainPrempal SinghGabriel OrisakaMatthias BussonnierrahuldanColin MarquardtAndrew TaberYash ReddyPeter Stanglelvis-sikNikos KaragiannakisJainul VaghasiaDennis MeckelHarshil MeenaMickyNick CurtisMichele ZaffalonMartha

GiannoudovardiDevangKulshreshthaSteph PapanikMohammad SadeqDoustiArif AhmedAbdullah JavedNesarLakshya AgrawalshrutiRohit RangoHong XuIvan PetuhovAlshehMarcel StimbergAlexey PakhocmhikTommy OlofssonZulfikarBlair AzzopardiDanny Hermes

18 / 21

Authors (continued)

Sergey PestovMohit ChandraKarthik ChintapalliMarcin BrianskiandreoFlamy OwlYicong GuoVarun GargRishabh MadanAditya KapoorKaran SharmaVedant RathoreJohan BlabackPranjal TaleJason TokayerRaghav JajodiaRajat ThakurDhruv BhanushaliAnjul Kumar TyagiBarun ParruckBao ChauTanay AgrawalRanjith Kumar

Shikhar MakhijaYathartha JoshiValeriia GladkovaSagar BharadwajDaniel MahlerKa YiRishat IskhakovSzymon MieszczakSachin AgarwalPriyank PatelSatya PrakashDwibeditools4originsNico SchlomerFermi ParadoxEkansh PurohitVedarth SharmaPeeyush KushwahaJayjayyyChristopher J.WrightJakub WilkMauro Garavello

Chris TeferShikhar JaiswalChiu-Hsiang HsuCarlos CordobaFabian BallYerniyazChristiano AndersonRobin NeatherwayThomas HuntTheodore HanDuc-Minh PhanLejla MetohajrovaSamyak JainAditya RohanVincent DelecroixMichael SparapanyHarsh JainNathan GoldbaumlatotKenneth LyonsStan SchymanskiDavid DalyAyush Shridhar

Javed NissarJiri Kuncarvedantc98Rupesh HarodeRob ZinkovJames HarropJames TaylorIshan JoshiMarco ManciniBoris EttingerMicah FitchDaniel WennbergylemkimonAkash VaishPeter EnenkelWaldir PimentaJithin D. GeorgeLev ChelyadinovLucas WimanRhea ParekhJames CottonRobert Pollakanca-mc

Sourav GhoshJonathan AllanNikhil PappuEthan WardCezary Marczakdps7udNilabja BhattacharyaItay4Poom ChiarawongseYang YangCavendish McKayBradley GannonB McGRob DrynkinSeth EbnerAkash KunduMark JerominRoberto Dıaz PerezGleb SirokiSegev Finer

19 / 21

Authors (continued)

Alex LubbockAyodeji IgeMatthew WardropHugoAustin Palmerder-blaue-elefantFilip GokstorpYuki MatsudaAaron MillerSalil Vishnu KapurAtharva KhareShubhamMaheshwariPavel TkachenkoAshish KumarGauravRajeev Singh

Keno GoertzLucas GallindoHimanshuDavid MenendezHurtadoAmit ManchandaRohit JainJonathan A. GrossUnknownSayan GoswamiSubhash SaurabhRastislav RabatinVishalJeremey GluckAkshat MaheshwarisymboliqueSaloni Jain

Arighna ChakrabartyAbhigyan KhaundJashanpreet SinghSaurabh Agarwalluz.pazP. Sai PrasanthNirmal SarswatCristian DiPietrantonioRavi charanNityananda GohainCedric TravellettiNicholas BollwegHimanshu LadiaewardAdwait BaokarMihail Tarigradschi

SakethrushyamsfooRahil HastuZach RainesSidhant Nagpalczgdp1807Rishav ChakrabortyMalkhan SinghJoaquim MonserratMayank SinghRemy LeoneMaxence MayrandNikoleta Glynatsihelo9Ken WakitaCarl Sandrock

Fredrik ErikssonIan SwireBulatEhren MetcalfeDmitry SavranskyKiyohito YamazakiCaley Finnzhouzq-thuAlexander PozdneevWes TurnerJMSS-UnknownArshdeep SinghStewart WadsworthJared Lumpecym1

20 / 21

Let’s begin!

21 / 21