def lambda_sum_largest(X, k):
 X = Expression.cast_to_const(X)
 if (X.size[0] != X.size[1]):
  raise ValueError('First argument must be a square matrix.')
 elif ((int(k) != k) or (k <= 0)):
  raise ValueError('Second argument must be a positive integer.')
 '\n    S_k(X) denotes lambda_sum_largest(X, k)\n    t >= k S_k(X - Z) + trace(Z), Z is PSD\n    implies\n    t >= ks + trace(Z)\n    Z is PSD\n    sI >= X - Z (PSD sense)\n    which implies\n    t >= ks + trace(Z) >= S_k(sI + Z) >= S_k(X)\n    We use the fact that\n    S_k(X) = sup_{sets of k orthonormal vectors u_i}\\sum_{i}u_i^T X u_i\n    and if Z >= X in PSD sense then\n    \\sum_{i}u_i^T Z u_i >= \\sum_{i}u_i^T X u_i\n\n    We have equality when s = lambda_k and Z diagonal\n    with Z_{ii} = (lambda_i - lambda_k)_+\n    '
 Z = Semidef(X.size[0])
 return ((k * lambda_max((X - Z))) + trace(Z))

def lambda_sum_largest ( X , k ) : X = Expression . cast_to_const ( X ) if ( X . size [ 0 ] != X . size [ 1 ] ) : raise ValueError ( 'First argument must be a square matrix.' ) elif ( ( int ( k ) != k ) or ( k <= 0 ) ) : raise ValueError ( 'Second argument must be a positive integer.' ) '\n    S_k(X) denotes lambda_sum_largest(X, k)\n    t >= k S_k(X - Z) + trace(Z), Z is PSD\n    implies\n    t >= ks + trace(Z)\n    Z is PSD\n    sI >= X - Z (PSD sense)\n    which implies\n    t >= ks + trace(Z) >= S_k(sI + Z) >= S_k(X)\n    We use the fact that\n    S_k(X) = sup_{sets of k orthonormal vectors u_i}\\sum_{i}u_i^T X u_i\n    and if Z >= X in PSD sense then\n    \\sum_{i}u_i^T Z u_i >= \\sum_{i}u_i^T X u_i\n\n    We have equality when s = lambda_k and Z diagonal\n    with Z_{ii} = (lambda_i - lambda_k)_+\n    ' Z = Semidef ( X . size [ 0 ] ) return ( ( k * lambda_max ( ( X - Z ) ) ) + trace ( Z ) )
sum of the largest k eigenvalues .