3
$\begingroup$

How can I solve an equation of the following form?

$$x = 10+\mathrm{\mathbf{PrimePi}[x]}$$

where $x$ is an integer. I am using Solve but am getting the following error:

$RecursionLimit::reclim2 Recursion depth of 1024 exceeded during evaluation of PrimePi[x]

It is the first time I attempt to do this type of task in Mathematica so I could be missing something very elemental.

$\endgroup$
3
  • 6
    $\begingroup$ You're probably using = (assignment) instead of == (equality). $\endgroup$ Commented Jan 28, 2020 at 6:33
  • $\begingroup$ Thanks for the comment, at first I did that and I think the message error was the same, but then corrected it and happened this. The answer below solved it, though I end up using a "while" loop to solve it iteratively, which happened to be much much quicker (not sure why) - and which did not require to specify an upper bound for x. $\endgroup$ Commented Jan 29, 2020 at 0:45
  • 3
    $\begingroup$ The reason why the problem didn't go away after you changed = to == was probably that you did not clear/quit the kernel, and so the previous definition was still lingering in the background (Mathematica doesn't forget anything unless you tell it to). With ?x you can find out what definitions are associated with x. $\endgroup$ Commented Jan 29, 2020 at 7:00

1 Answer 1

8
$\begingroup$
Solve[{0 < x < 1000 && x == 10 + PrimePi[x]}, x, Integers] (* {{x -> 16}, {x -> 17}} *) 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.