# solve for variable in iterator limit

Why can we not solve for P in the iterator limit in the problem below? How can it be solved?

f[P_] := 2*P
ttab[P_] := Table[t, {t, 1, f[P]}]
Total[ttab[55]]

(* 6105 *)

Solve[Total[ttab[P]] == 6105, P]


During evaluation of In[429]:= Table::iterb: Iterator {t,1,2 P} does not have appropriate bounds.

During evaluation of In[429]:= Table::iterb: Iterator {t,1,2 P} does not have appropriate bounds.

During evaluation of In[429]:= Solve::nsmet: This system cannot be solved with the methods available to Solve.

Solve[Total[Table[t, {t, 1, 2 P}]] == 6105, P]

• For this particular problem, Solve[Sum[t, {t, 1, 2 P}] == 6105, P] works. I'll let someone else explain why your attempt doesn't work (since I don't know! :) Commented Jan 19, 2021 at 3:28

Clear["Global*"]

f[P_] := 2*P

ttab[P_] := Range[f[P]]


Define the total as a function which only evaluates for a numeric argument.

total[P_?NumericQ] := Total[ttab[P]]

total[55]

(* 6105 *)


Also constrain the domain

Solve[{total[P] == 6105, 0 < P < 1000}, P, Integers]

(* {{P -> 55}} *)


However, as Chris K pointed out, the total can be simplified to

total2[P_] = Sum[t, {t, 1, f[P]}]

(* P (1 + 2 P) *)


Then the constraints can be relaxed

Solve[{total2[P] == 6105, P > 0}, P]

(* {{P -> 55}} *)
`