# %% # Import SymPy for symbolic mathematics import sympy as sp # Import display helpers to render LaTeX output in Jupyter/IPython from IPython.display import display, Math # Define the symbolic variable x x = sp.symbols("x") # List of functions to differentiate functions = [ 5 ** (x**3 - sp.sqrt(x) + 7), sp.log(9 * x**2 - 4, 2), sp.log(x**256) ** (1 / 4), 1 / (1 + sp.exp(-x)), sp.log(x) ** sp.log(x), (2 ** (-sp.sqrt(sp.Abs(x)))) / (sp.log(2)), ] # Loop over each function, compute its derivative, and display both for func in functions: # Differentiate with respect to x, then simplify the result derivativ = sp.simplify(sp.diff(func)) # Render f(x) and f'(x) as LaTeX; the double backslash (\\) creates a line break; ln_notation=True transforms log to ln display( Math( r"f(x) = {} \\ f'(x) = {}".format( sp.latex(func, ln_notation=True), sp.latex(derivativ, ln_notation=True) ) ) ) # %%