<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def controlled(num_ptr_bits, U):
 """ Given a one-qubit gate matrix U, construct a controlled-U on all pointer qubits. """

    d = 2 ** (1 + num_ptr_bits)
    m = np.eye(d)
    m[d - 2:, d - 2:] = U
    return m