## DEV Community is a community of 719,546 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# Discussion on: Optimizing code with algebra

## Replies for: Not quite... Solving for the given equation t(n) = 2^(n-1) + (2^(n-1) - 1) is straight forward. Nothing complicated about replacing n with an actu... `t(4) = 2^(3) + (2^(3) - 1)` // Math makes sense, but why did we decide to represent 8 as an 2 to the 3rd? Is the goal to find exponential representations?
`t(4) = 2^(4-1) + (2^(4-1) - 1)` // Why on earth did we decide 3 is better represented as 4-1??

Hold that thought right there. The reason why we use `4-1` instead of `3` is to represent the value of `n` in the formula, so we can write `n-1`. Because in that example, `n = 4`.

If you notice in my previous comment, my goal was not simply to solve the equation with several values of `n`, but to show how the result and the parameters of the function relate each other.

The goal of the deduction process is to find the function that solves these relations:
```t(1) = 1 + 0 // same as 2^(1-1) + (2^(1-1) - 1) t(2) = 2 + 1 // same as 2^(2-1) + (2^(2-1) - 1) t(3) = 4 + 3 // same as 2^(3-1) + (2^(3-1) - 1) t(4) = 8 + 7 // same as 2^(4-1) + (2^(4-1) - 1) t(5) = 16 + 15 // same as 2^(5-1) + (2^(5-1) - 1)```

That way you can find a function that solves for every value of `n`. Please let me know if I now made it clear.