Add quad_form_sym and reduce code duplication in quad_form varis.
Reduce code duplocation in trace_quad_form varis.
Fix gradients of quad_form.