Skip to main content
tweaked the display per kglr's answer
Source Link
Fred Daniel Kline
  • 2.4k
  • 2
  • 20
  • 41

I googled for images of graphs and found nothing that even comes close to this one, so I want to experiment some more.

limc = 4;  
primes = Join[{1}, Prime[Range[limc]]];  
(* if you want to evaluate several times, put the above 2 lines in a 
separate cell and evaluate. Then run these below as needed *)  

limc = Length[primes] - 1;  
limv = Prime[limc + 1]^2 - 1;  
a = Flatten[Table[p -> p (m + 1), {p, primes}, {m, 1, limv/p - 1}]];  
g = Graph[a]Graph[a];
sources = Select[VertexList[g],VertexOutDegree[g, #] >= 1 &];  
SetProperty[g, {VertexLabels -> (Thread[
 sources -> Placed["Name", Center]]), 
VertexSize -> (Thread[sources -> 3/2])}]
Show[g]
primes = Join[primes, Flatten[Position[VertexDegree[g], 1]]];  
Print[Length[%] - 1 , " primes less than ", limv]  

The graph of the first 4 primes up to limv is:
[![Sieve of Eratosthenes Graph][1]][1]enter image description here

You will notice the one points to many odd numbers that have only one connection. These are the primes.

My question: It there a method to retrieve parts of a graph from the graph object? Yes, we can use Flatten[Position[VertexDegree[g], 1]] as indicated above. The key to this solution was to use 1 (unity) to point to all numbers in the range. Then only the numbers with VertexDegree of 1 are the primes.

New question: How do we get only the source numbers p labeled?
[1]: https://i.sstatic.net/pQyzt.pngThanks, kglr, for the answer.

I googled for images of graphs and found nothing that even comes close to this one, so I want to experiment some more.

limc = 4;  
primes = Join[{1}, Prime[Range[limc]]];  
(* if you want to evaluate several times, put the above 2 lines in a 
separate cell and evaluate. Then run these below as needed *)  

limc = Length[primes] - 1;  
limv = Prime[limc + 1]^2 - 1;  
a = Flatten[Table[p -> p (m + 1), {p, primes}, {m, 1, limv/p - 1}]];  
g = Graph[a]  
primes = Join[primes, Flatten[Position[VertexDegree[g], 1]]];  
Print[Length[%] - 1 , " primes less than ", limv]  

The graph of the first 4 primes up to limv is:
[![Sieve of Eratosthenes Graph][1]][1]

You will notice the one points to many odd numbers that have only one connection. These are the primes.

My question: It there a method to retrieve parts of a graph from the graph object? Yes, we can use Flatten[Position[VertexDegree[g], 1]] as indicated above. The key to this solution was to use 1 (unity) to point to all numbers in the range. Then only the numbers with VertexDegree of 1 are the primes.

New question: How do we get only the source numbers p labeled?
[1]: https://i.sstatic.net/pQyzt.png

I googled for images of graphs and found nothing that even comes close to this one, so I want to experiment some more.

limc = 4;  
primes = Join[{1}, Prime[Range[limc]]];  
(* if you want to evaluate several times, put the above 2 lines in a 
separate cell and evaluate. Then run these below as needed *)  

limc = Length[primes] - 1;  
limv = Prime[limc + 1]^2 - 1;  
a = Flatten[Table[p -> p (m + 1), {p, primes}, {m, 1, limv/p - 1}]];  
g = Graph[a];
sources = Select[VertexList[g],VertexOutDegree[g, #] >= 1 &];  
SetProperty[g, {VertexLabels -> (Thread[
 sources -> Placed["Name", Center]]), 
VertexSize -> (Thread[sources -> 3/2])}]
Show[g]
primes = Join[primes, Flatten[Position[VertexDegree[g], 1]]];  
Print[Length[%] - 1 , " primes less than ", limv]  

The graph of the first 4 primes up to limv is:
enter image description here

You will notice the one points to many odd numbers that have only one connection. These are the primes.

My question: It there a method to retrieve parts of a graph from the graph object? Yes, we can use Flatten[Position[VertexDegree[g], 1]] as indicated above. The key to this solution was to use 1 (unity) to point to all numbers in the range. Then only the numbers with VertexDegree of 1 are the primes.

New question: How do we get only the source numbers p labeled?
Thanks, kglr, for the answer.

revised everything and answered first question
Source Link
Fred Daniel Kline
  • 2.4k
  • 2
  • 20
  • 41

I googled for images of graphs and found nothing that even comes close to this one, so I want to experiment some more.

limc = 4;  
limvprimes = Prime[limcJoin[{1}, +Prime[Range[limc]]]; 1]^2 -
(* 1;if you want to evaluate several times, put the above 2 lines in a 
bseparate cell and evaluate. Then run these below as needed *)  

limc = Table[1Length[primes] -> 21; n +
limv 1,= {n,Prime[limc 1,+ limv/21]^2 - 1}];1;  
a = Table[Prime[n]Flatten[Table[p -> Prime[n]p (m + 1), {n, 1p, limcprimes},
  {m, 1, limv/Prime[n]p - 1}];]];  
GraphicsGrid[{{GraphPlot[b],g GraphPlot[a[[1]]],= GraphPlot[a[[2]]]},Graph[a]  
primes {GraphPlot[a[[3]]],= GraphPlot[a[[4]]]Join[primes,}}]  
  GraphPlot[Join[Flatten[a]Flatten[Position[VertexDegree[g], b],1]]];  
  VertexRenderingFunctionPrint[Length[%] -> ({White, EdgeForm[Black],1 Disk[#, .1], 
  " primes less than Black", Text[#2,limv] #1]} &)]

List b represents the possible odd primes. List a is the 4 different prime cancellations.

The GraphicsGrid shows 5 radial graphs that we combine: 1 -> odd numbers, 2 -> evens, 3 -> multiples of 3, 5 -> multiples of 5, and 7 -> multiples of 7.

The graph of the first 4 primes up to limv is: 
Sieve of Eratosthenes Graph[![Sieve of Eratosthenes Graph][1]][1]

You will notice the one points to many odd numbers that have only one connection. These are the primes.

My question: It there a method to retrieve parts of a graph from the graph object? Yes, we can use Flatten[Position[VertexDegree[g], 1]] as indicated above. The key to this solution was to use 1 (unity) to point to all numbers in the range. Then only the numbers with VertexDegree of 1 are the primes.

MyNew question: It there a method to retrieve parts of a graph fromHow do we get only the graph objectsource numbers p labeled? I want those primes and the evens that also have no connections, so I can do more evaluation.
[1]: https://i.sstatic.net/pQyzt.png

I googled for images of graphs and found nothing that even comes close to this one, so I want to experiment some more.

limc = 4;  
limv = Prime[limc + 1]^2 - 1;  
b = Table[1 -> 2 n + 1, {n, 1, limv/2 - 1}];  
a = Table[Prime[n] -> Prime[n] (m + 1), {n, 1, limc},
  {m, 1, limv/Prime[n] - 1}];  
GraphicsGrid[{{GraphPlot[b], GraphPlot[a[[1]]], GraphPlot[a[[2]]]},  
 {GraphPlot[a[[3]]], GraphPlot[a[[4]]],}}]  
  GraphPlot[Join[Flatten[a], b],  
  VertexRenderingFunction -> ({White, EdgeForm[Black], Disk[#, .1], 
      Black, Text[#2, #1]} &)]

List b represents the possible odd primes. List a is the 4 different prime cancellations.

The GraphicsGrid shows 5 radial graphs that we combine: 1 -> odd numbers, 2 -> evens, 3 -> multiples of 3, 5 -> multiples of 5, and 7 -> multiples of 7.

The graph of the first 4 primes up to limv is: Sieve of Eratosthenes Graph

You will notice the one points to many odd numbers that have only one connection. These are the primes.

My question: It there a method to retrieve parts of a graph from the graph object? I want those primes and the evens that also have no connections, so I can do more evaluation.

I googled for images of graphs and found nothing that even comes close to this one, so I want to experiment some more.

limc = 4;  
primes = Join[{1}, Prime[Range[limc]]];  
(* if you want to evaluate several times, put the above 2 lines in a 
separate cell and evaluate. Then run these below as needed *)  

limc = Length[primes] - 1;  
limv = Prime[limc + 1]^2 - 1;  
a = Flatten[Table[p -> p (m + 1), {p, primes}, {m, 1, limv/p - 1}]];  
g = Graph[a]  
primes = Join[primes, Flatten[Position[VertexDegree[g], 1]]];  
Print[Length[%] - 1 , " primes less than ", limv]  

The graph of the first 4 primes up to limv is: 
[![Sieve of Eratosthenes Graph][1]][1]

You will notice the one points to many odd numbers that have only one connection. These are the primes.

My question: It there a method to retrieve parts of a graph from the graph object? Yes, we can use Flatten[Position[VertexDegree[g], 1]] as indicated above. The key to this solution was to use 1 (unity) to point to all numbers in the range. Then only the numbers with VertexDegree of 1 are the primes.

New question: How do we get only the source numbers p labeled?
[1]: https://i.sstatic.net/pQyzt.png

edited tags
Link
formatting
Source Link
Martin Ender
  • 8.8k
  • 1
  • 35
  • 61
Loading
Source Link
Fred Daniel Kline
  • 2.4k
  • 2
  • 20
  • 41
Loading