I was thinking about the way to write a function f(x) which results in the xth number of the fibonacci sequence. i.e. f(1) = 1, f(2) = 1, f(3) = 2 and so on. Thinking about this, f(n) = f(n-1) + f(n-2) will result in f(n) = f(n - 2) + f(n - 3) + f(n - 3) + f(n - 4) and so on infinitely, unless n = 1 or 2, in which case f(n) = 1 , so for example: f(3) = f(n - 1) + f(n -2) = f(2) + f(1) = 1 + 1 = 2, then f(4) = f(3) + f(2) = 2 + 1 = 3 and so on.
I don't believe this is correct mathematical notation, and I would need help with the conditionals part. I thought about:
f(x) = ((f(n-1) + f(n-2)) * (n > 2)) + (1 * (n < 3))
Given that the inequalities result in 0 or 1 (false/true), but I don't think that is correct mathematical notation either!
It's my first time here, so please tell me if I did something wrong!
You can write it as a "cases" function:
$$f(n)=\begin{cases}f(n-1)+f(n-2)&\text{if }n\ge3\\1&\text{otherwise}\end{cases}$$