Fix trace_quad_form to use value_of
Add unit test for trace_quad_form.