<jupyter_start><jupyter_text>Computing for Mathematics - Mock individual courseworkThis jupyter notebook contains questions that will resemble the questions in your individual coursework.**Important** Do not delete the cells containing: ``` BEGIN SOLUTION END SOLUTION```write your solution attempts in those cells.**If you would like to** submit this notebook:- Change the name of the notebook from `main` to: ``. For example, if your student number is `c1234567` then change the name of the notebook to `c1234567`.- Write all your solution attempts in the correct locations;- Save the notebook (`File>Save As`);- Follow the instructions given in class/email to submit.  Question 1Output the evaluation of the following expressions exactly.a. \\(\frac{(9a^2bc^4) ^ {\frac{1}{2}}}{6ab^{\frac{3}{2}}c}\\)<jupyter_code>### BEGIN SOLUTION
import sympy as sym
a, b, c = sym.Symbol("a"), sym.Symbol("b"), sym.Symbol("c")

sym.expand((9 * a ** 2 * b * c ** 4) ** (sym.S(1) / 2) / (6 * a * b ** (sym.S(3) / 2) * c))
### END SOLUTION<jupyter_output><empty_output><jupyter_text>b. \\((2 ^ {\frac{1}{2}} + 2) ^ 2 - 2 ^ {\frac{5}{2}}\\)<jupyter_code>### BEGIN SOLUTION
sym.expand((sym.S(2) ** (sym.S(1) / 2) + 2) ** 2 - 2 ** (sym.S(5) / 2))
### END SOLUTION<jupyter_output><empty_output><jupyter_text>3. \\((\frac{1}{8}) ^ {\frac{4}{3}}\\)<jupyter_code>### BEGIN SOLUTION
(sym.S(1) / 8) ** (sym.S(4) / 3)
### END SOLUTION<jupyter_output><empty_output><jupyter_text>Question 2Write a function `expand` that takes a given mathematical expression and returns the expanded expression.<jupyter_code>def expand(expression):
    ### BEGIN SOLUTION
    """
    Take a symbolic expression and expands it.
    """
    return sym.expand(expression)
    ### END SOLUTION<jupyter_output><empty_output><jupyter_text>Question 3The matrix \\(D\\) is given by \\(D = \begin{pmatrix} 1& 2 & a\\ 3 & 1 & 0\\ 1 & 1 & 1\end{pmatrix}\\) where \\(a\ne 2\\).a. Create a variable `D` which has value the matrix \\(D\\).<jupyter_code>### BEGIN SOLUTION
a = sym.Symbol("a")
D = sym.Matrix([[1, 2, a], [3, 1, 0], [1, 1, 1]])
### END SOLUTION<jupyter_output><empty_output><jupyter_text>b. Create a variable `D_inv` with value the inverse of \\(D\\).<jupyter_code>### BEGIN SOLUTION
D_inv = D.inv()
### END SOLUTION<jupyter_output><empty_output><jupyter_text>c. Using `D_inv` **output** the solution of the following system of equations:\\[\begin{array}{r}    x + 2y + 4z = 3\\    3x + y = 4\\    x + y + z = 1\\\end{array}\\]<jupyter_code>### BEGIN SOLUTION
b = sym.Matrix([[3], [4], [1]])
sym.simplify(D.inv() @ b).subs({a: 4})
### END SOLUTION<jupyter_output><empty_output><jupyter_text>Question 4During a game of frisbee between a handler and their dog the handler chooses to randomly select if they throw using a backhand or a forehand: 25% of the time they will throw a backhand.Because of the way their dog chooses to approach a flying frisbee they catch it with the following probabilities:- 80% of the time when it is thrown using a backhand- 90% of the time when it is thrown using a forehanda. Write a function `sample_experiment()` that simulates a given throw and returns the throw type (as a string with value `"backhand"` or `"forehand"`) and whether it was caught (as a boolean: either `True` or `False`).<jupyter_code>import random


def sample_experiment():
    """
    Returns the throw type and whether it was caught
    """
    ### BEGIN SOLUTION
    if random.random() < .25:
        throw = "backhand"
        probability_of_catch = .8
    else:
        throw = "forehand"
        probability_of_catch = .9
                
    caught = random.random() < probability_of_catch
    ### END SOLUTION
    return throw, caught<jupyter_output><empty_output><jupyter_text>b. Using 1,000,000 samples create a variable `probability_of_catch` which has value an estimate for the probability of the frisbee being caught.<jupyter_code>### BEGIN SOLUTION
number_of_repetitions = 1_000_000
random.seed(0)
samples = [sample_experiment() for repetition in range(number_of_repetitions)]
probability_of_catch = sum(catch is True for throw, catch in samples) / number_of_repetitions
### END SOLUTION<jupyter_output><empty_output><jupyter_text>c. Using the above, create a variable `probability_of_forehand_given_drop` which has value an estimate for the probability of the frisbee being thrown with a forehand given that it was not caught.<jupyter_code>### BEGIN SOLUTION
samples_with_drop = [(throw, catch) for throw, catch in samples if catch is False]
number_of_drops = len(samples_with_drop)
probability_of_forehand_given_drop = sum(throw == "forehand" for throw, catch in samples_with_drop) / number_of_drops
### END SOLUTION<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13550709294939656, 'fraction_numerical': 0.023502011433410967, 'mean_word_length': 4.512252042007002, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '277489', 'license': 'MIT', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1533, 'n_words': 523, 'path': 'assets/assessment/mock/solution.ipynb', 'repo_name': 'drvinceknight/cfm', 'size': '4723'}