diff --git a/content/06-python-sympy/sympy-basics.ipynb b/content/06-python-sympy/sympy-basics.ipynb deleted file mode 100644 index b7ac529..0000000 --- a/content/06-python-sympy/sympy-basics.ipynb +++ /dev/null @@ -1,5156 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# SymPy examples" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "sources:\n", - "http://docs.sympy.org/latest/tutorial/\n", - "http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/notebooks/SymPy%20Examples.ipynb" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import division\n", - "import sympy as sym\n", - "# make things look pretty in the notebook\n", - "from sympy import init_session\n", - "\n", - "import math" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SymPy provides support for symbolic math to python, similar to what you would do with Mathematica or Maple. The major difference is that it acts just like any other python module, so you can use the symbolic math together in your own python projects with the rest of python functionality." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "IPython console for SymPy 1.6 (Python 3.8.3-64-bit) (ground types: python)\n", - "\n", - "These commands were executed:\n", - ">>> from __future__ import division\n", - ">>> from sympy import *\n", - ">>> x, y, z, t = symbols('x y z t')\n", - ">>> k, m, n = symbols('k m n', integer=True)\n", - ">>> f, g, h = symbols('f g h', cls=Function)\n", - ">>> init_printing()\n", - "\n", - "Documentation can be found at https://docs.sympy.org/1.6/\n", - "\n" - ] - } - ], - "source": [ - "init_session()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## SymPy types and basic symbolic manipulation\n", - "\n", - "Sympy defines its own types, you can convert them to python types, but you don't always want to (and will probably lose accuracy when you do). " - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.4142135623730951\n" - ] - } - ], - "source": [ - "print(math.sqrt(2))" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "sqrt(2)\n" - ] - } - ], - "source": [ - "print(sym.sqrt(2))" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2*sqrt(2)\n" - ] - } - ], - "source": [ - "print(sym.sqrt(8))" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": { - "tags": [ - "hide-output" - ] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on Mul in module sympy.core.mul object:\n", - "\n", - "class Mul(sympy.core.expr.Expr, sympy.core.operations.AssocOp)\n", - " | Mul(*args, **options)\n", - " | \n", - " | Base class for algebraic expressions.\n", - " | \n", - " | Everything that requires arithmetic operations to be defined\n", - " | should subclass this class, instead of Basic (which should be\n", - " | used only for argument storage and expression manipulation, i.e.\n", - " | pattern matching, substitutions, etc).\n", - " | \n", - " | See Also\n", - " | ========\n", - " | \n", - " | sympy.core.basic.Basic\n", - " | \n", - " | Method resolution order:\n", - " | Mul\n", - " | sympy.core.expr.Expr\n", - " | sympy.core.operations.AssocOp\n", - " | sympy.core.basic.Basic\n", - " | sympy.core.evalf.EvalfMixin\n", - " | builtins.object\n", - " | \n", - " | Methods defined here:\n", - " | \n", - " | __neg__(self)\n", - " | \n", - " | as_base_exp(self)\n", - " | \n", - " | as_coeff_Mul(self, rational=False)\n", - " | Efficiently extract the coefficient of a product.\n", - " | \n", - " | as_coeff_mul(self, *deps, **kwargs)\n", - " | Return the tuple (c, args) where self is written as a Mul, ``m``.\n", - " | \n", - " | c should be a Rational multiplied by any factors of the Mul that are\n", - " | independent of deps.\n", - " | \n", - " | args should be a tuple of all other factors of m; args is empty\n", - " | if self is a Number or if self is independent of deps (when given).\n", - " | \n", - " | This should be used when you don't know if self is a Mul or not but\n", - " | you want to treat self as a Mul or if you want to process the\n", - " | individual arguments of the tail of self as a Mul.\n", - " | \n", - " | - if you know self is a Mul and want only the head, use self.args[0];\n", - " | - if you don't want to process the arguments of the tail but need the\n", - " | tail then use self.as_two_terms() which gives the head and tail;\n", - " | - if you want to split self into an independent and dependent parts\n", - " | use ``self.as_independent(*deps)``\n", - " | \n", - " | >>> from sympy import S\n", - " | >>> from sympy.abc import x, y\n", - " | >>> (S(3)).as_coeff_mul()\n", - " | (3, ())\n", - " | >>> (3*x*y).as_coeff_mul()\n", - " | (3, (x, y))\n", - " | >>> (3*x*y).as_coeff_mul(x)\n", - " | (3*y, (x,))\n", - " | >>> (3*y).as_coeff_mul(x)\n", - " | (3*y, ())\n", - " | \n", - " | as_coefficients_dict(self)\n", - " | Return a dictionary mapping terms to their coefficient.\n", - " | Since the dictionary is a defaultdict, inquiries about terms which\n", - " | were not present will return a coefficient of 0. The dictionary\n", - " | is considered to have a single term.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import a, x\n", - " | >>> (3*a*x).as_coefficients_dict()\n", - " | {a*x: 3}\n", - " | >>> _[a]\n", - " | 0\n", - " | \n", - " | as_content_primitive(self, radical=False, clear=True)\n", - " | Return the tuple (R, self/R) where R is the positive Rational\n", - " | extracted from self.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sqrt\n", - " | >>> (-3*sqrt(2)*(2 - 2*sqrt(2))).as_content_primitive()\n", - " | (6, -sqrt(2)*(1 - sqrt(2)))\n", - " | \n", - " | See docstring of Expr.as_content_primitive for more examples.\n", - " | \n", - " | as_numer_denom(self)\n", - " | expression -> a/b -> a, b\n", - " | \n", - " | This is just a stub that should be defined by\n", - " | an object's class methods to get anything else.\n", - " | \n", - " | See Also\n", - " | ========\n", - " | normal: return a/b instead of a, b\n", - " | \n", - " | as_ordered_factors(self, order=None)\n", - " | Transform an expression into an ordered list of factors.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin, cos\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> (2*x*y*sin(x)*cos(x)).as_ordered_factors()\n", - " | [2, x, y, sin(x), cos(x)]\n", - " | \n", - " | as_powers_dict(self)\n", - " | Return self as a dictionary of factors with each factor being\n", - " | treated as a power. The keys are the bases of the factors and the\n", - " | values, the corresponding exponents. The resulting dictionary should\n", - " | be used with caution if the expression is a Mul and contains non-\n", - " | commutative factors since the order that they appeared will be lost in\n", - " | the dictionary.\n", - " | \n", - " | See Also\n", - " | ========\n", - " | as_ordered_factors: An alternative for noncommutative applications,\n", - " | returning an ordered list of factors.\n", - " | args_cnc: Similar to as_ordered_factors, but guarantees separation\n", - " | of commutative and noncommutative factors.\n", - " | \n", - " | as_real_imag(self, deep=True, **hints)\n", - " | Performs complex expansion on 'self' and returns a tuple\n", - " | containing collected both real and imaginary parts. This\n", - " | method can't be confused with re() and im() functions,\n", - " | which does not perform complex expansion at evaluation.\n", - " | \n", - " | However it is possible to expand both re() and im()\n", - " | functions and get exactly the same results as with\n", - " | a single call to this function.\n", - " | \n", - " | >>> from sympy import symbols, I\n", - " | \n", - " | >>> x, y = symbols('x,y', real=True)\n", - " | \n", - " | >>> (x + y*I).as_real_imag()\n", - " | (x, y)\n", - " | \n", - " | >>> from sympy.abc import z, w\n", - " | \n", - " | >>> (z + w*I).as_real_imag()\n", - " | (re(z) - im(w), re(w) + im(z))\n", - " | \n", - " | as_two_terms(self)\n", - " | Return head and tail of self.\n", - " | \n", - " | This is the most efficient way to get the head and tail of an\n", - " | expression.\n", - " | \n", - " | - if you want only the head, use self.args[0];\n", - " | - if you want to process the arguments of the tail then use\n", - " | self.as_coef_mul() which gives the head and a tuple containing\n", - " | the arguments of the tail when treated as a Mul.\n", - " | - if you want the coefficient when self is treated as an Add\n", - " | then use self.as_coeff_add()[0]\n", - " | \n", - " | >>> from sympy.abc import x, y\n", - " | >>> (3*x*y).as_two_terms()\n", - " | (3, x*y)\n", - " | \n", - " | matches(self, expr, repl_dict={}, old=False)\n", - " | Helper method for match() that looks for a match between Wild symbols\n", - " | in self and expressions in expr.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import symbols, Wild, Basic\n", - " | >>> a, b, c = symbols('a b c')\n", - " | >>> x = Wild('x')\n", - " | >>> Basic(a + x, x).matches(Basic(a + b, c)) is None\n", - " | True\n", - " | >>> Basic(a + x, x).matches(Basic(a + b + c, b + c))\n", - " | {x_: b + c}\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Class methods defined here:\n", - " | \n", - " | class_key() from sympy.core.assumptions.ManagedProperties\n", - " | Nice order of classes.\n", - " | \n", - " | flatten(seq) from sympy.core.assumptions.ManagedProperties\n", - " | Return commutative, noncommutative and order arguments by\n", - " | combining related terms.\n", - " | \n", - " | Notes\n", - " | =====\n", - " | * In an expression like ``a*b*c``, python process this through sympy\n", - " | as ``Mul(Mul(a, b), c)``. This can have undesirable consequences.\n", - " | \n", - " | - Sometimes terms are not combined as one would like:\n", - " | {c.f. https://github.com/sympy/sympy/issues/4596}\n", - " | \n", - " | >>> from sympy import Mul, sqrt\n", - " | >>> from sympy.abc import x, y, z\n", - " | >>> 2*(x + 1) # this is the 2-arg Mul behavior\n", - " | 2*x + 2\n", - " | >>> y*(x + 1)*2\n", - " | 2*y*(x + 1)\n", - " | >>> 2*(x + 1)*y # 2-arg result will be obtained first\n", - " | y*(2*x + 2)\n", - " | >>> Mul(2, x + 1, y) # all 3 args simultaneously processed\n", - " | 2*y*(x + 1)\n", - " | >>> 2*((x + 1)*y) # parentheses can control this behavior\n", - " | 2*y*(x + 1)\n", - " | \n", - " | Powers with compound bases may not find a single base to\n", - " | combine with unless all arguments are processed at once.\n", - " | Post-processing may be necessary in such cases.\n", - " | {c.f. https://github.com/sympy/sympy/issues/5728}\n", - " | \n", - " | >>> a = sqrt(x*sqrt(y))\n", - " | >>> a**3\n", - " | (x*sqrt(y))**(3/2)\n", - " | >>> Mul(a,a,a)\n", - " | (x*sqrt(y))**(3/2)\n", - " | >>> a*a*a\n", - " | x*sqrt(y)*sqrt(x*sqrt(y))\n", - " | >>> _.subs(a.base, z).subs(z, a.base)\n", - " | (x*sqrt(y))**(3/2)\n", - " | \n", - " | - If more than two terms are being multiplied then all the\n", - " | previous terms will be re-processed for each new argument.\n", - " | So if each of ``a``, ``b`` and ``c`` were :class:`Mul`\n", - " | expression, then ``a*b*c`` (or building up the product\n", - " | with ``*=``) will process all the arguments of ``a`` and\n", - " | ``b`` twice: once when ``a*b`` is computed and again when\n", - " | ``c`` is multiplied.\n", - " | \n", - " | Using ``Mul(a, b, c)`` will process all arguments once.\n", - " | \n", - " | * The results of Mul are cached according to arguments, so flatten\n", - " | will only be called once for ``Mul(a, b, c)``. If you can\n", - " | structure a calculation so the arguments are most likely to be\n", - " | repeats then this can save time in computing the answer. For\n", - " | example, say you had a Mul, M, that you wished to divide by ``d[i]``\n", - " | and multiply by ``n[i]`` and you suspect there are many repeats\n", - " | in ``n``. It would be better to compute ``M*n[i]/d[i]`` rather\n", - " | than ``M/d[i]*n[i]`` since every time n[i] is a repeat, the\n", - " | product, ``M*n[i]`` will be returned without flattening -- the\n", - " | cached value will be returned. If you divide by the ``d[i]``\n", - " | first (and those are more unique than the ``n[i]``) then that will\n", - " | create a new Mul, ``M/d[i]`` the args of which will be traversed\n", - " | again when it is multiplied by ``n[i]``.\n", - " | \n", - " | {c.f. https://github.com/sympy/sympy/issues/5706}\n", - " | \n", - " | This consideration is moot if the cache is turned off.\n", - " | \n", - " | NB\n", - " | --\n", - " | The validity of the above notes depends on the implementation\n", - " | details of Mul and flatten which may change at any time. Therefore,\n", - " | you should only consider them when your code is highly performance\n", - " | sensitive.\n", - " | \n", - " | Removal of 1 from the sequence is already handled by AssocOp.__new__.\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Readonly properties defined here:\n", - " | \n", - " | __sympy__\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Data and other attributes defined here:\n", - " | \n", - " | default_assumptions = {}\n", - " | \n", - " | identity = 1\n", - " | \n", - " | is_Mul = True\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Methods inherited from sympy.core.expr.Expr:\n", - " | \n", - " | __abs__(self)\n", - " | \n", - " | __add__(self, other)\n", - " | \n", - " | __complex__(self)\n", - " | \n", - " | __div__(self, other)\n", - " | \n", - " | __divmod__(self, other)\n", - " | \n", - " | __eq__(self, other)\n", - " | Return a boolean indicating whether a == b on the basis of\n", - " | their symbolic trees.\n", - " | \n", - " | This is the same as a.compare(b) == 0 but faster.\n", - " | \n", - " | Notes\n", - " | =====\n", - " | \n", - " | If a class that overrides __eq__() needs to retain the\n", - " | implementation of __hash__() from a parent class, the\n", - " | interpreter must be told this explicitly by setting __hash__ =\n", - " | .__hash__. Otherwise the inheritance of __hash__()\n", - " | will be blocked, just as if __hash__ had been explicitly set to\n", - " | None.\n", - " | \n", - " | References\n", - " | ==========\n", - " | \n", - " | from http://docs.python.org/dev/reference/datamodel.html#object.__hash__\n", - " | \n", - " | __float__(self)\n", - " | \n", - " | __floordiv__(self, other)\n", - " | \n", - " | __ge__(self, other)\n", - " | Return self>=value.\n", - " | \n", - " | __gt__(self, other)\n", - " | Return self>value.\n", - " | \n", - " | __hash__(self)\n", - " | Return hash(self).\n", - " | \n", - " | __int__(self)\n", - " | \n", - " | __le__(self, other)\n", - " | Return self<=value.\n", - " | \n", - " | __long__ = __int__(self)\n", - " | \n", - " | __lt__(self, other)\n", - " | Return self>> from sympy import symbols, oo\n", - " | >>> A, B = symbols('A B', commutative=0)\n", - " | >>> x, y = symbols('x y')\n", - " | >>> (-2*x*y).args_cnc()\n", - " | [[-1, 2, x, y], []]\n", - " | >>> (-2.5*x).args_cnc()\n", - " | [[-1, 2.5, x], []]\n", - " | >>> (-2*x*A*B*y).args_cnc()\n", - " | [[-1, 2, x, y], [A, B]]\n", - " | >>> (-2*x*A*B*y).args_cnc(split_1=False)\n", - " | [[-2, x, y], [A, B]]\n", - " | >>> (-2*x*y).args_cnc(cset=True)\n", - " | [{-1, 2, x, y}, []]\n", - " | \n", - " | The arg is always treated as a Mul:\n", - " | \n", - " | >>> (-2 + x + A).args_cnc()\n", - " | [[], [x - 2 + A]]\n", - " | >>> (-oo).args_cnc() # -oo is a singleton\n", - " | [[-1, oo], []]\n", - " | \n", - " | as_coeff_Add(self, rational=False)\n", - " | Efficiently extract the coefficient of a summation.\n", - " | \n", - " | as_coeff_add(self, *deps)\n", - " | Return the tuple (c, args) where self is written as an Add, ``a``.\n", - " | \n", - " | c should be a Rational added to any terms of the Add that are\n", - " | independent of deps.\n", - " | \n", - " | args should be a tuple of all other terms of ``a``; args is empty\n", - " | if self is a Number or if self is independent of deps (when given).\n", - " | \n", - " | This should be used when you don't know if self is an Add or not but\n", - " | you want to treat self as an Add or if you want to process the\n", - " | individual arguments of the tail of self as an Add.\n", - " | \n", - " | - if you know self is an Add and want only the head, use self.args[0];\n", - " | - if you don't want to process the arguments of the tail but need the\n", - " | tail then use self.as_two_terms() which gives the head and tail.\n", - " | - if you want to split self into an independent and dependent parts\n", - " | use ``self.as_independent(*deps)``\n", - " | \n", - " | >>> from sympy import S\n", - " | >>> from sympy.abc import x, y\n", - " | >>> (S(3)).as_coeff_add()\n", - " | (3, ())\n", - " | >>> (3 + x).as_coeff_add()\n", - " | (3, (x,))\n", - " | >>> (3 + x + y).as_coeff_add(x)\n", - " | (y + 3, (x,))\n", - " | >>> (3 + y).as_coeff_add(x)\n", - " | (y + 3, ())\n", - " | \n", - " | as_coeff_exponent(self, x)\n", - " | ``c*x**e -> c,e`` where x can be any symbolic expression.\n", - " | \n", - " | as_coefficient(self, expr)\n", - " | Extracts symbolic coefficient at the given expression. In\n", - " | other words, this functions separates 'self' into the product\n", - " | of 'expr' and 'expr'-free coefficient. If such separation\n", - " | is not possible it will return None.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import E, pi, sin, I, Poly\n", - " | >>> from sympy.abc import x\n", - " | \n", - " | >>> E.as_coefficient(E)\n", - " | 1\n", - " | >>> (2*E).as_coefficient(E)\n", - " | 2\n", - " | >>> (2*sin(E)*E).as_coefficient(E)\n", - " | \n", - " | Two terms have E in them so a sum is returned. (If one were\n", - " | desiring the coefficient of the term exactly matching E then\n", - " | the constant from the returned expression could be selected.\n", - " | Or, for greater precision, a method of Poly can be used to\n", - " | indicate the desired term from which the coefficient is\n", - " | desired.)\n", - " | \n", - " | >>> (2*E + x*E).as_coefficient(E)\n", - " | x + 2\n", - " | >>> _.args[0] # just want the exact match\n", - " | 2\n", - " | >>> p = Poly(2*E + x*E); p\n", - " | Poly(x*E + 2*E, x, E, domain='ZZ')\n", - " | >>> p.coeff_monomial(E)\n", - " | 2\n", - " | >>> p.nth(0, 1)\n", - " | 2\n", - " | \n", - " | Since the following cannot be written as a product containing\n", - " | E as a factor, None is returned. (If the coefficient ``2*x`` is\n", - " | desired then the ``coeff`` method should be used.)\n", - " | \n", - " | >>> (2*E*x + x).as_coefficient(E)\n", - " | >>> (2*E*x + x).coeff(E)\n", - " | 2*x\n", - " | \n", - " | >>> (E*(x + 1) + x).as_coefficient(E)\n", - " | \n", - " | >>> (2*pi*I).as_coefficient(pi*I)\n", - " | 2\n", - " | >>> (2*I).as_coefficient(pi*I)\n", - " | \n", - " | See Also\n", - " | ========\n", - " | \n", - " | coeff: return sum of terms have a given factor\n", - " | as_coeff_Add: separate the additive constant from an expression\n", - " | as_coeff_Mul: separate the multiplicative constant from an expression\n", - " | as_independent: separate x-dependent terms/factors from others\n", - " | sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly\n", - " | sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used\n", - " | \n", - " | as_expr(self, *gens)\n", - " | Convert a polynomial to a SymPy expression.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> f = (x**2 + x*y).as_poly(x, y)\n", - " | >>> f.as_expr()\n", - " | x**2 + x*y\n", - " | \n", - " | >>> sin(x).as_expr()\n", - " | sin(x)\n", - " | \n", - " | as_independent(self, *deps, **hint)\n", - " | A mostly naive separation of a Mul or Add into arguments that are not\n", - " | are dependent on deps. To obtain as complete a separation of variables\n", - " | as possible, use a separation method first, e.g.:\n", - " | \n", - " | * separatevars() to change Mul, Add and Pow (including exp) into Mul\n", - " | * .expand(mul=True) to change Add or Mul into Add\n", - " | * .expand(log=True) to change log expr into an Add\n", - " | \n", - " | The only non-naive thing that is done here is to respect noncommutative\n", - " | ordering of variables and to always return (0, 0) for `self` of zero\n", - " | regardless of hints.\n", - " | \n", - " | For nonzero `self`, the returned tuple (i, d) has the\n", - " | following interpretation:\n", - " | \n", - " | * i will has no variable that appears in deps\n", - " | * d will either have terms that contain variables that are in deps, or\n", - " | be equal to 0 (when self is an Add) or 1 (when self is a Mul)\n", - " | * if self is an Add then self = i + d\n", - " | * if self is a Mul then self = i*d\n", - " | * otherwise (self, S.One) or (S.One, self) is returned.\n", - " | \n", - " | To force the expression to be treated as an Add, use the hint as_Add=True\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | -- self is an Add\n", - " | \n", - " | >>> from sympy import sin, cos, exp\n", - " | >>> from sympy.abc import x, y, z\n", - " | \n", - " | >>> (x + x*y).as_independent(x)\n", - " | (0, x*y + x)\n", - " | >>> (x + x*y).as_independent(y)\n", - " | (x, x*y)\n", - " | >>> (2*x*sin(x) + y + x + z).as_independent(x)\n", - " | (y + z, 2*x*sin(x) + x)\n", - " | >>> (2*x*sin(x) + y + x + z).as_independent(x, y)\n", - " | (z, 2*x*sin(x) + x + y)\n", - " | \n", - " | -- self is a Mul\n", - " | \n", - " | >>> (x*sin(x)*cos(y)).as_independent(x)\n", - " | (cos(y), x*sin(x))\n", - " | \n", - " | non-commutative terms cannot always be separated out when self is a Mul\n", - " | \n", - " | >>> from sympy import symbols\n", - " | >>> n1, n2, n3 = symbols('n1 n2 n3', commutative=False)\n", - " | >>> (n1 + n1*n2).as_independent(n2)\n", - " | (n1, n1*n2)\n", - " | >>> (n2*n1 + n1*n2).as_independent(n2)\n", - " | (0, n1*n2 + n2*n1)\n", - " | >>> (n1*n2*n3).as_independent(n1)\n", - " | (1, n1*n2*n3)\n", - " | >>> (n1*n2*n3).as_independent(n2)\n", - " | (n1, n2*n3)\n", - " | >>> ((x-n1)*(x-y)).as_independent(x)\n", - " | (1, (x - y)*(x - n1))\n", - " | \n", - " | -- self is anything else:\n", - " | \n", - " | >>> (sin(x)).as_independent(x)\n", - " | (1, sin(x))\n", - " | >>> (sin(x)).as_independent(y)\n", - " | (sin(x), 1)\n", - " | >>> exp(x+y).as_independent(x)\n", - " | (1, exp(x + y))\n", - " | \n", - " | -- force self to be treated as an Add:\n", - " | \n", - " | >>> (3*x).as_independent(x, as_Add=True)\n", - " | (0, 3*x)\n", - " | \n", - " | -- force self to be treated as a Mul:\n", - " | \n", - " | >>> (3+x).as_independent(x, as_Add=False)\n", - " | (1, x + 3)\n", - " | >>> (-3+x).as_independent(x, as_Add=False)\n", - " | (1, x - 3)\n", - " | \n", - " | Note how the below differs from the above in making the\n", - " | constant on the dep term positive.\n", - " | \n", - " | >>> (y*(-3+x)).as_independent(x)\n", - " | (y, x - 3)\n", - " | \n", - " | -- use .as_independent() for true independence testing instead\n", - " | of .has(). The former considers only symbols in the free\n", - " | symbols while the latter considers all symbols\n", - " | \n", - " | >>> from sympy import Integral\n", - " | >>> I = Integral(x, (x, 1, 2))\n", - " | >>> I.has(x)\n", - " | True\n", - " | >>> x in I.free_symbols\n", - " | False\n", - " | >>> I.as_independent(x) == (I, 1)\n", - " | True\n", - " | >>> (I + x).as_independent(x) == (I, x)\n", - " | True\n", - " | \n", - " | Note: when trying to get independent terms, a separation method\n", - " | might need to be used first. In this case, it is important to keep\n", - " | track of what you send to this routine so you know how to interpret\n", - " | the returned values\n", - " | \n", - " | >>> from sympy import separatevars, log\n", - " | >>> separatevars(exp(x+y)).as_independent(x)\n", - " | (exp(y), exp(x))\n", - " | >>> (x + x*y).as_independent(y)\n", - " | (x, x*y)\n", - " | >>> separatevars(x + x*y).as_independent(y)\n", - " | (x, y + 1)\n", - " | >>> (x*(1 + y)).as_independent(y)\n", - " | (x, y + 1)\n", - " | >>> (x*(1 + y)).expand(mul=True).as_independent(y)\n", - " | (x, x*y)\n", - " | >>> a, b=symbols('a b', positive=True)\n", - " | >>> (log(a*b).expand(log=True)).as_independent(b)\n", - " | (log(a), log(b))\n", - " | \n", - " | See Also\n", - " | ========\n", - " | .separatevars(), .expand(log=True), sympy.core.add.Add.as_two_terms(),\n", - " | sympy.core.mul.Mul.as_two_terms(), .as_coeff_add(), .as_coeff_mul()\n", - " | \n", - " | as_leading_term(self, *symbols)\n", - " | Returns the leading (nonzero) term of the series expansion of self.\n", - " | \n", - " | The _eval_as_leading_term routines are used to do this, and they must\n", - " | always return a non-zero value.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x\n", - " | >>> (1 + x + x**2).as_leading_term(x)\n", - " | 1\n", - " | >>> (1/x**2 + x + x**2).as_leading_term(x)\n", - " | x**(-2)\n", - " | \n", - " | as_ordered_terms(self, order=None, data=False)\n", - " | Transform an expression to an ordered list of terms.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin, cos\n", - " | >>> from sympy.abc import x\n", - " | \n", - " | >>> (sin(x)**2*cos(x) + sin(x)**2 + 1).as_ordered_terms()\n", - " | [sin(x)**2*cos(x), sin(x)**2, 1]\n", - " | \n", - " | as_poly(self, *gens, **args)\n", - " | Converts ``self`` to a polynomial or returns ``None``.\n", - " | \n", - " | >>> from sympy import sin\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> print((x**2 + x*y).as_poly())\n", - " | Poly(x**2 + x*y, x, y, domain='ZZ')\n", - " | \n", - " | >>> print((x**2 + x*y).as_poly(x, y))\n", - " | Poly(x**2 + x*y, x, y, domain='ZZ')\n", - " | \n", - " | >>> print((x**2 + sin(y)).as_poly(x, y))\n", - " | None\n", - " | \n", - " | as_terms(self)\n", - " | Transform an expression to a list of terms.\n", - " | \n", - " | aseries(self, x=None, n=6, bound=0, hir=False)\n", - " | Asymptotic Series expansion of self.\n", - " | This is equivalent to ``self.series(x, oo, n)``.\n", - " | \n", - " | Parameters\n", - " | ==========\n", - " | \n", - " | self : Expression\n", - " | The expression whose series is to be expanded.\n", - " | \n", - " | x : Symbol\n", - " | It is the variable of the expression to be calculated.\n", - " | \n", - " | n : Value\n", - " | The number of terms upto which the series is to be expanded.\n", - " | \n", - " | hir : Boolean\n", - " | Set this parameter to be True to produce hierarchical series.\n", - " | It stops the recursion at an early level and may provide nicer\n", - " | and more useful results.\n", - " | \n", - " | bound : Value, Integer\n", - " | Use the ``bound`` parameter to give limit on rewriting\n", - " | coefficients in its normalised form.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin, exp\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> e = sin(1/x + exp(-x)) - sin(1/x)\n", - " | \n", - " | >>> e.aseries(x)\n", - " | (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)\n", - " | \n", - " | >>> e.aseries(x, n=3, hir=True)\n", - " | -exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))\n", - " | \n", - " | >>> e = exp(exp(x)/(1 - 1/x))\n", - " | \n", - " | >>> e.aseries(x)\n", - " | exp(exp(x)/(1 - 1/x))\n", - " | \n", - " | >>> e.aseries(x, bound=3)\n", - " | exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))\n", - " | \n", - " | Returns\n", - " | =======\n", - " | \n", - " | Expr\n", - " | Asymptotic series expansion of the expression.\n", - " | \n", - " | Notes\n", - " | =====\n", - " | \n", - " | This algorithm is directly induced from the limit computational algorithm provided by Gruntz.\n", - " | It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first\n", - " | to look for the most rapidly varying subexpression w of a given expression f and then expands f\n", - " | in a series in w. Then same thing is recursively done on the leading coefficient\n", - " | till we get constant coefficients.\n", - " | \n", - " | If the most rapidly varying subexpression of a given expression f is f itself,\n", - " | the algorithm tries to find a normalised representation of the mrv set and rewrites f\n", - " | using this normalised representation.\n", - " | \n", - " | If the expansion contains an order term, it will be either ``O(x ** (-n))`` or ``O(w ** (-n))``\n", - " | where ``w`` belongs to the most rapidly varying expression of ``self``.\n", - " | \n", - " | References\n", - " | ==========\n", - " | \n", - " | .. [1] A New Algorithm for Computing Asymptotic Series - Dominik Gruntz\n", - " | .. [2] Gruntz thesis - p90\n", - " | .. [3] http://en.wikipedia.org/wiki/Asymptotic_expansion\n", - " | \n", - " | See Also\n", - " | ========\n", - " | \n", - " | Expr.aseries: See the docstring of this function for complete details of this wrapper.\n", - " | \n", - " | cancel(self, *gens, **args)\n", - " | See the cancel function in sympy.polys\n", - " | \n", - " | coeff(self, x, n=1, right=False)\n", - " | Returns the coefficient from the term(s) containing ``x**n``. If ``n``\n", - " | is zero then all terms independent of ``x`` will be returned.\n", - " | \n", - " | When ``x`` is noncommutative, the coefficient to the left (default) or\n", - " | right of ``x`` can be returned. The keyword 'right' is ignored when\n", - " | ``x`` is commutative.\n", - " | \n", - " | See Also\n", - " | ========\n", - " | \n", - " | as_coefficient: separate the expression into a coefficient and factor\n", - " | as_coeff_Add: separate the additive constant from an expression\n", - " | as_coeff_Mul: separate the multiplicative constant from an expression\n", - " | as_independent: separate x-dependent terms/factors from others\n", - " | sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly\n", - " | sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import symbols\n", - " | >>> from sympy.abc import x, y, z\n", - " | \n", - " | You can select terms that have an explicit negative in front of them:\n", - " | \n", - " | >>> (-x + 2*y).coeff(-1)\n", - " | x\n", - " | >>> (x - 2*y).coeff(-1)\n", - " | 2*y\n", - " | \n", - " | You can select terms with no Rational coefficient:\n", - " | \n", - " | >>> (x + 2*y).coeff(1)\n", - " | x\n", - " | >>> (3 + 2*x + 4*x**2).coeff(1)\n", - " | 0\n", - " | \n", - " | You can select terms independent of x by making n=0; in this case\n", - " | expr.as_independent(x)[0] is returned (and 0 will be returned instead\n", - " | of None):\n", - " | \n", - " | >>> (3 + 2*x + 4*x**2).coeff(x, 0)\n", - " | 3\n", - " | >>> eq = ((x + 1)**3).expand() + 1\n", - " | >>> eq\n", - " | x**3 + 3*x**2 + 3*x + 2\n", - " | >>> [eq.coeff(x, i) for i in reversed(range(4))]\n", - " | [1, 3, 3, 2]\n", - " | >>> eq -= 2\n", - " | >>> [eq.coeff(x, i) for i in reversed(range(4))]\n", - " | [1, 3, 3, 0]\n", - " | \n", - " | You can select terms that have a numerical term in front of them:\n", - " | \n", - " | >>> (-x - 2*y).coeff(2)\n", - " | -y\n", - " | >>> from sympy import sqrt\n", - " | >>> (x + sqrt(2)*x).coeff(sqrt(2))\n", - " | x\n", - " | \n", - " | The matching is exact:\n", - " | \n", - " | >>> (3 + 2*x + 4*x**2).coeff(x)\n", - " | 2\n", - " | >>> (3 + 2*x + 4*x**2).coeff(x**2)\n", - " | 4\n", - " | >>> (3 + 2*x + 4*x**2).coeff(x**3)\n", - " | 0\n", - " | >>> (z*(x + y)**2).coeff((x + y)**2)\n", - " | z\n", - " | >>> (z*(x + y)**2).coeff(x + y)\n", - " | 0\n", - " | \n", - " | In addition, no factoring is done, so 1 + z*(1 + y) is not obtained\n", - " | from the following:\n", - " | \n", - " | >>> (x + z*(x + x*y)).coeff(x)\n", - " | 1\n", - " | \n", - " | If such factoring is desired, factor_terms can be used first:\n", - " | \n", - " | >>> from sympy import factor_terms\n", - " | >>> factor_terms(x + z*(x + x*y)).coeff(x)\n", - " | z*(y + 1) + 1\n", - " | \n", - " | >>> n, m, o = symbols('n m o', commutative=False)\n", - " | >>> n.coeff(n)\n", - " | 1\n", - " | >>> (3*n).coeff(n)\n", - " | 3\n", - " | >>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m\n", - " | 1 + m\n", - " | >>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m\n", - " | m\n", - " | \n", - " | If there is more than one possible coefficient 0 is returned:\n", - " | \n", - " | >>> (n*m + m*n).coeff(n)\n", - " | 0\n", - " | \n", - " | If there is only one possible coefficient, it is returned:\n", - " | \n", - " | >>> (n*m + x*m*n).coeff(m*n)\n", - " | x\n", - " | >>> (n*m + x*m*n).coeff(m*n, right=1)\n", - " | 1\n", - " | \n", - " | collect(self, syms, func=None, evaluate=True, exact=False, distribute_order_term=True)\n", - " | See the collect function in sympy.simplify\n", - " | \n", - " | combsimp(self)\n", - " | See the combsimp function in sympy.simplify\n", - " | \n", - " | compute_leading_term(self, x, logx=None)\n", - " | as_leading_term is only allowed for results of .series()\n", - " | This is a wrapper to compute a series first.\n", - " | \n", - " | conjugate(self)\n", - " | Returns the complex conjugate of 'self'.\n", - " | \n", - " | could_extract_minus_sign(self)\n", - " | Return True if self is not in a canonical form with respect\n", - " | to its sign.\n", - " | \n", - " | For most expressions, e, there will be a difference in e and -e.\n", - " | When there is, True will be returned for one and False for the\n", - " | other; False will be returned if there is no difference.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x, y\n", - " | >>> e = x - y\n", - " | >>> {i.could_extract_minus_sign() for i in (e, -e)}\n", - " | {False, True}\n", - " | \n", - " | count_ops(self, visual=None)\n", - " | wrapper for count_ops that returns the operation count.\n", - " | \n", - " | diff(self, *symbols, **assumptions)\n", - " | \n", - " | equals(self, other, failing_expression=False)\n", - " | Return True if self == other, False if it doesn't, or None. If\n", - " | failing_expression is True then the expression which did not simplify\n", - " | to a 0 will be returned instead of None.\n", - " | \n", - " | If ``self`` is a Number (or complex number) that is not zero, then\n", - " | the result is False.\n", - " | \n", - " | If ``self`` is a number and has not evaluated to zero, evalf will be\n", - " | used to test whether the expression evaluates to zero. If it does so\n", - " | and the result has significance (i.e. the precision is either -1, for\n", - " | a Rational result, or is greater than 1) then the evalf value will be\n", - " | used to return True or False.\n", - " | \n", - " | expand(self, deep=True, modulus=None, power_base=True, power_exp=True, mul=True, log=True, multinomial=True, basic=True, **hints)\n", - " | Expand an expression using hints.\n", - " | \n", - " | See the docstring of the expand() function in sympy.core.function for\n", - " | more information.\n", - " | \n", - " | extract_additively(self, c)\n", - " | Return self - c if it's possible to subtract c from self and\n", - " | make all matching coefficients move towards zero, else return None.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x, y\n", - " | >>> e = 2*x + 3\n", - " | >>> e.extract_additively(x + 1)\n", - " | x + 2\n", - " | >>> e.extract_additively(3*x)\n", - " | >>> e.extract_additively(4)\n", - " | >>> (y*(x + 1)).extract_additively(x + 1)\n", - " | >>> ((x + 1)*(x + 2*y + 1) + 3).extract_additively(x + 1)\n", - " | (x + 1)*(x + 2*y) + 3\n", - " | \n", - " | Sometimes auto-expansion will return a less simplified result\n", - " | than desired; gcd_terms might be used in such cases:\n", - " | \n", - " | >>> from sympy import gcd_terms\n", - " | >>> (4*x*(y + 1) + y).extract_additively(x)\n", - " | 4*x*(y + 1) + x*(4*y + 3) - x*(4*y + 4) + y\n", - " | >>> gcd_terms(_)\n", - " | x*(4*y + 3) + y\n", - " | \n", - " | See Also\n", - " | ========\n", - " | extract_multiplicatively\n", - " | coeff\n", - " | as_coefficient\n", - " | \n", - " | extract_branch_factor(self, allow_half=False)\n", - " | Try to write self as ``exp_polar(2*pi*I*n)*z`` in a nice way.\n", - " | Return (z, n).\n", - " | \n", - " | >>> from sympy import exp_polar, I, pi\n", - " | >>> from sympy.abc import x, y\n", - " | >>> exp_polar(I*pi).extract_branch_factor()\n", - " | (exp_polar(I*pi), 0)\n", - " | >>> exp_polar(2*I*pi).extract_branch_factor()\n", - " | (1, 1)\n", - " | >>> exp_polar(-pi*I).extract_branch_factor()\n", - " | (exp_polar(I*pi), -1)\n", - " | >>> exp_polar(3*pi*I + x).extract_branch_factor()\n", - " | (exp_polar(x + I*pi), 1)\n", - " | >>> (y*exp_polar(-5*pi*I)*exp_polar(3*pi*I + 2*pi*x)).extract_branch_factor()\n", - " | (y*exp_polar(2*pi*x), -1)\n", - " | >>> exp_polar(-I*pi/2).extract_branch_factor()\n", - " | (exp_polar(-I*pi/2), 0)\n", - " | \n", - " | If allow_half is True, also extract exp_polar(I*pi):\n", - " | \n", - " | >>> exp_polar(I*pi).extract_branch_factor(allow_half=True)\n", - " | (1, 1/2)\n", - " | >>> exp_polar(2*I*pi).extract_branch_factor(allow_half=True)\n", - " | (1, 1)\n", - " | >>> exp_polar(3*I*pi).extract_branch_factor(allow_half=True)\n", - " | (1, 3/2)\n", - " | >>> exp_polar(-I*pi).extract_branch_factor(allow_half=True)\n", - " | (1, -1/2)\n", - " | \n", - " | extract_multiplicatively(self, c)\n", - " | Return None if it's not possible to make self in the form\n", - " | c * something in a nice way, i.e. preserving the properties\n", - " | of arguments of self.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import symbols, Rational\n", - " | \n", - " | >>> x, y = symbols('x,y', real=True)\n", - " | \n", - " | >>> ((x*y)**3).extract_multiplicatively(x**2 * y)\n", - " | x*y**2\n", - " | \n", - " | >>> ((x*y)**3).extract_multiplicatively(x**4 * y)\n", - " | \n", - " | >>> (2*x).extract_multiplicatively(2)\n", - " | x\n", - " | \n", - " | >>> (2*x).extract_multiplicatively(3)\n", - " | \n", - " | >>> (Rational(1, 2)*x).extract_multiplicatively(3)\n", - " | x/6\n", - " | \n", - " | factor(self, *gens, **args)\n", - " | See the factor() function in sympy.polys.polytools\n", - " | \n", - " | fourier_series(self, limits=None)\n", - " | Compute fourier sine/cosine series of self.\n", - " | \n", - " | See the docstring of the :func:`fourier_series` in sympy.series.fourier\n", - " | for more information.\n", - " | \n", - " | fps(self, x=None, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)\n", - " | Compute formal power power series of self.\n", - " | \n", - " | See the docstring of the :func:`fps` function in sympy.series.formal for\n", - " | more information.\n", - " | \n", - " | gammasimp(self)\n", - " | See the gammasimp function in sympy.simplify\n", - " | \n", - " | getO(self)\n", - " | Returns the additive O(..) symbol if there is one, else None.\n", - " | \n", - " | getn(self)\n", - " | Returns the order of the expression.\n", - " | \n", - " | The order is determined either from the O(...) term. If there\n", - " | is no O(...) term, it returns None.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import O\n", - " | >>> from sympy.abc import x\n", - " | >>> (1 + x + O(x**2)).getn()\n", - " | 2\n", - " | >>> (1 + x).getn()\n", - " | \n", - " | integrate(self, *args, **kwargs)\n", - " | See the integrate function in sympy.integrals\n", - " | \n", - " | invert(self, g, *gens, **args)\n", - " | Return the multiplicative inverse of ``self`` mod ``g``\n", - " | where ``self`` (and ``g``) may be symbolic expressions).\n", - " | \n", - " | See Also\n", - " | ========\n", - " | sympy.core.numbers.mod_inverse, sympy.polys.polytools.invert\n", - " | \n", - " | is_algebraic_expr(self, *syms)\n", - " | This tests whether a given expression is algebraic or not, in the\n", - " | given symbols, syms. When syms is not given, all free symbols\n", - " | will be used. The rational function does not have to be in expanded\n", - " | or in any kind of canonical form.\n", - " | \n", - " | This function returns False for expressions that are \"algebraic\n", - " | expressions\" with symbolic exponents. This is a simple extension to the\n", - " | is_rational_function, including rational exponentiation.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Symbol, sqrt\n", - " | >>> x = Symbol('x', real=True)\n", - " | >>> sqrt(1 + x).is_rational_function()\n", - " | False\n", - " | >>> sqrt(1 + x).is_algebraic_expr()\n", - " | True\n", - " | \n", - " | This function does not attempt any nontrivial simplifications that may\n", - " | result in an expression that does not appear to be an algebraic\n", - " | expression to become one.\n", - " | \n", - " | >>> from sympy import exp, factor\n", - " | >>> a = sqrt(exp(x)**2 + 2*exp(x) + 1)/(exp(x) + 1)\n", - " | >>> a.is_algebraic_expr(x)\n", - " | False\n", - " | >>> factor(a).is_algebraic_expr()\n", - " | True\n", - " | \n", - " | See Also\n", - " | ========\n", - " | is_rational_function()\n", - " | \n", - " | References\n", - " | ==========\n", - " | \n", - " | - https://en.wikipedia.org/wiki/Algebraic_expression\n", - " | \n", - " | is_constant(self, *wrt, **flags)\n", - " | Return True if self is constant, False if not, or None if\n", - " | the constancy could not be determined conclusively.\n", - " | \n", - " | If an expression has no free symbols then it is a constant. If\n", - " | there are free symbols it is possible that the expression is a\n", - " | constant, perhaps (but not necessarily) zero. To test such\n", - " | expressions, a few strategies are tried:\n", - " | \n", - " | 1) numerical evaluation at two random points. If two such evaluations\n", - " | give two different values and the values have a precision greater than\n", - " | 1 then self is not constant. If the evaluations agree or could not be\n", - " | obtained with any precision, no decision is made. The numerical testing\n", - " | is done only if ``wrt`` is different than the free symbols.\n", - " | \n", - " | 2) differentiation with respect to variables in 'wrt' (or all free\n", - " | symbols if omitted) to see if the expression is constant or not. This\n", - " | will not always lead to an expression that is zero even though an\n", - " | expression is constant (see added test in test_expr.py). If\n", - " | all derivatives are zero then self is constant with respect to the\n", - " | given symbols.\n", - " | \n", - " | 3) finding out zeros of denominator expression with free_symbols.\n", - " | It won't be constant if there are zeros. It gives more negative\n", - " | answers for expression that are not constant.\n", - " | \n", - " | If neither evaluation nor differentiation can prove the expression is\n", - " | constant, None is returned unless two numerical values happened to be\n", - " | the same and the flag ``failing_number`` is True -- in that case the\n", - " | numerical value will be returned.\n", - " | \n", - " | If flag simplify=False is passed, self will not be simplified;\n", - " | the default is True since self should be simplified before testing.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import cos, sin, Sum, S, pi\n", - " | >>> from sympy.abc import a, n, x, y\n", - " | >>> x.is_constant()\n", - " | False\n", - " | >>> S(2).is_constant()\n", - " | True\n", - " | >>> Sum(x, (x, 1, 10)).is_constant()\n", - " | True\n", - " | >>> Sum(x, (x, 1, n)).is_constant()\n", - " | False\n", - " | >>> Sum(x, (x, 1, n)).is_constant(y)\n", - " | True\n", - " | >>> Sum(x, (x, 1, n)).is_constant(n)\n", - " | False\n", - " | >>> Sum(x, (x, 1, n)).is_constant(x)\n", - " | True\n", - " | >>> eq = a*cos(x)**2 + a*sin(x)**2 - a\n", - " | >>> eq.is_constant()\n", - " | True\n", - " | >>> eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0\n", - " | True\n", - " | \n", - " | >>> (0**x).is_constant()\n", - " | False\n", - " | >>> x.is_constant()\n", - " | False\n", - " | >>> (x**x).is_constant()\n", - " | False\n", - " | >>> one = cos(x)**2 + sin(x)**2\n", - " | >>> one.is_constant()\n", - " | True\n", - " | >>> ((one - 1)**(x + 1)).is_constant() in (True, False) # could be 0 or 1\n", - " | True\n", - " | \n", - " | is_polynomial(self, *syms)\n", - " | Return True if self is a polynomial in syms and False otherwise.\n", - " | \n", - " | This checks if self is an exact polynomial in syms. This function\n", - " | returns False for expressions that are \"polynomials\" with symbolic\n", - " | exponents. Thus, you should be able to apply polynomial algorithms to\n", - " | expressions for which this returns True, and Poly(expr, \\*syms) should\n", - " | work if and only if expr.is_polynomial(\\*syms) returns True. The\n", - " | polynomial does not have to be in expanded form. If no symbols are\n", - " | given, all free symbols in the expression will be used.\n", - " | \n", - " | This is not part of the assumptions system. You cannot do\n", - " | Symbol('z', polynomial=True).\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Symbol\n", - " | >>> x = Symbol('x')\n", - " | >>> ((x**2 + 1)**4).is_polynomial(x)\n", - " | True\n", - " | >>> ((x**2 + 1)**4).is_polynomial()\n", - " | True\n", - " | >>> (2**x + 1).is_polynomial(x)\n", - " | False\n", - " | \n", - " | \n", - " | >>> n = Symbol('n', nonnegative=True, integer=True)\n", - " | >>> (x**n + 1).is_polynomial(x)\n", - " | False\n", - " | \n", - " | This function does not attempt any nontrivial simplifications that may\n", - " | result in an expression that does not appear to be a polynomial to\n", - " | become one.\n", - " | \n", - " | >>> from sympy import sqrt, factor, cancel\n", - " | >>> y = Symbol('y', positive=True)\n", - " | >>> a = sqrt(y**2 + 2*y + 1)\n", - " | >>> a.is_polynomial(y)\n", - " | False\n", - " | >>> factor(a)\n", - " | y + 1\n", - " | >>> factor(a).is_polynomial(y)\n", - " | True\n", - " | \n", - " | >>> b = (y**2 + 2*y + 1)/(y + 1)\n", - " | >>> b.is_polynomial(y)\n", - " | False\n", - " | >>> cancel(b)\n", - " | y + 1\n", - " | >>> cancel(b).is_polynomial(y)\n", - " | True\n", - " | \n", - " | See also .is_rational_function()\n", - " | \n", - " | is_rational_function(self, *syms)\n", - " | Test whether function is a ratio of two polynomials in the given\n", - " | symbols, syms. When syms is not given, all free symbols will be used.\n", - " | The rational function does not have to be in expanded or in any kind of\n", - " | canonical form.\n", - " | \n", - " | This function returns False for expressions that are \"rational\n", - " | functions\" with symbolic exponents. Thus, you should be able to call\n", - " | .as_numer_denom() and apply polynomial algorithms to the result for\n", - " | expressions for which this returns True.\n", - " | \n", - " | This is not part of the assumptions system. You cannot do\n", - " | Symbol('z', rational_function=True).\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Symbol, sin\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> (x/y).is_rational_function()\n", - " | True\n", - " | \n", - " | >>> (x**2).is_rational_function()\n", - " | True\n", - " | \n", - " | >>> (x/sin(y)).is_rational_function(y)\n", - " | False\n", - " | \n", - " | >>> n = Symbol('n', integer=True)\n", - " | >>> (x**n + 1).is_rational_function(x)\n", - " | False\n", - " | \n", - " | This function does not attempt any nontrivial simplifications that may\n", - " | result in an expression that does not appear to be a rational function\n", - " | to become one.\n", - " | \n", - " | >>> from sympy import sqrt, factor\n", - " | >>> y = Symbol('y', positive=True)\n", - " | >>> a = sqrt(y**2 + 2*y + 1)/y\n", - " | >>> a.is_rational_function(y)\n", - " | False\n", - " | >>> factor(a)\n", - " | (y + 1)/y\n", - " | >>> factor(a).is_rational_function(y)\n", - " | True\n", - " | \n", - " | See also is_algebraic_expr().\n", - " | \n", - " | leadterm(self, x)\n", - " | Returns the leading term a*x**b as a tuple (a, b).\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x\n", - " | >>> (1+x+x**2).leadterm(x)\n", - " | (1, 0)\n", - " | >>> (1/x**2+x+x**2).leadterm(x)\n", - " | (1, -2)\n", - " | \n", - " | limit(self, x, xlim, dir='+')\n", - " | Compute limit x->xlim.\n", - " | \n", - " | lseries(self, x=None, x0=0, dir='+', logx=None)\n", - " | Wrapper for series yielding an iterator of the terms of the series.\n", - " | \n", - " | Note: an infinite series will yield an infinite iterator. The following,\n", - " | for exaxmple, will never terminate. It will just keep printing terms\n", - " | of the sin(x) series::\n", - " | \n", - " | for term in sin(x).lseries(x):\n", - " | print term\n", - " | \n", - " | The advantage of lseries() over nseries() is that many times you are\n", - " | just interested in the next term in the series (i.e. the first term for\n", - " | example), but you don't know how many you should ask for in nseries()\n", - " | using the \"n\" parameter.\n", - " | \n", - " | See also nseries().\n", - " | \n", - " | normal(self)\n", - " | \n", - " | nseries(self, x=None, x0=0, n=6, dir='+', logx=None)\n", - " | Wrapper to _eval_nseries if assumptions allow, else to series.\n", - " | \n", - " | If x is given, x0 is 0, dir='+', and self has x, then _eval_nseries is\n", - " | called. This calculates \"n\" terms in the innermost expressions and\n", - " | then builds up the final series just by \"cross-multiplying\" everything\n", - " | out.\n", - " | \n", - " | The optional ``logx`` parameter can be used to replace any log(x) in the\n", - " | returned series with a symbolic value to avoid evaluating log(x) at 0. A\n", - " | symbol to use in place of log(x) should be provided.\n", - " | \n", - " | Advantage -- it's fast, because we don't have to determine how many\n", - " | terms we need to calculate in advance.\n", - " | \n", - " | Disadvantage -- you may end up with less terms than you may have\n", - " | expected, but the O(x**n) term appended will always be correct and\n", - " | so the result, though perhaps shorter, will also be correct.\n", - " | \n", - " | If any of those assumptions is not met, this is treated like a\n", - " | wrapper to series which will try harder to return the correct\n", - " | number of terms.\n", - " | \n", - " | See also lseries().\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin, log, Symbol\n", - " | >>> from sympy.abc import x, y\n", - " | >>> sin(x).nseries(x, 0, 6)\n", - " | x - x**3/6 + x**5/120 + O(x**6)\n", - " | >>> log(x+1).nseries(x, 0, 5)\n", - " | x - x**2/2 + x**3/3 - x**4/4 + O(x**5)\n", - " | \n", - " | Handling of the ``logx`` parameter --- in the following example the\n", - " | expansion fails since ``sin`` does not have an asymptotic expansion\n", - " | at -oo (the limit of log(x) as x approaches 0):\n", - " | \n", - " | >>> e = sin(log(x))\n", - " | >>> e.nseries(x, 0, 6)\n", - " | Traceback (most recent call last):\n", - " | ...\n", - " | PoleError: ...\n", - " | ...\n", - " | >>> logx = Symbol('logx')\n", - " | >>> e.nseries(x, 0, 6, logx=logx)\n", - " | sin(logx)\n", - " | \n", - " | In the following example, the expansion works but gives only an Order term\n", - " | unless the ``logx`` parameter is used:\n", - " | \n", - " | >>> e = x**y\n", - " | >>> e.nseries(x, 0, 2)\n", - " | O(log(x)**2)\n", - " | >>> e.nseries(x, 0, 2, logx=logx)\n", - " | exp(logx*y)\n", - " | \n", - " | nsimplify(self, constants=[], tolerance=None, full=False)\n", - " | See the nsimplify function in sympy.simplify\n", - " | \n", - " | powsimp(self, *args, **kwargs)\n", - " | See the powsimp function in sympy.simplify\n", - " | \n", - " | primitive(self)\n", - " | Return the positive Rational that can be extracted non-recursively\n", - " | from every term of self (i.e., self is treated like an Add). This is\n", - " | like the as_coeff_Mul() method but primitive always extracts a positive\n", - " | Rational (never a negative or a Float).\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x\n", - " | >>> (3*(x + 1)**2).primitive()\n", - " | (3, (x + 1)**2)\n", - " | >>> a = (6*x + 2); a.primitive()\n", - " | (2, 3*x + 1)\n", - " | >>> b = (x/2 + 3); b.primitive()\n", - " | (1/2, x + 6)\n", - " | >>> (a*b).primitive() == (1, a*b)\n", - " | True\n", - " | \n", - " | radsimp(self, **kwargs)\n", - " | See the radsimp function in sympy.simplify\n", - " | \n", - " | ratsimp(self)\n", - " | See the ratsimp function in sympy.simplify\n", - " | \n", - " | refine(self, assumption=True)\n", - " | See the refine function in sympy.assumptions\n", - " | \n", - " | removeO(self)\n", - " | Removes the additive O(..) symbol if there is one\n", - " | \n", - " | round(self, n=None)\n", - " | Return x rounded to the given decimal place.\n", - " | \n", - " | If a complex number would results, apply round to the real\n", - " | and imaginary components of the number.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import pi, E, I, S, Add, Mul, Number\n", - " | >>> pi.round()\n", - " | 3\n", - " | >>> pi.round(2)\n", - " | 3.14\n", - " | >>> (2*pi + E*I).round()\n", - " | 6 + 3*I\n", - " | \n", - " | The round method has a chopping effect:\n", - " | \n", - " | >>> (2*pi + I/10).round()\n", - " | 6\n", - " | >>> (pi/10 + 2*I).round()\n", - " | 2*I\n", - " | >>> (pi/10 + E*I).round(2)\n", - " | 0.31 + 2.72*I\n", - " | \n", - " | Notes\n", - " | =====\n", - " | \n", - " | The Python ``round`` function uses the SymPy ``round`` method so it\n", - " | will always return a SymPy number (not a Python float or int):\n", - " | \n", - " | >>> isinstance(round(S(123), -2), Number)\n", - " | True\n", - " | \n", - " | separate(self, deep=False, force=False)\n", - " | See the separate function in sympy.simplify\n", - " | \n", - " | series(self, x=None, x0=0, n=6, dir='+', logx=None)\n", - " | Series expansion of \"self\" around ``x = x0`` yielding either terms of\n", - " | the series one by one (the lazy series given when n=None), else\n", - " | all the terms at once when n != None.\n", - " | \n", - " | Returns the series expansion of \"self\" around the point ``x = x0``\n", - " | with respect to ``x`` up to ``O((x - x0)**n, x, x0)`` (default n is 6).\n", - " | \n", - " | If ``x=None`` and ``self`` is univariate, the univariate symbol will\n", - " | be supplied, otherwise an error will be raised.\n", - " | \n", - " | Parameters\n", - " | ==========\n", - " | \n", - " | expr : Expression\n", - " | The expression whose series is to be expanded.\n", - " | \n", - " | x : Symbol\n", - " | It is the variable of the expression to be calculated.\n", - " | \n", - " | x0 : Value\n", - " | The value around which ``x`` is calculated. Can be any value\n", - " | from ``-oo`` to ``oo``.\n", - " | \n", - " | n : Value\n", - " | The number of terms upto which the series is to be expanded.\n", - " | \n", - " | dir : String, optional\n", - " | The series-expansion can be bi-directional. If ``dir=\"+\"``,\n", - " | then (x->x0+). If ``dir=\"-\", then (x->x0-). For infinite\n", - " | ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined\n", - " | from the direction of the infinity (i.e., ``dir=\"-\"`` for\n", - " | ``oo``).\n", - " | \n", - " | logx : optional\n", - " | It is used to replace any log(x) in the returned series with a\n", - " | symbolic value rather than evaluating the actual value.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import cos, exp, tan, oo, series\n", - " | >>> from sympy.abc import x, y\n", - " | >>> cos(x).series()\n", - " | 1 - x**2/2 + x**4/24 + O(x**6)\n", - " | >>> cos(x).series(n=4)\n", - " | 1 - x**2/2 + O(x**4)\n", - " | >>> cos(x).series(x, x0=1, n=2)\n", - " | cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))\n", - " | >>> e = cos(x + exp(y))\n", - " | >>> e.series(y, n=2)\n", - " | cos(x + 1) - y*sin(x + 1) + O(y**2)\n", - " | >>> e.series(x, n=2)\n", - " | cos(exp(y)) - x*sin(exp(y)) + O(x**2)\n", - " | \n", - " | If ``n=None`` then a generator of the series terms will be returned.\n", - " | \n", - " | >>> term=cos(x).series(n=None)\n", - " | >>> [next(term) for i in range(2)]\n", - " | [1, -x**2/2]\n", - " | \n", - " | For ``dir=+`` (default) the series is calculated from the right and\n", - " | for ``dir=-`` the series from the left. For smooth functions this\n", - " | flag will not alter the results.\n", - " | \n", - " | >>> abs(x).series(dir=\"+\")\n", - " | x\n", - " | >>> abs(x).series(dir=\"-\")\n", - " | -x\n", - " | >>> f = tan(x)\n", - " | >>> f.series(x, 2, 6, \"+\")\n", - " | tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +\n", - " | (x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +\n", - " | 5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +\n", - " | 2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))\n", - " | \n", - " | >>> f.series(x, 2, 3, \"-\")\n", - " | tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))\n", - " | + O((x - 2)**3, (x, 2))\n", - " | \n", - " | Returns\n", - " | =======\n", - " | \n", - " | Expr : Expression\n", - " | Series expansion of the expression about x0\n", - " | \n", - " | Raises\n", - " | ======\n", - " | \n", - " | TypeError\n", - " | If \"n\" and \"x0\" are infinity objects\n", - " | \n", - " | PoleError\n", - " | If \"x0\" is an infinity object\n", - " | \n", - " | sort_key(self, order=None)\n", - " | Return a sort key.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.core import S, I\n", - " | \n", - " | >>> sorted([S(1)/2, I, -I], key=lambda x: x.sort_key())\n", - " | [1/2, -I, I]\n", - " | \n", - " | >>> S(\"[x, 1/x, 1/x**2, x**2, x**(1/2), x**(1/4), x**(3/2)]\")\n", - " | [x, 1/x, x**(-2), x**2, sqrt(x), x**(1/4), x**(3/2)]\n", - " | >>> sorted(_, key=lambda x: x.sort_key())\n", - " | [x**(-2), 1/x, x**(1/4), sqrt(x), x, x**(3/2), x**2]\n", - " | \n", - " | taylor_term(self, n, x, *previous_terms)\n", - " | General method for the taylor term.\n", - " | \n", - " | This method is slow, because it differentiates n-times. Subclasses can\n", - " | redefine it to make it faster by using the \"previous_terms\".\n", - " | \n", - " | together(self, *args, **kwargs)\n", - " | See the together function in sympy.polys\n", - " | \n", - " | transpose(self)\n", - " | \n", - " | trigsimp(self, **args)\n", - " | See the trigsimp function in sympy.simplify\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Readonly properties inherited from sympy.core.expr.Expr:\n", - " | \n", - " | expr_free_symbols\n", - " | Like ``free_symbols``, but returns the free symbols only if they are contained in an expression node.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x, y\n", - " | >>> (x + y).expr_free_symbols\n", - " | {x, y}\n", - " | \n", - " | If the expression is contained in a non-expression object, don't return\n", - " | the free symbols. Compare:\n", - " | \n", - " | >>> from sympy import Tuple\n", - " | >>> t = Tuple(x + y)\n", - " | >>> t.expr_free_symbols\n", - " | set()\n", - " | >>> t.free_symbols\n", - " | {x, y}\n", - " | \n", - " | is_number\n", - " | Returns True if ``self`` has no free symbols and no\n", - " | undefined functions (AppliedUndef, to be precise). It will be\n", - " | faster than ``if not self.free_symbols``, however, since\n", - " | ``is_number`` will fail as soon as it hits a free symbol\n", - " | or undefined function.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import log, Integral, cos, sin, pi\n", - " | >>> from sympy.core.function import Function\n", - " | >>> from sympy.abc import x\n", - " | >>> f = Function('f')\n", - " | \n", - " | >>> x.is_number\n", - " | False\n", - " | >>> f(1).is_number\n", - " | False\n", - " | >>> (2*x).is_number\n", - " | False\n", - " | >>> (2 + Integral(2, x)).is_number\n", - " | False\n", - " | >>> (2 + Integral(2, (x, 1, 2))).is_number\n", - " | True\n", - " | \n", - " | Not all numbers are Numbers in the SymPy sense:\n", - " | \n", - " | >>> pi.is_number, pi.is_Number\n", - " | (True, False)\n", - " | \n", - " | If something is a number it should evaluate to a number with\n", - " | real and imaginary parts that are Numbers; the result may not\n", - " | be comparable, however, since the real and/or imaginary part\n", - " | of the result may not have precision.\n", - " | \n", - " | >>> cos(1).is_number and cos(1).is_comparable\n", - " | True\n", - " | \n", - " | >>> z = cos(1)**2 + sin(1)**2 - 1\n", - " | >>> z.is_number\n", - " | True\n", - " | >>> z.is_comparable\n", - " | False\n", - " | \n", - " | See Also\n", - " | ========\n", - " | sympy.core.basic.Basic.is_comparable\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Data and other attributes inherited from sympy.core.expr.Expr:\n", - " | \n", - " | is_scalar = True\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Methods inherited from sympy.core.operations.AssocOp:\n", - " | \n", - " | doit(self, **hints)\n", - " | Evaluate objects that are not evaluated by default like limits,\n", - " | integrals, sums and products. All objects of this kind will be\n", - " | evaluated recursively, unless some species were excluded via 'hints'\n", - " | or unless the 'deep' hint was set to 'False'.\n", - " | \n", - " | >>> from sympy import Integral\n", - " | >>> from sympy.abc import x\n", - " | \n", - " | >>> 2*Integral(x, x)\n", - " | 2*Integral(x, x)\n", - " | \n", - " | >>> (2*Integral(x, x)).doit()\n", - " | x**2\n", - " | \n", - " | >>> (2*Integral(x, x)).doit(deep=False)\n", - " | 2*Integral(x, x)\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Class methods inherited from sympy.core.operations.AssocOp:\n", - " | \n", - " | make_args(expr) from sympy.core.assumptions.ManagedProperties\n", - " | Return a sequence of elements `args` such that cls(*args) == expr\n", - " | \n", - " | >>> from sympy import Symbol, Mul, Add\n", - " | >>> x, y = map(Symbol, 'xy')\n", - " | \n", - " | >>> Mul.make_args(x*y)\n", - " | (x, y)\n", - " | >>> Add.make_args(x*y)\n", - " | (x*y,)\n", - " | >>> set(Add.make_args(x*y + y)) == set([y, x*y])\n", - " | True\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Static methods inherited from sympy.core.operations.AssocOp:\n", - " | \n", - " | __new__(cls, *args, **options)\n", - " | Create and return a new object. See help(type) for accurate signature.\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Data descriptors inherited from sympy.core.operations.AssocOp:\n", - " | \n", - " | is_commutative\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Methods inherited from sympy.core.basic.Basic:\n", - " | \n", - " | __getnewargs__(self)\n", - " | \n", - " | __getstate__(self)\n", - " | \n", - " | __ne__(self, other)\n", - " | ``a != b`` -> Compare two symbolic trees and see whether they are different\n", - " | \n", - " | this is the same as:\n", - " | \n", - " | ``a.compare(b) != 0``\n", - " | \n", - " | but faster\n", - " | \n", - " | __reduce_ex__(self, proto)\n", - " | Pickling support.\n", - " | \n", - " | __repr__(self)\n", - " | Method to return the string representation.\n", - " | \n", - " | Return the expression as a string.\n", - " | \n", - " | __setstate__(self, state)\n", - " | \n", - " | __str__(self)\n", - " | Return str(self).\n", - " | \n", - " | as_dummy(self)\n", - " | Return the expression with any objects having structurally\n", - " | bound symbols replaced with unique, canonical symbols within\n", - " | the object in which they appear and having only the default\n", - " | assumption for commutativity being True.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Integral, Symbol\n", - " | >>> from sympy.abc import x, y\n", - " | >>> r = Symbol('r', real=True)\n", - " | >>> Integral(r, (r, x)).as_dummy()\n", - " | Integral(_0, (_0, x))\n", - " | >>> _.variables[0].is_real is None\n", - " | True\n", - " | \n", - " | Notes\n", - " | =====\n", - " | \n", - " | Any object that has structural dummy variables should have\n", - " | a property, `bound_symbols` that returns a list of structural\n", - " | dummy symbols of the object itself.\n", - " | \n", - " | Lambda and Subs have bound symbols, but because of how they\n", - " | are cached, they already compare the same regardless of their\n", - " | bound symbols:\n", - " | \n", - " | >>> from sympy import Lambda\n", - " | >>> Lambda(x, x + 1) == Lambda(y, y + 1)\n", - " | True\n", - " | \n", - " | atoms(self, *types)\n", - " | Returns the atoms that form the current object.\n", - " | \n", - " | By default, only objects that are truly atomic and can't\n", - " | be divided into smaller pieces are returned: symbols, numbers,\n", - " | and number symbols like I and pi. It is possible to request\n", - " | atoms of any type, however, as demonstrated below.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import I, pi, sin\n", - " | >>> from sympy.abc import x, y\n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms()\n", - " | {1, 2, I, pi, x, y}\n", - " | \n", - " | If one or more types are given, the results will contain only\n", - " | those types of atoms.\n", - " | \n", - " | >>> from sympy import Number, NumberSymbol, Symbol\n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(Symbol)\n", - " | {x, y}\n", - " | \n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(Number)\n", - " | {1, 2}\n", - " | \n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol)\n", - " | {1, 2, pi}\n", - " | \n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol, I)\n", - " | {1, 2, I, pi}\n", - " | \n", - " | Note that I (imaginary unit) and zoo (complex infinity) are special\n", - " | types of number symbols and are not part of the NumberSymbol class.\n", - " | \n", - " | The type can be given implicitly, too:\n", - " | \n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(x) # x is a Symbol\n", - " | {x, y}\n", - " | \n", - " | Be careful to check your assumptions when using the implicit option\n", - " | since ``S(1).is_Integer = True`` but ``type(S(1))`` is ``One``, a special type\n", - " | of sympy atom, while ``type(S(2))`` is type ``Integer`` and will find all\n", - " | integers in an expression:\n", - " | \n", - " | >>> from sympy import S\n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(S(1))\n", - " | {1}\n", - " | \n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(S(2))\n", - " | {1, 2}\n", - " | \n", - " | Finally, arguments to atoms() can select more than atomic atoms: any\n", - " | sympy type (loaded in core/__init__.py) can be listed as an argument\n", - " | and those types of \"atoms\" as found in scanning the arguments of the\n", - " | expression recursively:\n", - " | \n", - " | >>> from sympy import Function, Mul\n", - " | >>> from sympy.core.function import AppliedUndef\n", - " | >>> f = Function('f')\n", - " | >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(Function)\n", - " | {f(x), sin(y + I*pi)}\n", - " | >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(AppliedUndef)\n", - " | {f(x)}\n", - " | \n", - " | >>> (1 + x + 2*sin(y + I*pi)).atoms(Mul)\n", - " | {I*pi, 2*sin(y + I*pi)}\n", - " | \n", - " | compare(self, other)\n", - " | Return -1, 0, 1 if the object is smaller, equal, or greater than other.\n", - " | \n", - " | Not in the mathematical sense. If the object is of a different type\n", - " | from the \"other\" then their classes are ordered according to\n", - " | the sorted_classes list.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x, y\n", - " | >>> x.compare(y)\n", - " | -1\n", - " | >>> x.compare(x)\n", - " | 0\n", - " | >>> y.compare(x)\n", - " | 1\n", - " | \n", - " | copy(self)\n", - " | \n", - " | count(self, query)\n", - " | Count the number of matching subexpressions.\n", - " | \n", - " | dummy_eq(self, other, symbol=None)\n", - " | Compare two expressions and handle dummy symbols.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Dummy\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> u = Dummy('u')\n", - " | \n", - " | >>> (u**2 + 1).dummy_eq(x**2 + 1)\n", - " | True\n", - " | >>> (u**2 + 1) == (x**2 + 1)\n", - " | False\n", - " | \n", - " | >>> (u**2 + y).dummy_eq(x**2 + y, x)\n", - " | True\n", - " | >>> (u**2 + y).dummy_eq(x**2 + y, y)\n", - " | False\n", - " | \n", - " | find(self, query, group=False)\n", - " | Find all subexpressions matching a query.\n", - " | \n", - " | has(self, *patterns)\n", - " | Test whether any subexpression matches any of the patterns.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin\n", - " | >>> from sympy.abc import x, y, z\n", - " | >>> (x**2 + sin(x*y)).has(z)\n", - " | False\n", - " | >>> (x**2 + sin(x*y)).has(x, y, z)\n", - " | True\n", - " | >>> x.has(x)\n", - " | True\n", - " | \n", - " | Note ``has`` is a structural algorithm with no knowledge of\n", - " | mathematics. Consider the following half-open interval:\n", - " | \n", - " | >>> from sympy.sets import Interval\n", - " | >>> i = Interval.Lopen(0, 5); i\n", - " | Interval.Lopen(0, 5)\n", - " | >>> i.args\n", - " | (0, 5, True, False)\n", - " | >>> i.has(4) # there is no \"4\" in the arguments\n", - " | False\n", - " | >>> i.has(0) # there *is* a \"0\" in the arguments\n", - " | True\n", - " | \n", - " | Instead, use ``contains`` to determine whether a number is in the\n", - " | interval or not:\n", - " | \n", - " | >>> i.contains(4)\n", - " | True\n", - " | >>> i.contains(0)\n", - " | False\n", - " | \n", - " | \n", - " | Note that ``expr.has(*patterns)`` is exactly equivalent to\n", - " | ``any(expr.has(p) for p in patterns)``. In particular, ``False`` is\n", - " | returned when the list of patterns is empty.\n", - " | \n", - " | >>> x.has()\n", - " | False\n", - " | \n", - " | is_hypergeometric(self, k)\n", - " | \n", - " | match(self, pattern, old=False)\n", - " | Pattern matching.\n", - " | \n", - " | Wild symbols match all.\n", - " | \n", - " | Return ``None`` when expression (self) does not match\n", - " | with pattern. Otherwise return a dictionary such that::\n", - " | \n", - " | pattern.xreplace(self.match(pattern)) == self\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Wild\n", - " | >>> from sympy.abc import x, y\n", - " | >>> p = Wild(\"p\")\n", - " | >>> q = Wild(\"q\")\n", - " | >>> r = Wild(\"r\")\n", - " | >>> e = (x+y)**(x+y)\n", - " | >>> e.match(p**p)\n", - " | {p_: x + y}\n", - " | >>> e.match(p**q)\n", - " | {p_: x + y, q_: x + y}\n", - " | >>> e = (2*x)**2\n", - " | >>> e.match(p*q**r)\n", - " | {p_: 4, q_: x, r_: 2}\n", - " | >>> (p*q**r).xreplace(e.match(p*q**r))\n", - " | 4*x**2\n", - " | \n", - " | The ``old`` flag will give the old-style pattern matching where\n", - " | expressions and patterns are essentially solved to give the\n", - " | match. Both of the following give None unless ``old=True``:\n", - " | \n", - " | >>> (x - 2).match(p - x, old=True)\n", - " | {p_: 2*x - 2}\n", - " | >>> (2/x).match(p*x, old=True)\n", - " | {p_: 2/x**2}\n", - " | \n", - " | rcall(self, *args)\n", - " | Apply on the argument recursively through the expression tree.\n", - " | \n", - " | This method is used to simulate a common abuse of notation for\n", - " | operators. For instance in SymPy the the following will not work:\n", - " | \n", - " | ``(x+Lambda(y, 2*y))(z) == x+2*z``,\n", - " | \n", - " | however you can use\n", - " | \n", - " | >>> from sympy import Lambda\n", - " | >>> from sympy.abc import x, y, z\n", - " | >>> (x + Lambda(y, 2*y)).rcall(z)\n", - " | x + 2*z\n", - " | \n", - " | replace(self, query, value, map=False, simultaneous=True, exact=None)\n", - " | Replace matching subexpressions of ``self`` with ``value``.\n", - " | \n", - " | If ``map = True`` then also return the mapping {old: new} where ``old``\n", - " | was a sub-expression found with query and ``new`` is the replacement\n", - " | value for it. If the expression itself doesn't match the query, then\n", - " | the returned value will be ``self.xreplace(map)`` otherwise it should\n", - " | be ``self.subs(ordered(map.items()))``.\n", - " | \n", - " | Traverses an expression tree and performs replacement of matching\n", - " | subexpressions from the bottom to the top of the tree. The default\n", - " | approach is to do the replacement in a simultaneous fashion so\n", - " | changes made are targeted only once. If this is not desired or causes\n", - " | problems, ``simultaneous`` can be set to False.\n", - " | \n", - " | In addition, if an expression containing more than one Wild symbol\n", - " | is being used to match subexpressions and the ``exact`` flag is None\n", - " | it will be set to True so the match will only succeed if all non-zero\n", - " | values are received for each Wild that appears in the match pattern.\n", - " | Setting this to False accepts a match of 0; while setting it True\n", - " | accepts all matches that have a 0 in them. See example below for\n", - " | cautions.\n", - " | \n", - " | The list of possible combinations of queries and replacement values\n", - " | is listed below:\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | Initial setup\n", - " | \n", - " | >>> from sympy import log, sin, cos, tan, Wild, Mul, Add\n", - " | >>> from sympy.abc import x, y\n", - " | >>> f = log(sin(x)) + tan(sin(x**2))\n", - " | \n", - " | 1.1. type -> type\n", - " | obj.replace(type, newtype)\n", - " | \n", - " | When object of type ``type`` is found, replace it with the\n", - " | result of passing its argument(s) to ``newtype``.\n", - " | \n", - " | >>> f.replace(sin, cos)\n", - " | log(cos(x)) + tan(cos(x**2))\n", - " | >>> sin(x).replace(sin, cos, map=True)\n", - " | (cos(x), {sin(x): cos(x)})\n", - " | >>> (x*y).replace(Mul, Add)\n", - " | x + y\n", - " | \n", - " | 1.2. type -> func\n", - " | obj.replace(type, func)\n", - " | \n", - " | When object of type ``type`` is found, apply ``func`` to its\n", - " | argument(s). ``func`` must be written to handle the number\n", - " | of arguments of ``type``.\n", - " | \n", - " | >>> f.replace(sin, lambda arg: sin(2*arg))\n", - " | log(sin(2*x)) + tan(sin(2*x**2))\n", - " | >>> (x*y).replace(Mul, lambda *args: sin(2*Mul(*args)))\n", - " | sin(2*x*y)\n", - " | \n", - " | 2.1. pattern -> expr\n", - " | obj.replace(pattern(wild), expr(wild))\n", - " | \n", - " | Replace subexpressions matching ``pattern`` with the expression\n", - " | written in terms of the Wild symbols in ``pattern``.\n", - " | \n", - " | >>> a, b = map(Wild, 'ab')\n", - " | >>> f.replace(sin(a), tan(a))\n", - " | log(tan(x)) + tan(tan(x**2))\n", - " | >>> f.replace(sin(a), tan(a/2))\n", - " | log(tan(x/2)) + tan(tan(x**2/2))\n", - " | >>> f.replace(sin(a), a)\n", - " | log(x) + tan(x**2)\n", - " | >>> (x*y).replace(a*x, a)\n", - " | y\n", - " | \n", - " | Matching is exact by default when more than one Wild symbol\n", - " | is used: matching fails unless the match gives non-zero\n", - " | values for all Wild symbols:\n", - " | \n", - " | >>> (2*x + y).replace(a*x + b, b - a)\n", - " | y - 2\n", - " | >>> (2*x).replace(a*x + b, b - a)\n", - " | 2*x\n", - " | \n", - " | When set to False, the results may be non-intuitive:\n", - " | \n", - " | >>> (2*x).replace(a*x + b, b - a, exact=False)\n", - " | 2/x\n", - " | \n", - " | 2.2. pattern -> func\n", - " | obj.replace(pattern(wild), lambda wild: expr(wild))\n", - " | \n", - " | All behavior is the same as in 2.1 but now a function in terms of\n", - " | pattern variables is used rather than an expression:\n", - " | \n", - " | >>> f.replace(sin(a), lambda a: sin(2*a))\n", - " | log(sin(2*x)) + tan(sin(2*x**2))\n", - " | \n", - " | 3.1. func -> func\n", - " | obj.replace(filter, func)\n", - " | \n", - " | Replace subexpression ``e`` with ``func(e)`` if ``filter(e)``\n", - " | is True.\n", - " | \n", - " | >>> g = 2*sin(x**3)\n", - " | >>> g.replace(lambda expr: expr.is_Number, lambda expr: expr**2)\n", - " | 4*sin(x**9)\n", - " | \n", - " | The expression itself is also targeted by the query but is done in\n", - " | such a fashion that changes are not made twice.\n", - " | \n", - " | >>> e = x*(x*y + 1)\n", - " | >>> e.replace(lambda x: x.is_Mul, lambda x: 2*x)\n", - " | 2*x*(2*x*y + 1)\n", - " | \n", - " | When matching a single symbol, `exact` will default to True, but\n", - " | this may or may not be the behavior that is desired:\n", - " | \n", - " | Here, we want `exact=False`:\n", - " | \n", - " | >>> from sympy import Function\n", - " | >>> f = Function('f')\n", - " | >>> e = f(1) + f(0)\n", - " | >>> q = f(a), lambda a: f(a + 1)\n", - " | >>> e.replace(*q, exact=False)\n", - " | f(1) + f(2)\n", - " | >>> e.replace(*q, exact=True)\n", - " | f(0) + f(2)\n", - " | \n", - " | But here, the nature of matching makes selecting\n", - " | the right setting tricky:\n", - " | \n", - " | >>> e = x**(1 + y)\n", - " | >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=False)\n", - " | 1\n", - " | >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=True)\n", - " | x**(-x - y + 1)\n", - " | >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=False)\n", - " | 1\n", - " | >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=True)\n", - " | x**(1 - y)\n", - " | \n", - " | It is probably better to use a different form of the query\n", - " | that describes the target expression more precisely:\n", - " | \n", - " | >>> (1 + x**(1 + y)).replace(\n", - " | ... lambda x: x.is_Pow and x.exp.is_Add and x.exp.args[0] == 1,\n", - " | ... lambda x: x.base**(1 - (x.exp - 1)))\n", - " | ...\n", - " | x**(1 - y) + 1\n", - " | \n", - " | See Also\n", - " | ========\n", - " | \n", - " | subs: substitution of subexpressions as defined by the objects\n", - " | themselves.\n", - " | xreplace: exact node replacement in expr tree; also capable of\n", - " | using matching rules\n", - " | \n", - " | rewrite(self, *args, **hints)\n", - " | Rewrite functions in terms of other functions.\n", - " | \n", - " | Rewrites expression containing applications of functions\n", - " | of one kind in terms of functions of different kind. For\n", - " | example you can rewrite trigonometric functions as complex\n", - " | exponentials or combinatorial functions as gamma function.\n", - " | \n", - " | As a pattern this function accepts a list of functions to\n", - " | to rewrite (instances of DefinedFunction class). As rule\n", - " | you can use string or a destination function instance (in\n", - " | this case rewrite() will use the str() function).\n", - " | \n", - " | There is also the possibility to pass hints on how to rewrite\n", - " | the given expressions. For now there is only one such hint\n", - " | defined called 'deep'. When 'deep' is set to False it will\n", - " | forbid functions to rewrite their contents.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import sin, exp\n", - " | >>> from sympy.abc import x\n", - " | \n", - " | Unspecified pattern:\n", - " | \n", - " | >>> sin(x).rewrite(exp)\n", - " | -I*(exp(I*x) - exp(-I*x))/2\n", - " | \n", - " | Pattern as a single function:\n", - " | \n", - " | >>> sin(x).rewrite(sin, exp)\n", - " | -I*(exp(I*x) - exp(-I*x))/2\n", - " | \n", - " | Pattern as a list of functions:\n", - " | \n", - " | >>> sin(x).rewrite([sin, ], exp)\n", - " | -I*(exp(I*x) - exp(-I*x))/2\n", - " | \n", - " | simplify(self, **kwargs)\n", - " | See the simplify function in sympy.simplify\n", - " | \n", - " | subs(self, *args, **kwargs)\n", - " | Substitutes old for new in an expression after sympifying args.\n", - " | \n", - " | `args` is either:\n", - " | - two arguments, e.g. foo.subs(old, new)\n", - " | - one iterable argument, e.g. foo.subs(iterable). The iterable may be\n", - " | o an iterable container with (old, new) pairs. In this case the\n", - " | replacements are processed in the order given with successive\n", - " | patterns possibly affecting replacements already made.\n", - " | o a dict or set whose key/value items correspond to old/new pairs.\n", - " | In this case the old/new pairs will be sorted by op count and in\n", - " | case of a tie, by number of args and the default_sort_key. The\n", - " | resulting sorted list is then processed as an iterable container\n", - " | (see previous).\n", - " | \n", - " | If the keyword ``simultaneous`` is True, the subexpressions will not be\n", - " | evaluated until all the substitutions have been made.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import pi, exp, limit, oo\n", - " | >>> from sympy.abc import x, y\n", - " | >>> (1 + x*y).subs(x, pi)\n", - " | pi*y + 1\n", - " | >>> (1 + x*y).subs({x:pi, y:2})\n", - " | 1 + 2*pi\n", - " | >>> (1 + x*y).subs([(x, pi), (y, 2)])\n", - " | 1 + 2*pi\n", - " | >>> reps = [(y, x**2), (x, 2)]\n", - " | >>> (x + y).subs(reps)\n", - " | 6\n", - " | >>> (x + y).subs(reversed(reps))\n", - " | x**2 + 2\n", - " | \n", - " | >>> (x**2 + x**4).subs(x**2, y)\n", - " | y**2 + y\n", - " | \n", - " | To replace only the x**2 but not the x**4, use xreplace:\n", - " | \n", - " | >>> (x**2 + x**4).xreplace({x**2: y})\n", - " | x**4 + y\n", - " | \n", - " | To delay evaluation until all substitutions have been made,\n", - " | set the keyword ``simultaneous`` to True:\n", - " | \n", - " | >>> (x/y).subs([(x, 0), (y, 0)])\n", - " | 0\n", - " | >>> (x/y).subs([(x, 0), (y, 0)], simultaneous=True)\n", - " | nan\n", - " | \n", - " | This has the added feature of not allowing subsequent substitutions\n", - " | to affect those already made:\n", - " | \n", - " | >>> ((x + y)/y).subs({x + y: y, y: x + y})\n", - " | 1\n", - " | >>> ((x + y)/y).subs({x + y: y, y: x + y}, simultaneous=True)\n", - " | y/(x + y)\n", - " | \n", - " | In order to obtain a canonical result, unordered iterables are\n", - " | sorted by count_op length, number of arguments and by the\n", - " | default_sort_key to break any ties. All other iterables are left\n", - " | unsorted.\n", - " | \n", - " | >>> from sympy import sqrt, sin, cos\n", - " | >>> from sympy.abc import a, b, c, d, e\n", - " | \n", - " | >>> A = (sqrt(sin(2*x)), a)\n", - " | >>> B = (sin(2*x), b)\n", - " | >>> C = (cos(2*x), c)\n", - " | >>> D = (x, d)\n", - " | >>> E = (exp(x), e)\n", - " | \n", - " | >>> expr = sqrt(sin(2*x))*sin(exp(x)*x)*cos(2*x) + sin(2*x)\n", - " | \n", - " | >>> expr.subs(dict([A, B, C, D, E]))\n", - " | a*c*sin(d*e) + b\n", - " | \n", - " | The resulting expression represents a literal replacement of the\n", - " | old arguments with the new arguments. This may not reflect the\n", - " | limiting behavior of the expression:\n", - " | \n", - " | >>> (x**3 - 3*x).subs({x: oo})\n", - " | nan\n", - " | \n", - " | >>> limit(x**3 - 3*x, x, oo)\n", - " | oo\n", - " | \n", - " | If the substitution will be followed by numerical\n", - " | evaluation, it is better to pass the substitution to\n", - " | evalf as\n", - " | \n", - " | >>> (1/x).evalf(subs={x: 3.0}, n=21)\n", - " | 0.333333333333333333333\n", - " | \n", - " | rather than\n", - " | \n", - " | >>> (1/x).subs({x: 3.0}).evalf(21)\n", - " | 0.333333333333333314830\n", - " | \n", - " | as the former will ensure that the desired level of precision is\n", - " | obtained.\n", - " | \n", - " | See Also\n", - " | ========\n", - " | replace: replacement capable of doing wildcard-like matching,\n", - " | parsing of match, and conditional replacements\n", - " | xreplace: exact node replacement in expr tree; also capable of\n", - " | using matching rules\n", - " | sympy.core.evalf.EvalfMixin.evalf: calculates the given formula to a desired level of precision\n", - " | \n", - " | xreplace(self, rule)\n", - " | Replace occurrences of objects within the expression.\n", - " | \n", - " | Parameters\n", - " | ==========\n", - " | \n", - " | rule : dict-like\n", - " | Expresses a replacement rule\n", - " | \n", - " | Returns\n", - " | =======\n", - " | \n", - " | xreplace : the result of the replacement\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import symbols, pi, exp\n", - " | >>> x, y, z = symbols('x y z')\n", - " | >>> (1 + x*y).xreplace({x: pi})\n", - " | pi*y + 1\n", - " | >>> (1 + x*y).xreplace({x: pi, y: 2})\n", - " | 1 + 2*pi\n", - " | \n", - " | Replacements occur only if an entire node in the expression tree is\n", - " | matched:\n", - " | \n", - " | >>> (x*y + z).xreplace({x*y: pi})\n", - " | z + pi\n", - " | >>> (x*y*z).xreplace({x*y: pi})\n", - " | x*y*z\n", - " | >>> (2*x).xreplace({2*x: y, x: z})\n", - " | y\n", - " | >>> (2*2*x).xreplace({2*x: y, x: z})\n", - " | 4*z\n", - " | >>> (x + y + 2).xreplace({x + y: 2})\n", - " | x + y + 2\n", - " | >>> (x + 2 + exp(x + 2)).xreplace({x + 2: y})\n", - " | x + exp(y) + 2\n", - " | \n", - " | xreplace doesn't differentiate between free and bound symbols. In the\n", - " | following, subs(x, y) would not change x since it is a bound symbol,\n", - " | but xreplace does:\n", - " | \n", - " | >>> from sympy import Integral\n", - " | >>> Integral(x, (x, 1, 2*x)).xreplace({x: y})\n", - " | Integral(y, (y, 1, 2*y))\n", - " | \n", - " | Trying to replace x with an expression raises an error:\n", - " | \n", - " | >>> Integral(x, (x, 1, 2*x)).xreplace({x: 2*y}) # doctest: +SKIP\n", - " | ValueError: Invalid limits given: ((2*y, 1, 4*y),)\n", - " | \n", - " | See Also\n", - " | ========\n", - " | replace: replacement capable of doing wildcard-like matching,\n", - " | parsing of match, and conditional replacements\n", - " | subs: substitution of subexpressions as defined by the objects\n", - " | themselves.\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Class methods inherited from sympy.core.basic.Basic:\n", - " | \n", - " | fromiter(args, **assumptions) from sympy.core.assumptions.ManagedProperties\n", - " | Create a new object from an iterable.\n", - " | \n", - " | This is a convenience function that allows one to create objects from\n", - " | any iterable, without having to convert to a list or tuple first.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Tuple\n", - " | >>> Tuple.fromiter(i for i in range(5))\n", - " | (0, 1, 2, 3, 4)\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Readonly properties inherited from sympy.core.basic.Basic:\n", - " | \n", - " | args\n", - " | Returns a tuple of arguments of 'self'.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import cot\n", - " | >>> from sympy.abc import x, y\n", - " | \n", - " | >>> cot(x).args\n", - " | (x,)\n", - " | \n", - " | >>> cot(x).args[0]\n", - " | x\n", - " | \n", - " | >>> (x*y).args\n", - " | (x, y)\n", - " | \n", - " | >>> (x*y).args[1]\n", - " | y\n", - " | \n", - " | Notes\n", - " | =====\n", - " | \n", - " | Never use self._args, always use self.args.\n", - " | Only use _args in __new__ when creating a new function.\n", - " | Don't override .args() from Basic (so that it's easy to\n", - " | change the interface in the future if needed).\n", - " | \n", - " | assumptions0\n", - " | Return object `type` assumptions.\n", - " | \n", - " | For example:\n", - " | \n", - " | Symbol('x', real=True)\n", - " | Symbol('x', integer=True)\n", - " | \n", - " | are different objects. In other words, besides Python type (Symbol in\n", - " | this case), the initial assumptions are also forming their typeinfo.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Symbol\n", - " | >>> from sympy.abc import x\n", - " | >>> x.assumptions0\n", - " | {'commutative': True}\n", - " | >>> x = Symbol(\"x\", positive=True)\n", - " | >>> x.assumptions0\n", - " | {'commutative': True, 'complex': True, 'extended_negative': False,\n", - " | 'extended_nonnegative': True, 'extended_nonpositive': False,\n", - " | 'extended_nonzero': True, 'extended_positive': True, 'extended_real':\n", - " | True, 'finite': True, 'hermitian': True, 'imaginary': False,\n", - " | 'infinite': False, 'negative': False, 'nonnegative': True,\n", - " | 'nonpositive': False, 'nonzero': True, 'positive': True, 'real':\n", - " | True, 'zero': False}\n", - " | \n", - " | canonical_variables\n", - " | Return a dictionary mapping any variable defined in\n", - " | ``self.bound_symbols`` to Symbols that do not clash\n", - " | with any existing symbol in the expression.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import Lambda\n", - " | >>> from sympy.abc import x\n", - " | >>> Lambda(x, 2*x).canonical_variables\n", - " | {x: _0}\n", - " | \n", - " | free_symbols\n", - " | Return from the atoms of self those which are free symbols.\n", - " | \n", - " | For most expressions, all symbols are free symbols. For some classes\n", - " | this is not true. e.g. Integrals use Symbols for the dummy variables\n", - " | which are bound variables, so Integral has a method to return all\n", - " | symbols except those. Derivative keeps track of symbols with respect\n", - " | to which it will perform a derivative; those are\n", - " | bound variables, too, so it has its own free_symbols method.\n", - " | \n", - " | Any other method that uses bound variables should implement a\n", - " | free_symbols method.\n", - " | \n", - " | func\n", - " | The top-level function in an expression.\n", - " | \n", - " | The following should hold for all objects::\n", - " | \n", - " | >> x == x.func(*x.args)\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy.abc import x\n", - " | >>> a = 2*x\n", - " | >>> a.func\n", - " | \n", - " | >>> a.args\n", - " | (2, x)\n", - " | >>> a.func(*a.args)\n", - " | 2*x\n", - " | >>> a == a.func(*a.args)\n", - " | True\n", - " | \n", - " | is_algebraic\n", - " | \n", - " | is_antihermitian\n", - " | \n", - " | is_comparable\n", - " | Return True if self can be computed to a real number\n", - " | (or already is a real number) with precision, else False.\n", - " | \n", - " | Examples\n", - " | ========\n", - " | \n", - " | >>> from sympy import exp_polar, pi, I\n", - " | >>> (I*exp_polar(I*pi/2)).is_comparable\n", - " | True\n", - " | >>> (I*exp_polar(I*pi*2)).is_comparable\n", - " | False\n", - " | \n", - " | A False result does not mean that `self` cannot be rewritten\n", - " | into a form that would be comparable. For example, the\n", - " | difference computed below is zero but without simplification\n", - " | it does not evaluate to a zero with precision:\n", - " | \n", - " | >>> e = 2**pi*(1 + 2**pi)\n", - " | >>> dif = e - e.expand()\n", - " | >>> dif.is_comparable\n", - " | False\n", - " | >>> dif.n(2)._prec\n", - " | 1\n", - " | \n", - " | is_complex\n", - " | \n", - " | is_composite\n", - " | \n", - " | is_even\n", - " | \n", - " | is_extended_negative\n", - " | \n", - " | is_extended_nonnegative\n", - " | \n", - " | is_extended_nonpositive\n", - " | \n", - " | is_extended_nonzero\n", - " | \n", - " | is_extended_positive\n", - " | \n", - " | is_extended_real\n", - " | \n", - " | is_finite\n", - " | \n", - " | is_hermitian\n", - " | \n", - " | is_imaginary\n", - " | \n", - " | is_infinite\n", - " | \n", - " | is_integer\n", - " | \n", - " | is_irrational\n", - " | \n", - " | is_negative\n", - " | \n", - " | is_noninteger\n", - " | \n", - " | is_nonnegative\n", - " | \n", - " | is_nonpositive\n", - " | \n", - " | is_nonzero\n", - " | \n", - " | is_odd\n", - " | \n", - " | is_polar\n", - " | \n", - " | is_positive\n", - " | \n", - " | is_prime\n", - " | \n", - " | is_rational\n", - " | \n", - " | is_real\n", - " | \n", - " | is_transcendental\n", - " | \n", - " | is_zero\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Data and other attributes inherited from sympy.core.basic.Basic:\n", - " | \n", - " | is_Add = False\n", - " | \n", - " | is_AlgebraicNumber = False\n", - " | \n", - " | is_Atom = False\n", - " | \n", - " | is_Boolean = False\n", - " | \n", - " | is_Derivative = False\n", - " | \n", - " | is_Dummy = False\n", - " | \n", - " | is_Equality = False\n", - " | \n", - " | is_Float = False\n", - " | \n", - " | is_Function = False\n", - " | \n", - " | is_Indexed = False\n", - " | \n", - " | is_Integer = False\n", - " | \n", - " | is_MatAdd = False\n", - " | \n", - " | is_MatMul = False\n", - " | \n", - " | is_Matrix = False\n", - " | \n", - " | is_Not = False\n", - " | \n", - " | is_Number = False\n", - " | \n", - " | is_NumberSymbol = False\n", - " | \n", - " | is_Order = False\n", - " | \n", - " | is_Piecewise = False\n", - " | \n", - " | is_Point = False\n", - " | \n", - " | is_Poly = False\n", - " | \n", - " | is_Pow = False\n", - " | \n", - " | is_Rational = False\n", - " | \n", - " | is_Relational = False\n", - " | \n", - " | is_Symbol = False\n", - " | \n", - " | is_Vector = False\n", - " | \n", - " | is_Wild = False\n", - " | \n", - " | is_symbol = False\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Methods inherited from sympy.core.evalf.EvalfMixin:\n", - " | \n", - " | evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)\n", - " | Evaluate the given formula to an accuracy of *n* digits.\n", - " | \n", - " | Parameters\n", - " | ==========\n", - " | \n", - " | subs : dict, optional\n", - " | Substitute numerical values for symbols, e.g.\n", - " | ``subs={x:3, y:1+pi}``. The substitutions must be given as a\n", - " | dictionary.\n", - " | \n", - " | maxn : int, optional\n", - " | Allow a maximum temporary working precision of maxn digits.\n", - " | \n", - " | chop : bool or number, optional\n", - " | Specifies how to replace tiny real or imaginary parts in\n", - " | subresults by exact zeros.\n", - " | \n", - " | When ``True`` the chop value defaults to standard precision.\n", - " | \n", - " | Otherwise the chop value is used to determine the\n", - " | magnitude of \"small\" for purposes of chopping.\n", - " | \n", - " | >>> from sympy import N\n", - " | >>> x = 1e-4\n", - " | >>> N(x, chop=True)\n", - " | 0.000100000000000000\n", - " | >>> N(x, chop=1e-5)\n", - " | 0.000100000000000000\n", - " | >>> N(x, chop=1e-4)\n", - " | 0\n", - " | \n", - " | strict : bool, optional\n", - " | Raise ``PrecisionExhausted`` if any subresult fails to\n", - " | evaluate to full accuracy, given the available maxprec.\n", - " | \n", - " | quad : str, optional\n", - " | Choose algorithm for numerical quadrature. By default,\n", - " | tanh-sinh quadrature is used. For oscillatory\n", - " | integrals on an infinite interval, try ``quad='osc'``.\n", - " | \n", - " | verbose : bool, optional\n", - " | Print debug information.\n", - " | \n", - " | Notes\n", - " | =====\n", - " | \n", - " | When Floats are naively substituted into an expression,\n", - " | precision errors may adversely affect the result. For example,\n", - " | adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is\n", - " | then subtracted, the result will be 0.\n", - " | That is exactly what happens in the following:\n", - " | \n", - " | >>> from sympy.abc import x, y, z\n", - " | >>> values = {x: 1e16, y: 1, z: 1e16}\n", - " | >>> (x + y - z).subs(values)\n", - " | 0\n", - " | \n", - " | Using the subs argument for evalf is the accurate way to\n", - " | evaluate such an expression:\n", - " | \n", - " | >>> (x + y - z).evalf(subs=values)\n", - " | 1.00000000000000\n", - " | \n", - " | n = evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)\n", - "\n" - ] - } - ], - "source": [ - "help(sym.sqrt(8))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can do symbolic math not just on numbers, but we can tell SymPy what to treat as a symbol, using `symbols()`" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "from sympy import symbols\n", - "x, y, z = sym.symbols(\"x y z\")" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAADoAAAASCAYAAAAKRM1zAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACmElEQVRYCc2W3U1bQRBGDXIBiBKgAxI6MB0EUgGhg0R581tEOgBKgA6gAwIdhA6C3IFzzrKzGjuX6MryNYw03rmzs7vz7fyst+bz+ei90nQ63cO3b9W/j4zPfqN/rLrew9Z7BVpBXjAeBRrkc+Sv8BHyXej7jNt9jFa1wZkJ/GXF9YI6y2vZy+jO4Ous7yMPChQHdir38WXZZoLiN+DcI5OR3EFvWvemoYH2dqTDUEBPADKCXbR8AV02TTcOqd5cpNkh+lPYW/tcbe6xuany4ANnHb9yyIF65ktDYhSwfu/DD3xfMhaqc1eMxzmi5yh+yljdw1ewNWZduJk186aEL4L08qMT68/36vMt8rKPJ+g+aVQiiqE3ko1MFw2MqrQL5/mifIMfm9BNBTZiFLhBkezOPj+Z1JXuHKn7i0VPyeID8iM6Abvha2lUljB/gWDzWCYvyPUL3bMauf9/982b1TOs2bzG73hTjd6PvAZZn4ouIhrGYde1KOb+GTmsC8gIvVmxx2g5rEysN+N2GY1QI74jEAKyvHJ9Gm11JaK5RtGV249FrfGwoe3cRRsnzvWy9hlbJJG9PGs1yLmWgVUpjhl2JYhjBAGY+zYj0RsdDXIqW/C5AWAyPHGmUTnsOFvwLXrIgs7+8llqtkTTD1NX5LL/IQW9UNDonIuCR9wMca7OG4A7ZHtApgm6XA6CLP1AI+YCUyupMXpReztOanQG38Ju/gA/I7c01mZD5HMh2Hjb87HLPcVs8730ZfgD+6ZKLaKD/qnn4LU0oxef+/9WwEbd16PQdggDjTP2lQcjQcFmXiFky88sKM/Ki7b+YYiPdY8c2lJn3Xun/cyaXMP+o7vk7IVyGzR1kzODiQASqI3ISFqb110X/BfFu+8OLJ96AQAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle x + 2 y$" - ], - "text/plain": [ - "x + 2⋅y" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = x + 2*y\n", - "expr" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF0AAAASCAYAAAA5f9J6AAAACXBIWXMAAA7EAAAOxAGVKw4bAAADFklEQVRYCc2Y7VEbMRCGDeMCGNIBdBBCB6SDQCpIKCGTf/6XIR0AFTDQgUkFfHQQOojHHTjPo0ga+eZwjoP72Jm11nvS7avVq5XsrdVqNRmrzGazPbB9i/g+0C78jv8x+kbfgPU9IK/RA+ylgKd+jFFiws9pPyZ82GfYD/rQ2+QfWwu2HTBdopJEskieLNvZ6sAg+BH6teWrTfBpOZZ3yXrZInNGK+Bcoseo+K+qQDtNOsFccbWNHDHoN8Cr42X4Dv419rQJMNSYrpP+mnmZ3CeSK7PrpLoYdX1G6cs1PTIqlYJD0H5BZdPniPyOPjfR7rwh1vEzQTyYJjwPhymtyRf3Pmq9v6ANEp9d0j73rtS117Zk+hngfqoguEM9CKzJ1lEnZo0dVMBiwiVCutGI53vEPMeuYjzB98lOY5LAdEDLlBKwW1qwsl3ZRcvnwTnAhwfoTUzyhNZFkCCKtxxvC6XoG90tJ5WXeybwVKA9wH7EZ/Kd3MbtyfNzunnwVcXFcvzaLSR28v0b31u+LMawxpdj/J7u7LL6RzkGW0xV31oXxruLf6G2TcWbSYrbdEzul5hefUHdBPKgqgGAuqRO8Ltb9mgtWa2F8e7EXVqZm4XviRQm16SV9dxdoG8j0+M7JFlvUtb0EBQQaQL50MTnFe0lTHizCRDXhdunzQzHdiGt7Ul8lndmdDoP78tVQqUxg7VTQJlMa6UHqayQtYIty42HVXl40aV7IaZsPayJ7UJkVmO7ACVevoYav5HldhpCLC8yQvU/DRdggWbB57N0WGV/1wZxTaRkuMX2zCjFW1VZskx4OD/sxLM0p9qyV76oB/tdjCG+pfYUlQ2yRqACPkXnqBN9QBfYudTYpyfxCmji02+HMmy1ZLgLvY97w/qDemdXBmM6WCSMEvJKe41Pcsy3uvyXkSBvcpCK/CUSk+9u6PWAbIpxu2nHlv3cTmFLtRz/32EmGHVHBsG2RLo7Nl4V//Ue5tPy0pmQgD62t7uprPn+kr4g9hAlsVEuOy0vjRC8shPJNekeUjLcWm7t7GOxCdVO/gKZaQwpNNj88AAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle x + 2 y - 1$" - ], - "text/plain": [ - "x + 2⋅y - 1" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr - 1" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB4klEQVRIDb2W7VECQQyGD4cCGEvADnTs4OxAtAKlBMd//HOwA6EE7AA6QCiBDmToAN9nJ1n2jmNGGfcyk8tekt0km4+7zn6/L3LBaDQqdXZfdJLLxkWug+3cniiYDXIHkM1xP7jrC6WZm3q291vRJ2Ff+Gi8pXQ+bZ2dJP5cydgqLUOTTUUHaQbGYryD2rAUToWl3l9ECW4sbBNezZe5jNZtP4h3jzMhA1Lk5lOlnSmQBeBSmMoDM9dD/lzrbC4RuBNuw+rwgLfg1UvoS5s2B3lxo/VaPAIpRAeJ7Ggp+YeYTJw6EDj7h3WB3jn/1Lkbyda2h9t+q+3HVuB5BlzZ9Zo2ueyInnCwEJ80M0Ypy1+D9P3icJTyjWNYMrIDL2Qg7QHxwm35ptiw2tQDg0K7DzIUK8FM499O/oRL75pjMzFpYqIi3SikJUVD0cxtA1Mw9QP7sf55IQNEBG4tmErDiIfMG0rLVqHivPmCP0ymAF09uXVqDEEhpaFwLqQxV0ICi+WETotA1pn3TMBvId8EINQ/i07mf6GzmhjHmsACKUWZkgGOmtgF/0SZJuCfAWeFVEAArRkifK8qI5USygYyGlN9hhGyRxk78Gcw0ZmVcs5aQm75HCpHCYAPITdP7c+aLuQHuSioeUeu1ZIAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle x + y$" - ], - "text/plain": [ - "x + y" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr - y" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAVCAYAAADCUymGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD3klEQVRYCd2Y0VEbMRCGL4wL8FCC6YCECmJ3QEgFCR04kyf8xjgdABVkQgeQCojpwO4gHndA/k8naWRZd8Hn9RCyM3uSVtKvvdXuSnfV09NTZc0XFxcDa8zXgFd674PKmCaTyViQx8awrwVu4N8/6vsGz7AigZ8K60TlFyvMfeJIz4Hwg67vVF/Slvyx67qai4OtVF6DYWZgAfaF91PlW4D/dZKeGPdK5SjoqvpUdQw0Uv0+yLctNXemOe9VrixTBMpdbavMLuP1AkPx544Y6HuezhUW3rwS/0jlHerYAfzK0sBnUtCFRQeFuk4hauAuNNSkuXTO5+O5fcnx8E7k7YA9+iYGFhC5d9FJm5ebhCEX0h2PLVFu+NKYNhn2OOuFEVhb9RBuJ6p/ErOLH8XQg8bc1tWNJ3msMWftiL2xmIVAOn1owHE3IPW7gy7R/UjjZ2rHKPV9NypLWNhjlHrwVAO/wep4EN+IyXHkJYzvcorKEnECz0sdXrYLdgusbZfeFePiVOFmwQJfvU3uVM9tcCYZ0Vsi7DFwHiwAPDedTNgwES+GDsVpvxMmDzaAK84GGWBvYO5RwOF26w1aqcTgOBtElObv2Ba5jK0NrMovgaU5lKvWo2QYmoVKIUBXIDbAjQ2CpNwVm/U5lTmUcmJd+tduA34Q+v9N74jn1yAnp3Nou1ShgXjrZZxQV9Apl4Uh2LMfPDiAhM4SWOjbqkwUDPO2xhZGyYCV5EQZX0+ktc6k+UTwoUo8MpLawcEwJFGa5l+8G1nT2eOcLs3BGuu8IYDFA00LcW0BrIkIh7Z+N08YXbCb1jSRSyc26Uhl9FzV2TRycSD6YkR7Ie/CF1vunGEO9lj2NIAKuYeDiN3AW5iYpgwSfZr4NWSNGJsq5DqNsNcWsmxIP7yw9GmP0aO3qs67pfZQ0+XkJu+lHw9e9PRgJ2C+wZ3VVY8kGX0h0Ud5VmEXTzIZTQvsAuzuIr0XRsOx7lXPv0CHkqVpB+NiMEfeJrxbMXX5Ye4c66nBLrBbTKg0+Vx8J2ZRvqmXqsd0wZgCfZcMZXOywM4xrdpcuzByuPunuHnYE73cd7lJ/RZzJ4baPLjeAKv/rPoXOhcfW+E9B0frnYrHzxlrOUZrTsWzJkz1DcRz+g/qjTB5srttIWOySAayUhveG+G1YiLZkeqkUbz+spYUn3i8+24wM7AWJs3kp29xdSuh1iR/poeRFXSKw4FHCgzEF+611i2mTclJO9jB6UUOtiSuM+Titfuk5QIvgIU3ckceqyT38g+5LfdydsVINvvhLlBHfgdPVaancOj+r0u/CXxqxyvdHwOidMKb8DIVAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle x \\left(x + 2 y\\right)$" - ], - "text/plain": [ - "x⋅(x + 2⋅y)" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f = x*expr\n", - "f" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAAAXCAYAAACcTMh5AAAACXBIWXMAAA7EAAAOxAGVKw4bAAADTklEQVRYCeWY7VEbQQyGj4wLIJQAHUDowHSAoQKggzD8878M6QAoATqADvjoADrAcx0477ORlvXlTO4WHz7GmpEl66Q9rVbSyl6bTqdFWxiPx+uyOTO7TaNHkpdt1/rq+oPMDZwrWCduK/5C/KNwy2WrQr9lbvRYQRsmtufiNyXbTmQrweYGkOx7WIkI/WeTazk9sLqmMo8M3BdduRLO7YExhla2+xLsROEnM/KBi+zUXvtDdMJ3yZ9M1hn5UAaa41wgI/FLuYHdB9E9j5J4KuKncE/8ncu7oLk9sJBj4dRFcbLku8la+ym7ofC4teFfA4IVJwJEWots5ECv+d4lZAVQDhI8Mu9C/DYoHqcpnRxgrgRzgGngWT5U7cm8dfM1Z91GNrk9kJkPh6ER5OxMJsQH3TIEikMs57ymGtg5anniGEA7QS+jXS13JCTTDm3pe+ncwIt+N9nSiXwZzXEizKR6Hi8S8QSz6R5dl8niUbaX/h5b50p0lJYwvy5+g1K8F14J6U2UJovRa74EyGeCx+Hjewpt9nhmsbjVAtW9H0jG5FGEDJQip5IqlaZAFgIbwvR5EPb4g8vjxgIQ3GyzR+lyACQRwO1e7e3Iwu3uJfwgoxe0DZjpniQjkIXovDIx9WZE63DxDGu0OSDeU9dD8aPx++0dLzU2bfaIvZc+2far4jN7CDLPQFd2vTojf5ZN5VRdgArJKQfGINpHNsieStoQJUNmQLLGe5SuJw6Bon2l/Y/sRBYyMO2BkoUscKNwYZiMcQCj3oL84xC2RGO2iq+dTSVvukfWipVom8eWuTccyEAMgaFn0GCJKlmCQlrSNNRqQ5ZaP0C+kRW7NT4S1EvJc/fIRZTGgQ3H/seXgZCIgvx25EUTYQTJeOYNNcr7wsg/NkkC3Imnx6YwlIzJgkDm7JHghf7MolrHYxVb0UByso4a5yFKJ8JbIc4wKE/Ex3JGp2fAmEEQfb5L3fO+l7tHqo55jwnkVej/NoX+x4s+9GcCCywC5OBCLpFF+PLeGhZIsjr+8/TPJfLeAh0+K7U22BsgWML4U1U87Y0sD+OLO0oJLx3kXCyJpTvz5gBVkfZUfplxIc20s16U8JvP/eEUKALIBULm0fuu6w76D3alZny+4JLMAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle x^{2} + 2 x y$" - ], - "text/plain": [ - " 2 \n", - "x + 2⋅x⋅y" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "g = sym.expand(f)\n", - "g" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAVCAYAAADCUymGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD3klEQVRYCd2Y0VEbMRCGL4wL8FCC6YCECmJ3QEgFCR04kyf8xjgdABVkQgeQCojpwO4gHndA/k8naWRZd8Hn9RCyM3uSVtKvvdXuSnfV09NTZc0XFxcDa8zXgFd674PKmCaTyViQx8awrwVu4N8/6vsGz7AigZ8K60TlFyvMfeJIz4Hwg67vVF/Slvyx67qai4OtVF6DYWZgAfaF91PlW4D/dZKeGPdK5SjoqvpUdQw0Uv0+yLctNXemOe9VrixTBMpdbavMLuP1AkPx544Y6HuezhUW3rwS/0jlHerYAfzK0sBnUtCFRQeFuk4hauAuNNSkuXTO5+O5fcnx8E7k7YA9+iYGFhC5d9FJm5ebhCEX0h2PLVFu+NKYNhn2OOuFEVhb9RBuJ6p/ErOLH8XQg8bc1tWNJ3msMWftiL2xmIVAOn1owHE3IPW7gy7R/UjjZ2rHKPV9NypLWNhjlHrwVAO/wep4EN+IyXHkJYzvcorKEnECz0sdXrYLdgusbZfeFePiVOFmwQJfvU3uVM9tcCYZ0Vsi7DFwHiwAPDedTNgwES+GDsVpvxMmDzaAK84GGWBvYO5RwOF26w1aqcTgOBtElObv2Ba5jK0NrMovgaU5lKvWo2QYmoVKIUBXIDbAjQ2CpNwVm/U5lTmUcmJd+tduA34Q+v9N74jn1yAnp3Nou1ShgXjrZZxQV9Apl4Uh2LMfPDiAhM4SWOjbqkwUDPO2xhZGyYCV5EQZX0+ktc6k+UTwoUo8MpLawcEwJFGa5l+8G1nT2eOcLs3BGuu8IYDFA00LcW0BrIkIh7Z+N08YXbCb1jSRSyc26Uhl9FzV2TRycSD6YkR7Ie/CF1vunGEO9lj2NIAKuYeDiN3AW5iYpgwSfZr4NWSNGJsq5DqNsNcWsmxIP7yw9GmP0aO3qs67pfZQ0+XkJu+lHw9e9PRgJ2C+wZ3VVY8kGX0h0Ud5VmEXTzIZTQvsAuzuIr0XRsOx7lXPv0CHkqVpB+NiMEfeJrxbMXX5Ye4c66nBLrBbTKg0+Vx8J2ZRvqmXqsd0wZgCfZcMZXOywM4xrdpcuzByuPunuHnYE73cd7lJ/RZzJ4baPLjeAKv/rPoXOhcfW+E9B0frnYrHzxlrOUZrTsWzJkz1DcRz+g/qjTB5srttIWOySAayUhveG+G1YiLZkeqkUbz+spYUn3i8+24wM7AWJs3kp29xdSuh1iR/poeRFXSKw4FHCgzEF+611i2mTclJO9jB6UUOtiSuM+Titfuk5QIvgIU3ckceqyT38g+5LfdydsVINvvhLlBHfgdPVaancOj+r0u/CXxqxyvdHwOidMKb8DIVAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle x \\left(x + 2 y\\right)$" - ], - "text/plain": [ - "x⋅(x + 2⋅y)" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sym.factor(g)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## substitution\n", - "\n", - "SymPy provides methods to substitute values for symbols in symbolic expressions. Note, the follow likely does not do what you expect:" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSU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OStNZU12vB7r36FfRzayEx7XI2z/ozxSS7TU6+Gl6ew0BQFDeUDFLpdutYja88UgUVnWvitufVSMZEd6Oiwpm86r3P9DBX2DIaZ6SORMtQXVEfmjKZfp/BTTqfpKL3tdYQFSk+wQNzAIhmyjrEH8YXxUMqd98es8jOacoFIBsNMaQPip4Hrmsirpq2JWxAVdXZJOid/hsSJ/JqXirHvN2ioj3AdZXaZ9f6+rNuOSwIzcw87/ZejXLXoPiD99gkflou2vUh74DSAt/D1wSINv9GWr3XKzDeaeJdlZrJYu/9g7wsWkbM0NL2GfW35arsxy8QYHo1lyDQPYc2rF/tXH67HBWLLt+HDa1o6aIzmLjx/M6W5j+Tg8b+2E7+h/wMq0GtW/EaU9gAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\sin{\\left(2 \\pi z \\right)}$" - ], - "text/plain": [ - "sin(2⋅π⋅z)" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = sin(z*2*pi)\n", - "z = 0\n", - "expr" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We've now redefined `z` to be a python type" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(z)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "to do substitution, we use the `subs()` method" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAAVCAYAAADo49gpAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEIklEQVRYCc2Y7VEbMRCGDw8FOKQD0wEfHZgO+KgA6CAMv+BfhnQAqSCEDqADIB1ACY47IM8jThr5fIcvHp/xzqylW62kV69WqzsXb29vxaroxcXFYFWw5DjqcPWKFZHLy8tvQNla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pFaVsSEcvd6Quka5Xggqw+f1pBLo5vnKNqDf1tYv9Tlv9O6J3VwJI34sOKKtkdDXl3OOC0Y2U5M3e3KMsrqO3eIzQxY3azUhGtXjbf+R3gyNdRHW3ZFdTzjVuGW3iDO+GqxBxLsQcWL0A5lpgh53El07Gp+e4uNByR/cp89syNn9qCSa/ZSe+u/8B4Jd2DkRmIk0AAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\sin{\\left(2 \\pi x \\right)}$" - ], - "text/plain": [ - "sin(2⋅π⋅x)" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = sin(x*2*pi)\n", - "expr" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB0AAAAuCAYAAADUfRIMAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACv0lEQVRYCe2X21HdMBCG7QwFkJRw6ABIBSEdwNABdACTp3PeMkkHpIXQQVJCoAMogaGDw/efSIoua9myeQua0Uja1e6vvUj29tvttlvSNpvNIfLn9Kupevambqzs+wbvGvDryp6E9S5ZNS6clR3jfYvoIlCAvtBlaVOb7V6sW4G0YvwdIzq6d/UxvCe63B+8MRtUilxn+Nsc4A3j54gmT9yJRt8dcJZ7Ed5H0bFX4gEYBXAZrTv26HDP9J+ePgsUYSn/6pVE4wnzB3eoiNzJwn3oCknXDOoUnjDexlrdXMof4ckyq8lD3ZyYDmYsYGcWEjQ9IB38XTIloBBP4T0zJhkpgaidwj+I1tUpewUot/qM/mcpTD1jsuKRfkQvmttzUzDqBCXQLbLf/bZdTN1pfkBUP3RrvyceL2PhmGHN2asDKsaJ2z3oPQwF32ekLE4a/AsIk610+z8whjvrFSbZ64BlreKmOMRNMRFvtCGr3DhgDBZKn9eZgDpt/i0NgXdKFJehqxAOwh4lzkfGIO+YOoiexK63vqcI/IKni/5eQPQ75p80Zxxs8OUdyVrZr7u9y/rkykTaZK1AL9iobP4zBuhkBShgxT9v4cE3LdVuQGSdFAj0zIEzXd6smHqtymQ9W0p5Ab9aGwQFSG+rXJInxGLwQfcu1lxRMGhpRWYx6w10sQtrCvr1er3sF7+m3eBxK/q37DUc83qk/+fKDH3aTF+SeSsY/i026xRTMCNOzl4HaNUp+osMdUqm31y2xHRSnWKiZMQWUP1JjNYpmX5z2QI6qU4xUTLi5JhmcmFJrB9Y6PeyD8SRSYulhSqAijql2GQQFoGir6hTDIyCNNu9WKkSQ24tyoYCJSPMshQg/deadUqm31w2gwJYrVNMlIzYBArgaJ2S6TeXk2MK4AoNo3WKiZIRWx78SXVKpt9cvgBUCwUg/2Gr3AAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\frac{\\sqrt{2}}{2}$" - ], - "text/plain": [ - "√2\n", - "──\n", - "2 " - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a = expr.subs(x, 0.125)\n", - "a" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note that this is not a floating point number -- it is still a SymPy object. To make it floating point, we can use evalf()" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.707106781186548 \n" - ] - } - ], - "source": [ - "b = a.evalf()\n", - "print(b, type(b))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is still a SymPy object, because SymPy can do arbitrary precision " - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAABB0AAAAPCAYAAACoVLcdAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAXvUlEQVR4Ae1d7bEdxRG9VimAZxEBOAMQGUAG2ESAnYFd/OMfJWcARAA4A0MEgDIAR4D8MpDP2du96p2dmT69d58tuZiqvTM7e6Y/TvfM3p23uvrdy5cvL7eWzz777B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ij8SFjIl3TQC2IrfnIQs5Id+8YcymT+7gn5uUjA/GCcW5scP6F//Jwm00/zhQMNNdQPDPKW8XuHbO+/1LqA/tZPjMhyuV/JcwkKmHEfFxui/4A/jxkXKC7l9hnGb/PWL6J/mEa7L8QFWynPqBlbiMtg5jTfklTg3GzKZ5IaFtrLs1oFrt+4P7JTiA5ykG7hKfEocQfaUH/oOjCQTOMlvk8mcna4bhlM5knUH/dP7Y9DvufEEfaN7j8qRhKNuFnCaxsdw0nqtyIROed4WYz5dh2gbC2SquSFxCXkSznRLeaT6DZyUv6a7YqfKpSRTtVPFFeMocW4yJb8VLHyR11WTJ9mpcPSAuqX7M/RX5rg6HyV+irmh+iPPM+pnAQfDtbUSH2Alfkzn6f5Af5X30+575lN674GNkt+UxwJ8Os9Vv4FT10B5PYDM6vxROJfsVPlZiLQP2NvN9f8AXN3xTgqnfEIAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle 0.7071067811865475244008443621048490392848359376884740365883398689953662392310535194251937671638207864$" - ], - "text/plain": [ - "0.7071067811865475244008443621048490392848359376884740365883398689953662392310\n", - "535194251937671638207864" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a.evalf(100)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "want regular python types?" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.7071067811865476 \n" - ] - } - ], - "source": [ - "c = float(b)\n", - "print(c, type(c))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Python and SymPy" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], - "source": [ - "x, y, z, t = symbols('x y z t')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SymPy symbols are just objects and when you do operations on two sympy objects the result is a sympy object. \n", - "\n", - "When you combine a sympy and python object, the result is also a sympy object. \n", - "\n", - "But we need to be careful when doing fractions. For instance doing `x + 1/3` will first compute `1/3` in python (giving `0` or `0.333...` depending on the division operator) and then add it to the sympy `x` symbol. The `Rational()` function makes this all happen in sympy" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHcAAAArCAYAAABCdRcGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGLUlEQVR4Ae2a7XETMRCGnUwK4KODpAMIHYQO+KggoQOY/Ms/BjogVABJB9ABgQ6ghMQdhPcRWo1O0jlnE/vkG+2MLGn1tdp3d6W7887t7e2s0fZq4Ozs7Imkv1B6qvI83sleXGnl7dCAQHwgST8rXSsdKu0rZdTAzVRSP8N76EskVfmtMrw3o92M0xiT0UADdzJQ5htp4OY6mQyngTsZKPONNHBznUyG08CdDJT5Rhq4uU4mw2ngTgbKfCMN3Fwnk+FUBa7etuzXqNla5fK6euzzR6nuqgF30Wu0VOgR6vtevhGWLi8peS5Iaj3xPVxdPKvPdoZ8FdIAPOqn0juVz/1k95Zpzhea7Jnyd/Gkfl3j8YKcF+XI8Cvut4my1uQd7lz5ve9/XfIP9VzA5UvE0/sWRMpi3lPlBqJbQnXW/KT8jU+sDag/VT9ynTb4ozU/ajlkQd6toEHgakPftZuHyt+sYVcfNOenwrzwO+tpfQxgrkQ4GoOQE7lWJu3hSCmEzpUnGjBwELjMI4FQ6jroleYuhTq887faUk/B0B6Ij2dvlLycyJvKtIwcjP2f8YPXGgzu4BmX6Cglcdb+6RkCiH/UZ97TvhEFFdZG3lcFfnUs97FeCuRjL56CIk1pr8Xnrxt4CGGQ/Lvq9pGYMfwbAP5XJcIVYEHPlH6oL+fUInquRkDMyNbJGvyHabWHS5XKrE2oM9kLw2bn6hfCvMr0tfCIvMdK7OW1EoT8l/+KnV/kRe5StOl0HLuy5zf5QTkCB1LdKUI5lgrI3JYDqY5y4f9WzjPWE5UdmMoBnovPpVKfZ6qL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rVrFZ670m7aoKABgcnjmbuYGrA01nBbDkK2wnIaEJC8YwBYXgQRqq+UArWwHFSx3QUBbWE53JYbuNuNaUd6AXwjBo9J/Jlx3s7cjnq2o0I4JhWktbBMqJ41cAsa2gIW78D5GxNe2kvtQtWrmqobeL7la1l4zvXSHvrcvdBo4FaNYa9w6RewmYDmQoUn85zrQG8Xql791d0gADlX40+p+6p3Phz8BdA3IavwE+OtAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\sin{\\left(2 \\pi x \\right)} + \\frac{1}{3}$" - ], - "text/plain": [ - "sin(2⋅π⋅x) + 1/3" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f = expr + Rational(1,3)\n", - "f" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAARQAAAAVCAYAAACHWxFoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAHgUlEQVR4Ae2b63EUORCA1y4HACaCMxmAiQDIgEcEQAZQ/IJ/FGQARHBABnARcJABZADnDLjvGyQhzWp3x6Blx8N0lSyp1epuPbrV0qwX3759W4wlPXr06GgsuuR6jFWvXMe5PJ59/Cevxf5iJPD48eP7qHJpJOr01TgK+vXxc32egXkGshnY05tuAozpCJoPpAeUX2yiP207PG/Q5wr5g7xvkBtxx7R9JanDx5zud5SRqcM7IW8+/tPoj/yngf4L+UXSU3Cfh/CAznW8F2jPkVu3/7uA67LWdDJtzXMov6nJHvt4hjqUawzkLekFCxk3pGP7ZYCfG/sf8ss5s7BhnpNfj3jKGpOGfZ1yYQSRZps5MnWqV8lPtilnFe8g/wn5G2nInTt1cj7WOpVAq/NI60dZR/6adJNyzrMZHbwX8FbPZjyH8pua7LMwnkFXHhZQ4z1Pnjajg2sEOonnFV7iC3nIN1rRmDWCXYB6xgjhp+Qzhmuku6ftHPqcI+8M3/6UnQvrtfmTJAdl3qWPTiRC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SjJllo+H2IuHVXywX9nR/z/ti98uiUTB4kTengqcymPIfym5rsszCefRbHyMRF94S7SPLk1RjuUu42gu1bAk/paBBVEeigAapXumpR1iA7vbNO6uxJHaHfHvFFDh8NSR3StQucn6VX6SW+Fl0UfLdQMYqrjekwyNoU5fkGZmS1alxR5dZ08m3Ncyi/qcke/Xj20VCnEb92qPCCTefbgQZ2bH2L4KlaM5JOJHqo29JP8sHpZJJRByNxDK9ICcDrLAqQluTVKLbpiIwA8hP+IfWTouOPigac0/5o2W7JK1xtPYwuvSqt0jdqZbsRSJ8u8owOqTWd8lvzHMpvarJHP54DNQQ0IK84+WY7Bz5uso6IP+L6oIEl4+43bqh/pN2vDUuALjoajcjHU984crgGLn+b0Zl87ukvvVek/hh0JCYjMsdT6A7OtvekVdAZ8KrGbeHRy/VR5xuk+Ait/l7Xrka5tInzXUQnk78JFY+50tOuY5bex/MTcUBrum3wHKrj1GSPfjzxK4+G90VtA1wg9xTXmI0SfF/R0AQN9A5Jg4/vLm5G8U8C3lNf+g4Pj3RdAZcg8H5N7j+5FQAuPhQX+FApjAVarzr+309+bdEZ6WSKzUddA/KdSP4L6j50aljOgaH0V+qJD/UCaLOfBth3VAXdqkqQdao3lMiLvlF359X10hn7vz065gTU1dG1cx0SUHdN8rVwDX0vK8bSmk4FWvMcym9qssc+nkH/HOggtgVsDDe/X3oKo9iWvF/hi44aoI52yQEO5UtfnddPOZShMma6eQZ2NQP7uxKcyTVaKE7SrG1sRaMd9f0VMLowzTDPwORmYOcRijPKqe2VxWvELh47By0quhmdeK3yajTDPAPzDFRmYAwRimp5r+8/vFbU3SlK/c5KJLXTiZqF/7kzMIoIxekPEYBfMPKvN6NYGXRKP+kfhUKzEvMMjHQG/gfM862CcPQt6wAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\sin{\\left(2 \\pi x \\right)} + 0.333333333333333$" - ], - "text/plain": [ - "sin(2⋅π⋅x) + 0.333333333333333" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr + 1/3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## equality" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`=` is still the assignment operator of python (it does not mean symbolic equality), and `==` is still the logical test (exact structural equality). There is a separate object, `Eq()` to specify symbolic equality.\n", - "\n", - "And testing for _algebraic_ equality is not always accomplished using `==`, since that tests for _structural equality_." - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x + 1 == 4" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAAAQCAYAAABnYDOFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACIElEQVRYCeWY7VFCMRBFkaEARzuwBJUOKMGPCtQOdPzHP0c7UEvADrQD1BIsQekAz4lJRvTx4eiDgDuzbJJNXm5uNpvo2nA4bJQu3W53G4w9dIfyoDS8Ed8J9kRsrdIAJjwAXKd8i76iu+gWWqq44c8JXK2kQkyHibawN2nCWS1jjMh9+1M+xRitxUnENoKrOVL7+4rRpq6kQKgb7earWeomNU+0ooVDiP12CvPxx2lEHcfFt7FHqHnsMLb16XMXy//ewIUp6bqKiEwqzks6htsrDvCSkMgz1MGX6NKQGjGb038iz4wLeXzSIPoYbAPsS1W/QCpOI1TSkpgj9lCjVdlAP/tDY8k/rCkESE0YfT6djft2itTHL6zvMMBdCwkYO3H38BvJVVHhZjTwVy1wpqhwfEnCWgzAymOfcKZIzW+s6DjAXqRO0+wY0iTTaPdJdTXtG8vgZx0e+3Vs5bFPa0iRmuoNBhhxXlo5f9JmXV+IXMulC1jHnZ5J0KedHklt820f+5/Fp5XBY/tLi4KEWfGiesB6VL8m4XN8Y3MI/YsT8FalnF/hjPzI0YjQ/kbDAzakySYVI1N9pVGC/bMwC236+rlhMYXNOG3I0YuBMHFWeVODtPiVeR+wkteARG+2e9Tj84RKdk4F9pmXMG86ZgEb8/ZoM5+J79uje1640jxgkCNTgtKJePtrdf6XiklW6qL64G76r8e/ThnwcfVfyTuQgLc2tvj7GQAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle x + 1 = 4$" - ], - "text/plain": [ - "x + 1 = 4" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "Eq(x + 1, 4)" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [], - "source": [ - "a = (x + 1)**2\n", - "b = x**2 + 2*x + 1 # these are algebraically equal" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a == b" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can use `simplify()` to test for algebraic equality" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOCAYAAAAWo42rAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAz0lEQVQoFXWS4Q2CMBCFhQkIbqAjqBvgBsoGOkf/GUbQFXQENjAyAhtA2AC/V3tGG2hyeXdfH71LSzKO48KWc64KeYeuiQrWiiVmBLyoL+hDG2iGiO3J2zTAM5qZKbAB1UdX1d6IHolGIFpP6kKnm7EA9JFJpZ8PLdIwy4TnD+U6MQ9IM82tb+s5g/GlTpyazQzWrdOM1lL3Fi9jn3tktyZWsYvaTqzteu7A7YRxA2vU1RtJboAePZiZXG1L4iT2+9ba0E8xEPopdoTe3r/YGx/SQ0OZAIYmAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle 0$" - ], - "text/plain": [ - "0" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify(a - b)" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJYAAAAVCAYAAACkJReUAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFWElEQVRoBeWa63EUORCAF5cD4CADkwFwEZzJgEcEhgyO4pf9j4IMgAwOMjAZAM4AMoBzBr7vk9VTmlnt2J5ZmV1fV7X16m61+jWa8S7Ozs4W24iHh4d7U/Wewzt1z03nm2OTGu/OYgvh6Ojob9S+P0P1vSxjhoibw9rCnkuB5Sbgu6lmg1en/Qs+nypjjA+5j1m/S/tpjG5sDd7PrtM20XFs701bwwZN7LkUWBz8BXg6wwB78N4GH8yQUWXFCMp9RfuySnCFSWS8hfxFlnkFzptD2tKeS4HFZvfAyY6D12rwB60Bum54g8DJ1bSijLKUOQk44z64zVWvmT2XAmuShQdMGHtOxRtI6w2fIvt9b2bGIMtSppVwCsg3lXfKfuvmaWbPJoG17tMrD+d7F/jRQLYynzaQu9EiW9tz19OziVlnSb8HfmO8siqw5tvYPngKRrY+Y/4BuMfcR9D2M+MntAtaeT6Azv8DWoINFOFP8As03nnG4BGL6dJdI4I/zuCyMg9A93sGCu5Ru/ArU9krzyxzC8g6awttGdDTs6D5ngn00UfmO1vQX+mTEFppm9ozBRabpgsxChowBkbVyHFIWpXqgHG6T9Ga/QbYt26RDuOTPK9x7oD3mUuBRKtRDOZP4FhFegjd2P3qDfyhh58jDGSd9BKMu1QtsNTJc18roJNBr50O6Ce9aJP9aX+AJ6C20R+PnKNNQP/YNfAtaEJ59qpPMkutaWrPHRVk1y95ZytMd4CKNirzMB+mXB46/Fe5WPSVvQ9/52D6Bp1wkXM1YFUuMqy25SXcCmBFjAQxmMt1hh0oUydfNxgwBlBnC8aeUVB/QZpawvlyZTDpu8v6BNIeNLXnLlul7Mhbetd43du+GHAQH286wu9UluJj0INf9BgrpCy+loOiH0YtpnpdgyMM3ltg8BUdyoTwU4cZn+hp0yN5yJTH8o3uDb+JUwt8dVqwXnsDdv/qvsy7n0HRsxvzBlkKNPquG/CR9HTPgTVlO/AKYkWe4pOm9txFqTC+Ge6BI8tVvAY67RUovVXAzHkP1ozLcntg75PBLqMJMqAdM3AiXXU25rWBH4R7ATKQXxtGhfxZW8xzQZP8s4LO4BPW6pN12HPnXK/012Cx+pyCBtgSMJ8OS2uW+L3rFkQG1HP6ccglvjVNmJVVvUr56GFlka57xDB3Wyzpir7zyr5OiOrqRXwVBM0qveXzaTPVJ03tmQIrG93AiLuSQVYDaXofBOG1wulEn/UtQUMnI5abqDvoZTYeVQa6yRGOkdyXk9OSr+jfoV/SFkttulkXq2zVZqw/Bl1X596lXI1Yi7N6B5vqk6b2TIGFchH13qHsx6st3SXQScMscty9/maOIY3TOnEqaGg/IwxBI4u/sl5mYgfZCUv3lI7g/DGi7OsG718+RoeJ6vUi9PmLvh8xDZ4SpPGNMGx+WZ+UMpra85Y/5xBQ0uj3Mm6/es9iXgeaQeXd4C5jK4ZBqQGsdpFRHvwANFid905iFjr/GnTeCiN9mkfGqguvsv1+03t8MDaANXRKBsYa3H3U09d5A657LDLuAWvy+T/DcFJvfWyQ95lyx0pi4Q/dHUcy994CodFGvgVqH8Hxu9CXdtQniaPyB76m9uwCq7L3xk1hDI3/hDYyepaOyNFJJkUvWC8rFD4DeHJgXXafVnTo38yeO62UbiTXymSFWxek70EzhFlFopLMEPPbWNvZc9N/2TjUj18rHtd+sTiku2isDGVdRHfT11vZc9sqlqntHSzeXuekujLWWf3m6PI7eZvYc6vuWGH9fDfylfyqHyaTCPj8X2Lvkhyy/49tC3v+B4b/9qLn7J0RAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle i \\sin{\\left(x \\right)} + \\cos{\\left(x \\right)}$" - ], - "text/plain": [ - "ⅈ⋅sin(x) + cos(x)" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a = cos(x) + I*sin(x)\n", - "a" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAABkAAAATCAYAAABlcqYFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABhklEQVQ4EbWU200CQRRAB2MBBDvADoh2oB1IqMDQAcQv+NUO0BbsADowoQPpwEgH6zmTGbJkF7LLxpvcve/XzJ3tFUUR2sJyuewTM4DumsReNXGq8XlB91Sjr1X1LpmkNtMZ5aWTnElZNV1XVac13MED1hF4Dz8ueyLPknwLfQU9zsg3noQkXvYI+maCJMOGAG+Bz2QbwK8Sfwc/ajOJwe8E2+EOuodm2CPnTbOZdTI8o98GL74NLhaLNTg7FYOtAIdle+PjsjO6skvvxYm8myNIusNUyEMdWhXB3wJbgj2qKRhMBP7KAxMwH5vy3M/RO8HZTn1oPxoBt2OO3qQh2T9gv0AvOiaErpC/wS34COZ4J94fiiDYpc5jeJ0D1COZQGNH6i6BuF0k8ezciCl8LJCSWThvSlK1J7EIYU4g9CmSH9UN8hp5Ey0dPrmIHefH1CFdfWh5u7zMf4FcxC3xeCrAcTX+pVeCkyIflz+0uPfZkeSus3qxE5RX2At3GvddcAn8GXaGP+/HyOJOKtkXAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle e^{i x}$" - ], - "text/plain": [ - " ⅈ⋅x\n", - "ℯ " - ] - }, - "execution_count": 39, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify(a)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## More substitution" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "note that substitution returns a new expression: SymPy expressions are immutable" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAOCAYAAAASVl2WAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAZElEQVQYGWP8//8/Aww0NDQYAdmrgdgYyP4AEmcBMgSA9GwgfgfEJkCsBMRwAFIAUhkKEgGyy4AUyBQ4YIKzcDBGFUACBj0chKHhJQQLN0ZQZAGDGBRBIOACxKC4OQfE94B4NwDm+hiAOyllRAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle 1$" - ], - "text/plain": [ - "1" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = cos(x)\n", - "expr.subs(x, 0)" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAADkAAAAVCAYAAAD8dkbIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADMUlEQVRYCc2X0VEbQQyGDUMBTqggpgNCKgA6IKYCoAMzebJfoQOSCjLQAUkFJHRgdxDjDsj3LavL3mE7g/EMpxmddrWS7pe0u2d3Hh8fO23j4XDYWxXTPN/NTstoNBoNgLT7Cli9HKMK0aokAXcEsm3kTYXwhQN8f+iCPA3XDbdFGwhQXXD8RH5cBx7i/CbOPnLWpk5eAOpqHQnmGMYyZqdNnXyg6u8ywLUI4j0Q6EMrOgkYz+JkLZnVgxizvxU6XuSZsL2z0CHv0FeXQGEzzjY7yGv06bCrY+zNeAAbx5jSMfplZ+0QmypG8ige+BonLpJPjE/gHnwMSzWcT6r0NOZhSpIgOnhQTxinpJACNYEJfA8L/ho+VIdMxPjWNfgSFswFUtAVMT+rJvMHe6iXnUdjphhIPzHfYBM7h+PsVc0oXmEzDmK7Ct5kSsPowiw7aXODTZVg1p8jBWERBLvHOHyzydIEtNF+GsalJJYdTBdI1ovH7f01z98jy/WsTsKYva0MSICX5Sp6E46uum6370obx9jZZYduSStrYC8Rt8otbGFqsdE1SaBRzObaL/zLwrrtfWeyR35uOhRz/bp2UvDSnycx9xk2i4DoZCEkQZiUPlZ4DJBlWxGTxYTvfWO1z/x7Q7domopnklElL5FFFDbdRQbo3e6pGEg7ugNvoPcsnTKOIswLYfeXxU4+xPCe0K46Vui6cjJ4/lA/3cRgxsBqeZ6eEetHsOva1S4UjVnzxZJn1kTiFlTnumdHUHPjawNZxNgtSeEDXxPwYot3WLAZ8yi6Zl+Yi20e2cmJnZTc1/6wbQJ0u8V22Wfcx6bZEW28WeMT4EutYEnOY73Ux9h3+GloksnJ0xxzWhqgc+3ZPVHYpPNb/eLJQQQsxXewdptiY7W9TaNyzq/QpwTyS+12eb63mduNhUmyZuH8XNWODHOLI6aEh7nF9Gb1HX7yTL7ausxrxJp+Z635L8n/wDG8u+r/yKaf/yuNqT62a60CbzSxY//70fASaOn7rUNrkmRreUF5L3gEXkU5hrHSD4bWJJmz8gJc+ZtaVMYY/3ZFcy+/9TyfpcGqOPAfGKP0/wtdFxjUk+2N/wAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\cos{\\left(x \\right)}$" - ], - "text/plain": [ - "cos(x)" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAsAAAAJCAYAAADkZNYtAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAyklEQVQYGU2QvQ3CMBCFDWQAoKRkBBB9CkZAMAFQUkapktZsgJgAwQgU6SPYAErKKBuY7xlb4aTn9+Pc6Zyec86oyrIcQjtvjFnAWzAFm5DV/SBEloajgK7BGSzxGaxBNuEwBJpopUO18ApoumoMrNEaRVHMxBH4E3hEH9mvweSn7++ONfLS2Z/ya/yHNC7x2vEWczJ5kwRxReuBd3gPWvQbjpXjM62hSUITGpv4hZhMd/o7ZpCm6QfWa0dgzmVeVdULHMCEzJH5lb58Ulq0QJNfvQAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle x$" - ], - "text/plain": [ - "x" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "multiple substitutions, pass a list of tuples" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHMAAAAXCAYAAAA4JnCqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD70lEQVRoBe2a61HbQBCADUMBJOmAdBBCBZgOIFSQ0EEY/vGPgQ6ADiAdQCogUAKpII47IN93vtPIwgbrYUsZvDPrPe29dm8ftxKsPD099crC8fHxBnP64AC0vQWewH+ALqGlE1iruO8p8x4x3oXzod8hP8F3Pi+hnROoasyTgrgfeDZKl9DiCVQy5oR0uosORusSWjyBSsZM8sb0us/zOe2QclPfki7+BFbrbIkBz5i/De5Ew9ZZrrG5yPIJPG9swf9koVrGVEcObQg5BE89RHkdgGtkeN8BORYqQuk0i8HWkfA3uE07vYpoUOEzmHiBMcsP6/QZtwGtnapZw8r6TULpyOSwNJyV62PuxDSG/Kscr0xTBxFrAbKZGZRDfHNQOjLjCe1Bjzi8P/HZjwab0dCR1QrZR4ZD8KCV3VveNDMmB2BkfIvyaJyvoF93rFaFO8b8sAE1lZZOp86dFyCT6fXFoocxZXRMYz+y7j1zsysgrnMJ1akXCuxp9rEmEPZ4fgC1Uz+fZi1gzkQ67sBLB/BscaNinX2PjMoMofnUj8jPoIyOZh7P4gYs6v4Fnu/WCwXk0Q7aRac1sNRH2aQXITJpGJF5gYc8K6zRKVgZ5vsDs0M/B+ig002FMjoyVu/XoYUd0BohD/Ju84wFtbWDhaf2CUBbuwQ7pTT7C2beqzcZYPiGSdBG0gnr6FH9IMX4j0L26J901ynH1P3p0xFfTK9xqzI6+t05XSNGYfHzpToUeXGboIcR5Ldq6awQUuZLg5EpsxFt1z4C/QNHsFOKzCR4WmuSAqmvMmXTScbqwTcL+GpiWpsZGO9dsQ7NlJw2mTEz68jYcDhQjeah5e9Lo1be1MiM8w2IuQDrq/cudCwbBWPmd8wpEIod++ApvDQoabsjoFJbyJUKgiSWB65zyDfKxpTmORnpNR3NCFmGios71/u56Byxe74kyj7m+PB06OGaDbZXaS9Rvc3oKRYTFgNjB8KY1iHK+yxC4P9FuFtoSM/QqjrqLMWob+u+7KFHKLqgWaaIRrAo2jMy9TTR9zOVHoAZwLMvFQMZv+MN9RATVNVRQ4b73IXiWbjWxOvCMfMC9jbbuK+ZQmqV7Z8eNXBw2jUaeraWVkgFtjK8AS0q7sEB7SwdOaarEGU2moQ+z2YcHVH9quhoNvJ90orRDyS+cwrPssGIPddfP4iYFXpQDWg06mzaK6T8lSr/NsICjUIUbuweaHSDhhZDTo2qk8ytuKkj6mqdyQ3OHbKW2BnQcKCZKQBt07avQScjTvd+TbOtAwfVRtp6TW9TWf791bR2gaydvXI6kWZfO9U2+jGaxrT4MSK9K6876nSINoJ/bxCYC1L9PjMAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle x^{3} + 4 x y - z$" - ], - "text/plain": [ - " 3 \n", - "x + 4⋅x⋅y - z" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = x**3 + 4*x*y - z\n", - "expr" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABVUlEQVQ4EYWU4U3DQAyF26oDVGWDsAGoG3QEKBNAN6B/8w+VDWAF2IBsUNERskFLNgjfO53RxXWEJcfO87NzvvNl2vf9JJK6rm/At9itj4PtM3bCXqN7sFbYTI8R+QBf+hiJ32AH7A59xd+hX/iVuGFBgs8KegF/AltgPy2G3+Hr/U3YRUEIalUkqZd7gKMHeT+ga3IXFwUJPBB4D5IErdFzEEv7p/igIIXUalq6T9LXPRa8L/8KklBB6LD2Nc+3A4q2wriDljUiY61awn/2Kq2QQjq9sNWiQrR3FrbVn2a5VY3CWKspibi1Gu2lYe0ctvZuRYIGuRSNT5XxFqsBboSVpOzbCps5RJGkAwH/AWiwmj0TfdSunWGyt+gRbpf2sIwUvtqwVhJMgg7tjL0zHr44G/RR2NT/HCDocNSWhliia6W7q3s7yQW0yg7Vz2GFvoCnG/QL5btzwAlckjMAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle 40$" - ], - "text/plain": [ - "40" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr.subs([(x, 2), (y, 4), (z, 0)])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## simplifying" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There is not unique definition of what the simplest form of an expression is.\n", - "\n", - "`simplify()` tries lots of methods for simplification" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAOCAYAAAASVl2WAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAZElEQVQYGWP8//8/Aww0NDQYAdmrgdgYyP4AEmcBMgSA9GwgfgfEJkCsBMRwAFIAUhkKEgGyy4AUyBQ4YIKzcDBGFUACBj0chKHhJQQLN0ZQZAGDGBRBIOACxKC4OQfE94B4NwDm+hiAOyllRAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle 1$" - ], - "text/plain": [ - "1" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify(sin(x)**2 + cos(x)**2)" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC4AAAAOCAYAAABQFS4BAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABSElEQVRIDdWV203DQBBFE5QCEHSQEgh0EDogUAHQAYgv+w+FFiiBdABUkJAOoIQoHZhzrPVqsYTkL3tzpeuZfSR7ZzyzHldVNcodZVmeofENzvD36p34yBEIPEbXK9zBcziFETkLN7MLlRLEA8asRxxF78CcgxUeSyXU1F1I/AX2FlpXN2FuzZ5V8Ac3acaXCHuRqFpDG2PO+BFroyxhNqgzjjgznQqzMa6gWRcnMF2vJ4d8NKWyQfxPImSGv2XOAEbYuruT9T8u676RT6jtigW/23bd3N7XZLz9B9dsfG5v/m+MAAM02N6Q1nh9KCLmOGYuNqIZlb2p6nDQJAjyc2pzfmDv4R4/LZ0nxjZpNjDjZljuQhB+YiOYc81bZkichsO9JGqMi6KwBLwxvp1BqFeiN8ol/IIGFMuGcW/gXCtBNOVrL1oJ77+zk16agmP5dQAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle x - 1$" - ], - "text/plain": [ - "x - 1" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify( (x**3 + x**2 - x - 1)/(x**2 + 2*x + 1) )" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH8AAAAVCAYAAABv0jEvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD1klEQVRoBd2a7VEbMRCGHU8KIKQD0wGECmI6CKSChA7I5Jf9LwMdkFSQgQ6ACkjoAEpg3IHzPhrdzVq355MZm1i3M0LSanXafVcfK+HBfD4f2DSZTEa2Xmp5HXas4xvbgp9ny3BgaDqdnqm6b1glF0fRnhfZ0DMswKCBxxtmJiRjPyk7VP4tMLb4j3QcSb1Kzw8qP1MX/8GqrTqTeab8p+V3lSVfDBbWFunNwr1SOlB5Ztsoi7eAR3C+mDtqu1N+kHbYtrp0xPGXyo8q3VQ+VxnDjlS+rfjkqv9V9lF5AwwrV5UlVwwW6Bz1/aUiC4CFwAR412av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- 2)⋅(x - 1)" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify(gamma(x)/gamma(x - 2))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "but sometimes it doesn't have your idea of what the simplest form is" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGcAAAAVCAYAAABbq/AzAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADIElEQVRoBe2Z7VEbMRCGTcYFENIBdAChA6cDklQAdJAM//wvQzqAlAAdmA746CCUwLgD53luJM35cia2xDnnGe+M2L09fbzSfmgP78xms8GqNB6PdxlzEcbtB36KfrrqXNv+i09guPjVq28uMcR57IF8hfxIO4i6LS8/gXeZU5xhkFFt7CXyPrrDmm4rFp5ArnGMmofCtbfD/3ECOzl3TnNOIsbIOYFv01rzcAqec++ctGRIZScojpJyzQIYLEq+h2U/wl98Rv8UdL1n4RxvAHqEXBVWRcYJh2LUpAnXfQoBwxX8U1wbWUyP6mh3Ud83Djar3l80nUmnipUv4mCQbRwmrrzVA3Ci8Cx/9nkVYozFhQXF9SrjQl8NkSpHdcxj1Jwh6onv1XVFrJONnbFGyGexIX+DzRVUWQUBE2kYy2c99tCGbFrRA3JID7LlkIfzGwzN8UbMbsCaM++yY0qwv7pGbuT4TSMoeSIOYs6D04tuBY2gg0wXLNM02oJu/VMn4wTPMxVIx7RTmhHylSbd0+dWAd5pqnCNZQksVVpo6V+lCN6nogBZQy21x5b51q6qpzW/+n/aQHFP86Ia8Wy6clPm9o0gMGsYHStWcBH3Ru2xihw2ozfVD98UYXls9Eh7tPr7StnjPxYCt8HRKpibuMeY1h4AX6+y/GZ5QqeRBvBFqaPa+LJ/mMciYtTSX+O7TtudJY6l1w9rPLeMKdpjmLdT7M1ziZGT8nLo8AX+o9m59JkNth3+AL1RailtSs0mxpsB9uDpmydOhq5oj4zvFHvEWef1O6fSA0Lv8I6pLn+V6CxJ1fWWwKeBD+ApypA1uHfPHKHbiD0OAeqhm6O9LC1L9ZApcj3NXfDcvFzp1g8CmwXAcQtGDXaNfiP3aFrTi2x+VbuJuQ9JdL6zeuslgc/I0LnukL3T6jRCZwWqkfq+xw8BuPfvVHlIM1r8t4ngB2zknDahxR/QXpBTirNPz2gCHg0Uv1/q8OI909s9crY6llSdP/wGnVlr8iY/GThzCQHmTQqCEgy5Y7vE/ldBkAuycJxhXIVy4Tz/Y3hn2P8AVABHSXEKehUAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle x^{2} + 2 x + 1$" - ], - "text/plain": [ - " 2 \n", - "x + 2⋅x + 1" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify(x**2 + 2*x + 1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "instead factor may be what you want" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEYAAAAaCAYAAAAKYioIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADDklEQVRYCeWY7VEbMRCGDZMCIOnA6cCECkI6IKQCcAd4+GX+ZaCDkAoy0IGTCiB04JRA3IHzPBfpRj7f2T4y5xz2ziySVpK1+2o/xO1Mp9POttLl5eUetl8E+7uhPUU+ebWtoAS7rwChHzGg/4X+T/jtbhRuaXsGGEeJ7Vf0u8h62w6M3vKQAJN3d7Y5x+QohA6eoscc086HEsKYhIr7XtS4rh2s7wkKfKChM6HE5DkyF2wCmSu0ZykFEPWWA/oTN+ShhEC0DmkHTrwEQlcv8RbODUr1Zl5gJrQ3qTztM2eEDGiz6hTGf4FhYD3/QZu5Ubqxbf2g61f0eoLfwYKzjzy7afozhNzy+75sHpmgWKJTZxCgQXzH6EYuWBuhlGVSd6+8zTJlgoEfnaO/Suhrl/bl7xX3BhI0ncI2J363H4E5cZDPrKejQnKjhF038G/YcJnxKsb7VYfvMmlu+VW1YEPk2ndSxxY95gP8vWoTwHmrZ2H+kPYUNjY/Bdk9a+5Cv62N9mnnymFruTaBjeEq8v+Ja5kF97CJ74ixCUvQjN+2k/Z5mSuTHqNxZvg5wng9JTXcGDX09BrpNZzOZ8IW/tG+2sBonAaX0QPgpPnHcv6ILFtPm1WHso1RxhqrghWoSJ7bYb4s6XvG0t8u/uCCsTboACtTrEqlG1DusTBhAvtckC0cVhjeQa7nWa4N0aZp0eWXnm2O0c2WookB3rrr8kSLbE9G1nZSx9J0UaW4HqObzcVfMNjntsnXrK7L+7xOQ+uCcfpqZEkrSY9J9V6qpB5juFiGi6SHyE8BpBnEkTlnlfqf9CYcnuWrBYpkuXHB/NyUHvMN1jOKpJdY9wWgAxB9eASbTH1CC1geVq5ZF3Fu1DfTjXNvkekR6lf2VnFdWZKvVtkPVcPhcAz37K+LOe8YPm/6PM7owuO65xhKkm+Reohm2/7pz4TdctNkDqz/1opIgupIdON4E9rgLaPn2BI9xlvzQbXWTw8e2jBpz7MiIf+Cp4IkLsu2H4PX8ejyyMYIG/xWc0dbq0xHhf4AzwyH7E6hlr0AAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left(x + 1\\right)^{2}$" - ], - "text/plain": [ - " 2\n", - "(x + 1) " - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "factor(x**2 + 2*x + 1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### polynomial simplification" - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGcAAAAVCAYAAABbq/AzAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADIElEQVRoBe2Z7VEbMRCGTcYFENIBdAChA6cDklQAdJAM//wvQzqAlAAdmA746CCUwLgD53luJM35cia2xDnnGe+M2L09fbzSfmgP78xms8GqNB6P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50, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expand((x + 1)**2)" - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF4AAAATCAYAAAAZFLrcAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACcElEQVRYCe2Y/01bMRDHk4oBaEcIGwDdIN2AHxNAR0D8lfyH6AYtE7QwQpgAyAawQWk2SD8f17asKHktL6lkKe+ki8939uXy9b3zvfTn83nvrTQej3fZcxn3DeJ4hn72Vl/bun6n5Q+/BuTPaS/yV+QneC/purEZgXfN5pXWc8AeFtZr5AG6/ULXiQ0ItAXebH9s8NuZ/oJAv02NX/RJppvxR4xdqVkEZ8W8bY3P7mJ5OUJxkJWdkBGISZnnCN/RTdcCHgd2NGb7AXLX0RTwRmxuUV0gTzQxOpf3WgMfHev0U3Qa2krmL847CgCb3QH0iIdteMCnVY2PoNtCXhQAe+F6EFuf+WBg6TWz36/Co23G27N7eo6Z+JLc22fldgriMFsFupDkjGeRQJ6rhD7CZ7Dl4xSWHlhz90es67O22InnFwhZUsRQ/H7Cdny32ELpKft430a/yCx4gG/gIXPLiYfiJVor1Ra7eEmH4hdx9SkQeMtQLwDPxEwvgZ0xd8E3WPoAl/agrOGjttiJJ4G+j5zwS1D9QLhxTarxj0zKbsSefIrOA+gxHjuuS/gxqHs4BfcvLo/ZN21YuFbs/ykmwy3xTOF7J5rkhwH4JT/sBONVWr2pke/xIDf6orVu7JuOSX+wkIWkVVhCg7LGBzubhghmZL5I0e3KSxxUpaoodi/QJrxediKg9pxeUG5IrVD5qFxiK3v2KgCvOHbfccR0kXzafSImZrwZLr/GH/KKnAmdNrucGqnK2MHMajFhzA1JxNYSbovZ649GIx8JFzyrYIEtpR2NfwV4GXgguewwr4aIq+rYiU9cU8mxM7xCFxqF32pbFs+m8GuhAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle x^{2} - x - 6$" - ], - "text/plain": [ - " 2 \n", - "x - x - 6" - ] - }, - "execution_count": 51, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expand((x + 2)*(x - 3))" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAABkAAAAOCAYAAADaOrdAAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA/klEQVQ4EbWU0Q2CMBCGqXEAZsANjG4AG8gKuIE+wqtuwAy4gbiCG+AIxA3w+wkYUvHF1ksu1x7w/ddei+m6LnC1oigiGMeBsyG2mpO/K2dcRQaBkpgIKGN8IhzwhHG9UNLRBNxPGYC1qideKe9DJIbTAA4FnFjNOCQf+RAR7AFMlc9Z6NyTOapyiDaEiGh8rORDB/BaAnh/4v4iAlwNvyB2JgYmz3M17IbbjdPzb5YC6O+A/QL5kpy26X2kA90TX07BGV7ZvKVdya9zKt/x7YqYjgzG6ouXexIAU6O3xPHXMupIuHU+wkO1V2C6L7bFPF/52C4JaFsyW4F5fzhex8eV111V+AkAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle -2$" - ], - "text/plain": [ - "-2" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expand( (x + 1)*(x - 2) - (x - 1)*x)" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGEAAAAaCAYAAACn4zKhAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEzUlEQVRoBe2Z7VEUQRBAT8oAFCMQMkCJQMxAJAI1Ayh+wT8KMgAjsDQDMALADDAD9TLA95aZqdlld++W3QVKr6uGno+e7p7u6e7Z48n19fVkAeNbYH9//xlSdoOklYA/MD99Or74hYRggUMM/ilag/4x/Uva6lKcXODRLfARw29kUg7przC3tnBCZpWRu0bBRZ2MJ4uaUGeW8eeIACPh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UGchERe3Lxq3dwglQbCGgyItgDe/tV4FPjNvCDpLJF5qHqoI506hS6Ql85GVkeHA/23/TT6lJmnsCL5iOiN8uudjqWa2Lfg/4gvtF85tBaKsHrs/jKOluwH/q9G17e3tXtLW+fLrsR9472naXPX1pkXdIu2zjw/oK7aqNprq2FJ3RE3tTZoVoTxG3tltLRqsn3n6aEVsAfVOq0XNwM9P41+jp9O0ziBNQ0LRTfVk0ajnEAjLN6dVHxBCsIw/Tsqk2gin6BJmNKZQ105x26KRXrAlRUB9sAbc2lN7cfRg+8F5vtN8Q22Brgf+DmFULrHedM8IgP2UjuIBwE/zQS98Zce1fx8FZ/vQx99M02uQvvvTIsObtgsUAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle z \\left(x + 2 y\\right)^{2}$" - ], - "text/plain": [ - " 2\n", - "z⋅(x + 2⋅y) " - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "factor(x**2*z + 4*x*y*z + 4*y**2*z)" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAAVCAYAAABfcuJLAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAHEUlEQVR4Ad2b7VXdOBCG73IogCUdkA7IUsGSDiCpIEkH7OEX/OOQDhIq4CQdJKkggQ5IB5ulA/Z9hKTIsmVbtmU7mXN09THSzKsZfd97Nw8PD5swnJ2d7YX5OdPSfaJwZ8N+k+4l8TXhicvWgG8NGGK7/E75NvuKlxzDTe22NgGdn5+fKLsfFM2dfCKFb4TjqcJtrHwF+GJITfk9i7OJV7zsF7FRcTsUVpD0sez/VuGp9H9U2I1w1Nr9wcoEqdGRogPF/5iC6EPlTMwPCs+Uvo/Yk2Ql91KCPin+HAtUWSu+uH7JvLC02kJ8FrJ7xe9L4ohlr8lGMbY4L6x7KnNj7S+lf5BXeW3hjduWzPfFpXqtPha/cSzH7cwE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right)$" - ], - "text/plain": [ - "(1, [(z, 1), (x + 2⋅y, 2)])" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "factor_list(x**2*z + 4*x*y*z + 4*y**2*z)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "collect collects common powers" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAAXCAYAAADk1pHxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGb0lEQVR4Ae2b7XXUOBSGh5wUANkOoAM+KtjQASwVAB0sJ//yLwc6ACpgSQdkK+CjA+iA7HSQfR4hCY/xJGPHGtt47jkaaa4l+b1XuldXsn3j4uJi0ZaOj49v0+aQdE6y/IB0Av8L+agJjDcBeBRBil16Cn/5ozif350u5jPW6yTdX3fhCv5Lrn9jAr2xHvnfZP+Sbvl/5PQSvM8TRsqvKX8m3Um8GeU7XcxosJtE3WtibsA7oc67Sr0/KBsNTIGeYfRGL4l0Zrfh3U2MGeU7XcxosJtE7RQBYCz1UP8RnWtIUyBX/09TALoFjDtdbEHJY77FjS5nAEkgHIGh/xPSO8qvEn9KObh1XI/I57gFWBmqnS5W1DGLP9dyAGqISeOh2nvSB8qTcgLgNewX+z3Koz4EBJ8Hli9I0n2SW64X8OvRmNdb05R00Vq4GTeI8yadeWmrziPPfs5Uy7UdgJ3EyeNBmobUy4S035IEThXhAeBjylMw/tfgfJh0QtnIxQjsIeUwmOla25z2k9FFW9nmXJ9x1eDrB71u1130nPene20VZKek/0jVQ7NkQK5MoyewO+FdPTWepf8jrxh2+j8kPet4A409efHQBX0ZDah3B7MzRbl70cU1ZewsQ18Np46/QQ/ONw96NfpEabEIj8K7OAAnneHnt9Qjuafq8v+p8EZZjBPeld8V9a6JssakTCXpJp2bupD6/QrWensHU4esQ2tNsV2furiOjK3xF2gwdfx1lRiNL2MK1xhz/2fq9BSA1o9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vmOzofpisYjzRDt/Tnm5T0Fv6SqnEFbwgh/2ONEMIc4p5+2AdUZEpbA/QeawxybXsFz1nWzqZojQUgekE0jvaVDMlPCU0kW+UcFCV+xOcJ/3+3TmOyl90Wl/26Su+ItiRC9Ghi4Q1UXDeZS/H+nlY6CiUvwmnTMIOpJrHwKOWR1Dy8j9dQRO+E6HaUPjH2Js94a46Uzv6T6svhf73VSxNRk1dpIRaiDKhrVGSCc/OJ1+t4a/E7oCjXYRQAGl7rosrwEM/it38YOu8ISG3DMS3w/4Zd9bHs1077BzANMdu1kjx9DdUnkA6Mrv3t8XW7a99+e206b/AZzWbJZJbnE9AAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle x^{3} - x^{2} z + 2 x^{2} + x y + x - 3$" - ], - "text/plain": [ - " 3 2 2 \n", - "x - x ⋅z + 2⋅x + x⋅y + x - 3" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = x*y + x - 3 + 2*x**2 - z*x**2 + x**3\n", - "expr" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAARAAAAAYCAYAAAAyLqLMAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAH9UlEQVR4Ae2c7XEUORCGly0HgLkMIAODIziTAR8RABlA+Z//uSADjgh8OANMBIAzgAzwbQa+9xHSlFbWzEozOxrt1nSVLI0+u/uVWi3NrO/d3t4ucuns7Oyh2pwo3CiQPlY4V/614qpJPN4Xg6eWSXiHXil/9Sc5/501MGsgVQMHqRWDeu/1/EuL7h/yFb9V9FXhkOfK6b34feN4VPqj0j8UHrm8OZ41MGsgTQPLtGp3ap0r58LL/UtpvJFdoNcyGnhPjjCGD5V35DLmeNbArIE0DfQyIFps1wRviGdKsxB3gfA+vg9hVLK7o8+QbiZvuy9y+IrcF5l2RY5eBsQBJiHfKuD+f1RsjjOurNYYPhX8+w4MCscx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aUxvXGUzzvK6htV1LeodgMFLW7eRUeSDeL9ZRqAnJc4SgQXsrVw2QmJ5KFHY4fFia9es7svlj1GDbKw2tENvMmSjFHB74PuXO2L8ZoxkDis3psDjLkmav+uYRkEu70YguA5Hy7D54VF8QhNhgKvsvhM2yOZxiTye4+NH4uVY/N7IFkQmp3BT7Oar6vyOyimup2YfFl4V54VDM25afW/yeUg0MYLi6vAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle x^{3} + x^{2} \\left(2 - z\\right) + x \\left(y + 1\\right) - 3$" - ], - "text/plain": [ - " 3 2 \n", - "x + x ⋅(2 - z) + x⋅(y + 1) - 3" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "collected_expr = collect(expr, x)\n", - "collected_expr" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "cancel cancels" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAAAwCAYAAAASA1QFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAE8ElEQVR4Ae2b7VHcMBCGTeYKIKSDowMCHVw6gKQCoINk+AX/MtABpIIMdAAd8NFBKIG5Dsj7GEnjM77z+UOWNHhnhOS1LL27q5XWx3rj9fU1a0pnZ2ebeubEPDc19aH486Zjjf3rNTCp71LZ41wGObZ31L5U+1Fl2/LGuj8NfGo51JEMMys8e672VLydAm9s9qSBtkbCix56wjAOU6OBjTZnUnlMeRCetK86yHaneTkXfxlcu6pfuBb/yfCSqISXneha5ava7nxveyY5oc3A+wzsmAM2ND8GulT9zU6rNovmEZ7KneXHWAsfQdgfFRYWCwx5FqjtdpcPogkYEIUsWH5hhjUuNM5M5WiNrlVdmN8FMXTQWHgVK5FV6Z264Nezc5UDFWT4WwW2tZE0KAZiS2G1MhGBA7w2xGqitCECmH+au/w8HrTZAVMTLF3w187TarszghN2YyQb0bES7LlQO3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kC/dq87zdHfJMymeU4Kx2tjKXcCleCrnmwXB79yQMIIOQoZlUrnlMuIfwJFYghXRlDLZwNojHPaK92Cga3JMBNBN1HvYK+aPBPUh0t0IR3m/JU5POM0dBQ2x33g1RM8Fc9ynJ0n9j1Ca8CHq+ugAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\frac{x^{2} + 2 x + 1}{x^{2} + x}$" - ], - "text/plain": [ - " 2 \n", - "x + 2⋅x + 1\n", - "────────────\n", - " 2 \n", - " x + x " - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a = (x**2 + 2*x + 1)/(x**2 + x)\n", - "a" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAADAAAAArCAYAAAA+EwvfAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACOklEQVRoBe2Z7VECMRCGwaEARjugBNEOsAM/KlA60PEX/HOwA6ECBzvQDlA60BIYOsDnjbmbHHAqQxKOmezMks0mJO9+JMct9cViUdsH6vf7x+Acw23keYa5kQlVbAHaBNcInsEncAsuUHADANFhxxbtsLDzPzrW0xeainxLoygU6KDQC9ORF8VBKIYBQYBni+YpRIjkpRs7cEp7DSvnrqxuwpwXK1emcSMwAOCjGHQTWIenQ/+OVsYN4MqRiQAg5XkX4Jz+OawoiA5hd9woq/CRpdA7Rnw5gNrIU3QypEZrbgJnfEVkzhNK3TjLJOO1Rnd5gL72+HPtNd/LVVkEprnmR7ikeVjS/dotASjgiqSuUaWmd3LPgFmcjeRF5Xx+YNE1xd5397BgwwLTI1qH+I1WoZ4juyl1T1+HuXKkCMjj4pk1Ro/tnNBpTLfSrunIAjBnKgPTQJDX9ZgX0BqAu/ArrEP5AcuwPJ00Jyaxt7JDZPDRjtEpO4RxWA/9a5RN4h5imeqZdBWb69jzuma54BEIAdpdc+UadQf3QU4G7DpKKQIpAlt6oN7r9fajrlJiaHoOlDgmmjrdQtFcXbJRikCJY6KpUwSiubpkoxSBEsdEU+ul3ivxDqz6UbQicYgUilok9hoBvB+9SOzVAFJn6yLxpvnsNYWIwLoi8fOmoDaZ79UAd2OMUSVNBzqv6umAi91528reUsgCi14k9hkBeVwctUjs7Y3MRkB/Q30qLejr/zbVRc/gYEXib6xXwjwbBE1JAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\frac{x + 1}{x}$" - ], - "text/plain": [ - "x + 1\n", - "─────\n", - " x " - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "cancel(a)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "trigsimp simplifies trigonometric identities" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAAsCAYAAABrCeaiAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAF70lEQVR4Ae2c7XEUMQyGL5kUwEAHoQM+KgA6SKACoAMYfiV/SQeBCiDpIHQApAPogJAOwvsYy3i/fE6ye/ZypxmPvbZsyZIsa72+W1xdXS1qTAcHB7tT87UKGlPOYXtRIRweHr4RWw9WwNqup7UCUuOT2MIyagIJc0/8PFb+NsWX2lHua+WvU3jL2tQfQ7lU/mEZbol2P88T0X6o8mXMw078ULos5u6Ih3fKH2bwwoTOM/CSKKJ1pPRd6bNSQzjJjhM2ig/k8FHpQumR0q5SB6pSnrh7r3Tc4bJVocmxWsYEaEL7Vqt4LIa8Ee0znp9r7xZS2573XMwm3ZfamQgrZLRV4mlCG4ufDVSjPAmOve5nhuReeGFnoF4LBdrPr9WjMHJwm97qcB2xRX9V/anxGOH88HX3lZ+o/kuEw8p4qsQ4ZskIfNk+9kz4YRyVO6AxcJdJt+p5fOU7P1b+Uok944Wva8zJ15FBGx6SKx/EWsApTxNmct+VXqrslKUcBaCYn0rnSiiFIOEZdcodqHxGmxI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73oxVvFHeRnkzlsCMWd8pzbs2+F3xYB9I+WBLlMZdmJV+WSgthzb9HLkUVZ5nkO+BfHNzoDKn+/x2gCuGVXxb86zlZhzvkW4MmjcGvVQupfe8zicgMW4fe+1j5I2FUKIjBqd02y8UWXIprTxecrld1j6FZ8VxYwwLXEfIkktp5aEkbn4NuZm2UtdFkVlyqfKERcrkPgkn88kjqnXRpM2zLZfSK8/4CrkY5CIS7tIi0NC2zoU+uVSnPCmIQCX3ivw66bMjl6rcpqzLXetTHl4d1kk7Q3Mdkks1K08Mcmnn7kZxTRWm5FKF8sQgn1HuKw/fulRe6S2ypsjqeFoml+LKE4MEKH1/3YFC+z5o1iHZibnIkUvRPY/VJRnwG76+YzDuP87qBvNY+syVS9GzTa84FNh3SXWdD6Yx6KVy+QMDn4otKgG6UAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\frac{\\cos{\\left(4 x \\right)}}{2} + \\frac{1}{2}$" - ], - "text/plain": [ - "cos(4⋅x) 1\n", - "──────── + ─\n", - " 2 2" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "trigsimp(sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4)" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAYCAYAAABKtPtEAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADh0lEQVRYCdWY61EbMRCAbYYCIFQQ0wGQDqCDABUAHcDwC/5loIOQChLoADrg0QF0EOIOyPcpkiJf7sxhmyPszLLS3j6kfUgy/aenp14XcHx8vICfw+hrEOkO/GEX/pt8zDd9eAX+CZvdS3YZf2V8Cy4n3lvQuQ6d7rLp9cLfCeMBvJWC1/mwywCY/Ztpd0jAUvu82FSdbmcBwPkZWPa7AXmAd9d2J8juIztNxVhx2sjQKgAoqfgL3M2aUwyw4yY+g6ttzaCj/BL0oq1OVQ7dK3nQvI9WAUDHsvMUb71gZGsB59qy/1cZlxVRKy8TOX0fQg8ahVp+wMYponvRZq9VABA2covQfIq39Dcihr6bP4BugEPnkTciVzMxYN4aswJtabPX7/Ad4OZ1XGbRgBqQsZXAd9tvEdmZgTYx9rHLd4B3vqUszcBCxlYV3+39h6wwu4E2t0IAcOKh5B1tJlyksA3fPjVz56D0ivkmtAdV5xso/wdoSblY4RN4jYz9FoDxpBncwEA4vKKpEYJd15sONf3ugK5pGxRcR93Bqc2N+WjAV5qOMjAPmYEaKQNRzZzXl/x76AdwhXHYMNTg3EIvwGmzt4atcf2fX5j48oozKW7a1kq9XhcA170+xx8drCGcMs80QNXpY/pQoW5wHf3shHG628uXX0Wt9dR11frGj5kPh1m0NoRahWdxbmLK75EdiDYHVoBl7cSDxrK4BM1cLl/mz8FNg0A1qA1iY9luwo3VwQ3rLCvMa/oOXpCHhnatU4Sn3oIVIKjohgegEbtHuVoBsP8vYI2p0tLCthh8T5NnaAjsHEbcdA9qzyyDfab2vz9e7OW3Bqvz2UpirbabcmUrLsBv0pX/aAW4yXSKMgzBsIc05Pnw1mCphiSVC3Fj4GXcuJ9Mmo+rsiV8PQ5LvWJsBTwYAEHBaqScV6+fqoy6GnpNsMy93qpgxsXHuHYrJQM8v11nxr+DcF70j46OFPQK/FnILDE2uh6QVsghqJxgUNJdK99T1yjL/wKaLbOhfOBjY9xhhFgzRP/n0JF/nDA3GeG8Upv5Keha3ItXtoHJ7cB8BPjmNbjX2VN4xPsLJ3Gxm9DqofdCS3/EsWOSTPByaoGJDHWoZKatqlmBv0e02e7X4Ky8TmqHTHkot/3lONZNzL62wmPpvVSAm/IcmcXbRBt/q8mfw+8FObAH4P6k61VXG6X+b+ho+ndKtZv1AAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\sin^{2}{\\left(x \\right)}$" - ], - "text/plain": [ - " 2 \n", - "sin (x)" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "trigsimp(sin(x)*tan(x)/sec(x))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "the tutorial discusses some of the nuances of simplification of powers and special functions" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Calculus" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Calculus operations are simple in SymPy\n", - "\n", - "### derivatives" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAVCAYAAADhCHhTAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADLElEQVRYCd2Y61EbMRDHD4YCTFJBTAc8OjAd8Kgg0EEYPsG3DHQA6SDQAaQCHh2EDkLcAfn9NNKNOA57ciebGe/MevXav1ar1Urn6uXlpVpEPjk5GXZdV5vucrWAdHp6+o1lrfdY2jBi1BBLen2ehAFD5nuAjyhflp4bzB0wt5BHfbDR19njZONHRJSOGsAbfRbSpsuixD3u6ySxwThHHEbMau6OYuJbDFhFHmpQYToD76IgplhiVnM/egUX8QYK5/+FV9909GgQE/Uvc4+oHjZPVGVB5qaniYO6dYq5t9JN930tDPa2GcFj2Jwh7dO+AZufrmDlLfVdZIVU5wds+0/YcHfh0hZ8xxhzxiTaptNj3Uroa8tB7BTzK+x8+7HNOa5jORdibhd1VDTmDKnRNVEP+Qjp7ugwb72aqD9Ssf038hO8Tjk4BqkTH5DX8KSI2WTcpPykXckObzQ3Rud4+6Zc1OYobRot81OSNHaTiVMkJezmAp5TR0PqiBH6tcGUdaJklE4i52zFBcNICkk5AoyRRmx6nrg5eX8cFoSYw5W4qF9UmovLBzfLu9kC6j7aPE4Cm1QN2RvYSJh2bGoMCvd5JStPs8/F6oA2useGPBp9mjzSFsYjQwpoU6RNvYGOcnDJN41Yx7A75i4Z8pfwLJ4DwE8n5k5RmQbvUfieKlNk2ICiRw+Dhk6K9NyvwUtUddABZXPNLMlIHkybADs8wo7Lj/eA9vd0bX8u6igAdUa6WSgGp5kHNMr8NUvyiISNyifRAfBNdJBdbpyfJvlR9DU/zvWyshH1VNpR4jtpc3esN6/u5hh1Naoreby89ptkBMnP0S4jryba7LurG94WQj4r+jKPk/o0+JPN95myO2qiN+LMXxon6bz0nkl5zZ213RxihBgBjg/tYLQm3oh9hVxjbE3U3RBzpdd8Rf0cNn9qp88UHVgfQ+qviD71Dos66tUMH1CJi2q9kbuYA54b5SavzeLodbGplI6RYwSWIv+qCe+rhXIUO+/F4Z9uRkIvihhihUfpQjkqesYc1vwS6OI0MeroXKgclbwRo2EH+T9fBEm9Qs9vwVfflv8AnFH7HLy1ZWAAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle - \\sin{\\left(x \\right)}$" - ], - "text/plain": [ - "-sin(x)" - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "diff(cos(x), x)" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC8AAAAWCAYAAABQUsXJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACuElEQVRYCdWW/1FbMQyA83oMkNINyAZQNoANaDsBZQN6/Sv5r5duwDEBDRskG1DYgG7Ajw3S73Nsn5O8R2ggV57u9CTLtizJkvyq6XTaeeswGAwOsLEL7oA9cIRssgXTBtDY9xoK1YkHsHqnoAWwV9ho9B8dt8J4ov2nMH4I/8lx1YacT4bjxBn8GfQmyDS+Ddjv94dgV1uhp9I3EXkieRqjaycxLY7AwJsy4DXjXTCBst5/j7pRBHdiREfw48hfwx/JN2FolXhhBX+Lbn2E3jtGPsutOLEh8sg5qSBtg+N4zvGq8yu9ZrFFcJiMg/fqvMpD+EmSb5pyli9mD5qcefJIW6WGnpSr2Owt2EtHpXyTPGea0/kWGBvUJ0HjfXpvWeyVlWDEu89RUm76F17doK+l8AUsI57SOEzWfcx5jdxFSXi1ahYtOlWzZD0RZ9o1foGmaMj1yKtwpfGNrRIltygwMpWaBHgd+RoGnc4+9Bj0eo2acMWayxk7+8Y93xndRbkt0GbQFKy4bDUxbZYAxeafRi16P2Tup8jcFXgOHjB2nY5ZPxmQm5L26Itin6+kzrwYQqus0WKhXkYjwzS8ES+NM3I+JkZf2AbzPOt13lQ4gS9brg6ldgi7PiwZz0FGxlwMPz+F6t/IyoLyT+8GWbj+mvXqESz69IJ+YDxm/Crtd854lBrdbWju+Z4uICujp+gz+EOmAYzw3O01rFtbnHMe48L/BDRHHN6C9frnAJmGmeO5OJEZYWUlWBcbg2A8h1qg+9DFAtWh+2iY163Rgo9aflCChCJkPqRQHJtipskSsE69L4YtFBlZC3QCn/I0KbaT2F08TMNtcUbXf58MyJxbjHLdy+1e5bmws5I1GP9tQj9v2GtB7kWDPdC1HcbJIWvDVujt5BRyjYDMQjX6YR/U1LLNvgr8BSEfD4cQTku6AAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle 2 x e^{x^{2}}$" - ], - "text/plain": [ - " ⎛ 2⎞\n", - " ⎝x ⎠\n", - "2⋅x⋅ℯ " - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "diff(exp(x**2), x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "third derivative" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB4AAAAOCAYAAAA45qw5AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB7UlEQVQ4EZ2UMVKCMRBGg3IAxyNoa6XSU+ANFE+g3kDGClq8AdjZOVLaaUGhFcoN9AjKDfC9+IchaCzYmWX/fPvtZrPZUJvP56HX6+2EEDqocoh+oh3wqUBJ8O/ju8BelDglfBOHmw4IbjebzQd0OB6P98BusS+sP0rB+J/xzeDclzglfANHH80qpghPP0OLCeFc4l9b3LiFvpNoayXLE+stcDuSCZgttjB1LXFjN/ggWSnJakFudAp/6Me6UifBSSHYUwX82YCxtsWDQkyE4VjsecVpYM9QO3daYRNP/EsIdFOJadIjB1xshi0OXCQyN3CuVdYT9AZtsTafRfX/3BiHQzWqAvlciE/n3xbj96QObBKv8BhNcdt89+vJmyyBttE7z66gSvhvi6scr3CXO3IAPgWzgICNebMTA1rtNvZIUhLWttgJX06Y3JmFk80EzjZ6l5FY1PznUgiwHQ3s4l75dkNFm731iP600JOkl7GI1U+8T/UR3eU7Fo31jkNsNQuHKdtUJxLvpgoyeSbgXwBP2Ng+rEmdD4dLvsWuDuMVvk6dH08j2QSrd9gCczJL4kbxBBXBE6r+z4v7n78QMH1Oeah1u913bGqp2LI4FA5HJmAWaIyJlBFqQifXiTZngOeTsmvOzBv6yVpu+AZy3MLdfgvCvAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle 24 x$" - ], - "text/plain": [ - "24⋅x" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "diff(x**4, x, 3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "differentiate different variables" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAN4AAAAaCAYAAADYHuIVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIjUlEQVR4Ae2c+3EUORCHF5cD4JEBl4GNIwAygCMCIIOj+I//XJDBHREcJgMgAh4ZQAbncwbc92kllXb2NZrVjne57SqtNHq0Wj91q1szhhs/f/6ctKRXr17dhN/LyPNuzJ9SfzVknpb8WvIaspbDmAMCCYHjVEg5yvmM8g/yj6muMn/N2OdpDOU/KX8l/ZbqKvOW/FryqlzGoXsrBNSpUsda8R2Tz1E5GYt5xPMp+VCjk90zxj8o+L6mfJe6k6KuptiSX0teNWs49G2LgAfoh7Ysx+WWPR4LCSEi+emGIujtvmzIoxzekl9LXq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Ip/X2x3DjfWfhF3KOgcZV80uZfqXTeasespKeHl81JyPEk9V+f88C75PGOM0+rt/t7wv35g4n+ZxlfYvRawDZGYWzBURIHcC0JWjXzQy5UxFzg2tmPiwlw6AP/ZziKjHBPmqrmOYu935MFjVI0e2FlFiIAFDpR1936vOh/I8rqGGSF0o4TrkiXMuyPYjoJL1BvDZfV3r8hQUzLc+USau3fYuAXSU5QhlqGhYcDQsHULIq5nibzXFiGskO7asR0RFz+tLHpBtQKe3WgKoaaiAJaxtX9Gs3XlZw6Vw0uzns67nXH8Lioxou0X/Z+wZa3e07wTewfcKyoNTyP4xCL25o61V0gfhG2KAHrq1cQXI/mbbdMJtswsG57zsAg90Rn5WCHnlpd3YP8rIoB++vbXFyqjvZdojWN6uRL4shDDzO/k6VVu6/kO/A4ItEBAx7Cr32d7re8/A9UYRZ+ZVbsAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left(x^{2} y^{2} z^{2} + 3 x y z + 1\\right) e^{x y z}$" - ], - "text/plain": [ - "⎛ 2 2 2 ⎞ x⋅y⋅z\n", - "⎝x ⋅y ⋅z + 3⋅x⋅y⋅z + 1⎠⋅ℯ " - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = exp(x*y*z)\n", - "diff(expr, x, y, z)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "unevaluated derivaties can be useful for building up ODEs and PDEs" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG0AAAAyCAYAAABWIFV0AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAHY0lEQVR4Ae2b3XEUORCA1y4HYEwGdxkcOAJMBoAjwM4Aiif7zWUyOBwBmAyACPjJ4LgIjnIGvu/TSjrNWmtm1rezs8x2lVZSS+ppdU+3eiTt1vX19WSIcHp6+ht8HZB+kCzvk87AfyMfNewMePbn8PY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p4QutBMNL+FoYY0gJz5jnrcpn7nyct7lh2mFfTgzmbm3jOhv6KzQJnGsClbYjskRXtHehbZCTfS89eQ3W/h2g3ZpGenZP6XNOGkaGYYdeuqG/c5ZC/ZT5gf17CqpDxay0gbLIYwhTIXtumm0N3owEBkUqCBS/oinrIVoZWeDYnSFzAxOachCl/W2kIlu0n+ZrIXrKvheWnFw7hHlqDSDEC3Mtcybt401Etyo4V/CXYppc9cADAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\frac{\\partial^{3}}{\\partial z\\partial y\\partial x} e^{x y z}$" - ], - "text/plain": [ - " 3 \n", - " ∂ ⎛ x⋅y⋅z⎞\n", - "────────⎝ℯ ⎠\n", - "∂z ∂y ∂x " - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "deriv = Derivative(expr, x, y, z)\n", - "deriv" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAN4AAAAaCAYAAADYHuIVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIjUlEQVR4Ae2c+3EUORCHF5cD4JEBl4GNIwAygCMCIIOj+I//XJDBHREcJgMgAh4ZQAbncwbc92kllXb2NZrVjne57SqtNHq0Wj91q1szhhs/f/6ctKRXr17dhN/LyPNuzJ9SfzVknpb8WvIaspbDmAMCCYHjVEg5yvmM8g/yj6muMn/N2OdpDOU/KX8l/ZbqKvOW/FryqlzGoXsrBNSpUsda8R2Tz1E5GYt5xPMp+VCjk90zxj8o+L6mfJe6k6KuptiSX0teNWs49G2LgAfoh7Ysx+WWPR4LCSEi+emGIujtvmzIoxzekl9LXqWMh/KICKCjRmQXpD9Ib7YxtbwjXyM1nYdOKZRpc36di87kjPJj8kCUlat8ts8FyauW9eH6VXo8Gw0LNyIm/YtU3udUdgX9NoRxS34teQ1Zy2FMOwTcS7g9J9dhNCV4anTvyTXq2yRDW8v3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2FlFiIAFDpR1936vOh/I8rqGGSF0o4TrkiXMuyPYjoJL1BvDZfV3r8hQUzLc+USau3fYuAXSU5QhlqGhYcDQsHULIq5nibzXFiGskO7asR0RFz+tLHpBtQKe3WgKoaaiAJaxtX9Gs3XlZw6Vw0uzns67nXH8Lioxou0X/Z+wZa3e07wTewfcKyoNTyP4xCL25o61V0gfhG2KAHrq1cQXI/mbbdMJtswsG57zsAg90Rn5WCHnlpd3YP8rIoB++vbXFyqjvZdojWN6uRL4shDDzO/k6VVu6/kO/A4ItEBAx7Cr32d7re8/A9UYRZ+ZVbsAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left(x^{2} y^{2} z^{2} + 3 x y z + 1\\right) e^{x y z}$" - ], - "text/plain": [ - "⎛ 2 2 2 ⎞ x⋅y⋅z\n", - "⎝x ⋅y ⋅z + 3⋅x⋅y⋅z + 1⎠⋅ℯ " - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "deriv.doit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### integrals\n", - "\n", - "definite and indefinite integrals are supported" - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAADcAAAAVCAYAAADiv3Z7AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC+UlEQVRYCc2X61EbMRCAzx4KMEkFMR0Y6MB0kEAFwR2Y4Zf9LwMdJKkggQ6gAx4dmA7iuAPn+xTd5Xy+nF8H9s6sV1rtrvYlyZdMp9NkV3AwGLTX9aVMt5nsCAyHwz6udDZwpx1tZCYaZmoRoNRG5gm8YPxtkfyq69j8iM4x9GJV3bw8+iZokvq4bOUMrgUe5o3VMcYR7V5uGpi+YOMa0os2k6WCQ/gepX1oTyM1wxX2vtZoU1vaTJZqyxo3njNFwn6D+3MLGzC0ifqHpSq3wT6VqjjhWXupFFpvUZune+qyibdUF5yAngHhDP4h6Hm7AaX3zD9BE6g630H5P0FbQWeFY/ABGc9AFZywaMuXAvr6ch4XtfkZdL+zyHOP2zjOE22e7EUDV1A3yoB5OF9Qs2CQ3pYZMH9mIn8EfQd2GIdgoAb+BL0FqypzhFzVedOv1A9vQpNpQN7a6dkqC06fuk1+3OAI4bRiTAMUNx2nCwWq8130s00YG7hgN1SBe5baxYYVCxdDNDCB2hnpU2RC8+tRLBBttq2crebEg20570AzvqilEMvgMRvNDooJm139W3GdLoNHfMhX3WfoGV6Qh4bjUaYIT72WlRNUNJg2aDZGKBcrB/vtgP3T6qebnjL4kU4WUKs6aWLEgBKofXwANpja5+eMPTuvCXbMouom+GF7K5dv/Rb8/+nKH1s5A0hvJIYhUPtaQ57H1wTbJyQ3v4lOg3cxKJdMtn+r8m3qv5pJXi83tnIvBicoWMyC8+I1XZRRV0Prgq3nFV8EKyWOo19WOAN4rj1kjPlBOJ8NPhUU9Bn4lZN5z9jMedlY2UtQOcGA0/dGvjeYGZT/BbQSZlr5wMdG6eGPtm+gB8hmwNwkhrMvk/k16D766ZNk0FmLMp8B1nwKelv/liO5I7Cz7ndcUc/vOm3KT9tyJvI3nlghK10X+Nmkze0HRwt5efmhOXex6OAqEG1oKzz0u1A5/fdM1vGuauNfFxR7dlvzeFb66+6Pfl8bef0/1bbeJKcj2h4AAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\sin{\\left(x \\right)}$" - ], - "text/plain": [ - "sin(x)" - ] - }, - "execution_count": 67, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "integrate(cos(x), x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "definite integral -- note the construction of the infinity" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAOCAYAAAASVl2WAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAZElEQVQYGWP8//8/Aww0NDQYAdmrgdgYyP4AEmcBMgSA9GwgfgfEJkCsBMRwAFIAUhkKEgGyy4AUyBQ4YIKzcDBGFUACBj0chKHhJQQLN0ZQZAGDGBRBIOACxKC4OQfE94B4NwDm+hiAOyllRAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle 1$" - ], - "text/plain": [ - "1" - ] - }, - "execution_count": 68, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "integrate(exp(-x), (x, 0, oo))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "double integral" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAJCAYAAAAGuM1UAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAtUlEQVQYGXWQsQ3CMBREE2AAZmCECHpLkI45YARat1BSpqUCsQEpPAElZVpaOkrzTvKPTKR86XT/7t+345QxxkLlvT9COzCXHqmm1EIKK/MAWliBK1gm3cLKPadwBb6Is3OuCyFs0Rf0i35N3yrI7E1fzCRgwarGOyWhmxobiCe5IKjbPplX4eX6f4HgHugdVgtrjPsbOEmP1V+62VCMv8l1v4CpcDf8BLx6bEGDQz6kvw908QNYwThArcyywAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\pi$" - ], - "text/plain": [ - "π" - ] - }, - "execution_count": 69, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "integrate(exp(-x**2 - y**2), (x, -oo, oo), (y, -oo, oo))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "if it is unable to do the integral, it returns an Integral object" - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Integral(x**x, x)\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEcAAAAuCAYAAAB6SwSNAAAACXBIWXMAAA7EAA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2gOonyNx11fSjFaWYUu4BWLTFdZ4vsMFY4Iqh8ISWvARrjMwH8z8ZGkOxTEzgEAgUxyi7TKmlaVpaMpya0ktFqAseScX0XKBmTKrYmcHrxSUtqVcc2VKaCExMXycv9ql8KcFPBUYDGmnBOKCVgTxyzwOlGQ63MN8Q+Cxzbulu5UzWBw0myftSnT2tkFnNYVq1lDQyYCI52qlafb2xpTARHN1lSyBNz7nAY++W1gfNN/RPA2EOlX8xizoO8LT9mAP8BR2xhSXEyHvsr4zEHmev7ssDgK93oVz6+1vEfEt9CWi0rip6dKXyhEyDUYc5LaevlWb/f/ykUeqenp69V8g/klkD603pkBMBfYO1+aae6+o4AAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\int x^{x}\\, dx$" - ], - "text/plain": [ - "⌠ \n", - "⎮ x \n", - "⎮ x dx\n", - "⌡ " - ] - }, - "execution_count": 70, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "expr = integrate(x**x, x)\n", - "print(expr)\n", - "expr" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAANMAAAAqCAYAAAApmm4IAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIDElEQVR4Ae2d7XHcNhCGKU0KUOQKInfgjw7kDvxRgewO4tEv6Z/H7sBxBbbcQZwKZLuDOBVEUQfK+0BYDgiSd0fyJILWYgaHb3D3XSx2Ael4O1dXV5WHshA4PT3dE0UvI1WPlR4pHii+iHXn6vM55j0pBIHdQuhwMpoIvJWyvCOq+lzxg+Khyq+VomhvFT0UhsAvhdFz58mRwmCRUmW5VPmpItaJsK+YtodK/5gfAVem+WWQU/BVCvUjqXyo/HfVoVSV0mdJm2cLQsDdvIKEASlSlu8ZSc9V/pjVebFABFyZChSKkSTFOlSeM1J92aC6PaL18bQcBNzNK0cWVVSSM5HEBcQXpa8UL5VP3b5jlbmI8FAYAm6ZyhIIloh4ERX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RKBwiARXLwoE1tTCqaoYIIqDO9nMoooFFPurMpLEsFgLKALgsGnjG2taXIwmfAM+Fw2NFrvPDIkvaZ8NB9EwO4sMUxBZa629H9pDY1/qxyBaFh+hnnbPe8+t8Y7FSn7XrY5UysTCZgLPSlFuwmqCbzojO0cp007T5/D8/An1uHpqICWe3TX3k0hHBWhA9OAK3jsD/FMlG3/BTwQcAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\frac{x}{\\sqrt{x^{4} + 10 x^{2} - 96 x - 71}}$" - ], - "text/plain": [ - " x \n", - "───────────────────────────\n", - " ________________________\n", - " ╱ 4 2 \n", - "╲╱ x + 10⋅x - 96⋅x - 71 " - ] - }, - "execution_count": 71, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "a = x / sqrt(x**4 + 10*x**2 - 96*x - 71) # example from Wikipedia Risch algorithm page)\n", - "a" - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQgAAAAwCAYAAADtqOSLAAAACXBIWXMAAA7EAAAOxAGVKw4bAAALN0lEQVR4Ae2d6XUUORDHx34OwGsiADIAbwRrMuCIAJMB+/wJvvlBBiwRcGQAG4GBDJaNAK8zYP8/jarp6elDfUxP90zVe5pWq3VU/SWVStXHHPz8+XPRlV6+fPlBZb8r/FD8ddd6vJwj4AhME4HDrmxF5XCl8p8UXun8vGtdXs4RcASmiUAnBSFlcE/iPFT4S+Fa4UYBS8LJEXAEdgiBo46yXKjcZykKFMM3hd861uPFHAFHYMIIdLIgJA/WA1sLJ0fAEdhhBFpbELIaziIen3cYl70QTX15LEHNd/S74k8V7ig8UYCulOfjMuq/+4hAFwviEUBp4LC1cJo3AjiXXxMkBg7ntwpnOv9TR5THKwWnPUagtQUhrLAgXDnMfNBICWA55BUA/iS2jlgR0IlC/npI9J/9QqCVgtCgYlXBBOXuhdO8Efii/szfebovcb4pDUWx0DFYivMW0bn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tDlSW1gvrCa0ied7tLa7SCX+WNU35qTswpOXcQQ2hcCRBjxaLfgANtVIQ71sKdCcg981aWi362XwIjg5AjuPQO0n58aSPloRk7cexsLD23EEpoLA/88gSEXwfcyfAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\int \\frac{x}{\\sqrt{x^{4} + 10 x^{2} - 96 x - 71}}\\, dx$" - ], - "text/plain": [ - "⌠ \n", - "⎮ x \n", - "⎮ ─────────────────────────── dx\n", - "⎮ ________________________ \n", - "⎮ ╱ 4 2 \n", - "⎮ ╲╱ x + 10⋅x - 96⋅x - 71 \n", - "⌡ " - ] - }, - "execution_count": 72, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "integrate(a, x) # this has a known solution, but SymPy fails to find it" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### limits" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAOCAYAAAASVl2WAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAZElEQVQYGWP8//8/Aww0NDQYAdmrgdgYyP4AEmcBMgSA9GwgfgfEJkCsBMRwAFIAUhkKEgGyy4AUyBQ4YIKzcDBGFUACBj0chKHhJQQLN0ZQZAGDGBRBIOACxKC4OQfE94B4NwDm+hiAOyllRAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle 1$" - ], - "text/plain": [ - "1" - ] - }, - "execution_count": 73, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "limit(sin(x)/x, x, 0)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### series expansions" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": {}, - "outputs": [], - "source": [ - "expr = exp(sin(x))\n", - "a = expr.series(x, 0, 10)" - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 + x + x**2/2 - x**4/8 - x**5/15 - x**6/240 + x**7/90 + 31*x**8/5760 + x**9/5670 + O(x**10)\n" - ] - } - ], - "source": [ - "print(a)" - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAqsAAAAxCAYAAAD9eeD9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAUTElEQVR4Ae2d6ZUVNxOGhzkTAEsENhlgiACcgZcIsDMwh3/+x7EzsB0BSwY2EYDJABzBB5PBfO+jkXr69u1FfXuT1FXn9O1NV1K9paVUKqlvXV1dnRmVh8Cvv/56W1w995x97c9P9fyyPG7z40hyQCZPdHzWwfUjHS/0/IPORgkhIJn8q+ObhLK026z4evOzAPjbg0Dd+aznb3YLijFuCOwAgYsd8LhXFn9TA06j7kjXf+jiXx33r5/Y78YI/Kb0P0kuf5IPnX/R6a2OO9wbpYGAl8uDNHJjuRACKKc/6aC+fNLxJtQhXRsZAoZAoQicF8qXsaUGXY04lrtAKEdf65l1vAGRbc8vlPzLWhbu6Rorq1EiCPj6g0JklBYCjyWbWzru63iWVtYsN4aAIbAEAmZZXQLVNOLEqvo+jaxYLpoIqJNtTvd/pzAMKIwSQEDywY2GgZ2zfCeQJctCDQHJh4E4MvpH1+baVMPGLg2BEhEwy2qJUhVPasD/bDTiKK9MOzeVpEIRyIMtyeMXHbhn/KGzKUbpiI2Zid/TyY7lpIYAvvhYvP/R8ZfkxEDPyBAwBApGYFfKqho1/J2KoDG8KCwWIhr0pBeJjOEpZSGO4UNhUYge6/hW1/jhJUljeEqSAZ+pGD4UhrqS1YKdGL5SlkvI2xAfeo8l9XsdDLyxqOJO8zr8386GgCFQJgK7UVbVsKEIlOSvif/poHKjMCjoTC9/4xv3JEtyYfKJkk0QhJcLvncsikuujO5JNuKV+nJX52x8VXcmn6YV1clJGNT980PVsrMhYAgUgsAulFU1ZDRw93TOzVryQHn+qAPf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YTto3N5RF4riSe1pMxZbWOxkLXvvPl6y5RzugLZcOi9QjQsHY0rsENwKa1NiotkgvKDlOLNv2/kQz6kpVc2IKo61OQ/NUGen0AlvkOhZVvxhsZApMRUPuCVRXDXmVVJVJbYDUZ2v4IBDjTynx7ubKo6tpZH3S2DrkfvqXeus5W+LMjQDWduVRiFu8oBKgbjyQXXGbq5Py9/XMaMjpIo/URYCP4zy3J3uWZ5GKLrFrAKfmRZM4+qrjt2JZLJQt6Bd5Uhmj/saryEaUDMmX1AI55bwQ8HSwdb7NjRYE1f7x54R4TGwoq21c1FVU6Yqja0ur61n7XQkAyAfsj/PWcT3wis2rQt1aeLJ0DBFBMmu0ZAZiNOJLbwT/tpmQEHos5fP6po2aEKVnSC/GmcsOsDHuqPm0rQ6asLgc8IwSsQ1Tepv/dEz2zRVYLYR8R7VFnK3kwgKCyYCFoKrERUVqQhRFANhxG2yLAJ6TdZ6RDNnTvFkPo3gYSAZSdnWkzdeDmhs//Y+53BoGxOx0BtxWays7B9H+I9tbV1VW4tvOMCAjwj4rOTfe3RMsq9CMzd0s4e7QQAsIfS1C9c0VWv+m5WYcWwvyUaCUPBnrIBnlBNGTv9NwGew6O9X+EPfIIAz6m/3ELeKbnpqCsL46kUvRlA59zcwdJSjJpZ0blBUPEQ507+9//A+T+BcEImFidAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle -1 - \\frac{\\left(x - 1\\right)^{2}}{2} + \\frac{\\left(x - 1\\right)^{3}}{3} - \\frac{\\left(x - 1\\right)^{4}}{4} + \\frac{\\left(x - 1\\right)^{5}}{5} + x + O\\left(\\left(x - 1\\right)^{6}; x\\rightarrow 1\\right)$" - ], - "text/plain": [ - " 2 3 4 5 \n", - " (x - 1) (x - 1) (x - 1) (x - 1) ⎛ 6 ⎞\n", - "-1 - ──────── + ──────── - ──────── + ──────── + x + O⎝(x - 1) ; x → 1⎠\n", - " 2 3 4 5 " - ] - }, - "execution_count": 76, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "c = log(x).series(x, x0=1, n=6)\n", - "c" - ] - }, - { - "cell_type": "code", - "execution_count": 77, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUMAAAAuCAYAAACyLns3AAAACXBIWXMAAA7EAAAOxAGVKw4bAAANNklEQVR4Ae2d25XURhCGtXsIYMERGGeAlwi8ZIC9EbDOwD48wZuPnQEQAeAMjCMAOwOcgYEM1v/Xo2q3NK3LzEgzulSd06NWq2/1q7q6+qKes9vb22JXev78+X2l+VHujzIt958U/nt5v4qL+P1L7ttVMNuDyVIurhT1kxwy8VDuF4X/rauTIzBpBM73rB2CfiOHMnwh940Efm2K8Cfx/UDO6X8EfpU3yILk4Tf538v9+f9j9zkC00XgzgFV+26tPb74xvr55wDslpr0lxpjX+keK9HJEZg8Aocow6JUChfi8p38X6bErerzQK4yPNM9db2n696KrMwDi/DllPidQl3qeKtOj+WwFp0cgZMgIJlkFIvx8kb+Vh11iDJ8qgJ+lqPnf6WCXstNaaj8p+qD8jOFiB86dI7vRvn+Vua9yXGCv6ofCvst/MqfFQKFm6L6V/G+kftVYXt3FEofSHkwhXAt90J+7zQ2sPjvjghIdlplWM9RdKxdQLRv7pHhdwSURB5M5SGLZVDl8kXhdwnZSxmWhcUCdc/w6C+5MzKdCNnwDDBo4ChqJvOziqFPnZUWS2dKCr9SbdUPgXglB++XcghHlhSX9wUegZ8yLQtCj+QOUohKT2eBEnyra8F9thIe6AjUEJCs9JLhMt7PupoyLOSnff6h6/dy1k5ZxENX5WT6SuEYdIH2VYaPk8LIKBSksCu5qCQ3RZzs92/V5fuhSldeKJaDhthD1aUpH9URRR94lr9xgUfPWPy60NUEppCfHpJ7etFHcgdRmR+ChoJlGsUs9IPy9cTLRgC5EYedMqw4yDCjNJSfybHpHkatFlbo+ZY8KywYCkna4lyJ9iF6fCwuo3ulJ6d9Lc7cr/RYrJRihjO8DEPM8p4eaU6EsOWUE6u/dGjwuhORRu6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mtO+Qxk+FB/sYUoJhQDAhDNxG+cp0kgL9IeOT/zelTPhWiCbztLMEGBarm0UakquKZ5Zhq1rHF3KsPMkjJmBWqmuGjzgbAGkcD5BfKcrc2ZrIhQgfNcVIZ0itIXVJth/HYFREWAaq26wUOC3cix8mlwSp/65nsVjHrwu1zyL1DpMVqw+J2HEzBbkuRAvuLURFjCHhEaSALFwAhYsMrUKU0zkHkdgQAQkd8xb00lHRSc/MvmDHH/YFUhhLLBwoAYyGygXz57Vr30OasA8tWEi5iYTlWxMXlzDEE/0QPBrc2O8BP4N7SgnHausk5N4hffUIgYPP6jh5G/GKyDZRBmiBCF0Ed8gV6bqdM9z4qGfWDBhe9hWPIVt0X/kuLBj3cZn6wAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\frac{x^{5}}{5} - \\frac{5 x^{4}}{4} + \\frac{10 x^{3}}{3} - 5 x^{2} + 5 x - \\frac{137}{60}$" - ], - "text/plain": [ - " 5 4 3 \n", - "x 5⋅x 10⋅x 2 137\n", - "── - ──── + ───── - 5⋅x + 5⋅x - ───\n", - "5 4 3 60" - ] - }, - "execution_count": 77, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "simplify(c.removeO())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## solvers\n", - "\n", - "`solveset()` is the main interface to solvers in SymPy. Note that it used to be `solve()`, but this has been replaced (see http://docs.sympy.org/latest/modules/solvers/solveset.html)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If no Eq() is done, then it is assumed to be equal to 0" - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAVCAYAAAAAY20CAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACgUlEQVRIDcWX61EUQRCAD4oAQDM4MgCJQMxAzEDMQMp/94/CDJQIKMgAjUAgBDIQyeD8vnVm2Ovd5Xa5urWr5rqnHzv9msdtzOfzSYTZbLYN74186B9RPuac9aest8e4g76Pa29GBkqf4f1M/JsoH3uenNbxM+hrhsktsFGvAML3SC4ZO9CPRatGwD9L09/gXYYfbmSmZrKUxN4Mu+5+17p+BNk16BF85FzY+ofK7wHUfddH4N8iPwVfaQE2G7fgd4xBQSTbc+wfGLarrbIM7lAwyQUaLVQkgWDBY1jb4Mp5xdBWyfk350NAW8YR4xN2F0Ns67q9A8DIspmBCL9gHOLIQm9GpXXNhwRwiBOWO0JuHeWjQ68Aemb31ejes2AMwDawryNk59pkWXeMFvLky75U65YAyPIUzgfG4A1ZfWkyeZ3wOpEHhgdJOYm2kuOe7QbgqdB287b1fnY0Z8TsrBXwzSN+h0XOwV/Ap5syJRg3jBPmjVaAl1unIcMm8/JmhrVW0HGTra9XVQtB+M7wPBa8XNrAymgYIVegrXJRd6U5Pto6PnXeQlfrVQHUvuo5v1eb10mvem/MCPswTECu0gQ6VyXqrjr3peAFWNaKAXQugNF3hA/gsoGSo278j9kw8f6AfXb0hXwA5Go+Z7ewH+Nb6DlDZWbbx5uZcNOKLaeVqwDaDLkfPC0cJVtJpSBkVlXIl+BlsvXVacKWwqAAkjN5r3R+HL1dRqlUlyI6Pk9Wgt4t9IJVDlLALzDtbxIDaNx0/T/1pInjbuJ13At+d6ElYwCNm+7JrUHUMUF8HWSxRDklpfFSWPhH5jdQnIJOGJ4IF8wN6r9B8sd9p18Nf/4C1uXZfvXxYfgAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left\\{0, 1\\right\\}$" - ], - "text/plain": [ - "{0, 1}" - ] - }, - "execution_count": 78, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solveset(x**2 - x, x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "you can restrict the domain of the solution (e.g. to reals). Recall that Z is the set of integers" - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0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2TYBmhuITcmZOWSw5M+Vvio+K6e1JG4Ho4oA6DmgGI8rLiuf+H/dp1cxVJ/3fpbRRv5l60yHtOP4gWWbzzpokGsU2HcC9LKH2sIX00blxwgYT8y8CYtw38Q0bsBHc6CIZ3vM2JXp2T7yeQnPfUuMNhZ+AWedZLG+8lMz7beXfwFMiYNuXG3zvRddJT/rbNEDdJpp2XEsNFJGkMhe792wBh4wWClK714WQxshysD4rWoxAKzAmuJgXpkGC5ZiO5E5XglNrz9ITRiqclSC1SwllkOUKZ2LExbDGLLH3pyuYd5b6UeC8xtztpjhmnZ8py2RRMLsjBZqHzyIksyvVuF8Uvmmq6e9YZaXmCzFbTtENyQ5qrGLFDBapZY/xncOltfXdUQWyAFVuZNJXOuWPds0vKqnMowh+2bHszGFrf5oSmwsv3CKUSlDAsIoJzCdW6dZYhWloQFZE8cJaGz2EyBlZUuV7v2ErpqlmcB2YgTsbFbZ55EjWZY4LjhYS87oBRYT8XBrRiO/up0IDDXdUK2YUGVc+vsWqjGBi0gm3LTym5bdW5mde4GoK0BKQsGzrw5776JUx9UbwTJHow6XOZJHU1y64x/+FAp0wKyFx3fTv6Ca4G+iuQ+q4SZt3Lbm2HuhZ5cKpi8d+i/aMPiubfONuyzb/Vz+FutVOdvX/oHAuUdkWuYnzUAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left\\{2 n \\pi + \\frac{\\pi}{2}\\; |\\; n \\in \\mathbb{Z}\\right\\}$" - ], - "text/plain": [ - "⎧ π ⎫\n", - "⎨2⋅n⋅π + ─ | n ∊ ℤ⎬\n", - "⎩ 2 ⎭" - ] - }, - "execution_count": 79, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solveset(sin(x) - 1, x, domain=S.Reals)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### linear systems\n", - "\n", - "`linsolve()` is the interface to linear systems" - ] - }, - { - "cell_type": "code", - "execution_count": 80, - "metadata": {}, - "outputs": [ - { - "data":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iVLzp0JuJL36VNqlnVQVKQ0U6q+ntSYl4DiwO+7a4xx+RJ7GN55dvAnLWy7KpS1UGBMcdFpmhXVlZdTmGjzJw0lfqy+HiRZspnq4DuVeYf+rCEgxh9rL6KnSQa+9FXuydCyauCCvLZONtLzypqV3eQOtmsiqRdUQSIjs5xOtDSqV71O+eUxebKF729qu4d1aRk5rRVd1AQyuaPfUp0iTxUTHgsCjgVGC4KcNrpEL/2fSX56F79N1E7tTsLP3WYD9Jx0qHK0OigtCC8Xd2QFj+rPkwPB3q26EKhhnzxIJ3Tj+qpOeWg4kNPKdgFHMMZF7/1ZGU3BSxJ6ZyliC7eonugIKiGfIse7+Jg0tYjB2FMFXTPSk+hk6OLeBBFnLElo0g49jZ3xOMqHsyVL3qih3J3hr5m69FAnpqDmOhJL0bolf2PCJmLiJCbCqRl9z9WCkbBwcC7i8vl3ykH2bzB6HeDHEOKOlYZzi1unptEqP4xz37X1b0xFS1BgJ3hM0rpUQcFRCbnF6qzknKD6OFD2qQzNwbUnya16dpuC0o7J1qcwz9TAqJ8og4CW8REEcX+0RGPXRA6Qcqc5WyX8AWI1A+2BQy4fS978cDBfFOBkyb/l1H0nyl1hYoR80eTolSftYwUPSum5KvsruxNrKsPNur58ubMo6PocDCRwwo3uY34H5QQ0ZjShsueAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\left\\{\\left( \\frac{1}{2}, \\ \\frac{5}{2}\\right)\\right\\}$" - ], - "text/plain": [ - "{(1/2, 5/2)}" - ] - }, - "execution_count": 80, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "linsolve([x - y + 2, x + y - 3], [x, y])" - ] - }, - { - "cell_type": "code", - "execution_count": 81, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJcAAAAVCAYAAABL53yqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAE4UlEQVRoBe2a2VEcMRCGgSIAwBlABmAiMM4ACAEywMUTvF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FZH6/mGGZn1tAyjRPgPVPMVa36dGcJXvbsdQeEOPAPyrtX972VBZy6pEJ3VdRCZh1wdVT76FPBFWD5tZzFcYh5ILB1ZY3Lyjpb32yjOZXc7HyAnLoTmUAgX8B9H1DxexYyrgtEUrgo1EGZcnewVg89QAw/C2fYgBqtsH5V4QNZ2dnlwqvNh+KqVfYDtV1XWbm89x1v6PqT/PdV1jrov8q2bscKzVfjbOpkMQE7c18S3wrPnQz8liVzo8p7Uj+E/Rsx1eao4bddWHLZiDGj6lttRrK3misBmuIRUXntckH19Arq9+jFoKjIHar8Nnr5HEmOXYtcWu90Xg8zk09aZ5sBtavCdWSveVY2fPTOByf6No9DSUaI39pY/k+F4rEguwrpJTK9RVfpOp9RCzZxA7hzYXrLL4W/zmamK+VPesB45HmG3KGBxzxVF3Z24wVn8VwDQ5/5SkluQEWj9/I4aj0T1RKxQha+8Iq7ikfBJnhA4RNF5ThFjSlKyC9ssn5JMRFJUgGA4APzAxh5T+Zp5gPWwKUdQAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\left\\{\\left( - y - 1, \\ y, \\ 2\\right)\\right\\}$" - ], - "text/plain": [ - "{(-y - 1, y, 2)}" - ] - }, - "execution_count": 81, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "roots will report if a solution is multiple by listing it multiple times" - ] - }, - { - "cell_type": "code", - "execution_count": 82, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG4AAAAVCAYAAACnvtv5AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAESElEQVRoBe2Z61HcMBCAj5sUAKQD6IBHBUAHkHQAHYTJP/4xpANIBQx0AKkgQAfQQQgdkO/zeD0+2T7b3AF3GXZGSCet9q3Vyiw8Pz8PUjg6OlpkbsN5xtfp+sfv17cAdl+By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a0AnlHjXRh3x9g94KqgEHeMhYL7/YaYFVH0QdOqyzbWyBm15I+0aBqtbEgN7DfY1tMGTsjQRS8/GEvb+y2FTnZ0U/rfAR+dnii/+s8VILMnxCju7bhZVxSdKn4ZzrrQPeTzzvjvnNakf+q4ygu9aeMszeMw75hO78hZkruHLOo3EpSp4yw6vCdMO/ME/kum6VKfJz0qsuZBWfmiNXLHuQtEL06rLCu4c35nFSTjD3hDC+R+8G2tPyp++AcjY666Cp/l/AAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\left\\{ 0 : 1, \\ 3 : 2\\right\\}$" - ], - "text/plain": [ - "{0: 1, 3: 2}" - ] - }, - "execution_count": 82, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "roots(x**3 - 6*x**2 + 9*x, x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "0 is 1 root, and 3 is 2 more roots" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Differential equations" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "you need an undefined function (f and g already are by our init_session() above, but we've probably reset these" - ] - }, - { - "cell_type": "code", - "execution_count": 83, - "metadata": {}, - "outputs": [], - "source": [ - "f, g = symbols('f g', cls=Function)" - ] - }, - { - "cell_type": "code", - "execution_count": 84, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAACUAAAAVCAYAAADB5CeuAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACf0lEQVRIDa2W7VHbQBCGFSYFmHQQlUBCB9ABIRUk7sCZ/LL/MdCBoQKGdEA6gNABLsFxB87zHCflJOuEBnlnVvf17qu93b2Tiu12W4zV+XxevpWjy/agGCmLxWIGxdEImjJy1BTv3GFOAC9Z28T1C8ZVP0wxPqNzTPsjYt7UYO/GNrTXEmQjBeCS9Q/oLfodPUFrYX3C4CftKIckhOOKZho5804B0hEd0rFH9Deaik4byX2JXHIWnenDY6Nyjx7Sb6RMI4X5v+jhy2g/Tzlh+phL3ymLK0A5h6yl1X5cabDIef4+ncIJU6ZDRmrN+C62U9pUxLTTWa9jZ73JpRyj39AS/YoqD2B+vXQbTzlPG5ECeI1+YUHSpX207ZAsn9FnOxm5xO5KZf0BvUFPGHso5A61Q9sWOctGpERg6I6UbCRYk3gtqC3YG6H0pRvGpttoKR6cdD1Mxoecu04xGS5CyJ9SdKsvsS/rkkds03r7BOiJuYCnNRM50W7SSF9EWgMpaY6gc75jM+cAbzvBu5Nhs11OGam+KEllmE1hr+CgB0ZcXdTMTdSMofPrnZpi0iK+yBhV00ayqr1qrogv88Ra6Nakh8TPRxr5vq+AkVo1IoWxL9Lb1yLlumlui5FRvU7CrlMAc655GnMS6q8dKVNXYNx38oRYI0akLdr5UfXl8vg9u0f9hPxBdbZOpZiWaDdt/Evxb7NE74b8G4F7Ro+GYIdg4CrlFHuA52dotWvraehJ8a7pulhbmx889GKVM/wl2KlPxCvh1SYIONPkD9pOwUfI4CZyyBX+p6yp4FRs+y62rpeIN8p+C8eINfc/6kPy3YeJtTDrw/StYT+TI8X8A8ObApWBYhW/AAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle f{\\left(x \\right)}$" - ], - "text/plain": [ - "f(x)" - ] - }, - "execution_count": 84, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEAAAAArCAYAAADIWo5HAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEy0lEQVRoBd2Z/1UUMRCADx8FIFYgJYB2AB0oVKB0gM+/4D8fdgBUgNiBdADSAXQgXgf4fbnsmou3P9g9uD3nvblskpnZmcnMJNlbeXh4GD0Wjo6ONuE5AzfAb/T3HytjKPSrXRTB4Bv4tmj13o8uMobC86KrIhi/HXkvu8oYAl9nB6D8DniHI8ZDMKSrDn0cYA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lDrhwX+dJE+9TzMXcPur4H/gNlpPyN3wOIACuqR86/Xuvj/4HxTqUARppjhqeHico/QaEzh7tcQWEbFpRFEKPMdVfb/wFFr5c6Q8jzv+sVdCJtQL8hAuKKWmAa/wSFts8VdECmT1QpUiBUZ4wLW0OipVGRb1V9rqCJ6GE8FingNXIqzGNUWBOm9n/G87O7vOfDMOfxWryIhs466GjYiPkpx6SvYM4IkbeMEuWJKd2Qn4sUUMf0GmnfA0dYbQzyCOvzPWit6HoFhXVYYASMUclVNtwDRIO9B1zHoeJPUFdc7HoFjeKG04SDUAxZLz1X4CvQnNYxFkfHLqHxXmBoOxa+0tL3a6zRYbS0uYJCNiz4A8R8IAc4Bp7iAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\frac{d}{d x} f{\\left(x \\right)}$" - ], - "text/plain": [ - "d \n", - "──(f(x))\n", - "dx " - ] - }, - "execution_count": 85, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f(x).diff(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": {}, - "outputs": [], - "source": [ - "diffeq = Eq(f(x).diff(x, 2) - 2*f(x).diff(x) + f(x), sin(x))" - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUkAAAAuCAYAAAClDOv+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAALn0lEQVR4Ae2d65HUOBSFeygCADaChQyAyWDIAJYIgAyW4hf8o5YMgAhgyQCIgEcGSwbMTgbs+TySVlbbbrctue32vVUeyXrr3Nbx1cOek1+/fm1MDIE1IfDixYtr6u8z1+ebzn2k8Is14WB97YfA1X7JLJUhcFQI/CVCfOJ7JP9r+b/puuXDzDUEPAJXvMdcQ2BFCDwWMZ5F/f1L/psKux2FmdcQqBAwkrQfwhoRwIr8usaOW5/3R+DE1iT3B21oDmepvFV+1sHe6z5M+YaWafm6EeiDudJgSd6Xa9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ZOgJXl96BQ7Zfgwhi42QA5BhbGvjZ4Q5TNfmxIGMSJI41L6xJ5IauOL4KtD91BApjzsMOneIGUZ0HXTIJDTHPQRAwkhwHO6TGp6HSVxaxdMI021Ux5utI41p5XLmLYS49Zv13JMcF+3p7Y9PtcbrnC0e1KbWzdJi2cWIgiMLTw8jkfRcSmKcvAoZ5X6QsXRYEjCQHwujIkKlZjQx1zyDeKL5GnoR5URyWJnmDtUl5XD6NudsIOHwM821oLKQgAjbdHg9uvBZJaZyPrKxGDWrWHPGz8M/a5dCvIymrSYSAYR6BYd6yCJglORBfEeCFsmItMrWuxJEiO6L+1TbeA2ZAYzly8YEPLCFIM4jCiGO326QDAeFkmHfgY1FlELBzkiNwdYTHMR4Iji+esMbIQGZzgTA+u8YuN8RIGK8YbnTPMSCsTKxOdlIhzzD11r1JCwLCCSwN8xZ8LDg/Av8BpWJ4vaU8sLsAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle f{\\left(x \\right)} - 2 \\frac{d}{d x} f{\\left(x \\right)} + \\frac{d^{2}}{d x^{2}} f{\\left(x \\right)} = \\sin{\\left(x \\right)}$" - ], - "text/plain": [ - " 2 \n", - " d d \n", - "f(x) - 2⋅──(f(x)) + ───(f(x)) = sin(x)\n", - " dx 2 \n", - " dx " - ] - }, - "execution_count": 87, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "diffeq" - ] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAAAsCAYAAAC+EqeDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAL60lEQVR4Ae2d65EUNxDHl6sL4GxHYMjAhgiwM+ARAecMcPHp+EZBBrYjsE0GQAQ8MgBHYHwZ4P9PSCqN5rkz0uzcbXeVVo9ptdQtqdVqzdztvnz5srNgMrA5cLxz4OLi4ubc8R+re7IzMAmYBI5WAk+fPn0s5n9YIICbnkYnCVMwnWKxQ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mMytOnsUbG0e5F0/iMzzTozlwxgp5q10B0ozp99TpjB2SvG1lkU3Li4usETCeXyvf4atToaXnUrsWu6PAS1jp2ztUvyFXokeuz4LkSMkCxMn8b8q73UW6/nmQP3lI8KzvGMqX3QF6+WzuXmQ83kV8pIlLgw2gMbaVN59AKqYI351wAeDVmOyEI8ejYSTAvgwErVk+nCPNLthKUtoj2ZHUUvx5xryg11ilx/teE2EipNzq/Ogpjhr0WYT4z8MfKOQWrlYLty0TXnNYnHfGj6YOdToqO/wrF1Y9XkTE6dpQ9PO6UuNOkv5q9Gn60hz6/Pgqslc8mTj58XHhp/Pl+NHGvszI0VYXqxgivTCiJgETAKrSEAKBpcI1sui4+zUzp5MRTQ8k4BJ4GpLQEoFv5+7/VuLE1Mwa0na2jEJHF4CHJuqfsOVs2hHpFwiljcJXEMJyHrBgc7RaOmFzF7SMQtmL3EZskng6klASoVPWniBdlXlgqRMwVy9+WI9NglMloCUCjdG/N/q+AqK0lgy+GKqgymY6iK2BkwCh5GAlAhOXf5kSP7uFUqHzwaqg/lgqovYGjAJrC8Bb6Hwpn3XJwF88d94P6ZWD3mT18AkYBK4fhJAuXAMav1JEZWt9rHj/xkYPR2IlRyyAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle f{\\left(x \\right)} = \\left(C_{1} + C_{2} x\\right) e^{x} + \\frac{\\cos{\\left(x \\right)}}{2}$" - ], - "text/plain": [ - " x cos(x)\n", - "f(x) = (C₁ + C₂⋅x)⋅ℯ + ──────\n", - " 2 " - ] - }, - "execution_count": 88, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsolve(diffeq, f(x))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Matrices" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "consider the Euler equations:\n", - "\n", - "$$q_t + A(q) q_x = 0$$\n", - "\n", - "where\n", - "\n", - "$$q = \\left ( \\begin{array}{c} \\rho \\\\ u \\\\ p \\end{array} \\right )\n", - "\\qquad\n", - "A(q) = \\left ( \\begin{array}{ccc} u & \\rho & 0 \\\\ \n", - " 0 & u & 1/\\rho \\\\ \n", - " 0 & c^2 \\rho & u \\end{array} \\right ) $$\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHAAAABLCAYAAACoXQMlAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIvklEQVR4Ae2d/3EVNxDH7Qx/ZwjMpADTAYQKYjowoQKggzD8Bf95SAeECiB0AKkATAdQQGbweNJA8v2cbx96su691Z3uJ7cz55N0kna1X620OumeD589e3b74ODgTFeK3j5//vx+6sGaNowGpP/P4nSU4qZnh9eCB38oTOaQvoSRNTyKBl4kuN5T2gnpIYAvhegKWEJbfSVJ3wbOV/G4petFjIHif8b8lUZSBeAP8cM1PowGBALT1gfdn+hi9Hui653CyeGySaoVwCbN9JgukB6p+uu6vzU2Cl8oTPylpXnuK4AeLZXPg2P4KVHtB6UdC8zriWfJpBXApFp6TzwWh/MEF/NBeO6i0IlpLFD3CMyeifZM8a2JVfG/lP5Qd4aByZDkQRH0duQ60sV8Y0pSdHgSf4913fBK5rXAp2LMRPtOl3lOFQ+lA+yJ7lMDDznvS67HunAQmFua1rt6NBgZOLv05QG5EngvgGo8C33GZoj1R2z6pKXGc/KPQpIZF5tO9TgQ4KPCOA7u4SkoO3TwppfhXgBV0Rc12ryl3xSPvSQU8trLcKB8r8Rna6RQnCEUcvfuy+zF/8YGEDIw62Rd6KK9AAq8ytTrnkvjN/Of0lAKae9d3AbIFMj5JmJnljfqaGH6lGypjmRp7nl6L4CBEnAGsMaLIK16G6C0UZUSyEOwctEjOUl/oAv53cqhUE9Eh7cRIWRhFug2iBwAYRgDxfxXMZNiHumyHhQKNXQYS2O+25DkYh7nAtwpEF77LwlB7ijtk+QNjSSR7VtSDoBbPbdWCkIYqLdyGH8ToVxI/OlAdDTryQ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XheTfS/9+Uxhqy2ajZAAAAAElFTkSuQmCC\n", - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}u & \\rho & 0\\\\0 & u & \\frac{1}{\\rho}\\\\0 & c^{2} \\rho & u\\end{matrix}\\right]$" - ], - "text/plain": [ - "⎡u ρ 0⎤\n", - "⎢ ⎥\n", - "⎢ 1⎥\n", - "⎢0 u ─⎥\n", - "⎢ ρ⎥\n", - "⎢ ⎥\n", - "⎢ 2 ⎥\n", - "⎣0 c ⋅ρ u⎦" - ] - }, - "execution_count": 89, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from sympy.abc import rho\n", - "rho, u, c = symbols('rho u c')\n", - "A = Matrix([[u, rho, 0], [0, u, rho**-1], [0, c**2 * rho, u]])\n", - "A" - ] - }, - { - "cell_type": "code", - "execution_count": 90, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFQAAAAZCAYAAACvrQlzAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC+UlEQVRoBe2Z7VEbMRCGjwwFMKQD6CAJFQAdQFIB0EE8/LL/kg4SKshHB6QDAh2EDsJQQt5H3B5C3tPN2CdjZrQzslZ7ul3tq9VqbW9Mp9OfTdO8UzM6nM1mdzaofT8Cwumznp5FMyYbAvRGD95HwsougIAwPOW1Nwu8W1/JILCZeVYfCQFF3kULxD/1u2oXkvWmxBqhLVpeJ+BuJL9WP1H7In6idiV+x5uPrALag4xAIyduqf9lU8Q/iGf81WRpXwFNEXkaH4u9fRp23LW4A4G71UkipgIagZGwBxrfJzKGlj95Pke9l1K7A4Q9iZjS6lv8tsbUryfqOQbFSXZwgKjB3o4aec2c03A8kl43+hIL28k4DHMRei7FJOIrNbvpwkuSA/SR+lWBif1j2TtT42Igh3FhlCIDK+efC7oLqBbNNydyBXSoloY+Mi+/MH9U0lqOpJDNi7+R/JGMC8M9dqMuoF/ZW++RC6gm3mmxdrt91Di91XDku6ewgOxSOp+dEI058pAbJY+PlvpMAyhWZtFLXTpHLqACM4R6GwEsusufkuEMst9z2kYWRPZ/JKotMoucEvNfNr0NM5mbv11Ao8VzCRCtD5GMI9hIVsSZyA5sKF0S+8g/qbEu1ykmjEAEjJ2EWJ1FqBtQQ4CiMAWO/BmUyaFTNdux2OhYPJFIvuxI9sjvNMAuSVQxHxwD/JB0q3XEQdZNGwL0WQS0zmDEQN7tU9xZWJCRXjaKDbWIaFoZjnLb2xoWtJB/TfpJc/fqw4lktnjWxJ1ywtijTU8YyShRLqWIS4EkDMDsED8Q8FtgyYvJ8iT1JrYgamLKp6JgBkuPH+brnob4T7+fs58FVC8S1t7R8mSaOiqF0kxrYBOph1dOrf9xuTa4hqEjP6ig4AQi1E38BW0urXotAVVkWP60LxdLO7oqBWsJqJy327VG6EiRQKnEn4Xk8FdF2UvppTxpgXx10Qle63rkX2ovl7YbIlQR8TfSVP+Xj8DIscKN+tjKKr6ATP4DQ63RaSPXX9oAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}u & \\rho & 0\\end{matrix}\\right]$" - ], - "text/plain": [ - "[u ρ 0]" - ] - }, - "execution_count": 90, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "A.row(0)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The eigenvalues of the system are the speeds at which information propagates" - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAAVCAYAAABmFVMQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEhUlEQVR4Ae2b21HcMBSGgaEASDqADgJUkKQDSAchHcDwxhsDHQQqyIQOIBVw6SB0EEIHm/9zJCHJ9q7tZY1sdGa0ko4ulv5zju67PJlMlmI6Pj5eE28bvsLXcXqOZwQyAmkjILvdUAs/yN0r/BC3diVmKNOBeL8M/zZOz/GMQEYgfQSMsWPwpwpfyTGZO1r2Z3wl7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6+G2mL1AY/KtNpj2+rVvm5ZaU6kpST2pVx/i/oqfbg6ULJrlsZvq0oZd8YTOtDttT6ZPrR+nAvtX7UtScVOY0dZ/BXH0uG33apXyfHlPg76mjrGTalDpi20Icx9KMO2lTkNHacK/FfjbilFz5RetJRGfyaGkgfBk/qy6CvR6cJICU5jRlnTwbYRTCJxDN+6YWPV3gIQW4VWt17D6FTI2xjllNPQjWDLG8fePjkKNjjw1VGroEO5Tg5/6G4//xUrEwZgYxA6ggYO+ZtDvZcsuN/JyeWv2PpJtMAAAAASUVORK5CYII=\n", - "text/latex": [ - "$\\displaystyle \\left\\{ u : 1, \\ - c + u : 1, \\ c + u : 1\\right\\}$" - ], - "text/plain": [ - "{u: 1, -c + u: 1, c + u: 1}" - ] - }, - "execution_count": 91, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "A.eigenvals()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can diagonalize it, such that\n", - "$$ A = PDP^{-1}$$" - ] - }, - { - "cell_type": "code", - "execution_count": 92, - "metadata": {}, - "outputs": [], - "source": [ - "P, D = A.diagonalize()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$D$ will be a matrix of the eigenvalues" - ] - }, - { - "cell_type": "code", - "execution_count": 93, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAALIAAABLCAYAAADUF925AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAHiklEQVR4Ae1d7Y3cNhCVg/sdODGQAtYdOHEFuXRgpwPbHcTIr7t/ht2BnQqCuAM7FTjnDuwCAuRgpIK8p+PsSTxyReZW0ow4BHQUh/qYefNEDbXS3J2zs7MHXdddYEmVt+fn549THS5zBJZEADz8hPPtUudE352TQccrrHPjYfk8bPi6I7AiAi8T5/4JskeUD4n8Gsx24ibQctH6CICbb2ItIKPoBpHj7ZptAyC5+v8BCPexvPSLPE8HDXh9lVevzR44hfOFD6ifY2G49RzL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PAwS0Zby8JTNWIvKRifi4bCGBEVZGsxkdkG3xxLScQcCJPAOTdNhBwItvwk2s5gcAwRv6EeCfenP8FqWr2GB/A247AMRAAD5nXepc7FonMB9K5R2qjh9W5g7jcEVgAAfnoOXmq/wBWEusn10B53gAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}u & 0 & 0\\\\0 & - c + u & 0\\\\0 & 0 & c + u\\end{matrix}\\right]$" - ], - "text/plain": [ - "⎡u 0 0 ⎤\n", - "⎢ ⎥\n", - "⎢0 -c + u 0 ⎥\n", - "⎢ ⎥\n", - "⎣0 0 c + u⎦" - ] - }, - "execution_count": 93, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "D" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$P$ will be the matrix of right eigenvectors" - ] - }, - { - "cell_type": "code", - "execution_count": 94, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH4AAABOCAYAAADmWaIlAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGl0lEQVR4Ae2dT5LVNhDGZ1JU1gSW2b3cAJIT8LhByA0SbgDFbnZTcAOSE6TgBiEngOEGsM2KYW4w+X3G/crjZ4/leZZGLaurNLJk2e7uT2q1/r05vry8PCqVTk5O7iLbb4SnXD/0KmcMOe54VcYU3yjrAWW2bTlVAJcUS4477YvPRrTylvtPRu5lnQ3fH2HwI/GvWTM6wdxN5eC5T7x6M/R67h13W/wrCqlwlz53E/XalQZeDnD7mLymIXSBf01NqEAPaMtjFlj+2eebPGXtAd8vN5jmYfWdbwgPub4YLFQzs9dAt8WPMgvAco7+IpwTfiYM9h3kV3KigVDg1bIbJ49K8IxrtfpKjjXwnWPeK+sHaCCoxR/w/lt7FMuk7ugpYUvYkJaX+4VYoxc3FEuOkoHXCOW5G4RHGAX4KHJUUz+i8NKzK/ClIzwiXzGmHpN40GoTzx+P6Chpdio5SgI+C+AOrSW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1c6koCY+ravEgp5Y7ONnUtuoN93XezkjL0alXHZPwuDbgZcIF7o4A3LaTaXLjyFo3scopL/VwNQmPazP1asFjBy70k976fX718zLt2lN4Gz/UnITHVQEPqLYuAaZ7pP5cQ7fUpv0KI6l4XJupv6LkXuIB6dzXHBbjsQIP2rQy9efviFN67716d31yaR5XZerHVItS1QWoj8+WluaxtvhsoY7LWAU+rn6zffssU4+5sTGvFjBcHKGCZzlE7v+HztJyBAPPh89Q4G64Q1ozTDqo/5gwOBvG/Vuhljf3/0MnphxBwMPA4BEq8jXm1aJCVo4RfMk710TIEdeakFGrd0cx5Qjt46VEW7HqKrAeoepqw9F1KPBbZDofkMtMvO5XcqSBSeAxN+rLp+jeVIF6Py8NTAIPuwbqdbNaIZUjL8lXzk0I8CEqqkeoQrSUUZkQ4If6dhPBrIHG9ZUcaWAS+HZIIZGGzLnlmZPnSPR1szoJfKueeoSqsHoSCnw9QrVG4DH3no9QmeNp/ohXCBeVI2jKttWUqyNUVFZZKZFNLrn6HzrfWG+mnKPIEQx86+R195wbb1nG8NvM1WfJ3AymYskR2sfPYLUW9aCBCrwHlCLwWIGPoFQPr6zAe0ApAo9d5+4TjkT/EzpZUoST1Bes9DS46Tj4ZkxOAa/p1jFvvU7Fjmku/3zbHznI6f9V4INBV0EnRAAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}1 & \\frac{1}{c^{2}} & \\frac{1}{c^{2}}\\\\0 & - \\frac{1}{c \\rho} & \\frac{1}{c \\rho}\\\\0 & 1 & 1\\end{matrix}\\right]$" - ], - "text/plain": [ - "⎡ 1 1 ⎤\n", - "⎢1 ── ── ⎥\n", - "⎢ 2 2 ⎥\n", - "⎢ c c ⎥\n", - "⎢ ⎥\n", - "⎢ -1 1 ⎥\n", - "⎢0 ─── ───⎥\n", - "⎢ c⋅ρ c⋅ρ⎥\n", - "⎢ ⎥\n", - "⎣0 1 1 ⎦" - ] - }, - "execution_count": 94, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "P" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Inverse" - ] - }, - { - "cell_type": "code", - "execution_count": 95, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAABYCAYAAADcOOrYAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAOa0lEQVR4Ae2d3a3dNhLH7zXu88J2gH1eeDvwRwW57iDxVhCnAwd+un4zkg6SrSCIO0hSQWxjG3AKWCCOsQ1k/z9ZPObRkY5IitQXh8A5pChqhvwPhxxSpHh5c3Nz/+Li4o1+fe7VixcvvuzeUNxtxT3R72uFH3Tv27UhsAUE9lSPVZZ3wvxeH+66d3nl3fhOYRL77nf/grAeomG4buNReHOGwOYQ2GE9/rZHCI8V9wXxvqJ/r8KfKHb3YaV5q7i38hsC3ft23Y+A8KJRfK7fH/o90u9li6WC5uZGYG/1WOX5oYuh4ohq9PRW96ZdF0PgV1H+UeBjOb3Uj2tzhsAsCJiizwCzlPuZ2LyWjzWEw3K6rWsb+jRw2F9pBEzRSyP8kf7X8n7yWD0kLEX/4MVZ0BAohoApejFoPxJue+17unrtseJNxivv2oKGQFEE/Mm4oowqJt68oXC9t3yUnjh7LVlxpZi76Kbo5RHnFQfrERinY6r/U78HTvEVNmcIFEcgWtHbHokxJ73SPV3z/u4P+cwmmztFgPE4r9LMVD/FZrGY2upxiqIzY/zNYhLaHmMWGP2yvWzvO8dS9KrqsU3GFazPba/xi3ybXS+Is5EeRyC6Rx8naSkcAm2vwRjdnCGwKALBiq5K+1dITpXuMiRdahrRZ5EJq8rwQ92Xes4tVmmeCS1PKIO1pystl5Ty1yaDEIxKySlG0YsqcAgIpBEQmMGTX02VAjS0HJaukeUq6lQNsghW9BrAmFpGNR7XooGlwbtyXqP9pLjZJuKW5q/yLu62gIHyyARtszpSPp0WG8qOLM7cQJqi50UUxb4DSfko/J/6zdlrLc2foi/ttoABr6S/Qbn1Y3f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Ww+58QUGVjPJ60F/oTFQsZAuMIxPTo78+Qc70979WLunYIwWKSGOth1Wdxq0zFz3IXj0186XcOLIpW0Ejic8klWNGVoVWcj04+hGXoarNB2OcCeDADdqMXAZNLLyyTI4MVveVU9fnoY2irkl4rDZYGJvnsX5NZmv8YPkvdXxKXJXn7eMcqeu3no/vY9YWX/prM0vz7MFlD3JK4LMn7gH3UZJxap9rPRz8ANxDwhxT06gwzRp1w9U/qGE1/JkES/zP09nIrGpe9ySS2R0fwgFbl+ehjtV6Vwy0cImnM12RoFCa7Cfwn814zgURcdiWTaEUXaPRSqYtD1lwfovImHFBk3jKAR7Hz08mUeDH253170LZKpa/2azZzyWVrMoky3al05hrFeyccODyRD0iwGYUPRjSurWjZzjAXPSb3ZjtHuy3GJj1hNYtctigTU/TIKi0hD+491z228LK3POcZ5qxRCNpWWYh/JELLJJ9ZLpuTSbTpvowYy3BV5cAcdh/ROMeEL8e48ffg3nOl8Sd9eum1FbI7/rMz1D205pZLDTKpXdHZpRR7SgemtFN6r3qGBVWpTuY3FGdnqHvwCY9Z5VKDTMx09ypYYJBKeNQjq6KEWAWB5M8maxoY8WNyzjU4hM193Fq6hFw2IZOqe/RE7Ziy9zyRZfNYVdsqE4BaQi6bkYkpemSNUm9KC35ifkeSiU4uvlVtq4wFaAm5bEkmZrrH1qgy6ZPH/GWyY1SFwK5kcnlzc8PMM6+F+twrtVqYROYMAUNgxQhIT1lDcDRH4bKre5eY7udM0V21aq7g5hsCO0Tg7ITw/wEQMRKdy/WjYgAAAABJRU5ErkJggg==\n", - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{u} & - \\frac{\\rho}{- c^{2} + u^{2}} & \\frac{1}{- c^{2} u + u^{3}}\\\\0 & \\frac{u}{- c^{2} + u^{2}} & - \\frac{1}{- c^{2} \\rho + \\rho u^{2}}\\\\0 & - \\frac{c^{2} \\rho}{- c^{2} + u^{2}} & \\frac{u}{- c^{2} + u^{2}}\\end{matrix}\\right]$" - ], - "text/plain": [ - "⎡1 -ρ 1 ⎤\n", - "⎢─ ───────── ─────────── ⎥\n", - "⎢u 2 2 2 3 ⎥\n", - "⎢ - c + u - c ⋅u + u ⎥\n", - "⎢ ⎥\n", - "⎢ u -1 ⎥\n", - "⎢0 ───────── ─────────────⎥\n", - "⎢ 2 2 2 2⎥\n", - "⎢ - c + u - c ⋅ρ + ρ⋅u ⎥\n", - "⎢ ⎥\n", - "⎢ 2 ⎥\n", - "⎢ -c ⋅ρ u ⎥\n", - "⎢0 ───────── ───────── ⎥\n", - "⎢ 2 2 2 2 ⎥\n", - "⎣ - c + u - c + u ⎦" - ] - }, - "execution_count": 95, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "A**-1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "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.9.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/content/06-python-sympy/sympy-examples.ipynb b/content/06-python-sympy/sympy-examples.ipynb new file mode 100644 index 0000000..ceb4ac8 --- /dev/null +++ b/content/06-python-sympy/sympy-examples.ipynb @@ -0,0 +1,2427 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SymPy examples" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "sources:\n", + "http://docs.sympy.org/latest/tutorial/\n", + "http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/notebooks/SymPy%20Examples.ipynb" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SymPy provides support for symbolic math to python, similar to what you would do with Mathematica or Maple. The major difference is that it acts just like any other python module, so you can use the symbolic math together in your own python projects with the rest of python functionality.\n", + "\n", + "The following import and function (`init_session()`) sets up a nice environment for us when working in Jupyter" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "IPython console for SymPy 1.11.1 (Python 3.11.2-64-bit) (ground types: gmpy)\n", + "\n", + "These commands were executed:\n", + ">>> from sympy import *\n", + ">>> x, y, z, t = symbols('x y z t')\n", + ">>> k, m, n = symbols('k m n', integer=True)\n", + ">>> f, g, h = symbols('f g h', cls=Function)\n", + ">>> init_printing()\n", + "\n", + "Documentation can be found at https://docs.sympy.org/1.11.1/\n", + "\n" + ] + } + ], + "source": [ + "from sympy import init_session\n", + "init_session(use_latex=\"mathjax\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import math" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## SymPy types and basic symbolic manipulation\n", + "\n", + "Sympy defines its own types, you can convert them to python types, but you don't always want to (and will probably lose accuracy when you do). " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.4142135623730951\n" + ] + } + ], + "source": [ + "print(math.sqrt(2))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sqrt(2)\n" + ] + } + ], + "source": [ + "print(sqrt(2))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2*sqrt(2)\n" + ] + } + ], + "source": [ + "print(sqrt(8))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "#help(sqrt(8))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can do symbolic math not just on numbers, but we can tell SymPy what to treat as a symbol, using `symbols()`" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "from sympy import symbols\n", + "x, y, z = symbols(\"x y z\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x + 2 y$" + ], + "text/plain": [ + "x + 2⋅y" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = x + 2*y\n", + "expr" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x + 2 y - 1$" + ], + "text/plain": [ + "x + 2⋅y - 1" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x + y$" + ], + "text/plain": [ + "x + y" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr - y" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x \\left(x + 2 y\\right)$" + ], + "text/plain": [ + "x⋅(x + 2⋅y)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f = x*expr\n", + "f" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{2} + 2 x y$" + ], + "text/plain": [ + " 2 \n", + "x + 2⋅x⋅y" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "g = expand(f)\n", + "g" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x \\left(x + 2 y\\right)$" + ], + "text/plain": [ + "x⋅(x + 2⋅y)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "factor(g)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## substitution\n", + "\n", + "SymPy provides methods to substitute values for symbols in symbolic expressions. Note, the follow likely does not do what you expect:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin{\\left(2 \\pi z \\right)}$" + ], + "text/plain": [ + "sin(2⋅π⋅z)" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = sin(z*2*pi)\n", + "z = 0\n", + "expr" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We've now redefined `z` to be a python type" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(z)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "to do substitution, we use the `subs()` method" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin{\\left(2 \\pi x \\right)}$" + ], + "text/plain": [ + "sin(2⋅π⋅x)" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = sin(x*2*pi)\n", + "expr" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{\\sqrt{2}}{2}$" + ], + "text/plain": [ + "√2\n", + "──\n", + "2 " + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = expr.subs(x, 0.125)\n", + "a" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that this is not a floating point number -- it is still a SymPy object. To make it floating point, we can use evalf()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.707106781186548 \n" + ] + } + ], + "source": [ + "b = a.evalf()\n", + "print(b, type(b))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is still a SymPy object, because SymPy can do arbitrary precision " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 0.70710678118654752440084436210484903928483593768847$" + ], + "text/plain": [ + "0.70710678118654752440084436210484903928483593768847" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.evalf(50)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "want regular python types?" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.7071067811865476 \n" + ] + } + ], + "source": [ + "c = float(b)\n", + "print(c, type(c))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python and SymPy" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "x, y, z, t = symbols('x y z t')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SymPy symbols are just objects and when you do operations on two sympy objects the result is a sympy object. \n", + "\n", + "When you combine a sympy and python object, the result is also a sympy object. \n", + "\n", + "But we need to be careful when doing fractions. For instance doing `x + 1/3` will first compute `1/3` in python (giving `0.333...`) and then add it to the sympy `x` symbol. The `Rational()` function makes this all happen in sympy" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin{\\left(2 \\pi x \\right)} + \\frac{1}{3}$" + ], + "text/plain": [ + "sin(2⋅π⋅x) + 1/3" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f = expr + Rational(1,3)\n", + "f" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin{\\left(2 \\pi x \\right)} + 0.333333333333333$" + ], + "text/plain": [ + "sin(2⋅π⋅x) + 0.333333333333333" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr + 1/3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## equality" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`=` is still the assignment operator of python (it does not mean symbolic equality), and `==` is still the logical test (exact structural equality). There is a separate object, `Eq()` to specify symbolic equality.\n", + "\n", + "And testing for _algebraic_ equality is not always accomplished using `==`, since that tests for _structural equality_." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x + 1 == 4" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x + 1 = 4$" + ], + "text/plain": [ + "x + 1 = 4" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Eq(x + 1, 4)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "a = (x + 1)**2\n", + "b = x**2 + 2*x + 1 # these are algebraically equal" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a == b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can use `simplify()` to test for algebraic equality" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 0$" + ], + "text/plain": [ + "0" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify(a - b)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle i \\sin{\\left(x \\right)} + \\cos{\\left(x \\right)}$" + ], + "text/plain": [ + "ⅈ⋅sin(x) + cos(x)" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = cos(x) + I*sin(x)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle e^{i x}$" + ], + "text/plain": [ + " ⅈ⋅x\n", + "ℯ " + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## More substitution" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "note that substitution returns a new expression: SymPy expressions are immutable" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = cos(x)\n", + "expr.subs(x, 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\cos{\\left(x \\right)}$" + ], + "text/plain": [ + "cos(x)" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x$" + ], + "text/plain": [ + "x" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "multiple substitutions, pass a list of tuples" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{3} + 4 x y - z$" + ], + "text/plain": [ + " 3 \n", + "x + 4⋅x⋅y - z" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = x**3 + 4*x*y - z\n", + "expr" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 40$" + ], + "text/plain": [ + "40" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr.subs([(x, 2), (y, 4), (z, 0)])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## simplifying" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is not unique definition of what the simplest form of an expression is.\n", + "\n", + "`simplify()` tries lots of methods for simplification" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify(sin(x)**2 + cos(x)**2)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x - 1$" + ], + "text/plain": [ + "x - 1" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify( (x**3 + x**2 - x - 1)/(x**2 + 2*x + 1) )" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(x - 2\\right) \\left(x - 1\\right)$" + ], + "text/plain": [ + "(x - 2)⋅(x - 1)" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify(gamma(x)/gamma(x - 2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "but sometimes it doesn't have your idea of what the simplest form is" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{2} + 2 x + 1$" + ], + "text/plain": [ + " 2 \n", + "x + 2⋅x + 1" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify(x**2 + 2*x + 1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "instead factor may be what you want" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(x + 1\\right)^{2}$" + ], + "text/plain": [ + " 2\n", + "(x + 1) " + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "factor(x**2 + 2*x + 1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### polynomial simplification" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{2} + 2 x + 1$" + ], + "text/plain": [ + " 2 \n", + "x + 2⋅x + 1" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expand((x + 1)**2)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{2} - x - 6$" + ], + "text/plain": [ + " 2 \n", + "x - x - 6" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expand((x + 2)*(x - 3))" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle -2$" + ], + "text/plain": [ + "-2" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expand( (x + 1)*(x - 2) - (x - 1)*x)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle z \\left(x + 2 y\\right)^{2}$" + ], + "text/plain": [ + " 2\n", + "z⋅(x + 2⋅y) " + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "factor(x**2*z + 4*x*y*z + 4*y**2*z)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left( 1, \\ \\left[ \\left( z, \\ 1\\right), \\ \\left( x + 2 y, \\ 2\\right)\\right]\\right)$" + ], + "text/plain": [ + "(1, [(z, 1), (x + 2⋅y, 2)])" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "factor_list(x**2*z + 4*x*y*z + 4*y**2*z)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "collect collects common powers" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{3} - x^{2} z + 2 x^{2} + x y + x - 3$" + ], + "text/plain": [ + " 3 2 2 \n", + "x - x ⋅z + 2⋅x + x⋅y + x - 3" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = x*y + x - 3 + 2*x**2 - z*x**2 + x**3\n", + "expr" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{3} + x^{2} \\cdot \\left(2 - z\\right) + x \\left(y + 1\\right) - 3$" + ], + "text/plain": [ + " 3 2 \n", + "x + x ⋅(2 - z) + x⋅(y + 1) - 3" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "collected_expr = collect(expr, x)\n", + "collected_expr" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "cancel cancels" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{x^{2} + 2 x + 1}{x^{2} + x}$" + ], + "text/plain": [ + " 2 \n", + "x + 2⋅x + 1\n", + "────────────\n", + " 2 \n", + " x + x " + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = (x**2 + 2*x + 1)/(x**2 + x)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{x + 1}{x}$" + ], + "text/plain": [ + "x + 1\n", + "─────\n", + " x " + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cancel(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "trigsimp simplifies trigonometric identities" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{\\cos{\\left(4 x \\right)}}{2} + \\frac{1}{2}$" + ], + "text/plain": [ + "cos(4⋅x) 1\n", + "──────── + ─\n", + " 2 2" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trigsimp(sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin^{2}{\\left(x \\right)}$" + ], + "text/plain": [ + " 2 \n", + "sin (x)" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trigsimp(sin(x)*tan(x)/sec(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "the tutorial discusses some of the nuances of simplification of powers and special functions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Calculus" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Calculus operations are simple in SymPy\n", + "\n", + "### derivatives" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle - \\sin{\\left(x \\right)}$" + ], + "text/plain": [ + "-sin(x)" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "diff(cos(x), x)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 2 x e^{x^{2}}$" + ], + "text/plain": [ + " ⎛ 2⎞\n", + " ⎝x ⎠\n", + "2⋅x⋅ℯ " + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "diff(exp(x**2), x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "third derivative" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 24 x$" + ], + "text/plain": [ + "24⋅x" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "diff(x**4, x, 3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "differentiate different variables" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(x^{2} y^{2} z^{2} + 3 x y z + 1\\right) e^{x y z}$" + ], + "text/plain": [ + "⎛ 2 2 2 ⎞ x⋅y⋅z\n", + "⎝x ⋅y ⋅z + 3⋅x⋅y⋅z + 1⎠⋅ℯ " + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = exp(x*y*z)\n", + "diff(expr, x, y, z)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "unevaluated derivatives can be useful for building up ODEs and PDEs" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{\\partial^{3}}{\\partial z\\partial y\\partial x} e^{x y z}$" + ], + "text/plain": [ + " 3 \n", + " ∂ ⎛ x⋅y⋅z⎞\n", + "────────⎝ℯ ⎠\n", + "∂z ∂y ∂x " + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "deriv = Derivative(expr, x, y, z)\n", + "deriv" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left(x^{2} y^{2} z^{2} + 3 x y z + 1\\right) e^{x y z}$" + ], + "text/plain": [ + "⎛ 2 2 2 ⎞ x⋅y⋅z\n", + "⎝x ⋅y ⋅z + 3⋅x⋅y⋅z + 1⎠⋅ℯ " + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "deriv.doit()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### integrals\n", + "\n", + "definite and indefinite integrals are supported" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin{\\left(x \\right)}$" + ], + "text/plain": [ + "sin(x)" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "integrate(cos(x), x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "definite integral -- note the construction of the infinity" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "integrate(exp(-x), (x, 0, oo))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "double integral" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\pi$" + ], + "text/plain": [ + "π" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "integrate(exp(-x**2 - y**2), (x, -oo, oo), (y, -oo, oo))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "if it is unable to do the integral, it returns an Integral object" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Integral(x**x, x)\n" + ] + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\int x^{x}\\, dx$" + ], + "text/plain": [ + "⌠ \n", + "⎮ x \n", + "⎮ x dx\n", + "⌡ " + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = integrate(x**x, x)\n", + "print(expr)\n", + "expr" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{x}{\\sqrt{x^{4} + 10 x^{2} - 96 x - 71}}$" + ], + "text/plain": [ + " x \n", + "───────────────────────────\n", + " ________________________\n", + " ╱ 4 2 \n", + "╲╱ x + 10⋅x - 96⋅x - 71 " + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = x / sqrt(x**4 + 10*x**2 - 96*x - 71) # example from Wikipedia Risch algorithm page)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\int \\frac{x}{\\sqrt{x^{4} + 10 x^{2} - 96 x - 71}}\\, dx$" + ], + "text/plain": [ + "⌠ \n", + "⎮ x \n", + "⎮ ─────────────────────────── dx\n", + "⎮ ________________________ \n", + "⎮ ╱ 4 2 \n", + "⎮ ╲╱ x + 10⋅x - 96⋅x - 71 \n", + "⌡ " + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "integrate(a, x) # this has a known solution, but SymPy fails to find it" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### limits" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "limit(sin(x)/x, x, 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### series expansions" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1 + x + \\frac{x^{2}}{2} - \\frac{x^{4}}{8} - \\frac{x^{5}}{15} - \\frac{x^{6}}{240} + \\frac{x^{7}}{90} + \\frac{31 x^{8}}{5760} + \\frac{x^{9}}{5670} + O\\left(x^{10}\\right)$" + ], + "text/plain": [ + " 2 4 5 6 7 8 9 \n", + " x x x x x 31⋅x x ⎛ 10⎞\n", + "1 + x + ── - ── - ── - ─── + ── + ───── + ──── + O⎝x ⎠\n", + " 2 8 15 240 90 5760 5670 " + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr = exp(sin(x))\n", + "a = expr.series(x, 0, 10)\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle -1 - \\frac{\\left(x - 1\\right)^{2}}{2} + \\frac{\\left(x - 1\\right)^{3}}{3} - \\frac{\\left(x - 1\\right)^{4}}{4} + \\frac{\\left(x - 1\\right)^{5}}{5} + x + O\\left(\\left(x - 1\\right)^{6}; x\\rightarrow 1\\right)$" + ], + "text/plain": [ + " 2 3 4 5 \n", + " (x - 1) (x - 1) (x - 1) (x - 1) ⎛ 6 ⎞\n", + "-1 - ──────── + ──────── - ──────── + ──────── + x + O⎝(x - 1) ; x → 1⎠\n", + " 2 3 4 5 " + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c = log(x).series(x, x0=1, n=6)\n", + "c" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{x^{5}}{5} - \\frac{5 x^{4}}{4} + \\frac{10 x^{3}}{3} - 5 x^{2} + 5 x - \\frac{137}{60}$" + ], + "text/plain": [ + " 5 4 3 \n", + "x 5⋅x 10⋅x 2 137\n", + "── - ──── + ───── - 5⋅x + 5⋅x - ───\n", + "5 4 3 60" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "simplify(c.removeO())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## solvers\n", + "\n", + "`solveset()` is the main interface to solvers in SymPy. Note that it used to be `solve()`, but this has been replaced (see http://docs.sympy.org/latest/modules/solvers/solveset.html)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If no Eq() is done, then it is assumed to be equal to 0" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left\\{0, 1\\right\\}$" + ], + "text/plain": [ + "{0, 1}" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solveset(x**2 - x, x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "you can restrict the domain of the solution (e.g. to reals). Recall that Z is the set of integers" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left\\{2 n \\pi + \\frac{\\pi}{2}\\; \\middle|\\; n \\in \\mathbb{Z}\\right\\}$" + ], + "text/plain": [ + "⎧ π │ ⎫\n", + "⎨2⋅n⋅π + ─ │ n ∊ ℤ⎬\n", + "⎩ 2 │ ⎭" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solveset(sin(x) - 1, x, domain=S.Reals)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### linear systems\n", + "\n", + "`linsolve()` is the interface to linear systems" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left\\{\\left( \\frac{1}{2}, \\ \\frac{5}{2}\\right)\\right\\}$" + ], + "text/plain": [ + "{(1/2, 5/2)}" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linsolve([x - y + 2, x + y - 3], [x, y])" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left\\{\\left( - y - 1, \\ y, \\ 2\\right)\\right\\}$" + ], + "text/plain": [ + "{(-y - 1, y, 2)}" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "roots will report if a solution is multiple by listing it multiple times" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left\\{ 0 : 1, \\ 3 : 2\\right\\}$" + ], + "text/plain": [ + "{0: 1, 3: 2}" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "roots(x**3 - 6*x**2 + 9*x, x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "0 is 1 root, and 3 is 2 more roots" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Differential equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "you need an undefined function (f and g already are by our init_session() above, but we've probably reset these" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [], + "source": [ + "f, g = symbols('f g', cls=Function)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle f{\\left(x \\right)}$" + ], + "text/plain": [ + "f(x)" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{d}{d x} f{\\left(x \\right)}$" + ], + "text/plain": [ + "d \n", + "──(f(x))\n", + "dx " + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f(x).diff(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [], + "source": [ + "diffeq = Eq(f(x).diff(x, 2) - 2*f(x).diff(x) + f(x), sin(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle f{\\left(x \\right)} - 2 \\frac{d}{d x} f{\\left(x \\right)} + \\frac{d^{2}}{d x^{2}} f{\\left(x \\right)} = \\sin{\\left(x \\right)}$" + ], + "text/plain": [ + " 2 \n", + " d d \n", + "f(x) - 2⋅──(f(x)) + ───(f(x)) = sin(x)\n", + " dx 2 \n", + " dx " + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "diffeq" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle f{\\left(x \\right)} = \\left(C_{1} + C_{2} x\\right) e^{x} + \\frac{\\cos{\\left(x \\right)}}{2}$" + ], + "text/plain": [ + " x cos(x)\n", + "f(x) = (C₁ + C₂⋅x)⋅ℯ + ──────\n", + " 2 " + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dsolve(diffeq, f(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Matrices" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "consider the Euler equations:\n", + "\n", + "$$q_t + A(q) q_x = 0$$\n", + "\n", + "where\n", + "\n", + "$$q = \\left ( \\begin{array}{c} \\rho \\\\ u \\\\ p \\end{array} \\right )\n", + "\\qquad\n", + "A(q) = \\left ( \\begin{array}{ccc} u & \\rho & 0 \\\\ \n", + " 0 & u & 1/\\rho \\\\ \n", + " 0 & c^2 \\rho & u \\end{array} \\right ) $$\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left[\\begin{matrix}u & \\rho & 0\\\\0 & u & \\frac{1}{\\rho}\\\\0 & c^{2} \\rho & u\\end{matrix}\\right]$" + ], + "text/plain": [ + "⎡u ρ 0⎤\n", + "⎢ ⎥\n", + "⎢ 1⎥\n", + "⎢0 u ─⎥\n", + "⎢ ρ⎥\n", + "⎢ ⎥\n", + "⎢ 2 ⎥\n", + "⎣0 c ⋅ρ u⎦" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from sympy.abc import rho\n", + "rho, u, c = symbols('rho u c')\n", + "A = Matrix([[u, rho, 0], [0, u, rho**-1], [0, c**2 * rho, u]])\n", + "A" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left[\\begin{matrix}u & \\rho & 0\\end{matrix}\\right]$" + ], + "text/plain": [ + "[u ρ 0]" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.row(0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The eigenvalues of the system are the speeds at which information propagates" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left\\{ u : 1, \\ - c + u : 1, \\ c + u : 1\\right\\}$" + ], + "text/plain": [ + "{u: 1, -c + u: 1, c + u: 1}" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.eigenvals()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can diagonalize it, such that\n", + "$$ A = PDP^{-1}$$" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [], + "source": [ + "P, D = A.diagonalize()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$D$ will be a matrix of the eigenvalues" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left[\\begin{matrix}u & 0 & 0\\\\0 & - c + u & 0\\\\0 & 0 & c + u\\end{matrix}\\right]$" + ], + "text/plain": [ + "⎡u 0 0 ⎤\n", + "⎢ ⎥\n", + "⎢0 -c + u 0 ⎥\n", + "⎢ ⎥\n", + "⎣0 0 c + u⎦" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "D" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$P$ will be the matrix of right eigenvectors" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left[\\begin{matrix}1 & \\frac{1}{c^{2}} & \\frac{1}{c^{2}}\\\\0 & - \\frac{1}{c \\rho} & \\frac{1}{c \\rho}\\\\0 & 1 & 1\\end{matrix}\\right]$" + ], + "text/plain": [ + "⎡ 1 1 ⎤\n", + "⎢1 ── ── ⎥\n", + "⎢ 2 2 ⎥\n", + "⎢ c c ⎥\n", + "⎢ ⎥\n", + "⎢ -1 1 ⎥\n", + "⎢0 ─── ───⎥\n", + "⎢ c⋅ρ c⋅ρ⎥\n", + "⎢ ⎥\n", + "⎣0 1 1 ⎦" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "P" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Inverse" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{u} & - \\frac{\\rho}{- c^{2} + u^{2}} & \\frac{1}{- c^{2} u + u^{3}}\\\\0 & \\frac{u}{- c^{2} + u^{2}} & - \\frac{1}{- c^{2} \\rho + \\rho u^{2}}\\\\0 & - \\frac{c^{2} \\rho}{- c^{2} + u^{2}} & \\frac{u}{- c^{2} + u^{2}}\\end{matrix}\\right]$" + ], + "text/plain": [ + "⎡1 -ρ 1 ⎤\n", + "⎢─ ───────── ─────────── ⎥\n", + "⎢u 2 2 2 3 ⎥\n", + "⎢ - c + u - c ⋅u + u ⎥\n", + "⎢ ⎥\n", + "⎢ u -1 ⎥\n", + "⎢0 ───────── ─────────────⎥\n", + "⎢ 2 2 2 2⎥\n", + "⎢ - c + u - c ⋅ρ + ρ⋅u ⎥\n", + "⎢ ⎥\n", + "⎢ 2 ⎥\n", + "⎢ -c ⋅ρ u ⎥\n", + "⎢0 ───────── ───────── ⎥\n", + "⎢ 2 2 2 2 ⎥\n", + "⎣ - c + u - c + u ⎦" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A**-1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Units\n", + "\n", + "Sympy can attach units to numbers and propagate them through" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [], + "source": [ + "from sympy.physics.units import newton, kilogram, meter, second, convert_to" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 9.81 \\text{N}$" + ], + "text/plain": [ + "9.81⋅newton" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "F = 1 * kilogram * 9.81 * meter / second**2\n", + "convert_to(F, newton)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/content/06-python-sympy/sympy-exercises.ipynb b/content/06-python-sympy/sympy-exercises.ipynb index da80e81..72b5073 100644 --- a/content/06-python-sympy/sympy-exercises.ipynb +++ b/content/06-python-sympy/sympy-exercises.ipynb @@ -16,7 +16,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "IPython console for SymPy 1.6 (Python 3.8.3-64-bit) (ground types: python)\n", + "IPython console for SymPy 1.9 (Python 3.10.2-64-bit) (ground types: gmpy)\n", "\n", "These commands were executed:\n", ">>> from __future__ import division\n", @@ -26,7 +26,7 @@ ">>> f, g, h = symbols('f g h', cls=Function)\n", ">>> init_printing()\n", "\n", - "Documentation can be found at https://docs.sympy.org/1.6/\n", + "Documentation can be found at https://docs.sympy.org/1.9/\n", "\n" ] } @@ -65,7 +65,7 @@ "source": [ "## Q2: Factoring a polynomial, and finding its roots\n", "\n", - "Factor \n", + "Factor\n", "\n", "$$x^{4} - 6 x^{3} + x^{2} + 24 x + 16$$\n", "\n", @@ -87,9 +87,7 @@ "\n", "Integrate the function:\n", "\n", - "$$\n", - "f = \\sin(x) e^{-x}\n", - "$$\n", + "$$f = \\sin(x) e^{-x}$$\n", "\n", "Then differentiate the result to see if you get back the original function" ] @@ -179,9 +177,9 @@ "outputs": [ { "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAAPCAYAAADAraLQAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIx0lEQVRoBe2ba5YNOxSAD8sAaCPADGgjwAy4RoAZXMs//yxmgBF4zAAj8JgBdwRaz8D9vnTtSOWkqlK6b2vW3Wulk9rZ2e/spOpw6vv375v/4dd44OHDh5dpn0rpPJ/leYf+S4n/U8bYdRFbrtNeMt7/U+z6Xew4cxSKDkG8P/Dapd+j3Qc/SuZeWay7DO09+ntza+bomHtarN1hfAfcKMF4Nvm69V7BM/R28yrjMWvf0tfwDrw04SfHwpWD7sffTtmuf/Bj1cbnVy3Z4Lpt75FdyExD1kzFULyxeQpNoq3+7IM/FzjGj4fxV/pLNH05WQwL+mDxAlz4N3C5Z25Kz0xzkgaDvq/Q6Qrj/SndmAu/BUnyw6E3PIxNHIN3IzgPwj6Ko7USPUineg2aDFKxaIsOeSb5R5o6PZGW3qD+Q6+TUrLQd+sNbS9P6Sx0seE3jG+Ce0N/i/aacQl7w4P6qZfzj6DLgWTcJXvg42bIssXx7IY/S8uyGXfZ7jpYLPpykF13W7EZCK7SmxOtTevJHwV4g3xl64+ke+hDb16N1vOsTcrU/ynn6H22WSimYErPKfpjx2OHcXhOM188ULW1CUt+ON1ctQ5pJamTzKCZtDpzFaDw3z0LZuh0jFfitNnlxdji8YFWnvpr9O7leRcZd5HnJg+IgleevDH3CdpztFO0SzSTVb+V0CWbdcp2g9RwB0Qtu9f2Ltm1QHSZjSHzbth0g4seHur0lufY3NpTFyp943wZR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N+eur9AfVnCBilM6vrsE/kx6k1jHbmKTC3jpTH/euduiPXRW4l36SUe20oVM6N1TBHNCg4sr25Is5lbq3cITGovGgr4scF6nvdravKJK85FOW43Z3iBMAE3LftyfCdcD6ywgnsrfaL3snoAB85N7Z35SNvNNPsxlZuPRoprRnGio3jR9re3Xho6ffHq/ZEwDtxRbGc2pDXc2xZlN6pDr9P0JzFgHL+jHNuf8beY9LXIwGTyJxLvWgF9JB/3UO7g8l04j1pxEb1glKHmm32nh2XLi3oJDrbrvyRkeZSFIArM/vWxoDSKLoQk3AHCe5haOxDefBH/Sveey3cds3yBbnfX/qn3mKs8aI8MCtkmIV5SSZ9j2XF4LNpLEGEun6sgyiQyS+NBSbnwBvZte2jh4r0EmXF8QWulYo0z/kcI1ximo6Q0YT6LBqQe+Se8ZPJW3VCjAGehCvtfX8C3tJY169nQtsqHx1LGlK7hMCnD/PU/noF25d2hW2hIa+Q54d/xrPnQqIGxSK2RBc9F6D5W40eW6GVde21O85RNnMV47iVHcaurmDN7y3XYfXPzTRwOp9R1FWtsqqNGpTxkY6ueHl77qt+rdKdDEE9qlpESOiaCeyj/q+Nn5z0Jt/bWfsV+0hbx4tcp2je/dd2i9HMZel/2Zqb8NMW7yGetaZUO6BDXf5ETOC72ux4/Vv1c7rCdeC32VSSNyVBZ2S4WX3t/j47XIfTyg3Wnkv3GyS+v+nz3YjO9bOrsGg48KHa3J3gduvgi8RUBenkaChvoMfvCVexUd81EtI1AM7sFpwXOz3irSwrOjU/cyCf3INpDf0brXSHwD1OLjP1kdBOoM2Z6uTzs+dAnW2nur7BAGfasP3buvH/6HKSkhgkf04C2+gjbVlxbh9HrF3OgND5rZ0CoLOvUwvvSRH7Ju056D7w8Ins8U/gUKsNDonL5kMwAAAABJRU5ErkJggg==\n", "text/latex": [ - "$\\displaystyle -2.4492935982947064e-16$" + "$\\displaystyle -2.44929359829471 \\cdot 10^{-16}$" ], "text/plain": [ "-2.4492935982947064e-16" @@ -199,586 +197,10 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "tags": [ - "hide-output" - ] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on function lambdify in module sympy.utilities.lambdify:\n", - "\n", - "lambdify(args, expr, modules=None, printer=None, use_imps=True, dummify=False)\n", - " Convert a SymPy expression into a function that allows for fast\n", - " numeric evaluation.\n", - " \n", - " .. warning::\n", - " This function uses ``exec``, and thus shouldn't be used on\n", - " unsanitized input.\n", - " \n", - " Explanation\n", - " ===========\n", - " \n", - " For example, to convert the SymPy expression ``sin(x) + cos(x)`` to an\n", - " equivalent NumPy function that numerically evaluates it:\n", - " \n", - " >>> from sympy import sin, cos, symbols, lambdify\n", - " >>> import numpy as np\n", - " >>> x = symbols('x')\n", - " >>> expr = sin(x) + cos(x)\n", - " >>> expr\n", - " sin(x) + cos(x)\n", - " >>> f = lambdify(x, expr, 'numpy')\n", - " >>> a = np.array([1, 2])\n", - " >>> f(a)\n", - " [1.38177329 0.49315059]\n", - " \n", - " The primary purpose of this function is to provide a bridge from SymPy\n", - " expressions to numerical libraries such as NumPy, SciPy, NumExpr, mpmath,\n", - " and tensorflow. In general, SymPy functions do not work with objects from\n", - " other libraries, such as NumPy arrays, and functions from numeric\n", - " libraries like NumPy or mpmath do not work on SymPy expressions.\n", - " ``lambdify`` bridges the two by converting a SymPy expression to an\n", - " equivalent numeric function.\n", - " \n", - " The basic workflow with ``lambdify`` is to first create a SymPy expression\n", - " representing whatever mathematical function you wish to evaluate. This\n", - " should be done using only SymPy functions and expressions. Then, use\n", - " ``lambdify`` to convert this to an equivalent function for numerical\n", - " evaluation. For instance, above we created ``expr`` using the SymPy symbol\n", - " ``x`` and SymPy functions ``sin`` and ``cos``, then converted it to an\n", - " equivalent NumPy function ``f``, and called it on a NumPy array ``a``.\n", - " \n", - " Parameters\n", - " ==========\n", - " \n", - " args : List[Symbol]\n", - " A variable or a list of variables whose nesting represents the\n", - " nesting of the arguments that will be passed to the function.\n", - " \n", - " Variables can be symbols, undefined functions, or matrix symbols.\n", - " \n", - " >>> from sympy import Eq\n", - " >>> from sympy.abc import x, y, z\n", - " \n", - " The list of variables should match the structure of how the\n", - " arguments will be passed to the function. Simply enclose the\n", - " parameters as they will be passed in a list.\n", - " \n", - " To call a function like ``f(x)`` then ``[x]``\n", - " should be the first argument to ``lambdify``; for this\n", - " case a single ``x`` can also be used:\n", - " \n", - " >>> f = lambdify(x, x + 1)\n", - " >>> f(1)\n", - " 2\n", - " >>> f = lambdify([x], x + 1)\n", - " >>> f(1)\n", - " 2\n", - " \n", - " To call a function like ``f(x, y)`` then ``[x, y]`` will\n", - " be the first argument of the ``lambdify``:\n", - " \n", - " >>> f = lambdify([x, y], x + y)\n", - " >>> f(1, 1)\n", - " 2\n", - " \n", - " To call a function with a single 3-element tuple like\n", - " ``f((x, y, z))`` then ``[(x, y, z)]`` will be the first\n", - " argument of the ``lambdify``:\n", - " \n", - " >>> f = lambdify([(x, y, z)], Eq(z**2, x**2 + y**2))\n", - " >>> f((3, 4, 5))\n", - " True\n", - " \n", - " If two args will be passed and the first is a scalar but\n", - " the second is a tuple with two arguments then the items\n", - " in the list should match that structure:\n", - " \n", - " >>> f = lambdify([x, (y, z)], x + y + z)\n", - " >>> f(1, (2, 3))\n", - " 6\n", - " \n", - " expr : Expr\n", - " An expression, list of expressions, or matrix to be evaluated.\n", - " \n", - " Lists may be nested.\n", - " If the expression is a list, the output will also be a list.\n", - " \n", - " >>> f = lambdify(x, [x, [x + 1, x + 2]])\n", - " >>> f(1)\n", - " [1, [2, 3]]\n", - " \n", - " If it is a matrix, an array will be returned (for the NumPy module).\n", - " \n", - " >>> from sympy import Matrix\n", - " >>> f = lambdify(x, Matrix([x, x + 1]))\n", - " >>> f(1)\n", - " [[1]\n", - " [2]]\n", - " \n", - " Note that the argument order here (variables then expression) is used\n", - " to emulate the Python ``lambda`` keyword. ``lambdify(x, expr)`` works\n", - " (roughly) like ``lambda x: expr``\n", - " (see :ref:`lambdify-how-it-works` below).\n", - " \n", - " modules : str, optional\n", - " Specifies the numeric library to use.\n", - " \n", - " If not specified, *modules* defaults to:\n", - " \n", - " - ``[\"scipy\", \"numpy\"]`` if SciPy is installed\n", - " - ``[\"numpy\"]`` if only NumPy is installed\n", - " - ``[\"math\", \"mpmath\", \"sympy\"]`` if neither is installed.\n", - " \n", - " That is, SymPy functions are replaced as far as possible by\n", - " either ``scipy`` or ``numpy`` functions if available, and Python's\n", - " standard library ``math``, or ``mpmath`` functions otherwise.\n", - " \n", - " *modules* can be one of the following types:\n", - " \n", - " - The strings ``\"math\"``, ``\"mpmath\"``, ``\"numpy\"``, ``\"numexpr\"``,\n", - " ``\"scipy\"``, ``\"sympy\"``, or ``\"tensorflow\"``. This uses the\n", - " corresponding printer and namespace mapping for that module.\n", - " - A module (e.g., ``math``). This uses the global namespace of the\n", - " module. If the module is one of the above known modules, it will\n", - " also use the corresponding printer and namespace mapping\n", - " (i.e., ``modules=numpy`` is equivalent to ``modules=\"numpy\"``).\n", - " - A dictionary that maps names of SymPy functions to arbitrary\n", - " functions\n", - " (e.g., ``{'sin': custom_sin}``).\n", - " - A list that contains a mix of the arguments above, with higher\n", - " priority given to entries appearing first\n", - " (e.g., to use the NumPy module but override the ``sin`` function\n", - " with a custom version, you can use\n", - " ``[{'sin': custom_sin}, 'numpy']``).\n", - " \n", - " dummify : bool, optional\n", - " Whether or not the variables in the provided expression that are not\n", - " valid Python identifiers are substituted with dummy symbols.\n", - " \n", - " This allows for undefined functions like ``Function('f')(t)`` to be\n", - " supplied as arguments. By default, the variables are only dummified\n", - " if they are not valid Python identifiers.\n", - " \n", - " Set ``dummify=True`` to replace all arguments with dummy symbols\n", - " (if ``args`` is not a string) - for example, to ensure that the\n", - " arguments do not redefine any built-in names.\n", - " \n", - " Examples\n", - " ========\n", - " \n", - " >>> from sympy.utilities.lambdify import implemented_function\n", - " >>> from sympy import sqrt, sin, Matrix\n", - " >>> from sympy import Function\n", - " >>> from sympy.abc import w, x, y, z\n", - " \n", - " >>> f = lambdify(x, x**2)\n", - " >>> f(2)\n", - " 4\n", - " >>> f = lambdify((x, y, z), [z, y, x])\n", - " >>> f(1,2,3)\n", - " [3, 2, 1]\n", - " >>> f = lambdify(x, sqrt(x))\n", - " >>> f(4)\n", - " 2.0\n", - " >>> f = lambdify((x, y), sin(x*y)**2)\n", - " >>> f(0, 5)\n", - " 0.0\n", - " >>> row = lambdify((x, y), Matrix((x, x + y)).T, modules='sympy')\n", - " >>> row(1, 2)\n", - " Matrix([[1, 3]])\n", - " \n", - " ``lambdify`` can be used to translate SymPy expressions into mpmath\n", - " functions. This may be preferable to using ``evalf`` (which uses mpmath on\n", - " the backend) in some cases.\n", - " \n", - " >>> import mpmath\n", - " >>> f = lambdify(x, sin(x), 'mpmath')\n", - " >>> f(1)\n", - " 0.8414709848078965\n", - " \n", - " Tuple arguments are handled and the lambdified function should\n", - " be called with the same type of arguments as were used to create\n", - " the function:\n", - " \n", - " >>> f = lambdify((x, (y, z)), x + y)\n", - " >>> f(1, (2, 4))\n", - " 3\n", - " \n", - " The ``flatten`` function can be used to always work with flattened\n", - " arguments:\n", - " \n", - " >>> from sympy.utilities.iterables import flatten\n", - " >>> args = w, (x, (y, z))\n", - " >>> vals = 1, (2, (3, 4))\n", - " >>> f = lambdify(flatten(args), w + x + y + z)\n", - " >>> f(*flatten(vals))\n", - " 10\n", - " \n", - " Functions present in ``expr`` can also carry their own numerical\n", - " implementations, in a callable attached to the ``_imp_`` attribute. This\n", - " can be used with undefined functions using the ``implemented_function``\n", - " factory:\n", - " \n", - " >>> f = implemented_function(Function('f'), lambda x: x+1)\n", - " >>> func = lambdify(x, f(x))\n", - " >>> func(4)\n", - " 5\n", - " \n", - " ``lambdify`` always prefers ``_imp_`` implementations to implementations\n", - " in other namespaces, unless the ``use_imps`` input parameter is False.\n", - " \n", - " Usage with Tensorflow:\n", - " \n", - " >>> import tensorflow as tf\n", - " >>> from sympy import Max, sin, lambdify\n", - " >>> from sympy.abc import x\n", - " \n", - " >>> f = Max(x, sin(x))\n", - " >>> func = lambdify(x, f, 'tensorflow')\n", - " \n", - " After tensorflow v2, eager execution is enabled by default.\n", - " If you want to get the compatible result across tensorflow v1 and v2\n", - " as same as this tutorial, run this line.\n", - " \n", - " >>> tf.compat.v1.enable_eager_execution()\n", - " \n", - " If you have eager execution enabled, you can get the result out\n", - " immediately as you can use numpy.\n", - " \n", - " If you pass tensorflow objects, you may get an ``EagerTensor``\n", - " object instead of value.\n", - " \n", - " >>> result = func(tf.constant(1.0))\n", - " >>> print(result)\n", - " tf.Tensor(1.0, shape=(), dtype=float32)\n", - " >>> print(result.__class__)\n", - " \n", - " \n", - " You can use ``.numpy()`` to get the numpy value of the tensor.\n", - " \n", - " >>> result.numpy()\n", - " 1.0\n", - " \n", - " >>> var = tf.Variable(2.0)\n", - " >>> result = func(var) # also works for tf.Variable and tf.Placeholder\n", - " >>> result.numpy()\n", - " 2.0\n", - " \n", - " And it works with any shape array.\n", - " \n", - " >>> tensor = tf.constant([[1.0, 2.0], [3.0, 4.0]])\n", - " >>> result = func(tensor)\n", - " >>> result.numpy()\n", - " [[1. 2.]\n", - " [3. 4.]]\n", - " \n", - " Notes\n", - " =====\n", - " \n", - " - For functions involving large array calculations, numexpr can provide a\n", - " significant speedup over numpy. Please note that the available functions\n", - " for numexpr are more limited than numpy but can be expanded with\n", - " ``implemented_function`` and user defined subclasses of Function. If\n", - " specified, numexpr may be the only option in modules. The official list\n", - " of numexpr functions can be found at:\n", - " https://numexpr.readthedocs.io/en/latest/user_guide.html#supported-functions\n", - " \n", - " - In previous versions of SymPy, ``lambdify`` replaced ``Matrix`` with\n", - " ``numpy.matrix`` by default. As of SymPy 1.0 ``numpy.array`` is the\n", - " default. To get the old default behavior you must pass in\n", - " ``[{'ImmutableDenseMatrix': numpy.matrix}, 'numpy']`` to the\n", - " ``modules`` kwarg.\n", - " \n", - " >>> from sympy import lambdify, Matrix\n", - " >>> from sympy.abc import x, y\n", - " >>> import numpy\n", - " >>> array2mat = [{'ImmutableDenseMatrix': numpy.matrix}, 'numpy']\n", - " >>> f = lambdify((x, y), Matrix([x, y]), modules=array2mat)\n", - " >>> f(1, 2)\n", - " [[1]\n", - " [2]]\n", - " \n", - " - In the above examples, the generated functions can accept scalar\n", - " values or numpy arrays as arguments. However, in some cases\n", - " the generated function relies on the input being a numpy array:\n", - " \n", - " >>> from sympy import Piecewise\n", - " >>> from sympy.testing.pytest import ignore_warnings\n", - " >>> f = lambdify(x, Piecewise((x, x <= 1), (1/x, x > 1)), \"numpy\")\n", - " \n", - " >>> with ignore_warnings(RuntimeWarning):\n", - " ... f(numpy.array([-1, 0, 1, 2]))\n", - " [-1. 0. 1. 0.5]\n", - " \n", - " >>> f(0)\n", - " Traceback (most recent call last):\n", - " ...\n", - " ZeroDivisionError: division by zero\n", - " \n", - " In such cases, the input should be wrapped in a numpy array:\n", - " \n", - " >>> with ignore_warnings(RuntimeWarning):\n", - " ... float(f(numpy.array([0])))\n", - " 0.0\n", - " \n", - " Or if numpy functionality is not required another module can be used:\n", - " \n", - " >>> f = lambdify(x, Piecewise((x, x <= 1), (1/x, x > 1)), \"math\")\n", - " >>> f(0)\n", - " 0\n", - " \n", - " .. _lambdify-how-it-works:\n", - " \n", - " How it works\n", - " ============\n", - " \n", - " When using this function, it helps a great deal to have an idea of what it\n", - " is doing. At its core, lambdify is nothing more than a namespace\n", - " translation, on top of a special printer that makes some corner cases work\n", - " properly.\n", - " \n", - " To understand lambdify, first we must properly understand how Python\n", - " namespaces work. Say we had two files. One called ``sin_cos_sympy.py``,\n", - " with\n", - " \n", - " .. code:: python\n", - " \n", - " # sin_cos_sympy.py\n", - " \n", - " from sympy import sin, cos\n", - " \n", - " def sin_cos(x):\n", - " return sin(x) + cos(x)\n", - " \n", - " \n", - " and one called ``sin_cos_numpy.py`` with\n", - " \n", - " .. code:: python\n", - " \n", - " # sin_cos_numpy.py\n", - " \n", - " from numpy import sin, cos\n", - " \n", - " def sin_cos(x):\n", - " return sin(x) + cos(x)\n", - " \n", - " The two files define an identical function ``sin_cos``. However, in the\n", - " first file, ``sin`` and ``cos`` are defined as the SymPy ``sin`` and\n", - " ``cos``. In the second, they are defined as the NumPy versions.\n", - " \n", - " If we were to import the first file and use the ``sin_cos`` function, we\n", - " would get something like\n", - " \n", - " >>> from sin_cos_sympy import sin_cos # doctest: +SKIP\n", - " >>> sin_cos(1) # doctest: +SKIP\n", - " cos(1) + sin(1)\n", - " \n", - " On the other hand, if we imported ``sin_cos`` from the second file, we\n", - " would get\n", - " \n", - " >>> from sin_cos_numpy import sin_cos # doctest: +SKIP\n", - " >>> sin_cos(1) # doctest: +SKIP\n", - " 1.38177329068\n", - " \n", - " In the first case we got a symbolic output, because it used the symbolic\n", - " ``sin`` and ``cos`` functions from SymPy. In the second, we got a numeric\n", - " result, because ``sin_cos`` used the numeric ``sin`` and ``cos`` functions\n", - " from NumPy. But notice that the versions of ``sin`` and ``cos`` that were\n", - " used was not inherent to the ``sin_cos`` function definition. Both\n", - " ``sin_cos`` definitions are exactly the same. Rather, it was based on the\n", - " names defined at the module where the ``sin_cos`` function was defined.\n", - " \n", - " The key point here is that when function in Python references a name that\n", - " is not defined in the function, that name is looked up in the \"global\"\n", - " namespace of the module where that function is defined.\n", - " \n", - " Now, in Python, we can emulate this behavior without actually writing a\n", - " file to disk using the ``exec`` function. ``exec`` takes a string\n", - " containing a block of Python code, and a dictionary that should contain\n", - " the global variables of the module. It then executes the code \"in\" that\n", - " dictionary, as if it were the module globals. The following is equivalent\n", - " to the ``sin_cos`` defined in ``sin_cos_sympy.py``:\n", - " \n", - " >>> import sympy\n", - " >>> module_dictionary = {'sin': sympy.sin, 'cos': sympy.cos}\n", - " >>> exec('''\n", - " ... def sin_cos(x):\n", - " ... return sin(x) + cos(x)\n", - " ... ''', module_dictionary)\n", - " >>> sin_cos = module_dictionary['sin_cos']\n", - " >>> sin_cos(1)\n", - " cos(1) + sin(1)\n", - " \n", - " and similarly with ``sin_cos_numpy``:\n", - " \n", - " >>> import numpy\n", - " >>> module_dictionary = {'sin': numpy.sin, 'cos': numpy.cos}\n", - " >>> exec('''\n", - " ... def sin_cos(x):\n", - " ... return sin(x) + cos(x)\n", - " ... ''', module_dictionary)\n", - " >>> sin_cos = module_dictionary['sin_cos']\n", - " >>> sin_cos(1)\n", - " 1.38177329068\n", - " \n", - " So now we can get an idea of how ``lambdify`` works. The name \"lambdify\"\n", - " comes from the fact that we can think of something like ``lambdify(x,\n", - " sin(x) + cos(x), 'numpy')`` as ``lambda x: sin(x) + cos(x)``, where\n", - " ``sin`` and ``cos`` come from the ``numpy`` namespace. This is also why\n", - " the symbols argument is first in ``lambdify``, as opposed to most SymPy\n", - " functions where it comes after the expression: to better mimic the\n", - " ``lambda`` keyword.\n", - " \n", - " ``lambdify`` takes the input expression (like ``sin(x) + cos(x)``) and\n", - " \n", - " 1. Converts it to a string\n", - " 2. Creates a module globals dictionary based on the modules that are\n", - " passed in (by default, it uses the NumPy module)\n", - " 3. Creates the string ``\"def func({vars}): return {expr}\"``, where ``{vars}`` is the\n", - " list of variables separated by commas, and ``{expr}`` is the string\n", - " created in step 1., then ``exec``s that string with the module globals\n", - " namespace and returns ``func``.\n", - " \n", - " In fact, functions returned by ``lambdify`` support inspection. So you can\n", - " see exactly how they are defined by using ``inspect.getsource``, or ``??`` if you\n", - " are using IPython or the Jupyter notebook.\n", - " \n", - " >>> f = lambdify(x, sin(x) + cos(x))\n", - " >>> import inspect\n", - " >>> print(inspect.getsource(f))\n", - " def _lambdifygenerated(x):\n", - " return (sin(x) + cos(x))\n", - " \n", - " This shows us the source code of the function, but not the namespace it\n", - " was defined in. We can inspect that by looking at the ``__globals__``\n", - " attribute of ``f``:\n", - " \n", - " >>> f.__globals__['sin']\n", - " \n", - " >>> f.__globals__['cos']\n", - " \n", - " >>> f.__globals__['sin'] is numpy.sin\n", - " True\n", - " \n", - " This shows us that ``sin`` and ``cos`` in the namespace of ``f`` will be\n", - " ``numpy.sin`` and ``numpy.cos``.\n", - " \n", - " Note that there are some convenience layers in each of these steps, but at\n", - " the core, this is how ``lambdify`` works. Step 1 is done using the\n", - " ``LambdaPrinter`` printers defined in the printing module (see\n", - " :mod:`sympy.printing.lambdarepr`). This allows different SymPy expressions\n", - " to define how they should be converted to a string for different modules.\n", - " You can change which printer ``lambdify`` uses by passing a custom printer\n", - " in to the ``printer`` argument.\n", - " \n", - " Step 2 is augmented by certain translations. There are default\n", - " translations for each module, but you can provide your own by passing a\n", - " list to the ``modules`` argument. For instance,\n", - " \n", - " >>> def mysin(x):\n", - " ... print('taking the sin of', x)\n", - " ... return numpy.sin(x)\n", - " ...\n", - " >>> f = lambdify(x, sin(x), [{'sin': mysin}, 'numpy'])\n", - " >>> f(1)\n", - " taking the sin of 1\n", - " 0.8414709848078965\n", - " \n", - " The globals dictionary is generated from the list by merging the\n", - " dictionary ``{'sin': mysin}`` and the module dictionary for NumPy. The\n", - " merging is done so that earlier items take precedence, which is why\n", - " ``mysin`` is used above instead of ``numpy.sin``.\n", - " \n", - " If you want to modify the way ``lambdify`` works for a given function, it\n", - " is usually easiest to do so by modifying the globals dictionary as such.\n", - " In more complicated cases, it may be necessary to create and pass in a\n", - " custom printer.\n", - " \n", - " Finally, step 3 is augmented with certain convenience operations, such as\n", - " the addition of a docstring.\n", - " \n", - " Understanding how ``lambdify`` works can make it easier to avoid certain\n", - " gotchas when using it. For instance, a common mistake is to create a\n", - " lambdified function for one module (say, NumPy), and pass it objects from\n", - " another (say, a SymPy expression).\n", - " \n", - " For instance, say we create\n", - " \n", - " >>> from sympy.abc import x\n", - " >>> f = lambdify(x, x + 1, 'numpy')\n", - " \n", - " Now if we pass in a NumPy array, we get that array plus 1\n", - " \n", - " >>> import numpy\n", - " >>> a = numpy.array([1, 2])\n", - " >>> f(a)\n", - " [2 3]\n", - " \n", - " But what happens if you make the mistake of passing in a SymPy expression\n", - " instead of a NumPy array:\n", - " \n", - " >>> f(x + 1)\n", - " x + 2\n", - " \n", - " This worked, but it was only by accident. Now take a different lambdified\n", - " function:\n", - " \n", - " >>> from sympy import sin\n", - " >>> g = lambdify(x, x + sin(x), 'numpy')\n", - " \n", - " This works as expected on NumPy arrays:\n", - " \n", - " >>> g(a)\n", - " [1.84147098 2.90929743]\n", - " \n", - " But if we try to pass in a SymPy expression, it fails\n", - " \n", - " >>> try:\n", - " ... g(x + 1)\n", - " ... # NumPy release after 1.17 raises TypeError instead of\n", - " ... # AttributeError\n", - " ... except (AttributeError, TypeError):\n", - " ... raise AttributeError() # doctest: +IGNORE_EXCEPTION_DETAIL\n", - " Traceback (most recent call last):\n", - " ...\n", - " AttributeError:\n", - " \n", - " Now, let's look at what happened. The reason this fails is that ``g``\n", - " calls ``numpy.sin`` on the input expression, and ``numpy.sin`` does not\n", - " know how to operate on a SymPy object. **As a general rule, NumPy\n", - " functions do not know how to operate on SymPy expressions, and SymPy\n", - " functions do not know how to operate on NumPy arrays. This is why lambdify\n", - " exists: to provide a bridge between SymPy and NumPy.**\n", - " \n", - " However, why is it that ``f`` did work? That's because ``f`` doesn't call\n", - " any functions, it only adds 1. So the resulting function that is created,\n", - " ``def _lambdifygenerated(x): return x + 1`` does not depend on the globals\n", - " namespace it is defined in. Thus it works, but only by accident. A future\n", - " version of ``lambdify`` may remove this behavior.\n", - " \n", - " Be aware that certain implementation details described here may change in\n", - " future versions of SymPy. The API of passing in custom modules and\n", - " printers will not change, but the details of how a lambda function is\n", - " created may change. However, the basic idea will remain the same, and\n", - " understanding it will be helpful to understanding the behavior of\n", - " lambdify.\n", - " \n", - " **In general: you should create lambdified functions for one module (say,\n", - " NumPy), and only pass it input types that are compatible with that module\n", - " (say, NumPy arrays).** Remember that by default, if the ``module``\n", - " argument is not provided, ``lambdify`` creates functions using the NumPy\n", - " and SciPy namespaces.\n", - "\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ - "help(lambdify)" + "#help(lambdify)" ] }, { @@ -799,6 +221,7 @@ "http://docs.sympy.org/latest/modules/physics/units/quantities.html\n", "\n", "Let's try this out. Newton's 2nd law is\n", + "\n", "$$F = ma$$\n", "\n", "Create a mass of 1 kg and an acceleration of 10 m/s$^2$, and compute the force, $F$, and express the result in Newtons.\n", @@ -816,7 +239,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -830,7 +253,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.5" + "version": "3.10.10" } }, "nbformat": 4, diff --git a/content/_toc.yml b/content/_toc.yml index 9add4d2..0fc1289 100644 --- a/content/_toc.yml +++ b/content/_toc.yml @@ -31,5 +31,5 @@ chapters: - file: 05-python-scipy/scipy-exercises - file: 06-python-sympy/README sections: - - file: 06-python-sympy/sympy-basics + - file: 06-python-sympy/sympy-examples - file: 06-python-sympy/sympy-exercises