<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def diff(self, sym: Symbol, n: int = 1, expand_simplify: bool = True):
 """Differentiate by scalar parameter `sym`. Args: sym: What to differentiate by. n: How often to differentiate expand_simplify: Whether to simplify the result. Returns: The n-th derivative. """

        if not isinstance(sym, sympy.Basic):
            raise TypeError("%s needs to be a Sympy symbol" % sym)
        if sym.free_symbols.issubset(self.free_symbols):
            # QuantumDerivative.create delegates internally to _diff (the
            # explicit non-trivial derivative). Using `create` gives us free
            # caching
            deriv = QuantumDerivative.create(self, derivs={sym: n}, vals=None)
            if not deriv.is_zero and expand_simplify:
                deriv = deriv.expand().simplify_scalar()
            return deriv
        else:
            # the "issubset" of free symbols is a sufficient, but not a
            # necessary condition; if `sym` is non-atomic, determining whether
            # `self` depends on `sym` is not completely trivial (you'd have to
            # substitute with a Dummy)
            return self.__class__._zero