2
$\begingroup$

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!

$\endgroup$
5
  • $\begingroup$ Perhaps you should be a little bit more specific about what you want to achieve. $\endgroup$ Commented Oct 9, 2013 at 19:29
  • $\begingroup$ For example, Gather[PrimeOmega[Range[100]]]gives a kind of counting function for PrimeOmega[#]. I still don't know how to plot this though. $\endgroup$
    – martin
    Commented Oct 9, 2013 at 19:49
  • $\begingroup$ 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] $\endgroup$
    – martin
    Commented Oct 9, 2013 at 19:55
  • $\begingroup$ Having done that, how would I then create a semi-prime counting plot? $\endgroup$
    – martin
    Commented Oct 9, 2013 at 19:56
  • $\begingroup$ 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 $\endgroup$
    – martin
    Commented Oct 9, 2013 at 19:57

4 Answers 4

2
$\begingroup$
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}]}]

enter image description here

Makes quite a nice comparison

$\endgroup$
4
  • $\begingroup$ Thanks, Artes. Just a quick question - how do you link these images? $\endgroup$
    – martin
    Commented Oct 9, 2013 at 23:29
  • $\begingroup$ 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. $\endgroup$
    – Artes
    Commented Oct 9, 2013 at 23:43
  • $\begingroup$ 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. $\endgroup$
    – Artes
    Commented Oct 9, 2013 at 23:48
  • $\begingroup$ Great - OK, thanks $\endgroup$
    – martin
    Commented Oct 9, 2013 at 23:59
2
$\begingroup$
dat = Thread[{PrimeOmega[Range[100]], 
    PrimeNu[Range[100]]}] /. {{2, 1} | {2, 2} -> 1, {_, _} -> 0}

ListPlot[Accumulate@dat,Filling->Axis]

enter image description here

$\endgroup$
2
$\begingroup$

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]
$\endgroup$
1
$\begingroup$
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]

enter image description here

$\endgroup$
0

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.