{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SciPy / Havana\n", "\n", "In case I get to go to [SciPy / Havana](http://conf.scipyla.org/), I'm boning up on SymPy, an important component within the SciPy Ecosystem.\n", "\n", "Here's the kind of thing one might do with SymPy, a computer algebra system:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import sympy as sym" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "x = sym.symbols('x')\n", "sym.init_printing()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHAAAAApCAYAAADtYa10AAAABHNCSVQICAgIfAhkiAAABbNJREFU\neJztm2tsFUUUgL8W2rSiQY0UHymsUKv8oRWUqClNSAQi8YWGEImoQTSmiiT+kIAajS98gESNGnyl\naoxgWiUgappofaAphWp8URMURcWKIFZFWtri9ceZzW737uy9e3dub0PmS0jvzsw5e+49OzPnnFnA\nYvHxDZDS/LuncGZZsqUacdZFwMnAKcC/wCKgvIB2WbJkOvAfcKy6rkIcWl0wi45yimOMLQJGZBhT\nA+wCDqrrWuAQ8F180yzZkI0Dy4CVwAHgL+AR9I6cDHzpu64FvkZmpaVAvEJ6QLJCM7YNuNt3/Rbw\nbF6ts0RSgcyeFLAEmKc+/xwythhZOuf62jqBO/JsoyWCWXiz7kRk6dwMNALHBMaeocZN9LW9DvyB\nRKWWArAAcUpPoQ2xhJMpiDlO/f0734ZYciOTA9187mDkqPzgILO/0aDOl4DfgVEJdExF7FpsxCKo\nVPreyEU42xn4Ty7KhxnnAguBh5DqUK50ABuA+/Ae8CRMVX8/M6ArjVXI07ElH8ozUAKchZTjTNAC\ndGOmpDeN6HQqDvfilR+Ns1YpfycfyoeQaiQdMpmTdgK7iVfNCmMz8huPzUW4EHvgpcB7QBdwGPgV\n+BBoCIxzSN8D/W0OsA7YD/QC24GLNfdchJQC12v6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dfaOf6GBnvhpzAxKZPYkEPePyZmnu1CMluCQHupOQ0pdjwB6juHveIWSZcY85gkXm\nIFuRXM7PTqSSYBliNpH+DmhUDliKRGLzAu1PIUdEljwTXBoXAq8iLzF9AVyGPlEF2RtH4J1luexF\n/nOLJc+MDFx3A1cXwhBLbiR9HWA/UscMvg4wluhjFoshkjqwD0kbgq8VzAQ+TajbMkTMRxy5GAmx\nH0fSiPFRQpbhRQNySn4YmZH1BbXGYrFYLBbLUc//HuesqCR3OKAAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\int_{0}^{\\pi} \\sin{\\left (x \\right )}\\, dx$$" ], "text/plain": [ "π \n", "⌠ \n", "⎮ sin(x) dx\n", "⌡ \n", "0 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sym.Integral(sym.sin(x), (x, 0, sym.pi))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAMJJREFU\nKJHF0j9LQlEYB+DH6BNYhJ/HxcmpD9CgQ0OImxAIbi5u7eLSJji5NzQGDRItDtHQ3J0aSnS4LxJy\ntBMN/eBw4XCe+77nD3/MCdqYYYkPFLhHC0cpdIk13nCLIcZ4j/kpKruojmbijzW8Bjz/TevXgW7s\n6zORz/h+5VY5xiIqNXLRKMA8F3QCPKOaA64CPClP8Md0AyxwlgN6AR5xmgP6AR4c2MP3Z3GBCVbK\nSywS619izTaDqHJo3OW0+8/ZALIVMPhgrAZWAAAAAElFTkSuQmCC\n", "text/latex": [ "$$2$$" ], "text/plain": [ "2" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sym.Integral(sym.sin(x), (x, 0, sym.pi)).doit()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition, we have numpy, with its multi-dimensional array object. Numpy comes with a host of numeric recipes, already built in..." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[What are the ethics](http://ucsmp.uchicago.edu/resources/conferences/2012-03-01/) of using CAS in a poorly developing country, such as the United States, known for high infant mortality and poverty rates? \n", "\n", "Not everyone can easily afford a TI N-spire, and schools tend to not provide adequate computer infrastructure, even for accessing free and open source tools.\n", "\n", "Fortunately, even without a TI, we have CAS in the form of the SciPy ecosystem. Adapting a solution from a CAS blog post, [Quadratics and CAS](https://casmusings.wordpress.com/2017/06/30/quadratics-and-cas/), I was able to derive the same solution for the coefficients a, b and c. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([ 2., 4., -30.])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.polyfit(x=[10,5,-2],y=[210, 40, -30], deg=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "But don't we want algebra students to be able to derive the solution manually? Yes, we do. However, once this step becomes a means to an end, rather than an end in itself, a CAS will save time and facilitate deeper explorations.\n", "\n", "For further reading:\n", "* [Learning Math with Python: Youtube Lectures by Juan Klopper](https://youtu.be/P8DIM41B-mM?list=PLsu0TcgLDUiIqN76ZuRkhDUCd-c_EjIkN)\n", "* [Tutorial de SymPy: introducción y comandos básicos ... ](https://youtu.be/OGQRcYVys1Q)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }