# Use variable Length[] in Solve[]?

Posted 4 months ago
600 Views
|
3 Replies
|
3 Total Likes
|
 I'm trying to use Mathematica to solve some of the problems on Project Euler. I'm running into an issue with using Length[] in a Solve[] function.My full function is: Solve[Length[Divisors[PolygonalNumber[x]]] - 1 > 500, x, PositiveIntegers]It only outputs an empty set (no solutions). I've tried it with FindInstance[] and it does the same thing, and using Reduce[] simply evaluates to False. I'm very new to Mathematica so any help in understanding how I can fix this or what the limitations of equation solving are would be very appreciated!
3 Replies
Sort By:
Posted 4 months ago
 First thing would be to check how the input evaluates. In[4053]:= Length[Divisors[PolygonalNumber[x]]] - 1 Out[4053]= 0 So Solve sees False as its input, hence empty solution set.Since this is a PE problem, you will likely need to consider a less brute-force approach.
 Length is a programming construct, not a part of symbolic math. Solve works on statements of symbolic math. Mathematica's symbolic math basically consists of: Problems it can solve. Transformation rules it tries to use to transform your problem into one it can solve. Given that your problem is a research problem, it is unlikely to be in the first category. Given that its statement is procedural, transformation is also unlikely.
 That's a great explanation, though I'm still wondering if there is a way to mark the expression as variable since if I use Table[Length[Divisors[PolygonalNumber[x]]] - 1, {x, 100}], it shows the list of computed factors correctly. I thought Solve[] would not prematurely evaluate an expression containing the variable to be solved for...And yes, how I approach these problems is typically to design a theoretical brute-force method and then refactor the solution until it runs well and makes sense conceptually. In this case, though, I was able to use Table[] with the function and just tried a large range for x and it found the answer in a second or two. Still wondering if this could have been avoided with other functions that don't require an explicit range of values to be evaluated.