Plot counting function semi primes

I am trying to generate a plottable semi-prime counting function.

Have tried:

DiscretePlot[Gather[{a = PrimeOmega[Range[100]];
b = PrimeNu[Range[100]];
Count[Transpose[{a, b}], {2, 2}]}
+
{a = PrimeOmega[Range[100]];
b = PrimeNu[Range[100]];
Count[Transpose[{a, b}], {2, 1}]}],{x, 0, 15}, Filling -> Bottom]]


but really have no clue as to where to go from here!

• Perhaps you should be a little bit more specific about what you want to achieve. Oct 9 '13 at 19:29
• For example, Gather[PrimeOmega[Range[100]]]gives a kind of counting function for PrimeOmega[#]. I still don't know how to plot this though. Oct 9 '13 at 19:49
• Gather[PrimeOmega[Range[10]]] outputs the following: {{0}, {1, 1, 1, 1}, {2, 2, 2, 2}, {3}} How can I plot this as one continuous plot - ie - in the form of: Plot[PrimePi[x], {x, 0, 10}, Filling -> Bottom] Oct 9 '13 at 19:55
• Having done that, how would I then create a semi-prime counting plot? Oct 9 '13 at 19:56
• Given that:a = PrimeOmega[Range[100]]; b = PrimeNu[Range[100]]; Count[Transpose[{a, b}], {2, 2}]} PLUS a = PrimeOmega[Range[100]]; b = PrimeNu[Range[100]]; Count[Transpose[{a, b}], {2, 1}]} gives all semi primes up to a given range Oct 9 '13 at 19:57

4 Answers

a = PrimeOmega[Range[100]];
b = PrimeNu[Range[100]];
ListPlot[{Accumulate[Flatten[Inner[If[#1 === #2 === 2, 1, 0] &, a, b, List]] +
Inner[If[#1 === #2 + 1 === 2, 1, 0] &, a, b, List]],
Table[PrimePi[x], {x, 100}]}]


Makes quite a nice comparison

• Thanks, Artes. Just a quick question - how do you link these images? Oct 9 '13 at 23:29
• When editing an answer there are links to adequate tools, e.g. Ctrl + G opens a window to upload an image, e.g. in gif format. Oct 9 '13 at 23:43
• If you think you've got the best or the most appropriate answer to a question you may accept it by clicking a tick mark under the vote counter of a given answer. Usually it is sufficient to wait one or two days to get an expected answer. Oct 9 '13 at 23:48
• Great - OK, thanks Oct 9 '13 at 23:59
dat = Thread[{PrimeOmega[Range[100]],
PrimeNu[Range[100]]}] /. {{2, 1} | {2, 2} -> 1, {_, _} -> 0}

ListPlot[Accumulate@dat,Filling->Axis]


This formula for the number of semi-primes less than or equal to $n$ is from http://mathworld.wolfram.com/Semiprime.html. A semi-prime may be written as $p*q$, where we can assume $p\le q$. The number of semi-primes less than or equal to a maximum $n$ requires checking $\pi(\sqrt{n})$ values of $p$, where $\pi$ is the prime counting function. For each possible $p_k$ there are $\pi(n/p_k)$ values of $q$ such that $p*q\le n$. However, the condition $p\le q$ means that not all these possible $q$ are allowed. The first $k-1$ possible values of $q$ must be dropped. Thus, $\pi^{(2)}(n)=\sum_{k=1}^{\pi(\sqrt{n})} \left[ \pi(n/p_k)-k+1 \right]$

SemiprimeCount[n_Integer] := Sum[PrimePi[n/Prime[k]]-k+1, {k,1,PrimePi[Sqrt[n]]}]
SetAttributes[SemiprimeCount,Listable]


I make plots using the functionBlockPlot

 BlockPlot[v_] := Partition[Flatten[
{1, v[[1]], Table[{i, v[[i - 1]], i, v[[i]]}, {i, 2, Length[v]}]}], 2]


and, for example,

ListLinePlot[BlockPlot[SemiprimeCount[Range[50]]], Frame->True,
PlotStyle -> {Thick, Red}, BaseStyle -> {FontSize->14},
FrameLabel -> {"Number  n", "Semiprime Count"},
PlotLabel -> "Number of Semiprimes \[LessEqual] n",
Filling -> Automatic]

a = PrimeOmega[Range[100]];
b = PrimeNu[Range[100]];
ListPlot[Accumulate[Flatten[Inner[If[#1 === #2 === 2, 1, 0] &, a, b, List]]
+ Inner[If[#1 === #2 + 1 === 2, 1, 0] &, a, b, List]],
Filling -> Bottom]