Sick Gaming
[Tut] Python SymPy — A Short Primer - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Programming (https://www.sickgaming.net/forum-76.html)
+--- Forum: Python (https://www.sickgaming.net/forum-83.html)
+--- Thread: [Tut] Python SymPy — A Short Primer (/thread-96040.html)



[Tut] Python SymPy — A Short Primer - xSicKxBot - 07-05-2020

Python SymPy — A Short Primer

<div><figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio">
<div class="wp-block-embed__wrapper">
<div class="ast-oembed-container"><iframe title="Python SymPy | A Short Primer" width="1400" height="788" src="https://www.youtube.com/embed/4ohb0zsbYWk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>
</div>
</figure>
<h2>What’s SymPy Anyway?</h2>
<p>SymPy is a Python library for symbolic computation. So instead of approximating the result of the square root of 2, it keeps the square root intact—using a symbolic representation. This helps in further processing and can lead to situations where Python has introduced a <a href="https://blog.finxter.com/decimal-pythons-float-trap-and-how-to-solve-it/">floating point precision error</a> without need. Here’s a basic example:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import sympy print(sqrt(3))
# sqrt(3)</pre>
<p>The result is NOT an approximated square root of 3 like in the math package:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import math print(math.sqrt(3))
# 1.7320508075688772</pre>
<h2>An Interactive Example</h2>
<p>You can try it yourself in the interactive code shell:</p>
<figure class="wp-block-image size-large"><a href="https://live.sympy.org/" target="_blank" rel="noopener noreferrer"><img src="https://blog.finxter.com/wp-content/uploads/2020/07/image-1.png" alt="" class="wp-image-10462" srcset="https://blog.finxter.com/wp-content/uploads/2020/07/image-1.png 982w, https://blog.finxter.com/wp-content/uploads/2020/07/image-1-300x182.png 300w, https://blog.finxter.com/wp-content/uploads/2020/07/image-1-768x467.png 768w" sizes="(max-width: 982px) 100vw, 982px" /></a></figure>
<p><em>(Just click the image to create your own code!)</em></p>
<h2>How to Install SymPy?</h2>
<p>To install <a href="https://www.sympy.org/en/index.html">SymPy </a>in Python, simply run the following command in your shell:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pip install sympy</pre>
<figure class="wp-block-image"><img src="https://blog.finxter.com/wp-content/uploads/2019/10/grafik-13.png" alt="" class="wp-image-4730" srcset="https://blog.finxter.com/wp-content/uploads/2019/10/grafik-13.png 969w, https://blog.finxter.com/wp-content/uploads/2019/10/grafik-13-300x68.png 300w, https://blog.finxter.com/wp-content/uploads/2019/10/grafik-13-768x175.png 768w" sizes="(max-width: 969px) 100vw, 969px" /><figcaption></figcaption></figure>
<p>This works for all major operating systems (MacOS, Windows, Linux). A preliminary is to have the pip package manager installed. </p>
<p><a href="https://blog.finxter.com/the-complete-python-library-guide/">(Confused by all the libraries, modules, pip, and virtual environments? Read the ultimate library guide on my blog.)</a></p>
<p>To check whether it has installed correctly, simply run the following command in your Python shell:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">>>> help(sympy)
Help on package sympy: NAME sympy DESCRIPTION SymPy is a 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 be comprehensible and easily extensible. SymPy is written entirely in Python. It depends on mpmath, and other external libraries may be optionally for things like plotting support. See the webpage for more information and documentation: https://sympy.org PACKAGE CONTENTS abc algebras (package) assumptions (package)</pre>
<p>The output validates that the <a href="https://docs.sympy.org/latest/tutorial/intro.html" target="_blank" rel="noreferrer noopener" title="https://docs.sympy.org/latest/tutorial/intro.html">sympy package</a> has installed correctly.</p>
<h2>Where to Go From Here?</h2>
<p>Enough theory, let’s get some practice!</p>
<p>To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?</p>
<p><strong>Practice projects is how you sharpen your saw in coding!</strong></p>
<p>Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?</p>
<p>Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.</p>
<p>Join my free webinar <a rel="noreferrer noopener" href="https://blog.finxter.com/webinar-freelancer/" target="_blank">“How to Build Your High-Income Skill Python”</a> and watch how I grew my coding business online and how you can, too—from the comfort of your own home.</p>
<p><a href="https://blog.finxter.com/webinar-freelancer/" target="_blank" rel="noreferrer noopener">Join the free webinar now!</a></p>
</div>


https://www.sickgaming.net/blog/2020/07/04/python-sympy-a-short-primer/