2
$\begingroup$

I understand that

FixedPoint[(# + 2/# )/2 &, 1.]

can be written

x[0] = 1; x[1] = 2;
x[k_] := N@(x[k - 1] + x[1]/x[k - 1])/2
x@5

but I don't understand how to interpret

CompositeP[n_Integer] := FixedPoint[n + PrimePi[#] + 1 &, n] - n

mathematically. How could it be rewritten using a recurrence relation? How would it be written in standard mathematical notation?

$\endgroup$
2
  • 1
    $\begingroup$ $\begin{align}x_0&=n\\x_{k+1}&=π(x_k)+n+1\end{align}$ $\endgroup$ Commented May 9, 2015 at 11:25
  • $\begingroup$ @Guesswhoitis. great! so simple! thanks :) $\endgroup$
    – martin
    Commented May 9, 2015 at 11:28

1 Answer 1

1
$\begingroup$

Just to document what @Guesswhoitis. said in coments,

\begin{align}x_0&=n\\x_{k+1}&=π(x_k)+n+1\end{align}

which can be written

CompositeA[n_Integer] := FixedPoint[n + PrimePi[#] + 1 &, n]

or

rr = 10^2; x[0] = 1; x[1] = rr;
x[k_] := PrimePi[x[k - 1]] + x[1] + 1
x@5

On a different note, the same goal can be accomplised with

CompositeB[a_, r_] := 1 + a + Fold[PrimePi[a + #1 + 1] &, -1, Range[r]]

where

comp[a_] := 1 +a +Fold[PrimePi[a + #1 + 1] &, -1, Range[Floor[Log[a]] + 4]]

seems to do the trick, where Floor[Log[a]] + 4 is a rough (over) guess at number of iterations to make.

$\endgroup$
2
  • 3
    $\begingroup$ I think you should put more attention to wording. Those functions are not the same. Arguments provided for them are different things either. The only thing which is the same is the goal. Which still is arguable since in FixedPoint you don't have to know a priori how many iterations to make. $\endgroup$
    – Kuba
    Commented May 9, 2015 at 14:16
  • $\begingroup$ @Kuba ok, will update $\endgroup$
    – martin
    Commented May 9, 2015 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.