def _transform_derivatives(data, dof_data):
    """Transform derivatives back to the physical element by applying the
    transformation matrix."""
    f_loop = format['generate loop']
    f_num_derivs = format['num derivatives']
    f_derivatives = format['reference derivatives']
    f_values = format['argument values']
    f_mul = format['mul']
    f_iadd = format['iadd']
    f_component = format['component']
    f_transform = format['transform matrix']
    f_r, f_s = format['free indices'][:2]
    f_index = format['matrix index']
    if data['topological_dimension'] == data['geometric_dimension']:
        _t = ''
        _g = ''
    else:
        _t = '_t'
        _g = '_g'
    num_components = dof_data['num_components']
    reference_offset = dof_data['reference_offset']
    physical_offset = dof_data['physical_offset']
    offset = reference_offset
    mapping = dof_data['mapping']
    if 'piola' in mapping:
        _p = '_p'
        num_components_p = data['geometric_dimension']
    else:
        _p = ''
        num_components_p = num_components
    code = [format['comment']('Transform derivatives back to physical element')
        ]
    lines = []
    for i in range(num_components_p):
        access_name = f_index(offset + i, f_r, f_num_derivs(_g))
        name = f_component(f_values, access_name)
        access_val = f_index(i, f_s, f_num_derivs(_t))
        value = f_mul([f_component(f_transform, [f_r, f_s]), f_component(
            f_derivatives + _p, access_val)])
        lines += [f_iadd(name, value)]
    loop_vars = [(f_r, 0, f_num_derivs(_g)), (f_s, 0, f_num_derivs(_t))]
    code += f_loop(lines, loop_vars)
    return code
