def calculate_H_entry(i, j, k):
    """Returns the index of the free parameter for entry (i ,j) of a symmetric doubly stochastic matrix.
    Not applicable to last row and last column
    """
    assert i < k-1 and j < k-1, "unique index of the free parameters only exists for entries except last row or column"
    if i < j:
        return calculate_H_entry(j, i, k)
    else:
        return int(i+j*(k-1.5-j/2))