# Gotchas

Boilerplate to make the doctester work.  Run this cell first.


```
import sys
import os
sys.path.insert(1, os.path.join(os.path.pardir, "ipython_doctester"))
from sympy import *
from ipython_doctester import test
# Work around a bug in IPython. This will disable the ability to paste things with >>>
def notransform(line): return line
from IPython.core import inputsplitter
inputsplitter.transform_classic_prompt = notransform
```

For each exercise, fill in the function according to its docstring. Execute the cell to see if you did it right. 

## Symbols

What will be the output of the following code?

    x = 3
    y = symbols('y')
    a = x + y
    y = 5
    print a

Replace `???` in the below code with what you think the value of `a` will be.  Remember to define any Symbols you need!


```
@test
def symbols_exercise():
    """
    (This tests that your output is correct)

    >>> def testfunc():
    ...     x = 3
    ...     y = symbols('y')
    ...     a = x + y
    ...     y = 5
    ...     return a
    >>> symbols_exercise() == testfunc()
    True
    """
    return ??? # Replace ??? with what you think the value of a is
```

## Equality

Write a function that takes two expressions as input, and returns a tuple of two booleans. The first if they are equal symbolically, and the second if they are equal mathematically.


```
@test
def equality_exercise(a, b):
    """
    Determine if a = b symbolically and mathematically.

    Returns a tuple of two booleans. The first is True if a = b symbolically,
    the second is True if a = b mathematically.  Note the second may be False
    but the two still equal if SymPy is not powerful enough.

    Examples
    ========

    >>> x = symbols('x')
    >>> equality_exercise(x, 2)
    (False, False)
    >>> equality_exercise((x + 1)**2, x**2 + 2*x + 1)
    (False, True)
    >>> equality_exercise(2*x, 2*x)
    (True, True)
    """

```

## `^` and `/`

Correct the following functions


```
@test
def operator_exercise1():
    """
    >>> operator_exercise1()
    x**2 + 2*x + 1/2
    """
    x = symbols('x')
    return x^2 + 2*x + 1/2
```


```
@test
def operator_exercise2():
    """
    >>> operator_exercise2()
    (x**2/2 + 2*x + 3/4)**(3/2)
    """
    x = symbols('x')
    return (1/2*x^2 + 2*x + 3/4)^(3/2)
```

8e7961f1ec9290549ee1f972a5bdba0f416fd90f
ipynb
Jupyter Notebook
tutorial_exercises/Gotchas.ipynb
certik/scipy-2013-tutorial
26a1cab3a16402afdc20088cedf47acd9bc58483
BSD-3-Clause
2015-02-28T08:53:05.000Z
2021-12-05T05:37:59.000Z
sympy/Gotchas.ipynb
certik/scipy-in-13
418c139ab6e1b0c9acd53e7e1a02b8b930005096
BSD-3-Clause
2021-04-17T15:05:46.000Z
2021-04-17T15:05:46.000Z
sympy/Gotchas.ipynb
certik/scipy-in-13
418c139ab6e1b0c9acd53e7e1a02b8b930005096
BSD-3-Clause
2015-03-11T00:25:21.000Z
2021-08-25T14:52:40.000Z
Qwen/Qwen-72B
1. YES
2. YES