def even_fibonacci_mathematical(upper_limit): n = int(round(log(upper_limit * sqrt(5)) / log(PSI))) last_even_n = n if fibonacci(n) % 2 != 0: last_even_n = n - 1 if fibonacci(n - 1) % 2 != 0: last_even_n = n - 2 return sum_of_nth_first_fibonnaci_numbers(last_even_n) / 2
def sum_of_nth_first_fibonnaci_numbers(last_even_n): return fibonacci(last_even_n + 2) - 1