@staticmethod
def _simplifyLinExpr(lexpr):
    """ simplify the given linear expression by combining coefficients

        This function combines all entries with the same name by adding up the
        corresponding coefficients, preserving the order of the names (first
        occurrence). Terms with coefficient zero are removed.

        Keyword arguments:

        lexpr -- list of (coefficient, name) pairs

        Returns: list of (coefficient, name) pairs with unique name
        """
    firstIndex = {}
    nUniqueNames = 0
    result = []
    for coef, name in lexpr:
        if name not in firstIndex:
            result.append((coef, name))
            firstIndex[name] = nUniqueNames
            nUniqueNames += 1
        else:
            j = firstIndex[name]
            result[j] = result[j][0] + coef, name
    for i in range(len(result) - 1, -1, -1):
        if result[i][0] == 0.0:
            del result[i]
    return result
