Buckets:
| { | |
| "metadata": { | |
| "name": "Simplification" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "heading", | |
| "level": 1, | |
| "metadata": {}, | |
| "source": [ | |
| "Simplification" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "Boilerplate to make the doctester work." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "import sys\n", | |
| "import os\n", | |
| "sys.path.insert(1, os.path.join(os.path.pardir, \"ipython_doctester\"))\n", | |
| "from sympy import *\n", | |
| "from ipython_doctester import test\n", | |
| "x, y, z = symbols('x y z')" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "For each exercise, fill in the function according to its docstring. Execute the cell to see if you did it right. " | |
| ] | |
| }, | |
| { | |
| "cell_type": "heading", | |
| "level": 2, | |
| "metadata": {}, | |
| "source": [ | |
| "Polynomial/Rational Function Simplification" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "In each exercise, apply specific simplification functions to get the desired result." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def polysimp1(expr):\n", | |
| " \"\"\"\n", | |
| " >>> polysimp1(cos(x)*sin(x) + cos(x))\n", | |
| " (sin(x) + 1)*cos(x)\n", | |
| " >>> polysimp1(cos(x)*sin(x) + cos(x) + 1)\n", | |
| " (sin(x) + 1)*cos(x) + 1\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def polysimp2(expr):\n", | |
| " \"\"\"\n", | |
| " >>> polysimp2((2*x + 1)/(x**2 + x))\n", | |
| " 1/(x + 1) + 1/x\n", | |
| " >>> polysimp2((x**2 + 3*x + 1)/(x**3 + 2*x**2 + x))\n", | |
| " 1/(x**2 + 2*x + 1) + 1/x\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "heading", | |
| "level": 2, | |
| "metadata": {}, | |
| "source": [ | |
| "Powers" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "In each exercise, apply specific simplification functions to get the desired result. " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def powersimp1(expr):\n", | |
| " \"\"\"\n", | |
| " >>> powersimp1(exp(x)*(exp(y) + 1))\n", | |
| " exp(x) + exp(x + y)\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def powersimp2(expr):\n", | |
| " \"\"\"\n", | |
| " >>> powersimp2(2**x*x**x)\n", | |
| " (2*x)**x\n", | |
| " >>> powersimp2(x**x*x**x)\n", | |
| " (x**2)**x\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def powersimp3(expr):\n", | |
| " \"\"\"\n", | |
| " >>> a, b, c = symbols('a b c')\n", | |
| " >>> powersimp3((a**b)**c)\n", | |
| " a**(b*c)\n", | |
| " >>> powersimp3((a**b)**(c + 1))\n", | |
| " a**(b*c + b)\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "heading", | |
| "level": 2, | |
| "metadata": {}, | |
| "source": [ | |
| "Logs" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def logsimp1(expr):\n", | |
| " \"\"\"\n", | |
| " >>> a, b = symbols('a b', positive=True)\n", | |
| " >>> logsimp1(log(x**y*a**b))\n", | |
| " y*log(x) + log(a**b)\n", | |
| " >>> logsimp1(log(x*y*a*b))\n", | |
| " log(x) + log(y) + log(a*b)\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "heading", | |
| "level": 2, | |
| "metadata": {}, | |
| "source": [ | |
| "Miscellaneous " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def miscsimp1(expr):\n", | |
| " \"\"\"\n", | |
| " >>> miscsimp1(sin(x + y))\n", | |
| " 2*(-tan(x/2)**2 + 1)*tan(y/2)/((tan(x/2)**2 + 1)*(tan(y/2)**2 + 1)) + 2*(-tan(y/2)**2 + 1)*tan(x/2)/((tan(x/2)**2 + 1)*(tan(y/2)**2 + 1))\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def miscsimp2(expr):\n", | |
| " \"\"\"\n", | |
| " >>> miscsimp2(gamma(x + 4))\n", | |
| " x**4*gamma(x) + 6*x**3*gamma(x) + 11*x**2*gamma(x) + 6*x*gamma(x)\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "heading", | |
| "level": 2, | |
| "metadata": {}, | |
| "source": [ | |
| "Continued Fractions" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "def list_to_frac(l):\n", | |
| " expr = Integer(0)\n", | |
| " for i in reversed(l[1:]):\n", | |
| " expr += i\n", | |
| " expr = 1/expr\n", | |
| " return l[0] + expr" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "a0, a1, a2, a3, a4 = symbols('a0:5')" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "Determine the list used to create the continued fraction $$\\frac{a_{0} a_{1} a_{2} a_{3} a_{4} + a_{0} a_{1} a_{2} + a_{0} a_{3} a_{4} + a_{0} + a_{1} a_{2} a_{3} + a_{1} a_{3} a_{4} + a_{1} + a_{3}}{a_{0} a_{1} a_{2} a_{4} + a_{0} a_{4} + a_{1} a_{2} + a_{1} a_{4} + 1}.$$" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "@test\n", | |
| "def continued_frac():\n", | |
| " \"\"\"\n", | |
| " Determine the original list used to create the fraction. \n", | |
| "\n", | |
| " Return the original list from this function.\n", | |
| "\n", | |
| " >>> orig_frac = (a0*a1*a2*a3*a4 + a0*a1*a2 + a0*a3*a4 + a0 + a1*a2*a3 + a1*a3*a4 + a1 + a3)/(a0*a1*a2*a4 + a0*a4 + a1*a2 + a1*a4 + 1)\n", | |
| " >>> pprint(orig_frac, use_unicode=False, wrap_line=False)\n", | |
| " a0*a1*a2*a3*a4 + a0*a1*a2 + a0*a3*a4 + a0 + a1*a2*a3 + a1*a3*a4 + a1 + a3\n", | |
| " -------------------------------------------------------------------------\n", | |
| " a0*a1*a2*a4 + a0*a4 + a1*a2 + a1*a4 + 1 \n", | |
| " >>> cancel(list_to_frac(continued_frac())) == orig_frac\n", | |
| " True\n", | |
| " \"\"\"\n" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Xet Storage Details
- Size:
- 7.39 kB
- Xet hash:
- a8370678939e01984735ceb53966ab4af6a0c87f76b8ef6e311e4abea6a7ab81
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.