import math


def _element_order(num_basis_functions):
    """
    Calculate the order of an element based on the number of basis
    functions.

    This formula is based on solving k = n*(n + 1)/2 (for a triangular
    number k) and taking the positive root from the quadratic formula.
    """
    return int(round((math.sqrt(1 + 8*num_basis_functions) - 1)/2.0 - 1.0))