   df = dSdm;
end
f = S;

function [f, df] = conT2(m, policy, s)                                  % dCdm
if nargout < 2
    [M, S, C] = policy.fcn(policy, m, s);
else
    [M, S, C, dMdm, dSdm, dCdm] = policy.fcn(policy, m, s);
    df = dCdm;
end
f = C;

function [f, df] = conT3(s, policy, m)                                  % dMds
d = length(m);
v(tril(ones(d))==1) = s; s = reshape(v,d,d); s = s+s'-diag(diag(s));
if nargout < 2
    M = policy.fcn(policy, m, s);
else
    [M, S, C, dMdm, dSdm, dCdm, dMds] = p